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

Delta Between Two Patch Sets: options.js

Issue 29339314: Issue 3870 - Rewrite legacy options page to use async messages (Closed)
Left Patch Set: Update for adblockplusui changes and work around around a race condition with Downloading... label Created April 7, 2016, 11:46 a.m.
Right Patch Set: Avoid another race condition Created April 7, 2016, 1:27 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 | « lib/notificationHelper.js ('k') | safari/ext/background.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 /* 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 var importRawFilters = wrapper({type: "filters.importRaw"}, 75 var importRawFilters = wrapper({type: "filters.importRaw"},
76 "text", "removeExisting"); 76 "text", "removeExisting");
77 var addFilter = wrapper({type: "filters.add"}, "text"); 77 var addFilter = wrapper({type: "filters.add"}, "text");
78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl");
79 var removeFilter = wrapper({type: "filters.remove"}, "text"); 79 var removeFilter = wrapper({type: "filters.remove"}, "text");
80 80
81 var i18n = ext.i18n; 81 var i18n = ext.i18n;
82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/;
83 var delayedSubscriptionSelection = null; 83 var delayedSubscriptionSelection = null;
84 84
85 var acceptableAdsUrl;
86
85 // Loads options and sets UI elements accordingly 87 // Loads options and sets UI elements accordingly
86 function loadOptions() 88 function loadOptions()
87 { 89 {
88 // Set page title to i18n version of "Adblock Plus Options" 90 // Set page title to i18n version of "Adblock Plus Options"
89 document.title = i18n.getMessage("options"); 91 document.title = i18n.getMessage("options");
90 92
91 // Set links 93 // Set links
92 getPref("subscriptions_exceptionsurl", function(url) 94 getPref("subscriptions_exceptionsurl", function(url)
93 { 95 {
94 $("#acceptableAdsLink").attr("href", url); 96 acceptableAdsUrl = url;
97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl);
95 }); 98 });
96 getDocLink("acceptable_ads", function(url) 99 getDocLink("acceptable_ads", function(url)
97 { 100 {
98 $("#acceptableAdsDocs").attr("href", url); 101 $("#acceptableAdsDocs").attr("href", url);
99 }); 102 });
100 getDocLink("filterdoc", function(url) 103 getDocLink("filterdoc", function(url)
101 { 104 {
102 setLinks("filter-must-follow-syntax", url); 105 setLinks("filter-must-follow-syntax", url);
103 }); 106 });
104 getInfo("application", function(application) 107 getInfo("application", function(application)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 $(loadOptions); 193 $(loadOptions);
191 194
192 // Reloads the displayed subscriptions and filters 195 // Reloads the displayed subscriptions and filters
193 function reloadFilters() 196 function reloadFilters()
194 { 197 {
195 // Load user filter URLs 198 // Load user filter URLs
196 var container = document.getElementById("filterLists"); 199 var container = document.getElementById("filterLists");
197 while (container.lastChild) 200 while (container.lastChild)
198 container.removeChild(container.lastChild); 201 container.removeChild(container.lastChild);
199 202
200 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) 203 getSubscriptions(true, false, function(subscriptions)
201 { 204 {
202 getSubscriptions(true, false, function(subscriptions) 205 for (var i = 0; i < subscriptions.length; i++)
203 { 206 {
204 for (var i = 0; i < subscriptions.length; i++) 207 var subscription = subscriptions[i];
205 { 208 if (subscription.url == acceptableAdsUrl)
206 var subscription = subscriptions[i]; 209 $("#acceptableAds").prop("checked", !subscription.disabled);
207 if (subscription.url == acceptableAdsUrl) 210 else
208 $("#acceptableAds").prop("checked", !subscription.disabled); 211 addSubscriptionEntry(subscription);
209 else 212 }
210 addSubscriptionEntry(subscription);
211 }
212 });
213 }); 213 });
214 214
215 // User-entered filters 215 // User-entered filters
216 getSubscriptions(false, true, function(subscriptions) 216 getSubscriptions(false, true, function(subscriptions)
217 { 217 {
218 clearListBox("userFiltersBox"); 218 clearListBox("userFiltersBox");
219 clearListBox("excludedDomainsBox"); 219 clearListBox("excludedDomainsBox");
220 220
221 for (var i = 0; i < subscriptions.length; i++) 221 for (var i = 0; i < subscriptions.length; i++)
222 getFilters(subscriptions[i].url, function(filters) 222 getFilters(subscriptions[i].url, function(filters)
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 addSubscription(url, title, null); 385 addSubscription(url, title, null);
386 } 386 }
387 387
388 $("#addSubscriptionContainer").hide(); 388 $("#addSubscriptionContainer").hide();
389 $("#customSubscriptionContainer").hide(); 389 $("#customSubscriptionContainer").hide();
390 $("#addSubscriptionButton").show(); 390 $("#addSubscriptionButton").show();
391 } 391 }
392 392
393 function toggleAcceptableAds() 393 function toggleAcceptableAds()
394 { 394 {
395 getPref("subscriptions_exceptionsurl", function(url) 395 toggleSubscription(acceptableAdsUrl, true);
396 {
397 toggleSubscription(url, true);
398 });
399 } 396 }
400 397
401 function findSubscriptionElement(subscription) 398 function findSubscriptionElement(subscription)
402 { 399 {
403 var children = document.getElementById("filterLists").childNodes; 400 var children = document.getElementById("filterLists").childNodes;
404 for (var i = 0; i < children.length; i++) 401 for (var i = 0; i < children.length; i++)
405 if (children[i]._subscription.url == subscription.url) 402 if (children[i]._subscription.url == subscription.url)
406 return children[i]; 403 return children[i];
407 return null; 404 return null;
408 } 405 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 case "disabled": 462 case "disabled":
466 case "downloading": 463 case "downloading":
467 case "downloadStatus": 464 case "downloadStatus":
468 case "homepage": 465 case "homepage":
469 case "lastDownload": 466 case "lastDownload":
470 case "title": 467 case "title":
471 if (element) 468 if (element)
472 updateSubscriptionInfo(element, subscription); 469 updateSubscriptionInfo(element, subscription);
473 break; 470 break;
474 case "added": 471 case "added":
475 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) 472 if (subscription.url == acceptableAdsUrl)
476 { 473 $("#acceptableAds").prop("checked", true);
477 // Hack - Assume newly added subscriptions are currently downloading as 474 else if (!element)
478 // we process the downloading message before we have finished 475 addSubscriptionEntry(subscription);
479 // adding the subscription's element!
480 subscription.isDownloading = true;
Sebastian Noack 2016/04/07 12:49:14 That is because you asynchronously retrieve the Ac
kzar 2016/04/07 13:04:53 Much better solution and works fine. Done.
481
482 if (subscription.url == acceptableAdsUrl)
483 $("#acceptableAds").prop("checked", true);
484 else if (!element)
485 addSubscriptionEntry(subscription);
486 });
487 break; 476 break;
488 case "removed": 477 case "removed":
489 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) 478 if (subscription.url == acceptableAdsUrl)
490 { 479 $("#acceptableAds").prop("checked", false);
491 if (subscription.url == acceptableAdsUrl) 480 else if (element)
492 $("#acceptableAds").prop("checked", false); 481 element.parentNode.removeChild(element);
493 else if (element)
494 element.parentNode.removeChild(element);
495 });
496 break; 482 break;
497 } 483 }
498 } 484 }
499 485
500 function onPrefMessage(key, value) 486 function onPrefMessage(key, value)
501 { 487 {
502 switch (key) 488 switch (key)
503 { 489 {
504 case "notifications_showui": 490 case "notifications_showui":
505 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 491 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e;
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 onFilterMessage(message.action, message.args[0]); 741 onFilterMessage(message.action, message.args[0]);
756 break; 742 break;
757 case "prefs.respond": 743 case "prefs.respond":
758 onPrefMessage(message.action, message.args[0]); 744 onPrefMessage(message.action, message.args[0]);
759 break; 745 break;
760 case "subscriptions.respond": 746 case "subscriptions.respond":
761 onSubscriptionMessage(message.action, message.args[0]); 747 onSubscriptionMessage(message.action, message.args[0]);
762 break; 748 break;
763 } 749 }
764 }); 750 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld