From 8f71270f1d6c28d96bac6d686f34e5bfbb8acaca Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Thu, 28 May 2015 14:48:50 +0800 Subject: [PATCH] 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. --- omega-target-chromium-extension/src/options.coffee | 10 +++++++++- .../src/web_request_monitor.coffee | 7 ++++--- omega-web/src/coffee/popup.coffee | 12 +++++------- omega-web/src/popup.jade | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/omega-target-chromium-extension/src/options.coffee b/omega-target-chromium-extension/src/options.coffee index 19cc656..7377f1c 100644 --- a/omega-target-chromium-extension/src/options.coffee +++ b/omega-target-chromium-extension/src/options.coffee @@ -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 diff --git a/omega-target-chromium-extension/src/web_request_monitor.coffee b/omega-target-chromium-extension/src/web_request_monitor.coffee index 6c0cefb..1e14676 100644 --- a/omega-target-chromium-extension/src/web_request_monitor.coffee +++ b/omega-target-chromium-extension/src/web_request_monitor.coffee @@ -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,8 +154,9 @@ module.exports = class WebRequestMonitor info = @tabInfo[req.tabId] if info if status == 'start' and req.type == 'main_frame' - for own key, value of @_newTabInfo() - info[key] = value + if req.url.indexOf('chrome://errorpage/') != 0 + for own key, value of @_newTabInfo() + info[key] = value return if info.requestCount > 1000 info.requests[req.requestId] = req if (oldStatus = info.requestStatus[req.requestId]) diff --git a/omega-web/src/coffee/popup.coffee b/omega-web/src/coffee/popup.coffee index e91cf4f..2ebcacb 100644 --- a/omega-web/src/coffee/popup.coffee +++ b/omega-web/src/coffee/popup.coffee @@ -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 diff --git a/omega-web/src/popup.jade b/omega-web/src/popup.jade index 543ba2c..2c18c12 100644 --- a/omega-web/src/popup.jade +++ b/omega-web/src/popup.jade @@ -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 = ' '