Bug 1575830 - Update how Page / Frame / Image info works. r=frg
--- a/suite/base/content/nsContextMenu.js
+++ b/suite/base/content/nsContextMenu.js
@@ -1026,27 +1026,28 @@ nsContextMenu.prototype = {
gViewSourceUtils.viewSource({
browser: this.browser,
URL: gContextMenuContentData.docLocation,
outerWindowID: gContextMenuContentData.frameOuterWindowID,
});
},
viewInfo: function() {
- BrowserPageInfo();
+ BrowserPageInfo(gContextMenuContentData.docLocation, null,
+ null, null, this.browser);
},
viewImageInfo: function() {
- BrowserPageInfo(this.target.ownerDocument.defaultView.top.document,
- "mediaTab", this.target);
+ BrowserPageInfo(gContextMenuContentData.docLocation, "mediaTab",
+ this.target, null, this.browser);
},
viewFrameInfo: function() {
- BrowserPageInfo(this.target.ownerDocument, null, null,
- gContextMenuContentData.frameOuterWindowID);
+ BrowserPageInfo(gContextMenuContentData.docLocation, null, null,
+ gContextMenuContentData.frameOuterWindowID, this.browser);
},
toggleImageSize: function() {
content.document.toggleImageSize();
},
// Reload image
reloadImage: function() {
--- a/suite/browser/content.js
+++ b/suite/browser/content.js
@@ -81,20 +81,24 @@ let PageInfoListener = {
window = Services.wm.getOuterWindowWithId(frameOuterWindowID);
document = window.document;
}
else {
document = content.document;
window = content.window;
}
+ let imageElement = message.objects.imageElement;
+
let pageInfoData = {metaViewRows: this.getMetaInfo(document),
docInfo: this.getDocumentInfo(document),
feeds: this.getFeedsInfo(document, strings),
- windowInfo: this.getWindowInfo(window)};
+ windowInfo: this.getWindowInfo(window),
+ imageInfo: this.getImageInfo(imageElement)};
+
sendAsyncMessage("PageInfo:data", pageInfoData);
// Separate step so page info dialog isn't blank while waiting for this
// to finish.
this.getMediaInfo(document, window, strings);
// Send the message after all the media elements have been walked through.
let pageInfoMediaData = {imageViewRows: this.imageViewRows,
@@ -103,16 +107,29 @@ let PageInfoListener = {
this.imageViewRows = null;
this.linkViewRows = null;
this.formViewRows = null;
sendAsyncMessage("PageInfo:mediaData", pageInfoMediaData);
},
+ getImageInfo: function(imageElement) {
+ let imageInfo = null;
+ if (imageElement) {
+ imageInfo = {
+ currentSrc: imageElement.currentSrc,
+ width: imageElement.width,
+ height: imageElement.height,
+ imageText: imageElement.title || imageElement.alt
+ };
+ }
+ return imageInfo;
+ },
+
getMetaInfo: function(document) {
let metaViewRows = [];
// Get the meta tags from the page.
let metaNodes = document.getElementsByTagName("meta");
for (let metaNode of metaNodes) {
metaViewRows.push([metaNode.name || metaNode.httpEquiv ||
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -2447,28 +2447,37 @@ function BrowserViewSourceOfDocument(aAr
function BrowserViewSource(aBrowser) {
gViewSourceUtils.viewSource({
browser: aBrowser,
outerWindowID: aBrowser.outerWindowID,
URL: aBrowser.currentURI.spec,
});
}
-// doc - document to use for source, or null for the current tab
+// documentURL - URL of the document to view, or null for this window's document
// initialTab - id 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(doc, initialTab, imageElement, frameOuterWindowID) {
- var args = {doc: doc, initialTab: initialTab, imageElement: imageElement,
- frameOuterWindowID: 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=1575830");
+ documentURL = documentURL.location;
+ }
+
+ let args = { initialTab, imageElement, frameOuterWindowID, browser };
var windows = Services.wm.getEnumerator("Browser:page-info");
- var documentURL = doc ? doc.location : window.gBrowser.selectedBrowser.currentURI.spec;
+ documentURL = documentURL || window.gBrowser.selectedBrowser.currentURI.spec;
// Check for windows matching the url.
while (windows.hasMoreElements()) {
let win = windows.getNext();
if (win.closed) {
continue;
}
if (win.document.documentElement
--- a/suite/browser/pageinfo/pageInfo.js
+++ b/suite/browser/pageinfo/pageInfo.js
@@ -227,19 +227,16 @@ var loadContextInfo = Services.loadConte
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext), false);
var diskStorage = Services.cache2.diskCacheStorage(loadContextInfo, false);
const nsICertificateDialogs = Ci.nsICertificateDialogs;
const CERTIFICATEDIALOGS_CONTRACTID = "@mozilla.org/nsCertificateDialogs;1"
-// Interface for image loading content
-const nsIImageLoadingContent = Ci.nsIImageLoadingContent;
-
/* Overlays register functions here.
* These arrays are used to hold callbacks that Page Info will call at
* various stages. Use them by simply appending a function to them.
* For example, add a function to onLoadRegistry by invoking
* "onLoadRegistry.push(XXXLoadFunc);"
* The XXXLoadFunc should be unique to the overlay module, and will be
* invoked as "XXXLoadFunc();"
*/
@@ -297,45 +294,49 @@ function onLoadPageInfo()
initView("linktree", gLinkView);
initPermission();
/* Select the requested tab, if the name is specified */
loadTab(args);
Services.obs.notifyObservers(window, "page-info-dialog-loaded");
}
-function loadPageInfo(frameOuterWindowID)
+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.
mm.sendAsyncMessage("PageInfo:getData", {strings: gStrings,
- frameOuterWindowID: frameOuterWindowID});
+ frameOuterWindowID: frameOuterWindowID},
+ { imageElement });
let pageInfoData = null;
// Get initial pageInfoData needed to display the general, feeds, permission
// and security tabs.
mm.addMessageListener("PageInfo:data", function onmessage(message) {
mm.removeMessageListener("PageInfo:data", onmessage);
pageInfoData = message.data;
let docInfo = pageInfoData.docInfo;
let windowInfo = pageInfoData.windowInfo;
let uri = makeURI(docInfo.documentURIObject.spec,
docInfo.documentURIObject.originCharset);
let principal = docInfo.principal;
gDocInfo = docInfo;
+ gImageElement = pageInfoData.imageInfo;
+
var titleFormat = windowInfo.isTopWindow ? "pageInfo.page.title"
: "pageInfo.frame.title";
document.title = gBundle.getFormattedString(titleFormat,
[docInfo.location]);
document.getElementById("main-window").setAttribute("relatedUrl",
docInfo.location);
@@ -428,29 +429,21 @@ function showTab(id)
selectedTab.focus();
}
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;
- if (imageElement) {
- gImageElement = {currentSrc: imageElement.currentSrc,
- width: imageElement.width, height: imageElement.height,
- imageText: imageElement.title || imageElement.alt};
- }
- else {
- gImageElement = null;
- }
-
let frameOuterWindowID = args && args.frameOuterWindowID;
+ let browser = args && args.browser;
/* Load the page info */
- loadPageInfo(frameOuterWindowID);
+ loadPageInfo(frameOuterWindowID, imageElement, browser);
/* Select the requested tab, if the name is specified */
var initialTab = (args && args.initialTab) || "generalTab";
showTab(initialTab);
}
function onClickMore()
{