| OLD | NEW |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return isolate; | 75 return isolate; |
| 76 } | 76 } |
| 77 private: | 77 private: |
| 78 ScopedV8Isolate(const ScopedV8Isolate&); | 78 ScopedV8Isolate(const ScopedV8Isolate&); |
| 79 ScopedV8Isolate& operator=(const ScopedV8Isolate&); | 79 ScopedV8Isolate& operator=(const ScopedV8Isolate&); |
| 80 | 80 |
| 81 v8::Isolate* isolate; | 81 v8::Isolate* isolate; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Shared smart pointer to ScopedV8Isolate instance; | |
| 86 */ | |
| 87 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr; | |
| 88 | |
| 89 /** | |
| 90 * JavaScript engine used by `FilterEngine`, wraps v8. | 85 * JavaScript engine used by `FilterEngine`, wraps v8. |
| 91 */ | 86 */ |
| 92 class JsEngine : public std::enable_shared_from_this<JsEngine> | 87 class JsEngine : public std::enable_shared_from_this<JsEngine> |
| 93 { | 88 { |
| 94 friend class JsValue; | 89 friend class JsValue; |
| 95 friend class JsContext; | 90 friend class JsContext; |
| 96 | 91 |
| 97 struct JsWeakValuesList | 92 struct JsWeakValuesList |
| 98 { | 93 { |
| 99 ~JsWeakValuesList(); | 94 ~JsWeakValuesList(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 125 * Creates a new JavaScript engine instance. | 120 * Creates a new JavaScript engine instance. |
| 126 * @param appInfo Information about the app. | 121 * @param appInfo Information about the app. |
| 127 * @param timer Implementation of timer. | 122 * @param timer Implementation of timer. |
| 128 * @param webRequest Implementation of web request. | 123 * @param webRequest Implementation of web request. |
| 129 * @param isolate v8::Isolate wrapper. This parameter should be considered | 124 * @param isolate v8::Isolate wrapper. This parameter should be considered |
| 130 * as a temporary hack for tests, it will go away. Issue #3593. | 125 * as a temporary hack for tests, it will go away. Issue #3593. |
| 131 * @return New `JsEngine` instance. | 126 * @return New `JsEngine` instance. |
| 132 */ | 127 */ |
| 133 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), | 128 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), |
| 134 TimerPtr timer = CreateDefaultTimer(), | 129 TimerPtr timer = CreateDefaultTimer(), |
| 135 WebRequestPtr webRequest = CreateDefaultWebRequest(), | 130 WebRequestPtr webRequest = CreateDefaultWebRequest()); |
| 136 const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate
())); | |
| 137 | 131 |
| 138 /** | 132 /** |
| 139 * Registers the callback function for an event. | 133 * Registers the callback function for an event. |
| 140 * @param eventName Event name. Note that this can be any string - it's a | 134 * @param eventName Event name. Note that this can be any string - it's a |
| 141 * general purpose event handling mechanism. | 135 * general purpose event handling mechanism. |
| 142 * @param callback Event callback function. | 136 * @param callback Event callback function. |
| 143 */ | 137 */ |
| 144 void SetEventCallback(const std::string& eventName, const EventCallback& cal
lback); | 138 void SetEventCallback(const std::string& eventName, const EventCallback& cal
lback); |
| 145 | 139 |
| 146 /** | 140 /** |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 * @param name Name of the property to set. | 297 * @param name Name of the property to set. |
| 304 * @param value Value of the property to set. | 298 * @param value Value of the property to set. |
| 305 */ | 299 */ |
| 306 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue&
value); | 300 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue&
value); |
| 307 | 301 |
| 308 /** | 302 /** |
| 309 * Returns a pointer to associated v8::Isolate. | 303 * Returns a pointer to associated v8::Isolate. |
| 310 */ | 304 */ |
| 311 v8::Isolate* GetIsolate() | 305 v8::Isolate* GetIsolate() |
| 312 { | 306 { |
| 313 return isolate->Get(); | 307 return isolate.Get(); |
| 314 } | 308 } |
| 315 | 309 |
| 316 private: | 310 private: |
| 317 void CallTimerTask(const JsWeakValuesID& timerParamsID); | 311 void CallTimerTask(const JsWeakValuesID& timerParamsID); |
| 318 | 312 |
| 319 explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer, WebRequ
estPtr webRequest); | 313 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest); |
| 320 | 314 |
| 321 JsValue GetGlobalObject(); | 315 JsValue GetGlobalObject(); |
| 322 | 316 |
| 323 /// Isolate must be disposed only after disposing of all objects which are | 317 /// Isolate must be disposed only after disposing of all objects which are |
| 324 /// using it. | 318 /// using it. |
| 325 ScopedV8IsolatePtr isolate; | 319 ScopedV8Isolate isolate; |
| 326 | 320 |
| 327 FileSystemPtr fileSystem; | 321 FileSystemPtr fileSystem; |
| 328 LogSystemPtr logSystem; | 322 LogSystemPtr logSystem; |
| 329 std::unique_ptr<v8::Persistent<v8::Context>> context; | 323 std::unique_ptr<v8::Persistent<v8::Context>> context; |
| 330 EventMap eventCallbacks; | 324 EventMap eventCallbacks; |
| 331 std::mutex eventCallbacksMutex; | 325 std::mutex eventCallbacksMutex; |
| 332 JsWeakValuesLists jsWeakValuesLists; | 326 JsWeakValuesLists jsWeakValuesLists; |
| 333 std::mutex jsWeakValuesListsMutex; | 327 std::mutex jsWeakValuesListsMutex; |
| 334 TimerPtr timer; | 328 TimerPtr timer; |
| 335 WebRequestPtr webRequest; | 329 WebRequestPtr webRequest; |
| 336 WebRequestSharedPtr webRequestLegacy; | 330 WebRequestSharedPtr webRequestLegacy; |
| 337 }; | 331 }; |
| 338 } | 332 } |
| 339 | 333 |
| 340 #endif | 334 #endif |
| OLD | NEW |