From fa7674e6520394dc9b342a0ba20a32f7733cc9fb Mon Sep 17 00:00:00 2001 From: Infocatcher Date: Mon, 12 Sep 2016 22:37:47 +0300 Subject: [PATCH] Handle view source window from BrowserViewSourceOfDocument() (related to #234) --- bootstrap.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index 598e81f..1b1feeb 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -941,12 +941,35 @@ var privateTab = { patcher.wrapFunction( window, fnViewSource, fnViewSource, function before(argsOrDoc) { - if(!prefs.getPref("view_source.tab")) - return; - var w = this.getNotPopupWindow(window, true) || window; - var isPrivate = this.isPrivateContent(w); - _log(fnViewSource + "(): wait for tab to make " + (isPrivate ? "private" : "not private")); - this.readyToOpenTab(w, isPrivate); + if(prefs.getPref("view_source.tab")) { + var w = this.getNotPopupWindow(window, true) || window; + var isPrivate = this.isPrivateContent(w); + _log(fnViewSource + "(): wait for tab to make " + (isPrivate ? "private" : "not private")); + this.readyToOpenTab(w, isPrivate); + } + else if(!prefs.getPref("view_source.editor.external")) { + var isPrivate = this.isPrivateContent(window); + var _p = isPrivate ? "private" : "not private"; + _log(fnViewSource + "(): wait for window to make " + _p); + var observer, onLoad; + Services.obs.addObserver(observer = function(window, topic, data) { + Services.obs.removeObserver(observer, topic); + window.addEventListener("load", onLoad = function(e) { + window.removeEventListener("load", onLoad, false); + if(window.location.href != "chrome://global/content/viewSource.xul") { + _log(fnViewSource + "(): can't get view source window"); + return; + } + var privacyContext = this.getPrivacyContext(window); + if(privacyContext.usePrivateBrowsing == isPrivate) + _log(fnViewSource + "(): window already " + _p); + else { + _log(fnViewSource + "(): make window " + _p); + privacyContext.usePrivateBrowsing = isPrivate; + } + }.bind(this), false); + }.bind(this), "domwindowopened", false); + } }.bind(this) ); }