| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 }; | 65 }; |
| 66 } | 66 } |
| 67 | 67 |
| 68 using namespace AdblockPlus; | 68 using namespace AdblockPlus; |
| 69 | 69 |
| 70 TimerPtr AdblockPlus::CreateDefaultTimer() | 70 TimerPtr AdblockPlus::CreateDefaultTimer() |
| 71 { | 71 { |
| 72 return TimerPtr(new DefaultTimer()); | 72 return TimerPtr(new DefaultTimer()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() |
| 76 { |
| 77 return WebRequestPtr(new DefaultWebRequest(std::make_shared<DefaultWebRequestS
ync>())); |
| 78 } |
| 79 |
| 75 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() | 80 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
| 76 { | 81 { |
| 77 V8Initializer::Init(); | 82 V8Initializer::Init(); |
| 78 isolate = v8::Isolate::New(); | 83 isolate = v8::Isolate::New(); |
| 79 } | 84 } |
| 80 | 85 |
| 81 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() | 86 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() |
| 82 { | 87 { |
| 83 isolate->Dispose(); | 88 isolate->Dispose(); |
| 84 isolate = nullptr; | 89 isolate = nullptr; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 113 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) | 118 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) |
| 114 { | 119 { |
| 115 auto timerParams = TakeJsValues(timerParamsID); | 120 auto timerParams = TakeJsValues(timerParamsID); |
| 116 JsValue callback = std::move(timerParams[0]); | 121 JsValue callback = std::move(timerParams[0]); |
| 117 | 122 |
| 118 timerParams.erase(timerParams.begin()); // remove callback placeholder | 123 timerParams.erase(timerParams.begin()); // remove callback placeholder |
| 119 timerParams.erase(timerParams.begin()); // remove timeout param | 124 timerParams.erase(timerParams.begin()); // remove timeout param |
| 120 callback.Call(timerParams); | 125 callback.Call(timerParams); |
| 121 } | 126 } |
| 122 | 127 |
| 123 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr time
r) | 128 AdblockPlus::JsEngine::JsEngine(const ScopedV8IsolatePtr& isolate, |
| 129 TimerPtr timer, WebRequestPtr webRequest) |
| 124 : isolate(isolate) | 130 : isolate(isolate) |
| 125 , fileSystem(new DefaultFileSystem()) | 131 , fileSystem(new DefaultFileSystem()) |
| 126 , webRequest(new DefaultWebRequest()) | |
| 127 , logSystem(new DefaultLogSystem()) | 132 , logSystem(new DefaultLogSystem()) |
| 128 , timer(std::move(timer)) | 133 , timer(std::move(timer)) |
| 134 , webRequest(std::move(webRequest)) |
| 129 { | 135 { |
| 130 } | 136 } |
| 131 | 137 |
| 132 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, | 138 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, |
| 133 TimerPtr timer, | 139 TimerPtr timer, WebRequestPtr webRequest, |
| 134 const ScopedV8IsolatePtr& isolate) | 140 const ScopedV8IsolatePtr& isolate) |
| 135 { | 141 { |
| 136 JsEnginePtr result(new JsEngine(isolate, std::move(timer))); | 142 JsEnginePtr result(new JsEngine(isolate, std::move(timer), std::move(webReques
t))); |
| 137 | 143 |
| 138 const v8::Locker locker(result->GetIsolate()); | 144 const v8::Locker locker(result->GetIsolate()); |
| 139 const v8::Isolate::Scope isolateScope(result->GetIsolate()); | 145 const v8::Isolate::Scope isolateScope(result->GetIsolate()); |
| 140 const v8::HandleScope handleScope(result->GetIsolate()); | 146 const v8::HandleScope handleScope(result->GetIsolate()); |
| 141 | 147 |
| 142 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), | 148 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), |
| 143 v8::Context::New(result->GetIsolate()))); | 149 v8::Context::New(result->GetIsolate()))); |
| 144 auto global = result->GetGlobalObject(); | 150 auto global = result->GetGlobalObject(); |
| 145 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); | 151 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); |
| 146 return result; | 152 return result; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 308 } |
| 303 | 309 |
| 304 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemPtr& val) | 310 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemPtr& val) |
| 305 { | 311 { |
| 306 if (!val) | 312 if (!val) |
| 307 throw std::runtime_error("FileSystem cannot be null"); | 313 throw std::runtime_error("FileSystem cannot be null"); |
| 308 | 314 |
| 309 fileSystem = val; | 315 fileSystem = val; |
| 310 } | 316 } |
| 311 | 317 |
| 312 WebRequestSharedPtr AdblockPlus::JsEngine::GetWebRequest() const | |
| 313 { | |
| 314 return webRequest; | |
| 315 } | |
| 316 | |
| 317 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr
& val) | 318 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr
& val) |
| 318 { | 319 { |
| 319 if (!val) | 320 if (!val) |
| 320 throw std::runtime_error("WebRequest cannot be null"); | 321 throw std::runtime_error("WebRequest cannot be null"); |
| 321 | 322 |
| 322 webRequest = val; | 323 webRequestLegacy = val; |
| 323 } | 324 } |
| 324 | 325 |
| 325 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const | 326 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const |
| 326 { | 327 { |
| 327 return logSystem; | 328 return logSystem; |
| 328 } | 329 } |
| 329 | 330 |
| 330 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) | 331 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) |
| 331 { | 332 { |
| 332 if (!val) | 333 if (!val) |
| 333 throw std::runtime_error("LogSystem cannot be null"); | 334 throw std::runtime_error("LogSystem cannot be null"); |
| 334 | 335 |
| 335 logSystem = val; | 336 logSystem = val; |
| 336 } | 337 } |
| 337 | 338 |
| 338 | 339 |
| 339 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 340 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 340 const AdblockPlus::JsValue& value) | 341 const AdblockPlus::JsValue& value) |
| 341 { | 342 { |
| 342 auto global = GetGlobalObject(); | 343 auto global = GetGlobalObject(); |
| 343 global.SetProperty(name, value); | 344 global.SetProperty(name, value); |
| 344 } | 345 } |
| OLD | NEW |