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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 FileSystemPtr AdblockPlus::CreateDefaultFileSystem() | 82 FileSystemPtr AdblockPlus::CreateDefaultFileSystem() |
83 { | 83 { |
84 return FileSystemPtr(new DefaultFileSystem(std::make_shared<DefaultFileSystemS
ync>())); | 84 return FileSystemPtr(new DefaultFileSystem(std::make_shared<DefaultFileSystemS
ync>())); |
85 } | 85 } |
86 | 86 |
87 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() | 87 WebRequestPtr AdblockPlus::CreateDefaultWebRequest() |
88 { | 88 { |
89 return WebRequestPtr(new DefaultWebRequest(std::unique_ptr<DefaultWebRequestSy
nc>(new DefaultWebRequestSync()))); | 89 return WebRequestPtr(new DefaultWebRequest(std::unique_ptr<DefaultWebRequestSy
nc>(new DefaultWebRequestSync()))); |
90 } | 90 } |
91 | 91 |
| 92 LogSystemPtr AdblockPlus::CreateDefaultLogSystem() |
| 93 { |
| 94 return LogSystemPtr(new DefaultLogSystem()); |
| 95 } |
| 96 |
92 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() | 97 AdblockPlus::ScopedV8Isolate::ScopedV8Isolate() |
93 { | 98 { |
94 V8Initializer::Init(); | 99 V8Initializer::Init(); |
95 v8::Isolate::CreateParams isolateParams; | 100 v8::Isolate::CreateParams isolateParams; |
96 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultA
llocator(); | 101 isolateParams.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultA
llocator(); |
97 isolate = v8::Isolate::New(isolateParams); | 102 isolate = v8::Isolate::New(isolateParams); |
98 } | 103 } |
99 | 104 |
100 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() | 105 AdblockPlus::ScopedV8Isolate::~ScopedV8Isolate() |
101 { | 106 { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 { | 142 { |
138 auto timerParams = TakeJsValues(timerParamsID); | 143 auto timerParams = TakeJsValues(timerParamsID); |
139 JsValue callback = std::move(timerParams[0]); | 144 JsValue callback = std::move(timerParams[0]); |
140 | 145 |
141 timerParams.erase(timerParams.begin()); // remove callback placeholder | 146 timerParams.erase(timerParams.begin()); // remove callback placeholder |
142 timerParams.erase(timerParams.begin()); // remove timeout param | 147 timerParams.erase(timerParams.begin()); // remove timeout param |
143 callback.Call(timerParams); | 148 callback.Call(timerParams); |
144 } | 149 } |
145 | 150 |
146 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, FileSystemPtr fileSystem, | 151 AdblockPlus::JsEngine::JsEngine(TimerPtr timer, FileSystemPtr fileSystem, |
147 WebRequestPtr webRequest) | 152 WebRequestPtr webRequest, LogSystemPtr logSystem) |
148 : fileSystem(std::move(fileSystem)) | 153 : fileSystem(std::move(fileSystem)) |
149 , logSystem(new DefaultLogSystem()) | |
150 , timer(std::move(timer)) | 154 , timer(std::move(timer)) |
151 , webRequest(std::move(webRequest)) | 155 , webRequest(std::move(webRequest)) |
| 156 , logSystem(std::move(logSystem)) |
152 { | 157 { |
153 } | 158 } |
154 | 159 |
155 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, | 160 AdblockPlus::JsEnginePtr AdblockPlus::JsEngine::New(const AppInfo& appInfo, |
156 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest) | 161 TimerPtr timer, FileSystemPtr fileSystem, WebRequestPtr webRequest, LogSystemP
tr logSystem) |
157 { | 162 { |
158 JsEnginePtr result(new JsEngine(std::move(timer), | 163 JsEnginePtr result(new JsEngine(std::move(timer), |
159 std::move(fileSystem), | 164 std::move(fileSystem), |
160 std::move(webRequest))); | 165 std::move(webRequest), |
| 166 std::move(logSystem))); |
161 | 167 |
162 const v8::Locker locker(result->GetIsolate()); | 168 const v8::Locker locker(result->GetIsolate()); |
163 const v8::Isolate::Scope isolateScope(result->GetIsolate()); | 169 const v8::Isolate::Scope isolateScope(result->GetIsolate()); |
164 const v8::HandleScope handleScope(result->GetIsolate()); | 170 const v8::HandleScope handleScope(result->GetIsolate()); |
165 | 171 |
166 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(), | 172 result->context.reset(new v8::Global<v8::Context>(result->GetIsolate(), |
167 v8::Context::New(result->GetIsolate()))); | 173 v8::Context::New(result->GetIsolate()))); |
168 auto global = result->GetGlobalObject(); | 174 auto global = result->GetGlobalObject(); |
169 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); | 175 AdblockPlus::GlobalJsObject::Setup(*result, appInfo, global); |
170 return result; | 176 return result; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 332 } |
327 | 333 |
328 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemSyncPtr&
val) | 334 void AdblockPlus::JsEngine::SetFileSystem(const AdblockPlus::FileSystemSyncPtr&
val) |
329 { | 335 { |
330 if (!val) | 336 if (!val) |
331 throw std::runtime_error("FileSystem cannot be null"); | 337 throw std::runtime_error("FileSystem cannot be null"); |
332 | 338 |
333 fileSystem.reset(new DefaultFileSystem(val)); | 339 fileSystem.reset(new DefaultFileSystem(val)); |
334 } | 340 } |
335 | 341 |
336 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const | 342 AdblockPlus::LogSystem& AdblockPlus::JsEngine::GetLogSystem() |
337 { | 343 { |
338 return logSystem; | 344 return *logSystem; |
339 } | 345 } |
340 | 346 |
341 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) | |
342 { | |
343 if (!val) | |
344 throw std::runtime_error("LogSystem cannot be null"); | |
345 | |
346 logSystem = val; | |
347 } | |
348 | |
349 | |
350 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 347 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
351 const AdblockPlus::JsValue& value) | 348 const AdblockPlus::JsValue& value) |
352 { | 349 { |
353 auto global = GetGlobalObject(); | 350 auto global = GetGlobalObject(); |
354 global.SetProperty(name, value); | 351 global.SetProperty(name, value); |
355 } | 352 } |
OLD | NEW |