diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 441ad89f701..2c66b639d23 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -33,7 +33,6 @@ const bookmarksState = require('../common/state/bookmarksState') const bookmarkFoldersState = require('../common/state/bookmarkFoldersState') const historyState = require('../common/state/historyState') const bookmarkOrderCache = require('../common/cache/bookmarkOrderCache') -const {getWindow} = require('./windows') let currentPartitionNumber = 0 const incrementPartitionNumber = () => ++currentPartitionNumber @@ -737,27 +736,9 @@ const api = { createProperties.discarded = false createProperties.autoDiscardable = false } - - const doCreate = () => { - extensions.createTab(createProperties, (tab) => { - cb && cb(tab) - }) - } - - if (createProperties.windowId) { - const win = getWindow(createProperties.windowId) - if (!win || win.isDestroyed()) { - console.error('Cannot create a tab for a window which does not exist or is destroyed') - return - } - if (!win.__ready) { - win.once(messages.WINDOW_RENDERER_READY, () => { - doCreate() - }) - return - } - } - doCreate() + extensions.createTab(createProperties, (tab) => { + cb && cb(tab) + }) }) }, diff --git a/app/browser/windows.js b/app/browser/windows.js index 613afd3aaa9..63836dfdec8 100644 --- a/app/browser/windows.js +++ b/app/browser/windows.js @@ -302,7 +302,6 @@ const api = { if (win && !win.isDestroyed()) { updatePinnedTabs(win) win.__ready = true - win.emit(messages.WINDOW_RENDERER_READY) } }) }, diff --git a/app/common/actions/extensionActions.js b/app/common/actions/extensionActions.js index badf28a5ea7..1711c64689a 100644 --- a/app/common/actions/extensionActions.js +++ b/app/common/actions/extensionActions.js @@ -3,7 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ 'use strict' -const appDispatcher = require('../../../js/dispatcher/appDispatcher') +const AppDispatcher = require('../../../js/dispatcher/appDispatcher') const ExtensionConstants = require('../constants/extensionConstants') const extensionActions = { @@ -14,7 +14,7 @@ const extensionActions = { * @param {object} browserAction - browser action details */ browserActionRegistered: function (extensionId, browserAction) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.BROWSER_ACTION_REGISTERED, extensionId, browserAction @@ -22,7 +22,7 @@ const extensionActions = { }, browserActionUpdated: function (extensionId, browserAction, tabId) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.BROWSER_ACTION_UPDATED, extensionId, browserAction, @@ -36,7 +36,7 @@ const extensionActions = { * @param {string} extensionId - the extension id */ extensionInstalled: function (extensionId, installInfo) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.EXTENSION_INSTALLED, extensionId, installInfo @@ -49,7 +49,7 @@ const extensionActions = { * @param {string} extensionId - the extension id */ extensionUninstalled: function (extensionId) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.EXTENSION_UNINSTALLED, extensionId }) @@ -61,7 +61,7 @@ const extensionActions = { * @param {string} extensionId - the extension id */ extensionEnabled: function (extensionId) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.EXTENSION_ENABLED, extensionId }) @@ -73,7 +73,7 @@ const extensionActions = { * @param {string} extensionId - the extension id */ extensionDisabled: function (extensionId) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.EXTENSION_DISABLED, extensionId }) @@ -88,7 +88,7 @@ const extensionActions = { * @param {string} icon - 16x16 extension icon */ contextMenuCreated: function (extensionId, menuItemId, properties, icon) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.CONTEXT_MENU_CREATED, extensionId, menuItemId, @@ -103,7 +103,7 @@ const extensionActions = { * @param {string} extensionId - the extension id */ contextMenuAllRemoved: function (extensionId) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.CONTEXT_MENU_ALL_REMOVED, extensionId }) @@ -117,7 +117,7 @@ const extensionActions = { * @param {object} info - the arg of onclick callback */ contextMenuClicked: function (extensionId, tabId, info) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: ExtensionConstants.CONTEXT_MENU_CLICKED, extensionId, tabId, diff --git a/js/actions/syncActions.js b/js/actions/syncActions.js index 62a97228322..f9982d84cc3 100644 --- a/js/actions/syncActions.js +++ b/js/actions/syncActions.js @@ -3,32 +3,32 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ 'use strict' -const appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const syncConstants = require('../constants/syncConstants') const syncActions = { addSites: function (items) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: syncConstants.SYNC_ADD_SITES, items }) }, removeSites: function (items) { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: syncConstants.SYNC_REMOVE_SITES, items }) }, clearHistory: function () { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: syncConstants.SYNC_CLEAR_HISTORY }) }, clearSiteSettings: function () { - appDispatcher.dispatch({ + AppDispatcher.dispatch({ actionType: syncConstants.SYNC_CLEAR_SITE_SETTINGS }) } diff --git a/js/constants/messages.js b/js/constants/messages.js index 21afa547b8a..9d11a863735 100644 --- a/js/constants/messages.js +++ b/js/constants/messages.js @@ -118,8 +118,6 @@ const messages = { SET_CERT_ERROR_DETAIL: _, SET_SECURITY_STATE: _, /** @arg {number} key of frame, @arg {Object} security state */ HTTPSE_RULE_APPLIED: _, /** @arg {string} name of ruleset file, @arg {Object} details of rewritten request */ - // Dispatch related message - WINDOW_RENDERER_READY: _, // Extensions NEW_POPUP_WINDOW: _, // Localization diff --git a/js/dispatcher/appDispatcher.js b/js/dispatcher/appDispatcher.js index a7e19081369..ec86225ead8 100644 --- a/js/dispatcher/appDispatcher.js +++ b/js/dispatcher/appDispatcher.js @@ -49,16 +49,6 @@ class AppDispatcher { if (process.type === 'renderer') { ipc.send('app-dispatcher-register') } - return this.registerLocalCallback(callback) - } - - /** - * Same as above, but registers the specified callback - * locally only. This is used by the windowStore since - * the store process is registered as soon as the window - * is created. - */ - registerLocalCallback (callback) { this.callbacks.push(callback) return this.callbacks.length - 1 // index } @@ -141,8 +131,33 @@ class AppDispatcher { shutdown () { appDispatcher.dispatch = (payload) => {} } +} + +const appDispatcher = new AppDispatcher() + +const doneDispatching = () => { + if (dispatchCargo.idle()) { + appDispatcher.dispatching = false + } +} - registerWindow (registrant, hostWebContents) { +const dispatchCargo = async.cargo((task, callback) => { + for (let i = 0; i < task.length; i++) { + appDispatcher.dispatchInternal(task[i], () => {}) + } + callback() + doneDispatching() +}, 200) + +const ipcCargo = async.cargo((tasks, callback) => { + ipc.send(messages.DISPATCH_ACTION, Serializer.serialize(tasks)) + callback() +}, 200) + +if (processType === 'browser') { + ipc.on('app-dispatcher-register', (event) => { + const registrant = event.sender + const hostWebContents = event.sender.hostWebContents || event.sender const win = BrowserWindow.fromWebContents(hostWebContents) const windowId = win.id @@ -153,15 +168,6 @@ class AppDispatcher { callback() }, 20) - // If the window isn't ready yet then wait until it is ready before delivering - // messages to it. - if (!win.__ready) { - registrantCargo.pause() - win.on(messages.WINDOW_RENDERER_READY, () => { - registrantCargo.resume() - }) - } - const callback = function (payload) { try { if (registrant.isDestroyed()) { @@ -190,42 +196,13 @@ class AppDispatcher { appDispatcher.unregister(callback) } } - registrant.on('crashed', () => { + event.sender.on('crashed', () => { appDispatcher.unregister(callback) }) - registrant.on('destroyed', () => { + event.sender.on('destroyed', () => { appDispatcher.unregister(callback) }) appDispatcher.register(callback) - } -} - -const appDispatcher = new AppDispatcher() - -const doneDispatching = () => { - if (dispatchCargo.idle()) { - appDispatcher.dispatching = false - } -} - -const dispatchCargo = async.cargo((task, callback) => { - for (let i = 0; i < task.length; i++) { - appDispatcher.dispatchInternal(task[i], () => {}) - } - callback() - doneDispatching() -}, 200) - -const ipcCargo = async.cargo((tasks, callback) => { - ipc.send(messages.DISPATCH_ACTION, Serializer.serialize(tasks)) - callback() -}, 200) - -if (processType === 'browser') { - ipc.on('app-dispatcher-register', (event) => { - const registrant = event.sender - const hostWebContents = event.sender.hostWebContents || event.sender - appDispatcher.registerWindow(registrant, hostWebContents) }) const dispatchEventPayload = (event, payload) => { diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index 0beffd8c56a..e901b04a57c 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -2,7 +2,7 @@ * 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 appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const AppStore = require('../stores/appStore') const appConstants = require('../constants/appConstants') const appConfig = require('../constants/appConfig') @@ -383,21 +383,21 @@ const doAction = (action) => { case appConstants.APP_REMOVE_SITE_SETTING: case appConstants.APP_CHANGE_SITE_SETTING: case appConstants.APP_ADD_NOSCRIPT_EXCEPTIONS: - appDispatcher.waitFor([AppStore.dispatchToken], () => { + AppDispatcher.waitFor([AppStore.dispatchToken], () => { userPrefsUpdateTrigger(action.temporary) contentSettingsUpdateTrigger(action.temporary) }) break case appConstants.APP_CHANGE_SETTING: case appConstants.APP_SET_RESOURCE_ENABLED: - appDispatcher.waitFor([AppStore.dispatchToken], () => { + AppDispatcher.waitFor([AppStore.dispatchToken], () => { userPrefsUpdateTrigger() contentSettingsUpdateTrigger() }) break case appConstants.APP_ALLOW_FLASH_ONCE: case appConstants.APP_ALLOW_FLASH_ALWAYS: - appDispatcher.waitFor([AppStore.dispatchToken], () => { + AppDispatcher.waitFor([AppStore.dispatchToken], () => { userPrefsUpdateTrigger(action.isPrivate) contentSettingsUpdateTrigger(action.isPrivate) }) @@ -415,5 +415,5 @@ module.exports.init = () => { updateContentSettings(AppStore.getState(), appConfig, incognito) ) - appDispatcher.register(doAction) + AppDispatcher.register(doAction) } diff --git a/js/state/privacy.js b/js/state/privacy.js index 416c8818de3..c499825f84d 100644 --- a/js/state/privacy.js +++ b/js/state/privacy.js @@ -2,7 +2,7 @@ * 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 appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const AppStore = require('../stores/appStore') const appConstants = require('../constants/appConstants') const {passwordManagers} = require('../constants/passwordManagers') @@ -24,7 +24,7 @@ let updateTrigger // Register callback to handle all updates const doAction = (action) => { if (action.actionType === appConstants.APP_CHANGE_SETTING) { - appDispatcher.waitFor([AppStore.dispatchToken], () => { + AppDispatcher.waitFor([AppStore.dispatchToken], () => { updateTrigger() }) } @@ -32,5 +32,5 @@ const doAction = (action) => { module.exports.init = () => { updateTrigger = registerUserPrefs(() => getPrivacySettings()) - appDispatcher.register(doAction) + AppDispatcher.register(doAction) } diff --git a/js/stores/appStore.js b/js/stores/appStore.js index 5e8fcc08793..2b1c5901687 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -6,7 +6,7 @@ const appConstants = require('../constants/appConstants') const windowConstants = require('../constants/windowConstants') const ExtensionConstants = require('../../app/common/constants/extensionConstants') -const appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const settings = require('../constants/settings') const {STATE_SITES} = require('../constants/stateConstants') const syncUtil = require('../state/syncUtil') @@ -74,81 +74,6 @@ class AppStore extends EventEmitter { this.lastEmittedState = null } -<<<<<<< HEAD -======= - const homepageSetting = getSetting(settings.HOMEPAGE) - const startupSetting = getSetting(settings.STARTUP_MODE) - const toolbarUserInterfaceScale = getSetting(settings.TOOLBAR_UI_SCALE) - - setImmediate(() => { - const win = new BrowserWindow(Object.assign(windowProps, browserOpts, {disposition: frameOpts.disposition})) - let restoredImmutableWindowState = action.restoredState - initWindowCacheState(win.id, restoredImmutableWindowState) - - // initialize frames state - let frames = Immutable.List() - if (restoredImmutableWindowState) { - frames = restoredImmutableWindowState.get('frames') - restoredImmutableWindowState = restoredImmutableWindowState.set('frames', Immutable.List()) - restoredImmutableWindowState = restoredImmutableWindowState.set('tabs', Immutable.List()) - } else { - if (frameOpts && Object.keys(frameOpts).length > 0) { - if (frameOpts.forEach) { - frames = Immutable.fromJS(frameOpts) - } else { - frames = frames.push(Immutable.fromJS(frameOpts)) - } - } else if (startupSetting === 'homePage' && homepageSetting) { - frames = Immutable.fromJS(homepageSetting.split('|').map((homepage) => { - return { - location: homepage - } - })) - } - } - - if (frames.size === 0) { - frames = Immutable.fromJS([{}]) - } - - if (immutableWindowState.getIn(['ui', 'isMaximized'])) { - win.maximize() - } - - if (immutableWindowState.getIn(['ui', 'isFullScreen'])) { - win.setFullScreen(true) - } - - appDispatcher.registerWindow(win, win.webContents) - win.webContents.on('did-finish-load', (e) => { - lastEmittedState = appState - win.webContents.setZoomLevel(zoomLevel[toolbarUserInterfaceScale] || 0.0) - - const mem = muon.shared_memory.create({ - windowValue: { - disposition: frameOpts.disposition, - id: win.id - }, - appState: appState.toJS(), - frames: frames.toJS(), - windowState: (restoredImmutableWindowState && restoredImmutableWindowState.toJS()) || undefined}) - - e.sender.sendShared(messages.INITIALIZE_WINDOW, mem) - if (action.cb) { - action.cb() - } - }) - - win.on('ready-to-show', () => { - win.show() - }) - - win.loadURL(appUrlUtil.getBraveExtIndexHTML()) - }) -} - -class AppStore extends EventEmitter { ->>>>>>> db1c16f77... Fix dispatch issues for actions pre windowReady getState () { return appState } @@ -300,7 +225,7 @@ const handleAppAction = (action) => { calculateTopSites(true, true) break case appConstants.APP_SHUTTING_DOWN: - appDispatcher.shutdown() + AppDispatcher.shutdown() app.quit() break case appConstants.APP_CHANGE_NEW_TAB_DETAIL: @@ -772,6 +697,6 @@ const handleAppAction = (action) => { emitChanges() } -appStore.dispatchToken = appDispatcher.register(handleAppAction) +appStore.dispatchToken = AppDispatcher.register(handleAppAction) module.exports = appStore diff --git a/js/stores/eventStore.js b/js/stores/eventStore.js index c33068cff38..d8d9ec7edb4 100644 --- a/js/stores/eventStore.js +++ b/js/stores/eventStore.js @@ -3,7 +3,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const appConstants = require('../constants/appConstants') -const appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const AppStore = require('./appStore') const EventEmitter = require('events').EventEmitter const Immutable = require('immutable') @@ -112,7 +112,7 @@ const doAction = (action) => { } break case appConstants.APP_CLOSE_WINDOW: - appDispatcher.waitFor([AppStore.dispatchToken], () => { + AppDispatcher.waitFor([AppStore.dispatchToken], () => { windowClosed(action.windowId) }) break @@ -151,6 +151,6 @@ const doAction = (action) => { emitChanges() } -appDispatcher.register(doAction) +AppDispatcher.register(doAction) module.exports = eventStore diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 762e062a2d8..47a51acbab7 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -2,7 +2,7 @@ * 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 appDispatcher = require('../dispatcher/appDispatcher') +const AppDispatcher = require('../dispatcher/appDispatcher') const EventEmitter = require('events').EventEmitter const appActions = require('../actions/appActions') const appConstants = require('../constants/appConstants') @@ -848,6 +848,6 @@ frameShortcuts.forEach((shortcut) => { } }) -appDispatcher.registerLocalCallback(doAction) +AppDispatcher.register(doAction) module.exports = windowStore diff --git a/test/unit/js/stores/windowStoreTest.js b/test/unit/js/stores/windowStoreTest.js index 6f8e5a294e1..f3b258e0ee7 100644 --- a/test/unit/js/stores/windowStoreTest.js +++ b/test/unit/js/stores/windowStoreTest.js @@ -19,9 +19,6 @@ describe('Window store unit tests', function () { const fakeDispatcher = { register: (actionHandler) => { doAction = actionHandler - }, - registerLocalCallback: (actionHandler) => { - doAction = actionHandler } }