Bug 782850 fix nsContextMenu to work in social content panels, r=felipe
☠☠ backed out by 177ddb6900f4 ☠ ☠
authorShane Caraveo <scaraveo@mozilla.com>
Sat, 26 Jan 2013 16:48:54 -0800
changeset 119995 e9795d97ccf6e2d845ce90cfb06f09bf8dbc86f6
parent 119994 3bc89c4fedd7a2fda43f2ade2f97edebadeacfed
child 119996 177ddb6900f465cf844bc1124c9b63dccb663ec5
push id21984
push usermixedpuppy@gmail.com
push dateSun, 27 Jan 2013 01:03:12 +0000
treeherdermozilla-inbound@e9795d97ccf6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs782850
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 782850 fix nsContextMenu to work in social content panels, r=felipe
browser/base/content/browser-context.inc
browser/base/content/browser.xul
browser/base/content/nsContextMenu.js
browser/base/content/socialchat.xml
browser/base/content/test/browser_bug417483.js
browser/base/content/test/browser_bug423833.js
browser/base/content/test/browser_bug424101.js
browser/base/content/test/browser_bug734076.js
browser/base/content/test/browser_plainTextLinks.js
browser/base/content/web-panels.xul
browser/devtools/inspector/test/browser_inspector_initialization.js
--- a/browser/base/content/browser-context.inc
+++ b/browser/base/content/browser-context.inc
@@ -179,17 +179,17 @@
       <menuitem id="context-forward"
                 label="&forwardCmd.label;"
                 accesskey="&forwardCmd.accesskey;"
                 command="Browser:ForwardOrForwardDuplicate"
                 onclick="checkForMiddleClick(this, event);"/>
       <menuitem id="context-reload"
                 label="&reloadCmd.label;"
                 accesskey="&reloadCmd.accesskey;"
-                command="Browser:ReloadOrDuplicate"
+                oncommand="gContextMenu.reload(event);"
                 onclick="checkForMiddleClick(this, event);"/>
       <menuitem id="context-stop"
                 label="&stopCmd.label;"
                 accesskey="&stopCmd.accesskey;"
                 command="Browser:Stop"/>
       <menuseparator id="context-sep-stop"/>
       <menuitem id="context-bookmarkpage"
                 label="&bookmarkPageCmd2.label;"
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -1102,16 +1102,17 @@
               class="chromeclass-extrachrome sidebar-splitter"
               observes="socialSidebarBroadcaster"/>
     <vbox id="social-sidebar-box"
           class="chromeclass-extrachrome"
           observes="socialSidebarBroadcaster"
           persist="width">
       <browser id="social-sidebar-browser"
                type="content"
+               context="contentAreaContextMenu"
                disableglobalhistory="true"
                flex="1"
                style="min-width: 14em; width: 18em; max-width: 36em;"/>
     </vbox>
     <vbox id="browser-border-end" hidden="true" layer="true"/>
   </hbox>
 
   <hbox id="full-screen-warning-container" hidden="true" fadeout="true">
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1,30 +1,28 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
 
-function nsContextMenu(aXulMenu, aBrowser, aIsShift) {
+function nsContextMenu(aXulMenu, aIsShift) {
   this.shouldDisplay = true;
-  this.initMenu(aBrowser, aXulMenu, aIsShift);
+  this.initMenu(aXulMenu, aIsShift);
 }
 
 // Prototype for nsContextMenu "class."
 nsContextMenu.prototype = {
-  initMenu: function CM_initMenu(aBrowser, aXulMenu, aIsShift) {
+  initMenu: function CM_initMenu(aXulMenu, aIsShift) {
     // Get contextual info.
     this.setTarget(document.popupNode, document.popupRangeParent,
                    document.popupRangeOffset);
     if (!this.shouldDisplay)
       return;
 
-    this.browser = aBrowser;
-
     this.hasPageMenu = false;
     if (!aIsShift) {
       this.hasPageMenu = PageMenu.maybeBuildAndAttachMenu(this.target,
                                                           aXulMenu);
     }
 
     this.isFrameImage = document.getElementById("isFrameImage");
     this.ellipsis = "\u2026";
@@ -149,23 +147,30 @@ nsContextMenu.prototype = {
     this.showItem("context-openlinkintab", shouldShow);
     this.showItem("context-openlinkincurrent", this.onPlainTextLink);
     this.showItem("context-sep-open", shouldShow);
   },
 
   initNavigationItems: function CM_initNavigationItems() {
     var shouldShow = !(this.isContentSelected || this.onLink || this.onImage ||
                        this.onCanvas || this.onVideo || this.onAudio ||
-                       this.onTextInput);
+                       this.onTextInput || this.onSocial);
     this.showItem("context-back", shouldShow);
     this.showItem("context-forward", shouldShow);
-    var shouldShowReload = XULBrowserWindow.stopCommand.getAttribute("disabled") == "true";
-    this.showItem("context-reload", shouldShow && shouldShowReload);
-    this.showItem("context-stop", shouldShow && !shouldShowReload);
-    this.showItem("context-sep-stop", shouldShow);
+
+    let stopped = XULBrowserWindow.stopCommand.getAttribute("disabled") == "true";
+
+    let stopReloadItem = "";
+    if (shouldShow || this.onSocial) {
+      stopReloadItem = (stopped || this.onSocial) ? "reload" : "stop";
+    }
+
+    this.showItem("context-reload", stopReloadItem == "reload");
+    this.showItem("context-stop", stopReloadItem == "stop");
+    this.showItem("context-sep-stop", !!stopReloadItem);
 
     // XXX: Stop is determined in browser.js; the canStop broadcaster is broken
     //this.setItemAttrFromNode( "context-stop", "disabled", "canStop" );
   },
 
   initLeaveDOMFullScreenItems: function CM_initLeaveFullScreenItem() {
     // only show the option if the user is in DOM fullscreen
     var shouldShow = (this.target.ownerDocument.mozFullScreenElement != null);
@@ -206,17 +211,17 @@ nsContextMenu.prototype = {
                   this.isContentSelected);
     this.showItem("context-viewpartialsource-mathml",
                   this.onMathML && !this.isContentSelected);
 
     var shouldShow = !(this.isContentSelected ||
                        this.onImage || this.onCanvas ||
                        this.onVideo || this.onAudio ||
                        this.onLink || this.onTextInput);
-    var showInspect = gPrefService.getBoolPref("devtools.inspector.enabled");
+    var showInspect = !this.onSocial && gPrefService.getBoolPref("devtools.inspector.enabled");
     this.showItem("context-viewsource", shouldShow);
     this.showItem("context-viewinfo", shouldShow);
     this.showItem("inspect-separator", showInspect);
     this.showItem("context-inspect", showInspect);
 
     this.showItem("context-sep-viewsource", shouldShow);
 
     // Set as Desktop background depends on whether an image was clicked on,
@@ -263,18 +268,19 @@ nsContextMenu.prototype = {
   },
 
   initMiscItems: function CM_initMiscItems() {
     var isTextSelected = this.isTextSelected;
 
     // Use "Bookmark This Link" if on a link.
     this.showItem("context-bookmarkpage",
                   !(this.isContentSelected || this.onTextInput || this.onLink ||
-                    this.onImage || this.onVideo || this.onAudio));
-    this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink) || this.onPlainTextLink);
+                    this.onImage || this.onVideo || this.onAudio || this.onSocial));
+    this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink &&
+                                           !this.onSocial) || this.onPlainTextLink);
     this.showItem("context-searchselect", isTextSelected);
     this.showItem("context-keywordfield",
                   this.onTextInput && this.onKeywordField);
     this.showItem("frame", this.inFrame);
     this.showItem("frame-sep", this.inFrame && isTextSelected);
 
     // Hide menu entries for images, show otherwise
     if (this.inFrame) {
@@ -469,16 +475,23 @@ nsContextMenu.prototype = {
     this.bgImageURL        = "";
     this.onEditableArea    = false;
     this.isDesignMode      = false;
     this.onCTPPlugin       = false;
 
     // Remember the node that was clicked.
     this.target = aNode;
 
+    this.browser = this.target.ownerDocument.defaultView
+                                .QueryInterface(Ci.nsIInterfaceRequestor)
+                                .getInterface(Ci.nsIWebNavigation)
+                                .QueryInterface(Ci.nsIDocShell)
+                                .chromeEventHandler;
+    this.onSocial = !!this.browser.getAttribute("origin");
+
     // Check if we are in a synthetic document (stand alone image, video, etc.).
     this.inSyntheticDoc =  this.target.ownerDocument.mozSyntheticDocument;
     // First, do checks for nodes that never have children.
     if (this.target.nodeType == Node.ELEMENT_NODE) {
       // See if the user clicked on an image.
       if (this.target instanceof Ci.nsIImageLoadingContent &&
           this.target.currentURI) {
         this.onImage = true;
@@ -758,16 +771,28 @@ nsContextMenu.prototype = {
 
     urlSecurityCheck(frameURL, this.browser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
     var referrer = doc.referrer;
     openUILinkIn(frameURL, "current", { disallowInheritPrincipal: true,
                                         referrerURI: referrer ? makeURI(referrer) : null });
   },
 
+  reload: function(event) {
+    if (this.onSocial) {
+      // full reload of social provider
+      Social.enabled = false;
+      Services.tm.mainThread.dispatch(function() {
+        Social.enabled = true;
+      }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+    } else {
+      BrowserReloadOrDuplicate(event);
+    }
+  },
+
   // View Partial Source
   viewPartialSource: function(aContext) {
     var focusedWindow = document.commandDispatcher.focusedWindow;
     if (focusedWindow == window)
       focusedWindow = content;
 
     var docCharset = null;
     if (focusedWindow)
--- a/browser/base/content/socialchat.xml
+++ b/browser/base/content/socialchat.xml
@@ -10,16 +10,17 @@
       <xul:hbox class="chat-titlebar" xbl:inherits="minimized,selected,activity"
                 onclick="document.getBindingParent(this).onTitlebarClick(event);" align="baseline">
         <xul:image class="chat-status-icon" xbl:inherits="src=image"/>
         <xul:label class="chat-title" flex="1" xbl:inherits="value=label" crop="center"/>
         <xul:toolbarbutton class="chat-close-button chat-toolbarbutton"
                            oncommand="document.getBindingParent(this).close();"/>
       </xul:hbox>
       <xul:iframe anonid="iframe" class="chat-frame" flex="1"
+                  context="contentAreaContextMenu"
                   xbl:inherits="src,origin,collapsed=minimized" type="content"/>
     </content>
 
     <implementation implements="nsIDOMEventListener">
       <field name="iframe" readonly="true">
         document.getAnonymousElementByAttribute(this, "anonid", "iframe");
       </field>
 
--- a/browser/base/content/test/browser_bug417483.js
+++ b/browser/base/content/test/browser_bug417483.js
@@ -14,13 +14,13 @@ function onPageShow() {
     var tn = frame.document.body.childNodes[0];
     range.setStart(tn , 4);
     range.setEnd(tn , 5);
     sel.addRange(range);
     frame.focus();
     
     document.popupNode = frame.document.body;
     var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-    var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+    var contextMenu = new nsContextMenu(contentAreaContextMenu);
 
     ok(document.getElementById("frame-sep").hidden, "'frame-sep' should be hidden if the selection contains only spaces");
     finish();
 }
--- a/browser/base/content/test/browser_bug423833.js
+++ b/browser/base/content/test/browser_bug423833.js
@@ -27,17 +27,17 @@ function test1Setup() {
     return;
 
   gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true);
 
   var badFrame = content.frames[1];
   document.popupNode = badFrame.document.firstChild;
 
   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  var contextMenu = new nsContextMenu(contentAreaContextMenu);
 
   // We'd like to use another load listener here, but error pages don't fire load events
   contextMenu.showOnlyThisFrame();
   intervalID = setInterval(testShowOnlyThisFrame, 3000);
 }
 
 function testShowOnlyThisFrame() {
   if (content.location.href == testPage)
@@ -64,17 +64,17 @@ function test2Setup() {
   gBrowser.removeEventListener("load", test2Setup, true);
 
   // Now let's do the whole thing again, but this time for "Open frame in new tab"
   var badFrame = content.frames[1];
 
   document.popupNode = badFrame.document.firstChild;
 
   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  var contextMenu = new nsContextMenu(contentAreaContextMenu);
 
   gBrowser.tabContainer.addEventListener("TabOpen", function (event) {
     test2tab = event.target;
     gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false);
   }, false);
   contextMenu.openFrameInTab();
   ok(test2tab, "openFrameInTab() opened a tab");
 
@@ -100,17 +100,17 @@ function testOpenFrameInTab() {
 }
 
 function test3Setup() {
   // One more time, for "Open frame in new window"
   var badFrame = content.frames[1];
   document.popupNode = badFrame.document.firstChild;
 
   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  var contextMenu = new nsContextMenu(contentAreaContextMenu);
 
   Services.ww.registerNotification(function (aSubject, aTopic, aData) {
     if (aTopic == "domwindowopened")
       test3window = aSubject;
     Services.ww.unregisterNotification(arguments.callee);
   });
 
   contextMenu.openFrame();
--- a/browser/base/content/test/browser_bug424101.js
+++ b/browser/base/content/test/browser_bug424101.js
@@ -11,27 +11,27 @@ function test() {
     let doc = gBrowser.contentDocument;
     let testInput = function(type, expected) {
       let element = doc.createElement("input");
       element.setAttribute("type", type);
       doc.body.appendChild(element);
       document.popupNode = element;
 
       let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-      let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+      let contextMenu = new nsContextMenu(contentAreaContextMenu);
 
       is(contextMenu.shouldDisplay, expected, "context menu behavior for <input type=" + type + "> is wrong");
     };
     let testElement = function(tag, expected) {
       let element = doc.createElement(tag);
       doc.body.appendChild(element);
       document.popupNode = element;
 
       let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-      let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+      let contextMenu = new nsContextMenu(contentAreaContextMenu);
 
       is(contextMenu.shouldDisplay, expected, "context menu behavior for <" + tag + "> is wrong");
     };
 
     testInput("text", true);
     testInput("password", true);
     testInput("image", true);
     testInput("button", true);
--- a/browser/base/content/test/browser_bug734076.js
+++ b/browser/base/content/test/browser_bug734076.js
@@ -97,11 +97,11 @@ function test() {
   }
 
   doNext();
 }
 
 function initContextMenu(aNode) {
   document.popupNode = aNode;
   let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  let contextMenu = new nsContextMenu(contentAreaContextMenu);
   return contextMenu;
 }
--- a/browser/base/content/test/browser_plainTextLinks.js
+++ b/browser/base/content/test/browser_plainTextLinks.js
@@ -9,17 +9,17 @@ function setSelection(el1, el2, index1, 
   range.setStart(el1, index1);
   range.setEnd(el2, index2);
   selection.addRange(range);
 }
 
 function initContextMenu(aNode) {
   document.popupNode = aNode;
   let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  let contextMenu = new nsContextMenu(contentAreaContextMenu);
   return contextMenu;
 }
 
 function testExpected(expected, msg, aNode) {
   let popupNode = aNode || doc.getElementsByTagName("DIV")[0];
   initContextMenu(popupNode);
   let linkMenuItem = document.getElementById("context-openlinkincurrent");
   is(linkMenuItem.hidden, expected, msg);
--- a/browser/base/content/web-panels.xul
+++ b/browser/base/content/web-panels.xul
@@ -45,17 +45,17 @@
     <command id="Browser:Reload" oncommand="PanelBrowserReload();"/>
   </commandset>
 
   <popupset id="mainPopupSet">
     <tooltip id="aHTMLTooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
     <menupopup id="contentAreaContextMenu" pagemenu="start"
                onpopupshowing="if (event.target != this)
                                  return true;
-                               gContextMenu = new nsContextMenu(this, getPanelBrowser(), event.shiftKey);
+                               gContextMenu = new nsContextMenu(this, event.shiftKey);
                                if (gContextMenu.shouldDisplay)
                                  document.popupNode = this.triggerNode;
                                return gContextMenu.shouldDisplay;"
                onpopuphiding="if (event.target != this)
                                 return;
                               gContextMenu.hiding();
                               gContextMenu = null;">
 #include browser-context.inc
--- a/browser/devtools/inspector/test/browser_inspector_initialization.js
+++ b/browser/devtools/inspector/test/browser_inspector_initialization.js
@@ -87,17 +87,17 @@ function testBreadcrumbs(node)
   let button = b.container.querySelector("button[checked=true]");
   ok(button, "A crumbs is checked=true");
   is(button.getAttribute("tooltiptext"), expectedText, "Crumb refers to the right node");
 }
 
 function _clickOnInspectMenuItem(node) {
   document.popupNode = node;
   var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
-  var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
+  var contextMenu = new nsContextMenu(contentAreaContextMenu);
   return contextMenu.inspectNode();
 }
 
 function runContextMenuTest()
 {
   salutation = doc.getElementById("salutation");
   _clickOnInspectMenuItem(salutation).then(testInitialNodeIsSelected);
 }
@@ -137,9 +137,8 @@ function test()
   gBrowser.selectedBrowser.addEventListener("load", function() {
     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
     doc = content.document;
     waitForFocus(createDocument, content);
   }, true);
 
   content.location = "data:text/html,basic tests for inspector";
 }
-