mirror of https://github.com/gorhill/uBlock.git
Initial UI support for Fennec
This commit is contained in:
parent
2349df9cbb
commit
2b60436ece
|
@ -44,6 +44,25 @@ const restartListener = {
|
|||
}
|
||||
};
|
||||
|
||||
const optionsObserver = {
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
if (aTopic === "addon-options-displayed" && aData === "{2b10c1c8-a11f-4bad-fe9c-1c11e82cac42}") {
|
||||
var doc = aSubject;
|
||||
setupOptionsButton(doc, "showDashboardButton", "dashboard.html");
|
||||
setupOptionsButton(doc, "showNetworkLogButton", "devtools.html");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function setupOptionsButton(doc, id, page) {
|
||||
var vAPI = bgProcess.contentWindow.vAPI;
|
||||
var button = doc.getElementById(id);
|
||||
button.addEventListener("command", function () {
|
||||
vAPI.tabs.open({ url: vAPI.getURL(page), index: -1 });
|
||||
});
|
||||
button.label = vAPI.i18n(id);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
function startup(data, reason) {
|
||||
|
@ -74,6 +93,10 @@ function startup(data, reason) {
|
|||
);
|
||||
};
|
||||
|
||||
let obs = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
obs.addObserver(optionsObserver, "addon-options-displayed", false);
|
||||
|
||||
if (reason !== APP_STARTUP) {
|
||||
onReady();
|
||||
return;
|
||||
|
@ -118,6 +141,10 @@ function shutdown(data, reason) {
|
|||
hostName + '-restart',
|
||||
restartListener
|
||||
);
|
||||
|
||||
let obs = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
obs.removeObserver(optionsObserver, "addon-options-displayed");
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
<type>2</type>
|
||||
<bootstrap>true</bootstrap>
|
||||
<multiprocessCompatible>true</multiprocessCompatible>
|
||||
<optionsType>3</optionsType>
|
||||
<optionsURL>chrome://ublock/content/dashboard.html</optionsURL>
|
||||
<optionsType>2</optionsType>
|
||||
{localized}
|
||||
|
||||
<!-- Firefox -->
|
||||
|
|
|
@ -269,17 +269,20 @@ var windowWatcher = {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( tabBrowser.tabContainer ) {
|
||||
if ( tabBrowser.deck ) {
|
||||
// Fennec
|
||||
tabContainer = tabBrowser.deck;
|
||||
} else if ( tabBrowser.tabContainer ) {
|
||||
// desktop Firefox
|
||||
tabContainer = tabBrowser.tabContainer;
|
||||
tabBrowser.addTabsProgressListener(tabWatcher);
|
||||
vAPI.contextMenu.register(this.document);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
|
||||
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
|
||||
vAPI.contextMenu.register(this.document);
|
||||
|
||||
// when new window is opened TabSelect doesn't run on the selected tab?
|
||||
},
|
||||
|
@ -417,7 +420,10 @@ vAPI.tabs.registerListeners = function() {
|
|||
continue;
|
||||
}
|
||||
|
||||
if ( tabBrowser.tabContainer ) {
|
||||
if ( tabBrowser.deck ) {
|
||||
// Fennec
|
||||
tabContainer = tabBrowser.deck;
|
||||
} else if ( tabBrowser.tabContainer ) {
|
||||
tabContainer = tabBrowser.tabContainer;
|
||||
tabBrowser.removeTabsProgressListener(tabWatcher);
|
||||
}
|
||||
|
@ -740,6 +746,24 @@ vAPI.tabs.reload = function(tabId) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.select = function(tabId) {
|
||||
var tab = this.get(tabId);
|
||||
|
||||
if ( !tab ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tabBrowser = getTabBrowser(getOwnerWindow(tab));
|
||||
|
||||
if (vAPI.fennec) {
|
||||
tabBrowser.selectTab(tab);
|
||||
} else {
|
||||
tabBrowser.selectedTab = tab;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.tabs.injectScript = function(tabId, details, callback) {
|
||||
var tab = this.get(tabId);
|
||||
|
||||
|
@ -752,7 +776,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
|
|||
}
|
||||
|
||||
details.file = vAPI.getURL(details.file);
|
||||
tab.linkedBrowser.messageManager.sendAsyncMessage(
|
||||
getBrowserForTab(tab).messageManager.sendAsyncMessage(
|
||||
location.host + ':broadcast',
|
||||
JSON.stringify({
|
||||
broadcast: true,
|
||||
|
@ -790,23 +814,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
|
|||
return;
|
||||
}
|
||||
|
||||
var button = win.document.getElementById(tb.id);
|
||||
|
||||
if ( !button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var icon = tb.tabs[tabId];
|
||||
button.setAttribute('badge', icon && icon.badge || '');
|
||||
|
||||
if ( !icon || !icon.img ) {
|
||||
icon = '';
|
||||
}
|
||||
else {
|
||||
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
|
||||
}
|
||||
|
||||
button.style.listStyleImage = icon;
|
||||
tb.updateState(win, tabId);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -995,6 +1003,7 @@ var httpObserver = {
|
|||
classDescription: 'net-channel-event-sinks for ' + location.host,
|
||||
classID: Components.ID('{dc8d6319-5f6e-4438-999e-53722db99e84}'),
|
||||
contractID: '@' + location.host + '/net-channel-event-sinks;1',
|
||||
REQDATAKEY: location.host + 'reqdata',
|
||||
ABORT: Components.results.NS_BINDING_ABORTED,
|
||||
ACCEPT: Components.results.NS_SUCCEEDED,
|
||||
// Request types: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy#Constants
|
||||
|
@ -1141,9 +1150,6 @@ var httpObserver = {
|
|||
return;
|
||||
}
|
||||
|
||||
var reqDataKey = location.host + 'reqdata';
|
||||
|
||||
|
||||
var URI = channel.URI;
|
||||
var channelData, result;
|
||||
|
||||
|
@ -1160,7 +1166,7 @@ var httpObserver = {
|
|||
frameId,
|
||||
parentFrameId
|
||||
]*/
|
||||
channelData = channel.getProperty(reqDataKey);
|
||||
channelData = channel.getProperty(this.REQDATAKEY);
|
||||
} catch (ex) {
|
||||
return;
|
||||
}
|
||||
|
@ -1258,7 +1264,7 @@ var httpObserver = {
|
|||
// If request is not handled we may use the data in on-modify-request
|
||||
if ( channel instanceof Ci.nsIWritablePropertyBag ) {
|
||||
channel.setProperty(
|
||||
reqDataKey,
|
||||
this.REQDATAKEY,
|
||||
[
|
||||
lastRequest.type,
|
||||
lastRequest.tabId,
|
||||
|
@ -1295,7 +1301,7 @@ var httpObserver = {
|
|||
// TODO: what if a behind-the-scene request is being redirected?
|
||||
// This data is present only for tabbed requests, so if this throws,
|
||||
// the redirection won't be evaluated and canceled (if necessary)
|
||||
var channelData = oldChannel.getProperty(location.host + 'reqdata');
|
||||
var channelData = oldChannel.getProperty(this.REQDATAKEY);
|
||||
|
||||
if ( this.handlePopup(URI, channelData[1], channelData[2]) ) {
|
||||
result = this.ABORT;
|
||||
|
@ -1316,7 +1322,7 @@ var httpObserver = {
|
|||
|
||||
// Carry the data on in case of multiple redirects
|
||||
if ( newChannel instanceof Ci.nsIWritablePropertyBag ) {
|
||||
newChannel.setProperty(location.host + 'reqdata', channelData);
|
||||
newChannel.setProperty(this.REQDATAKEY, channelData);
|
||||
}
|
||||
} catch (ex) {
|
||||
// console.error(ex);
|
||||
|
@ -1378,6 +1384,74 @@ vAPI.toolbarButton = {
|
|||
tabs: {/*tabId: {badge: 0, img: boolean}*/}
|
||||
};
|
||||
|
||||
if (vAPI.fennec) {
|
||||
// Menu UI
|
||||
vAPI.toolbarButton.menuItemIds = new WeakMap();
|
||||
|
||||
vAPI.toolbarButton.getMenuItemLabel = function(tabId) {
|
||||
var label = this.label;
|
||||
if (tabId !== undefined) {
|
||||
var tabDetails = this.tabs[tabId];
|
||||
if (tabDetails) {
|
||||
if (tabDetails.img) {
|
||||
if (tabDetails.badge) {
|
||||
label = label + " (" + tabDetails.badge + ")";
|
||||
}
|
||||
} else {
|
||||
label = label + " (" + vAPI.i18n("fennecMenuItemBlockingOff") + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.init = function() {
|
||||
// Only actually expecting one window under Fennec (note, not tabs, windows)
|
||||
for (var win of vAPI.tabs.getWindows()) {
|
||||
this.addToWindow(win, this.getMenuItemLabel());
|
||||
}
|
||||
|
||||
cleanupTasks.push(this.cleanUp);
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.addToWindow = function(win, label) {
|
||||
var id = win.NativeWindow.menu.add({
|
||||
name: label,
|
||||
callback: this.onClick
|
||||
});
|
||||
this.menuItemIds.set(win, id);
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.cleanUp = function() {
|
||||
for (var win of vAPI.tabs.getWindows()) {
|
||||
vAPI.toolbarButton.removeFromWindow(win);
|
||||
}
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.removeFromWindow = function(win) {
|
||||
var id = this.menuItemIds.get(win);
|
||||
if (id) {
|
||||
win.NativeWindow.menu.remove(id);
|
||||
this.menuItemIds.delete(win);
|
||||
}
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.updateState = function (win, tabId) {
|
||||
var id = this.menuItemIds.get(win);
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
win.NativeWindow.menu.update(id, { name: this.getMenuItemLabel(tabId) });
|
||||
}
|
||||
|
||||
vAPI.toolbarButton.onClick = function() {
|
||||
var win = Services.wm.getMostRecentWindow('navigator:browser');
|
||||
var curTabId = vAPI.tabs.getTabId(getTabBrowser(win).selectedTab);
|
||||
vAPI.tabs.open({ url: vAPI.getURL("popup.html?tabId=" + curTabId), index: -1, select: true });
|
||||
}
|
||||
} else {
|
||||
// Toolbar button UI
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarButton.init = function() {
|
||||
|
@ -1585,6 +1659,27 @@ vAPI.toolbarButton.onViewHiding = function({target}) {
|
|||
target.firstChild.setAttribute('src', 'about:blank');
|
||||
};
|
||||
|
||||
vAPI.toolbarButton.updateState = function(win, tabId) {
|
||||
var button = win.document.getElementById(this.id);
|
||||
|
||||
if ( !button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var icon = this.tabs[tabId];
|
||||
button.setAttribute('badge', icon && icon.badge || '');
|
||||
|
||||
if ( !icon || !icon.img ) {
|
||||
icon = '';
|
||||
}
|
||||
else {
|
||||
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
|
||||
}
|
||||
|
||||
button.style.listStyleImage = icon;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
vAPI.toolbarButton.init();
|
||||
|
|
|
@ -499,6 +499,18 @@
|
|||
"message":"Unable to connect to {{url}}",
|
||||
"description":"English: Network error: unable to connect to {{url}}"
|
||||
},
|
||||
"showDashboardButton":{
|
||||
"message":"Show Dashboard",
|
||||
"description":"English: Show Dashboard"
|
||||
},
|
||||
"showNetworkLogButton":{
|
||||
"message":"Show Network Request Log",
|
||||
"description":"English: Show Network Request Log"
|
||||
},
|
||||
"fennecMenuItemBlockingOff": {
|
||||
"message": "off",
|
||||
"description": "Appears as µBlock (off)"
|
||||
},
|
||||
"dummy":{
|
||||
"message":"This entry must be the last one",
|
||||
"description":"so we dont need to deal with comma for last entry"
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="initial-scale=1">
|
||||
|
||||
<title data-i18n="dashboardName"></title>
|
||||
<link href="css/dashboard.css" rel="stylesheet" type="text/css">
|
||||
<link href="css/common.css" rel="stylesheet" type="text/css">
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="initial-scale=1">
|
||||
|
||||
<title data-i18n="statsPageName"></title>
|
||||
<link rel="stylesheet" type="text/css" href="css/common.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/devtools.css">
|
||||
|
|
|
@ -74,6 +74,9 @@ var onMessage = function(request, sender, callback) {
|
|||
case 'reloadTab':
|
||||
if ( vAPI.isNoTabId(request.tabId) === false ) {
|
||||
vAPI.tabs.reload(request.tabId);
|
||||
if (request.select && vAPI.tabs.select) {
|
||||
vAPI.tabs.select(request.tabId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -187,7 +190,7 @@ var getFirewallRules = function(srcHostname, desHostnames) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var getStats = function(tabId) {
|
||||
var getStats = function(tabId, tabTitle) {
|
||||
var r = {
|
||||
advancedUserEnabled: µb.userSettings.advancedUserEnabled,
|
||||
appName: vAPI.app.name,
|
||||
|
@ -201,7 +204,8 @@ var getStats = function(tabId) {
|
|||
pageURL: '',
|
||||
pageAllowedRequestCount: 0,
|
||||
pageBlockedRequestCount: 0,
|
||||
tabId: tabId
|
||||
tabId: tabId,
|
||||
tabTitle: tabTitle
|
||||
};
|
||||
var pageStore = µb.pageStoreFromTabId(tabId);
|
||||
if ( pageStore ) {
|
||||
|
@ -269,8 +273,8 @@ var onMessage = function(request, sender, callback) {
|
|||
// Async
|
||||
switch ( request.what ) {
|
||||
case 'getPopupData':
|
||||
vAPI.tabs.get(null, function(tab) {
|
||||
callback(getStats(getTargetTabId(tab)));
|
||||
vAPI.tabs.get(request.tabId, function(tab) {
|
||||
callback(getStats(getTargetTabId(tab), tab.title));
|
||||
});
|
||||
return;
|
||||
|
||||
|
@ -287,6 +291,9 @@ var onMessage = function(request, sender, callback) {
|
|||
µb.contextMenuClientX = -1;
|
||||
µb.contextMenuClientY = -1;
|
||||
µb.elementPickerExec(request.tabId);
|
||||
if (request.select && vAPI.tabs.select) {
|
||||
vAPI.tabs.select(request.tabId);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'hasPopupContentChanged':
|
||||
|
|
|
@ -364,6 +364,9 @@ var renderPrivacyExposure = function() {
|
|||
// Assume everything has to be done incrementally.
|
||||
|
||||
var renderPopup = function () {
|
||||
if (popupData.tabTitle) {
|
||||
document.title = popupData.appName + " - " + popupData.tabTitle;
|
||||
}
|
||||
uDom('#appname').text(popupData.appName);
|
||||
uDom('#version').text(popupData.appVersion);
|
||||
uDom('body').toggleClass('advancedUser', popupData.advancedUserEnabled);
|
||||
|
@ -449,7 +452,8 @@ var toggleNetFilteringSwitch = function(ev) {
|
|||
var gotoPick = function() {
|
||||
messager.send({
|
||||
what: 'gotoPick',
|
||||
tabId: popupData.tabId
|
||||
tabId: popupData.tabId,
|
||||
select: true
|
||||
});
|
||||
|
||||
vAPI.closePopup();
|
||||
|
@ -577,7 +581,7 @@ var setFirewallRuleHandler = function(ev) {
|
|||
/******************************************************************************/
|
||||
|
||||
var reloadTab = function() {
|
||||
messager.send({ what: 'reloadTab', tabId: popupData.tabId });
|
||||
messager.send({ what: 'reloadTab', tabId: popupData.tabId, select: true });
|
||||
|
||||
// Polling will take care of refreshing the popup content
|
||||
|
||||
|
@ -651,7 +655,7 @@ var pollForContentChange = (function() {
|
|||
|
||||
var queryCallback = function(response) {
|
||||
if ( response ) {
|
||||
getPopupData();
|
||||
getPopupData(popupData.tabId);
|
||||
return;
|
||||
}
|
||||
poll();
|
||||
|
@ -669,14 +673,14 @@ var pollForContentChange = (function() {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var getPopupData = function() {
|
||||
var getPopupData = function(tabId) {
|
||||
var onDataReceived = function(response) {
|
||||
cachePopupData(response);
|
||||
renderPopup();
|
||||
hashFromPopupData(true);
|
||||
pollForContentChange();
|
||||
};
|
||||
messager.send({ what: 'getPopupData' }, onDataReceived);
|
||||
messager.send({ what: 'getPopupData', tabId: tabId }, onDataReceived);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -684,7 +688,15 @@ var getPopupData = function() {
|
|||
// Make menu only when popup html is fully loaded
|
||||
|
||||
uDom.onLoad(function () {
|
||||
getPopupData();
|
||||
var tabId = null; //If there's no tab ID specified in the query string, it will default to current tab.
|
||||
|
||||
// Extract the tab id of the page this popup is for
|
||||
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
|
||||
if (matches && matches.length === 2) {
|
||||
tabId = matches[1];
|
||||
}
|
||||
|
||||
getPopupData(tabId);
|
||||
uDom('#switch').on('click', toggleNetFilteringSwitch);
|
||||
uDom('#gotoPick').on('click', gotoPick);
|
||||
uDom('a[href]').on('click', gotoURL);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" ?>
|
||||
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<setting type="control">
|
||||
<vbox>
|
||||
<button id="showDashboardButton"/>
|
||||
<button id="showNetworkLogButton"/>
|
||||
</vbox>
|
||||
</setting>
|
||||
</vbox>
|
|
@ -1,7 +1,8 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta name="viewport" content="width=470"> <!-- When showing as a tab in fennec, scale to full size (150px + 320px)-->
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="css/common.css" type="text/css">
|
||||
<link rel="stylesheet" href="css/popup.css" type="text/css">
|
||||
|
|
|
@ -15,6 +15,7 @@ xcopy /S /I src\js %DES%\js
|
|||
xcopy /S /I src\lib %DES%\lib
|
||||
xcopy /S /I src\_locales %DES%\_locales
|
||||
xcopy src\*.html %DES%\
|
||||
xcopy src\*.xul %DES%\
|
||||
move %DES%\img\icon_128.png %DES%\icon.png
|
||||
xcopy platform\firefox\vapi-*.js %DES%\js\
|
||||
xcopy platform\firefox\bootstrap.js %DES%\
|
||||
|
@ -30,6 +31,7 @@ c:\python34\python "%~dp0\make-firefox-meta.py" %DES%\
|
|||
if "%1"=="all" (
|
||||
echo "*** uBlock.firefox: Creating package..."
|
||||
pushd %DES%\
|
||||
del ..\uBlock.firefox.xpi
|
||||
"%ProgramW6432%\7-Zip\7z.exe" a -tzip -mx5 -bd ..\uBlock.firefox.xpi *
|
||||
popd
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue