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

Side by Side Diff: desktop-options.js

Issue 29573735: Issue 4580 - Replace ext.backgroundPage.sendMessage with runtime.sendMessage (Closed) Base URL: https://hg.adblockplus.org/adblockplusui/
Patch Set: Created Oct. 11, 2017, 3:37 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 | « common.js ('k') | devtools-panel.js » ('j') | ext/content.js » ('J')
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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return element.getAttribute("data-" + dataName); 536 return element.getAttribute("data-" + dataName);
537 } 537 }
538 538
539 element = element.parentElement; 539 element = element.parentElement;
540 } 540 }
541 return null; 541 return null;
542 } 542 }
543 543
544 function sendMessageHandleErrors(message, onSuccess) 544 function sendMessageHandleErrors(message, onSuccess)
545 { 545 {
546 ext.backgroundPage.sendMessage(message, (errors) => 546 chrome.runtime.sendMessage(message, (errors) =>
547 { 547 {
548 if (errors.length > 0) 548 if (errors.length > 0)
549 alert(errors.join("\n")); 549 alert(errors.join("\n"));
550 else if (onSuccess) 550 else if (onSuccess)
551 onSuccess(); 551 onSuccess();
552 }); 552 });
553 } 553 }
554 554
555 function switchTab(id) 555 function switchTab(id)
556 { 556 {
(...skipping 21 matching lines...) Expand all
578 case "cancel-custom-filters": 578 case "cancel-custom-filters":
579 setCustomFiltersView("read"); 579 setCustomFiltersView("read");
580 break; 580 break;
581 case "change-language-subscription": 581 case "change-language-subscription":
582 for (let key in subscriptionsMap) 582 for (let key in subscriptionsMap)
583 { 583 {
584 let subscription = subscriptionsMap[key]; 584 let subscription = subscriptionsMap[key];
585 let subscriptionType = subscription.recommended; 585 let subscriptionType = subscription.recommended;
586 if (subscriptionType == "ads" && subscription.disabled == false) 586 if (subscriptionType == "ads" && subscription.disabled == false)
587 { 587 {
588 ext.backgroundPage.sendMessage({ 588 chrome.runtime.sendMessage({
589 type: "subscriptions.remove", 589 type: "subscriptions.remove",
590 url: subscription.url 590 url: subscription.url
591 }); 591 });
592 ext.backgroundPage.sendMessage({ 592 chrome.runtime.sendMessage({
593 type: "subscriptions.add", 593 type: "subscriptions.add",
594 url: findParentData(element, "access", false) 594 url: findParentData(element, "access", false)
595 }); 595 });
596 break; 596 break;
597 } 597 }
598 } 598 }
599 break; 599 break;
600 case "close-dialog": 600 case "close-dialog":
601 closeDialog(); 601 closeDialog();
602 break; 602 break;
(...skipping 17 matching lines...) Expand all
620 if (listItem && !listItem.classList.contains("show-context-menu")) 620 if (listItem && !listItem.classList.contains("show-context-menu"))
621 listItem.classList.add("show-context-menu"); 621 listItem.classList.add("show-context-menu");
622 break; 622 break;
623 } 623 }
624 case "open-dialog": { 624 case "open-dialog": {
625 let dialog = findParentData(element, "dialog", false); 625 let dialog = findParentData(element, "dialog", false);
626 openDialog(dialog); 626 openDialog(dialog);
627 break; 627 break;
628 } 628 }
629 case "remove-filter": 629 case "remove-filter":
630 ext.backgroundPage.sendMessage({ 630 chrome.runtime.sendMessage({
631 type: "filters.remove", 631 type: "filters.remove",
632 text: findParentData(element, "access", false) 632 text: findParentData(element, "access", false)
633 }); 633 });
634 break; 634 break;
635 case "remove-subscription": 635 case "remove-subscription":
636 ext.backgroundPage.sendMessage({ 636 chrome.runtime.sendMessage({
637 type: "subscriptions.remove", 637 type: "subscriptions.remove",
638 url: findParentData(element, "access", false) 638 url: findParentData(element, "access", false)
639 }); 639 });
640 break; 640 break;
641 case "save-custom-filters": 641 case "save-custom-filters":
642 sendMessageHandleErrors({ 642 sendMessageHandleErrors({
643 type: "filters.importRaw", 643 type: "filters.importRaw",
644 text: E("custom-filters-raw").value, 644 text: E("custom-filters-raw").value,
645 removeExisting: true 645 removeExisting: true
646 }, 646 },
647 () => 647 () =>
648 { 648 {
649 setCustomFiltersView("read"); 649 setCustomFiltersView("read");
650 }); 650 });
651 break; 651 break;
652 case "show-more-filters-section": 652 case "show-more-filters-section":
653 E("more-filters").setAttribute("aria-hidden", false); 653 E("more-filters").setAttribute("aria-hidden", false);
654 break; 654 break;
655 case "switch-acceptable-ads": 655 case "switch-acceptable-ads":
656 let value = element.value || element.dataset.value; 656 let value = element.value || element.dataset.value;
657 ext.backgroundPage.sendMessage({ 657 chrome.runtime.sendMessage({
658 type: value == "privacy" ? "subscriptions.add" : 658 type: value == "privacy" ? "subscriptions.add" :
659 "subscriptions.remove", 659 "subscriptions.remove",
660 url: acceptableAdsPrivacyUrl 660 url: acceptableAdsPrivacyUrl
661 }); 661 });
662 ext.backgroundPage.sendMessage({ 662 chrome.runtime.sendMessage({
663 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove", 663 type: value == "ads" ? "subscriptions.add" : "subscriptions.remove",
664 url: acceptableAdsUrl 664 url: acceptableAdsUrl
665 }); 665 });
666 break; 666 break;
667 case "switch-tab": 667 case "switch-tab":
668 switchTab(element.getAttribute("href").substr(1)); 668 switchTab(element.getAttribute("href").substr(1));
669 break; 669 break;
670 case "toggle-disable-subscription": 670 case "toggle-disable-subscription":
671 ext.backgroundPage.sendMessage({ 671 chrome.runtime.sendMessage({
672 type: "subscriptions.toggle", 672 type: "subscriptions.toggle",
673 keepInstalled: true, 673 keepInstalled: true,
674 url: findParentData(element, "access", false) 674 url: findParentData(element, "access", false)
675 }); 675 });
676 break; 676 break;
677 case "toggle-pref": 677 case "toggle-pref":
678 ext.backgroundPage.sendMessage({ 678 chrome.runtime.sendMessage({
679 type: "prefs.toggle", 679 type: "prefs.toggle",
680 key: findParentData(element, "pref", false) 680 key: findParentData(element, "pref", false)
681 }); 681 });
682 break; 682 break;
683 case "toggle-remove-subscription": 683 case "toggle-remove-subscription":
684 let subscriptionUrl = findParentData(element, "access", false); 684 let subscriptionUrl = findParentData(element, "access", false);
685 if (element.getAttribute("aria-checked") == "true") 685 if (element.getAttribute("aria-checked") == "true")
686 { 686 {
687 ext.backgroundPage.sendMessage({ 687 chrome.runtime.sendMessage({
688 type: "subscriptions.remove", 688 type: "subscriptions.remove",
689 url: subscriptionUrl 689 url: subscriptionUrl
690 }); 690 });
691 } 691 }
692 else 692 else
693 addEnableSubscription(subscriptionUrl); 693 addEnableSubscription(subscriptionUrl);
694 break; 694 break;
695 case "update-all-subscriptions": 695 case "update-all-subscriptions":
696 ext.backgroundPage.sendMessage({ 696 chrome.runtime.sendMessage({
697 type: "subscriptions.update" 697 type: "subscriptions.update"
698 }); 698 });
699 break; 699 break;
700 case "update-subscription": 700 case "update-subscription":
701 ext.backgroundPage.sendMessage({ 701 chrome.runtime.sendMessage({
702 type: "subscriptions.update", 702 type: "subscriptions.update",
703 url: findParentData(element, "access", false) 703 url: findParentData(element, "access", false)
704 }); 704 });
705 break; 705 break;
706 case "validate-import-subscription": 706 case "validate-import-subscription":
707 let form = findParentData(element, "validation", true); 707 let form = findParentData(element, "validation", true);
708 if (!form) 708 if (!form)
709 return; 709 return;
710 710
711 if (form.checkValidity()) 711 if (form.checkValidity())
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 if (!tabContent) 853 if (!tabContent)
854 break; 854 break;
855 } 855 }
856 } 856 }
857 857
858 function onDOMLoaded() 858 function onDOMLoaded()
859 { 859 {
860 populateLists(); 860 populateLists();
861 861
862 // Initialize navigation sidebar 862 // Initialize navigation sidebar
863 ext.backgroundPage.sendMessage({ 863 chrome.runtime.sendMessage({
864 type: "app.get", 864 type: "app.get",
865 what: "addonVersion" 865 what: "addonVersion"
866 }, 866 },
867 (addonVersion) => 867 (addonVersion) =>
868 { 868 {
869 E("abp-version").textContent = getMessage("options_dialog_about_version", 869 E("abp-version").textContent = getMessage("options_dialog_about_version",
870 [addonVersion]); 870 [addonVersion]);
871 }); 871 });
872 872
873 updateTooltips(); 873 updateTooltips();
(...skipping 28 matching lines...) Expand all
902 { 902 {
903 return checkbox.getAttribute("data-pref"); 903 return checkbox.getAttribute("data-pref");
904 }); 904 });
905 for (let key of customize) 905 for (let key of customize)
906 { 906 {
907 getPref(key, (value) => 907 getPref(key, (value) =>
908 { 908 {
909 onPrefMessage(key, value, true); 909 onPrefMessage(key, value, true);
910 }); 910 });
911 } 911 }
912 ext.backgroundPage.sendMessage({ 912 chrome.runtime.sendMessage({
913 type: "app.get", 913 type: "app.get",
914 what: "features" 914 what: "features"
915 }, 915 },
916 (features) => 916 (features) =>
917 { 917 {
918 hidePref("show_devtools_panel", !features.devToolsPanel); 918 hidePref("show_devtools_panel", !features.devToolsPanel);
919 }); 919 });
920 920
921 getDocLink("filterdoc", (link) => 921 getDocLink("filterdoc", (link) =>
922 { 922 {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 function populateLists() 1058 function populateLists()
1059 { 1059 {
1060 subscriptionsMap = Object.create(null); 1060 subscriptionsMap = Object.create(null);
1061 filtersMap = Object.create(null); 1061 filtersMap = Object.create(null);
1062 1062
1063 // Empty collections and lists 1063 // Empty collections and lists
1064 for (let property in collections) 1064 for (let property in collections)
1065 collections[property].clearAll(); 1065 collections[property].clearAll();
1066 1066
1067 setCustomFiltersView("empty"); 1067 setCustomFiltersView("empty");
1068 ext.backgroundPage.sendMessage({ 1068 chrome.runtime.sendMessage({
1069 type: "subscriptions.get", 1069 type: "subscriptions.get",
1070 special: true 1070 special: true
1071 }, 1071 },
1072 (subscriptions) => 1072 (subscriptions) =>
1073 { 1073 {
1074 // Load filters 1074 // Load filters
1075 for (let subscription of subscriptions) 1075 for (let subscription of subscriptions)
1076 { 1076 {
1077 ext.backgroundPage.sendMessage({ 1077 chrome.runtime.sendMessage({
1078 type: "filters.get", 1078 type: "filters.get",
1079 subscriptionUrl: subscription.url 1079 subscriptionUrl: subscription.url
1080 }, 1080 },
1081 (filters) => 1081 (filters) =>
1082 { 1082 {
1083 loadCustomFilters(filters); 1083 loadCustomFilters(filters);
1084 }); 1084 });
1085 } 1085 }
1086 }); 1086 });
1087 loadRecommendations(); 1087 loadRecommendations();
1088 ext.backgroundPage.sendMessage({ 1088 chrome.runtime.sendMessage({
1089 type: "prefs.get", 1089 type: "prefs.get",
1090 key: "subscriptions_exceptionsurl" 1090 key: "subscriptions_exceptionsurl"
1091 }, 1091 },
1092 (url) => 1092 (url) =>
1093 { 1093 {
1094 acceptableAdsUrl = url; 1094 acceptableAdsUrl = url;
1095 1095
1096 ext.backgroundPage.sendMessage({ 1096 chrome.runtime.sendMessage({
1097 type: "prefs.get", 1097 type: "prefs.get",
1098 key: "subscriptions_exceptionsurl_privacy" 1098 key: "subscriptions_exceptionsurl_privacy"
1099 }, 1099 },
1100 (urlPrivacy) => 1100 (urlPrivacy) =>
1101 { 1101 {
1102 acceptableAdsPrivacyUrl = urlPrivacy; 1102 acceptableAdsPrivacyUrl = urlPrivacy;
1103 1103
1104 // Load user subscriptions 1104 // Load user subscriptions
1105 ext.backgroundPage.sendMessage({ 1105 chrome.runtime.sendMessage({
1106 type: "subscriptions.get", 1106 type: "subscriptions.get",
1107 downloadable: true 1107 downloadable: true
1108 }, 1108 },
1109 (subscriptions) => 1109 (subscriptions) =>
1110 { 1110 {
1111 for (let subscription of subscriptions) 1111 for (let subscription of subscriptions)
1112 onSubscriptionMessage("added", subscription); 1112 onSubscriptionMessage("added", subscription);
1113 1113
1114 setAcceptableAds(); 1114 setAcceptableAds();
1115 }); 1115 });
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1153
1154 let message = { 1154 let message = {
1155 type: messageType, 1155 type: messageType,
1156 url 1156 url
1157 }; 1157 };
1158 if (title) 1158 if (title)
1159 message.title = title; 1159 message.title = title;
1160 if (homepage) 1160 if (homepage)
1161 message.homepage = homepage; 1161 message.homepage = homepage;
1162 1162
1163 ext.backgroundPage.sendMessage(message); 1163 chrome.runtime.sendMessage(message);
1164 } 1164 }
1165 1165
1166 function onFilterMessage(action, filter) 1166 function onFilterMessage(action, filter)
1167 { 1167 {
1168 switch (action) 1168 switch (action)
1169 { 1169 {
1170 case "added": 1170 case "added":
1171 filter[timestampUI] = Date.now(); 1171 filter[timestampUI] = Date.now();
1172 updateFilter(filter); 1172 updateFilter(filter);
1173 break; 1173 break;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 { 1264 {
1265 let checkPref = getPref.checks[key] || getPref.checkNone; 1265 let checkPref = getPref.checks[key] || getPref.checkNone;
1266 checkPref((isActive) => 1266 checkPref((isActive) =>
1267 { 1267 {
1268 if (!isActive) 1268 if (!isActive)
1269 { 1269 {
1270 hidePref(key, !isActive); 1270 hidePref(key, !isActive);
1271 return; 1271 return;
1272 } 1272 }
1273 1273
1274 ext.backgroundPage.sendMessage({ 1274 chrome.runtime.sendMessage({
1275 type: "prefs.get", 1275 type: "prefs.get",
1276 key 1276 key
1277 }, callback); 1277 }, callback);
1278 }); 1278 });
1279 } 1279 }
1280 1280
1281 getPref.checkNone = function(callback) 1281 getPref.checkNone = function(callback)
1282 { 1282 {
1283 callback(true); 1283 callback(true);
1284 }; 1284 };
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 break; 1358 break;
1359 case "prefs.respond": 1359 case "prefs.respond":
1360 onPrefMessage(message.action, message.args[0], false); 1360 onPrefMessage(message.action, message.args[0], false);
1361 break; 1361 break;
1362 case "subscriptions.respond": 1362 case "subscriptions.respond":
1363 onSubscriptionMessage(message.action, message.args[0]); 1363 onSubscriptionMessage(message.action, message.args[0]);
1364 break; 1364 break;
1365 } 1365 }
1366 }); 1366 });
1367 1367
1368 ext.backgroundPage.sendMessage({ 1368 chrome.runtime.sendMessage({
1369 type: "app.listen", 1369 type: "app.listen",
1370 filter: ["addSubscription", "focusSection"] 1370 filter: ["addSubscription", "focusSection"]
1371 }); 1371 });
1372 ext.backgroundPage.sendMessage({ 1372 chrome.runtime.sendMessage({
1373 type: "filters.listen", 1373 type: "filters.listen",
1374 filter: ["added", "loaded", "removed"] 1374 filter: ["added", "loaded", "removed"]
1375 }); 1375 });
1376 ext.backgroundPage.sendMessage({ 1376 chrome.runtime.sendMessage({
1377 type: "prefs.listen", 1377 type: "prefs.listen",
1378 filter: ["notifications_ignoredcategories", "notifications_showui", 1378 filter: ["notifications_ignoredcategories", "notifications_showui",
1379 "show_devtools_panel", "shouldShowBlockElementMenu"] 1379 "show_devtools_panel", "shouldShowBlockElementMenu"]
1380 }); 1380 });
1381 ext.backgroundPage.sendMessage({ 1381 chrome.runtime.sendMessage({
1382 type: "subscriptions.listen", 1382 type: "subscriptions.listen",
1383 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1383 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1384 "title", "downloadStatus", "downloading"] 1384 "title", "downloadStatus", "downloading"]
1385 }); 1385 });
1386 1386
1387 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1387 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1388 window.addEventListener("hashchange", onHashChange, false); 1388 window.addEventListener("hashchange", onHashChange, false);
1389 } 1389 }
OLDNEW
« no previous file with comments | « common.js ('k') | devtools-panel.js » ('j') | ext/content.js » ('J')

Powered by Google App Engine
This is Rietveld