From ecdee65fda8632a9b25fc8e12db4d7f1707d6ec3 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Wed, 17 Dec 2014 21:33:53 +0100 Subject: [PATCH] Add license headers, plus some code styling --- platform/chromium/vapi-background.js | 2 +- platform/chromium/vapi-client.js | 2 +- platform/chromium/vapi-common.js | 2 +- platform/firefox/bootstrap.js | 41 +++++++++++++++++++++-- platform/firefox/frameModule.js | 50 +++++++++++++++++++++++----- platform/firefox/frameScript.js | 37 +++++++++++++++++++- platform/firefox/vapi-background.js | 3 +- platform/firefox/vapi-client.js | 2 +- platform/firefox/vapi-common.js | 2 +- platform/safari/sitepatch-safari.js | 31 +++++++++++++++-- platform/safari/vapi-background.js | 3 +- platform/safari/vapi-client.js | 2 +- platform/safari/vapi-common.js | 2 +- 13 files changed, 156 insertions(+), 23 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 9609980f6..181ffead7 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -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 diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 67f6ddf49..b0b599c73 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -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 diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 81667dbfa..7797452d3 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -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 diff --git a/platform/firefox/bootstrap.js b/platform/firefox/bootstrap.js index 2dbd4294c..c601c7381 100644 --- a/platform/firefox/bootstrap.js +++ b/platform/firefox/bootstrap.js @@ -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() {} + +/******************************************************************************/ diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index a48ebdc95..8223817f8 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -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(); + +/******************************************************************************/ diff --git a/platform/firefox/frameScript.js b/platform/firefox/frameScript.js index 37caefb63..d1ae54a28 100644 --- a/platform/firefox/frameScript.js +++ b/platform/firefox/frameScript.js @@ -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); \ No newline at end of file +/******************************************************************************/ + +})(this); + +/******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 25151cf1f..a357cd356 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -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 = []; diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js index 79f6ef922..a70000510 100644 --- a/platform/firefox/vapi-client.js +++ b/platform/firefox/vapi-client.js @@ -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 diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 0bcc95c30..cbe6dc75f 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -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 diff --git a/platform/safari/sitepatch-safari.js b/platform/safari/sitepatch-safari.js index b99a28ea7..45b775cf4 100644 --- a/platform/safari/sitepatch-safari.js +++ b/platform/safari/sitepatch-safari.js @@ -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_': { diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 362ab1a00..50cfea73b 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -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 /******************************************************************************/ diff --git a/platform/safari/vapi-client.js b/platform/safari/vapi-client.js index 523b4dca1..9ce6b07aa 100644 --- a/platform/safari/vapi-client.js +++ b/platform/safari/vapi-client.js @@ -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 diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 6aa7639c6..f324fd6ad 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -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