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: Created Jan. 15, 2016, 1:57 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') | options.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -224,20 +224,15 @@
if (!addSubscription && !addAcceptable)
return;
- function notifyUser()
- {
- 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()
+ Promise.resolve(addSubscription && fetch("subscriptions.xml")
+ .then(function(response)
{
- var node = Utils.chooseFilterSubscription(request.responseXML.getElementsByTagName("subscription"));
+ return response.text();
+ })
+ .then(function(text)
+ {
+ var doc = new DOMParser().parseFromString(text, "application/xml");
+ var node = Utils.chooseFilterSubscription(doc.getElementsByTagName("subscription"));
kzar 2016/01/17 17:14:06 Nit: While changing mind fixing some of these long
Sebastian Noack 2016/01/19 14:58:10 Done.
var subscription = (node ? Subscription.fromURL(node.getAttribute("url")) : null);
if (subscription)
{
@@ -247,14 +242,13 @@
subscription.homepage = node.getAttribute("homepage");
if (subscription instanceof DownloadableSubscription && !subscription.lastDownload)
Synchronizer.execute(subscription);
-
- notifyUser();
}
- }, false);
- request.send(null);
- }
- else
- notifyUser();
+ })
+ ).then(function()
kzar 2016/01/17 17:14:06 Nit: The indentation of this `.then(...` call seem
Sebastian Noack 2016/01/19 14:58:10 Intending the code above like that: Promise.res
kzar 2016/01/19 15:39:19 What about doing this here? That way they'd all be
Sebastian Noack 2016/01/19 16:13:25 Note sure if I like it any better, but done.
+ {
+ if (!Prefs.suppress_first_run_page)
kzar 2016/01/17 17:14:06 I think previously we always called `notifyUser()`
Sebastian Noack 2016/01/19 14:58:10 That's not correct. Promise.resolve(addSubscriptio
kzar 2016/01/19 15:39:19 Ah, I see.
+ ext.pages.open(ext.getURL("firstRun.html"));
+ });
}
Prefs.onChanged.addListener(function(name)
« no previous file with comments | « no previous file | options.html » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld