| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include <vector> | 18 #include <vector> |
| 19 #include <stdexcept> | 19 #include <stdexcept> |
| 20 | 20 |
| 21 #include <AdblockPlus/JsValue.h> | 21 #include <AdblockPlus/JsValue.h> |
| 22 | 22 |
| 23 #include "AppInfoJsObject.h" | 23 #include "AppInfoJsObject.h" |
| 24 #include "ConsoleJsObject.h" | 24 #include "ConsoleJsObject.h" |
| 25 #include "FileSystemJsObject.h" | 25 #include "FileSystemJsObject.h" |
| 26 #include "GlobalJsObject.h" | 26 #include "GlobalJsObject.h" |
| 27 #include "ConsoleJsObject.h" | 27 #include "ConsoleJsObject.h" |
| 28 #include "WebRequestJsObject.h" | 28 #include "WebRequestJsObject.h" |
| 29 #include "Thread.h" | 29 #include "Thread.h" |
| 30 #include "Utils.h" |
| 30 | 31 |
| 31 using namespace AdblockPlus; | 32 using namespace AdblockPlus; |
| 32 | 33 |
| 33 namespace | 34 namespace |
| 34 { | 35 { |
| 35 class TimeoutThread : public Thread | 36 class TimeoutThread : public Thread |
| 36 { | 37 { |
| 37 public: | 38 public: |
| 38 TimeoutThread(JsValueList& arguments) | 39 TimeoutThread(JsValueList& arguments) |
| 39 { | 40 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 TimeoutThread* timeoutThread; | 69 TimeoutThread* timeoutThread; |
| 69 try | 70 try |
| 70 { | 71 { |
| 71 AdblockPlus::JsValueList converted = | 72 AdblockPlus::JsValueList converted = |
| 72 AdblockPlus::JsEngine::FromArguments(arguments) | 73 AdblockPlus::JsEngine::FromArguments(arguments) |
| 73 ->ConvertArguments(arguments); | 74 ->ConvertArguments(arguments); |
| 74 timeoutThread = new TimeoutThread(converted); | 75 timeoutThread = new TimeoutThread(converted); |
| 75 } | 76 } |
| 76 catch (const std::exception& e) | 77 catch (const std::exception& e) |
| 77 { | 78 { |
| 78 return v8::ThrowException(v8::String::New(e.what())); | 79 v8::Isolate* isolate = arguments.GetIsolate(); |
| 80 return v8::ThrowException(Utils::ToV8String(isolate, e.what())); |
| 79 } | 81 } |
| 80 timeoutThread->Start(); | 82 timeoutThread->Start(); |
| 81 | 83 |
| 82 // We should actually return the timer ID here, which could be | 84 // We should actually return the timer ID here, which could be |
| 83 // used via clearTimeout(). But since we don't seem to need | 85 // used via clearTimeout(). But since we don't seem to need |
| 84 // clearTimeout(), we can save that for later. | 86 // clearTimeout(), we can save that for later. |
| 85 return v8::Undefined(); | 87 return v8::Undefined(); |
| 86 } | 88 } |
| 87 | 89 |
| 88 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) | 90 v8::Handle<v8::Value> TriggerEventCallback(const v8::Arguments& arguments) |
| 89 { | 91 { |
| 90 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); | 92 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(arg
uments); |
| 91 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); | 93 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); |
| 92 if (converted.size() < 1) | 94 if (converted.size() < 1) |
| 93 return v8::ThrowException(v8::String::New("_triggerEvent expects at least
one parameter")); | 95 { |
| 94 | 96 v8::Isolate* isolate = arguments.GetIsolate(); |
| 97 return v8::ThrowException(Utils::ToV8String(isolate, |
| 98 "_triggerEvent expects at least one parameter")); |
| 99 } |
| 95 std::string eventName = converted.front()->AsString(); | 100 std::string eventName = converted.front()->AsString(); |
| 96 converted.erase(converted.begin()); | 101 converted.erase(converted.begin()); |
| 97 jsEngine->TriggerEvent(eventName, converted); | 102 jsEngine->TriggerEvent(eventName, converted); |
| 98 return v8::Undefined(); | 103 return v8::Undefined(); |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, | 107 JsValuePtr GlobalJsObject::Setup(JsEnginePtr jsEngine, const AppInfo& appInfo, |
| 103 JsValuePtr obj) | 108 JsValuePtr obj) |
| 104 { | 109 { |
| 105 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); | 110 obj->SetProperty("setTimeout", jsEngine->NewCallback(::SetTimeoutCallback)); |
| 106 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback
)); | 111 obj->SetProperty("_triggerEvent", jsEngine->NewCallback(::TriggerEventCallback
)); |
| 107 obj->SetProperty("_fileSystem", | 112 obj->SetProperty("_fileSystem", |
| 108 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); | 113 FileSystemJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 109 obj->SetProperty("_webRequest", | 114 obj->SetProperty("_webRequest", |
| 110 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); | 115 WebRequestJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 111 obj->SetProperty("console", | 116 obj->SetProperty("console", |
| 112 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); | 117 ConsoleJsObject::Setup(jsEngine, jsEngine->NewObject())); |
| 113 obj->SetProperty("_appInfo", | 118 obj->SetProperty("_appInfo", |
| 114 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); | 119 AppInfoJsObject::Setup(jsEngine, appInfo, jsEngine->NewObject())); |
| 115 return obj; | 120 return obj; |
| 116 } | 121 } |
| OLD | NEW |