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

Delta Between Two Patch Sets: background.js

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Left Patch Set: Created Oct. 12, 2012, 1:11 p.m.
Right Patch Set: Created Oct. 19, 2012, 4:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | button.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 importAll("filterClasses", this); 1 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption;
2 importAll("subscriptionClasses", this); 2 var WhitelistFilter = require("filterClasses").WhitelistFilter;
3 importAll("filterStorage", this); 3 var FilterNotifier = require("filterNotifier").FilterNotifier;
4 importAll("elemHide", this); 4 var FilterStorage = require("filterStorage").FilterStorage;
5 importAll("filterListener", this); 5 var Prefs = require("prefs").Prefs;
6 importAll("filterNotifier", this); 6 var Synchronizer = require("synchronizer").Synchronizer;
7 importAll("matcher", this); 7 var Subscription = require("subscriptionClasses").Subscription;
8 importAll("prefs", this); 8 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
9 importAll("synchronizer", this); 9 var Utils = require("utils").Utils;
10 importAll("utils", this);
Wladimir Palant 2012/10/12 15:04:02 Please don't use importAll, it hides what is actua
Felix Dahlke 2012/10/16 14:20:01 Okay, done. I tried to keep it similar to Chrome s
Felix Dahlke 2012/10/16 14:20:01 Done. I actually did that to keep the files simila
11 10
12 var isFirstRun = false; 11 var isFirstRun = false;
13 FilterNotifier.addListener(function(action) 12 FilterNotifier.addListener(function(action)
14 { 13 {
15 if (action == "load") 14 if (action == "load")
16 { 15 {
17 importOldData(); 16 importOldData();
18 if (!window.localStorage.currentVersion) 17 if (!window.localStorage.currentVersion)
19 { 18 {
20 isFirstRun = true; 19 isFirstRun = true;
21 executeFirstRunActions(); 20 executeFirstRunActions();
22 } 21 }
23 window.localStorage.currentVersion = require("info").addonVersion; 22 window.localStorage.currentVersion = require("info").addonVersion;
24 } 23 }
25 }); 24 });
25
26 var toolbarButton;
27 var i18nMessages;
26 28
27 function importOldData() 29 function importOldData()
28 { 30 {
29 // TODO: Remove this once most people have the update 31 // TODO: Remove this once most people have the update
30 if ("version" in widget.preferences) 32 if ("version" in widget.preferences)
31 { 33 {
32 var oldLists = { 34 var oldLists = {
33 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt", 35 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt",
34 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt", 36 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt",
35 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt", 37 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt",
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 subscription.title = selectedItem.getAttribute("title"); 145 subscription.title = selectedItem.getAttribute("title");
144 subscription.homepage = selectedItem.getAttribute("homepage"); 146 subscription.homepage = selectedItem.getAttribute("homepage");
145 if (subscription instanceof DownloadableSubscription && !subscription.last Download) 147 if (subscription instanceof DownloadableSubscription && !subscription.last Download)
146 Synchronizer.execute(subscription); 148 Synchronizer.execute(subscription);
147 FilterStorage.addSubscription(subscription); 149 FilterStorage.addSubscription(subscription);
148 } 150 }
149 }; 151 };
150 request.send(null); 152 request.send(null);
151 } 153 }
152 154
153 function addToolbarIcon() 155 function setDefaultOptions()
156 {
157 function defaultOptionValue(opt, val)
158 {
159 if(!(opt in localStorage))
160 localStorage[opt] = val;
161 }
162
163 defaultOptionValue("shouldShowIcon", "true");
164 }
165
166 function createToolbarButton()
154 { 167 {
155 var properties = { 168 var properties = {
156 disabled: false, 169 disabled: false,
157 title: "Adblock Plus", 170 title: "Adblock Plus",
158 icon: "icons/abp-18.png" 171 icon: "icons/abp-18.png"
159 }; 172 };
160 173
161 var button = opera.contexts.toolbar.createItem(properties); 174 toolbarButton = opera.contexts.toolbar.createItem(properties);
162 opera.contexts.toolbar.addItem(button); 175 }
163 } 176
164 177 function refreshToolbarButton()
165 function loadMessages(callback) 178 {
179 var toolbar = opera.contexts.toolbar;
180 if (localStorage["shouldShowIcon"] === "true")
181 toolbar.addItem(toolbarButton);
182 else
183 toolbar.removeItem(toolbarButton);
184 }
185
186 function getJson(url)
166 { 187 {
167 var request = new XMLHttpRequest(); 188 var request = new XMLHttpRequest();
168 request.open("GET", "messages.json"); 189 request.open("GET", url, false);
169 request.responseType = "json"; 190 request.responseType = "json";
170 request.addEventListener("load", function()
171 {
172 callback(request.response);
173 });
174 request.send(); 191 request.send();
175 } 192 return request.response;
176 193 }
177 addToolbarIcon(); 194
178 195 function loadMessagesForLocale(locale)
179 var i18nMessages; 196 {
180 loadMessages(function(messages) 197 var messagesFileName = "messages.json";
181 { 198 var messagesPath;
182 i18nMessages = messages; 199 if (locale)
183 }); 200 messagesPath = "locales/" + locale + "/" + messagesFileName;
Wladimir Palant 2012/10/12 15:04:02 a) Is it necessary to assign explicitly here? Can'
Felix Dahlke 2012/10/16 14:20:01 Hm, don't you think it would be less obvious that
201 else
202 messagesPath = messagesFileName;
203
204 var messages = getJson(messagesPath);
205 if (!messages)
206 {
207 console.error("Failed to load messages for locale "
208 + (locale ? locale : "default"));
209 return;
210 }
211
212 for (var i in messages)
213 i18nMessages[i] = messages[i];
214 }
215
216 function loadI18nMessages()
217 {
218 // Could be parsed from config.xml
219 var defaultLocale = "en";
220
221 i18nMessages = {};
222 loadMessagesForLocale(defaultLocale);
223 loadMessagesForLocale();
224 }
225
226 setDefaultOptions();
227 createToolbarButton();
228 refreshToolbarButton();
229 loadI18nMessages();
LEFTRIGHT
« no previous file | button.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld