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

Side by Side Diff: subscriptionLink.postload.js

Issue 29342971: Fixes 4065 - Subscription links on Chrome 30 (Closed)
Patch Set: Addressed feedback Created May 24, 2016, 12:45 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 | « no previous file | 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
(...skipping 25 matching lines...) Expand all
36 // Search the link associated with the click 36 // Search the link associated with the click
37 var link = event.target; 37 var link = event.target;
38 while (!(link instanceof HTMLAnchorElement)) 38 while (!(link instanceof HTMLAnchorElement))
39 { 39 {
40 link = link.parentNode; 40 link = link.parentNode;
41 41
42 if (!link) 42 if (!link)
43 return; 43 return;
44 } 44 }
45 45
46 let queryString = null;
46 if (link.protocol == "http:" || link.protocol == "https:") 47 if (link.protocol == "http:" || link.protocol == "https:")
47 { 48 {
48 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") 49 if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
49 return; 50 queryString = link.search.substr(1);
50 } 51 }
51 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) 52 else
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)
52 return; 63 return;
53 64
54 // This is our link - make sure the browser doesn't handle it 65 // This is our link - make sure the browser doesn't handle it
55 event.preventDefault(); 66 event.preventDefault();
56 event.stopPropagation(); 67 event.stopPropagation();
57 68
58 // Decode URL parameters 69 // Decode URL parameters (Note: Old versions of Chrome (30) don't populate
Sebastian Noack 2016/05/24 12:48:06 Nit: That comment, or at least the part you added,
kzar 2016/05/24 12:59:40 Whoops missed that, Done.
59 var params = link.search.substr(1).split("&"); 70 // link.search here so we have to grab the search part of the URL manually.)
71 var params = queryString.split("&");
60 var title = null; 72 var title = null;
61 var url = null; 73 var url = null;
62 for (var i = 0; i < params.length; i++) 74 for (var i = 0; i < params.length; i++)
63 { 75 {
64 var parts = params[i].split("=", 2); 76 var parts = params[i].split("=", 2);
65 if (parts.length != 2 || !/\S/.test(parts[1])) 77 if (parts.length != 2 || !/\S/.test(parts[1]))
66 continue; 78 continue;
67 switch (parts[0]) 79 switch (parts[0])
68 { 80 {
69 case "title": 81 case "title":
(...skipping 18 matching lines...) Expand all
88 return; 100 return;
89 101
90 ext.backgroundPage.sendMessage({ 102 ext.backgroundPage.sendMessage({
91 type: "subscriptions.add", 103 type: "subscriptions.add",
92 title: title, 104 title: title,
93 url: url, 105 url: url,
94 confirm: true 106 confirm: true
95 }); 107 });
96 }, true); 108 }, true);
97 } 109 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld