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

Unified Diff: lib/ui.js

Issue 5309182173511680: Issue 2211 - Implemented subscribe.adblockplus.org subscription links (Closed)
Patch Set: Removed redundant URL scheme check Created April 1, 2015, 2:59 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/ui.js
===================================================================
--- a/lib/ui.js
+++ b/lib/ui.js
@@ -895,12 +895,26 @@
/**
* Handles clicks inside the browser's content area, will intercept clicks on
- * abp: links. This can be called either with an event object or with the link
- * target (if it is the former then link target will be retrieved from event
- * target).
+ * abp: links as well as links to subscribe.adblockplus.org. This can be called
+ * either with an event object or with the link target (if it is the former then
Wladimir Palant 2015/04/01 17:49:31 Nit: Please stick to the 80 characters line limit.
Thomas Greiner 2015/04/02 14:26:43 Done. I also added a preference to my editor to no
+ * link target will be retrieved from event target).
*/
onBrowserClick: function (/**Window*/ window, /**Event*/ event, /**String*/ linkTarget)
Wladimir Palant 2015/04/01 17:49:31 It seems that the linkTarget parameter is no longe
Thomas Greiner 2015/04/02 14:26:43 Done.
{
+ let link = null;
+ if (linkTarget)
+ {
+ try
+ {
+ link = new URL(linkTarget);
+ }
+ catch(ex)
+ {
+ // Don't handle links with invalid URLs
+ return;
+ }
+ }
+
if (event)
{
// Ignore right-clicks
@@ -908,30 +922,48 @@
return;
// Search the link associated with the click
- let link = event.target;
- while (link && !(link instanceof Ci.nsIDOMHTMLAnchorElement))
+ link = event.target;
+ while (!(link instanceof Ci.nsIDOMHTMLAnchorElement))
+ {
link = link.parentNode;
- if (!link || link.protocol != "abp:")
- return;
+ if (!link)
+ return;
+ }
+ }
+ let queryString = null;
+ if (link.protocol == "http:" || link.protocol == "https:")
+ {
+ if (link.host == "subscribe.adblockplus.org" || link.pathname == "/")
+ queryString = link.search.substr(1);
+ }
+ else
+ {
+ // Firefox doesn't populate the "search" property for links with
+ // non-standard URL schemes so we need to extract the query string
+ // manually
+ let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(link.href);
+ if (match)
+ queryString = match[1];
+ }
+
+ if (!queryString)
+ return;
+
+ if (event)
+ {
// This is our link - make sure the browser doesn't handle it
event.preventDefault();
event.stopPropagation();
-
- linkTarget = link.href;
}
- let match = /^abp:\/*subscribe\/*\?(.*)/i.exec(linkTarget);
- if (!match)
- return;
-
// Decode URL parameters
let title = null;
let url = null;
let mainSubscriptionTitle = null;
let mainSubscriptionURL = null;
- for (let param of match[1].split('&'))
+ for (let param of queryString.split("&"))
{
let parts = param.split("=", 2);
if (parts.length != 2 || !/\S/.test(parts[1]))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld