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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 | 222 |
223 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val) | 223 void AdblockPlus::JsEngine::SetWebRequest(AdblockPlus::WebRequestPtr val) |
224 { | 224 { |
225 if (!val) | 225 if (!val) |
226 throw std::runtime_error("WebRequest cannot be null"); | 226 throw std::runtime_error("WebRequest cannot be null"); |
227 | 227 |
228 webRequest = val; | 228 webRequest = val; |
229 } | 229 } |
230 | 230 |
| 231 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll
owedCallback& callback) |
| 232 { |
| 233 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex); |
| 234 isConnectionAllowed = callback; |
| 235 } |
| 236 |
| 237 bool AdblockPlus::JsEngine::IsConnectionAllowed() |
| 238 { |
| 239 // The call of isConnectionAllowed can be very expensive and it makes a |
| 240 // little sense to block execution of JavaScript for it. Currently this |
| 241 // method is called from a thread of web request, so let only this thread be |
| 242 // blocked by the call of the callback. |
| 243 IsConnectionAllowedCallback localCopy; |
| 244 { |
| 245 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex); |
| 246 localCopy = isConnectionAllowed; |
| 247 } |
| 248 return !localCopy || localCopy(); |
| 249 } |
| 250 |
231 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() | 251 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() |
232 { | 252 { |
233 if (!logSystem) | 253 if (!logSystem) |
234 logSystem.reset(new DefaultLogSystem()); | 254 logSystem.reset(new DefaultLogSystem()); |
235 return logSystem; | 255 return logSystem; |
236 } | 256 } |
237 | 257 |
238 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) | 258 void AdblockPlus::JsEngine::SetLogSystem(AdblockPlus::LogSystemPtr val) |
239 { | 259 { |
240 if (!val) | 260 if (!val) |
241 throw std::runtime_error("LogSystem cannot be null"); | 261 throw std::runtime_error("LogSystem cannot be null"); |
242 | 262 |
243 logSystem = val; | 263 logSystem = val; |
244 } | 264 } |
245 | 265 |
246 | 266 |
247 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, | 267 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, |
248 AdblockPlus::JsValuePtr value) | 268 AdblockPlus::JsValuePtr value) |
249 { | 269 { |
250 auto global = GetGlobalObject(); | 270 auto global = GetGlobalObject(); |
251 if (!global) | 271 if (!global) |
252 throw std::runtime_error("Global object cannot be null"); | 272 throw std::runtime_error("Global object cannot be null"); |
253 global->SetProperty(name, value); | 273 global->SetProperty(name, value); |
254 } | 274 } |
OLD | NEW |