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

Side by Side Diff: subscriptionLink.postload.js

Issue 29373686: Issue 4775 - Fix subscription links for Firefox (Closed)
Patch Set: Created Jan. 28, 2017, 12:31 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 21 matching lines...) Expand all
32 // Search the link associated with the click 32 // Search the link associated with the click
33 let link = event.target; 33 let link = event.target;
34 while (!(link instanceof HTMLAnchorElement)) 34 while (!(link instanceof HTMLAnchorElement))
35 { 35 {
36 link = link.parentNode; 36 link = link.parentNode;
37 37
38 if (!link) 38 if (!link)
39 return; 39 return;
40 } 40 }
41 41
42 let queryString = null;
kzar 2017/01/28 12:35:01 (The workaround that will apparently never die. Pr
42 if (link.protocol == "http:" || link.protocol == "https:") 43 if (link.protocol == "http:" || link.protocol == "https:")
43 { 44 {
44 if (link.host != "subscribe.adblockplus.org" || link.pathname != "/") 45 if (link.host == "subscribe.adblockplus.org" && link.pathname == "/")
45 return; 46 queryString = link.search.substr(1);
46 } 47 }
47 else if (!/^abp:\/*subscribe\/*\?/i.test(link.href)) 48 else
49 {
50 // Firefox 51 doesn't seem to populate the "search" property for
51 // links with non-standard URL schemes so we need to extract the query
52 // string manually.
53 let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
54 if (match)
55 queryString = match[1];
56 }
57
58 if (!queryString)
48 return; 59 return;
49 60
50 // This is our link - make sure the browser doesn't handle it 61 // This is our link - make sure the browser doesn't handle it
51 event.preventDefault(); 62 event.preventDefault();
52 event.stopPropagation(); 63 event.stopPropagation();
53 64
54 // Decode URL parameters 65 // Decode URL parameters
55 let title = null; 66 let title = null;
56 let url = null; 67 let url = null;
57 for (let param of link.search.substr(1).split("&")) 68 for (let param of queryString.split("&"))
58 { 69 {
59 let parts = param.split("=", 2); 70 let parts = param.split("=", 2);
60 if (parts.length != 2 || !/\S/.test(parts[1])) 71 if (parts.length != 2 || !/\S/.test(parts[1]))
61 continue; 72 continue;
62 switch (parts[0]) 73 switch (parts[0])
63 { 74 {
64 case "title": 75 case "title":
65 title = decodeURIComponent(parts[1]); 76 title = decodeURIComponent(parts[1]);
66 break; 77 break;
67 case "location": 78 case "location":
(...skipping 15 matching lines...) Expand all
83 return; 94 return;
84 95
85 ext.backgroundPage.sendMessage({ 96 ext.backgroundPage.sendMessage({
86 type: "subscriptions.add", 97 type: "subscriptions.add",
87 title: title, 98 title: title,
88 url: url, 99 url: url,
89 confirm: true 100 confirm: true
90 }); 101 });
91 }, true); 102 }, true);
92 } 103 }
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