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

Unified 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.
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 | options.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -224,37 +224,37 @@
if (!addSubscription && !addAcceptable)
return;
- function notifyUser()
+ Promise.resolve(addSubscription && fetch("subscriptions.xml")
+ .then(function(response)
+ {
+ return response.text();
+ })
+ .then(function(text)
+ {
+ var doc = new DOMParser().parseFromString(text, "application/xml");
+ var nodes = doc.getElementsByTagName("subscription");
+ var node = Utils.chooseFilterSubscription(nodes);
+ var subscription = node && Subscription.fromURL(node.getAttribute("url"));
+
+ if (subscription)
+ {
+ FilterStorage.addSubscription(subscription);
+
+ subscription.disabled = false;
+ subscription.title = node.getAttribute("title");
+ subscription.homepage = node.getAttribute("homepage");
+
+ if (subscription instanceof DownloadableSubscription &&
+ !subscription.lastDownload)
+ Synchronizer.execute(subscription);
+ }
+ })
+ )
+ .then(function()
{
if (!Prefs.suppress_first_run_page)
ext.pages.open(ext.getURL("firstRun.html"));
- }
-
- if (addSubscription)
- {
- // Load subscriptions data
- var request = new XMLHttpRequest();
- request.open("GET", "subscriptions.xml");
- request.addEventListener("load", function()
- {
- var node = Utils.chooseFilterSubscription(request.responseXML.getElementsByTagName("subscription"));
- var subscription = (node ? Subscription.fromURL(node.getAttribute("url")) : null);
- if (subscription)
- {
- FilterStorage.addSubscription(subscription);
- subscription.disabled = false;
- subscription.title = node.getAttribute("title");
- subscription.homepage = node.getAttribute("homepage");
- if (subscription instanceof DownloadableSubscription && !subscription.lastDownload)
- Synchronizer.execute(subscription);
-
- notifyUser();
- }
- }, false);
- request.send(null);
- }
- else
- notifyUser();
+ });
}
Prefs.onChanged.addListener(function(name)
« no previous file with comments | « no previous file | options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld