Bug 634883 - Hide Share/Open in context menu for non-shareable/openable links [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 28 Feb 2011 14:46:40 -0800
changeset 67440 249f4e8fa68980bf89e8f60280a7d6172b5bdcbe
parent 67439 ab3c98ecbb826158cd1922c9609c1506222da3da
child 67441 2c75546245e03de23b8bce8a538c5a69a120feda
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs634883
Bug 634883 - Hide Share/Open in context menu for non-shareable/openable links [r=mfinkle]
mobile/chrome/content/Util.js
mobile/chrome/content/bindings.xml
mobile/chrome/content/content.js
--- a/mobile/chrome/content/Util.js
+++ b/mobile/chrome/content/Util.js
@@ -106,16 +106,21 @@ let Util = {
     // Note:  makeURI() will throw if url is not a valid URI
     return this.makeURI(url, null, this.makeURI(base)).spec;
   },
 
   isLocalScheme: function isLocalScheme(aURL) {
     return (aURL.indexOf("about:") == 0 && aURL != "about:blank" && aURL != "about:empty") || aURL.indexOf("chrome:") == 0;
   },
 
+  isOpenableScheme: function isShareableScheme(aProtocol) {
+    let dontOpen = /^(mailto|javascript|news|snews)$/;
+    return (aProtocol && !dontOpen.test(aProtocol));
+  },
+
   isShareableScheme: function isShareableScheme(aProtocol) {
     let dontShare = /^(chrome|about|file|javascript|resource)$/;
     return (aProtocol && !dontShare.test(aProtocol));
   },
 
   clamp: function(num, min, max) {
     return Math.max(min, Math.min(max, num));
   },
--- a/mobile/chrome/content/bindings.xml
+++ b/mobile/chrome/content/bindings.xml
@@ -133,21 +133,30 @@
   <binding id="popup_autocomplete_result">
     <handlers>
       <handler event="contextmenu" phase="capturing">
         <![CDATA[
           let url = this.getAttribute("url");
           if (!url)
             return;
 
+          let types = [];
+          try { // In case makeURI fails.
+            let uri = Util.makeURI(url);
+            if (Util.isOpenableScheme(uri.scheme))
+              types.push("link-openable");
+            if (Util.isShareableScheme(uri.scheme))
+              types.push("link-shareable");
+          } catch (ex) { Util.dumpLn(ex); }
+
           let value = this.getAttribute("value");
           let data = {
             target: this,
             json: {
-              types: ["link-shareable", "link-openable"],
+              types: types,
               label: value,
               linkTitle: value,
               linkURL: url
             }
           };
           ContextHelper.showPopup(data);
         ]]>
       </handler>
@@ -592,20 +601,28 @@
             this.control._fireOpen(event, this);
         ]]>
       </handler>
       <handler event="contextmenu" phase="capturing">
         <![CDATA[
           if (!this.uri || this._isEditing)
             return;
 
+          let types = ["edit-bookmark"];
+          try { // In case makeURI fails.
+            if (Util.isOpenableScheme(this.uri.scheme))
+              types.push("link-openable");
+            if (Util.isShareableScheme(this.uri.scheme))
+              types.push("link-shareable");
+          } catch (ex) { Util.dumpLn(ex); }
+
           let data = {
             target: this,
             json: {
-              types: ["edit-bookmark", "link-shareable", "link-openable"],
+              types: types,
               label: this.name,
               linkTitle: this.name,
               linkURL: this.spec
            }};
            ContextHelper.showPopup(data);
          ]]>
        </handler>
      </handlers>
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -911,18 +911,17 @@ ContextHandler.registerType("callto", fu
 });
 
 ContextHandler.registerType("link-saveable", function(aState, aElement) {
   let protocol = aState.linkProtocol;
   return (protocol && protocol != "mailto" && protocol != "javascript" && protocol != "news" && protocol != "snews");
 });
 
 ContextHandler.registerType("link-openable", function(aState, aElement) {
-  let protocol = aState.linkProtocol;
-  return (protocol && protocol != "mailto" && protocol != "javascript" && protocol != "news" && protocol != "snews");
+  return Util.isOpenableScheme(aState.linkProtocol);
 });
 
 ContextHandler.registerType("link-shareable", function(aState, aElement) {
   return Util.isShareableScheme(aState.linkProtocol);
 });
 
 ContextHandler.registerType("input-text", function(aState, aElement) {
     return aElement instanceof Ci.nsIDOMHTMLInputElement;