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

Side by Side Diff: background.js

Issue 4731979438227456: Issue 1663 - Emulate background page and implement proper message responder (Closed)
Patch Set: Properly convert Subscription objects as notification arguments Created Dec. 17, 2014, 10:15 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 | « background.html ('k') | ext/background.js » ('j') | ext/common.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 (function(global)
19 {
20 function getURLParameters(data)
Thomas Greiner 2014/12/18 17:32:06 The function name is not reflecting what it does (
Wladimir Palant 2014/12/18 22:04:44 Fixed by rebasing.
21 {
22 if (window.location.search)
23 {
24 var params = window.location.search.substr(1).split("&");
25 for (var i = 0; i < params.length; i++)
26 {
27 var parts = params[i].split("=", 2);
28 if (parts.length == 2 && parts[0] in data)
29 data[parts[0]] = decodeURIComponent(parts[1]);
30 }
31 }
32 }
33
34 var subscriptions =[
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
38 ];
39
40 global.Utils = {
41 getDocLink: function(link)
42 {
43 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(link) ;
44 }
45 };
46
47 global.Subscription = {
48 fromURL: function(url)
49 {
50 return {
51 url: url,
52 title: "Subscription " + url,
53 disabled: false,
54 lastDownload: 1234
55 };
56 }
57 };
58
59 global.FilterStorage = {
60 get subscriptions()
61 {
62 return subscriptions.map(global.Subscription.fromURL);
63 },
64
65 get knownSubscriptions()
66 {
67 var result = {};
68 for (var i = 0; i < subscriptions.length; i++)
69 result[subscriptions[i]] = global.Subscription.fromURL(subscriptions[i]) ;
70 return result;
71 },
72
73 addSubscription: function(subscription)
74 {
75 var index = subscriptions.indexOf(subscription.url);
76 if (index < 0)
77 {
78 subscriptions.push(subscription.url);
79 global.FilterNotifier.triggerListeners("subscription.added", subscriptio n);
80 }
81 },
82
83 removeSubscription: function(subscription)
84 {
85 var index = subscriptions.indexOf(subscription.url);
86 if (index >= 0)
87 {
88 subscriptions.splice(index, 1);
89 global.FilterNotifier.triggerListeners("subscription.removed", subscript ion);
90 }
91 }
92 };
93
94 global.BlockingFilter = function() {};
95
96 global.defaultMatcher = {
97 matchesAny: function(url, requestType, docDomain, thirdParty)
98 {
99 var params = {blockedURLs: ""};
100 getURLParameters(params);
101 var blocked = params.blockedURLs.split(",");
102 if (blocked.indexOf(url) >= 0)
103 return new global.BlockingFilter();
104 else
105 return null;
106 }
107 };
108
109 var notifierListeners = [];
110 global.FilterNotifier = {
111 addListener: function(listener)
112 {
113 if (notifierListeners.indexOf(listener) < 0)
114 notifierListeners.push(listener);
115 },
116
117 removeListener: function(listener)
118 {
119 var index = notifierListeners.indexOf(listener);
120 if (index >= 0)
121 notifierListeners.splice(index, 1);
122 },
123
124 triggerListeners: function()
125 {
126 var args = Array.prototype.slice.apply(arguments);
127 var listeners = notifierListeners.slice();
128 for (var i = 0; i < listeners.length; i++)
129 listeners[i].apply(null, args);
130 }
131 };
132
133 global.require = function(module)
134 {
135 if (module == "info")
136 {
137 var result = {platform: "gecko", platformVersion: "34.0", application: "fi refox", applicationVersion: "34.0"};
Thomas Greiner 2014/12/18 17:32:06 Again a line that doesn't need to be that long.
Wladimir Palant 2014/12/18 22:04:44 Done.
138 getURLParameters(result);
139 return result;
140 }
141 else
142 return undefined;
143 }
144
145 global.openOptions = function()
146 {
147 window.open("http://example.com/options.html", "_blank");
148 };
149
150 var issues = {seenDataCorruption: false, filterlistsReinitialized: false};
151 getURLParameters(issues);
152 global.seenDataCorruption = issues.seenDataCorruption;
153 global.filterlistsReinitialized = issues.filterlistsReinitialized;
154 })(this);
OLDNEW
« no previous file with comments | « background.html ('k') | ext/background.js » ('j') | ext/common.js » ('J')

Powered by Google App Engine
This is Rietveld