| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 * Shared smart pointer to a `JsEngine` instance. | 50 * Shared smart pointer to a `JsEngine` instance. |
| 51 */ | 51 */ |
| 52 typedef std::shared_ptr<JsEngine> JsEnginePtr; | 52 typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * A factory to construct DefaultTimer. | 55 * A factory to construct DefaultTimer. |
| 56 */ | 56 */ |
| 57 TimerPtr CreateDefaultTimer(); | 57 TimerPtr CreateDefaultTimer(); |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * A factory to construct DefaultWebRequest. |
| 61 */ |
| 62 WebRequestPtr CreateDefaultWebRequest(); |
| 63 |
| 64 /** |
| 60 * Scope based isolate manager. Creates a new isolate instance on | 65 * Scope based isolate manager. Creates a new isolate instance on |
| 61 * constructing and disposes it on destructing. | 66 * constructing and disposes it on destructing. |
| 62 */ | 67 */ |
| 63 class ScopedV8Isolate | 68 class ScopedV8Isolate |
| 64 { | 69 { |
| 65 public: | 70 public: |
| 66 ScopedV8Isolate(); | 71 ScopedV8Isolate(); |
| 67 ~ScopedV8Isolate(); | 72 ~ScopedV8Isolate(); |
| 68 v8::Isolate* Get() | 73 v8::Isolate* Get() |
| 69 { | 74 { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 class JsWeakValuesID | 118 class JsWeakValuesID |
| 114 { | 119 { |
| 115 friend class JsEngine; | 120 friend class JsEngine; |
| 116 JsWeakValuesLists::const_iterator iterator; | 121 JsWeakValuesLists::const_iterator iterator; |
| 117 }; | 122 }; |
| 118 | 123 |
| 119 /** | 124 /** |
| 120 * Creates a new JavaScript engine instance. | 125 * Creates a new JavaScript engine instance. |
| 121 * @param appInfo Information about the app. | 126 * @param appInfo Information about the app. |
| 122 * @param timer Implementation of timer. | 127 * @param timer Implementation of timer. |
| 128 * @param webRequest Implementation of web request. |
| 123 * @param isolate v8::Isolate wrapper. This parameter should be considered | 129 * @param isolate v8::Isolate wrapper. This parameter should be considered |
| 124 * as a temporary hack for tests, it will go away. Issue #3593. | 130 * as a temporary hack for tests, it will go away. Issue #3593. |
| 125 * @return New `JsEngine` instance. | 131 * @return New `JsEngine` instance. |
| 126 */ | 132 */ |
| 127 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), | 133 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), |
| 128 TimerPtr timer = CreateDefaultTimer(), | 134 TimerPtr timer = CreateDefaultTimer(), |
| 135 WebRequestPtr webRequest = CreateDefaultWebRequest(), |
| 129 const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate
())); | 136 const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate
())); |
| 130 | 137 |
| 131 /** | 138 /** |
| 132 * Registers the callback function for an event. | 139 * Registers the callback function for an event. |
| 133 * @param eventName Event name. Note that this can be any string - it's a | 140 * @param eventName Event name. Note that this can be any string - it's a |
| 134 * general purpose event handling mechanism. | 141 * general purpose event handling mechanism. |
| 135 * @param callback Event callback function. | 142 * @param callback Event callback function. |
| 136 */ | 143 */ |
| 137 void SetEventCallback(const std::string& eventName, const EventCallback& cal
lback); | 144 void SetEventCallback(const std::string& eventName, const EventCallback& cal
lback); |
| 138 | 145 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 */ | 241 */ |
| 235 JsValueList TakeJsValues(const JsWeakValuesID& id); | 242 JsValueList TakeJsValues(const JsWeakValuesID& id); |
| 236 | 243 |
| 237 /* | 244 /* |
| 238 * Private functionality required to implement timers. | 245 * Private functionality required to implement timers. |
| 239 * @param arguments `v8::Arguments` is the arguments received in C++ | 246 * @param arguments `v8::Arguments` is the arguments received in C++ |
| 240 * callback associated for global setTimeout method. | 247 * callback associated for global setTimeout method. |
| 241 */ | 248 */ |
| 242 static void ScheduleTimer(const v8::Arguments& arguments); | 249 static void ScheduleTimer(const v8::Arguments& arguments); |
| 243 | 250 |
| 251 /* |
| 252 * Private functionality required to implement web requests. |
| 253 * @param arguments `v8::Arguments` is the arguments received in C++ |
| 254 * callback associated for global GET method. |
| 255 */ |
| 256 static void ScheduleWebRequest(const v8::Arguments& arguments); |
| 257 |
| 244 /** | 258 /** |
| 245 * Converts v8 arguments to `JsValue` objects. | 259 * Converts v8 arguments to `JsValue` objects. |
| 246 * @param arguments `v8::Arguments` object containing the arguments to | 260 * @param arguments `v8::Arguments` object containing the arguments to |
| 247 * convert. | 261 * convert. |
| 248 * @return List of arguments converted to `const JsValue` objects. | 262 * @return List of arguments converted to `const JsValue` objects. |
| 249 */ | 263 */ |
| 250 JsValueList ConvertArguments(const v8::Arguments& arguments); | 264 JsValueList ConvertArguments(const v8::Arguments& arguments); |
| 251 | 265 |
| 252 /** | 266 /** |
| 253 * @see `SetFileSystem()`. | 267 * @see `SetFileSystem()`. |
| 254 */ | 268 */ |
| 255 FileSystemPtr GetFileSystem() const; | 269 FileSystemPtr GetFileSystem() const; |
| 256 | 270 |
| 257 /** | 271 /** |
| 258 * Sets the `FileSystem` implementation used for all file I/O. | 272 * Sets the `FileSystem` implementation used for all file I/O. |
| 259 * Setting this is optional, the engine will use a `DefaultFileSystem` | 273 * Setting this is optional, the engine will use a `DefaultFileSystem` |
| 260 * instance by default, which might be sufficient. | 274 * instance by default, which might be sufficient. |
| 261 * @param The `FileSystem` instance to use. | 275 * @param The `FileSystem` instance to use. |
| 262 */ | 276 */ |
| 263 void SetFileSystem(const FileSystemPtr& val); | 277 void SetFileSystem(const FileSystemPtr& val); |
| 264 | 278 |
| 265 /** | 279 /** |
| 266 * @see `SetWebRequest()`. | |
| 267 */ | |
| 268 WebRequestSharedPtr GetWebRequest() const; | |
| 269 | |
| 270 /** | 280 /** |
| 271 * Sets the `WebRequest` implementation used for XMLHttpRequests. | 281 * Sets the `WebRequest` implementation used for XMLHttpRequests. |
| 272 * Setting this is optional, the engine will use a `DefaultWebRequest` | 282 * Setting this is optional, the engine will use a `DefaultWebRequest` |
| 273 * instance by default, which might be sufficient. | 283 * instance by default, which might be sufficient. |
| 274 * @param The `WebRequest` instance to use. | 284 * @param The `WebRequest` instance to use. |
| 275 */ | 285 */ |
| 276 void SetWebRequest(const WebRequestSharedPtr& val); | 286 void SetWebRequest(const WebRequestSharedPtr& val); |
| 277 | 287 |
| 278 /** | 288 /** |
| 279 * @see `SetLogSystem()`. | 289 * @see `SetLogSystem()`. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 300 * Returns a pointer to associated v8::Isolate. | 310 * Returns a pointer to associated v8::Isolate. |
| 301 */ | 311 */ |
| 302 v8::Isolate* GetIsolate() | 312 v8::Isolate* GetIsolate() |
| 303 { | 313 { |
| 304 return isolate->Get(); | 314 return isolate->Get(); |
| 305 } | 315 } |
| 306 | 316 |
| 307 private: | 317 private: |
| 308 void CallTimerTask(const JsWeakValuesID& timerParamsID); | 318 void CallTimerTask(const JsWeakValuesID& timerParamsID); |
| 309 | 319 |
| 310 explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer); | 320 explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer, WebRequ
estPtr webRequest); |
| 311 | 321 |
| 312 JsValue GetGlobalObject(); | 322 JsValue GetGlobalObject(); |
| 313 | 323 |
| 314 /// Isolate must be disposed only after disposing of all objects which are | 324 /// Isolate must be disposed only after disposing of all objects which are |
| 315 /// using it. | 325 /// using it. |
| 316 ScopedV8IsolatePtr isolate; | 326 ScopedV8IsolatePtr isolate; |
| 317 | 327 |
| 318 FileSystemPtr fileSystem; | 328 FileSystemPtr fileSystem; |
| 319 WebRequestSharedPtr webRequest; | |
| 320 LogSystemPtr logSystem; | 329 LogSystemPtr logSystem; |
| 321 std::unique_ptr<v8::Persistent<v8::Context>> context; | 330 std::unique_ptr<v8::Persistent<v8::Context>> context; |
| 322 EventMap eventCallbacks; | 331 EventMap eventCallbacks; |
| 323 std::mutex eventCallbacksMutex; | 332 std::mutex eventCallbacksMutex; |
| 324 JsWeakValuesLists jsWeakValuesLists; | 333 JsWeakValuesLists jsWeakValuesLists; |
| 325 std::mutex jsWeakValuesListsMutex; | 334 std::mutex jsWeakValuesListsMutex; |
| 326 TimerPtr timer; | 335 TimerPtr timer; |
| 336 WebRequestPtr webRequest; |
| 337 WebRequestSharedPtr webRequestLegacy; |
| 327 }; | 338 }; |
| 328 } | 339 } |
| 329 | 340 |
| 330 #endif | 341 #endif |
| OLD | NEW |