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

Delta Between Two Patch Sets: lib/api.js

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Left Patch Set: Created April 12, 2013, 2:55 p.m.
Right Patch Set: Addressed review comments Created April 17, 2013, 7:56 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « include/AdblockPlus/JsValue.h ('k') | lib/compat.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of the Adblock Plus extension,
3 * Copyright (C) 2006-2012 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 var API = (function()
19 {
20 var Filter = require("filterClasses").Filter;
21 var Subscription = require("subscriptionClasses").Subscription;
22 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
23 var FilterStorage = require("filterStorage").FilterStorage;
24 var defaultMatcher = require("matcher").defaultMatcher;
25 var ElemHide = require("elemHide").ElemHide;
26 var Synchronizer = require("synchronizer").Synchronizer;
27
28 return {
29 getFilterFromText: function(text)
30 {
31 text = Filter.normalize(text);
32 if (!text)
33 throw "Attempted to create a filter from empty text";
34 return Filter.fromText(text);
35 },
36
37 isListedFilter: function(filter)
38 {
39 return filter.subscriptions.some(function(s)
40 {
41 return (s instanceof SpecialSubscription && !s.disabled);
42 });
43 },
44
45 addFilterToList: function(filter)
46 {
47 FilterStorage.addFilter(filter);
48 },
49
50 removeFilterFromList: function(filter)
51 {
52 FilterStorage.removeFilter(filter);
53 },
54
55 getListedFilters: function()
56 {
57 var filters = {};
58 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
59 {
60 var subscription = FilterStorage.subscriptions[i];
61 if (subscription instanceof SpecialSubscription)
62 {
63 for (var j = 0; j < subscription.filters.length; j++)
64 {
65 var filter = subscription.filters[j];
66 if (!(filter.text in filters))
67 filters[filter.text] = filter;
68 }
69 }
70 }
71 return Object.keys(filters).map(function(k)
72 {
73 return filters[k];
74 });
75 },
76
77 getSubscriptionFromUrl: function(url)
78 {
79 return Subscription.fromURL(url);
80 },
81
82 isListedSubscription: function(subscription)
83 {
84 return subscription.url in FilterStorage.knownSubscriptions;
85 },
86
87 addSubscriptionToList: function(subscription)
88 {
89 FilterStorage.addSubscription(subscription);
90
91 // TODO, this currently crashes due to errors reported on a thread
92 //if (!subscription.lastDownload)
93 // Synchronizer.execute(subscription);
94 },
95
96 removeSubscriptionFromList: function(subscription)
97 {
98 FilterStorage.removeSubscription(subscription);
99 },
100
101 updateSubscription: function(subscription)
102 {
103 Synchronizer.execute(subscription);
104 },
105
106 isSubscriptionUpdating: function(subscription)
107 {
108 return Synchronizer.isExecuting(subscription.url);
109 },
110
111 getListedSubscriptions: function()
112 {
113 return FilterStorage.subscriptions.filter(function(s)
114 {
115 return !(s instanceof SpecialSubscription)
116 });
117 },
118
119 checkFilterMatch: function(url, contentType, documentUrl)
120 {
121 // TODO: set thirdParty properly
122 var thirdParty = false;
123 return defaultMatcher.matchesAny(url, contentType, documentUrl, thirdParty );
124 },
125
126 getElementHidingSelectors: function(domain)
127 {
128 return ElemHide.getSelectorsForDomain(domain, false);
129 }
130 };
131 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld