Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/JsEngine.cpp

Issue 29424786: Issue 5182 - fix IsConnectionAllowed (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 28, 2017, 2:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/WebRequestJsObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 316
317 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestPtr& val) 317 void AdblockPlus::JsEngine::SetWebRequest(const AdblockPlus::WebRequestPtr& val)
318 { 318 {
319 if (!val) 319 if (!val)
320 throw std::runtime_error("WebRequest cannot be null"); 320 throw std::runtime_error("WebRequest cannot be null");
321 321
322 webRequest = val; 322 webRequest = val;
323 } 323 }
324 324
325 void AdblockPlus::JsEngine::SetIsConnectionAllowedCallback(const IsConnectionAll owedCallback& callback)
326 {
327 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
328 isConnectionAllowed = callback;
329 }
330
331 bool AdblockPlus::JsEngine::IsConnectionAllowed() const
332 {
333 // The call of isConnectionAllowed can be very expensive and it makes a
334 // little sense to block execution of JavaScript for it. Currently this
335 // method is called from a thread of web request, so let only this thread be
336 // blocked by the call of the callback.
337 IsConnectionAllowedCallback localCopy;
338 {
339 std::lock_guard<std::mutex> lock(isConnectionAllowedMutex);
340 localCopy = isConnectionAllowed;
341 }
342 return !localCopy || localCopy();
343 }
344
345 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const 325 AdblockPlus::LogSystemPtr AdblockPlus::JsEngine::GetLogSystem() const
346 { 326 {
347 return logSystem; 327 return logSystem;
348 } 328 }
349 329
350 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val) 330 void AdblockPlus::JsEngine::SetLogSystem(const AdblockPlus::LogSystemPtr& val)
351 { 331 {
352 if (!val) 332 if (!val)
353 throw std::runtime_error("LogSystem cannot be null"); 333 throw std::runtime_error("LogSystem cannot be null");
354 334
355 logSystem = val; 335 logSystem = val;
356 } 336 }
357 337
358 338
359 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name, 339 void AdblockPlus::JsEngine::SetGlobalProperty(const std::string& name,
360 const AdblockPlus::JsValue& value) 340 const AdblockPlus::JsValue& value)
361 { 341 {
362 auto global = GetGlobalObject(); 342 auto global = GetGlobalObject();
363 global.SetProperty(name, value); 343 global.SetProperty(name, value);
364 } 344 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | src/WebRequestJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld