This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 974
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2224
- Loading branch information
Showing
20 changed files
with
1,066 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const extensionActions = require('../../common/actions/extensionActions') | ||
const { makeImmutable } = require('../../common/state/immutableUtil') | ||
const electron = require('electron') | ||
const BrowserWindow = electron.BrowserWindow | ||
const messages = require('../../../js/constants/messages') | ||
|
||
const browserActions = { | ||
init: () => { | ||
// TODO - clear tab ids when tab is closed | ||
process.on('chrome-browser-action-registered', (extensionId, details) => { | ||
extensionActions.browserActionRegistered(extensionId, makeImmutable(details)) | ||
}) | ||
|
||
process.on('chrome-browser-action-set-icon', (extensionId, details) => { | ||
extensionActions.browserActionUpdated(extensionId, makeImmutable(details), details.tabId) | ||
}) | ||
|
||
process.on('chrome-browser-action-set-badge-text', (extensionId, details) => { | ||
extensionActions.browserActionUpdated(extensionId, makeImmutable(details), details.tabId) | ||
}) | ||
|
||
process.on('chrome-browser-action-set-badge-background-color', (extensionId, details) => { | ||
extensionActions.browserActionUpdated(extensionId, makeImmutable(details), details.tabId) | ||
}) | ||
|
||
process.on('chrome-browser-action-set-title', (extensionId, details) => { | ||
extensionActions.browserActionUpdated(extensionId, makeImmutable(details), details.tabId) | ||
}) | ||
|
||
process.on('chrome-browser-action-popup', (extensionId, tabId, name, popup, props) => { | ||
let nodeProps = { | ||
left: props.x, | ||
top: props.y + 20, | ||
src: popup | ||
} | ||
|
||
let win = BrowserWindow.getFocusedWindow() | ||
if (!win) { | ||
return | ||
} | ||
|
||
win.webContents.send(messages.NEW_POPUP_WINDOW, extensionId, popup, nodeProps) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = browserActions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
const AppDispatcher = require('../../../js/dispatcher/appDispatcher') | ||
const ExtensionConstants = require('../constants/extensionConstants') | ||
|
||
const extensionActions = { | ||
/** | ||
* Dispatched when an extension browser action is added | ||
* | ||
* @param {string} extensionId - the extension id | ||
* @param {object} browserAction - browser action details | ||
*/ | ||
browserActionRegistered: function (extensionId, browserAction) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.BROWSER_ACTION_REGISTERED, | ||
extensionId, | ||
browserAction | ||
}) | ||
}, | ||
|
||
browserActionUpdated: function (extensionId, browserAction, tabId) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.BROWSER_ACTION_UPDATED, | ||
extensionId, | ||
browserAction, | ||
tabId | ||
}) | ||
}, | ||
|
||
/** | ||
* Dispatched when an extension has been installed | ||
* | ||
* @param {string} extensionId - the extension id | ||
*/ | ||
extensionInstalled: function (extensionId, installInfo) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.EXTENSION_INSTALLED, | ||
extensionId, | ||
installInfo | ||
}) | ||
}, | ||
|
||
/** | ||
* Dispatched when an extension has been uninstalled | ||
* | ||
* @param {string} extensionId - the extension id | ||
*/ | ||
extensionUninstalled: function (extensionId) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.EXTENSION_UNINSTALLED, | ||
extensionId | ||
}) | ||
}, | ||
|
||
/** | ||
* Dispatched when an extension has been enabled | ||
* | ||
* @param {string} extensionId - the extension id | ||
*/ | ||
extensionEnabled: function (extensionId) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.EXTENSION_ENABLED, | ||
extensionId | ||
}) | ||
}, | ||
|
||
/** | ||
* Dispatched when an extension has been disabled | ||
* | ||
* @param {string} extensionId - the extension id | ||
*/ | ||
extensionDisabled: function (extensionId) { | ||
AppDispatcher.dispatch({ | ||
actionType: ExtensionConstants.EXTENSION_DISABLED, | ||
extensionId | ||
}) | ||
} | ||
} | ||
|
||
module.exports = extensionActions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const mapValuesByKeys = require('../../../js/lib/functional').mapValuesByKeys | ||
|
||
const _ = null | ||
const ExtensionConstants = { | ||
BROWSER_ACTION_REGISTERED: _, | ||
BROWSER_ACTION_UPDATED: _, | ||
EXTENSION_INSTALLED: _, | ||
EXTENSION_UNINSTALLED: _, | ||
EXTENSION_ENABLED: _, | ||
EXTENSION_DISABLED: _ | ||
} | ||
|
||
module.exports = mapValuesByKeys(ExtensionConstants) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const tabState = require('./tabState') | ||
const { makeImmutable } = require('./immutableUtil') | ||
const Immutable = require('immutable') | ||
|
||
let transientFields = [] | ||
|
||
tabState.addTransientFields(['browserAction']) | ||
|
||
const browserActionDefaults = Immutable.fromJS({ | ||
tabs: {} | ||
}) | ||
|
||
const extensionState = { | ||
|
||
getEnabledExtensions: (state) => { | ||
return state.get('extensions').filter((installInfo, extensionId) => { | ||
return installInfo.get('enabled') === true | ||
}) | ||
}, | ||
|
||
getExtensionById: (state, extensionId) => { | ||
return state.getIn(['extensions', extensionId]) | ||
}, | ||
|
||
getBrowserActionByTabId: (state, extensionId, tabId) => { | ||
tabId = tabId ? tabId.toString() : '-1' | ||
let extension = extensionState.getExtensionById(state, extensionId) | ||
if (extension && extension.get('browserAction')) { | ||
let tabBrowserAction = extension.getIn(['tabs', tabId]) || Immutable.Map() | ||
return extension.get('browserAction').merge(tabBrowserAction).merge({base_path: extension.get('base_path')}) | ||
} | ||
return null | ||
}, | ||
|
||
browserActionRegistered: (state, action) => { | ||
action = makeImmutable(action) | ||
state = makeImmutable(state) | ||
let extensionId = action.get('extensionId').toString() | ||
let extension = extensionState.getExtensionById(state, extensionId) | ||
if (extension) { | ||
extension = extension.set('browserAction', browserActionDefaults.merge(action.get('browserAction'))) | ||
return state.setIn(['extensions', extensionId], extension) | ||
} else { | ||
return state | ||
} | ||
}, | ||
|
||
browserActionUpdated: (state, action) => { | ||
action = makeImmutable(action) | ||
state = makeImmutable(state) | ||
let extensionId = action.get('extensionId').toString() | ||
let extension = extensionState.getExtensionById(state, extensionId) | ||
if (extension && extension.get('browserAction')) { | ||
let tabId = action.get('tabId') | ||
if (tabId) { | ||
let tabs = extension.getIn(['browserAction', 'tabs']) | ||
let tab = tabs.get(tabId) || Immutable.Map() | ||
tabs = tabs.set(tabId, tab.merge(action.get('browserAction'))) | ||
extension = extension.setIn(['browserAction', 'tabs'], tabs) | ||
} else { | ||
extension = extension.set('browserAction', extension.get('browserAction').merge(action.get('browserAction'))) | ||
} | ||
return state.setIn(['extensions', extensionId], extension) | ||
} else { | ||
return state | ||
} | ||
}, | ||
|
||
extensionInstalled: (state, action) => { | ||
action = makeImmutable(action) | ||
state = makeImmutable(state) | ||
let extensionId = action.get('extensionId').toString() | ||
return state.setIn(['extensions', extensionId], action.get('installInfo')) | ||
}, | ||
|
||
extensionEnabled: (state, action) => { | ||
action = makeImmutable(action) | ||
state = makeImmutable(state) | ||
let extensionId = action.get('extensionId').toString() | ||
let extension = extensionState.getExtensionById(state, extensionId) | ||
if (extension) { | ||
return state.setIn(['extensions', extensionId], extension.set('enabled', true)) | ||
} else { | ||
return state | ||
} | ||
}, | ||
|
||
extensionDisabled: (state, action) => { | ||
action = makeImmutable(action) | ||
state = makeImmutable(state) | ||
let extensionId = action.get('extensionId').toString() | ||
let extension = extensionState.getExtensionById(state, extensionId) | ||
if (extension) { | ||
return state.setIn(['extensions', action.get('extensionId')], extension.set('enabled', false)) | ||
} else { | ||
return state | ||
} | ||
}, | ||
|
||
getTransientFields: () => { | ||
return transientFields | ||
}, | ||
|
||
getPersistentTabState: (extension) => { | ||
extension = makeImmutable(extension) | ||
extensionState.getTransientFields().forEach((field) => { | ||
extension = extension.delete(field) | ||
}) | ||
return extension | ||
} | ||
} | ||
|
||
module.exports = extensionState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.