Bug 959108 - Update helper apps page actions URL on location change. r=wesj
authorEugen Sawin <esawin@mozilla.com>
Wed, 26 Feb 2014 22:38:09 +0100
changeset 171788 e3ce8fb65c5fc75e27fada38427632529f42bf05
parent 171787 ebcbf7155214548727b891a432671666d02b6344
child 171789 0bffec16177c6e3b00db97e2cc4ac62cdb6a0d34
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerswesj
bugs959108
milestone30.0a1
Bug 959108 - Update helper apps page actions URL on location change. r=wesj
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3925,16 +3925,21 @@ Tab.prototype = {
         if (!domain.endsWith(baseDomain)) {
           // getBaseDomainFromHost converts its resultant to ACE.
           let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
           baseDomain = IDNService.convertACEtoUTF8(baseDomain);
         }
       } catch (e) {}
     }
 
+    // Update the page actions URI for helper apps.
+    if (BrowserApp.selectedTab == this) {
+      ExternalApps.updatePageActionUri(fixedURI);
+    }
+
     let message = {
       type: "Content:LocationChange",
       tabID: this.id,
       uri: fixedURI.spec,
       userSearch: this.userSearch || "",
       baseDomain: baseDomain,
       contentType: (contentType ? contentType : ""),
       sameDocument: sameDocument
@@ -7846,17 +7851,17 @@ let Reader = {
       cacheDB.createObjectStore("articles", { keyPath: "url" });
 
       this.log("Database upgrade done: " + this.DB_VERSION);
     }.bind(this);
   }
 };
 
 var ExternalApps = {
-  _contextMenuId: -1,
+  _contextMenuId: null,
 
   // extend _getLink to pickup html5 media links.
   _getMediaLink: function(aElement) {
     let uri = NativeWindow.contextmenus._getLink(aElement);
     if (uri == null && aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE && (aElement instanceof Ci.nsIDOMHTMLMediaElement)) {
       try {
         let mediaSrc = aElement.currentSrc || aElement.src;
         uri = ContentAreaUtils.makeURI(mediaSrc, null, null);
@@ -7878,17 +7883,20 @@ var ExternalApps = {
         apps = HelperApps.getAppsForUri(uri);
 
       return apps.length == 1 ? Strings.browser.formatStringFromName("helperapps.openWithApp2", [apps[0].name], 1) :
                                 Strings.browser.GetStringFromName("helperapps.openWithList2");
     }, this.filter, this.openExternal);
   },
 
   uninit: function helper_uninit() {
-    NativeWindow.contextmenus.remove(this._contextMenuId);
+    if (this._contextMenuId !== null) {
+      NativeWindow.contextmenus.remove(this._contextMenuId);
+    }
+    this._contextMenuId = null;
   },
 
   filter: {
     matches: function(aElement) {
       let uri = ExternalApps._getMediaLink(aElement);
       let apps = [];
       if (uri) {
         apps = HelperApps.getAppsForUri(uri);
@@ -7914,49 +7922,50 @@ var ExternalApps = {
     HelperApps.getAppsForUri(uri, { filterHttp: true }, (apps) => {
       if (apps.length > 0)
         this._setUriForPageAction(uri, apps);
       else
         this._removePageAction();
     });
   },
 
+  updatePageActionUri: function updatePageActionUri(uri) {
+    this._pageActionUri = uri;
+  },
+
   _setUriForPageAction: function setUriForPageAction(uri, apps) {
-    this._pageActionUri = uri;
+    this.updatePageActionUri(uri);
 
     // If the pageaction is already added, simply update the URI to be launched when 'onclick' is triggered.
     if (this._pageActionId != undefined)
       return;
 
     this._pageActionId = NativeWindow.pageactions.add({
       title: Strings.browser.GetStringFromName("openInApp.pageAction"),
       icon: "drawable://icon_openinapp",
-      clickCallback: (function() {
-        let callback = function(app) {
-          app.launch(uri);
-        }
-
+
+      clickCallback: () => {
         if (apps.length > 1) {
           // Use the HelperApps prompt here to filter out any Http handlers
           HelperApps.prompt(apps, {
             title: Strings.browser.GetStringFromName("openInApp.pageAction"),
             buttons: [
               Strings.browser.GetStringFromName("openInApp.ok"),
               Strings.browser.GetStringFromName("openInApp.cancel")
             ]
           }, function(result) {
-            if (result.button != 0)
+            if (result.button != 0) {
               return;
-
-            callback(apps[result.icongrid0]);
+            }
+            apps[result.icongrid0].launch(this._pageActionUri);
           });
         } else {
-          callback(apps[0]);
+          apps[0].launch(this._pageActionUri);
         }
-      }).bind(this)
+      }
     });
   },
 
   _removePageAction: function removePageAction() {
     if(!this._pageActionId)
       return;
 
     NativeWindow.pageactions.remove(this._pageActionId);