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

Side by Side Diff: desktop-options.js

Issue 29674584: Issue 5549 - Implement missing error handlings for custom filter lists (Closed)
Patch Set: removed filterError flag + added better way to check invalid filters Created Jan. 30, 2018, 1:11 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 | « desktop-options.html ('k') | locale/en_US/desktop-options.json » ('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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (returnElement) 540 if (returnElement)
541 return element; 541 return element;
542 return element.getAttribute("data-" + dataName); 542 return element.getAttribute("data-" + dataName);
543 } 543 }
544 544
545 element = element.parentElement; 545 element = element.parentElement;
546 } 546 }
547 return null; 547 return null;
548 } 548 }
549 549
550 function sendMessageHandleErrors(message, onSuccess) 550 function sendMessageHandleErrors(message, callback)
551 { 551 {
552 browser.runtime.sendMessage(message, (errors) => 552 browser.runtime.sendMessage(message, (errors) =>
553 { 553 {
554 if (errors.length > 0) 554 if (callback)
555 alert(errors.join("\n")); 555 {
556 else if (onSuccess) 556 if (errors.length > 0)
557 onSuccess(); 557 callback(errors);
558 else
559 callback();
560 }
558 }); 561 });
559 } 562 }
560 563
561 function switchTab(id) 564 function switchTab(id)
562 { 565 {
563 location.hash = id; 566 location.hash = id;
564 } 567 }
565 568
566 function execAction(action, element) 569 function execAction(action, element)
567 { 570 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 text: findParentData(element, "access", false) 644 text: findParentData(element, "access", false)
642 }); 645 });
643 break; 646 break;
644 case "remove-subscription": 647 case "remove-subscription":
645 browser.runtime.sendMessage({ 648 browser.runtime.sendMessage({
646 type: "subscriptions.remove", 649 type: "subscriptions.remove",
647 url: findParentData(element, "access", false) 650 url: findParentData(element, "access", false)
648 }); 651 });
649 break; 652 break;
650 case "save-custom-filters": 653 case "save-custom-filters":
654 const filters = E("custom-filters-raw").value;
651 sendMessageHandleErrors({ 655 sendMessageHandleErrors({
652 type: "filters.importRaw", 656 type: "filters.importRaw",
653 text: E("custom-filters-raw").value, 657 text: filters,
654 removeExisting: true 658 removeExisting: true
655 }, 659 },
656 () => 660 (errors) =>
657 { 661 {
658 setCustomFiltersView("read"); 662 if (errors)
663 {
664 E("custom-filters").classList.add("warning");
665 const editFilters = E("custom-filters-error");
666 editFilters.textContent = "";
667
668 // The current error does not contain info about the line
669 // that generated such error.
670 // Whenever the error object will pass the bad filter
671 // within its properties, this split should be removed.
672 const lines = filters.split("\n");
673 const messages = errors.map(error => lines[error.lineno - 1]);
674 for (const message of messages)
675 {
676 const li = document.createElement("li");
677 editFilters.appendChild(li).textContent = message;
678 }
679 if (errors.length > 5)
680 editFilters.classList.add("many");
681 }
682 else
683 {
684 setCustomFiltersView("read");
685 }
659 }); 686 });
660 break; 687 break;
661 case "show-more-filters-section": 688 case "show-more-filters-section":
662 E("more-filters").setAttribute("aria-hidden", false); 689 E("more-filters").setAttribute("aria-hidden", false);
663 break; 690 break;
664 case "switch-acceptable-ads": 691 case "switch-acceptable-ads":
665 let value = element.value || element.dataset.value; 692 let value = element.value || element.dataset.value;
666 // User check the checkbox 693 // User check the checkbox
667 let shouldCheck = element.getAttribute("aria-checked") != "true"; 694 let shouldCheck = element.getAttribute("aria-checked") != "true";
668 let installAcceptableAds = false; 695 let installAcceptableAds = false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 break; 775 break;
749 } 776 }
750 } 777 }
751 778
752 function setCustomFiltersView(mode) 779 function setCustomFiltersView(mode)
753 { 780 {
754 let customFiltersElement = E("custom-filters-raw"); 781 let customFiltersElement = E("custom-filters-raw");
755 updateCustomFiltersUi(); 782 updateCustomFiltersUi();
756 if (mode == "read") 783 if (mode == "read")
757 { 784 {
785 E("custom-filters").classList.remove("warning");
786 const editFilters = E("custom-filters-error");
787 editFilters.textContent = "";
788 editFilters.classList.remove("many");
758 customFiltersElement.disabled = true; 789 customFiltersElement.disabled = true;
759 if (!customFiltersElement.value) 790 if (!customFiltersElement.value)
760 { 791 {
761 setCustomFiltersView("empty"); 792 setCustomFiltersView("empty");
762 return; 793 return;
763 } 794 }
764 } 795 }
765 else if (mode == "write") 796 else if (mode == "write")
766 { 797 {
767 customFiltersElement.disabled = false; 798 customFiltersElement.disabled = false;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 942
912 // General tab 943 // General tab
913 getDocLink("contribute", (link) => 944 getDocLink("contribute", (link) =>
914 { 945 {
915 E("contribute").href = link; 946 E("contribute").href = link;
916 }); 947 });
917 getDocLink("acceptable_ads_criteria", (link) => 948 getDocLink("acceptable_ads_criteria", (link) =>
918 { 949 {
919 setLinks("enable-acceptable-ads-description", link); 950 setLinks("enable-acceptable-ads-description", link);
920 }); 951 });
921 setElementText(E("tracking-warning-1"), "options_tracking_warning_1", 952 setElementText(E("tracking-warning-1"), "options_tracking_warning_1",
922 [getMessage("common_feature_privacy_title"), 953 [getMessage("common_feature_privacy_title"),
923 getMessage("options_acceptableAds_ads_label")]); 954 getMessage("options_acceptableAds_ads_label")]);
924 setElementText(E("tracking-warning-3"), "options_tracking_warning_3", 955 setElementText(E("tracking-warning-3"), "options_tracking_warning_3",
925 [getMessage("options_acceptableAds_privacy_label")]); 956 [getMessage("options_acceptableAds_privacy_label")]);
926 957
927 getDocLink("privacy_friendly_ads", (link) => 958 getDocLink("privacy_friendly_ads", (link) =>
928 { 959 {
929 E("enable-acceptable-ads-privacy-description").href = link; 960 E("enable-acceptable-ads-privacy-description").href = link;
930 }); 961 });
931 getDocLink("adblock_plus_{browser}_dnt", url => 962 getDocLink("adblock_plus_{browser}_dnt", url =>
932 { 963 {
933 setLinks("dnt", url); 964 setLinks("dnt", url);
934 }); 965 });
(...skipping 21 matching lines...) Expand all
956 type: "app.get", 987 type: "app.get",
957 what: "features" 988 what: "features"
958 }, 989 },
959 (features) => 990 (features) =>
960 { 991 {
961 hidePref("show_devtools_panel", !features.devToolsPanel); 992 hidePref("show_devtools_panel", !features.devToolsPanel);
962 }); 993 });
963 994
964 getDocLink("filterdoc", (link) => 995 getDocLink("filterdoc", (link) =>
965 { 996 {
966 E("link-filters").setAttribute("href", link); 997 E("link-filters-1").setAttribute("href", link);
998 E("link-filters-2").setAttribute("href", link);
967 }); 999 });
968 1000
969 getDocLink("subscriptions", (link) => 1001 getDocLink("subscriptions", (link) =>
970 { 1002 {
971 E("filter-lists-learn-more").setAttribute("href", link); 1003 E("filter-lists-learn-more").setAttribute("href", link);
972 }); 1004 });
973 1005
974 E("custom-filters-raw").setAttribute("placeholder", 1006 E("custom-filters-raw").setAttribute("placeholder",
975 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); 1007 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"]));
976 1008
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 }, 1184 },
1153 (subscriptions) => 1185 (subscriptions) =>
1154 { 1186 {
1155 // Load filters 1187 // Load filters
1156 for (let subscription of subscriptions) 1188 for (let subscription of subscriptions)
1157 { 1189 {
1158 browser.runtime.sendMessage({ 1190 browser.runtime.sendMessage({
1159 type: "filters.get", 1191 type: "filters.get",
1160 subscriptionUrl: subscription.url 1192 subscriptionUrl: subscription.url
1161 }, 1193 },
1162 (filters) => 1194 loadCustomFilters);
1163 {
1164 loadCustomFilters(filters);
1165 });
1166 } 1195 }
1167 }); 1196 });
1168 loadRecommendations(); 1197 loadRecommendations();
1169 browser.runtime.sendMessage({ 1198 browser.runtime.sendMessage({
1170 type: "prefs.get", 1199 type: "prefs.get",
1171 key: "subscriptions_exceptionsurl" 1200 key: "subscriptions_exceptionsurl"
1172 }, 1201 },
1173 (url) => 1202 (url) =>
1174 { 1203 {
1175 acceptableAdsUrl = url; 1204 acceptableAdsUrl = url;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 setPrivacyConflict(); 1317 setPrivacyConflict();
1289 break; 1318 break;
1290 case "downloading": 1319 case "downloading":
1291 case "downloadStatus": 1320 case "downloadStatus":
1292 case "homepage": 1321 case "homepage":
1293 case "lastDownload": 1322 case "lastDownload":
1294 case "title": 1323 case "title":
1295 updateSubscription(subscription); 1324 updateSubscription(subscription);
1296 break; 1325 break;
1297 case "added": 1326 case "added":
1298 let {url, recommended} = subscription; 1327 let {url} = subscription;
1299 // Handle custom subscription 1328 // Handle custom subscription
1300 if (/^~user/.test(url)) 1329 if (/^~user/.test(url))
1301 { 1330 {
1302 loadCustomFilters(subscription.filters); 1331 loadCustomFilters(subscription.filters);
1303 return; 1332 return;
1304 } 1333 }
1305 else if (url in subscriptionsMap) 1334 else if (url in subscriptionsMap)
1306 updateSubscription(subscription); 1335 updateSubscription(subscription);
1307 else 1336 else
1308 addSubscription(subscription); 1337 addSubscription(subscription);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 }); 1498 });
1470 browser.runtime.sendMessage({ 1499 browser.runtime.sendMessage({
1471 type: "subscriptions.listen", 1500 type: "subscriptions.listen",
1472 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1501 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1473 "title", "downloadStatus", "downloading"] 1502 "title", "downloadStatus", "downloading"]
1474 }); 1503 });
1475 1504
1476 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1505 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1477 window.addEventListener("hashchange", onHashChange, false); 1506 window.addEventListener("hashchange", onHashChange, false);
1478 } 1507 }
OLDNEW
« no previous file with comments | « desktop-options.html ('k') | locale/en_US/desktop-options.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld