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

Delta Between Two Patch Sets: chrome/content/ui/sendReport.js

Issue 6519778499887104: Issue 2010 - Remove some uses of "for each" with "for of" (Closed)
Left Patch Set: Created Feb. 18, 2015, 1:32 p.m.
Right Patch Set: Created Feb. 26, 2015, 11:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/ui/filters-subscriptionview.js ('k') | chrome/content/ui/sidebar.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
(no file at all)
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 904
905 collectData: function(wnd, windowURI, callback) 905 collectData: function(wnd, windowURI, callback)
906 { 906 {
907 this.contentWnd = wnd; 907 this.contentWnd = wnd;
908 this.whitelistFilter = Policy.isWindowWhitelisted(wnd); 908 this.whitelistFilter = Policy.isWindowWhitelisted(wnd);
909 909
910 if (!this.whitelistFilter && this.isEnabled) 910 if (!this.whitelistFilter && this.isEnabled)
911 { 911 {
912 // Find disabled filters in active subscriptions matching any of the reque sts 912 // Find disabled filters in active subscriptions matching any of the reque sts
913 let disabledMatcher = new CombinedMatcher(); 913 let disabledMatcher = new CombinedMatcher();
914 for each (let subscription in FilterStorage.subscriptions) 914 for (let subscription of FilterStorage.subscriptions)
915 { 915 {
916 if (subscription.disabled) 916 if (subscription.disabled)
917 continue; 917 continue;
918 918
919 for each (let filter in subscription.filters) 919 for (let filter of subscription.filters)
920 if (filter instanceof BlockingFilter && filter.disabled) 920 if (filter instanceof BlockingFilter && filter.disabled)
921 disabledMatcher.add(filter); 921 disabledMatcher.add(filter);
922 } 922 }
923 923
924 let seenFilters = Object.create(null); 924 let seenFilters = Object.create(null);
925 for each (let request in requestsDataSource.origRequests) 925 for (let request of requestsDataSource.origRequests)
926 { 926 {
927 if (request.filter) 927 if (request.filter)
928 continue; 928 continue;
929 929
930 let filter = disabledMatcher.matchesAny(request.location, request.typeDe scr, request.docDomain, request.thirdParty); 930 let filter = disabledMatcher.matchesAny(request.location, request.typeDe scr, request.docDomain, request.thirdParty);
931 if (filter && !(filter.text in seenFilters)) 931 if (filter && !(filter.text in seenFilters))
932 { 932 {
933 this.disabledFilters.push(filter); 933 this.disabledFilters.push(filter);
934 seenFilters[filter.text] = true; 934 seenFilters[filter.text] = true;
935 } 935 }
936 } 936 }
937 937
938 // Find disabled subscriptions with filters matching any of the requests 938 // Find disabled subscriptions with filters matching any of the requests
939 let seenSubscriptions = Object.create(null); 939 let seenSubscriptions = Object.create(null);
940 for each (let subscription in FilterStorage.subscriptions) 940 for (let subscription of FilterStorage.subscriptions)
941 { 941 {
942 if (!subscription.disabled) 942 if (!subscription.disabled)
943 continue; 943 continue;
944 944
945 disabledMatcher.clear(); 945 disabledMatcher.clear();
946 for each (let filter in subscription.filters) 946 for (let filter of subscription.filters)
947 if (filter instanceof BlockingFilter) 947 if (filter instanceof BlockingFilter)
948 disabledMatcher.add(filter); 948 disabledMatcher.add(filter);
949 949
950 for each (let request in requestsDataSource.origRequests) 950 for (let request of requestsDataSource.origRequests)
951 { 951 {
952 if (request.filter) 952 if (request.filter)
953 continue; 953 continue;
954 954
955 let filter = disabledMatcher.matchesAny(request.location, request.type Descr, request.docDomain, request.thirdParty); 955 let filter = disabledMatcher.matchesAny(request.location, request.type Descr, request.docDomain, request.thirdParty);
956 if (filter && !(subscription.url in seenSubscriptions)) 956 if (filter && !(subscription.url in seenSubscriptions))
957 { 957 {
958 this.disabledSubscriptions.push(subscription); 958 this.disabledSubscriptions.push(subscription);
959 seenSubscriptions[subscription.text] = true; 959 seenSubscriptions[subscription.text] = true;
960 break; 960 break;
961 } 961 }
962 } 962 }
963 } 963 }
964 964
965 this.numSubscriptions = FilterStorage.subscriptions.filter(this.subscripti onFilter).length; 965 this.numSubscriptions = FilterStorage.subscriptions.filter(this.subscripti onFilter).length;
966 this.numAppliedFilters = 0; 966 this.numAppliedFilters = 0;
967 for each (let filter in filtersDataSource.origFilters) 967 for (let filter of filtersDataSource.origFilters)
968 { 968 {
969 if (filter instanceof WhitelistFilter) 969 if (filter instanceof WhitelistFilter)
970 continue; 970 continue;
971 971
972 this.numAppliedFilters++; 972 this.numAppliedFilters++;
973 if (filter.subscriptions.some(function(subscription) subscription instan ceof SpecialSubscription)) 973 if (filter.subscriptions.some(function(subscription) subscription instan ceof SpecialSubscription))
974 this.ownFilters.push(filter); 974 this.ownFilters.push(filter);
975 } 975 }
976 } 976 }
977 977
(...skipping 11 matching lines...) Expand all
989 E("issuesWhitelistBox").hidden = !this.whitelistFilter; 989 E("issuesWhitelistBox").hidden = !this.whitelistFilter;
990 E("issuesDisabledBox").hidden = this.isEnabled; 990 E("issuesDisabledBox").hidden = this.isEnabled;
991 E("issuesNoFiltersBox").hidden = (type != "false positive" || this.numApplie dFilters > 0); 991 E("issuesNoFiltersBox").hidden = (type != "false positive" || this.numApplie dFilters > 0);
992 E("issuesNoSubscriptionsBox").hidden = (type != "false negative" || this.num AppliedFilters > 0 || this.numSubscriptions > 0); 992 E("issuesNoSubscriptionsBox").hidden = (type != "false negative" || this.num AppliedFilters > 0 || this.numSubscriptions > 0);
993 E("issuesSubscriptionCountBox").hidden = (this.numSubscriptions < 5); 993 E("issuesSubscriptionCountBox").hidden = (this.numSubscriptions < 5);
994 994
995 let ownFiltersBox = E("issuesOwnFilters"); 995 let ownFiltersBox = E("issuesOwnFilters");
996 if (this.ownFilters.length && !ownFiltersBox.firstChild) 996 if (this.ownFilters.length && !ownFiltersBox.firstChild)
997 { 997 {
998 let template = E("issuesOwnFiltersTemplate"); 998 let template = E("issuesOwnFiltersTemplate");
999 for each (let filter in this.ownFilters) 999 for (let filter of this.ownFilters)
1000 { 1000 {
1001 let element = template.cloneNode(true); 1001 let element = template.cloneNode(true);
1002 element.removeAttribute("id"); 1002 element.removeAttribute("id");
1003 element.removeAttribute("hidden"); 1003 element.removeAttribute("hidden");
1004 element.firstChild.setAttribute("value", filter.text); 1004 element.firstChild.setAttribute("value", filter.text);
1005 element.firstChild.setAttribute("tooltiptext", filter.text); 1005 element.firstChild.setAttribute("tooltiptext", filter.text);
1006 element.abpFilter = filter; 1006 element.abpFilter = filter;
1007 ownFiltersBox.appendChild(element); 1007 ownFiltersBox.appendChild(element);
1008 } 1008 }
1009 } 1009 }
1010 E("issuesOwnFiltersBox").hidden = (type != "false positive" || this.ownFilte rs.length == 0); 1010 E("issuesOwnFiltersBox").hidden = (type != "false positive" || this.ownFilte rs.length == 0);
1011 1011
1012 let disabledSubscriptionsBox = E("issuesDisabledSubscriptions"); 1012 let disabledSubscriptionsBox = E("issuesDisabledSubscriptions");
1013 if (this.disabledSubscriptions.length && !disabledSubscriptionsBox.firstChil d) 1013 if (this.disabledSubscriptions.length && !disabledSubscriptionsBox.firstChil d)
1014 { 1014 {
1015 let template = E("issuesDisabledSubscriptionsTemplate"); 1015 let template = E("issuesDisabledSubscriptionsTemplate");
1016 for each (let subscription in this.disabledSubscriptions) 1016 for (let subscription of this.disabledSubscriptions)
1017 { 1017 {
1018 let element = template.cloneNode(true); 1018 let element = template.cloneNode(true);
1019 element.removeAttribute("id"); 1019 element.removeAttribute("id");
1020 element.removeAttribute("hidden"); 1020 element.removeAttribute("hidden");
1021 element.firstChild.setAttribute("value", subscription.title); 1021 element.firstChild.setAttribute("value", subscription.title);
1022 element.setAttribute("tooltiptext", subscription instanceof Downloadable Subscription ? subscription.url : subscription.title); 1022 element.setAttribute("tooltiptext", subscription instanceof Downloadable Subscription ? subscription.url : subscription.title);
1023 element.abpSubscription = subscription; 1023 element.abpSubscription = subscription;
1024 disabledSubscriptionsBox.appendChild(element); 1024 disabledSubscriptionsBox.appendChild(element);
1025 } 1025 }
1026 } 1026 }
1027 E("issuesDisabledSubscriptionsBox").hidden = (type != "false negative" || th is.disabledSubscriptions.length == 0); 1027 E("issuesDisabledSubscriptionsBox").hidden = (type != "false negative" || th is.disabledSubscriptions.length == 0);
1028 1028
1029 let disabledFiltersBox = E("issuesDisabledFilters"); 1029 let disabledFiltersBox = E("issuesDisabledFilters");
1030 if (this.disabledFilters.length && !disabledFiltersBox.firstChild) 1030 if (this.disabledFilters.length && !disabledFiltersBox.firstChild)
1031 { 1031 {
1032 let template = E("issuesDisabledFiltersTemplate"); 1032 let template = E("issuesDisabledFiltersTemplate");
1033 for each (let filter in this.disabledFilters) 1033 for (let filter of this.disabledFilters)
1034 { 1034 {
1035 let element = template.cloneNode(true); 1035 let element = template.cloneNode(true);
1036 element.removeAttribute("id"); 1036 element.removeAttribute("id");
1037 element.removeAttribute("hidden"); 1037 element.removeAttribute("hidden");
1038 element.firstChild.setAttribute("value", filter.text); 1038 element.firstChild.setAttribute("value", filter.text);
1039 element.setAttribute("tooltiptext", filter.text); 1039 element.setAttribute("tooltiptext", filter.text);
1040 element.abpFilter = filter; 1040 element.abpFilter = filter;
1041 disabledFiltersBox.appendChild(element); 1041 disabledFiltersBox.appendChild(element);
1042 } 1042 }
1043 } 1043 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 { 1112 {
1113 let result = {}; 1113 let result = {};
1114 openDialog("subscriptionSelection.xul", "_blank", "chrome,centerscreen,modal ,resizable,dialog=no", null, result); 1114 openDialog("subscriptionSelection.xul", "_blank", "chrome,centerscreen,modal ,resizable,dialog=no", null, result);
1115 if (!("url" in result)) 1115 if (!("url" in result))
1116 return; 1116 return;
1117 1117
1118 let subscriptionResults = [[result.url, result.title]]; 1118 let subscriptionResults = [[result.url, result.title]];
1119 if ("mainSubscriptionURL" in result) 1119 if ("mainSubscriptionURL" in result)
1120 subscriptionResults.push([result.mainSubscriptionURL, result.mainSubscript ionTitle]); 1120 subscriptionResults.push([result.mainSubscriptionURL, result.mainSubscript ionTitle]);
1121 1121
1122 for each (let [url, title] in subscriptionResults) 1122 for (let [url, title] of subscriptionResults)
1123 { 1123 {
1124 let subscription = Subscription.fromURL(url); 1124 let subscription = Subscription.fromURL(url);
1125 if (!subscription) 1125 if (!subscription)
1126 continue; 1126 continue;
1127 1127
1128 FilterStorage.addSubscription(subscription); 1128 FilterStorage.addSubscription(subscription);
1129 1129
1130 subscription.disabled = false; 1130 subscription.disabled = false;
1131 subscription.title = title; 1131 subscription.title = title;
1132 1132
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 1574
1575 function censorURL(url) 1575 function censorURL(url)
1576 { 1576 {
1577 return url.replace(/([?;&\/#][^?;&\/#]+?=)[^?;&\/#]+/g, "$1*"); 1577 return url.replace(/([?;&\/#][^?;&\/#]+?=)[^?;&\/#]+/g, "$1*");
1578 } 1578 }
1579 1579
1580 function encodeHTML(str) 1580 function encodeHTML(str)
1581 { 1581 {
1582 return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"). replace(/"/g, "&quot;"); 1582 return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"). replace(/"/g, "&quot;");
1583 } 1583 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld