Bug 1187956 - View source from SeaMonkey uses deprecated API r=Neil a=Ratty for a CLOSED TREE

This commit is contained in:
Ian Neal 2015-08-02 15:51:37 +01:00
Родитель e9e64e01be
Коммит 8b2bc2101a
6 изменённых файлов: 72 добавлений и 45 удалений

Просмотреть файл

@ -1854,46 +1854,65 @@ function readFromClipboard()
return url;
}
function BrowserViewSourceOfDocument(aDocument)
{
var pageCookie;
var webNav;
/**
* Open the View Source dialog.
*
* @param aArgsOrDocument
* Either an object or a Document. Passing a Document is deprecated,
* and is not supported with e10s. This function will throw if
* aArgsOrDocument is a CPOW.
*
* If aArgsOrDocument is an object, that object can take the
* following properties:
*
* URL (required):
* A string URL for the page we'd like to view the source of.
* browser (optional):
* The browser containing the document that we would like to view the
* source of. This is required if outerWindowID is passed.
* outerWindowID (optional):
* The outerWindowID of the content window containing the document that
* we want to view the source of. You only need to provide this if you
* want to attempt to retrieve the document source from the network
* cache.
* lineNumber (optional):
* The line number to focus on once the source is loaded.
*/
function BrowserViewSourceOfDocument(aArgsOrDocument) {
if (aArgsOrDocument instanceof Document) {
// Deprecated API - callers should pass args object instead.
if (Components.utils.isCrossProcessWrapper(aArgsOrDocument)) {
throw new Error("BrowserViewSourceOfDocument cannot accept a CPOW " +
"as a document.");
}
// Get the nsIWebNavigation associated with the document
try {
var win;
var ifRequestor;
// Get the DOMWindow for the requested document. If the DOMWindow
// cannot be found, then just use the content window...
//
// XXX: This is a bit of a hack...
win = aDocument.defaultView;
if (win == window) {
win = content;
}
ifRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
webNav = ifRequestor.getInterface(Components.interfaces.nsIWebNavigation);
} catch(err) {
// If nsIWebNavigation cannot be found, just get the one for the whole
// window...
webNav = getWebNavigation();
}
//
// Get the 'PageDescriptor' for the current document. This allows the
// view-source to access the cached copy of the content rather than
// refetching it from the network...
//
try{
var PageLoader = webNav.QueryInterface(Components.interfaces.nsIWebPageDescriptor);
pageCookie = PageLoader.currentDescriptor;
} catch(err) {
// If no page descriptor is available, just use the view-source URL...
let requestor = aArgsOrDocument.defaultView
.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
let browser = requestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.chromeEventHandler;
let outerWindowID = requestor.getInterface(Components.interfaces.nsIDOMWindowUtils)
.outerWindowID;
let URL = browser.currentURI.spec;
aArgsOrDocument = { browser, outerWindowID, URL };
}
gViewSourceUtils.viewSource(webNav.currentURI.spec, pageCookie, aDocument);
gViewSourceUtils.viewSource(aArgsOrDocument);
}
/**
* Opens the View Source dialog for the source loaded in the root
* top-level document of the browser.
*
* @param aBrowser
* The browser that we want to load the source of.
*/
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

Просмотреть файл

@ -158,7 +158,7 @@
<command id="cmd_copyImage"/>
<!-- View Menu -->
<command id="View:PageSource" oncommand="BrowserViewSourceOfDocument(content.document);" observes="isImage"/>
<command id="View:PageSource" oncommand="BrowserViewSource(gBrowser.selectedBrowser);" observes="isImage"/>
<command id="View:PageInfo" oncommand="BrowserPageInfo();"/>
<command id="View:FullScreen" oncommand="BrowserFullScreen();"/>
<command id="cmd_SwitchDocumentDirection" oncommand="SwitchDocumentDirection(window.content);" />

Просмотреть файл

@ -276,7 +276,7 @@
label="&viewPageSourceCmd.label;"
accesskey="&viewPageSourceCmd.accesskey;"
observes="isImage"
oncommand="BrowserViewSourceOfDocument(content.document);"/>
oncommand="BrowserViewSource(gContextMenu.browser);"/>
<menuitem id="context-viewinfo"
label="&viewPageInfoCmd.label;"
accesskey="&viewPageInfoCmd.accesskey;"

Просмотреть файл

@ -102,6 +102,9 @@ nsContextMenu.prototype = {
referrerPolicy: doc.referrerPolicy,
contentType: contentType,
contentDisposition: contentDisposition,
frameOuterWindowID: doc.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils)
.outerWindowID,
};
},
@ -869,7 +872,11 @@ nsContextMenu.prototype = {
// Open new "view source" window with the frame's URL.
viewFrameSource: function() {
BrowserViewSourceOfDocument(this.target.ownerDocument);
gViewSourceUtils.viewSource({
browser: this.browser,
URL: gContextMenuContentData.docLocation,
outerWindowID: gContextMenuContentData.frameOuterWindowID,
});
},
viewInfo: function() {

Просмотреть файл

@ -419,14 +419,14 @@ function ViewPageSource(messages)
return false;
}
var browser = getBrowser();
try {
// First, get the mail session
const nsIMsgMailSession = Components.interfaces.nsIMsgMailSession;
var mailSession = Components.classes["@mozilla.org/messenger/services/session;1"]
.getService(nsIMsgMailSession);
var mailCharacterSet = "charset=" + msgWindow.mailCharacterSet;
for (var i = 0; i < numMessages; i++)
{
// Now, we need to get a URL from a URI
@ -437,8 +437,9 @@ function ViewPageSource(messages)
url = url.replace(/(\?|&)type=application\/x-message-display(&|$)/, "$1")
.replace(/\?$/, "");
window.openDialog( "chrome://global/content/viewSource.xul",
"_blank", "all,dialog=no", url,
mailCharacterSet);
"_blank", "all,dialog=no",
{URL: url, browser: browser,
outerWindowID: browser.outerWindowID});
}
return true;
} catch (e) {

Просмотреть файл

@ -1377,7 +1377,7 @@ createNewAttachmentInfo.prototype.viewAttachment = function viewAttachment()
if (!this.isExternalAttachment)
url += "&filename=" + encodeURIComponent(this.displayName);
openDialog("chrome://global/content/viewSource.xul",
"_blank", "all,dialog=no", url);
"_blank", "all,dialog=no", {URL: url});
}
createNewAttachmentInfo.prototype.openAttachment = function openAttachment()