Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
open background page devtools when navigating to background page url
Browse files Browse the repository at this point in the history
fix #7880
requires brave/muon@42b9c96

note: url will not properly reset until #7894 is fixed
  • Loading branch information
bridiver committed Mar 25, 2017
1 parent 396cdbc commit d11603e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const api = {
return
}

if (newTab.isBackgroundPage()) {
newTab.openDevTools()
return
}

let location = newTab.getURL()
if (!location || location === '') {
location = 'about:blank'
Expand Down
7 changes: 7 additions & 0 deletions app/common/lib/httpUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 15 additions & 1 deletion app/renderer/reducers/urlBarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const windowConstants = require('../../../js/constants/windowConstants')
const {getSourceAboutUrl, getSourceMagnetUrl, isIntermediateAboutPage, navigatableTypes} = require('../../../js/lib/appUrlUtil')
const {isURL, getUrlFromInput} = require('../../../js/lib/urlutil')
const {activeFrameStatePath, frameStatePath, getFrameByKey, getActiveFrame, tabStatePath} = require('../../../js/state/frameStateUtil')
const {activeFrameStatePath, frameStatePath, getFrameByKey, getActiveFrame, tabStatePath, getFrameByTabId} = require('../../../js/state/frameStateUtil')
const urlParse = require('../../common/urlParse')

const updateNavBarInput = (state, loc, framePath) => {
Expand All @@ -18,6 +18,17 @@ const updateNavBarInput = (state, loc, framePath) => {
return state
}

const navigationAborted = (state, action) => {
const frame = getFrameByTabId(state, action.tabId)
if (frame) {
const location = frame.get('provisionalLocation')
if (location) {
state = updateNavBarInput(state, location)
}
}
return state
}

const urlBarReducer = (state, action) => {
switch (action.actionType) {
case windowConstants.WINDOW_SET_NAVBAR_INPUT:
Expand Down Expand Up @@ -122,6 +133,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
}
Expand Down
12 changes: 12 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ const windowActions = {
})
},

/**
* Dispatches a message to the store to let it know the page navigation was aborted
*
* @param {number} tabId
*/
navigationAborted: function (tabId) {
dispatch({
actionType: windowConstants.WINDOW_SET_NAVIGATION_ABORTED,
tabId
})
},

/**
* Dispatches a message to set the security state.
* @param {Object} frameProps - The frame properties to modify.
Expand Down
5 changes: 4 additions & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'))
} else if (provisionLoadFailure) {
windowActions.setNavigated(url, this.props.frameKey, true, this.frame.get('tabId'))
}
Expand Down
1 change: 1 addition & 0 deletions js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: _,
Expand Down

0 comments on commit d11603e

Please sign in to comment.