| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2016 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 |
| 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 * |
| 14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #ifndef ADBLOCK_PLUS_FILTER_ENGINE_H | 18 #ifndef ADBLOCK_PLUS_FILTER_ENGINE_H |
| 19 #define ADBLOCK_PLUS_FILTER_ENGINE_H | 19 #define ADBLOCK_PLUS_FILTER_ENGINE_H |
| 20 | 20 |
| 21 #include <functional> | 21 #include <functional> |
| 22 #include <map> | 22 #include <map> |
| 23 #include <string> | 23 #include <string> |
| 24 #include <vector> | 24 #include <vector> |
| 25 #include <AdblockPlus/JsEngine.h> | 25 #include <AdblockPlus/JsEngine.h> |
| 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 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; | |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Wrapper for an Adblock Plus filter object. | 35 * Wrapper for an Adblock Plus filter object. |
| 35 * There are no accessors for most | 36 * There are no accessors for most |
| 36 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml), | 37 * [filter properties](https://adblockplus.org/jsdoc/adblockpluscore/Filter.ht ml), |
| 37 * use `GetProperty()` to retrieve them by name. | 38 * use `GetProperty()` to retrieve them by name. |
| 38 */ | 39 */ |
| 39 class Filter : public JsValue, | 40 class Filter : public JsValue, |
| 40 public std::enable_shared_from_this<Filter> | 41 public std::enable_shared_from_this<Filter> |
| 41 { | 42 { |
| 42 public: | 43 public: |
| 43 /** | 44 /** |
| 44 * Filter types, see https://adblockplus.org/en/filters. | 45 * Filter types, see https://adblockplus.org/en/filters. |
| 45 */ | 46 */ |
| 46 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, | 47 enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, |
| 47 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, | 48 TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, |
| 48 TYPE_COMMENT, TYPE_INVALID}; | 49 TYPE_COMMENT, TYPE_INVALID}; |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Retrieves the type of this filter. | 52 * Retrieves the type of this filter. |
| 52 * @return Type of this filter. | 53 * @return Type of this filter. |
| 53 */ | 54 */ |
| 54 Type GetType(); | 55 Type GetType() const; |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * Checks whether this filter has been added to the list of custom filters. | 58 * Checks whether this filter has been added to the list of custom filters. |
| 58 * @return `true` if this filter has been added. | 59 * @return `true` if this filter has been added. |
| 59 */ | 60 */ |
| 60 bool IsListed(); | 61 bool IsListed() const; |
| 61 | 62 |
| 62 /** | 63 /** |
| 63 * Adds this filter to the list of custom filters. | 64 * Adds this filter to the list of custom filters. |
| 64 */ | 65 */ |
| 65 void AddToList(); | 66 void AddToList(); |
| 66 | 67 |
| 67 /** | 68 /** |
| 68 * Removes this filter from the list of custom filters. | 69 * Removes this filter from the list of custom filters. |
| 69 */ | 70 */ |
| 70 void RemoveFromList(); | 71 void RemoveFromList(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 87 * use `GetProperty()` to retrieve them by name. | 88 * use `GetProperty()` to retrieve them by name. |
| 88 */ | 89 */ |
| 89 class Subscription : public JsValue, | 90 class Subscription : public JsValue, |
| 90 public std::enable_shared_from_this<Subscription> | 91 public std::enable_shared_from_this<Subscription> |
| 91 { | 92 { |
| 92 public: | 93 public: |
| 93 /** | 94 /** |
| 94 * Checks if this subscription has been added to the list of subscriptions. | 95 * Checks if this subscription has been added to the list of subscriptions. |
| 95 * @return `true` if this subscription has been added. | 96 * @return `true` if this subscription has been added. |
| 96 */ | 97 */ |
| 97 bool IsListed(); | 98 bool IsListed() const; |
| 98 | 99 |
| 99 /** | 100 /** |
| 100 * Adds this subscription to the list of subscriptions. | 101 * Adds this subscription to the list of subscriptions. |
| 101 */ | 102 */ |
| 102 void AddToList(); | 103 void AddToList(); |
| 103 | 104 |
| 104 /** | 105 /** |
| 105 * Removes this subscription from the list of subscriptions. | 106 * Removes this subscription from the list of subscriptions. |
| 106 */ | 107 */ |
| 107 void RemoveFromList(); | 108 void RemoveFromList(); |
| 108 | 109 |
| 109 /** | 110 /** |
| 110 * Updates this subscription, i.e.\ retrieves the current filters from the | 111 * Updates this subscription, i.e.\ retrieves the current filters from the |
| 111 * subscription URL. | 112 * subscription URL. |
| 112 */ | 113 */ |
| 113 void UpdateFilters(); | 114 void UpdateFilters(); |
| 114 | 115 |
| 115 /** | 116 /** |
| 116 * Checks if the subscription is currently being updated. | 117 * Checks if the subscription is currently being updated. |
| 117 * @return `true` if the subscription is currently being updated. | 118 * @return `true` if the subscription is currently being updated. |
| 118 */ | 119 */ |
| 119 bool IsUpdating(); | 120 bool IsUpdating() const; |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Indicates whether the subscription is acceptable ads subscription. | 123 * Indicates whether the subscription is acceptable ads subscription. |
| 123 * @return `true` if this subscription is acceptable ads subscription. | 124 * @return `true` if this subscription is acceptable ads subscription. |
| 124 */ | 125 */ |
| 125 bool IsAA(); | 126 bool IsAA() const; |
| 126 | 127 |
|
Eric
2016/12/05 14:40:57
Typo: extra column of spaces
sergei
2017/03/17 15:55:25
Done.
| |
| 127 bool operator==(const Subscription& subscription) const; | 128 bool operator==(const Subscription& subscription) const; |
| 128 | 129 |
| 129 /** | 130 /** |
| 130 * Creates a wrapper for an existing JavaScript subscription object. | 131 * Creates a wrapper for an existing JavaScript subscription object. |
| 131 * Normally you shouldn't call this directly, but use | 132 * Normally you shouldn't call this directly, but use |
| 132 * FilterEngine::GetSubscription() instead. | 133 * FilterEngine::GetSubscription() instead. |
| 133 * @param value JavaScript subscription object. | 134 * @param value JavaScript subscription object. |
| 134 */ | 135 */ |
| 135 Subscription(JsValue&& value); | 136 Subscription(JsValue&& value); |
| 136 }; | 137 }; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 */ | 213 */ |
| 213 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; | 214 typedef std::map<std::string, AdblockPlus::JsValuePtr> Prefs; |
| 214 | 215 |
| 215 /** | 216 /** |
| 216 * Callback type invoked when a new notification should be shown. | 217 * Callback type invoked when a new notification should be shown. |
| 217 * The parameter is the Notification object to be shown. | 218 * The parameter is the Notification object to be shown. |
| 218 */ | 219 */ |
| 219 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback ; | 220 typedef std::function<void(const NotificationPtr&)> ShowNotificationCallback ; |
| 220 | 221 |
| 221 /** | 222 /** |
| 222 * Constructor. | 223 * Callback function returning false when current connection is not |
| 224 * allowedConnectionType, e.g. because it is a metered connection. | |
| 225 */ | |
| 226 typedef std::function<bool(const std::string* allowedConnectionType)> IsConn ectionAllowedCallback; | |
| 227 | |
| 228 /** | |
| 229 * FilterEngine creation parameters. | |
| 230 */ | |
| 231 struct CreationParameters | |
| 232 { | |
| 233 /** | |
| 234 * `AdblockPlus::FilterEngine::Prefs` name - value list of preconfigured | |
| 235 * prefs. | |
| 236 */ | |
| 237 Prefs preconfiguredPrefs; | |
| 238 /** | |
| 239 * `AdblockPlus::FilterEngine::IsConnectionAllowedCallback` a callback | |
| 240 * checking whether the request from Adblock Plus should be blocked on | |
| 241 * the current connection. | |
| 242 */ | |
| 243 IsConnectionAllowedCallback isConnectionAllowedCallback; | |
| 244 }; | |
| 245 | |
| 246 /** | |
| 247 * Callback type invoked when FilterEngine is created. | |
| 248 */ | |
| 249 typedef std::function<void(const FilterEnginePtr&)> OnCreatedCallback; | |
| 250 | |
| 251 /** | |
| 252 * Asynchronously constructs FilterEngine. | |
| 223 * @param jsEngine `JsEngine` instance used to run JavaScript code | 253 * @param jsEngine `JsEngine` instance used to run JavaScript code |
| 224 * internally. | 254 * internally. |
| 225 * @param preconfiguredPrefs `AdblockPlus::FilterEngine::Prefs` | 255 * @param onCreated A callback which is called when FilterEngine is ready |
| 226 * name-value list of preconfigured prefs. | 256 * for use. |
| 227 */ | 257 * @param parameters optional creation parameters. |
| 228 explicit FilterEngine(JsEnginePtr jsEngine, | 258 */ |
| 229 const Prefs& preconfiguredPrefs = Prefs() | 259 static void CreateAsync(const JsEnginePtr& jsEngine, |
| 230 ); | 260 const OnCreatedCallback& onCreated, |
| 261 const CreationParameters& parameters = CreationParameters()); | |
| 262 | |
| 263 /** | |
| 264 * Synchronous interface to construct FilterEngine. For details see | |
| 265 * asynchronous version CreateAsync. | |
| 266 */ | |
| 267 static FilterEnginePtr Create(const JsEnginePtr& jsEngine, | |
| 268 const CreationParameters& params = CreationParameters()); | |
| 231 | 269 |
| 232 /** | 270 /** |
| 233 * Retrieves the `JsEngine` instance associated with this `FilterEngine` | 271 * Retrieves the `JsEngine` instance associated with this `FilterEngine` |
| 234 * instance. | 272 * instance. |
| 235 */ | 273 */ |
| 236 JsEnginePtr GetJsEngine() const { return jsEngine; } | 274 JsEnginePtr GetJsEngine() const { return jsEngine; } |
| 237 | 275 |
| 238 /** | 276 /** |
| 239 * Checks if this is the first run of the application. | 277 * Checks if this is the first run of the application. |
| 240 * @return `true` if the application is running for the first time. | 278 * @return `true` if the application is running for the first time. |
| 241 */ | 279 */ |
| 242 bool IsFirstRun() const; | 280 bool IsFirstRun() const; |
| 243 | 281 |
| 244 /** | 282 /** |
| 245 * Retrieves a filter object from its text representation. | 283 * Retrieves a filter object from its text representation. |
| 246 * @param text Text representation of the filter, | 284 * @param text Text representation of the filter, |
| 247 * see https://adblockplus.org/en/filters. | 285 * see https://adblockplus.org/en/filters. |
| 248 * @return New `Filter` instance. | 286 * @return New `Filter` instance. |
| 249 */ | 287 */ |
| 250 FilterPtr GetFilter(const std::string& text); | 288 FilterPtr GetFilter(const std::string& text) const; |
| 251 | 289 |
| 252 /** | 290 /** |
| 253 * Retrieves a subscription object for the supplied URL. | 291 * Retrieves a subscription object for the supplied URL. |
| 254 * @param url Subscription URL. | 292 * @param url Subscription URL. |
| 255 * @return New `Subscription` instance. | 293 * @return New `Subscription` instance. |
| 256 */ | 294 */ |
| 257 SubscriptionPtr GetSubscription(const std::string& url); | 295 SubscriptionPtr GetSubscription(const std::string& url) const; |
| 258 | 296 |
| 259 /** | 297 /** |
| 260 * Retrieves the list of custom filters. | 298 * Retrieves the list of custom filters. |
| 261 * @return List of custom filters. | 299 * @return List of custom filters. |
| 262 */ | 300 */ |
| 263 std::vector<FilterPtr> GetListedFilters() const; | 301 std::vector<FilterPtr> GetListedFilters() const; |
| 264 | 302 |
| 265 /** | 303 /** |
| 266 * Retrieves all subscriptions. | 304 * Retrieves all subscriptions. |
| 267 * @return List of subscriptions. | 305 * @return List of subscriptions. |
| 268 */ | 306 */ |
| 269 std::vector<SubscriptionPtr> GetListedSubscriptions() const; | 307 std::vector<SubscriptionPtr> GetListedSubscriptions() const; |
| 270 | 308 |
| 271 /** | 309 /** |
| 272 * Retrieves all recommended subscriptions. | 310 * Retrieves all recommended subscriptions. |
| 273 * @return List of recommended subscriptions. | 311 * @return List of recommended subscriptions. |
| 274 */ | 312 */ |
| 275 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; | 313 std::vector<SubscriptionPtr> FetchAvailableSubscriptions() const; |
| 276 | 314 |
| 277 /** | 315 /** |
| 278 * Ensures that Acceptable Ads subscription is enabled or disabled. | 316 * Ensures that Acceptable Ads subscription is enabled or disabled. |
| 279 * @param enabled If the value is true, adds AA subscription in case of | 317 * @param enabled |
| 280 * necessity and enables AA subscription is disabled. If the value | 318 * - if the value is `true` |
| 281 * is false, disables the subscription if it is present and enabled. | 319 * - ensure that the filter set includes an enabled AA subscription, |
| 282 * Otherwise has not effect. | 320 * adding it if needed and enabling it if disabled. |
|
Eric
2016/12/05 14:40:57
* @param enabled
* - if the argument is `true`
*
sergei
2017/03/17 15:55:25
The proposed variant is taken mostly without chang
| |
| 321 * - if the value is `false` | |
| 322 * - if an AA subscription is present, disable it. | |
| 323 * - if absent, do nothing. | |
| 283 */ | 324 */ |
| 284 void SetAAEnabled(bool enabled); | 325 void SetAAEnabled(bool enabled); |
| 285 | 326 |
| 286 /** | 327 /** |
| 287 * Checks whether Acceptable Ads subscription is enaled. | 328 * Checks whether Acceptable Ads subscription is enabled. |
|
Eric
2016/12/05 14:40:57
"... whether the filter set includes an Acceptable
sergei
2017/03/17 15:55:25
It cannot be enabled and not included in a filter
| |
| 288 * @return `true` if acceptable ads subscription is present and enabled. | 329 * @return `true` if acceptable ads subscription is present and enabled. |
| 289 */ | 330 */ |
| 290 bool IsAAEnabled() const; | 331 bool IsAAEnabled() const; |
| 291 | 332 |
| 292 /** | 333 /** |
| 293 * Retrieves the URL of Acceptable Ads provisioned in configuration, what | 334 * Retrieves the URL of Acceptable Ads subscription, what makes the URL |
| 294 * makes it available even if subscription is not add yet. | 335 * available even if subscription is not add yet. |
|
Eric
2016/12/05 14:40:57
* Retrieve the URL for an Acceptable Ads subscript
sergei
2017/03/17 15:55:25
The aim of this method is not to add the AA subscr
| |
| 295 * @return Returns URL of Acceptable Ads. | 336 * @return Returns URL of Acceptable Ads. |
| 296 */ | 337 */ |
| 297 std::string GetAAURL() const; | 338 std::string GetAAUrl() const; |
|
Eric
2016/12/05 14:40:57
Nit: According to our style conventions, it should
sergei
2017/03/17 15:55:25
Done.
| |
| 298 | 339 |
| 299 /** | 340 /** |
| 300 * Invokes the listener set via SetNotificationAvailableCallback() with the | 341 * Invokes the listener set via SetNotificationAvailableCallback() with the |
| 301 * next notification to be shown. | 342 * next notification to be shown. |
| 302 * @param url URL to match notifications to (optional). | 343 * @param url URL to match notifications to (optional). |
| 303 */ | 344 */ |
| 304 void ShowNextNotification(const std::string& url = std::string()); | 345 void ShowNextNotification(const std::string& url = std::string()); |
| 305 | 346 |
| 306 /** | 347 /** |
| 307 * Sets the callback invoked when a notification should be shown. | 348 * Sets the callback invoked when a notification should be shown. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 * @param pref Preference name. | 435 * @param pref Preference name. |
| 395 * @param value New value of the preference. | 436 * @param value New value of the preference. |
| 396 */ | 437 */ |
| 397 void SetPref(const std::string& pref, JsValuePtr value); | 438 void SetPref(const std::string& pref, JsValuePtr value); |
| 398 | 439 |
| 399 /** | 440 /** |
| 400 * Extracts the host from a URL. | 441 * Extracts the host from a URL. |
| 401 * @param url URL to extract the host from. | 442 * @param url URL to extract the host from. |
| 402 * @return Extracted host. | 443 * @return Extracted host. |
| 403 */ | 444 */ |
| 404 std::string GetHostFromURL(const std::string& url); | 445 std::string GetHostFromURL(const std::string& url) const; |
| 405 | 446 |
| 406 /** | 447 /** |
| 407 * Sets the callback invoked when an application update becomes available. | 448 * Sets the callback invoked when an application update becomes available. |
| 408 * @param callback Callback to invoke. | 449 * @param callback Callback to invoke. |
| 409 */ | 450 */ |
| 410 void SetUpdateAvailableCallback(UpdateAvailableCallback callback); | 451 void SetUpdateAvailableCallback(UpdateAvailableCallback callback); |
| 411 | 452 |
| 412 /** | 453 /** |
| 413 * Removes the callback invoked when an application update becomes | 454 * Removes the callback invoked when an application update becomes |
| 414 * available. | 455 * available. |
| 415 */ | 456 */ |
| 416 void RemoveUpdateAvailableCallback(); | 457 void RemoveUpdateAvailableCallback(); |
| 417 | 458 |
| 418 /** | 459 /** |
| 419 * Forces an immediate update check. | 460 * Forces an immediate update check. |
| 420 * `FilterEngine` will automatically check for updates in regular intervals, | 461 * `FilterEngine` will automatically check for updates in regular intervals, |
| 421 * so applications should only call this when the user triggers an update | 462 * so applications should only call this when the user triggers an update |
| 422 * check manually. | 463 * check manually. |
| 423 * @param callback Optional callback to invoke when the update check is | 464 * @param callback Optional callback to invoke when the update check is |
| 424 * finished. The string parameter will be empty when the update check | 465 * finished. The string parameter will be empty when the update check |
| 425 * succeeded, or contain an error message if it failed. | 466 * succeeded, or contain an error message if it failed. |
| 426 * Note that the callback will be invoked whether updates are | 467 * Note that the callback will be invoked whether updates are |
| 427 * available or not - to react to updates being available, use | 468 * available or not - to react to updates being available, use |
| 428 * `FilterEngine::SetUpdateAvailableCallback()`. | 469 * `FilterEngine::SetUpdateAvailableCallback()`. |
| 429 */ | 470 */ |
| 430 void ForceUpdateCheck(UpdateCheckDoneCallback callback); | 471 void ForceUpdateCheck(const UpdateCheckDoneCallback& callback = UpdateCheckD oneCallback()); |
| 431 | 472 |
| 432 /** | 473 /** |
| 433 * Sets the callback invoked when the filters change. | 474 * Sets the callback invoked when the filters change. |
| 434 * @param callback Callback to invoke. | 475 * @param callback Callback to invoke. |
| 435 */ | 476 */ |
| 436 void SetFilterChangeCallback(FilterChangeCallback callback); | 477 void SetFilterChangeCallback(FilterChangeCallback callback); |
| 437 | 478 |
| 438 /** | 479 /** |
| 439 * Removes the callback invoked when the filters change. | 480 * Removes the callback invoked when the filters change. |
| 440 */ | 481 */ |
| 441 void RemoveFilterChangeCallback(); | 482 void RemoveFilterChangeCallback(); |
| 483 | |
| 484 /** | |
| 485 * Stores the value indicating what connection types are allowed, it is | |
| 486 * passed to CreateParameters::isConnectionAllowed callback. | |
| 487 * @param value Stored value. nullptr means removing of any previously | |
| 488 * stored value. | |
| 489 */ | |
| 490 void SetAllowedConnectionType(const std::string* value); | |
| 491 | |
| 492 /** | |
| 493 * Retrieves previously stored allowed connection type. | |
| 494 * @return Preference value, or `nullptr` if it doesn't exist. | |
| 495 */ | |
| 496 std::unique_ptr<std::string> GetAllowedConnectionType() const; | |
| 442 | 497 |
| 443 /** | 498 /** |
| 444 * Compares two version strings in | 499 * Compares two version strings in |
| 445 * [Mozilla toolkit version format](https://developer.mozilla.org/en/docs/To olkit_version_format). | 500 * [Mozilla toolkit version format](https://developer.mozilla.org/en/docs/To olkit_version_format). |
| 446 * @param v1 First version string. | 501 * @param v1 First version string. |
| 447 * @param v2 Second version string. | 502 * @param v2 Second version string. |
| 448 * @return | 503 * @return |
| 449 * - `0` if `v1` and `v2` are identical. | 504 * - `0` if `v1` and `v2` are identical. |
| 450 * - A negative number if `v1` is less than `v2`. | 505 * - A negative number if `v1` is less than `v2`. |
| 451 * - A positive number if `v1` is greater than `v2`. | 506 * - A positive number if `v1` is greater than `v2`. |
| 452 */ | 507 */ |
| 453 int CompareVersions(const std::string& v1, const std::string& v2); | 508 int CompareVersions(const std::string& v1, const std::string& v2) const; |
| 454 | 509 |
| 455 /** | 510 /** |
| 456 * Retrieves the `ContentType` for the supplied string. | 511 * Retrieves the `ContentType` for the supplied string. |
| 457 * @param contentType Content type string. | 512 * @param contentType Content type string. |
| 458 * @return The `ContentType` for the string. | 513 * @return The `ContentType` for the string. |
| 459 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. | 514 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. |
| 460 */ | 515 */ |
| 461 static ContentType StringToContentType(const std::string& contentType); | 516 static ContentType StringToContentType(const std::string& contentType); |
| 462 | 517 |
| 463 /** | 518 /** |
| 464 * Retrieves the string representation of the supplied `ContentType`. | 519 * Retrieves the string representation of the supplied `ContentType`. |
| 465 * @param contentType `ContentType` value. | 520 * @param contentType `ContentType` value. |
| 466 * @return The string representation of `contentType`. | 521 * @return The string representation of `contentType`. |
| 467 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. | 522 * @throw `std::invalid_argument`, if an invalid `contentType` was supplied. |
| 468 */ | 523 */ |
| 469 static std::string ContentTypeToString(ContentType contentType); | 524 static std::string ContentTypeToString(ContentType contentType); |
| 470 | 525 |
| 471 private: | 526 private: |
| 472 JsEnginePtr jsEngine; | 527 JsEnginePtr jsEngine; |
| 473 bool initialized; | |
| 474 bool firstRun; | 528 bool firstRun; |
| 475 int updateCheckId; | 529 int updateCheckId; |
| 476 static const std::map<ContentType, std::string> contentTypes; | 530 static const std::map<ContentType, std::string> contentTypes; |
| 477 | 531 |
| 478 void InitDone(JsValueList& params); | 532 explicit FilterEngine(const JsEnginePtr& jsEngine); |
| 533 | |
| 479 FilterPtr CheckFilterMatch(const std::string& url, | 534 FilterPtr CheckFilterMatch(const std::string& url, |
| 480 ContentTypeMask contentTypeMask, | 535 ContentTypeMask contentTypeMask, |
| 481 const std::string& documentUrl) const; | 536 const std::string& documentUrl) const; |
| 482 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); | 537 void UpdateAvailable(UpdateAvailableCallback callback, JsValueList& params); |
| 483 void UpdateCheckDone(const std::string& eventName, | 538 void UpdateCheckDone(const std::string& eventName, |
| 484 UpdateCheckDoneCallback callback, JsValueList& params); | 539 UpdateCheckDoneCallback callback, JsValueList& params); |
| 485 void FilterChanged(FilterChangeCallback callback, JsValueList& params); | 540 void FilterChanged(FilterChangeCallback callback, JsValueList& params); |
| 486 void ShowNotification(const ShowNotificationCallback& callback, | 541 void ShowNotification(const ShowNotificationCallback& callback, |
| 487 const JsValueList& params); | 542 const JsValueList& params); |
| 488 FilterPtr GetWhitelistingFilter(const std::string& url, | 543 FilterPtr GetWhitelistingFilter(const std::string& url, |
| 489 ContentTypeMask contentTypeMask, const std::string& documentUrl) const; | 544 ContentTypeMask contentTypeMask, const std::string& documentUrl) const; |
| 490 FilterPtr GetWhitelistingFilter(const std::string& url, | 545 FilterPtr GetWhitelistingFilter(const std::string& url, |
| 491 ContentTypeMask contentTypeMask, | 546 ContentTypeMask contentTypeMask, |
| 492 const std::vector<std::string>& documentUrls) const; | 547 const std::vector<std::string>& documentUrls) const; |
| 493 }; | 548 }; |
| 494 } | 549 } |
| 495 | 550 |
| 496 #endif | 551 #endif |
| LEFT | RIGHT |