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

Delta Between Two Patch Sets: firstRun.js

Issue 4731979438227456: Issue 1663 - Emulate background page and implement proper message responder (Closed)
Left Patch Set: Created Dec. 17, 2014, 6:32 p.m.
Right Patch Set: Using Services.vc Created Dec. 19, 2014, 5:45 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') | messageResponder.js » ('j') | messageResponder.js » ('J')
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 var known = Object.create(null); 259 var known = Object.create(null);
256 for (var i = 0; i < subscriptions.length; i++) 260 for (var i = 0; i < subscriptions.length; i++)
257 known[subscriptions[i].url] = true; 261 known[subscriptions[i].url] = true;
258 for (var i = 0; i < featureSubscriptions.length; i++) 262 for (var i = 0; i < featureSubscriptions.length; i++)
259 { 263 {
260 var featureSubscription = featureSubscriptions[i]; 264 var featureSubscription = featureSubscriptions[i];
261 updateToggleButton(featureSubscription.feature, featureSubscription.url in known); 265 updateToggleButton(featureSubscription.feature, featureSubscription.url in known);
262 } 266 }
263 }); 267 });
264 } 268 }
265 269
266 function updateToggleButton(feature, isEnabled) 270 function updateToggleButton(feature, isEnabled)
267 { 271 {
268 var button = E("toggle-" + feature); 272 var button = E("toggle-" + feature);
269 if (isEnabled) 273 if (isEnabled)
270 button.classList.remove("off"); 274 button.classList.remove("off");
271 else 275 else
272 button.classList.add("off"); 276 button.classList.add("off");
273 } 277 }
274 278
275 document.addEventListener("DOMContentLoaded", onDOMLoaded, false); 279 document.addEventListener("DOMContentLoaded", onDOMLoaded, false);
276 })(); 280 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld