| 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 FileSystemPtr AdblockPlus::CreateDefaultFileSystem() |
| 76 { |
| 77 return FileSystemPtr(new DefaultFileSystem(std::make_shared<DefaultFileSystemS
ync>())); |
| 78 } |
| 79 |
| 75 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() | 80 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() |
| 76 { | 81 { |
| 77 return WebRequestPtr(new DefaultWebRequest(std::make_shared<DefaultWebRequestS
ync>())); | 82 return WebRequestPtr(new DefaultWebRequest(std::make_shared<DefaultWebRequestS
ync>())); |
| 78 } | 83 } |
| 79 | 84 |
| 80 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() | 85 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
| 81 { | 86 { |
| 82 V8Initializer::Init(); | 87 V8Initializer::Init(); |
| 83 isolate = v8::Isolate::New(); | 88 isolate = v8::Isolate::New(); |
| 84 } | 89 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) | 129 void JsEngine::CallTimerTask(const JsWeakValuesID& timerParamsID) |
| 125 { | 130 { |
| 126 auto timerParams = TakeJsValues(timerParamsID); | 131 auto timerParams = TakeJsValues(timerParamsID); |
| 127 JsValue callback = std::move(timerParams[0]); | 132 JsValue callback = std::move(timerParams[0]); |
| 128 | 133 |
| 129 timerParams.erase(timerParams.begin()); // remove callback placeholder | 134 timerParams.erase(timerParams.begin()); // remove callback placeholder |
| 130 timerParams.erase(timerParams.begin()); // remove timeout param | 135 timerParams.erase(timerParams.begin()); // remove timeout param |
| 131 callback.Call(timerParams); | 136 callback.Call(timerParams); |
| 132 } | 137 } |
| 133 | 138 |
| 134 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, WebRequestPtr webRequest) | 139 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, FileSystemPtr fileSystem, |
| 135 : fileSystem(new DefaultFileSystem()) | 140 WebRequestPtr webRequest) |
| 141 : fileSystem(std::move(fileSystem)) |
| 136 , logSystem(new DefaultLogSystem()) | 142 , logSystem(new DefaultLogSystem()) |
| 137 , timer(std::move(timer)) | 143 , timer(std::move(timer)) |
| 138 , webRequest(std::move(webRequest)) | 144 , webRequest(std::move(webRequest)) |
| 139 { | 145 { |
| 140 } | 146 } |
| 141 | 147 |
| 142 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, | 148 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, |
| 143 TimerPtr timer, WebRequestPtr webRequest) | 149 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest) |
| 144 { | 150 { |
| 145 JsEnginePtr result(new JsEngine(std::move(timer), std::move(webRequest))); | 151 JsEnginePtr result(new JsEngine(std::move(timer), |
| 152 std::move(fileSystem), |
| 153 std::move(webRequest))); |
| 146 | 154 |
| 147 const v8::Locker locker(result->GetIsolate()); | 155 const v8::Locker locker(result->GetIsolate()); |
| 148 const v8::Isolate::Scope isolateScope(result->GetIsolate()); | 156 const v8::Isolate::Scope isolateScope(result->GetIsolate()); |
| 149 const v8::HandleScope handleScope(result->GetIsolate()); | 157 const v8::HandleScope handleScope(result->GetIsolate()); |
| 150 | 158 |
| 151 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), | 159 result->context.reset(new v8::Persistent<v8::Context>(result->GetIsolate(), |
| 152 v8::Context::New(result->GetIsolate()))); | 160 v8::Context::New(result->GetIsolate()))); |
| 153 auto global = result->GetGlobalObject(); | 161 auto global = result->GetGlobalObject(); |
| 154 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); | 162 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); |
| 155 return result; | 163 return result; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 for (int i = 0; i < arguments.Length(); i++) | 311 for (int i = 0; i < arguments.Length(); i++) |
| 304 list.push_back(JsValue(shared_from_this(), arguments[i])); | 312 list.push_back(JsValue(shared_from_this(), arguments[i])); |
| 305 return list; | 313 return list; |
| 306 } | 314 } |
| 307 | 315 |
| 308 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const | 316 AdblockPlus::FileSystemPtr AdblockPlus::JsEngine::GetFileSystem() const |
| 309 { | 317 { |
| 310 return fileSystem; | 318 return fileSystem; |
| 311 } | 319 } |
| 312 | 320 |
| 313 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemPtr& val) | |
| 314 { | |
| 315 if (!val) | |
| 316 throw std::runtime_error("FileSystem cannot be null"); | |
| 317 | |
| 318 fileSystem = val; | |
| 319 } | |
| 320 | |
| 321 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr
& val) | 321 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestSharedPtr
& val) |
| 322 { | 322 { |
| 323 if (!val) | 323 if (!val) |
| 324 throw std::runtime_error("WebRequest cannot be null"); | 324 throw std::runtime_error("WebRequest cannot be null"); |
| 325 | 325 |
| 326 webRequestLegacy = val; | 326 webRequestLegacy = val; |
| 327 } | 327 } |
| 328 | 328 |
| 329 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const | 329 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const |
| 330 { | 330 { |
| 331 return logSystem; | 331 return logSystem; |
| 332 } | 332 } |
| 333 | 333 |
| 334 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) | 334 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) |
| 335 { | 335 { |
| 336 if (!val) | 336 if (!val) |
| 337 throw std::runtime_error("LogSystem cannot be null"); | 337 throw std::runtime_error("LogSystem cannot be null"); |
| 338 | 338 |
| 339 logSystem = val; | 339 logSystem = val; |
| 340 } | 340 } |
| 341 | 341 |
| 342 | 342 |
| 343 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 343 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
| 344 const AdblockPlus::JsValue& value) | 344 const AdblockPlus::JsValue& value) |
| 345 { | 345 { |
| 346 auto global = GetGlobalObject(); | 346 auto global = GetGlobalObject(); |
| 347 global.SetProperty(name, value); | 347 global.SetProperty(name, value); |
| 348 } | 348 } |
| OLD | NEW |