Bug 912347 - Prevent already registered protocol handler info bar. r=jaws
authorDoug Turner <doug.turner@gmail.com>
Thu, 12 Sep 2013 10:41:08 +0200
changeset 159606 a4e9c9c9dbf94494b508ca9108f30f1941a70d4a
parent 159605 a98569f21abe10fc486631e4ad40e20999ea5d25
child 159676 b83f6d80af5fe8fef0a7718eae9741153d4dbfe0
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs912347
milestone26.0a1
first release with
nightly linux32
a4e9c9c9dbf9 / 26.0a1 / 20130912030201 / files
nightly linux64
a4e9c9c9dbf9 / 26.0a1 / 20130912030201 / files
nightly mac
a4e9c9c9dbf9 / 26.0a1 / 20130912030201 / files
nightly win32
a4e9c9c9dbf9 / 26.0a1 / 20130912030201 / files
nightly win64
a4e9c9c9dbf9 / 26.0a1 / 20130912030201 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 912347 - Prevent already registered protocol handler info bar. r=jaws
browser/components/feeds/src/WebContentConverter.js
browser/locales/en-US/chrome/browser/feeds/subscribe.properties
--- a/browser/components/feeds/src/WebContentConverter.js
+++ b/browser/components/feeds/src/WebContentConverter.js
@@ -364,16 +364,23 @@ WebContentConverterRegistrar.prototype =
 
   /**
    * See nsIWebContentHandlerRegistrar
    */
   registerProtocolHandler: 
   function WCCR_registerProtocolHandler(aProtocol, aURIString, aTitle, aContentWindow) {
     LOG("registerProtocolHandler(" + aProtocol + "," + aURIString + "," + aTitle + ")");
 
+    var uri = this._checkAndGetURI(aURIString, aContentWindow);
+
+    // If the protocol handler is already registered, just return early.
+    if (this._protocolHandlerRegistered(aProtocol, uri.spec)) {
+      return;
+    }
+
     var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow);    
     if (PrivateBrowsingUtils.isWindowPrivate(browserWindow)) {
       // Inside the private browsing mode, we don't want to alert the user to save
       // a protocol handler.  We log it to the error console so that web developers
       // would have some way to tell what's going wrong.
       Cc["@mozilla.org/consoleservice;1"].
       getService(Ci.nsIConsoleService).
       logStringMessage("Web page denied access to register a protocol handler inside private browsing mode");
@@ -401,35 +408,28 @@ WebContentConverterRegistrar.prototype =
     catch (e) {
       allowed = pb.getBoolPref(PREF_HANDLER_EXTERNAL_PREFIX + "-default");
     }
     if (!allowed) {
       // XXX this should be a "security exception" according to spec
       throw("Not allowed to register a protocol handler for " + aProtocol);
     }
 
-    var uri = this._checkAndGetURI(aURIString, aContentWindow);
+    // Now Ask the user and provide the proper callback
+    var message = this._getFormattedString("addProtocolHandler",
+                                           [aTitle, uri.host, aProtocol]);
 
-    var buttons, message;
-    if (this._protocolHandlerRegistered(aProtocol, uri.spec))
-      message = this._getFormattedString("protocolHandlerRegistered",
-                                         [aTitle, aProtocol]);
-    else {
-      // Now Ask the user and provide the proper callback
-      message = this._getFormattedString("addProtocolHandler",
-                                         [aTitle, uri.host, aProtocol]);
+    var notificationIcon = uri.prePath + "/favicon.ico";
+    var notificationValue = "Protocol Registration: " + aProtocol;
+    var addButton = {
+      label: this._getString("addProtocolHandlerAddButton"),
+      accessKey: this._getString("addHandlerAddButtonAccesskey"),
+      protocolInfo: { protocol: aProtocol, uri: uri.spec, name: aTitle },
 
-      var notificationIcon = uri.prePath + "/favicon.ico";
-      var notificationValue = "Protocol Registration: " + aProtocol;
-      var addButton = {
-        label: this._getString("addProtocolHandlerAddButton"),
-        accessKey: this._getString("addHandlerAddButtonAccesskey"),
-        protocolInfo: { protocol: aProtocol, uri: uri.spec, name: aTitle },
-
-        callback:
+      callback:
         function WCCR_addProtocolHandlerButtonCallback(aNotification, aButtonInfo) {
           var protocol = aButtonInfo.protocolInfo.protocol;
           var uri      = aButtonInfo.protocolInfo.uri;
           var name     = aButtonInfo.protocolInfo.name;
 
           var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
                         createInstance(Ci.nsIWebHandlerApp);
           handler.name = name;
@@ -445,21 +445,18 @@ WebContentConverterRegistrar.prototype =
           // to want to use it.  Reset the handlerInfo to ask before the next
           // use.
           handlerInfo.alwaysAskBeforeHandling = true;
 
           var hs = Cc["@mozilla.org/uriloader/handler-service;1"].
                    getService(Ci.nsIHandlerService);
           hs.store(handlerInfo);
         }
-      };
-      buttons = [addButton];
-    }
-
-
+    };
+    var buttons;
     var browserElement = this._getBrowserForContentWindow(browserWindow, aContentWindow);
     var notificationBox = browserWindow.getBrowser().getNotificationBox(browserElement);
     notificationBox.appendNotification(message,
                                        notificationValue,
                                        notificationIcon,
                                        notificationBox.PRIORITY_INFO_LOW,
                                        buttons);
   },
--- a/browser/locales/en-US/chrome/browser/feeds/subscribe.properties
+++ b/browser/locales/en-US/chrome/browser/feeds/subscribe.properties
@@ -44,10 +44,8 @@ feedSubscriptionVideoPodcast1=This is a 
 feedSubscriptionFeed2=You can subscribe to this feed to receive updates when this content changes.
 feedSubscriptionAudioPodcast2=You can subscribe to this podcast to receive updates when this content changes.
 feedSubscriptionVideoPodcast2=You can subscribe to this video podcast to receive updates when this content changes.
 
 # Protocol Handling
 # "Add %appName (%appDomain) as an application for %protocolType links?"
 addProtocolHandler=Add %S (%S) as an application for %S links?
 addProtocolHandlerAddButton=Add Application
-# "%appName has already been added as an application for %protocolType links."
-protocolHandlerRegistered=%S has already been added as an application for %S links.