From 17b7cbe4c4bba688cb066cb69f692416462544ad Mon Sep 17 00:00:00 2001 From: bridiver Date: Sat, 25 Mar 2017 13:04:25 -0700 Subject: [PATCH] open background page devtools when navigating to background page url fix #7880 requires https://github.com/brave/muon/commit/42b9c96af6652ee7387d1e26d45a5832d23027da --- app/browser/tabs.js | 9 ++++++ app/common/lib/httpUtil.js | 7 ++++ app/renderer/reducers/urlBarReducer.js | 44 ++++++++++++++++++++------ docs/windowActions.md | 12 +++++++ js/actions/windowActions.js | 14 ++++++++ js/components/frame.js | 5 ++- js/constants/windowConstants.js | 1 + 7 files changed, 81 insertions(+), 11 deletions(-) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 94202d54e22..cfcd74d8cee 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -48,6 +48,15 @@ const api = { return } + if (newTab.isBackgroundPage()) { + if (newTab.isDevToolsOpened()) { + newTab.devToolsWebContents.focus() + } else { + newTab.openDevTools() + } + return + } + let location = newTab.getURL() if (!location || location === '') { location = 'about:blank' diff --git a/app/common/lib/httpUtil.js b/app/common/lib/httpUtil.js index dfa10c984c4..b6d5225591a 100644 --- a/app/common/lib/httpUtil.js +++ b/app/common/lib/httpUtil.js @@ -21,6 +21,11 @@ module.exports.isFrameError = function (errorCode) { return errorCode >= 100 && errorCode <= 899 } +module.exports.isAborted = function (errorCode) { + errorCode = Math.abs(errorCode) + return errorCode === 3 +} + /** * Gets the l10n id for the chrome error code * @param {number} errorCode the error code @@ -56,6 +61,8 @@ module.exports.l10nErrorText = function (errorCode) { } module.exports.errorMap = { + // An operation was aborted (due to user action). + 3: 'aborted', // A connection was reset (corresponding to a TCP RST). 101: 'connectionReset', // A connection attempt was refused. diff --git a/app/renderer/reducers/urlBarReducer.js b/app/renderer/reducers/urlBarReducer.js index b1f1616cbe4..5c5a83792e0 100644 --- a/app/renderer/reducers/urlBarReducer.js +++ b/app/renderer/reducers/urlBarReducer.js @@ -6,10 +6,23 @@ const windowConstants = require('../../../js/constants/windowConstants') const {getSourceAboutUrl, getSourceMagnetUrl, isIntermediateAboutPage, navigatableTypes} = require('../../../js/lib/appUrlUtil') -const {isURL, isPotentialPhishingUrl, getUrlFromInput} = require('../../../js/lib/urlutil') -const {activeFrameStatePath, frameStatePath, getFrameByKey, getActiveFrame, tabStatePath} = require('../../../js/state/frameStateUtil') +const {isURL, getUrlFromInput} = require('../../../js/lib/urlutil') +const {activeFrameStatePath, frameStatePath, frameStatePathForFrame, getFrameByKey, getActiveFrame, tabStatePath, getFrameByTabId} = require('../../../js/state/frameStateUtil') const urlParse = require('../../common/urlParse') +const getLocation = (location) => { + location = location.trim() + location = getSourceAboutUrl(location) || + getSourceMagnetUrl(location) || + location + + if (isURL(location)) { + location = getUrlFromInput(location) + } + + return location +} + const updateNavBarInput = (state, loc, framePath) => { if (framePath === undefined) { framePath = activeFrameStatePath(state) @@ -18,6 +31,21 @@ const updateNavBarInput = (state, loc, framePath) => { return state } +const navigationAborted = (state, action) => { + const frame = getFrameByTabId(state, action.tabId) + if (frame) { + let location = action.location || frame.get('provisionalLocation') + if (location) { + location = getLocation(location) + state = updateNavBarInput(state, location) + state = state.mergeIn(frameStatePathForFrame(state, frame), { + location + }) + } + } + return state +} + const urlBarReducer = (state, action) => { switch (action.actionType) { case windowConstants.WINDOW_SET_NAVBAR_INPUT: @@ -77,16 +105,9 @@ const urlBarReducer = (state, action) => { } break case windowConstants.WINDOW_SET_NAVIGATED: - action.location = action.location.trim() // For about: URLs, make sure we store the URL as about:something // and not what we map to. - action.location = getSourceAboutUrl(action.location) || - getSourceMagnetUrl(action.location) || - action.location - - if (isURL(action.location)) { - action.location = getUrlFromInput(action.location) - } + action.location = getLocation(action.location) const key = action.key || state.get('activeFrameKey') state = state.mergeIn(frameStatePath(state, key), { @@ -127,6 +148,9 @@ const urlBarReducer = (state, action) => { state = updateNavBarInput(state, action.location, frameStatePath(state, key)) } break + case windowConstants.WINDOW_SET_NAVIGATION_ABORTED: + state = navigationAborted(state, action) + break } return state } diff --git a/docs/windowActions.md b/docs/windowActions.md index be1f887b98d..cf581e9d463 100644 --- a/docs/windowActions.md +++ b/docs/windowActions.md @@ -64,6 +64,18 @@ Dispatches a message to the store to let it know a page has been navigated. +### navigationAborted(tabId, location) + +Dispatches a message to the store to let it know the page navigation was aborted + +**Parameters** + +**tabId**: `number`, Dispatches a message to the store to let it know the page navigation was aborted + +**location**: `string`, the last committed location if available + + + ### setSecurityState(frameProps, securityState) Dispatches a message to set the security state. diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index 6b9edd66b53..22305f2c4c1 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -108,6 +108,20 @@ const windowActions = { }) }, + /** + * Dispatches a message to the store to let it know the page navigation was aborted + * + * @param {number} tabId + * @param {string} location the last committed location if available + */ + navigationAborted: function (tabId, location) { + dispatch({ + actionType: windowConstants.WINDOW_SET_NAVIGATION_ABORTED, + tabId, + location + }) + }, + /** * Dispatches a message to set the security state. * @param {Object} frameProps - The frame properties to modify. diff --git a/js/components/frame.js b/js/components/frame.js index 0506c365a5e..d32ddef1a22 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -22,7 +22,7 @@ const getSetting = require('../settings').getSetting const config = require('../constants/config') const settings = require('../constants/settings') const {aboutUrls, isSourceMagnetUrl, isSourceAboutUrl, isTargetAboutUrl, getTargetAboutUrl, getBaseUrl, isIntermediateAboutPage} = require('../lib/appUrlUtil') -const {isFrameError} = require('../../app/common/lib/httpUtil') +const {isFrameError, isAborted} = require('../../app/common/lib/httpUtil') const locale = require('../l10n') const appConfig = require('../constants/appConfig') const {getSiteSettingsForHostPattern} = require('../state/siteSettings') @@ -881,6 +881,9 @@ class Frame extends ImmutableComponent { }) windowActions.loadUrl(this.frame, 'about:error') appActions.removeSite(siteUtil.getDetailFromFrame(this.frame)) + } else if (isAborted(e.errorCode)) { + // just stay put + windowActions.navigationAborted(this.frame.get('tabId'), url) } else if (provisionLoadFailure) { windowActions.setNavigated(url, this.props.frameKey, true, this.frame.get('tabId')) } diff --git a/js/constants/windowConstants.js b/js/constants/windowConstants.js index fe3aa2b58f6..df01e2d1896 100644 --- a/js/constants/windowConstants.js +++ b/js/constants/windowConstants.js @@ -38,6 +38,7 @@ const windowConstants = { WINDOW_SET_FRAME_TAB_ID: _, WINDOW_SET_FRAME_TITLE: _, WINDOW_SET_NAVIGATED: _, + WINDOW_SET_NAVIGATION_ABORTED: _, WINDOW_SET_URL_BAR_ACTIVE: _, // whether the URL bar is being typed in WINDOW_UNDO_CLOSED_FRAME: _, WINDOW_CLEAR_CLOSED_FRAMES: _,