mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Firefox/Fennec code cleanup
This commit is contained in:
parent
aa0e713c79
commit
dc8623f1e8
@ -53,6 +53,7 @@ const contentObserver = {
|
|||||||
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
|
||||||
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
contentBaseURI: 'chrome://' + hostName + '/content/js/',
|
||||||
cpMessageName: hostName + ':shouldLoad',
|
cpMessageName: hostName + ':shouldLoad',
|
||||||
|
|
||||||
ignoredPopups: new WeakMap(),
|
ignoredPopups: new WeakMap(),
|
||||||
uniqueSandboxId: 1,
|
uniqueSandboxId: 1,
|
||||||
|
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
</r:Description>
|
</r:Description>
|
||||||
</targetApplication>
|
</targetApplication>
|
||||||
|
|
||||||
<!-- Firefox for Android -->
|
<!-- Fennec -->
|
||||||
<targetApplication>
|
<targetApplication>
|
||||||
<r:Description>
|
<r:Description>
|
||||||
<id>{{aa3c5121-dab2-40e2-81ca-7ea25febc110}}</id>
|
<id>{{aa3c5121-dab2-40e2-81ca-7ea25febc110}}</id>
|
||||||
<minVersion>24.0</minVersion>
|
<minVersion>24.0</minVersion>
|
||||||
<maxVersion>38.0</maxVersion>
|
<maxVersion>39.0</maxVersion>
|
||||||
</r:Description>
|
</r:Description>
|
||||||
</targetApplication>
|
</targetApplication>
|
||||||
|
|
||||||
@ -40,23 +40,5 @@
|
|||||||
<maxVersion>2.36</maxVersion>
|
<maxVersion>2.36</maxVersion>
|
||||||
</r:Description>
|
</r:Description>
|
||||||
</targetApplication>
|
</targetApplication>
|
||||||
|
|
||||||
<!-- Firefox for Android
|
|
||||||
<targetApplication>
|
|
||||||
<r:Description>
|
|
||||||
<id>{{aa3c5121-dab2-40e2-81ca-7ea25febc110}}</id>
|
|
||||||
<minVersion>24.0</minVersion>
|
|
||||||
<maxVersion>39.0</maxVersion>
|
|
||||||
</r:Description>
|
|
||||||
</targetApplication> -->
|
|
||||||
|
|
||||||
<!-- Thunderbird
|
|
||||||
<targetApplication>
|
|
||||||
<r:Description>
|
|
||||||
<id>{{3550f703-e582-4d05-9a08-453d09bdfdc6}}</id>
|
|
||||||
<minVersion>24.0</minVersion>
|
|
||||||
<maxVersion>39.0</maxVersion>
|
|
||||||
</r:Description>
|
|
||||||
</targetApplication> -->
|
|
||||||
</r:Description>
|
</r:Description>
|
||||||
</r:RDF>
|
</r:RDF>
|
||||||
|
@ -38,12 +38,8 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var vAPI = self.vAPI = self.vAPI || {};
|
var vAPI = self.vAPI = self.vAPI || {};
|
||||||
|
|
||||||
vAPI.firefox = true;
|
vAPI.firefox = true;
|
||||||
|
vAPI.fennec = Services.appinfo.ID === '{aa3c5121-dab2-40e2-81ca-7ea25febc110}';
|
||||||
vAPI.fennec = Components.classes["@mozilla.org/xre/app-info;1"]
|
|
||||||
.getService(Components.interfaces.nsIXULAppInfo)
|
|
||||||
.ID == "{aa3c5121-dab2-40e2-81ca-7ea25febc110}";
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
@ -266,23 +262,30 @@ var windowWatcher = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.gBrowser && this.gBrowser.tabContainer ) {
|
var tabContainer;
|
||||||
// desktop Firefox
|
var tabBrowser = getTabBrowser(this);
|
||||||
var tC = this.gBrowser.tabContainer;
|
|
||||||
|
|
||||||
this.gBrowser.addTabsProgressListener(tabWatcher);
|
if ( !tabBrowser ) {
|
||||||
tC.addEventListener('TabClose', tabWatcher.onTabClose);
|
return;
|
||||||
tC.addEventListener('TabSelect', tabWatcher.onTabSelect);
|
|
||||||
|
|
||||||
} else if ( this.BrowserApp && this.BrowserApp.deck ) {
|
|
||||||
// Fennec
|
|
||||||
var deck = this.BrowserApp.deck;
|
|
||||||
|
|
||||||
deck.addEventListener('DOMTitleChanged', tabWatcher.onFennecLocationChange);
|
|
||||||
deck.addEventListener('TabClose', tabWatcher.onTabClose);
|
|
||||||
deck.addEventListener('TabSelect', tabWatcher.onTabSelect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( tabBrowser.deck ) {
|
||||||
|
// Fennec
|
||||||
|
tabContainer = tabBrowser.deck;
|
||||||
|
tabContainer.addEventListener(
|
||||||
|
'DOMTitleChanged',
|
||||||
|
tabWatcher.onFennecLocationChange
|
||||||
|
);
|
||||||
|
} else if ( tabBrowser.tabContainer ) {
|
||||||
|
// desktop Firefox
|
||||||
|
tabContainer = tabBrowser.tabContainer;
|
||||||
|
tabBrowser.addTabsProgressListener(tabWatcher);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
|
||||||
|
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
|
||||||
vAPI.contextMenu.register(this.document);
|
vAPI.contextMenu.register(this.document);
|
||||||
|
|
||||||
// when new window is opened TabSelect doesn't run on the selected tab?
|
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||||
@ -298,26 +301,23 @@ var windowWatcher = {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var tabWatcher = {
|
var tabWatcher = {
|
||||||
onTabClose: function({target: tab}) {
|
SAME_DOCUMENT: Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT,
|
||||||
var tabId = vAPI.tabs.getTabId(tab);
|
|
||||||
|
onTabClose: function({target}) {
|
||||||
|
// target is tab in Firefox, browser in Fennec
|
||||||
|
var tabId = vAPI.tabs.getTabId(target);
|
||||||
vAPI.tabs.onClosed(tabId);
|
vAPI.tabs.onClosed(tabId);
|
||||||
delete vAPI.toolbarButton.tabs[tabId];
|
delete vAPI.toolbarButton.tabs[tabId];
|
||||||
},
|
},
|
||||||
|
|
||||||
onTabSelect: function({target: tab}) {
|
onTabSelect: function({target}) {
|
||||||
var URI = null;
|
// target is tab in Firefox, browser in Fennec
|
||||||
if ( tab.currentURI ) {
|
var URI = (target.linkedBrowser || target).currentURI;
|
||||||
// on Fennec the target is actually the linked browser
|
|
||||||
URI = tab.currentURI;
|
|
||||||
} else {
|
|
||||||
// desktop Firefox
|
|
||||||
URI = tab.linkedBrowser.currentURI;
|
|
||||||
}
|
|
||||||
var aboutPath = URI.schemeIs('about') && URI.path;
|
var aboutPath = URI.schemeIs('about') && URI.path;
|
||||||
var tabId = vAPI.tabs.getTabId(tab);
|
var tabId = vAPI.tabs.getTabId(target);
|
||||||
|
|
||||||
if ( !aboutPath || (aboutPath !== 'blank' && aboutPath !== 'newtab') ) {
|
if ( !aboutPath || (aboutPath !== 'blank' && aboutPath !== 'newtab') ) {
|
||||||
vAPI.setIcon(tabId, tab.ownerDocument.defaultView);
|
vAPI.setIcon(tabId, getOwnerWindow(target));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ var tabWatcher = {
|
|||||||
var tabId = vAPI.tabs.getTabId(browser);
|
var tabId = vAPI.tabs.getTabId(browser);
|
||||||
|
|
||||||
// LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
|
// LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
|
||||||
if ( flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT ) {
|
if ( flags & this.SAME_DOCUMENT ) {
|
||||||
vAPI.tabs.onUpdated(tabId, {url: location.asciiSpec}, {
|
vAPI.tabs.onUpdated(tabId, {url: location.asciiSpec}, {
|
||||||
frameId: 0,
|
frameId: 0,
|
||||||
tabId: tabId,
|
tabId: tabId,
|
||||||
@ -354,23 +354,22 @@ var tabWatcher = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onFennecLocationChange: function(e) {
|
onFennecLocationChange: function({target: doc}) {
|
||||||
// Fennec "equivalent" to onLocationChange
|
// Fennec "equivalent" to onLocationChange
|
||||||
// note that DOMTitleChanged is selected as it fires very early
|
// note that DOMTitleChanged is selected as it fires very early
|
||||||
// (before DOMContentLoaded), and it does fire even if there is no title
|
// (before DOMContentLoaded), and it does fire even if there is no title
|
||||||
|
|
||||||
var tabId = vAPI.tabs.getTabId(e.target);
|
var win = doc.defaultView;
|
||||||
if ( tabId === -1 ) {
|
if ( win !== win.top ) {
|
||||||
// probably not top level
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vAPI.tabs.onNavigation({
|
vAPI.tabs.onNavigation({
|
||||||
frameId: 0,
|
frameId: 0,
|
||||||
tabId: tabId,
|
tabId: getOwnerWindow(win).getTabForWindow(win).id,
|
||||||
url: e.target.location.href
|
url: Services.io.newURI(win.location.href, null, null).asciiSpec
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -383,6 +382,37 @@ vAPI.noTabId = '-1';
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var getTabBrowser = function(win) {
|
||||||
|
return vAPI.fennec && win.BrowserApp || win.gBrowser || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var getBrowserForTab = function(tab) {
|
||||||
|
return vAPI.fennec && tab.browser || tab.linkedBrowser || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var getOwnerWindow = function(target) {
|
||||||
|
if ( target.ownerDocument ) {
|
||||||
|
return target.ownerDocument.defaultView;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fennec
|
||||||
|
for ( var win of vAPI.tabs.getWindows() ) {
|
||||||
|
for ( var tab of win.BrowserApp.tabs) {
|
||||||
|
if ( tab === target || tab.window === target ) {
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.tabs = {};
|
vAPI.tabs = {};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -405,37 +435,36 @@ vAPI.tabs.registerListeners = function() {
|
|||||||
vAPI.contextMenu.unregister(win.document);
|
vAPI.contextMenu.unregister(win.document);
|
||||||
win.removeEventListener('DOMContentLoaded', windowWatcher.onReady);
|
win.removeEventListener('DOMContentLoaded', windowWatcher.onReady);
|
||||||
|
|
||||||
if ( win.gBrowser && win.gBrowser.tabContainer ) {
|
var tabContainer;
|
||||||
// desktop Firefox
|
var tabBrowser = getTabBrowser(win);
|
||||||
var tC = win.gBrowser.tabContainer;
|
if ( !tabBrowser ) {
|
||||||
|
continue;
|
||||||
win.gBrowser.removeTabsProgressListener(tabWatcher);
|
|
||||||
tC.removeEventListener('TabClose', tabWatcher.onTabClose);
|
|
||||||
tC.removeEventListener('TabSelect', tabWatcher.onTabSelect);
|
|
||||||
|
|
||||||
// close extension tabs
|
|
||||||
for ( var tab of win.gBrowser.tabs ) {
|
|
||||||
var URI = tab.linkedBrowser.currentURI;
|
|
||||||
|
|
||||||
if ( URI.schemeIs('chrome') && URI.host === location.host ) {
|
|
||||||
win.gBrowser.removeTab(tab);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if ( win.BrowserApp && win.BrowserApp.deck ) {
|
if ( tabBrowser.deck ) {
|
||||||
// Fennec
|
// Fennec
|
||||||
var deck = win.BrowserApp.deck;
|
tabContainer = tabBrowser.deck;
|
||||||
|
tabContainer.removeEventListener(
|
||||||
deck.removeEventListener('DOMTitleChanged', tabWatcher.onFennecLocationChange);
|
'DOMTitleChanged',
|
||||||
deck.removeEventListener('TabClose', tabWatcher.onTabClose);
|
tabWatcher.onFennecLocationChange
|
||||||
deck.removeEventListener('TabSelect', tabWatcher.onTabSelect);
|
);
|
||||||
|
} else if ( tabBrowser.tabContainer ) {
|
||||||
// close extension tabs
|
tabContainer = tabBrowser.tabContainer;
|
||||||
for ( var tab of win.BrowserApp.tabs ) {
|
tabBrowser.removeTabsProgressListener(tabWatcher);
|
||||||
var URI = tab.browser.currentURI;
|
|
||||||
|
|
||||||
if ( URI.schemeIs('chrome') && URI.host === location.host ) {
|
|
||||||
win.BrowserApp.closeTab(tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tabContainer.removeEventListener('TabClose', tabWatcher.onTabClose);
|
||||||
|
tabContainer.removeEventListener('TabSelect', tabWatcher.onTabSelect);
|
||||||
|
|
||||||
|
// Close extension tabs
|
||||||
|
for ( var tab of tabBrowser.tabs ) {
|
||||||
|
var browser = getBrowserForTab(tab);
|
||||||
|
if ( browser === null ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var URI = browser.currentURI;
|
||||||
|
if ( URI.schemeIs('chrome') && URI.host === location.host ) {
|
||||||
|
vAPI.tabs._remove(tab, win);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,26 +475,20 @@ vAPI.tabs.registerListeners = function() {
|
|||||||
|
|
||||||
vAPI.tabs.getTabId = function(target) {
|
vAPI.tabs.getTabId = function(target) {
|
||||||
if ( vAPI.fennec ) {
|
if ( vAPI.fennec ) {
|
||||||
// Fennec
|
|
||||||
|
|
||||||
if ( target.browser ) {
|
if ( target.browser ) {
|
||||||
// target is a tab
|
// target is a tab
|
||||||
return target.id;
|
return target.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// target is a browser or contentDocument
|
for ( var win of this.getWindows() ) {
|
||||||
for ( var win of vAPI.tabs.getWindows() ) {
|
var tab = win.BrowserApp.getTabForBrowser(target);
|
||||||
for ( var tab of win.BrowserApp.tabs ) {
|
if ( tab && tab.id ) {
|
||||||
if ( target === tab.browser ||
|
|
||||||
target === tab.window.document ) {
|
|
||||||
return tab.id;
|
return tab.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
} else {
|
return -1;
|
||||||
// desktop Firefox
|
}
|
||||||
|
|
||||||
if ( target.linkedPanel ) {
|
if ( target.linkedPanel ) {
|
||||||
// target is a tab
|
// target is a tab
|
||||||
@ -473,7 +496,8 @@ vAPI.tabs.getTabId = function(target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// target is a browser
|
// target is a browser
|
||||||
var i, gBrowser = target.ownerDocument.defaultView.gBrowser;
|
var i;
|
||||||
|
var gBrowser = getOwnerWindow(target).gBrowser;
|
||||||
|
|
||||||
if ( !gBrowser ) {
|
if ( !gBrowser ) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -496,7 +520,39 @@ vAPI.tabs.getTabId = function(target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// If tabIds is an array, then an array of tabs will be returned,
|
||||||
|
// otherwise a single tab
|
||||||
|
|
||||||
|
vAPI.tabs.getTabsForIds = function(tabIds, tabBrowser) {
|
||||||
|
var tabId;
|
||||||
|
var tabs = [];
|
||||||
|
var singleTab = !Array.isArray(tabIds);
|
||||||
|
|
||||||
|
if ( singleTab ) {
|
||||||
|
tabIds = [tabIds];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( vAPI.fennec ) {
|
||||||
|
for ( tabId of tabIds ) {
|
||||||
|
var tab = tabBrowser.getTabForId(tabId);
|
||||||
|
if ( tab ) {
|
||||||
|
tabs.push(tab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var query = [];
|
||||||
|
for ( tabId of tabIds ) {
|
||||||
|
query.push('tab[linkedpanel="' + tabId + '"]');
|
||||||
|
}
|
||||||
|
query = query.join(',');
|
||||||
|
tabs = [].slice.call(tabBrowser.tabContainer.querySelectorAll(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
return singleTab ? tabs[0] || null : tabs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -506,38 +562,16 @@ vAPI.tabs.get = function(tabId, callback) {
|
|||||||
|
|
||||||
if ( tabId === null ) {
|
if ( tabId === null ) {
|
||||||
win = Services.wm.getMostRecentWindow('navigator:browser');
|
win = Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
if ( win.gBrowser ) {
|
tab = getTabBrowser(win).selectedTab;
|
||||||
// desktop Firefox
|
tabId = this.getTabId(tab);
|
||||||
tab = win.gBrowser.selectedTab;
|
|
||||||
} else if ( win.BrowserApp ) {
|
|
||||||
// Fennec
|
|
||||||
tab = win.BrowserApp.selectedTab;
|
|
||||||
}
|
|
||||||
tabId = vAPI.tabs.getTabId(tab);
|
|
||||||
} else {
|
} else {
|
||||||
windows = this.getWindows();
|
windows = this.getWindows();
|
||||||
|
|
||||||
if ( vAPI.fennec ) {
|
|
||||||
// Fennec
|
|
||||||
for ( win of windows ) {
|
for ( win of windows ) {
|
||||||
tab = win.BrowserApp.getTabForId(tabId);
|
tab = vAPI.tabs.getTabsForIds(tabId, getTabBrowser(win));
|
||||||
|
|
||||||
if ( tab ) {
|
if ( tab ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// desktop Firefox
|
|
||||||
for ( win of windows ) {
|
|
||||||
tab = win.gBrowser.tabContainer.querySelector(
|
|
||||||
'tab[linkedpanel="' + tabId + '"]'
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( tab ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for internal use
|
// for internal use
|
||||||
@ -550,63 +584,43 @@ vAPI.tabs.get = function(tabId, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( tab.linkedBrowser ) {
|
|
||||||
// desktop Firefox
|
|
||||||
var browser = tab.linkedBrowser;
|
|
||||||
var gBrowser = win.gBrowser;
|
|
||||||
|
|
||||||
if ( !windows ) {
|
if ( !windows ) {
|
||||||
windows = this.getWindows();
|
windows = this.getWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var browser = getBrowserForTab(tab);
|
||||||
|
var tabBrowser = getTabBrowser(win);
|
||||||
|
var tabIndex = vAPI.fennec
|
||||||
|
? tabBrowser.tabs.indexOf(tab)
|
||||||
|
: tabBrowser.browsers.indexOf(browser);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
id: tabId,
|
id: tabId,
|
||||||
index: gBrowser.browsers.indexOf(browser),
|
index: tabIndex,
|
||||||
windowId: windows.indexOf(win),
|
windowId: windows.indexOf(win),
|
||||||
active: tab === gBrowser.selectedTab,
|
active: tab === tabBrowser.selectedTab,
|
||||||
url: browser.currentURI.asciiSpec,
|
url: browser.currentURI.asciiSpec,
|
||||||
title: tab.label
|
title: tab.label
|
||||||
});
|
});
|
||||||
} else if ( tab.browser ) {
|
|
||||||
// Fennec
|
|
||||||
var browser = tab.browser;
|
|
||||||
var BrowserApp = win.BrowserApp;
|
|
||||||
|
|
||||||
if ( !windows ) {
|
|
||||||
windows = this.getWindows();
|
|
||||||
}
|
|
||||||
|
|
||||||
callback({
|
|
||||||
id: tabId,
|
|
||||||
index: BrowserApp.tabs.indexOf(tab),
|
|
||||||
windowId: windows.indexOf(win),
|
|
||||||
active: tab === BrowserApp.selectedTab,
|
|
||||||
url: browser.currentURI.asciiSpec,
|
|
||||||
title: browser.contentDocument.title
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.tabs.getAll = function(window) {
|
vAPI.tabs.getAll = function(window) {
|
||||||
var win, tab, tabs = [];
|
var win, tab;
|
||||||
|
var tabs = [];
|
||||||
|
|
||||||
for ( win of this.getWindows() ) {
|
for ( win of this.getWindows() ) {
|
||||||
if ( window && window !== win ) {
|
if ( window && window !== win ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tabList;
|
var tabBrowser = getTabBrowser(win);
|
||||||
if ( win.gBrowser ) {
|
if ( tabBrowser === null ) {
|
||||||
// desktop Firefox
|
continue;
|
||||||
tabList = win.gBrowser.tabs;
|
|
||||||
} else {
|
|
||||||
// Fennec
|
|
||||||
tabList = win.BrowserApp.tabs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( tab of tabList ) {
|
for ( tab of tabBrowser.tabs ) {
|
||||||
tabs.push(tab);
|
tabs.push(tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,88 +663,71 @@ vAPI.tabs.open = function(details) {
|
|||||||
details.url = vAPI.getURL(details.url);
|
details.url = vAPI.getURL(details.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
var tab, tabs;
|
var win, tab, tabBrowser;
|
||||||
|
|
||||||
if ( details.select ) {
|
if ( details.select ) {
|
||||||
var URI = Services.io.newURI(details.url, null, null);
|
var URI = Services.io.newURI(details.url, null, null);
|
||||||
tabs = this.getAll();
|
|
||||||
|
|
||||||
for ( tab of tabs ) {
|
for ( tab of this.getAll() ) {
|
||||||
var browser;
|
var browser = getBrowserForTab(tab);
|
||||||
if ( tab.linkedBrowser ) {
|
|
||||||
// desktop Firefox
|
|
||||||
browser = tab.linkedBrowser;
|
|
||||||
} else {
|
|
||||||
// Fennec
|
|
||||||
browser = tab.browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or simply .equals if we care about the fragment
|
// Or simply .equals if we care about the fragment
|
||||||
if ( URI.equalsExceptRef(browser.currentURI) ) {
|
if ( URI.equalsExceptRef(browser.currentURI) === false ) {
|
||||||
var win = browser.ownerDocument.defaultView;
|
continue;
|
||||||
if ( win.gBrowser ) {
|
}
|
||||||
// desktop Firefox
|
|
||||||
win.gBrowser.selectedTab = tab;
|
tabBrowser = getTabBrowser(getOwnerWindow(tab));
|
||||||
|
if ( vAPI.fennec ) {
|
||||||
|
tabBrowser.selectTab(tab);
|
||||||
} else {
|
} else {
|
||||||
// Fennec
|
tabBrowser.selectedTab = tab;
|
||||||
win.BrowserApp.selectTab(tab);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( details.active === undefined ) {
|
if ( details.active === undefined ) {
|
||||||
details.active = true;
|
details.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var win = Services.wm.getMostRecentWindow('navigator:browser');
|
|
||||||
if ( win.gBrowser ) {
|
|
||||||
// desktop Firefox
|
|
||||||
var gBrowser = win.gBrowser;
|
|
||||||
|
|
||||||
if ( details.index === -1 ) {
|
|
||||||
details.index = gBrowser.browsers.indexOf(gBrowser.selectedBrowser) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( details.tabId ) {
|
if ( details.tabId ) {
|
||||||
tabs = tabs || this.getAll();
|
for ( win in this.getWindows() ) {
|
||||||
|
tab = this.getTabsForIds(details.tabId, win);
|
||||||
for ( tab of tabs ) {
|
if ( tab ) {
|
||||||
if ( vAPI.tabs.getTabId(tab) === details.tabId ) {
|
getBrowserForTab(tab).loadURI(details.url);
|
||||||
tab.linkedBrowser.loadURI(details.url);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tab = gBrowser.loadOneTab(details.url, {inBackground: !details.active});
|
win = Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
|
tabBrowser = getTabBrowser(win);
|
||||||
|
|
||||||
|
if ( vAPI.fennec ) {
|
||||||
|
tabBrowser.addTab(details.url, {selected: details.active !== false});
|
||||||
|
// Note that it's impossible to move tabs on Fennec, so don't bother
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( details.index === -1 ) {
|
||||||
|
details.index = tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tab = tabBrowser.loadOneTab(details.url, {inBackground: !details.active});
|
||||||
|
|
||||||
if ( details.index !== undefined ) {
|
if ( details.index !== undefined ) {
|
||||||
gBrowser.moveTabTo(tab, details.index);
|
tabBrowser.moveTabTo(tab, details.index);
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
// Fennec
|
|
||||||
var BrowserApp = win.BrowserApp;
|
|
||||||
|
|
||||||
if ( details.index === -1 ) {
|
/******************************************************************************/
|
||||||
details.index = BrowserApp.tabs.indexOf(gBrowser.selectedTab) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( details.tabId ) {
|
vAPI.tabs._remove = function(tab, tabBrowser) {
|
||||||
tabs = tabs || this.getAll();
|
if ( vAPI.fennec ) {
|
||||||
|
tabBrowser.closeTab(tab);
|
||||||
tab = BrowserApp.getTabForId(details.tabId);
|
|
||||||
if ( tab ) {
|
|
||||||
tab.browser.loadURI(details.url);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
tabBrowser.removeTab(tab);
|
||||||
|
|
||||||
tab = BrowserApp.addTab(details.url, {selected: details.active});
|
|
||||||
|
|
||||||
// note that it's impossible to move tabs on Fennec, so don't bother
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -740,35 +737,14 @@ vAPI.tabs.remove = function(tabIds) {
|
|||||||
tabIds = [tabIds];
|
tabIds = [tabIds];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( vAPI.fennec ) {
|
|
||||||
// Fennec
|
|
||||||
for ( var win of this.getWindows() ) {
|
for ( var win of this.getWindows() ) {
|
||||||
var tabs = win.BrowserApp.tabs;
|
var tabBrowser = getTabBrowser(win);
|
||||||
|
var tabs = this.getTabsForIds(tabIds, tabBrowser);
|
||||||
if ( !tabs ) {
|
if ( !tabs ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( var tab of tabs ) {
|
for ( var tab of tabs ) {
|
||||||
if ( tab.id in tabIds ) {
|
this._remove(tab, tabBrowser);
|
||||||
win.BrowserApp.closeTab(tab);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// desktop Firefox
|
|
||||||
tabIds = tabIds.map(function(tabId) {
|
|
||||||
return 'tab[linkedpanel="' + 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -778,21 +754,22 @@ vAPI.tabs.remove = function(tabIds) {
|
|||||||
vAPI.tabs.reload = function(tabId) {
|
vAPI.tabs.reload = function(tabId) {
|
||||||
var tab = this.get(tabId);
|
var tab = this.get(tabId);
|
||||||
|
|
||||||
if ( tab ) {
|
if ( !tab ) {
|
||||||
if ( tab.browser ) {
|
return;
|
||||||
// Fennec
|
}
|
||||||
|
|
||||||
|
if ( vAPI.fennec ) {
|
||||||
tab.browser.reload();
|
tab.browser.reload();
|
||||||
} else {
|
return;
|
||||||
// desktop Firefox
|
|
||||||
tab.ownerDocument.defaultView.gBrowser.reloadTab(tab);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOwnerWindow(tab).gBrowser.reloadTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.tabs.injectScript = function(tabId, details, callback) {
|
vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||||
var tab = vAPI.tabs.get(tabId);
|
var tab = this.get(tabId);
|
||||||
|
|
||||||
if ( !tab ) {
|
if ( !tab ) {
|
||||||
return;
|
return;
|
||||||
@ -827,17 +804,8 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
|
|||||||
var win = badge === undefined
|
var win = badge === undefined
|
||||||
? iconStatus
|
? iconStatus
|
||||||
: Services.wm.getMostRecentWindow('navigator:browser');
|
: Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
|
var curTabId = vAPI.tabs.getTabId(getTabBrowser(win).selectedTab);
|
||||||
var tb = vAPI.toolbarButton;
|
var tb = vAPI.toolbarButton;
|
||||||
var selectedTab, curTabId;
|
|
||||||
|
|
||||||
if ( win.gBrowser ) {
|
|
||||||
// desktop Firefox
|
|
||||||
selectedTab = win.gBrowser.selectedTab;
|
|
||||||
} else {
|
|
||||||
// Fennec
|
|
||||||
selectedTab = win.BrowserApp.selectedTab;
|
|
||||||
}
|
|
||||||
curTabId = vAPI.tabs.getTabId(selectedTab);
|
|
||||||
|
|
||||||
// from 'TabSelect' event
|
// from 'TabSelect' event
|
||||||
if ( tabId === undefined ) {
|
if ( tabId === undefined ) {
|
||||||
@ -897,9 +865,9 @@ vAPI.messaging.onMessage = function({target, data}) {
|
|||||||
if ( !messageManager ) {
|
if ( !messageManager ) {
|
||||||
// Message came from a popup, and its message manager is not usable.
|
// Message came from a popup, and its message manager is not usable.
|
||||||
// So instead we broadcast to the parent window.
|
// So instead we broadcast to the parent window.
|
||||||
messageManager = target
|
messageManager = getOwnerWindow(
|
||||||
.webNavigation.QueryInterface(Ci.nsIDocShell)
|
target.webNavigation.QueryInterface(Ci.nsIDocShell).chromeEventHandler
|
||||||
.chromeEventHandler.ownerDocument.defaultView.messageManager;
|
).messageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
var channelNameRaw = data.channelName;
|
var channelNameRaw = data.channelName;
|
||||||
@ -1430,8 +1398,9 @@ vAPI.toolbarButton = {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.toolbarButton.init = function() {
|
vAPI.toolbarButton.init = function() {
|
||||||
|
var CustomizableUI;
|
||||||
try {
|
try {
|
||||||
var {CustomizableUI} = Cu.import('resource:///modules/CustomizableUI.jsm', null);
|
CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1468,6 +1437,7 @@ vAPI.toolbarButton.init = function() {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.CUIEvents = {};
|
this.CUIEvents = {};
|
||||||
|
|
||||||
this.CUIEvents.onCustomizeEnd = function() {
|
this.CUIEvents.onCustomizeEnd = function() {
|
||||||
var wId = vAPI.toolbarButton.id;
|
var wId = vAPI.toolbarButton.id;
|
||||||
var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL;
|
var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL;
|
||||||
@ -1489,8 +1459,9 @@ vAPI.toolbarButton.init = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Anonymous elements need some time to be reachable
|
// Anonymous elements need some time to be reachable
|
||||||
setTimeout(this.updateBadgeStyle, 0);
|
setTimeout(this.updateBadgeStyle, 250);
|
||||||
}.bind(this.CUIEvents);
|
}.bind(this.CUIEvents);
|
||||||
|
|
||||||
this.CUIEvents.updateBadgeStyle = function() {
|
this.CUIEvents.updateBadgeStyle = function() {
|
||||||
var css = [
|
var css = [
|
||||||
'background: #666',
|
'background: #666',
|
||||||
@ -1517,7 +1488,7 @@ vAPI.toolbarButton.init = function() {
|
|||||||
|
|
||||||
this.onCreated = function(button) {
|
this.onCreated = function(button) {
|
||||||
button.setAttribute('badge', '');
|
button.setAttribute('badge', '');
|
||||||
setTimeout(this.CUIEvents.onCustomizeEnd, 0);
|
setTimeout(this.CUIEvents.onCustomizeEnd, 250);
|
||||||
};
|
};
|
||||||
|
|
||||||
CustomizableUI.addListener(this.CUIEvents);
|
CustomizableUI.addListener(this.CUIEvents);
|
||||||
@ -1650,8 +1621,8 @@ vAPI.contextMenu = {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
vAPI.contextMenu.displayMenuItem = function(e) {
|
vAPI.contextMenu.displayMenuItem = function({target}) {
|
||||||
var doc = e.target.ownerDocument;
|
var doc = target.ownerDocument;
|
||||||
var gContextMenu = doc.defaultView.gContextMenu;
|
var gContextMenu = doc.defaultView.gContextMenu;
|
||||||
|
|
||||||
if ( !gContextMenu.browser ) {
|
if ( !gContextMenu.browser ) {
|
||||||
@ -1702,17 +1673,15 @@ vAPI.contextMenu.register = function(doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( vAPI.fennec ) {
|
if ( vAPI.fennec ) {
|
||||||
// Fennec
|
// TODO https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/NativeWindow/contextmenus/add
|
||||||
// TODO
|
/*var nativeWindow = doc.defaultView.NativeWindow;
|
||||||
/*
|
|
||||||
var nativeWindow = doc.defaultView.NativeWindow;
|
|
||||||
contextId = nativeWindow.contextmenus.add(
|
contextId = nativeWindow.contextmenus.add(
|
||||||
this.menuLabel,
|
this.menuLabel,
|
||||||
nativeWindow.contextmenus.linkOpenableContext, // TODO https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/NativeWindow/contextmenus/add
|
nativeWindow.contextmenus.linkOpenableContext,
|
||||||
this.onCommand);
|
this.onCommand
|
||||||
*/
|
);*/
|
||||||
} else {
|
return;
|
||||||
// desktop Firefox
|
}
|
||||||
|
|
||||||
var contextMenu = doc.getElementById('contentAreaContextMenu');
|
var contextMenu = doc.getElementById('contentAreaContextMenu');
|
||||||
var menuitem = doc.createElement('menuitem');
|
var menuitem = doc.createElement('menuitem');
|
||||||
@ -1723,7 +1692,6 @@ vAPI.contextMenu.register = function(doc) {
|
|||||||
menuitem.addEventListener('command', this.onCommand);
|
menuitem.addEventListener('command', this.onCommand);
|
||||||
contextMenu.addEventListener('popupshowing', this.displayMenuItem);
|
contextMenu.addEventListener('popupshowing', this.displayMenuItem);
|
||||||
contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator'));
|
contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator'));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -1734,17 +1702,15 @@ vAPI.contextMenu.unregister = function(doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( vAPI.fennec ) {
|
if ( vAPI.fennec ) {
|
||||||
// Fennec
|
|
||||||
// TODO
|
// TODO
|
||||||
} else {
|
return;
|
||||||
// desktop Firefox
|
}
|
||||||
|
|
||||||
var menuitem = doc.getElementById(this.menuItemId);
|
var menuitem = doc.getElementById(this.menuItemId);
|
||||||
var contextMenu = menuitem.parentNode;
|
var contextMenu = menuitem.parentNode;
|
||||||
menuitem.removeEventListener('command', this.onCommand);
|
menuitem.removeEventListener('command', this.onCommand);
|
||||||
contextMenu.removeEventListener('popupshowing', this.displayMenuItem);
|
contextMenu.removeEventListener('popupshowing', this.displayMenuItem);
|
||||||
contextMenu.removeChild(menuitem);
|
contextMenu.removeChild(menuitem);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -1762,13 +1728,14 @@ vAPI.contextMenu.create = function(details, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.onCommand = function() {
|
this.onCommand = function() {
|
||||||
var gContextMenu = this.ownerDocument.defaultView.gContextMenu;
|
var gContextMenu = getOwnerWindow(this).gContextMenu;
|
||||||
var details = {
|
var details = {
|
||||||
menuItemId: this.id
|
menuItemId: this.id
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( gContextMenu.inFrame ) {
|
if ( gContextMenu.inFrame ) {
|
||||||
details.tagName = 'iframe';
|
details.tagName = 'iframe';
|
||||||
|
// Probably won't work with e01s
|
||||||
details.frameUrl = gContextMenu.focusedWindow.location.href;
|
details.frameUrl = gContextMenu.focusedWindow.location.href;
|
||||||
} else if ( gContextMenu.onImage ) {
|
} else if ( gContextMenu.onImage ) {
|
||||||
details.tagName = 'img';
|
details.tagName = 'img';
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
vAPI.storage = {
|
vAPI.storage = {
|
||||||
_storage: safari.extension.settings,
|
_storage: safari.extension.settings,
|
||||||
QUOTA_BYTES: 52428800, // copied from Info.plist
|
QUOTA_BYTES: 104857600, // copied from Info.plist
|
||||||
|
|
||||||
get: function(keys, callback) {
|
get: function(keys, callback) {
|
||||||
if(typeof callback !== 'function') {
|
if(typeof callback !== 'function') {
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# This script assumes a linux environment
|
|
||||||
|
|
||||||
echo "*** uBlock.fennec: Copying files"
|
|
||||||
|
|
||||||
DES=dist/build/uBlock.fennec
|
|
||||||
rm -rf $DES
|
|
||||||
mkdir -p $DES
|
|
||||||
|
|
||||||
cp -R assets $DES/
|
|
||||||
rm $DES/assets/*.sh
|
|
||||||
cp -R src/css $DES/
|
|
||||||
cp -R src/img $DES/
|
|
||||||
cp -R src/js $DES/
|
|
||||||
cp -R src/lib $DES/
|
|
||||||
cp -R src/_locales $DES/
|
|
||||||
cp src/*.html $DES/
|
|
||||||
mv $DES/img/icon_128.png $DES/icon.png
|
|
||||||
cp platform/firefox/vapi-*.js $DES/js/
|
|
||||||
cp platform/firefox/bootstrap.js $DES/
|
|
||||||
cp platform/firefox/frame*.js $DES/
|
|
||||||
cp platform/firefox/chrome.manifest $DES/
|
|
||||||
cp platform/firefox/install.rdf $DES/
|
|
||||||
cp platform/fennec/vapi-*.js $DES/
|
|
||||||
cp LICENSE.txt $DES/
|
|
||||||
|
|
||||||
echo "*** uBlock.fennec: Generating meta..."
|
|
||||||
python tools/make-firefox-meta.py $DES/
|
|
||||||
|
|
||||||
if [ "$1" = all ]; then
|
|
||||||
echo "*** uBlock.fennec: Creating package..."
|
|
||||||
pushd $DES/
|
|
||||||
zip ../uBlock.fennec.xpi -qr *
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "*** uBlock.fennec: Package done."
|
|
Loading…
Reference in New Issue
Block a user