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

Side by Side Diff: include/AdblockPlus/FilterEngine.h

Issue 29364548: Issue 4188 - Update libadblockplus-android to use the latest libadblockplus (Closed)
Patch Set: Created Nov. 25, 2016, 12:36 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 | « include/AdblockPlus/FileSystem.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | 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-2015 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 12 matching lines...) Expand all
26 #include <AdblockPlus/JsValue.h> 26 #include <AdblockPlus/JsValue.h>
27 #include <AdblockPlus/Notification.h> 27 #include <AdblockPlus/Notification.h>
28 28
29 namespace AdblockPlus 29 namespace AdblockPlus
30 { 30 {
31 class FilterEngine; 31 class FilterEngine;
32 32
33 /** 33 /**
34 * Wrapper for an Adblock Plus filter object. 34 * Wrapper for an Adblock Plus filter object.
35 * There are no accessors for most 35 * There are no accessors for most
36 * [filter properties](https://adblockplus.org/jsdoc/adblockplus/symbols/Filte r.html), 36 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml),
37 * use `GetProperty()` to retrieve them by name. 37 * use `GetProperty()` to retrieve them by name.
38 */ 38 */
39 class Filter : public JsValue, 39 class Filter : public JsValue,
40 public std::enable_shared_from_this<Filter> 40 public std::enable_shared_from_this<Filter>
41 { 41 {
42 public: 42 public:
43 /** 43 /**
44 * Filter types, see https://adblockplus.org/en/filters. 44 * Filter types, see https://adblockplus.org/en/filters.
45 */ 45 */
46 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, 46 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
(...skipping 23 matching lines...) Expand all
70 void RemoveFromList(); 70 void RemoveFromList();
71 71
72 bool operator==(const Filter& filter) const; 72 bool operator==(const Filter& filter) const;
73 73
74 /** 74 /**
75 * Creates a wrapper for an existing JavaScript filter object. 75 * Creates a wrapper for an existing JavaScript filter object.
76 * Normally you shouldn't call this directly, but use 76 * Normally you shouldn't call this directly, but use
77 * FilterEngine::GetFilter() instead. 77 * FilterEngine::GetFilter() instead.
78 * @param value JavaScript filter object. 78 * @param value JavaScript filter object.
79 */ 79 */
80 Filter(JsValuePtr value); 80 Filter(JsValue&& value);
81 }; 81 };
82 82
83 /** 83 /**
84 * Wrapper for a subscription object. 84 * Wrapper for a subscription object.
85 * There are no accessors for most 85 * There are no accessors for most
86 * [subscription properties](https://adblockplus.org/jsdoc/adblockplus/symbols /Subscription.html), 86 * [subscription properties](https://adblockplus.org/jsdoc/adblockpluscore/Sub scription.html),
87 * use `GetProperty()` to retrieve them by name. 87 * use `GetProperty()` to retrieve them by name.
88 */ 88 */
89 class Subscription : public JsValue, 89 class Subscription : public JsValue,
90 public std::enable_shared_from_this<Subscription> 90 public std::enable_shared_from_this<Subscription>
91 { 91 {
92 public: 92 public:
93 /** 93 /**
94 * Checks if this subscription has been added to the list of subscriptions. 94 * Checks if this subscription has been added to the list of subscriptions.
95 * @return `true` if this subscription has been added. 95 * @return `true` if this subscription has been added.
96 */ 96 */
(...skipping 22 matching lines...) Expand all
119 bool IsUpdating(); 119 bool IsUpdating();
120 120
121 bool operator==(const Subscription& subscription) const; 121 bool operator==(const Subscription& subscription) const;
122 122
123 /** 123 /**
124 * Creates a wrapper for an existing JavaScript subscription object. 124 * Creates a wrapper for an existing JavaScript subscription object.
125 * Normally you shouldn't call this directly, but use 125 * Normally you shouldn't call this directly, but use
126 * FilterEngine::GetSubscription() instead. 126 * FilterEngine::GetSubscription() instead.
127 * @param value JavaScript subscription object. 127 * @param value JavaScript subscription object.
128 */ 128 */
129 Subscription(JsValuePtr value); 129 Subscription(JsValue&& value);
130 }; 130 };
131 131
132 /** 132 /**
133 * Shared smart pointer to a `Filter` instance. 133 * Shared smart pointer to a `Filter` instance.
134 */ 134 */
135 typedef std::shared_ptr<Filter> FilterPtr; 135 typedef std::shared_ptr<Filter> FilterPtr;
136 136
137 /** 137 /**
138 * Shared smart pointer to a `Subscription` instance. 138 * Shared smart pointer to a `Subscription` instance.
139 */ 139 */
140 typedef std::shared_ptr<Subscription> SubscriptionPtr; 140 typedef std::shared_ptr<Subscription> SubscriptionPtr;
141 141
142 /** 142 /**
143 * Main component of libadblockplus. 143 * Main component of libadblockplus.
144 * It handles: 144 * It handles:
145 * - Filter management and matching. 145 * - Filter management and matching.
146 * - Subscription management and synchronization. 146 * - Subscription management and synchronization.
147 * - Update checks for the application. 147 * - Update checks for the application.
148 */ 148 */
149 class FilterEngine 149 class FilterEngine
150 { 150 {
151 public: 151 public:
152 // Make sure to keep ContentType in sync with FilterEngine::contentTypes 152 // Make sure to keep ContentType in sync with FilterEngine::contentTypes
153 // and with RegExpFilter.typeMap from filterClasses.js.
153 /** 154 /**
154 * Possible resource content types. 155 * Possible resource content types.
155 */ 156 */
156 enum ContentType {CONTENT_TYPE_OTHER, CONTENT_TYPE_SCRIPT, 157 enum ContentType
157 CONTENT_TYPE_IMAGE, CONTENT_TYPE_STYLESHEET, 158 {
158 CONTENT_TYPE_OBJECT, CONTENT_TYPE_SUBDOCUMENT, 159 CONTENT_TYPE_OTHER = 1,
159 CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_XMLHTTPREQUEST, 160 CONTENT_TYPE_SCRIPT = 2,
160 CONTENT_TYPE_OBJECT_SUBREQUEST, CONTENT_TYPE_FONT, 161 CONTENT_TYPE_IMAGE = 4,
161 CONTENT_TYPE_MEDIA, CONTENT_TYPE_ELEMHIDE}; 162 CONTENT_TYPE_STYLESHEET = 8,
163 CONTENT_TYPE_OBJECT = 16,
164 CONTENT_TYPE_SUBDOCUMENT = 32,
165 CONTENT_TYPE_DOCUMENT = 64,
166 CONTENT_TYPE_PING = 1024,
167 CONTENT_TYPE_XMLHTTPREQUEST = 2048,
168 CONTENT_TYPE_OBJECT_SUBREQUEST = 4096,
169 CONTENT_TYPE_MEDIA = 16384,
170 CONTENT_TYPE_FONT = 32768,
171 CONTENT_TYPE_GENERICBLOCK = 0x20000000,
172 CONTENT_TYPE_ELEMHIDE = 0x40000000,
173 CONTENT_TYPE_GENERICHIDE = 0x80000000
174 };
175
176 /**
177 * Bitmask of `ContentType` values.
178 * The underlying type is signed 32 bit integer because it is actually used
179 * in JavaScript where it is converted into 32 bit signed integer.
180 */
181 typedef int32_t ContentTypeMask;
162 182
163 /** 183 /**
164 * Callback type invoked when an update becomes available. 184 * Callback type invoked when an update becomes available.
165 * The parameter is the download URL of the update. 185 * The parameter is the download URL of the update.
166 */ 186 */
167 typedef std::function<void(const std::string&)> UpdateAvailableCallback; 187 typedef std::function<void(const std::string&)> UpdateAvailableCallback;
168 188
169 /** 189 /**
170 * Callback type invoked when a manually triggered update check finishes. 190 * Callback type invoked when a manually triggered update check finishes.
171 * The parameter is an optional error message. 191 * The parameter is an optional error message.
172 */ 192 */
173 typedef std::function<void(const std::string&)> UpdateCheckDoneCallback; 193 typedef std::function<void(const std::string&)> UpdateCheckDoneCallback;
174 194
175 /** 195 /**
176 * Callback type invoked when the filters change. 196 * Callback type invoked when the filters change.
177 * The first parameter is the action event code (see 197 * The first parameter is the action event code (see
178 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl us/symbols/FilterNotifier.html#.triggerListeners) 198 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl uscore/FilterNotifier.html#.triggerListeners)
179 * for the full list). 199 * for the full list).
180 * The second parameter is the filter/subscription object affected, if any. 200 * The second parameter is the filter/subscription object affected, if any.
181 */ 201 */
182 typedef std::function<void(const std::string&, const JsValuePtr)> FilterChan geCallback; 202 typedef std::function<void(const std::string&, const JsValuePtr)> FilterChan geCallback;
183 203
184 /** 204 /**
185 * Container of name-value pairs representing a set of preferences. 205 * Container of name-value pairs representing a set of preferences.
186 */ 206 */
187 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; 207 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs;
188 208
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 void SetShowNotificationCallback(const ShowNotificationCallback& value); 282 void SetShowNotificationCallback(const ShowNotificationCallback& value);
263 283
264 /** 284 /**
265 * Removes the callback invoked when a notification should be shown. 285 * Removes the callback invoked when a notification should be shown.
266 */ 286 */
267 void RemoveShowNotificationCallback(); 287 void RemoveShowNotificationCallback();
268 288
269 /** 289 /**
270 * Checks if any active filter matches the supplied URL. 290 * Checks if any active filter matches the supplied URL.
271 * @param url URL to match. 291 * @param url URL to match.
272 * @param contentType Content type of the requested resource. 292 * @param contentTypeMask Content type mask of the requested resource.
273 * @param documentUrl URL of the document requesting the resource. 293 * @param documentUrl URL of the document requesting the resource.
274 * Note that there will be more than one document if frames are 294 * Note that there will be more than one document if frames are
275 * involved, see 295 * involved, see
276 * Matches(const std::string&, const std::string&, const std::vector< std::string>&) const. 296 * Matches(const std::string&, const std::string&, const std::vector< std::string>&) const.
277 * @return Matching filter, or `null` if there was no match. 297 * @return Matching filter, or `null` if there was no match.
278 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. 298 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied.
279 */ 299 */
280 FilterPtr Matches(const std::string& url, 300 FilterPtr Matches(const std::string& url,
281 ContentType contentType, 301 ContentTypeMask contentTypeMask,
282 const std::string& documentUrl) const; 302 const std::string& documentUrl) const;
283 303
284 /** 304 /**
285 * Checks if any active filter matches the supplied URL. 305 * Checks if any active filter matches the supplied URL.
286 * @param url URL to match. 306 * @param url URL to match.
287 * @param contentType Content type of the requested resource. 307 * @param contentTypeMask Content type mask of the requested resource.
288 * @param documentUrls Chain of documents requesting the resource, starting 308 * @param documentUrls Chain of documents requesting the resource, starting
289 * with the current resource's parent frame, ending with the 309 * with the current resource's parent frame, ending with the
290 * top-level frame. 310 * top-level frame.
291 * If the application is not capable of identifying the frame 311 * If the application is not capable of identifying the frame
292 * structure, e.g. because it is a proxy, it can be approximated 312 * structure, e.g. because it is a proxy, it can be approximated
293 * using `ReferrerMapping`. 313 * using `ReferrerMapping`.
294 * @return Matching filter, or a `null` if there was no match. 314 * @return Matching filter, or a `null` if there was no match.
295 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. 315 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied.
296 */ 316 */
297 FilterPtr Matches(const std::string& url, 317 FilterPtr Matches(const std::string& url,
298 ContentType contentType, 318 ContentTypeMask contentTypeMask,
299 const std::vector<std::string>& documentUrls) const; 319 const std::vector<std::string>& documentUrls) const;
300 320
301 /** 321 /**
302 * Checks whether the document at the supplied URL is whitelisted. 322 * Checks whether the document at the supplied URL is whitelisted.
303 * @param url URL of the document. 323 * @param url URL of the document.
304 * @param documentUrls Chain of document URLs requesting the document, 324 * @param documentUrls Chain of document URLs requesting the document,
305 * starting with the current document's parent frame, ending with 325 * starting with the current document's parent frame, ending with
306 * the top-level frame. 326 * the top-level frame.
307 * If the application is not capable of identifying the frame 327 * If the application is not capable of identifying the frame
308 * structure, e.g. because it is a proxy, it can be approximated 328 * structure, e.g. because it is a proxy, it can be approximated
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 442
423 private: 443 private:
424 JsEnginePtr jsEngine; 444 JsEnginePtr jsEngine;
425 bool initialized; 445 bool initialized;
426 bool firstRun; 446 bool firstRun;
427 int updateCheckId; 447 int updateCheckId;
428 static const std::map<ContentType, std::string> contentTypes; 448 static const std::map<ContentType, std::string> contentTypes;
429 449
430 void InitDone(JsValueList& params); 450 void InitDone(JsValueList& params);
431 FilterPtr CheckFilterMatch(const std::string& url, 451 FilterPtr CheckFilterMatch(const std::string& url,
432 ContentType contentType, 452 ContentTypeMask contentTypeMask,
433 const std::string& documentUrl) const; 453 const std::string& documentUrl) const;
434 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); 454 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params);
435 void UpdateCheckDone(const std::string& eventName, 455 void UpdateCheckDone(const std::string& eventName,
436 UpdateCheckDoneCallback callback, JsValueList& params); 456 UpdateCheckDoneCallback callback, JsValueList& params);
437 void FilterChanged(FilterChangeCallback callback, JsValueList& params); 457 void FilterChanged(FilterChangeCallback callback, JsValueList& params);
438 void ShowNotification(const ShowNotificationCallback& callback, 458 void ShowNotification(const ShowNotificationCallback& callback,
439 const JsValueList& params); 459 const JsValueList& params);
440 FilterPtr GetWhitelistingFilter(const std::string& url, 460 FilterPtr GetWhitelistingFilter(const std::string& url,
441 ContentType contentType, const std::string& documentUrl) const; 461 ContentTypeMask contentTypeMask, const std::string& documentUrl) const;
442 FilterPtr GetWhitelistingFilter(const std::string& url, 462 FilterPtr GetWhitelistingFilter(const std::string& url,
443 ContentType contentType, 463 ContentTypeMask contentTypeMask,
444 const std::vector<std::string>& documentUrls) const; 464 const std::vector<std::string>& documentUrls) const;
445 }; 465 };
446 } 466 }
447 467
448 #endif 468 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/FileSystem.h ('k') | include/AdblockPlus/JsEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld