Bug 1241892 - Make Page Info work for sidebar browser. r?florian
The modifications that were made in
bug 1238180 assumed that
gBrowser.selectedBrowser from the opening window context would
be defined. This is true in normal browser tabs, but not so much
in the sidebar browser. This patch makes it so that callers can
supply a browser to override the assumption.
MozReview-Commit-ID: FKSyl7WUu1V
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2317,25 +2317,26 @@ function BrowserViewSource(browser) {
URL: browser.currentURI.spec,
});
}
// documentURL - URL of the document to view, or null for this window's document
// initialTab - name of the initial tab to display, or null for the first tab
// imageElement - image to load in the Media Tab of the Page Info window; can be null/omitted
// frameOuterWindowID - the id of the frame that the context menu opened in; can be null/omitted
-function BrowserPageInfo(documentURL, initialTab, imageElement, frameOuterWindowID) {
+// browser - the browser containing the document we're interested in inspecting; can be null/omitted
+function BrowserPageInfo(documentURL, initialTab, imageElement, frameOuterWindowID, browser) {
if (documentURL instanceof HTMLDocument) {
Deprecated.warning("Please pass the location URL instead of the document " +
"to BrowserPageInfo() as the first argument.",
"https://bugzilla.mozilla.org/show_bug.cgi?id=1238180");
documentURL = documentURL.location;
}
- let args = { initialTab, imageElement, frameOuterWindowID };
+ let args = { initialTab, imageElement, frameOuterWindowID, browser };
var windows = Services.wm.getEnumerator("Browser:page-info");
documentURL = documentURL || window.gBrowser.selectedBrowser.currentURI.spec;
// Check for windows matching the url
while (windows.hasMoreElements()) {
var currentWindow = windows.getNext();
if (currentWindow.closed) {
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -1105,37 +1105,35 @@ nsContextMenu.prototype = {
BrowserViewSourceOfDocument({
browser: this.browser,
URL: gContextMenuContentData.docLocation,
outerWindowID: this.frameOuterWindowID,
});
},
viewInfo: function() {
- BrowserPageInfo();
+ BrowserPageInfo(gContextMenuContentData.docLocation, null, null, null, this.browser);
},
viewImageInfo: function() {
- // Don't need to pass in ownerDocument.defaultView.top.document here;
- // window.gBrowser.selectedBrowser.currentURI.spec does the job without
- // using CPOWs
- BrowserPageInfo(null, "mediaTab", this.target);
+ BrowserPageInfo(gContextMenuContentData.docLocation, "mediaTab",
+ this.target, null, this.browser);
},
viewImageDesc: function(e) {
urlSecurityCheck(this.imageDescURL,
this.browser.contentPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
openUILink(this.imageDescURL, e, { disallowInheritPrincipal: true,
referrerURI: gContextMenuContentData.documentURIObject });
},
viewFrameInfo: function() {
BrowserPageInfo(gContextMenuContentData.docLocation, null, null,
- this.frameOuterWindowID);
+ this.frameOuterWindowID, this.browser);
},
reloadImage: function() {
urlSecurityCheck(this.mediaURL,
this.browser.contentPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
this.browser.messageManager.sendAsyncMessage("ContextMenu:ReloadImage",
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -345,19 +345,20 @@ function onLoadPageInfo()
/* Select the requested tab, if the name is specified */
loadTab(args);
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService)
.notifyObservers(window, "page-info-dialog-loaded", null);
}
-function loadPageInfo(frameOuterWindowID, imageElement)
+function loadPageInfo(frameOuterWindowID, imageElement, browser)
{
- let mm = window.opener.gBrowser.selectedBrowser.messageManager;
+ browser = browser || window.opener.gBrowser.selectedBrowser;
+ let mm = browser.messageManager;
gStrings["application/rss+xml"] = gBundle.getString("feedRss");
gStrings["application/atom+xml"] = gBundle.getString("feedAtom");
gStrings["text/xml"] = gBundle.getString("feedXML");
gStrings["application/xml"] = gBundle.getString("feedXML");
gStrings["application/rdf+xml"] = gBundle.getString("feedXML");
// Look for pageInfoListener in content.js. Sends message to listener with arguments.
@@ -481,21 +482,21 @@ function showTab(id)
deck.selectedPanel = pagel;
}
function loadTab(args)
{
// If the "View Image Info" context menu item was used, the related image
// element is provided as an argument. This can't be a background image.
let imageElement = args && args.imageElement;
-
let frameOuterWindowID = args && args.frameOuterWindowID;
+ let browser = args && args.browser;
/* Load the page info */
- loadPageInfo(frameOuterWindowID, imageElement);
+ loadPageInfo(frameOuterWindowID, imageElement, browser);
var initialTab = (args && args.initialTab) || "generalTab";
var radioGroup = document.getElementById("viewGroup");
initialTab = document.getElementById(initialTab) || document.getElementById("generalTab");
radioGroup.selectedItem = initialTab;
radioGroup.selectedItem.doCommand();
radioGroup.focus();
}