Browse Source

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.
FelisCatus 10 years ago
parent
commit
8f71270f1d

+ 9 - 1
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

+ 4 - 3
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])

+ 5 - 7
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

+ 1 - 1
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
           = ' '