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

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

Issue 29429555: Noissue - updated to libadblockplus revision dca8df9af1a7 (Closed)
Patch Set: Created May 4, 2017, 5:08 a.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 19 matching lines...) Expand all
30 { 30 {
31 class FilterEngine; 31 class FilterEngine;
32 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; 32 typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
33 33
34 /** 34 /**
35 * Wrapper for an Adblock Plus filter object. 35 * Wrapper for an Adblock Plus filter object.
36 * There are no accessors for most 36 * There are no accessors for most
37 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml), 37 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml),
38 * use `GetProperty()` to retrieve them by name. 38 * use `GetProperty()` to retrieve them by name.
39 */ 39 */
40 class Filter : public JsValue, 40 class Filter : public JsValue
41 public std::enable_shared_from_this<Filter>
42 { 41 {
42 friend class FilterEngine;
43 public: 43 public:
44 Filter(const Filter& src);
45 Filter(Filter&& src);
46 Filter& operator=(const Filter& src);
47 Filter& operator=(Filter&& src);
48
44 /** 49 /**
45 * Filter types, see https://adblockplus.org/en/filters. 50 * Filter types, see https://adblockplus.org/en/filters.
46 */ 51 */
47 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, 52 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION,
48 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, 53 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION,
49 TYPE_COMMENT, TYPE_INVALID}; 54 TYPE_COMMENT, TYPE_INVALID};
50 55
51 /** 56 /**
52 * Retrieves the type of this filter. 57 * Retrieves the type of this filter.
53 * @return Type of this filter. 58 * @return Type of this filter.
(...skipping 11 matching lines...) Expand all
65 */ 70 */
66 void AddToList(); 71 void AddToList();
67 72
68 /** 73 /**
69 * Removes this filter from the list of custom filters. 74 * Removes this filter from the list of custom filters.
70 */ 75 */
71 void RemoveFromList(); 76 void RemoveFromList();
72 77
73 bool operator==(const Filter& filter) const; 78 bool operator==(const Filter& filter) const;
74 79
80 protected:
75 /** 81 /**
76 * Creates a wrapper for an existing JavaScript filter object. 82 * Creates a wrapper for an existing JavaScript filter object.
77 * Normally you shouldn't call this directly, but use 83 * Normally you shouldn't call this directly, but use
78 * FilterEngine::GetFilter() instead. 84 * FilterEngine::GetFilter() instead.
79 * @param value JavaScript filter object. 85 * @param value JavaScript filter object.
80 */ 86 */
81 Filter(JsValue&& value); 87 Filter(JsValue&& value);
82 }; 88 };
83 89
84 /** 90 /**
85 * Wrapper for a subscription object. 91 * Wrapper for a subscription object.
86 * There are no accessors for most 92 * There are no accessors for most
87 * [subscription properties](https://adblockplus.org/jsdoc/adblockpluscore/Sub scription.html), 93 * [subscription properties](https://adblockplus.org/jsdoc/adblockpluscore/Sub scription.html),
88 * use `GetProperty()` to retrieve them by name. 94 * use `GetProperty()` to retrieve them by name.
89 */ 95 */
90 class Subscription : public JsValue, 96 class Subscription : public JsValue
91 public std::enable_shared_from_this<Subscription>
92 { 97 {
98 friend class FilterEngine;
93 public: 99 public:
94 /** 100 /**
101 * Copy constructor
102 */
103 Subscription(const Subscription& src);
104
105 /**
106 * Move constructor
107 */
108 Subscription(Subscription&& src);
109
110 /**
111 * Assignment operator
112 */
113 Subscription& operator=(const Subscription& src);
114
115 /**
116 * Move assignment operator
117 */
118 Subscription& operator=(Subscription&& src);
119
120 /**
121 * Checks if the subscription is disabled.
122 * @return `true` if this subscription is disabled.
123 */
124 bool IsDisabled() const;
125
126 /**
127 * Allows to enable or disable current subscription.
128 * @param `value` disabling the subscription if true and enabling if false.
129 * If the previous state was the same then it has no effect.
130 */
131 void SetDisabled(bool value);
132
133 /**
95 * Checks if this subscription has been added to the list of subscriptions. 134 * Checks if this subscription has been added to the list of subscriptions.
96 * @return `true` if this subscription has been added. 135 * @return `true` if this subscription has been added.
97 */ 136 */
98 bool IsListed() const; 137 bool IsListed() const;
99 138
100 /** 139 /**
101 * Adds this subscription to the list of subscriptions. 140 * Adds this subscription to the list of subscriptions.
102 */ 141 */
103 void AddToList(); 142 void AddToList();
104 143
105 /** 144 /**
106 * Removes this subscription from the list of subscriptions. 145 * Removes this subscription from the list of subscriptions.
107 */ 146 */
108 void RemoveFromList(); 147 void RemoveFromList();
109 148
110 /** 149 /**
111 * Updates this subscription, i.e.\ retrieves the current filters from the 150 * Updates this subscription, i.e.\ retrieves the current filters from the
112 * subscription URL. 151 * subscription URL.
113 */ 152 */
114 void UpdateFilters(); 153 void UpdateFilters();
115 154
116 /** 155 /**
117 * Checks if the subscription is currently being updated. 156 * Checks if the subscription is currently being updated.
118 * @return `true` if the subscription is currently being updated. 157 * @return `true` if the subscription is currently being updated.
119 */ 158 */
120 bool IsUpdating() const; 159 bool IsUpdating() const;
121 160
122 /** 161 /**
123 * Indicates whether the subscription is acceptable ads subscription. 162 * Indicates whether the subscription is the Acceptable Ads subscription.
124 * @return `true` if this subscription is acceptable ads subscription. 163 * @return `true` if this subscription is the Acceptable Ads subscription.
125 */ 164 */
126 bool IsAA() const; 165 bool IsAA() const;
127 166
128 bool operator==(const Subscription& subscription) const; 167 bool operator==(const Subscription& subscription) const;
129 168
169 protected:
130 /** 170 /**
131 * Creates a wrapper for an existing JavaScript subscription object. 171 * Creates a wrapper for an existing JavaScript subscription object.
132 * Normally you shouldn't call this directly, but use 172 * Normally you shouldn't call this directly, but use
133 * FilterEngine::GetSubscription() instead. 173 * FilterEngine::GetSubscription() instead.
134 * @param value JavaScript subscription object. 174 * @param value JavaScript subscription object.
135 */ 175 */
136 Subscription(JsValue&& value); 176 Subscription(JsValue&& value);
137 }; 177 };
138 178
139 /** 179 /**
140 * Shared smart pointer to a `Filter` instance. 180 * A smart pointer to a `Filter` instance.
141 */ 181 */
142 typedef std::shared_ptr<Filter> FilterPtr; 182 typedef std::unique_ptr<Filter> FilterPtr;
143
144 /**
145 * Shared smart pointer to a `Subscription` instance.
146 */
147 typedef std::shared_ptr<Subscription> SubscriptionPtr;
148 183
149 /** 184 /**
150 * Main component of libadblockplus. 185 * Main component of libadblockplus.
151 * It handles: 186 * It handles:
152 * - Filter management and matching. 187 * - Filter management and matching.
153 * - Subscription management and synchronization. 188 * - Subscription management and synchronization.
154 * - Update checks for the application. 189 * - Update checks for the application.
155 */ 190 */
156 class FilterEngine 191 class FilterEngine
157 { 192 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 */ 234 */
200 typedef std::function<void(const std::string&)> UpdateCheckDoneCallback; 235 typedef std::function<void(const std::string&)> UpdateCheckDoneCallback;
201 236
202 /** 237 /**
203 * Callback type invoked when the filters change. 238 * Callback type invoked when the filters change.
204 * The first parameter is the action event code (see 239 * The first parameter is the action event code (see
205 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl uscore/FilterNotifier.html#.triggerListeners) 240 * [FilterNotifier.triggerListeners](https://adblockplus.org/jsdoc/adblockpl uscore/FilterNotifier.html#.triggerListeners)
206 * for the full list). 241 * for the full list).
207 * The second parameter is the filter/subscription object affected, if any. 242 * The second parameter is the filter/subscription object affected, if any.
208 */ 243 */
209 typedef std::function<void(const std::string&, const JsValuePtr)> FilterChan geCallback; 244 typedef std::function<void(const std::string&, JsValue&&)> FilterChangeCallb ack;
210 245
211 /** 246 /**
212 * Container of name-value pairs representing a set of preferences. 247 * Container of name-value pairs representing a set of preferences.
213 */ 248 */
214 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; 249 typedef std::map<std::string, AdblockPlus::JsValue> Prefs;
215 250
216 /** 251 /**
217 * Callback type invoked when a new notification should be shown. 252 * Callback type invoked when a new notification should be shown.
218 * The parameter is the Notification object to be shown. 253 * The parameter is the Notification object to be shown.
219 */ 254 */
220 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback ; 255 typedef std::function<void(Notification&&)> ShowNotificationCallback;
221 256
222 /** 257 /**
223 * Callback function returning false when current connection is not 258 * Callback function returning false when current connection is not
224 * allowedConnectionType, e.g. because it is a metered connection. 259 * allowedConnectionType, e.g. because it is a metered connection.
225 */ 260 */
226 typedef std::function<bool(const std::string* allowedConnectionType)> IsConn ectionAllowedCallback; 261 typedef std::function<bool(const std::string* allowedConnectionType)> IsConn ectionAllowedCallback;
227 262
228 /** 263 /**
229 * FilterEngine creation parameters. 264 * FilterEngine creation parameters.
230 */ 265 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 * @return `true` if the application is running for the first time. 313 * @return `true` if the application is running for the first time.
279 */ 314 */
280 bool IsFirstRun() const; 315 bool IsFirstRun() const;
281 316
282 /** 317 /**
283 * Retrieves a filter object from its text representation. 318 * Retrieves a filter object from its text representation.
284 * @param text Text representation of the filter, 319 * @param text Text representation of the filter,
285 * see https://adblockplus.org/en/filters. 320 * see https://adblockplus.org/en/filters.
286 * @return New `Filter` instance. 321 * @return New `Filter` instance.
287 */ 322 */
288 FilterPtr GetFilter(const std::string& text) const; 323 Filter GetFilter(const std::string& text) const;
289 324
290 /** 325 /**
291 * Retrieves a subscription object for the supplied URL. 326 * Retrieves a subscription object for the supplied URL.
292 * @param url Subscription URL. 327 * @param url Subscription URL.
293 * @return New `Subscription` instance. 328 * @return New `Subscription` instance.
294 */ 329 */
295 SubscriptionPtr GetSubscription(const std::string& url) const; 330 Subscription GetSubscription(const std::string& url) const;
296 331
297 /** 332 /**
298 * Retrieves the list of custom filters. 333 * Retrieves the list of custom filters.
299 * @return List of custom filters. 334 * @return List of custom filters.
300 */ 335 */
301 std::vector<FilterPtr> GetListedFilters() const; 336 std::vector<Filter> GetListedFilters() const;
302 337
303 /** 338 /**
304 * Retrieves all subscriptions. 339 * Retrieves all subscriptions.
305 * @return List of subscriptions. 340 * @return List of subscriptions.
306 */ 341 */
307 std::vector<SubscriptionPtr> GetListedSubscriptions() const; 342 std::vector<Subscription> GetListedSubscriptions() const;
308 343
309 /** 344 /**
310 * Retrieves all recommended subscriptions. 345 * Retrieves all recommended subscriptions.
311 * @return List of recommended subscriptions. 346 * @return List of recommended subscriptions.
312 */ 347 */
313 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; 348 std::vector<Subscription> FetchAvailableSubscriptions() const;
314 349
315 /** 350 /**
316 * Ensures that Acceptable Ads subscription is enabled or disabled. 351 * Ensures that the Acceptable Ads subscription is enabled or disabled.
317 * @param enabled 352 * @param enabled
318 * - if the value is `true` 353 * - if the value is `true`
319 * - ensure that the filter set includes an enabled AA subscription, 354 * - ensure that the filter set includes an enabled AA subscription,
320 * adding it if needed and enabling it if disabled. 355 * adding it if needed and enabling it if disabled.
321 * - if the value is `false` 356 * - if the value is `false`
322 * - if an AA subscription is present, disable it. 357 * - if an AA subscription is present, disable it.
323 * - if absent, do nothing. 358 * - if absent, do nothing.
324 */ 359 */
325 void SetAAEnabled(bool enabled); 360 void SetAAEnabled(bool enabled);
326 361
327 /** 362 /**
328 * Checks whether Acceptable Ads subscription is enabled. 363 * Checks whether the Acceptable Ads subscription is enabled.
329 * @return `true` if acceptable ads subscription is present and enabled. 364 * @return `true` if the Acceptable Ads subscription is present and enabled.
330 */ 365 */
331 bool IsAAEnabled() const; 366 bool IsAAEnabled() const;
332 367
333 /** 368 /**
334 * Retrieves the URL of Acceptable Ads subscription, what makes the URL 369 * Retrieves the URL of the Acceptable Ads subscription, what makes the URL
335 * available even if subscription is not add yet. 370 * available even if subscription is not added yet.
336 * @return Returns URL of Acceptable Ads. 371 * @return Returns URL of the Acceptable Ads.
337 */ 372 */
338 std::string GetAAUrl() const; 373 std::string GetAAUrl() const;
339 374
340 /** 375 /**
341 * Invokes the listener set via SetNotificationAvailableCallback() with the 376 * Invokes the listener set via SetNotificationAvailableCallback() with the
342 * next notification to be shown. 377 * next notification to be shown.
343 * @param url URL to match notifications to (optional). 378 * @param url URL to match notifications to (optional).
344 */ 379 */
345 void ShowNextNotification(const std::string& url = std::string()); 380 void ShowNextNotification(const std::string& url = std::string()) const;
346 381
347 /** 382 /**
348 * Sets the callback invoked when a notification should be shown. 383 * Sets the callback invoked when a notification should be shown.
349 * @param callback Callback to invoke. 384 * @param callback Callback to invoke.
350 */ 385 */
351 void SetShowNotificationCallback(const ShowNotificationCallback& value); 386 void SetShowNotificationCallback(const ShowNotificationCallback& value);
352 387
353 /** 388 /**
354 * Removes the callback invoked when a notification should be shown. 389 * Removes the callback invoked when a notification should be shown.
355 */ 390 */
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 * @param domain Domain to retrieve CSS selectors for. 456 * @param domain Domain to retrieve CSS selectors for.
422 * @return List of CSS selectors. 457 * @return List of CSS selectors.
423 */ 458 */
424 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const; 459 std::vector<std::string> GetElementHidingSelectors(const std::string& domain ) const;
425 460
426 /** 461 /**
427 * Retrieves a preference value. 462 * Retrieves a preference value.
428 * @param pref Preference name. 463 * @param pref Preference name.
429 * @return Preference value, or `null` if it doesn't exist. 464 * @return Preference value, or `null` if it doesn't exist.
430 */ 465 */
431 JsValuePtr GetPref(const std::string& pref) const; 466 JsValue GetPref(const std::string& pref) const;
432 467
433 /** 468 /**
434 * Sets a preference value. 469 * Sets a preference value.
435 * @param pref Preference name. 470 * @param pref Preference name.
436 * @param value New value of the preference. 471 * @param value New value of the preference.
437 */ 472 */
438 void SetPref(const std::string& pref, JsValuePtr value); 473 void SetPref(const std::string& pref, const JsValue& value);
439 474
440 /** 475 /**
441 * Extracts the host from a URL. 476 * Extracts the host from a URL.
442 * @param url URL to extract the host from. 477 * @param url URL to extract the host from.
443 * @return Extracted host. 478 * @return Extracted host.
444 */ 479 */
445 std::string GetHostFromURL(const std::string& url) const; 480 std::string GetHostFromURL(const std::string& url) const;
446 481
447 /** 482 /**
448 * Sets the callback invoked when an application update becomes available. 483 * Sets the callback invoked when an application update becomes available.
449 * @param callback Callback to invoke. 484 * @param callback Callback to invoke.
450 */ 485 */
451 void SetUpdateAvailableCallback(UpdateAvailableCallback callback); 486 void SetUpdateAvailableCallback(const UpdateAvailableCallback& callback);
452 487
453 /** 488 /**
454 * Removes the callback invoked when an application update becomes 489 * Removes the callback invoked when an application update becomes
455 * available. 490 * available.
456 */ 491 */
457 void RemoveUpdateAvailableCallback(); 492 void RemoveUpdateAvailableCallback();
458 493
459 /** 494 /**
460 * Forces an immediate update check. 495 * Forces an immediate update check.
461 * `FilterEngine` will automatically check for updates in regular intervals, 496 * `FilterEngine` will automatically check for updates in regular intervals,
462 * so applications should only call this when the user triggers an update 497 * so applications should only call this when the user triggers an update
463 * check manually. 498 * check manually.
464 * @param callback Optional callback to invoke when the update check is 499 * @param callback Optional callback to invoke when the update check is
465 * finished. The string parameter will be empty when the update check 500 * finished. The string parameter will be empty when the update check
466 * succeeded, or contain an error message if it failed. 501 * succeeded, or contain an error message if it failed.
467 * Note that the callback will be invoked whether updates are 502 * Note that the callback will be invoked whether updates are
468 * available or not - to react to updates being available, use 503 * available or not - to react to updates being available, use
469 * `FilterEngine::SetUpdateAvailableCallback()`. 504 * `FilterEngine::SetUpdateAvailableCallback()`.
470 */ 505 */
471 void ForceUpdateCheck(const UpdateCheckDoneCallback& callback = UpdateCheckD oneCallback()); 506 void ForceUpdateCheck(const UpdateCheckDoneCallback& callback = UpdateCheckD oneCallback());
472 507
473 /** 508 /**
474 * Sets the callback invoked when the filters change. 509 * Sets the callback invoked when the filters change.
475 * @param callback Callback to invoke. 510 * @param callback Callback to invoke.
476 */ 511 */
477 void SetFilterChangeCallback(FilterChangeCallback callback); 512 void SetFilterChangeCallback(const FilterChangeCallback& callback);
478 513
479 /** 514 /**
480 * Removes the callback invoked when the filters change. 515 * Removes the callback invoked when the filters change.
481 */ 516 */
482 void RemoveFilterChangeCallback(); 517 void RemoveFilterChangeCallback();
483 518
484 /** 519 /**
485 * Stores the value indicating what connection types are allowed, it is 520 * Stores the value indicating what connection types are allowed, it is
486 * passed to CreateParameters::isConnectionAllowed callback. 521 * passed to CreateParameters::isConnectionAllowed callback.
487 * @param value Stored value. nullptr means removing of any previously 522 * @param value Stored value. nullptr means removing of any previously
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 JsEnginePtr jsEngine; 562 JsEnginePtr jsEngine;
528 bool firstRun; 563 bool firstRun;
529 int updateCheckId; 564 int updateCheckId;
530 static const std::map<ContentType, std::string> contentTypes; 565 static const std::map<ContentType, std::string> contentTypes;
531 566
532 explicit FilterEngine(const JsEnginePtr& jsEngine); 567 explicit FilterEngine(const JsEnginePtr& jsEngine);
533 568
534 FilterPtr CheckFilterMatch(const std::string& url, 569 FilterPtr CheckFilterMatch(const std::string& url,
535 ContentTypeMask contentTypeMask, 570 ContentTypeMask contentTypeMask,
536 const std::string& documentUrl) const; 571 const std::string& documentUrl) const;
537 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); 572 void FilterChanged(const FilterChangeCallback& callback, JsValueList&& param s) const;
538 void UpdateCheckDone(const std::string& eventName,
539 UpdateCheckDoneCallback callback, JsValueList& params);
540 void FilterChanged(FilterChangeCallback callback, JsValueList& params);
541 void ShowNotification(const ShowNotificationCallback& callback,
542 const JsValueList& params);
543 FilterPtr GetWhitelistingFilter(const std::string& url, 573 FilterPtr GetWhitelistingFilter(const std::string& url,
544 ContentTypeMask contentTypeMask, const std::string& documentUrl) const; 574 ContentTypeMask contentTypeMask, const std::string& documentUrl) const;
545 FilterPtr GetWhitelistingFilter(const std::string& url, 575 FilterPtr GetWhitelistingFilter(const std::string& url,
546 ContentTypeMask contentTypeMask, 576 ContentTypeMask contentTypeMask,
547 const std::vector<std::string>& documentUrls) const; 577 const std::vector<std::string>& documentUrls) const;
548 }; 578 };
549 } 579 }
550 580
551 #endif 581 #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