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

Side by Side Diff: subscriptionLink.postload.js

Issue 29367316: Issue 4722 - Drop support for Chrome 41 - 48 (Closed)
Patch Set: Removed getIndistinguishableTypes function Created Dec. 16, 2016, 9:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/requestBlocker.js ('K') | « options.js ('k') | no next file » | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 // In Chrome 37-40, the document_end content script (this one) runs properly, 20 if (document instanceof HTMLDocument)
21 // while the document_start content scripts (that defines ext) might not. Check
22 // whether variable ext exists before continuing to avoid
23 // "Uncaught ReferenceError: ext is not defined". See https://crbug.com/416907
24 if ("ext" in window && document instanceof HTMLDocument)
25 { 21 {
26 document.addEventListener("click", function(event) 22 document.addEventListener("click", function(event)
27 { 23 {
28 // Ignore right-clicks 24 // Ignore right-clicks
29 if (event.button == 2) 25 if (event.button == 2)
30 return; 26 return;
31 27
32 // Ignore simulated clicks. 28 // Ignore simulated clicks.
33 if (event.isTrusted == false) 29 if (event.isTrusted == false)
34 return; 30 return;
35 31
36 // Search the link associated with the click 32 // Search the link associated with the click
37 var link = event.target; 33 var link = event.target;
38 while (!(link instanceof HTMLAnchorElement)) 34 while (!(link instanceof HTMLAnchorElement))
39 { 35 {
40 link = link.parentNode; 36 link = link.parentNode;
41 37
42 if (!link) 38 if (!link)
43 return; 39 return;
44 } 40 }
45 41
46 let queryString = null;
47 if (link.protocol == "http:" || link.protocol == "https:") 42 if (link.protocol == "http:" || link.protocol == "https:")
48 { 43 {
49 if (link.host == "subscribe.adblockplus.org" && link.pathname == "/") 44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/")
50 queryString = link.search.substr(1); 45 return;
51 } 46 }
52 else 47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href))
53 {
54 // Old versions of Chrome (30) don't populate the "search" property for
55 // links with non-standard URL schemes so we need to extract the query
56 // string manually.
57 let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
58 if (match)
59 queryString = match[1];
60 }
61
62 if (!queryString)
63 return; 48 return;
64 49
65 // This is our link - make sure the browser doesn't handle it 50 // This is our link - make sure the browser doesn't handle it
66 event.preventDefault(); 51 event.preventDefault();
67 event.stopPropagation(); 52 event.stopPropagation();
68 53
69 // Decode URL parameters 54 // Decode URL parameters
70 var params = queryString.split("&"); 55 var params = link.search.substr(1).split("&");
71 var title = null; 56 var title = null;
72 var url = null; 57 var url = null;
73 for (var i = 0; i < params.length; i++) 58 for (var i = 0; i < params.length; i++)
74 { 59 {
75 var parts = params[i].split("=", 2); 60 var parts = params[i].split("=", 2);
76 if (parts.length != 2 || !/\S/.test(parts[1])) 61 if (parts.length != 2 || !/\S/.test(parts[1]))
77 continue; 62 continue;
78 switch (parts[0]) 63 switch (parts[0])
79 { 64 {
80 case "title": 65 case "title":
(...skipping 18 matching lines...) Expand all
99 return; 84 return;
100 85
101 ext.backgroundPage.sendMessage({ 86 ext.backgroundPage.sendMessage({
102 type: "subscriptions.add", 87 type: "subscriptions.add",
103 title: title, 88 title: title,
104 url: url, 89 url: url,
105 confirm: true 90 confirm: true
106 }); 91 });
107 }, true); 92 }, true);
108 } 93 }
OLDNEW
« lib/requestBlocker.js ('K') | « options.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld