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

Side by Side Diff: chrome/content/ui/ext/common.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Patch Set: Created Sept. 26, 2014, 12:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/content/ui/ext/popup.js » ('j') | chrome/content/ui/ext/popup.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 (function()
19 {
20 var UI = require("ui").UI;
Thomas Greiner 2014/09/29 16:19:49 We can make use of some ES6 features in this and o
saroyanm 2014/10/02 07:53:56 updated scripts imported to popup.html except the
Thomas Greiner 2014/10/08 10:40:43 We haven't done this in other files which are used
saroyanm 2014/10/10 12:05:58 np, I should also wrote that down, reverted.
21
22 /* Background page */
23
24 function Tab(tab) // {id, url}
Thomas Greiner 2014/09/29 16:19:49 This is not a proper documentation format (for exa
saroyanm 2014/10/02 07:53:56 Done.
25 {
26 this._location = tab.location;
27 }
28 Tab.prototype = {
29 _location: null,
30
31 get location()
32 {
33 return this._location;
34 },
35
36 sendMessage: function(message, responseCallback)
37 {
38 // TODO
39 responseCallback(); // TODO
Thomas Greiner 2014/09/29 16:19:49 Remove the TODOs here if nothing's missing.
saroyanm 2014/10/02 07:53:56 Done.
40 }
41 };
42
43 function Window(win) // {id, status}
44 {
45 // TODO
Thomas Greiner 2014/09/29 16:19:49 Remove the TODOs here if nothing's missing.
saroyanm 2014/10/02 07:53:56 Done.
46 this._window = win;
47 }
48 Window.prototype = {
49 _window: null,
50
51 getActiveTab: function(callback)
52 {
53 var location = UI.getCurrentLocation(this._window);
54 var tab = {
55 location: location
56 };
57 callback(new Tab(tab));
58 }
59 };
60
61 var backgroundPage = {
62 extractHostFromURL: function(url)
63 {
64 try
65 {
66 return Utils.unwrapURL(url).host;
67 }
68 catch(e)
69 {
70 return null;
71 }
72 },
73
74 openOptions: function()
75 {
76 UI.openFiltersDialog();
77 },
78
79 require: function()
80 {
81 return require;
82 }
83 };
84
85 /* i18n */
86
87 // Randomize URI to work around bug 719376
88 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
89 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName +
90 ".properties?" + Math.random());
91
92 function getI18nMessage(key, args)
93 {
94 return {
95 "message": (args ? stringBundle.formatStringFromName(key, args, args.lengt h) : stringBundle.GetStringFromName(key))
96 };
97 }
98
99 function getText(message, args)
100 {
101 var text = message.message;
102 var placeholders = message.placeholders;
103
104 if (!args || !placeholders)
105 return text;
106
107 for (var key in placeholders)
108 {
109 var content = placeholders[key].content;
110 if (!content)
111 continue;
112
113 var index = parseInt(content.slice(1), 10);
114 if (isNaN(index))
115 continue;
116
117 var replacement = args[index - 1];
118 if (typeof replacement === "undefined")
119 continue;
120
121 text = text.split("$" + key + "$").join(replacement);
122 }
123 return text;
124 }
125
126 /* API */
127
128 ext = {
129 backgroundPage: {
130 getWindow: function()
131 {
132 return backgroundPage;
133 }
134 },
135
136 i18n: {
137 getMessage: function(key, args)
138 {
139 try{
140 var message = getI18nMessage(key, args);
141 return getText(message, args);
142 }
143 catch(e)
144 {
145 Cu.reportError(e);
146 return "Missing translation: " + key;
Thomas Greiner 2014/10/08 10:40:43 We should at least return null here.
saroyanm 2014/10/10 12:05:58 Done.
147 }
148 }
149 },
150
151 windows: {
152 getLastFocused: function(callback)
153 {
154 var win = UI.currentWindow;
155 callback(new Window(UI.currentWindow));
156 }
157 }
158 };
159 })();
OLDNEW
« 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