[Pkg-mozext-commits] [adblock-plus] 19/52: Issue 1663 - Various Firefox-related changes of the first-run page
David Prévot
taffit at moszumanska.debian.org
Thu Jan 22 21:43:45 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit 5ad367b0c89a4b644a9b181dcbb30babbfb093ad
Author: Wladimir Palant <trev at adblockplus.org>
Date: Fri Dec 19 14:33:08 2014 +0100
Issue 1663 - Various Firefox-related changes of the first-run page
--HG--
extra : rebase_source : 3552e42c34e85ff2dcedd69a9b0893f09e30e738
extra : amend_source : 4c5147c0602dd5e8b6bb94228bd062b6247ab4db
extra : histedit_source : 4f3dc81dde318e925bd182b2686db105339529b0
---
README.md | 1 -
background.js | 186 ++++++++++++++++++++++++++++------------------------
ext/common.js | 2 +-
firstRun.html | 1 -
firstRun.js | 7 +-
i18n.js | 84 +++++-------------------
messageResponder.js | 30 +++++++--
utils.js | 24 -------
8 files changed, 148 insertions(+), 187 deletions(-)
diff --git a/README.md b/README.md
index c31d070..f957207 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,6 @@ Directory structure
* Top-level files:
* `firstRun.html` and `firstRun.js`: First-run page, see below
* `i18n.js`: Localization functions, should be included by all pages.
- * `utils.js`: Utility functions, to be removed soon.
* `messageResponder.js`: Script to be used on the background page to respond
to messages sent by UI code.
* `background.html`, `background.js`: Test implementation of the background
diff --git a/background.js b/background.js
index 93f4896..227c193 100644
--- a/background.js
+++ b/background.js
@@ -37,119 +37,131 @@
"https://easylist-downloads.adblockplus.org/fanboy-social.txt"
];
- global.Utils = {
- getDocLink: function(link)
- {
- return "https://adblockplus.org/redirect?link=" + encodeURIComponent(link);
- }
- };
-
- global.Subscription = function(url)
+ var modules = {};
+ global.require = function(module)
{
- this.url = url;
- this.title = "Subscription " + url;
- this.disabled = false;
- this.lastDownload = 1234;
+ return modules[module];
};
- global.Subscription.fromURL = function(url)
- {
- return new global.Subscription(url);
+ modules.utils = {
+ Utils: {
+ getDocLink: function(link)
+ {
+ return "https://adblockplus.org/redirect?link=" + encodeURIComponent(link);
+ }
+ }
};
- global.DownloadableSubscription = global.Subscription;
- global.SpecialSubscription = function() {};
-
- global.FilterStorage = {
- get subscriptions()
+ modules.subscriptionClasses = {
+ Subscription: function(url)
{
- return subscriptions.map(global.Subscription.fromURL);
+ this.url = url;
+ this.title = "Subscription " + url;
+ this.disabled = false;
+ this.lastDownload = 1234;
},
- get knownSubscriptions()
- {
- var result = {};
- for (var i = 0; i < subscriptions.length; i++)
- result[subscriptions[i]] = global.Subscription.fromURL(subscriptions[i]);
- return result;
- },
+ SpecialSubscription: function() {}
+ };
+ modules.subscriptionClasses.Subscription.fromURL = function(url)
+ {
+ return new modules.subscriptionClasses.Subscription(url);
+ };
+ modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionClasses.Subscription;
- addSubscription: function(subscription)
- {
- var index = subscriptions.indexOf(subscription.url);
- if (index < 0)
+ modules.filterStorage = {
+ FilterStorage: {
+ get subscriptions()
{
- subscriptions.push(subscription.url);
- global.FilterNotifier.triggerListeners("subscription.added", subscription);
- }
- },
+ return subscriptions.map(modules.subscriptionClasses.Subscription.fromURL);
+ },
- removeSubscription: function(subscription)
- {
- var index = subscriptions.indexOf(subscription.url);
- if (index >= 0)
+ get knownSubscriptions()
+ {
+ var result = {};
+ for (var i = 0; i < subscriptions.length; i++)
+ result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fromURL(subscriptions[i]);
+ return result;
+ },
+
+ addSubscription: function(subscription)
+ {
+ var index = subscriptions.indexOf(subscription.url);
+ if (index < 0)
+ {
+ subscriptions.push(subscription.url);
+ modules.filterNotifier.FilterNotifier.triggerListeners("subscription.added", subscription);
+ }
+ },
+
+ removeSubscription: function(subscription)
{
- subscriptions.splice(index, 1);
- global.FilterNotifier.triggerListeners("subscription.removed", subscription);
+ var index = subscriptions.indexOf(subscription.url);
+ if (index >= 0)
+ {
+ subscriptions.splice(index, 1);
+ modules.filterNotifier.FilterNotifier.triggerListeners("subscription.removed", subscription);
+ }
}
}
};
- global.BlockingFilter = function() {};
+ modules.filterClasses = {
+ BlockingFilter: function() {}
+ };
- global.defaultMatcher = {
- matchesAny: function(url, requestType, docDomain, thirdParty)
- {
- var params = {blockedURLs: ""};
- updateFromURL(params);
- var blocked = params.blockedURLs.split(",");
- if (blocked.indexOf(url) >= 0)
- return new global.BlockingFilter();
- else
- return null;
+ modules.synchronizer = {
+ Synchronizer: {}
+ };
+
+ modules.matcher = {
+ defaultMatcher: {
+ matchesAny: function(url, requestType, docDomain, thirdParty)
+ {
+ var params = {blockedURLs: ""};
+ updateFromURL(params);
+ var blocked = params.blockedURLs.split(",");
+ if (blocked.indexOf(url) >= 0)
+ return new modules.filterClasses.BlockingFilter();
+ else
+ return null;
+ }
}
};
var notifierListeners = [];
- global.FilterNotifier = {
- addListener: function(listener)
- {
- if (notifierListeners.indexOf(listener) < 0)
- notifierListeners.push(listener);
- },
+ modules.filterNotifier = {
+ FilterNotifier: {
+ addListener: function(listener)
+ {
+ if (notifierListeners.indexOf(listener) < 0)
+ notifierListeners.push(listener);
+ },
- removeListener: function(listener)
- {
- var index = notifierListeners.indexOf(listener);
- if (index >= 0)
- notifierListeners.splice(index, 1);
- },
+ removeListener: function(listener)
+ {
+ var index = notifierListeners.indexOf(listener);
+ if (index >= 0)
+ notifierListeners.splice(index, 1);
+ },
- triggerListeners: function()
- {
- var args = Array.prototype.slice.apply(arguments);
- var listeners = notifierListeners.slice();
- for (var i = 0; i < listeners.length; i++)
- listeners[i].apply(null, args);
+ triggerListeners: function()
+ {
+ var args = Array.prototype.slice.apply(arguments);
+ var listeners = notifierListeners.slice();
+ for (var i = 0; i < listeners.length; i++)
+ listeners[i].apply(null, args);
+ }
}
};
- global.require = function(module)
- {
- if (module == "info")
- {
- var result = {
- platform: "gecko",
- platformVersion: "34.0",
- application: "firefox",
- applicationVersion: "34.0"
- };
- updateFromURL(result);
- return result;
- }
- else
- return undefined;
- }
+ modules.info = {
+ platform: "gecko",
+ platformVersion: "34.0",
+ application: "firefox",
+ applicationVersion: "34.0"
+ };
+ updateFromURL(modules.info);
global.openOptions = function()
{
diff --git a/ext/common.js b/ext/common.js
index 1104062..7b87df0 100644
--- a/ext/common.js
+++ b/ext/common.js
@@ -85,7 +85,7 @@
// dash is dropped, since we only support language and region
var parts = selectedLocale.split("-");
var language = parts[0];
- var region = (parts[1] || "").toUpperCase();
+ var region = (parts[1] || "").toUpperCase();
if (region)
candidates.push(language + "-" + region);
diff --git a/firstRun.html b/firstRun.html
index 6c00a91..44e1470 100644
--- a/firstRun.html
+++ b/firstRun.html
@@ -23,7 +23,6 @@
<link type="text/css" href="skin/firstRun.css" rel="stylesheet"/>
<script type="text/javascript" src="ext/common.js"></script>
<script type="text/javascript" src="ext/content.js"></script>
- <script type="text/javascript" src="utils.js"></script>
<script type="text/javascript" src="i18n.js"></script>
<script type="text/javascript" src="firstRun.js"></script>
</head>
diff --git a/firstRun.js b/firstRun.js
index fc40eda..4550b46 100644
--- a/firstRun.js
+++ b/firstRun.js
@@ -19,6 +19,11 @@
(function()
{
+ function E(id)
+ {
+ return document.getElementById(id);
+ }
+
// Load subscriptions for features
var featureSubscriptions = [
{
@@ -114,7 +119,7 @@
});
ext.backgroundPage.sendMessage({
type: "subscriptions.listen",
- filter: ["added", "removed", "disabled"]
+ filter: ["added", "removed", "updated", "disabled"]
});
}
diff --git a/i18n.js b/i18n.js
index cc33b0f..8201cbb 100644
--- a/i18n.js
+++ b/i18n.js
@@ -15,85 +15,33 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-var i18n;
+// This variable should no longer be necessary once options.js in Chrome
+// accesses ext.i18n directly.
+var i18n = ext.i18n;
-if (typeof ext != "undefined")
+if (ext.i18n.getMessage("@@ui_locale"))
{
- i18n = ext.i18n;
-
document.documentElement.lang = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
document.documentElement.dir = ext.i18n.getMessage("@@bidi_dir");
}
else
{
- // Using Firefox' approach on i18n instead
-
- // Randomize URI to work around bug 719376
- var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
- var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/" + pageName +
- ".properties?" + Math.random());
-
- function getI18nMessage(key)
- {
- return {
- "message": stringBundle.GetStringFromName(key)
- };
- }
-
- i18n = (function()
+ // Getting UI locale cannot be done synchronously on Firefox, requires
+ // messaging the background page.
+ ext.backgroundPage.sendMessage({
+ type: "app.get",
+ what: "localeInfo"
+ }, function(localeInfo)
{
- function getText(message, args)
- {
- var text = message.message;
- var placeholders = message.placeholders;
-
- if (!args || !placeholders)
- return text;
-
- for (var key in placeholders)
- {
- var content = placeholders[key].content;
- if (!content)
- continue;
-
- var index = parseInt(content.slice(1), 10);
- if (isNaN(index))
- continue;
-
- var replacement = args[index - 1];
- if (typeof replacement === "undefined")
- continue;
-
- text = text.split("$" + key + "$").join(replacement);
- }
- return text;
- }
-
- return {
- getMessage: function(key, args)
- {
- try{
- var message = getI18nMessage(key);
- return getText(message, args);
- }
- catch(e)
- {
- Cu.reportError(e);
- return "Missing translation: " + key;
- }
- }
- };
- })();
-
- var Utils = require("utils").Utils;
- document.documentElement.lang = Utils.appLocale;
- document.documentElement.dir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr";
+ document.documentElement.lang = localeInfo.locale;
+ document.documentElement.dir = localeInfo.isRTL ? "rtl" : "ltr";
+ });
}
// Inserts i18n strings into matching elements. Any inner HTML already in the element is
// parsed as JSON and used as parameters to substitute into placeholders in the i18n
// message.
-i18n.setElementText = function(element, stringName, arguments)
+ext.i18n.setElementText = function(element, stringName, arguments)
{
function processString(str, element)
{
@@ -114,7 +62,7 @@ i18n.setElementText = function(element, stringName, arguments)
while (element.lastChild)
element.removeChild(element.lastChild);
- processString(i18n.getMessage(stringName, arguments), element);
+ processString(ext.i18n.getMessage(stringName, arguments), element);
}
// Loads i18n strings
@@ -133,7 +81,7 @@ function loadI18nStrings()
className = className.animVal;
var stringName = className.split(/\s/)[0].substring(5);
- i18n.setElementText(node, stringName, arguments);
+ ext.i18n.setElementText(node, stringName, arguments);
}
}
diff --git a/messageResponder.js b/messageResponder.js
index 9a4b310..4404a1d 100644
--- a/messageResponder.js
+++ b/messageResponder.js
@@ -17,6 +17,21 @@
(function(global)
{
+ if (!global.ext)
+ global.ext = require("ext_background");
+
+ var Utils = require("utils").Utils;
+ var FilterStorage = require("filterStorage").FilterStorage;
+ var FilterNotifier = require("filterNotifier").FilterNotifier;
+ var defaultMatcher = require("matcher").defaultMatcher;
+ var BlockingFilter = require("filterClasses").BlockingFilter;
+ var Synchronizer = require("synchronizer").Synchronizer;
+
+ var subscriptionClasses = require("subscriptionClasses");
+ var Subscription = subscriptionClasses.Subscription;
+ var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
+ var SpecialSubscription = subscriptionClasses.SpecialSubscription;
+
var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url", "downloadStatus"];
function convertSubscription(subscription)
{
@@ -74,7 +89,7 @@
}
};
- ext.onMessage.addListener(function(message, sender, callback)
+ global.ext.onMessage.addListener(function(message, sender, callback)
{
switch (message.type)
{
@@ -93,16 +108,23 @@
}
else if (message.what == "doclink")
callback(Utils.getDocLink(message.link));
+ else if (message.what == "localeInfo")
+ {
+ callback({
+ locale: Utils.appLocale,
+ isRTL: Utils.chromeRegistry.isLocaleRTL("adblockplus")
+ });
+ }
else
callback(null);
break;
case "app.open":
if (message.what == "options")
{
- if (typeof UI != "undefined")
- UI.openFiltersDialog();
- else
+ if (typeof global.openOptions == "function")
global.openOptions();
+ else
+ require("ui").UI.openFiltersDialog();
}
break;
case "subscriptions.get":
diff --git a/utils.js b/utils.js
deleted file mode 100644
index fb91fb7..0000000
--- a/utils.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * This file is part of Adblock Plus <http://adblockplus.org/>,
- * Copyright (C) 2006-2014 Eyeo GmbH
- *
- * Adblock Plus is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as
- * published by the Free Software Foundation.
- *
- * Adblock Plus 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 Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * Shortcut for document.getElementById(id)
- */
-function E(id)
-{
- return document.getElementById(id);
-}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list