aboutsummaryrefslogtreecommitdiffstats
path: root/platform/firefox/frameModule.js
diff options
context:
space:
mode:
authorDeathamns <deathamns@gmail.com>2015-01-26 20:26:45 +0100
committerDeathamns <deathamns@gmail.com>2015-01-26 20:26:45 +0100
commit263b756764829eebb877f1b5b92bba3da5cf28e0 (patch)
treee1e58db44a3e2a47b0a6c2514e71ab0483cb2889 /platform/firefox/frameModule.js
parent44fa4d72d01b8e286478005d12f796501ac082b2 (diff)
downloaduBlock-263b756764829eebb877f1b5b92bba3da5cf28e0.zip
uBlock-263b756764829eebb877f1b5b92bba3da5cf28e0.tar.gz
uBlock-263b756764829eebb877f1b5b92bba3da5cf28e0.tar.bz2
Firefox: behind-the-scene requests / non-http tabs
Diffstat (limited to 'platform/firefox/frameModule.js')
-rw-r--r--platform/firefox/frameModule.js68
1 files changed, 30 insertions, 38 deletions
diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js
index 8288fcf..d949b5d 100644
--- a/platform/firefox/frameModule.js
+++ b/platform/firefox/frameModule.js
@@ -30,6 +30,8 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
let uniqueSandboxId = 1;
+// let {console} = Cu.import('resource://gre/modules/devtools/Console.jsm', null);
+
/******************************************************************************/
const getMessageManager = function(win) {
@@ -112,32 +114,18 @@ const contentObserver = {
// https://bugzil.la/612921
shouldLoad: function(type, location, origin, context) {
- // If we don't know what initiated the request, probably it's not a tab
if ( !context ) {
- return this.ACCEPT;
+ return;
}
- let openerURL;
-
if ( !location.schemeIs('http') && !location.schemeIs('https') ) {
- if ( type !== this.MAIN_FRAME ) {
- return this.ACCEPT;
- }
-
- context = context.contentWindow || context;
-
- try {
- if ( context !== context.opener ) {
- openerURL = context.opener.location.href;
- }
- } catch (ex) {}
+ return this.ACCEPT;
+ }
- let isPopup = location.spec === 'about:blank' && openerURL;
+ let openerURL, frameId;
- if ( !location.schemeIs('data') && !isPopup ) {
- return this.ACCEPT;
- }
- } else if ( type === this.MAIN_FRAME ) {
+ if ( type === this.MAIN_FRAME ) {
+ frameId = -1;
context = context.contentWindow || context;
try {
@@ -146,31 +134,33 @@ const contentObserver = {
}
} catch (ex) {}
} else {
+ // TODO: frameId from outerWindowID?
+ // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils
+ frameId = context === context.top ? 0 : 1;
context = (context.ownerDocument || context).defaultView;
}
// The context for the toolbar popup is an iframe element here,
// so check context.top instead of context
- if ( context.top && context.location ) {
- // https://bugzil.la/1092216
- let messageManager = getMessageManager(context);
- let details = {
- openerURL: openerURL || null,
- url: location.spec,
- type: type,
- frameId: type === this.MAIN_FRAME ? -1 : (context === context.top ? 0 : 1),
- parentFrameId: context === context.top ? -1 : 0
- };
+ if ( !context.top || !context.location ) {
+ return this.ACCEPT;
+ }
- // TODO: frameId from outerWindowID?
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils
+ let messageManager = getMessageManager(context);
+ let details = {
+ frameId: frameId,
+ openerURL: openerURL || null,
+ parentFrameId: context === context.top ? -1 : 0,
+ type: type,
+ url: location.spec
+ };
- if ( typeof messageManager.sendRpcMessage === 'function' ) {
- messageManager.sendRpcMessage(this.cpMessageName, details);
- } else {
- // Compatibility for older versions
- messageManager.sendSyncMessage(this.cpMessageName, details);
- }
+ if ( typeof messageManager.sendRpcMessage === 'function' ) {
+ // https://bugzil.la/1092216
+ messageManager.sendRpcMessage(this.cpMessageName, details);
+ } else {
+ // Compatibility for older versions
+ messageManager.sendSyncMessage(this.cpMessageName, details);
}
return this.ACCEPT;
@@ -208,6 +198,7 @@ const contentObserver = {
sandbox._sandboxId_ = sandboxId;
sandbox.sendAsyncMessage = messager.sendAsyncMessage;
+
sandbox.addMessageListener = function(callback) {
if ( this._messageListener_ ) {
this.removeMessageListener(
@@ -229,6 +220,7 @@ const contentObserver = {
this._messageListener_
);
}.bind(sandbox);
+
sandbox.removeMessageListener = function() {
try {
messager.removeMessageListener(