Bug 482235 - instead of exposing bookmarklets attribute, expose scheme in uri nodes, r=mak77
authorPardal Freudenthal <pardal@gmx.de>
Thu, 12 Mar 2009 14:05:48 +0100
changeset 26095 297c00e7245b1eba41a68bdea35ca4c9760c59e1
parent 26094 6d2ef6b135fa996edca8d3c28d88579b97b6909b
child 26096 709e55b2747d2aa0c2272f1e08f54b4dddd9398c
push idunknown
push userunknown
push dateunknown
reviewersmak77
bugs482235
milestone1.9.2a1pre
Bug 482235 - instead of exposing bookmarklets attribute, expose scheme in uri nodes, r=mak77
browser/components/places/content/menu.xml
browser/components/places/content/toolbar.xml
browser/components/places/content/treeView.js
browser/components/places/content/utils.js
--- a/browser/components/places/content/menu.xml
+++ b/browser/components/places/content/menu.xml
@@ -816,20 +816,17 @@
           if (PlacesUtils.nodeIsLivemarkContainer(aNode)) {
             if (!menuitem.hasAttribute("livemark"))
               menuitem.setAttribute("livemark", "true");
             // If this is a livemark container check if the status menuitem has
             // to be added or removed.
             PlacesUIUtils.ensureLivemarkStatusMenuItem(menuitem.firstChild);
           }
           else if (PlacesUtils.nodeIsURI(aNode)) {
-            if (aNode.uri.lastIndexOf("javascript:", 0) == 0)
-              menuitem.setAttribute("bookmarklet", "true");
-            else
-              menuitem.removeAttribute("bookmarklet");
+              menuitem.setAttribute("scheme", PlacesUIUtils.guessUrlSchemeForUI(aNode.uri))
           }
         },
 
         itemReplaced:
         function PMV_itemReplaced(aParentNode, aOldNode, aNewNode, aIndex) {
           var popup = this._getPopupForContainer(aParentNode);
           if (!popup._built)
             return;
--- a/browser/components/places/content/toolbar.xml
+++ b/browser/components/places/content/toolbar.xml
@@ -215,20 +215,17 @@
               popup._resultNode = asContainer(aChild);
 #ifndef XP_MACOSX
               popup.setAttribute("context", "placesContext");
 #endif
               this._containerNodesMap.push({ resultNode: aChild,
                                              domNode: popup });
             }
             else if (PlacesUtils.nodeIsURI(aChild)) {
-              if (aChild.uri.lastIndexOf("javascript:", 0) == 0)
-                button.setAttribute("bookmarklet", "true");
-              else
-                button.removeAttribute("bookmarklet");
+              button.setAttribute("scheme", PlacesUIUtils.guessUrlSchemeForUI(aChild.uri))
             }
           }
 
           button.node = aChild;
           button.node.viewIndex = 0;
           if (aBefore)
             this.insertBefore(button, aBefore);
           else
@@ -640,20 +637,17 @@
           if (PlacesUtils.nodeIsLivemarkContainer(aNode)) {
             if (!element.hasAttribute("livemark"))
               element.setAttribute("livemark", "true");
             // If this is a livemark container check if the status menuitem has
             // to be added or removed.
             PlacesUIUtils.ensureLivemarkStatusMenuItem(element.firstChild);
           }
           else if (PlacesUtils.nodeIsURI(aNode)) {
-            if (aNode.uri.lastIndexOf("javascript:", 0) == 0)
-              element.setAttribute("bookmarklet", "true");
-            else
-              element.removeAttribute("bookmarklet");
+            element.setAttribute("scheme", PlacesUIUtils.guessUrlSchemeForUI(aNode.uri))
           }
         },
 
         itemReplaced:
         function TV_V_itemReplaced(aParentNode, aOldNode, aNewNode, aIndex) {
           if (aParentNode == this._self.getResultNode()) {
             var children = this._self.childNodes;
             for (var i = 0; i < children.length; i++) {
--- a/browser/components/places/content/treeView.js
+++ b/browser/components/places/content/treeView.js
@@ -920,22 +920,21 @@ PlacesTreeView.prototype = {
                                                    ORGANIZER_QUERY_ANNO);
             properties.push(this._getAtomFor("OrganizerQuery_" + oqAnno));
           }
           catch (ex) { /* not a special query */ }
         }
       }
       else if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR)
         properties.push(this._getAtomFor("separator"));
-      else if (itemId != -1) { // bookmark nodes
-        if (PlacesUtils.nodeIsLivemarkContainer(node.parent))
-          properties.push(this._getAtomFor("livemarkItem"));
-        else if (PlacesUtils.nodeIsURI(node)) {
-          if (node.uri.lastIndexOf("javascript:", 0) == 0)
-            properties.push(this._getAtomFor("bookmarklet"));
+      else if (PlacesUtils.nodeIsURI(node)) {
+        properties.push(this._getAtomFor(PlacesUIUtils.guessUrlSchemeForUI(node.uri)));
+        if (itemId != -1) {
+          if (PlacesUtils.nodeIsLivemarkContainer(node.parent))
+            properties.push(this._getAtomFor("livemarkItem"));
         }
       }
 
       this._visibleElements[aRow].properties = properties;
     }
     for (var i = 0; i < properties.length; i++)
       aProperties.AppendElement(properties[i]);
   },
--- a/browser/components/places/content/utils.js
+++ b/browser/components/places/content/utils.js
@@ -977,16 +977,30 @@ var PlacesUIUtils = {
           }
         }
       }
       openUILinkIn(aNode.uri, aWhere);
     }
   },
 
   /**
+   * Helper for guessing scheme from an url string.
+   * Used to avoid nsIURI overhead in frequently called UI functions.
+   *
+   * @param aUrlString the url to guess the scheme from.
+   * 
+   * @return guessed scheme for this url string.
+   *
+   * @note this is not supposed be perfect, so use it only for UI purposes.
+   */
+  guessUrlSchemeForUI: function PUU_guessUrlSchemeForUI(aUrlString) {
+    return aUrlString.substr(0, aUrlString.indexOf(":"));
+  },
+
+  /**
    * Helper for the toolbar and menu views
    */
   createMenuItemForNode:
   function PUU_createMenuItemForNode(aNode, aContainersMap) {
     var element;
     var type = aNode.type;
     if (type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR)
       element = document.createElement("menuseparator");
@@ -994,19 +1008,17 @@ var PlacesUIUtils = {
       var iconURI = aNode.icon;
       var iconURISpec = "";
       if (iconURI)
         iconURISpec = iconURI.spec;
 
       if (PlacesUtils.uriTypes.indexOf(type) != -1) {
         element = document.createElement("menuitem");
         element.className = "menuitem-iconic bookmark-item";
-
-        if (aNode.uri.lastIndexOf("javascript:", 0) == 0)
-          element.setAttribute("bookmarklet", "true");
+        element.setAttribute("scheme", this.guessUrlSchemeForUI(aNode.uri))
       }
       else if (PlacesUtils.containerTypes.indexOf(type) != -1) {
         element = document.createElement("menu");
         element.setAttribute("container", "true");
 
         if (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY) {
           element.setAttribute("query", "true");
           if (PlacesUtils.nodeIsTagQuery(aNode))