Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/ui/ext/common.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Patch Set: Created Oct. 10, 2014, 11:36 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/content/ui/ext/popup.js » ('j') | chrome/content/ui/ext/popup.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/ui/ext/common.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/chrome/content/ui/ext/common.js
@@ -0,0 +1,122 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * @fileOverview Implemenation of Firefox-specific general classes
+ */
+
+(function()
+{
+ var UI = require("ui").UI;
+
+ /**
+ * Page class
+ * @param {Object} tab an object with url property
+ */
+ function Page(tab)
+ {
+ this._url = tab.url;
+ }
+
+ Page.prototype = {
+ _url: null,
+
+ get url()
+ {
+ return this._url;
+ },
+
+ sendMessage: function(message, responseCallback)
+ {
+ responseCallback();
+ }
+ };
+
+ var backgroundPage = {
+ extractHostFromURL: function(url)
+ {
+ try
+ {
+ return Utils.unwrapURL(url).host;
+ }
+ catch(e)
+ {
+ return null;
+ }
+ },
+
+ openOptions: function()
+ {
+ UI.openFiltersDialog();
+ },
+
+ require: function()
+ {
+ return require;
+ }
+ };
+
+ // 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());
+
+
+ ext = {
+ backgroundPage: {
+ getWindow: function()
+ {
+ return backgroundPage;
+ }
+ },
+
+ i18n: {
+ /**
+ * Get locale string
+ * @param {String} key name of string
+ * @param {Array} args parameters to pass
+ * @return {String} string or null if translation is missing
+ */
+ getMessage: function(key, args)
+ {
+ try
+ {
+ return (args ? stringBundle.formatStringFromName(key, args, args.length) : stringBundle.GetStringFromName(key));
+ }
+ catch(e)
+ {
+ Cu.reportError("Missing translation: " + key);
+ return null;
+ }
+ }
+ },
+
+ pages: {
+ query: function(info, callback)
+ {
+ if (info.active && info.lastFocusedWindow)
saroyanm 2014/10/10 12:05:58 Not sure about array that should be returned with
Thomas Greiner 2014/10/13 13:18:24 We do need to call the callback function even if t
saroyanm 2014/10/16 11:26:15 Done.
+ {
+ var location = UI.getCurrentLocation(UI.currentWindow);
+ var tab = {
+ url: location.spec
Thomas Greiner 2014/10/13 13:18:24 This will throw an error if location is `null`.
saroyanm 2014/10/16 11:26:15 Done.
+ };
+ callback([new Page(tab)]);
+ }
+ }
+ }
+ };
+})();
« no previous file with comments | « no previous file | chrome/content/ui/ext/popup.js » ('j') | chrome/content/ui/ext/popup.js » ('J')

Powered by Google App Engine
This is Rietveld