Fix a bug where failed resources cannot be added as rules in some cases.

currentProfileCanAddRule is now correctly set regardless of page info.

Parse URLs like `chrome://errorpage/?lasturl=` in some browsers. Fix #365.
This commit is contained in:
FelisCatus 2015-05-28 14:48:50 +08:00
parent 807fad5449
commit 8f71270f1d
4 changed files with 19 additions and 12 deletions

View File

@ -3,6 +3,7 @@ OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise
xhr = Promise.promisify(require('xhr'))
Url = require('url')
querystring = require('querystring')
chromeApiPromisifyAll = require('./chrome_api')
proxySettings = chromeApiPromisifyAll(chrome.proxy.settings)
parseExternalProfile = require('./parse_external_profile')
@ -321,7 +322,14 @@ class ChromeOptions extends OmegaTarget.Options
url = inspectUrl
else
@clearBadge()
return null if not url or url.substr(0, 6) == 'chrome'
return null if not url
if url.substr(0, 6) == 'chrome'
errorPagePrefix = 'chrome://errorpage/'
if url.substr(0, errorPagePrefix.length) == errorPagePrefix
url = querystring.parse(url.substr(url.indexOf('?') + 1)).lasturl
return null if not url
else
return null
domain = OmegaPac.getBaseDomain(Url.parse(url).hostname)
return {
url: url

View File

@ -129,7 +129,7 @@ module.exports = class WebRequestMonitor
chrome.tabs.onReplaced?.addListener (added, removed) =>
@tabInfo[added] ?= @_newTabInfo()
delete @tabInfo[removed]
chrome.tabs.onUpdated.addListener (tab) =>
chrome.tabs.onUpdated.addListener (tabId, changeInfo, tab) =>
info = @tabInfo[tab.id] ?= @_newTabInfo()
return unless info
for callback in @_tabCallbacks
@ -154,6 +154,7 @@ module.exports = class WebRequestMonitor
info = @tabInfo[req.tabId]
if info
if status == 'start' and req.type == 'main_frame'
if req.url.indexOf('chrome://errorpage/') != 0
for own key, value of @_newTabInfo()
info[key] = value
return if info.requestCount > 1000

View File

@ -251,18 +251,16 @@ module.controller 'PopupCtrl', ($scope, $window, $q, omegaTarget,
$scope.domainsForCondition[domain.domain] ?= true
$scope.profileForDomains ?= preselectedProfileNameForCondition
omegaTarget.getActivePageInfo().then((info) ->
$q.all([
omegaTarget.state('currentProfileCanAddRule')
omegaTarget.getActivePageInfo(),
]).then ([canAddRule, info]) ->
$scope.currentProfileCanAddRule = canAddRule
if info
$scope.currentTempRuleProfile = info.tempRuleProfileName
if $scope.currentTempRuleProfile
preselectedProfileNameForCondition = $scope.currentTempRuleProfile
$scope.currentDomain = info.domain
else
$q.reject()
).then(->
omegaTarget.state('currentProfileCanAddRule')
).then (value) ->
$scope.currentProfileCanAddRule = value
$scope.prepareConditionForm = ->
currentDomain = $scope.currentDomain

View File

@ -58,7 +58,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
a(href='#' role='button' ng-click='setDefaultProfile(profile.name, p.name)' title='{{getProfileTitle(profile)}}')
span(omega-profile-inline='p' options='availableProfiles' disp-name='dispNameFilter')
li.divider(ng-show='!!currentDomain && validResultProfiles.length')
li(ng-show='!!currentProfileCanAddRule')
li(ng-show='!!currentProfileCanAddRule && !!currentDomain')
a(href='#' role='button' ng-click='prepareConditionForm()' data-shortcut='addRule')
span.glyphicon.glyphicon-plus
= ' '