1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 16:47:15 +02:00

Add license headers, plus some code styling

This commit is contained in:
Deathamns 2014-12-17 21:33:53 +01:00
parent 8bb0d3276b
commit ecdee65fda
13 changed files with 156 additions and 23 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,12 +1,37 @@
/*******************************************************************************
µ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, APP_STARTUP, APP_SHUTDOWN */
/* exported startup, shutdown, install, uninstall */
'use strict';
Components.utils['import']('resource://gre/modules/Services.jsm');
/******************************************************************************/
var bgProcess;
Components.utils['import']('resource://gre/modules/Services.jsm');
/******************************************************************************/
function startup(data, reason) {
bgProcess = function(ev) {
if (ev) {
@ -33,13 +58,23 @@ function startup(data, reason) {
}
}
/******************************************************************************/
function shutdown(data, reason) {
if (reason !== APP_SHUTDOWN) {
bgProcess.parentNode.removeChild(bgProcess);
}
}
// https://bugzil.la/719376
function install() Services.strings.flushBundles();
/******************************************************************************/
function install() {
// https://bugzil.la/719376
Services.strings.flushBundles();
}
/******************************************************************************/
function uninstall() {}
/******************************************************************************/

View File

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

View File

@ -1,9 +1,36 @@
/*******************************************************************************
µ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
*/
/* globals Services, sendAsyncMessage, addMessageListener, removeMessageListener */
'use strict';
/******************************************************************************/
(function(frameScriptContext) {
'use strict';
/******************************************************************************/
let appName;
let listeners = {};
@ -13,6 +40,8 @@ try { throw new Error; } catch (ex) {
Components.utils['import']('chrome://' + appName + '/content/frameModule.js', {});
/******************************************************************************/
frameScriptContext[appName + '_addMessageListener'] = function(id, fn) {
frameScriptContext[appName + '_removeMessageListener'](id);
listeners[id] = function(msg) {
@ -29,10 +58,16 @@ frameScriptContext[appName + '_removeMessageListener'] = function(id) {
delete listeners[id];
};
/******************************************************************************/
addMessageListener(appName + ':broadcast', function(msg) {
for (let id in listeners) {
listeners[id](msg);
}
});
})(this);
/******************************************************************************/
})(this);
/******************************************************************************/

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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
@ -56,6 +56,7 @@ vAPI.app.restart = function() {};
/******************************************************************************/
// list of things that needs to be destroyed when disabling the extension
// only functions should be added to it
vAPI.unload = [];

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,8 +1,33 @@
/*******************************************************************************
µ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
*/
'use strict';
/******************************************************************************/
// Adding new URL requires to whitelist it in the background script too (addContentScriptFromURL)
// Note that the sitePach function will be converted to a string, and injected
// into the web-page in order to run in that scope. Because of this, variables
// from the extension scope won't be accessible in the sitePatch function.
'use strict';
self.vAPI = self.vAPI || {};
@ -33,8 +58,10 @@ if (/^www\.youtube(-nocookie)?\.com/.test(location.host)) {
playerConfig = data;
var playerRoot = document.querySelector('[data-swf-config]');
if (playerRoot)
if (playerRoot) {
playerRoot.dataset.swfConfig = JSON.stringify(yt.playerConfig);
}
}
},
'config_': {

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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
@ -20,6 +20,7 @@
*/
/* global µBlock, SafariBrowserTab */
// For background page
/******************************************************************************/

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
µ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