mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Firefox: partial vAPI.tabs implementation
This commit is contained in:
parent
8297014700
commit
3c76c61f61
55
platform/firefox/bootstrap.js
vendored
55
platform/firefox/bootstrap.js
vendored
@ -3,44 +3,45 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var bgProcess;
|
|
||||||
Components.utils['import']('resource://gre/modules/Services.jsm');
|
Components.utils['import']('resource://gre/modules/Services.jsm');
|
||||||
|
|
||||||
|
var bgProcess;
|
||||||
|
|
||||||
function startup(data, reason) {
|
function startup(data, reason) {
|
||||||
bgProcess = function(ev) {
|
bgProcess = function(ev) {
|
||||||
if (ev) {
|
if (ev) {
|
||||||
this.removeEventListener('load', bgProcess);
|
this.removeEventListener('load', bgProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
bgProcess = Services.appShell.hiddenDOMWindow.document;
|
bgProcess = Services.appShell.hiddenDOMWindow.document;
|
||||||
bgProcess = bgProcess.documentElement.appendChild(
|
bgProcess = bgProcess.documentElement.appendChild(
|
||||||
bgProcess.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
bgProcess.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
|
||||||
);
|
);
|
||||||
bgProcess.setAttribute('src', 'chrome://ublock/content/background.html');
|
bgProcess.setAttribute('src', 'chrome://ublock/content/background.html');
|
||||||
};
|
};
|
||||||
|
|
||||||
if (reason === APP_STARTUP) {
|
if (reason === APP_STARTUP) {
|
||||||
Services.ww.registerNotification({
|
Services.ww.registerNotification({
|
||||||
observe: function(subject) {
|
observe: function(subject) {
|
||||||
Services.ww.unregisterNotification(this);
|
Services.ww.unregisterNotification(this);
|
||||||
subject.addEventListener('load', bgProcess);
|
subject.addEventListener('load', bgProcess);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bgProcess();
|
bgProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shutdown(data, reason) {
|
function shutdown(data, reason) {
|
||||||
if (reason !== APP_SHUTDOWN) {
|
if (reason !== APP_SHUTDOWN) {
|
||||||
bgProcess.parentNode.removeChild(bgProcess);
|
bgProcess.parentNode.removeChild(bgProcess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function install() {
|
function install() {
|
||||||
// https://bugzil.la/719376
|
// https://bugzil.la/719376
|
||||||
Services.strings.flushBundles();
|
Services.strings.flushBundles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall() {}
|
function uninstall() {}
|
@ -4,96 +4,95 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
let
|
let appName = 'ublock';
|
||||||
appName = 'ublock',
|
let contentBaseURI = 'chrome://' + appName + '/content/js/';
|
||||||
contentBaseURI = 'chrome://' + appName + '/content/js/',
|
let listeners = {};
|
||||||
listeners = {},
|
|
||||||
_addMessageListener = function(id, fn) {
|
|
||||||
_removeMessageListener(id);
|
|
||||||
listeners[id] = function(msg) {
|
|
||||||
fn(msg.data);
|
|
||||||
};
|
|
||||||
addMessageListener(id, listeners[id]);
|
|
||||||
},
|
|
||||||
_removeMessageListener = function(id) {
|
|
||||||
if (listeners[id]) {
|
|
||||||
removeMessageListener(id, listeners[id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete listeners[id];
|
let _addMessageListener = function(id, fn) {
|
||||||
};
|
_removeMessageListener(id);
|
||||||
|
listeners[id] = function(msg) {
|
||||||
|
fn(msg.data);
|
||||||
|
};
|
||||||
|
addMessageListener(id, listeners[id]);
|
||||||
|
};
|
||||||
|
|
||||||
|
let _removeMessageListener = function(id) {
|
||||||
|
if (listeners[id]) {
|
||||||
|
removeMessageListener(id, listeners[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete listeners[id];
|
||||||
|
};
|
||||||
|
|
||||||
addMessageListener('µBlock:broadcast', function(msg) {
|
addMessageListener('µBlock:broadcast', function(msg) {
|
||||||
for (var id in listeners) {
|
for (let id in listeners) {
|
||||||
listeners[id](msg);
|
listeners[id](msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var observer = {
|
let initContext = function(win, sandbox) {
|
||||||
unload: function(e) {
|
if (sandbox) {
|
||||||
Services.obs.removeObserver(observer, 'content-document-global-created');
|
win = Components.utils.Sandbox([win], {
|
||||||
observer = listeners = null;
|
sandboxPrototype: win,
|
||||||
},
|
wantComponents: false,
|
||||||
onDOMReady: function(e) {
|
wantXHRConstructor: false
|
||||||
var win = e.target.defaultView;
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (win.location.protocol === 'chrome:' && win.location.host === appName) {
|
win.sendAsyncMessage = sendAsyncMessage;
|
||||||
win.sendAsyncMessage = sendAsyncMessage;
|
win.addMessageListener = _addMessageListener;
|
||||||
win.addMessageListener = _addMessageListener;
|
win.removeMessageListener = _removeMessageListener;
|
||||||
win.removeMessageListener = _removeMessageListener;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
observe: function(win) {
|
|
||||||
if (!win || win.top !== content) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// baseURI is more reliable
|
return win;
|
||||||
var location = Services.io.newURI(
|
};
|
||||||
win.location.protocol === 'data:' ? 'data:text/plain,' : win.document.baseURI,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!(win.document instanceof win.HTMLDocument
|
let observer = {
|
||||||
&& (/^https?$/.test(location.scheme)))) {
|
observe: function(win) {
|
||||||
return;
|
if (!win || win.top !== content) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
win = Components.utils.Sandbox([win], {
|
if (!(win.document instanceof win.HTMLDocument
|
||||||
sandboxPrototype: win,
|
&& (/^https?:$/.test(win.location.protocol)))) {
|
||||||
wantComponents: false,
|
return;
|
||||||
wantXHRConstructor: false
|
}
|
||||||
});
|
|
||||||
|
|
||||||
win.sendAsyncMessage = sendAsyncMessage;
|
let lss = Services.scriptloader.loadSubScript;
|
||||||
win.addMessageListener = _addMessageListener;
|
win = initContext(win, true);
|
||||||
win.removeMessageListener = _removeMessageListener;
|
|
||||||
|
|
||||||
var lss = Services.scriptloader.loadSubScript;
|
lss(contentBaseURI + 'vapi-client.js', win);
|
||||||
|
lss(contentBaseURI + 'contentscript-start.js', win);
|
||||||
|
|
||||||
lss(contentBaseURI + 'vapi-client.js', win);
|
if (win.document.readyState === 'loading') {
|
||||||
lss(contentBaseURI + 'contentscript-start.js', win);
|
let docReady = function(e) {
|
||||||
|
this.removeEventListener(e.type, docReady, true);
|
||||||
|
lss(contentBaseURI + 'contentscript-end.js', win);
|
||||||
|
};
|
||||||
|
|
||||||
if (win.document.readyState === 'loading') {
|
win.document.addEventListener('DOMContentLoaded', docReady, true);
|
||||||
let docReady = function(e) {
|
}
|
||||||
this.removeEventListener(e.type, docReady, true);
|
else {
|
||||||
lss(contentBaseURI + 'contentscript-end.js', win);
|
lss(contentBaseURI + 'contentscript-end.js', win);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
win.document.addEventListener('DOMContentLoaded', docReady, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lss(contentBaseURI + 'contentscript-end.js', win);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Services.obs.addObserver(observer, 'content-document-global-created', false);
|
Services.obs.addObserver(observer, 'content-document-global-created', false);
|
||||||
|
|
||||||
addEventListener('unload', observer.unload, false);
|
let DOMReady = function(e) {
|
||||||
|
let win = e.target.defaultView;
|
||||||
|
|
||||||
// for the Options page
|
// inject the message handlers for the options page
|
||||||
addEventListener('DOMContentLoaded', observer.onDOMReady, true);
|
if (win.location.protocol === 'chrome:' && win.location.host === appName) {
|
||||||
|
initContext(win);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addEventListener('DOMContentLoaded', DOMReady, true);
|
||||||
|
|
||||||
|
addEventListener('unload', function() {
|
||||||
|
Services.obs.removeObserver(observer, 'content-document-global-created');
|
||||||
|
observer = listeners = null;
|
||||||
|
}, false);
|
||||||
|
|
||||||
})();
|
})();
|
@ -2,7 +2,7 @@
|
|||||||
<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">
|
<r:RDF xmlns:r="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.mozilla.org/2004/em-rdf#">
|
||||||
<r:Description about="urn:mozilla:install-manifest">
|
<r:Description about="urn:mozilla:install-manifest">
|
||||||
<id>{2b10c1c8-a11f-4bad-fe9c-1c11e82cac42}</id>
|
<id>{2b10c1c8-a11f-4bad-fe9c-1c11e82cac42}</id>
|
||||||
<version>0.7.0.11</version>
|
<version>0.7.2.0</version>
|
||||||
<name>µBlock</name>
|
<name>µBlock</name>
|
||||||
<description>Finally, an efficient blocker. Easy on CPU and memory.</description>
|
<description>Finally, an efficient blocker. Easy on CPU and memory.</description>
|
||||||
<homepageURL>https://github.com/gorhill/uBlock</homepageURL>
|
<homepageURL>https://github.com/gorhill/uBlock</homepageURL>
|
||||||
|
@ -43,6 +43,13 @@ vAPI.firefox = true;
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.app = {
|
||||||
|
name: 'µBlock',
|
||||||
|
version: '0.7.2.0'
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
var SQLite = {
|
var SQLite = {
|
||||||
open: function() {
|
open: function() {
|
||||||
var path = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
var path = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
||||||
@ -114,10 +121,10 @@ var SQLite = {
|
|||||||
|
|
||||||
vAPI.storage = {
|
vAPI.storage = {
|
||||||
QUOTA_BYTES: 100 * 1024 * 1024,
|
QUOTA_BYTES: 100 * 1024 * 1024,
|
||||||
sqlWhere: function(col, valNum) {
|
sqlWhere: function(col, params) {
|
||||||
if (valNum > 0) {
|
if (params > 0) {
|
||||||
valNum = Array(valNum + 1).join('?, ').slice(0, -2);
|
params = Array(params + 1).join('?, ').slice(0, -2);
|
||||||
return ' WHERE ' + col + ' IN (' + valNum + ')';
|
return ' WHERE ' + col + ' IN (' + params + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@ -165,12 +172,12 @@ vAPI.storage = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
set: function(details, callback) {
|
set: function(details, callback) {
|
||||||
var key, values = [], questionmarks = [];
|
var key, values = [], placeholders = [];
|
||||||
|
|
||||||
for (key in details) {
|
for (key in details) {
|
||||||
values.push(key);
|
values.push(key);
|
||||||
values.push(JSON.stringify(details[key]));
|
values.push(JSON.stringify(details[key]));
|
||||||
questionmarks.push('?, ?');
|
placeholders.push('?, ?');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!values.length) {
|
if (!values.length) {
|
||||||
@ -179,7 +186,7 @@ vAPI.storage = {
|
|||||||
|
|
||||||
SQLite.run(
|
SQLite.run(
|
||||||
'INSERT OR REPLACE INTO settings (name, value) SELECT ' +
|
'INSERT OR REPLACE INTO settings (name, value) SELECT ' +
|
||||||
questionmarks.join(' UNION SELECT '),
|
placeholders.join(' UNION SELECT '),
|
||||||
values,
|
values,
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
@ -205,7 +212,7 @@ vAPI.storage = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SQLite.run(
|
SQLite.run(
|
||||||
"SELECT 'size' AS size, SUM(LENGTH(value)) FROM settings" +
|
'SELECT "size" AS size, SUM(LENGTH(value)) FROM settings' +
|
||||||
this.sqlWhere('name', Array.isArray(keys) ? keys.length : 0),
|
this.sqlWhere('name', Array.isArray(keys) ? keys.length : 0),
|
||||||
keys,
|
keys,
|
||||||
function(result) {
|
function(result) {
|
||||||
@ -217,6 +224,295 @@ vAPI.storage = {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var windowWatcher = {
|
||||||
|
onTabClose: function(e) {
|
||||||
|
vAPI.tabs.onClosed(vAPI.tabs.getTabId(e.target));
|
||||||
|
},
|
||||||
|
onTabSelect: function(e) {
|
||||||
|
console.log(vAPI.tabs.getTabId(e.target));
|
||||||
|
// vAPI.setIcon();
|
||||||
|
},
|
||||||
|
onLoad: function(e) {
|
||||||
|
if (e) {
|
||||||
|
this.removeEventListener('load', windowWatcher.onLoad);
|
||||||
|
}
|
||||||
|
|
||||||
|
var docElement = this.document.documentElement;
|
||||||
|
|
||||||
|
if (docElement.getAttribute('windowtype') !== 'navigator:browser') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.gBrowser || this.gBrowser.tabContainer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tC = this.gBrowser.tabContainer;
|
||||||
|
|
||||||
|
this.gBrowser.addTabsProgressListener(tabsProgressListener);
|
||||||
|
tC.addEventListener('TabClose', windowWatcher.onTabClose);
|
||||||
|
tC.addEventListener('TabSelect', windowWatcher.onTabSelect);
|
||||||
|
|
||||||
|
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||||
|
},
|
||||||
|
unregister: function() {
|
||||||
|
Services.ww.unregisterNotification(this);
|
||||||
|
|
||||||
|
for (var win of vAPI.tabs.getWindows()) {
|
||||||
|
win.removeEventListener('load', this.onLoad);
|
||||||
|
win.gBrowser.removeTabsProgressListener(tabsProgressListener);
|
||||||
|
|
||||||
|
var tC = win.gBrowser.tabContainer;
|
||||||
|
tC.removeEventListener('TabClose', this.onTabClose);
|
||||||
|
tC.removeEventListener('TabSelect', this.onTabSelect);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
observe: function(win, topic) {
|
||||||
|
if (topic === 'domwindowopened') {
|
||||||
|
win.addEventListener('load', this.onLoad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var tabsProgressListener = {
|
||||||
|
onLocationChange: function(browser, webProgress, request, location, flags) {
|
||||||
|
if (!webProgress.isTopLevel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tabId = vAPI.tabs.getTabId(browser);
|
||||||
|
|
||||||
|
if (flags & 1) {
|
||||||
|
vAPI.tabs.onUpdated(tabId, {url: location.spec}, {
|
||||||
|
frameId: 0,
|
||||||
|
tabId: tabId,
|
||||||
|
url: browser.currentURI.spec
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vAPI.tabs.onNavigation({
|
||||||
|
frameId: 0,
|
||||||
|
tabId: tabId,
|
||||||
|
url: location.spec
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs = {};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.registerListeners = function() {
|
||||||
|
// onNavigation and onUpdated handled with tabsProgressListener
|
||||||
|
// onClosed - handled in windowWatcher.onTabClose
|
||||||
|
// onPopup ?
|
||||||
|
|
||||||
|
Services.ww.registerNotification(windowWatcher);
|
||||||
|
|
||||||
|
// already opened windows
|
||||||
|
for (var win of this.getWindows()) {
|
||||||
|
windowWatcher.onLoad.call(win);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.getTabId = function(target) {
|
||||||
|
if (target.linkedPanel) {
|
||||||
|
return target.linkedPanel.slice(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
var gBrowser = target.ownerDocument.defaultView.gBrowser;
|
||||||
|
var i = gBrowser.browsers.indexOf(target);
|
||||||
|
|
||||||
|
if (i !== -1) {
|
||||||
|
i = this.getTabId(gBrowser.tabs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.get = function(tabId, callback) {
|
||||||
|
var tab, windows;
|
||||||
|
|
||||||
|
if (tabId === null) {
|
||||||
|
tab = Services.wm.getMostRecentWindow('navigator:browser').gBrowser.selectedTab;
|
||||||
|
tabId = vAPI.tabs.getTabId(tab);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
windows = this.getWindows();
|
||||||
|
|
||||||
|
for (var win of windows) {
|
||||||
|
tab = win.gBrowser.tabContainer.querySelector(
|
||||||
|
'tab[linkedpanel="panel-' + tabId + '"]'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (tab) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tab) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var browser = tab.linkedBrowser;
|
||||||
|
var gBrowser = browser.ownerDocument.defaultView.gBrowser;
|
||||||
|
|
||||||
|
if (!windows) {
|
||||||
|
windows = this.getWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
callback({
|
||||||
|
id: tabId,
|
||||||
|
index: gBrowser.browsers.indexOf(browser),
|
||||||
|
windowId: windows.indexOf(browser.ownerDocument.defaultView),
|
||||||
|
active: tab === gBrowser.selectedTab,
|
||||||
|
url: browser.currentURI.spec,
|
||||||
|
title: tab.label
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.getAll = function(window) {
|
||||||
|
var tabs = [];
|
||||||
|
|
||||||
|
for (var win of this.getWindows()) {
|
||||||
|
if (window && window !== win) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var tab of win.gBrowser.tabs) {
|
||||||
|
tabs.push(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tabs;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.getWindows = function() {
|
||||||
|
var winumerator = Services.wm.getEnumerator('navigator:browser');
|
||||||
|
var windows = [];
|
||||||
|
|
||||||
|
while (winumerator.hasMoreElements()) {
|
||||||
|
var win = winumerator.getNext();
|
||||||
|
|
||||||
|
if (!win.closed) {
|
||||||
|
windows.push(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return windows;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// properties of the details object:
|
||||||
|
// url: 'URL', // the address that will be opened
|
||||||
|
// tabId: 1, // the tab is used if set, instead of creating a new one
|
||||||
|
// index: -1, // undefined: end of the list, -1: following tab, or after index
|
||||||
|
// active: false, // opens the tab in background - true and undefined: foreground
|
||||||
|
// select: true // if a tab is already opened with that url, then select it instead of opening a new one
|
||||||
|
|
||||||
|
vAPI.tabs.open = function(details) {
|
||||||
|
if (!details.url) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// extension pages
|
||||||
|
if (!/^[\w-]{2,}:/.test(details.url)) {
|
||||||
|
details.url = vAPI.getURL(details.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tab, tabs;
|
||||||
|
|
||||||
|
if (details.select) {
|
||||||
|
var rgxHash = /#.*/;
|
||||||
|
// this is questionable
|
||||||
|
var url = details.url.replace(rgxHash, '');
|
||||||
|
tabs = this.getAll();
|
||||||
|
|
||||||
|
for (tab of tabs) {
|
||||||
|
var browser = tab.linkedBrowser;
|
||||||
|
|
||||||
|
if (browser.currentURI.spec.replace(rgxHash, '') === url) {
|
||||||
|
browser.ownerDocument.defaultView.gBrowser.selectedTab = tab;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.active === undefined) {
|
||||||
|
details.active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var gBrowser = Services.wm.getMostRecentWindow('navigator:browser').gBrowser;
|
||||||
|
|
||||||
|
if (details.index === -1) {
|
||||||
|
details.index = gBrowser.browsers.indexOf(gBrowser.selectedBrowser) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details.tabId) {
|
||||||
|
tabs = tabs || this.getAll();
|
||||||
|
|
||||||
|
for (tab of tabs) {
|
||||||
|
if (vAPI.tabs.getTabId(tab) === details.tabId) {
|
||||||
|
tab.linkedBrowser.loadURI(details.url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tab = gBrowser.loadOneTab(details.url, {inBackground: !details.active});
|
||||||
|
|
||||||
|
if (details.index !== undefined) {
|
||||||
|
gBrowser.moveTabTo(tab, details.index);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.tabs.close = function(tabIds) {
|
||||||
|
if (!Array.isArray(tabIds)) {
|
||||||
|
tabIds = [tabIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
tabIds = tabIds.map(function(tabId) {
|
||||||
|
return 'tab[linkedpanel="panel-' + tabId + '"]';
|
||||||
|
}).join(',');
|
||||||
|
|
||||||
|
for (var win of this.getWindows()) {
|
||||||
|
var tabs = win.gBrowser.tabContainer.querySelectorAll(tabIds);
|
||||||
|
|
||||||
|
if (!tabs) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var tab of tabs) {
|
||||||
|
win.gBrowser.removeTab(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
/*vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||||
|
|
||||||
|
};*/
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.messaging = {
|
vAPI.messaging = {
|
||||||
gmm: Cc['@mozilla.org/globalmessagemanager;1'].getService(Ci.nsIMessageListenerManager),
|
gmm: Cc['@mozilla.org/globalmessagemanager;1'].getService(Ci.nsIMessageListenerManager),
|
||||||
frameScript: 'chrome://ublock/content/frameScript.js',
|
frameScript: 'chrome://ublock/content/frameScript.js',
|
||||||
@ -241,16 +537,17 @@ vAPI.messaging.listen = function(listenerName, callback) {
|
|||||||
vAPI.messaging.onMessage = function(request) {
|
vAPI.messaging.onMessage = function(request) {
|
||||||
var messageManager = request.target.messageManager;
|
var messageManager = request.target.messageManager;
|
||||||
var listenerId = request.data.portName.split('|');
|
var listenerId = request.data.portName.split('|');
|
||||||
|
var requestId = request.data.requestId;
|
||||||
var portName = listenerId[1];
|
var portName = listenerId[1];
|
||||||
listenerId = listenerId[0];
|
listenerId = listenerId[0];
|
||||||
|
|
||||||
var callback = vAPI.messaging.NOOPFUNC;
|
var callback = vAPI.messaging.NOOPFUNC;
|
||||||
if ( request.data.requestId !== undefined ) {
|
if ( requestId !== undefined ) {
|
||||||
callback = function(response) {
|
callback = function(response) {
|
||||||
messageManager.sendAsyncMessage(
|
messageManager.sendAsyncMessage(
|
||||||
listenerId,
|
listenerId,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
requestId: request.data.requestId,
|
requestId: requestId,
|
||||||
portName: portName,
|
portName: portName,
|
||||||
msg: response !== undefined ? response : null
|
msg: response !== undefined ? response : null
|
||||||
})
|
})
|
||||||
@ -258,10 +555,9 @@ vAPI.messaging.onMessage = function(request) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
var sender = {
|
var sender = {
|
||||||
tab: {
|
tab: {
|
||||||
id: 0
|
id: vAPI.tabs.getTabId(request.target)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -316,6 +612,16 @@ vAPI.messaging.broadcast = function(message) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.messaging.unload = function() {
|
||||||
|
this.gmm.removeMessageListener(
|
||||||
|
vAPI.app.name + ':background',
|
||||||
|
this.onMessage
|
||||||
|
);
|
||||||
|
this.gmm.removeDelayedFrameScript(this.frameScript);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.lastError = function() {
|
vAPI.lastError = function() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@ -326,27 +632,18 @@ vAPI.lastError = function() {
|
|||||||
|
|
||||||
window.addEventListener('unload', function() {
|
window.addEventListener('unload', function() {
|
||||||
SQLite.close();
|
SQLite.close();
|
||||||
vAPI.messaging.gmm.removeMessageListener(
|
windowWatcher.unregister();
|
||||||
vAPI.app.name + ':background',
|
vAPI.messaging.unload();
|
||||||
vAPI.messaging.postMessage
|
|
||||||
);
|
|
||||||
vAPI.messaging.gmm.removeDelayedFrameScript(vAPI.messaging.frameScript);
|
|
||||||
|
|
||||||
// close extension tabs
|
// close extension tabs
|
||||||
var enumerator = Services.wm.getEnumerator('navigator:browser');
|
var extURI, win, tab, host = 'ublock';
|
||||||
var host = 'ublock';
|
|
||||||
var gBrowser, tabs, i, extURI;
|
|
||||||
|
|
||||||
while (enumerator.hasMoreElements()) {
|
for (win of vAPI.tabs.getWindows()) {
|
||||||
gBrowser = enumerator.getNext().gBrowser;
|
for (tab of win.gBrowser.tabs) {
|
||||||
tabs = gBrowser.tabs;
|
extURI = tab.linkedBrowser.currentURI;
|
||||||
i = tabs.length;
|
|
||||||
|
|
||||||
while (i--) {
|
|
||||||
extURI = tabs[i].linkedBrowser.currentURI;
|
|
||||||
|
|
||||||
if (extURI.scheme === 'chrome' && extURI.host === host) {
|
if (extURI.scheme === 'chrome' && extURI.host === host) {
|
||||||
gBrowser.removeTab(tabs[i]);
|
win.gBrowser.removeTab(tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ vAPI.messaging = {
|
|||||||
listeners: {},
|
listeners: {},
|
||||||
requestId: 1,
|
requestId: 1,
|
||||||
connectorId: uniqueId(),
|
connectorId: uniqueId(),
|
||||||
|
bgMessageName: 'µBlock:background',
|
||||||
|
|
||||||
setup: function() {
|
setup: function() {
|
||||||
this.connector = function(msg) {
|
this.connector = function(msg) {
|
||||||
@ -124,7 +125,7 @@ vAPI.messaging = {
|
|||||||
vAPI.messaging.listeners[message.requestId] = callback;
|
vAPI.messaging.listeners[message.requestId] = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendAsyncMessage('µBlock:background', message);
|
sendAsyncMessage(vAPI.messaging.bgMessageName, message);
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
delete vAPI.messaging.channels[this.portName];
|
delete vAPI.messaging.channels[this.portName];
|
||||||
|
@ -44,7 +44,14 @@ if ( !matches || matches.length !== 2 ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
messager.send({ what : 'getAssetContent', url: matches[1] }, onAssetContentReceived);
|
uDom.onLoad(function() {
|
||||||
|
messager.send({
|
||||||
|
what: 'getAssetContent',
|
||||||
|
url: matches[1]
|
||||||
|
},
|
||||||
|
onAssetContentReceived
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@ cp -R src/lib $DES/
|
|||||||
cp -R src/_locales $DES/
|
cp -R src/_locales $DES/
|
||||||
cp src/*.html $DES/
|
cp src/*.html $DES/
|
||||||
cp src/img/icon_128.png $DES/icon.png
|
cp src/img/icon_128.png $DES/icon.png
|
||||||
cp platform/vapi-appinfo.js $DES/js/
|
|
||||||
cp platform/firefox/vapi-*.js $DES/js/
|
cp platform/firefox/vapi-*.js $DES/js/
|
||||||
cp platform/firefox/bootstrap.js $DES/
|
cp platform/firefox/bootstrap.js $DES/
|
||||||
cp platform/firefox/frameScript.js $DES/
|
cp platform/firefox/frameScript.js $DES/
|
||||||
cp platform/firefox/chrome.manifest $DES/
|
cp platform/firefox/chrome.manifest $DES/
|
||||||
cp platform/firefox/install.rdf $DES/
|
cp platform/firefox/install.rdf $DES/
|
||||||
|
|
||||||
python tools/xpi-convert-locale.py $DES/
|
echo "*** uBlock_xpi: Generating locales"
|
||||||
|
python tools/make-locale-firefox.py $DES/
|
||||||
|
|
||||||
echo "*** uBlock_xpi: Package done."
|
echo "*** uBlock_xpi: Package done."
|
||||||
|
Loading…
Reference in New Issue
Block a user