Fix: Using "View Source" from Browser Console

Issue #121
This commit is contained in:
janekptacijarabaci 2018-04-13 06:17:25 +02:00 • committed by Roy Tam
commit a47dfd1d82

View file

@ -2017,49 +2017,43 @@ function readFromClipboard()
return url; return url;
} }
function BrowserViewSourceOfDocument(aDocument) function BrowserViewSourceOfDocument(aArgsOrDocument)
{ {
var pageCookie; let args;
var webNav;
// Get the document charset if (aArgsOrDocument instanceof Document) {
var docCharset = "charset=" + aDocument.characterSet; let doc = aArgsOrDocument;
// Get the nsIWebNavigation associated with the document let requestor = doc.defaultView
try { .QueryInterface(Ci.nsIInterfaceRequestor);
var win; let browser = requestor.getInterface(Ci.nsIWebNavigation)
var ifRequestor; .QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
// Get the DOMWindow for the requested document. If the DOMWindow let outerWindowID = requestor.getInterface(Ci.nsIDOMWindowUtils)
// cannot be found, then just use the content window... .outerWindowID;
// let URL = browser.currentURI.spec;
// XXX: This is a bit of a hack... args = { browser, outerWindowID, URL };
win = aDocument.defaultView; } else {
if (win == window) { args = aArgsOrDocument;
win = content;
}
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;
}
//
// 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); 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();
}
});
} else {
// Display using internal view source
viewInternal();
}
} }
// doc - document to use for source, or null for this window's document // doc - document to use for source, or null for this window's document