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: Make use of the subscription.isDownloading property Created April 6, 2016, 9:31 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 }); 156 });
154 getPref("notifications_showui", function(notifications_showui) 157 getPref("notifications_showui", function(notifications_showui)
155 { 158 {
156 if (!notifications_showui) 159 if (!notifications_showui)
157 document.getElementById("shouldShowNotificationsContainer").hidden = true; 160 document.getElementById("shouldShowNotificationsContainer").hidden = true;
158 }); 161 });
159 162
160 // Register listeners in the background message responder 163 // Register listeners in the background message responder
161 ext.backgroundPage.sendMessage({ 164 ext.backgroundPage.sendMessage({
162 type: "app.listen", 165 type: "app.listen",
163 filter: ["addSubscription", "switchToOptionsSection"] 166 filter: ["addSubscription", "focusSection"]
164 }); 167 });
165 ext.backgroundPage.sendMessage( 168 ext.backgroundPage.sendMessage(
166 { 169 {
167 type: "filters.listen", 170 type: "filters.listen",
168 filter: ["added", "loaded", "removed"] 171 filter: ["added", "loaded", "removed"]
169 }); 172 });
170 ext.backgroundPage.sendMessage( 173 ext.backgroundPage.sendMessage(
171 { 174 {
172 type: "prefs.listen", 175 type: "prefs.listen",
173 filter: ["notifications_ignoredcategories", "notifications_showui", 176 filter: ["notifications_ignoredcategories", "notifications_showui",
(...skipping 16 matching lines...) Expand all
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 if (subscription.url == acceptableAdsUrl) 474 else if (!element)
478 $("#acceptableAds").prop("checked", true); 475 addSubscriptionEntry(subscription);
479 else if (!element)
480 addSubscriptionEntry(subscription);
481 });
482 break; 476 break;
483 case "removed": 477 case "removed":
484 getPref("subscriptions_exceptionsurl", function(acceptableAdsUrl) 478 if (subscription.url == acceptableAdsUrl)
485 { 479 $("#acceptableAds").prop("checked", false);
486 if (subscription.url == acceptableAdsUrl) 480 else if (element)
487 $("#acceptableAds").prop("checked", false); 481 element.parentNode.removeChild(element);
488 else if (element)
489 element.parentNode.removeChild(element);
490 });
491 break; 482 break;
492 } 483 }
493 } 484 }
494 485
495 function onPrefMessage(key, value) 486 function onPrefMessage(key, value)
496 { 487 {
497 switch (key) 488 switch (key)
498 { 489 {
499 case "notifications_showui": 490 case "notifications_showui":
500 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 491 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 { 709 {
719 switch (message.type) 710 switch (message.type)
720 { 711 {
721 case "app.respond": 712 case "app.respond":
722 switch (message.action) 713 switch (message.action)
723 { 714 {
724 case "addSubscription": 715 case "addSubscription":
725 var subscription = message.args[0]; 716 var subscription = message.args[0];
726 startSubscriptionSelection(subscription.title, subscription.url); 717 startSubscriptionSelection(subscription.title, subscription.url);
727 break; 718 break;
728 case "switchToOptionsSection": 719 case "focusSection":
Sebastian Noack 2016/04/06 23:00:18 As per Thomas' suggestion I changed that message t
kzar 2016/04/07 11:47:51 Done.
729 var tabs = document.getElementsByClassName("ui-tabs-panel"); 720 var tabs = document.getElementsByClassName("ui-tabs-panel");
730 for (var i = 0; i < tabs.length; i++) 721 for (var i = 0; i < tabs.length; i++)
731 { 722 {
732 var found = tabs[i].querySelector( 723 var found = tabs[i].querySelector(
733 "[data-section='" + message.args[0] + "']" 724 "[data-section='" + message.args[0] + "']"
734 ); 725 );
735 if (!found) 726 if (!found)
736 continue; 727 continue;
737 728
738 var previous = document.getElementsByClassName("focused"); 729 var previous = document.getElementsByClassName("focused");
(...skipping 11 matching lines...) Expand all
750 onFilterMessage(message.action, message.args[0]); 741 onFilterMessage(message.action, message.args[0]);
751 break; 742 break;
752 case "prefs.respond": 743 case "prefs.respond":
753 onPrefMessage(message.action, message.args[0]); 744 onPrefMessage(message.action, message.args[0]);
754 break; 745 break;
755 case "subscriptions.respond": 746 case "subscriptions.respond":
756 onSubscriptionMessage(message.action, message.args[0]); 747 onSubscriptionMessage(message.action, message.args[0]);
757 break; 748 break;
758 } 749 }
759 }); 750 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld