Add license headers, plus some code styling

pull/2/head
Deathamns 10 years ago committed by gorhill
parent afe6a29c36
commit 6faa9e85c2

@ -1,20 +1,46 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
Copyright (C) 2014 The µBlock 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
*/
/* global Services, Components, XPCOMUtils */ /* global Services, Components, XPCOMUtils */
'use strict'; 'use strict';
/******************************************************************************/
this.EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver']; this.EXPORTED_SYMBOLS = ['contentPolicy', 'docObserver'];
Components.utils['import']('resource://gre/modules/Services.jsm'); const {interfaces: Ci, utils: Cu} = Components;
Components.utils['import']('resource://gre/modules/XPCOMUtils.jsm');
// Components.utils['import']('resource://gre/modules/devtools/Console.jsm');
const Ci = Components.interfaces;
let appName; let appName;
try { throw new Error; } catch (ex) { try { throw new Error; } catch (ex) {
appName = ex.fileName.match(/:\/\/([^\/]+)/)[1]; appName = ex.fileName.match(/:\/\/([^\/]+)/)[1];
} }
Cu['import']('resource://gre/modules/Services.jsm');
Cu['import']('resource://gre/modules/XPCOMUtils.jsm');
// Cu['import']('resource://gre/modules/devtools/Console.jsm');
/******************************************************************************/
let getMessager = function(win) { let getMessager = function(win) {
try { try {
// e10s // e10s
@ -35,6 +61,8 @@ let getMessager = function(win) {
} }
}; };
/******************************************************************************/
let contentPolicy = { let contentPolicy = {
classDescription: 'content-policy implementation for ' + appName, classDescription: 'content-policy implementation for ' + appName,
classID: Components.ID('{e6d173c8-8dbf-4189-a6fd-189e8acffd27}'), classID: Components.ID('{e6d173c8-8dbf-4189-a6fd-189e8acffd27}'),
@ -100,7 +128,7 @@ let contentPolicy = {
let result = getMessager(win).sendSyncMessage(this.requestMessageName, { let result = getMessager(win).sendSyncMessage(this.requestMessageName, {
url: location.spec, url: location.spec,
type: type, type: type,
tabId: -1, tabId: -1, // determined in background script
frameId: type === 6 ? -1 : (win === win.top ? 0 : 1), frameId: type === 6 ? -1 : (win === win.top ? 0 : 1),
parentFrameId: win === win.top ? -1 : 0 parentFrameId: win === win.top ? -1 : 0
})[0]; })[0];
@ -112,13 +140,15 @@ let contentPolicy = {
}*/ }*/
}; };
/******************************************************************************/
let docObserver = { let docObserver = {
contentBaseURI: 'chrome://' + appName + '/content/', contentBaseURI: 'chrome://' + appName + '/content/',
initContext: function(win, sandbox) { initContext: function(win, sandbox) {
let messager = getMessager(win); let messager = getMessager(win);
if (sandbox) { if (sandbox) {
win = Components.utils.Sandbox([win], { win = Cu.Sandbox([win], {
sandboxPrototype: win, sandboxPrototype: win,
wantComponents: false, wantComponents: false,
wantXHRConstructor: false wantXHRConstructor: false
@ -127,10 +157,10 @@ let docObserver = {
win.self = win; win.self = win;
// anonymous function needs to be used here // anonymous function needs to be used here
win.injectScript = Components.utils.exportFunction( win.injectScript = Cu.exportFunction(
function(script, evalCode) { function(script, evalCode) {
if (evalCode) { if (evalCode) {
Components.utils.evalInSandbox(script, win); Cu.evalInSandbox(script, win);
return; return;
} }
@ -186,5 +216,9 @@ let docObserver = {
} }
}; };
/******************************************************************************/
contentPolicy.register(); contentPolicy.register();
docObserver.register(); docObserver.register();
/******************************************************************************/

Loading…
Cancel
Save