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

Side by Side Diff: background.js

Issue 29333528: Issue 3515 - Use fetch() API instead XMLHttpRequest (Platform) (Closed)
Patch Set: Addressed comment Created Jan. 19, 2016, 4:12 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 | options.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 subscription.disabled = true; 217 subscription.disabled = true;
218 FilterStorage.addSubscription(subscription); 218 FilterStorage.addSubscription(subscription);
219 if (subscription instanceof DownloadableSubscription && !subscription.last Download) 219 if (subscription instanceof DownloadableSubscription && !subscription.last Download)
220 Synchronizer.execute(subscription); 220 Synchronizer.execute(subscription);
221 } 221 }
222 } 222 }
223 223
224 if (!addSubscription && !addAcceptable) 224 if (!addSubscription && !addAcceptable)
225 return; 225 return;
226 226
227 function notifyUser() 227 Promise.resolve(addSubscription && fetch("subscriptions.xml")
228 .then(function(response)
229 {
230 return response.text();
231 })
232 .then(function(text)
233 {
234 var doc = new DOMParser().parseFromString(text, "application/xml");
235 var nodes = doc.getElementsByTagName("subscription");
236 var node = Utils.chooseFilterSubscription(nodes);
237 var subscription = node && Subscription.fromURL(node.getAttribute("url"));
238
239 if (subscription)
240 {
241 FilterStorage.addSubscription(subscription);
242
243 subscription.disabled = false;
244 subscription.title = node.getAttribute("title");
245 subscription.homepage = node.getAttribute("homepage");
246
247 if (subscription instanceof DownloadableSubscription &&
248 !subscription.lastDownload)
249 Synchronizer.execute(subscription);
250 }
251 })
252 )
253 .then(function()
228 { 254 {
229 if (!Prefs.suppress_first_run_page) 255 if (!Prefs.suppress_first_run_page)
230 ext.pages.open(ext.getURL("firstRun.html")); 256 ext.pages.open(ext.getURL("firstRun.html"));
231 } 257 });
232
233 if (addSubscription)
234 {
235 // Load subscriptions data
236 var request = new XMLHttpRequest();
237 request.open("GET", "subscriptions.xml");
238 request.addEventListener("load", function()
239 {
240 var node = Utils.chooseFilterSubscription(request.responseXML.getElementsB yTagName("subscription"));
241 var subscription = (node ? Subscription.fromURL(node.getAttribute("url")) : null);
242 if (subscription)
243 {
244 FilterStorage.addSubscription(subscription);
245 subscription.disabled = false;
246 subscription.title = node.getAttribute("title");
247 subscription.homepage = node.getAttribute("homepage");
248 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload)
249 Synchronizer.execute(subscription);
250
251 notifyUser();
252 }
253 }, false);
254 request.send(null);
255 }
256 else
257 notifyUser();
258 } 258 }
259 259
260 Prefs.onChanged.addListener(function(name) 260 Prefs.onChanged.addListener(function(name)
261 { 261 {
262 if (name == "shouldShowBlockElementMenu") 262 if (name == "shouldShowBlockElementMenu")
263 refreshIconAndContextMenuForAllPages(); 263 refreshIconAndContextMenuForAllPages();
264 }); 264 });
265 265
266 // This is a hack to speedup loading of the options page on Safari. 266 // This is a hack to speedup loading of the options page on Safari.
267 // Once we replaced the background page proxy with message passing 267 // Once we replaced the background page proxy with message passing
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 419 }
420 }); 420 });
421 421
422 // update icon when page changes location 422 // update icon when page changes location
423 ext.pages.onLoading.addListener(function(page) 423 ext.pages.onLoading.addListener(function(page)
424 { 424 {
425 page.sendMessage({type: "clickhide-deactivate"}); 425 page.sendMessage({type: "clickhide-deactivate"});
426 refreshIconAndContextMenu(page); 426 refreshIconAndContextMenu(page);
427 showNextNotificationForUrl(page.url); 427 showNextNotificationForUrl(page.url);
428 }); 428 });
OLDNEW
« no previous file with comments | « no previous file | options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld