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

Delta Between Two Patch Sets: firstRun.js

Issue 6180766664884224: Issue 1663 - Made first-run page use an asynchronous messaging protocol (Closed)
Left Patch Set: More common approach to wrapping code Created Dec. 17, 2014, 1:12 p.m.
Right Patch Set: Adressed comments Created Dec. 18, 2014, 7:30 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 | « ext/content.js ('k') | no next file » | 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 25 matching lines...) Expand all
36 { 36 {
37 feature: "tracking", 37 feature: "tracking",
38 homepage: "https://easylist.adblockplus.org/", 38 homepage: "https://easylist.adblockplus.org/",
39 title: "EasyPrivacy", 39 title: "EasyPrivacy",
40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt" 40 url: "https://easylist-downloads.adblockplus.org/easyprivacy.txt"
41 } 41 }
42 ]; 42 ];
43 43
44 function getDocLink(link, callback) 44 function getDocLink(link, callback)
45 { 45 {
46 ext.backgroundPage.sendMessage({type: "app.doclink", args: [link]}, callback ); 46 ext.backgroundPage.sendMessage({
47 type: "app.get",
48 what: "doclink",
49 link: link
50 }, callback);
47 } 51 }
48 52
49 function onDOMLoaded() 53 function onDOMLoaded()
50 { 54 {
51 // Set up URLs 55 // Set up URLs
52 getDocLink("donate", function(link) 56 getDocLink("donate", function(link)
53 { 57 {
54 E("donate").href = link; 58 E("donate").href = link;
55 }); 59 });
56 60
57 getDocLink("contributors", function(link) 61 getDocLink("contributors", function(link)
58 { 62 {
59 E("contributors").href = link; 63 E("contributors").href = link;
60 }); 64 });
61 65
62 getDocLink("acceptable_ads_criteria", function(link) 66 getDocLink("acceptable_ads_criteria", function(link)
63 { 67 {
64 setLinks("acceptableAdsExplanation", link, openFilters); 68 setLinks("acceptableAdsExplanation", link, openFilters);
65 }); 69 });
66 70
67 getDocLink("contribute", function(link) 71 getDocLink("contribute", function(link)
68 { 72 {
69 setLinks("share-headline", link); 73 setLinks("share-headline", link);
70 }); 74 });
71 75
72 ext.backgroundPage.sendMessage({type: "app.issues"}, function(issues) 76 ext.backgroundPage.sendMessage({
77 type: "app.get",
78 what: "issues"
79 }, function(issues)
73 { 80 {
74 // Show warning if data corruption was detected 81 // Show warning if data corruption was detected
75 if (issues.seenDataCorruption) 82 if (issues.seenDataCorruption)
76 { 83 {
77 E("dataCorruptionWarning").removeAttribute("hidden"); 84 E("dataCorruptionWarning").removeAttribute("hidden");
78 getDocLink("knownIssuesChrome_filterstorage", function(link) 85 getDocLink("knownIssuesChrome_filterstorage", function(link)
79 { 86 {
80 setLinks("dataCorruptionWarning", link); 87 setLinks("dataCorruptionWarning", link);
81 }); 88 });
82 } 89 }
83 90
84 // Show warning if filterlists settings were reinitialized 91 // Show warning if filterlists settings were reinitialized
85 if (issues.filterlistsReinitialized) 92 if (issues.filterlistsReinitialized)
86 { 93 {
87 E("filterlistsReinitializedWarning").removeAttribute("hidden"); 94 E("filterlistsReinitializedWarning").removeAttribute("hidden");
88 setLinks("filterlistsReinitializedWarning", openFilters); 95 setLinks("filterlistsReinitializedWarning", openFilters);
89 } 96 }
90 }); 97
91 98 if (issues.legacySafariVersion)
92 // Show warning if Safari version isn't supported
93 ext.backgroundPage.sendMessage({type: "app.info"}, function(info)
94 {
95 if (info.platform == "safari" && (
96 parseInt(info.platformVersion, 10) < 6 || // beforeload breaks websites in Safari 5
97 info.platformVersion == "6.1" || // extensions are broken in 6 .1 and 7.0
98 info.platformVersion == "7.0"
99 ))
100 {
101 E("legacySafariWarning").removeAttribute("hidden"); 99 E("legacySafariWarning").removeAttribute("hidden");
102 }
103 }); 100 });
104 101
105 // Set up feature buttons linked to subscriptions 102 // Set up feature buttons linked to subscriptions
106 featureSubscriptions.forEach(initToggleSubscriptionButton); 103 featureSubscriptions.forEach(initToggleSubscriptionButton);
107 updateToggleButtons(); 104 updateToggleButtons();
108 initSocialLinks(); 105 updateSocialLinks();
109 106
110 ext.onMessage.addListener(function(message) 107 ext.onMessage.addListener(function(message)
111 { 108 {
112 if (message.type == "subscriptions.listen") 109 if (message.type == "subscriptions.listen")
113 { 110 {
114 updateToggleButtons(); 111 updateToggleButtons();
115 initSocialLinks(); 112 updateSocialLinks();
116 } 113 }
117 }); 114 });
118 ext.backgroundPage.sendMessage({type: "subscriptions.listen", filter: ["adde d", "removed", "disabled"]}); 115 ext.backgroundPage.sendMessage({
116 type: "subscriptions.listen",
117 filter: ["added", "removed", "disabled"]
118 });
119 } 119 }
120 120
121 function initToggleSubscriptionButton(featureSubscription) 121 function initToggleSubscriptionButton(featureSubscription)
122 { 122 {
123 var feature = featureSubscription.feature; 123 var feature = featureSubscription.feature;
124 124
125 var element = E("toggle-" + feature); 125 var element = E("toggle-" + feature);
126 element.addEventListener("click", function(event) 126 element.addEventListener("click", function(event)
127 { 127 {
128 ext.backgroundPage.sendMessage({ 128 ext.backgroundPage.sendMessage({
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 178
179 iframe.removeEventListener("load", popupLoadListener); 179 iframe.removeEventListener("load", popupLoadListener);
180 }; 180 };
181 iframe.addEventListener("load", popupLoadListener, false); 181 iframe.addEventListener("load", popupLoadListener, false);
182 182
183 iframe.src = url; 183 iframe.src = url;
184 glassPane.className = "visible"; 184 glassPane.className = "visible";
185 } 185 }
186 186
187 function initSocialLinks() 187 function updateSocialLinks()
188 { 188 {
189 var networks = ["twitter", "facebook", "gplus"]; 189 var networks = ["twitter", "facebook", "gplus"];
190 networks.forEach(function(network) 190 networks.forEach(function(network)
191 { 191 {
192 var link = E("share-" + network); 192 var link = E("share-" + network);
193 var message = { 193 var message = {
194 type: "filters.blocked", 194 type: "filters.blocked",
195 url: link.getAttribute("data-script"), 195 url: link.getAttribute("data-script"),
196 requestType: "SCRIPT", 196 requestType: "SCRIPT",
197 docDomain: "adblockplus.org", 197 docDomain: "adblockplus.org",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 else if (typeof arguments[i + 1] == "function") 238 else if (typeof arguments[i + 1] == "function")
239 { 239 {
240 links[i].href = "javascript:void(0);"; 240 links[i].href = "javascript:void(0);";
241 links[i].addEventListener("click", arguments[i + 1], false); 241 links[i].addEventListener("click", arguments[i + 1], false);
242 } 242 }
243 } 243 }
244 } 244 }
245 245
246 function openFilters() 246 function openFilters()
247 { 247 {
248 ext.backgroundPage.sendMessage({type: "app.options"}); 248 ext.backgroundPage.sendMessage({type: "app.open", what: "options"});
249 } 249 }
250 250
251 function updateToggleButtons() 251 function updateToggleButtons()
252 { 252 {
253 ext.backgroundPage.sendMessage({type: "subscriptions.get"}, function(subscri ptions) 253 ext.backgroundPage.sendMessage({
254 type: "subscriptions.get",
255 downloadable: true,
256 ignoreDisabled: true
257 }, function(subscriptions)
254 { 258 {
255 for (var i = 0; i < featureSubscriptions.length; i++) 259 for (var i = 0; i < featureSubscriptions.length; i++)
256 { 260 {
257 var featureSubscription = featureSubscriptions[i]; 261 var featureSubscription = featureSubscriptions[i];
258 updateToggleButton(featureSubscription.feature, subscriptions.indexOf(fe atureSubscription.url) >= 0); 262 updateToggleButton(featureSubscription.feature, subscriptions.indexOf(fe atureSubscription.url) >= 0);
259 } 263 }
260 }); 264 });
261 } 265 }
262 266
263 function updateToggleButton(feature, isEnabled) 267 function updateToggleButton(feature, isEnabled)
264 { 268 {
265 var button = E("toggle-" + feature); 269 var button = E("toggle-" + feature);
266 if (isEnabled) 270 if (isEnabled)
267 button.classList.remove("off"); 271 button.classList.remove("off");
268 else 272 else
269 button.classList.add("off"); 273 button.classList.add("off");
270 } 274 }
271 275
272 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); 276 document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
273 })(); 277 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld