Bug 1255824 - fix hidden state on startup when pocket button not available, r=gijs, a=lizzard
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 14 Mar 2016 10:36:52 -0700
changeset 351222 025c8013b0623b9d176372cf2e90e1f3a8288cdd
parent 351221 888d64f75c9d12755d9ab85dcaf61bdad454ce54
child 351223 854a8a7e9606c5e5dc0eaa6a67cd52b19d58f51f
push id15502
push userahunt@mozilla.com
push dateThu, 14 Apr 2016 20:27:48 +0000
reviewersgijs, lizzard
bugs1255824
milestone47.0a2
Bug 1255824 - fix hidden state on startup when pocket button not available, r=gijs, a=lizzard
browser/extensions/pocket/bootstrap.js
--- a/browser/extensions/pocket/bootstrap.js
+++ b/browser/extensions/pocket/bootstrap.js
@@ -318,16 +318,18 @@ var PocketReader = {
                                  title: gPocketBundle.GetStringFromName("pocket-button.tooltiptext"),
                                  image: "chrome://pocket/content/panels/img/pocket.svg#pocket-mark" });
     }
   },
   receiveMessage: function(message) {
     switch (message.name) {
       case "Reader:OnSetup": {
         // Tell the reader about our button.
+        if (this.hidden)
+          break;
         message.target.messageManager.
           sendAsyncMessage("Reader:AddButton", { id: "pocket-button",
                                                  title: gPocketBundle.GetStringFromName("pocket-button.tooltiptext"),
                                                  image: "chrome://pocket/content/panels/img/pocket.svg#pocket-mark"});
         break;
       }
       case "Reader:Clicked-pocket-button": {
         let doc = message.target.ownerDocument;
@@ -421,60 +423,67 @@ var PocketOverlay = {
     // on window, and so the defineProperty inside defineLazyGetter fails.
     Object.defineProperty(window, "pktUI", pktUIGetter("pktUI", window));
     Object.defineProperty(window, "pktUIMessaging", pktUIGetter("pktUIMessaging", window));
   },
   // called for each window as it is opened
   updateWindow: function(window) {
     // insert our three menu items
     let document = window.document;
+    let hidden = !CustomizableUI.getPlacementOfWidget("pocket-button");
 
     // add to bookmarksMenu
     let sib = document.getElementById("menu_bookmarkThisPage");
     if (sib && !document.getElementById("menu_pocket")) {
       let menu = createElementWithAttrs(document, "menuitem", {
         "id": "menu_pocket",
         "label": gPocketBundle.GetStringFromName("pocketMenuitem.label"),
         "class": "menuitem-iconic", // OSX only
-        "oncommand": "openUILink(Pocket.listURL, event);"
+        "oncommand": "openUILink(Pocket.listURL, event);",
+        "hidden": hidden
       });
       let sep = createElementWithAttrs(document, "menuseparator", {
-        "id": "menu_pocketSeparator"
+        "id": "menu_pocketSeparator",
+        "hidden": hidden
       });
       sib.parentNode.insertBefore(menu, sib);
       sib.parentNode.insertBefore(sep, sib);
     }
 
     // add to bookmarks-menu-button
     sib = document.getElementById("BMB_bookmarksToolbar");
     if (sib && !document.getElementById("BMB_pocket")) {
       let menu = createElementWithAttrs(document, "menuitem", {
         "id": "BMB_pocket",
         "label": gPocketBundle.GetStringFromName("pocketMenuitem.label"),
         "class": "menuitem-iconic bookmark-item subviewbutton",
-        "oncommand": "openUILink(Pocket.listURL, event);"
+        "oncommand": "openUILink(Pocket.listURL, event);",
+        "hidden": hidden
       });
       let sep = createElementWithAttrs(document, "menuseparator", {
-        "id": "BMB_pocketSeparator"
+        "id": "BMB_pocketSeparator",
+        "hidden": hidden
       });
       sib.parentNode.insertBefore(menu, sib);
       sib.parentNode.insertBefore(sep, sib);
     }
 
     // add to PanelUI-bookmarks
     sib = document.getElementById("panelMenuBookmarkThisPage");
     if (sib && !document.getElementById("panelMenu_pocket")) {
       let menu = createElementWithAttrs(document, "toolbarbutton", {
         "id": "panelMenu_pocket",
         "label": gPocketBundle.GetStringFromName("pocketMenuitem.label"),
         "class": "subviewbutton cui-withicon",
-        "oncommand": "openUILink(Pocket.listURL, event);"
+        "oncommand": "openUILink(Pocket.listURL, event);",
+        "hidden": hidden
       });
       let sep = createElementWithAttrs(document, "toolbarseparator", {
-        "id": "panelMenu_pocketSeparator"
+        "id": "panelMenu_pocketSeparator",
+        "hidden": hidden
       });
       // nextSibling is no-id toolbarseparator
       // insert separator first then button
       sib = sib.nextSibling;
       sib.parentNode.insertBefore(sep, sib);
       sib.parentNode.insertBefore(menu, sib);
     }
   },