Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicole-ashley committed Sep 28, 2016
2 parents 07ee47b + 56176c8 commit c2c8e9c
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 104 deletions.
2 changes: 1 addition & 1 deletion platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,

"name": "uBlock Origin",
"version": "1.9.10",
"version": "1.9.11.101",

"default_locale": "en",
"description": "__MSG_extShortDesc__",
Expand Down
2 changes: 1 addition & 1 deletion platform/edge/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,

"name": "uBlock Origin",
"version": "1.9.10",
"version": "1.9.11.101",

"default_locale": "en",
"description": "__MSG_extShortDesc__",
Expand Down
151 changes: 119 additions & 32 deletions platform/firefox/frameModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
Home: https://github.com/gorhill/uBlock
*/

/* exported processObserver */

'use strict';

/******************************************************************************/

// https://github.com/gorhill/uBlock/issues/800
this.EXPORTED_SYMBOLS = ['contentObserver', 'LocationChangeListener'];
this.EXPORTED_SYMBOLS = [
'contentObserver',
'processObserver',
'LocationChangeListener'
];

const {interfaces: Ci, utils: Cu} = Components;
const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
Expand Down Expand Up @@ -64,20 +70,81 @@ const getMessageManager = function(win) {

/******************************************************************************/

const getChildProcessMessageManager = function() {
var svc = Services;
if ( !svc ) {
return;
}
var cpmm = svc.cpmm;
if ( cpmm ) {
return cpmm;
}
cpmm = Components.classes['@mozilla.org/childprocessmessagemanager;1'];
if ( cpmm ) {
return cpmm.getService(Ci.nsISyncMessageSender);
}
};
// https://github.com/gorhill/uBlock/issues/2014
// Have a dictionary of hostnames for which there are script tag filters. This
// allow for coarse-testing before firing a synchronous message to the
// parent process. Script tag filters are not very common, so this allows
// to skip the blocking of the child process most of the time.

var scriptTagFilterer = (function() {
var scriptTagHostnames;

var getCpmm = function() {
var svc = Services;
if ( !svc ) { return; }
var cpmm = svc.cpmm;
if ( cpmm ) { return cpmm; }
cpmm = Components.classes['@mozilla.org/childprocessmessagemanager;1'];
if ( cpmm ) { return cpmm.getService(Ci.nsISyncMessageSender); }
};

var getScriptTagHostnames = function() {
if ( scriptTagHostnames ) {
return scriptTagHostnames;
}
var cpmm = getCpmm();
if ( !cpmm ) { return; }
var r = cpmm.sendSyncMessage(rpcEmitterName, { fnName: 'getScriptTagHostnames' });
if ( Array.isArray(r) && Array.isArray(r[0]) ) {
scriptTagHostnames = new Set(r[0]);
}
return scriptTagHostnames;
};

var getScriptTagFilters = function(details) {
let cpmm = getCpmm();
if ( !cpmm ) { return; }
let r = cpmm.sendSyncMessage(rpcEmitterName, {
fnName: 'getScriptTagFilters',
rootURL: details.rootURL,
frameURL: details.frameURL,
frameHostname: details.frameHostname
});
if ( Array.isArray(r) ) {
return r[0];
}
};

var regexFromHostname = function(details) {
// If target hostname has no script tag filter, no point querying
// chrome process.
var hostnames = getScriptTagHostnames();
if ( !hostnames ) { return; }
var hn = details.frameHostname, pos, entity;
for (;;) {
if ( hostnames.has(hn) ) {
return getScriptTagFilters(details);
}
pos = hn.indexOf('.');
if ( pos === -1 ) { break; }
entity = hn.slice(0, pos) + '.*';
if ( hostnames.has(entity) ) {
return getScriptTagFilters(details);
}
hn = hn.slice(pos + 1);
if ( hn === '' ) { break; }
}
};

var reset = function() {
scriptTagHostnames = undefined;
};

return {
get: regexFromHostname,
reset: reset
};
})();

/******************************************************************************/

Expand Down Expand Up @@ -305,18 +372,9 @@ var contentObserver = {
wantXHRConstructor: false
});

if ( getChildProcessMessageManager() ) {
sandbox.rpc = function(details) {
var cpmm = getChildProcessMessageManager();
if ( !cpmm ) { return; }
var r = cpmm.sendSyncMessage(rpcEmitterName, details);
if ( Array.isArray(r) ) {
return r[0];
}
};
} else {
sandbox.rpc = function() {};
}
sandbox.getScriptTagFilters = function(details) {
return scriptTagFilterer.get(details);
};

sandbox.injectScript = function(script) {
let svc = Services;
Expand Down Expand Up @@ -344,6 +402,9 @@ var contentObserver = {
}
};

sandbox.topContentScript = win === win.top;

// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime#Unloading_frame_scripts
// The goal is to have content scripts removed from web pages. This
// helps remove traces of uBlock from memory when disabling/removing
// the addon.
Expand All @@ -353,12 +414,12 @@ var contentObserver = {
sandbox.outerShutdown = function() {
sandbox.removeMessageListener();
sandbox.addMessageListener =
sandbox.getScriptTagFilters =
sandbox.injectCSS =
sandbox.injectScript =
sandbox.outerShutdown =
sandbox.removeCSS =
sandbox.removeMessageListener =
sandbox.rpc =
sandbox.sendAsyncMessage = function(){};
sandbox.vAPI = {};
messager = null;
Expand All @@ -380,34 +441,52 @@ var contentObserver = {
callback(message.data);
};

sandbox._broadcastListener_ = function(message) {
// https://github.com/gorhill/uBlock/issues/2014
if ( sandbox.topContentScript ) {
let details;
try { details = JSON.parse(message.data); } catch (ex) {}
let msg = details && details.msg || {};
if ( msg.what === 'staticFilteringDataChanged' ) {
if ( scriptTagFilterer ) {
scriptTagFilterer.reset();
}
}
}
callback(message.data);
};

messager.addMessageListener(
sandbox._sandboxId_,
sandbox._messageListener_
);
messager.addMessageListener(
hostName + ':broadcast',
sandbox._messageListener_
sandbox._broadcastListener_
);
};

sandbox.removeMessageListener = function() {
if ( !sandbox._messageListener_ ) {
return;
}
// It throws sometimes, mostly when the popup closes
try {
messager.removeMessageListener(
sandbox._sandboxId_,
sandbox._messageListener_
);
} catch (ex) {
}
try {
messager.removeMessageListener(
hostName + ':broadcast',
sandbox._messageListener_
sandbox._broadcastListener_
);
} catch (ex) {
// It throws sometimes, mostly when the popup closes
}

sandbox._messageListener_ = null;
sandbox._messageListener_ = sandbox._broadcastListener_ = null;
};

return sandbox;
Expand Down Expand Up @@ -498,6 +577,14 @@ var contentObserver = {

/******************************************************************************/

var processObserver = {
start: function() {
scriptTagFilterer.reset();
}
};

/******************************************************************************/

var LocationChangeListener = function(docShell, webProgress) {
var mm = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIContentFrameMessageManager);
Expand Down
31 changes: 17 additions & 14 deletions platform/firefox/frameScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@

// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment

(function() {
(function(context) {
'use strict';

let {LocationChangeListener} = Components.utils.import(
Components.stack.filename.replace('Script', 'Module'),
null
);

if ( !this.docShell ) {
if ( !context.docShell ) {
return;
}

let webProgress = this.docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebProgress);
let webProgress = context.docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebProgress);
if ( !webProgress ) {
return;
}
Expand All @@ -49,11 +44,19 @@
return;
}

let {LocationChangeListener} = Components.utils.import(
Components.stack.filename.replace('Script', 'Module'),
null
);

// https://github.com/gorhill/uBlock/issues/1444
// Apparently, on older versions of Firefox (31 and less), the same context
// is used for all extensions, hence we must use a unique variable name to
// ensure no collision.
this.ublock0LocationChangeListener = new LocationChangeListener(this.docShell, webProgress);
}).call(this);
// is used for all frame scripts, hence we must use a unique variable name
// to ensure no collision.
context.ublock0LocationChangeListener = new LocationChangeListener(
context.docShell,
webProgress
);
})(this);

/******************************************************************************/
40 changes: 40 additions & 0 deletions platform/firefox/processScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2016 The uBlock Origin authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/

/******************************************************************************/

// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader

// Some module tasks need to run once per-content process. This is the purpose
// of this content process script.

(function() {
'use strict';

let {processObserver} = Components.utils.import(
Components.stack.filename.replace('processScript.js', 'frameModule.js'),
null
);

processObserver.start();
})();

/******************************************************************************/
Loading

0 comments on commit c2c8e9c

Please sign in to comment.