summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNew Tobin Paradigm <email@mattatobin.com>2018-04-13 00:45:26 -0400
committerGitHub <noreply@github.com>2018-04-13 00:45:26 -0400
commitff362dd20098bb3b2122fb7c7daf1d057b29c570 (patch)
tree6237cbdf313705e3996b2bb9769a3f6f81e15e9e
parente226e36a6c1792b68ba22a2ae43b8e1e230b5246 (diff)
parent7bbe1c3f3db8028e4592c4dfdfbd473eec34705d (diff)
downloadUXP-ff362dd20098bb3b2122fb7c7daf1d057b29c570.tar
UXP-ff362dd20098bb3b2122fb7c7daf1d057b29c570.tar.gz
UXP-ff362dd20098bb3b2122fb7c7daf1d057b29c570.tar.lz
UXP-ff362dd20098bb3b2122fb7c7daf1d057b29c570.tar.xz
UXP-ff362dd20098bb3b2122fb7c7daf1d057b29c570.zip
Merge pull request #137 from janekptacijarabaci/pm_viewSource_1
Fix: Using "View Source" from Browser Console; Added support for "view_source.editor.external"
-rw-r--r--application/palemoon/base/content/browser.js70
1 files changed, 32 insertions, 38 deletions
diff --git a/application/palemoon/base/content/browser.js b/application/palemoon/base/content/browser.js
index 8cc091e85..8b3fa0b4f 100644
--- a/application/palemoon/base/content/browser.js
+++ b/application/palemoon/base/content/browser.js
@@ -2017,49 +2017,43 @@ function readFromClipboard()
return url;
}
-function BrowserViewSourceOfDocument(aDocument)
+function BrowserViewSourceOfDocument(aArgsOrDocument)
{
- var pageCookie;
- var webNav;
-
- // Get the document charset
- var docCharset = "charset=" + aDocument.characterSet;
-
- // 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(nsIWebNavigation);
- } catch(err) {
- // If nsIWebNavigation cannot be found, just get the one for the whole
- // window...
- webNav = gBrowser.webNavigation;
+ let args;
+
+ if (aArgsOrDocument instanceof Document) {
+ let doc = aArgsOrDocument;
+
+ 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 '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 viewInternal = () => {
+ top.gViewSourceUtils.viewSource(args);
}
- top.gViewSourceUtils.viewSource(webNav.currentURI.spec, pageCookie, aDocument);
+ // 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