Bug 1181437 - Disable AddBookmarkAs command on non-bookmarkable pages draft
authorMatt Brubeck <mbrubeck@mozilla.com>
Mon, 25 Apr 2016 13:59:00 -0700
changeset 356160 e1b8947e2d3baed24302a9f881f1f78f4300d3d9
parent 355956 1c6385ae1fe7e37d8f23f958ce14582f07af729e
child 519356 2f6f4c31e55d36b869ed15830cd4c3f55724242c
push id16462
push usermbrubeck@mozilla.com
push dateMon, 25 Apr 2016 21:23:12 +0000
bugs1181437
milestone48.0a1
Bug 1181437 - Disable AddBookmarkAs command on non-bookmarkable pages MozReview-Commit-ID: K1GRFJ0Ikvf
browser/base/content/browser-places.js
browser/base/content/browser-sets.inc
browser/base/content/nsContextMenu.js
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -1408,29 +1408,34 @@ var BookmarkingUI = {
     root.containerOpen = false;
     aHeaderItem.parentNode.insertBefore(fragment, aHeaderItem.nextSibling);
   },
 
   /**
    * Handles star styling based on page proxy state changes.
    */
   onPageProxyStateChanged: function BUI_onPageProxyStateChanged(aState) {
+    let disabled = aState == "invalid";
+    if (disabled) {
+      this.broadcaster.setAttribute("disabled", "true");
+    } else {
+      this.broadcaster.removeAttribute("disabled");
+    }
+
     if (!this._shouldUpdateStarState() || !this.star) {
       return;
     }
 
-    if (aState == "invalid") {
+    if (disabled) {
       this.star.setAttribute("disabled", "true");
-      this.broadcaster.setAttribute("stardisabled", "true");
       this.broadcaster.removeAttribute("starred");
       this.broadcaster.setAttribute("buttontooltiptext", "");
     }
     else {
       this.star.removeAttribute("disabled");
-      this.broadcaster.removeAttribute("stardisabled");
       this._updateStar();
     }
   },
 
   _updateCustomizationState: function BUI__updateCustomizationState() {
     let placement = CustomizableUI.getPlacementOfWidget(this.BOOKMARK_BUTTON_ID);
     this._currentAreaType = placement && CustomizableUI.getAreaType(placement.area);
   },
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -52,17 +52,19 @@
     <command id="cmd_findPrevious"
              oncommand="gFindBar.onFindAgainCommand(true);"
              observes="isImage"/>
 #ifdef XP_MACOSX
     <command id="cmd_findSelection" oncommand="gFindBar.onFindSelectionCommand();"/>
 #endif
     <!-- work-around bug 392512 -->
     <command id="Browser:AddBookmarkAs"
-             oncommand="PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksMenuFolderId);"/>
+             oncommand="PlacesCommandHook.bookmarkCurrentPage(true, PlacesUtils.bookmarksMenuFolderId);">
+      <observes element="bookmarkThisPageBroadcaster" attribute="disabled"/>
+    </command>
     <!-- The command disabled state must be manually updated through
          PlacesCommandHook.updateBookmarkAllTabsCommand() -->
     <command id="Browser:BookmarkAllTabs"
              oncommand="PlacesCommandHook.bookmarkCurrentPages();"/>
     <command id="Browser:Home"    oncommand="BrowserHome();"/>
     <command id="Browser:Back"    oncommand="BrowserBack();" disabled="true"/>
     <command id="Browser:BackOrBackDuplicate" oncommand="BrowserBack(event);" disabled="true">
       <observes element="Browser:Back" attribute="disabled"/>
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -286,17 +286,16 @@ nsContextMenu.prototype = {
   initMiscItems: function CM_initMiscItems() {
     // Use "Bookmark This Link" if on a link.
     let bookmarkPage = document.getElementById("context-bookmarkpage");
     this.showItem(bookmarkPage,
                   !(this.isContentSelected || this.onTextInput || this.onLink ||
                     this.onImage || this.onVideo || this.onAudio || this.onSocial ||
                     this.onCanvas));
     bookmarkPage.setAttribute("tooltiptext", bookmarkPage.getAttribute("buttontooltiptext"));
-    bookmarkPage.disabled = bookmarkPage.hasAttribute("stardisabled");
 
     this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink &&
                                            !this.onSocial) || this.onPlainTextLink);
     this.showItem("context-keywordfield",
                   this.onTextInput && this.onKeywordField);
     this.showItem("frame", this.inFrame);
 
     let showSearchSelect = (this.isTextSelected || this.onLink) && !this.onImage;