Fix: Using "View Source" from Browser Console

Issue #121
This commit is contained in:
janekptacijarabaci
2018-04-13 06:17:25 +02:00
parent e226e36a6c
commit 7bbe1c3f3d
+31 -37
View File
@@ -2017,49 +2017,43 @@ function readFromClipboard()
return url;
}
function BrowserViewSourceOfDocument(aDocument)
function BrowserViewSourceOfDocument(aArgsOrDocument)
{
var pageCookie;
var webNav;
let args;
// Get the document charset
var docCharset = "charset=" + aDocument.characterSet;
if (aArgsOrDocument instanceof Document) {
let doc = aArgsOrDocument;
// Get the nsIWebNavigation associated with the document
try {
var win;
var ifRequestor;
let requestor = doc.defaultView
.QueryInterface(Ci.nsIInterfaceRequestor);
let browser = requestor.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
let outerWindowID = requestor.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
let URL = browser.currentURI.spec;
args = { browser, outerWindowID, URL };
} else {
args = aArgsOrDocument;
}
// 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;
let viewInternal = () => {
top.gViewSourceUtils.viewSource(args);
}
// Check if external view source is enabled. If so, try it. If it fails,
// fallback to internal view source.
if (Services.prefs.getBoolPref("view_source.editor.external")) {
top.gViewSourceUtils
.openInExternalEditor(args, null, null, null, result => {
if (!result) {
viewInternal();
}
ifRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
webNav = ifRequestor.getInterface(nsIWebNavigation);
} catch(err) {
// If nsIWebNavigation cannot be found, just get the one for the whole
// window...
webNav = gBrowser.webNavigation;
});
} else {
// Display using internal view source
viewInternal();
}
//
// 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...
}
top.gViewSourceUtils.viewSource(webNav.currentURI.spec, pageCookie, aDocument);
}
// doc - document to use for source, or null for this window's document