| Index: include/AdblockPlus/JsEngine.h |
| diff --git a/include/AdblockPlus/JsEngine.h b/include/AdblockPlus/JsEngine.h |
| index f7470ab84367b00e298c9038d92b21837fb08202..c3c2b6724dcf3a1dabd51ccb7888c7239f80afe6 100644 |
| --- a/include/AdblockPlus/JsEngine.h |
| +++ b/include/AdblockPlus/JsEngine.h |
| @@ -1,6 +1,6 @@ |
| /* |
| * This file is part of Adblock Plus <https://adblockplus.org/>, |
| - * Copyright (C) 2006-2017 eyeo GmbH |
| + * Copyright (C) 2006-present eyeo GmbH |
| * |
| * Adblock Plus is free software: you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 3 as |
| @@ -27,10 +27,11 @@ |
| #include <mutex> |
| #include <AdblockPlus/AppInfo.h> |
| #include <AdblockPlus/LogSystem.h> |
| -#include <AdblockPlus/FileSystem.h> |
| +#include <AdblockPlus/IFileSystem.h> |
| #include <AdblockPlus/JsValue.h> |
| -#include <AdblockPlus/WebRequest.h> |
| +#include <AdblockPlus/IWebRequest.h> |
| #include <AdblockPlus/ITimer.h> |
| +#include <AdblockPlus/Scheduler.h> |
| namespace v8 |
| { |
| @@ -44,6 +45,7 @@ namespace v8 |
| namespace AdblockPlus |
| { |
| class JsEngine; |
| + class Platform; |
| /** |
| * Shared smart pointer to a `JsEngine` instance. |
| @@ -51,21 +53,6 @@ namespace AdblockPlus |
| typedef std::shared_ptr<JsEngine> JsEnginePtr; |
| /** |
| - * A factory to construct DefaultTimer. |
| - */ |
| - TimerPtr CreateDefaultTimer(); |
| - |
| - /** |
| - * A factory to construct DefaultFileSystem. |
| - */ |
| - FileSystemPtr CreateDefaultFileSystem(); |
| - |
| - /** |
| - * A factory to construct DefaultWebRequest. |
| - */ |
| - WebRequestPtr CreateDefaultWebRequest(); |
| - |
| - /** |
| * Scope based isolate manager. Creates a new isolate instance on |
| * constructing and disposes it on destructing. |
| */ |
| @@ -122,17 +109,13 @@ namespace AdblockPlus |
| /** |
| * Creates a new JavaScript engine instance. |
| + * |
| * @param appInfo Information about the app. |
| - * @param timer Implementation of timer. |
| - * @param fileSystem Implementation of filesystem. |
| - * @param webRequest Implementation of web request. |
| + * @param platform AdblockPlus platform providing with necessary |
| + * dependencies. |
| * @return New `JsEngine` instance. |
| */ |
| - static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), |
| - TimerPtr timer = CreateDefaultTimer(), |
| - FileSystemPtr fileSystem = CreateDefaultFileSystem(), |
| - WebRequestPtr webRequest = CreateDefaultWebRequest()); |
| - |
| + static JsEnginePtr New(const AppInfo& appInfo, Platform& platform); |
| /** |
| * Registers the callback function for an event. |
| * @param eventName Event name. Note that this can be any string - it's a |
| @@ -262,43 +245,6 @@ namespace AdblockPlus |
| JsValueList ConvertArguments(const v8::FunctionCallbackInfo<v8::Value>& arguments); |
| /** |
| - * Private functionality. |
| - * @return The asynchronous IFileSystem implementation. |
| - */ |
| - FileSystemPtr GetAsyncFileSystem() const; |
| - |
| - /** |
| - * Sets the synchronous `FileSystem` implementation used for all |
| - * file I/O. Setting this is optional, the engine will use the |
| - * implementation created by `CreateDefaultFileSystem()` by |
| - * default, which might be sufficient. |
| - * @param The `FileSystem` instance to use. |
| - */ |
| - void SetFileSystem(const FileSystemSyncPtr& val); |
| - |
| - /** |
| - * Sets the `WebRequest` implementation used for XMLHttpRequests. |
| - * Setting this is optional, the engine will use a `DefaultWebRequest` |
| - * instance by default, which might be sufficient. |
| - * @param The `WebRequest` instance to use. |
| - */ |
| - void SetWebRequest(const WebRequestSharedPtr& val); |
| - |
| - /** |
| - * @see `SetLogSystem()`. |
| - */ |
| - LogSystemPtr GetLogSystem() const; |
| - |
| - /** |
| - * Sets the `LogSystem` implementation used for logging (e.g. to handle |
| - * `console.log()` calls from JavaScript). |
| - * Setting this is optional, the engine will use a `DefaultLogSystem` |
| - * instance by default, which might be sufficient. |
| - * @param The `LogSystem` instance to use. |
| - */ |
| - void SetLogSystem(const LogSystemPtr& val); |
| - |
| - /** |
| * Sets a global property that can be accessed by all the scripts. |
| * @param name Name of the property to set. |
| * @param value Value of the property to set. |
| @@ -318,27 +264,31 @@ namespace AdblockPlus |
| * garbage collection. |
| */ |
| void NotifyLowMemory(); |
| + |
| + /** |
| + * Private functionality. |
| + */ |
| + Platform& GetPlatform() |
| + { |
| + return platform; |
| + } |
| private: |
| void CallTimerTask(const JsWeakValuesID& timerParamsID); |
| - explicit JsEngine(TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest); |
| + explicit JsEngine(Platform& platform); |
| JsValue GetGlobalObject(); |
| /// Isolate must be disposed only after disposing of all objects which are |
| /// using it. |
| ScopedV8Isolate isolate; |
| + Platform& platform; |
| - FileSystemPtr fileSystem; |
| - LogSystemPtr logSystem; |
| std::unique_ptr<v8::Global<v8::Context>> context; |
| EventMap eventCallbacks; |
| std::mutex eventCallbacksMutex; |
| JsWeakValuesLists jsWeakValuesLists; |
| std::mutex jsWeakValuesListsMutex; |
| - TimerPtr timer; |
| - WebRequestPtr webRequest; |
| - WebRequestSharedPtr webRequestLegacy; |
| }; |
| } |