| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 <map> | 18 #include <map> |
| 19 #include <AdblockPlus/JsValue.h> | 19 #include <AdblockPlus/JsValue.h> |
| 20 #include <AdblockPlus/WebRequest.h> | 20 #include <AdblockPlus/WebRequest.h> |
| 21 | 21 |
| 22 #include "JsContext.h" | 22 #include "JsContext.h" |
| 23 #include "Thread.h" | 23 #include "Thread.h" |
| 24 #include "Utils.h" |
| 24 #include "WebRequestJsObject.h" | 25 #include "WebRequestJsObject.h" |
| 25 | 26 |
| 26 namespace | 27 namespace |
| 27 { | 28 { |
| 28 class WebRequestThread : public AdblockPlus::Thread | 29 class WebRequestThread : public AdblockPlus::Thread |
| 29 { | 30 { |
| 30 public: | 31 public: |
| 31 WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList
& arguments) | 32 WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList
& arguments) |
| 32 : jsEngine(jsEngine), url(arguments[0]->AsString()) | 33 : jsEngine(jsEngine), url(arguments[0]->AsString()) |
| 33 { | 34 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 84 private: |
| 84 AdblockPlus::JsEnginePtr jsEngine; | 85 AdblockPlus::JsEnginePtr jsEngine; |
| 85 std::string url; | 86 std::string url; |
| 86 AdblockPlus::HeaderList headers; | 87 AdblockPlus::HeaderList headers; |
| 87 AdblockPlus::JsValuePtr callback; | 88 AdblockPlus::JsValuePtr callback; |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) | 91 v8::Handle<v8::Value> GETCallback(const v8::Arguments& arguments) |
| 91 { | 92 { |
| 92 WebRequestThread* thread; | 93 WebRequestThread* thread; |
| 94 |
| 95 v8::Isolate* isolate = arguments.GetIsolate(); |
| 93 try | 96 try |
| 94 { | 97 { |
| 95 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(a
rguments); | 98 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(a
rguments); |
| 96 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments)
; | 99 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments)
; |
| 97 if (converted.size() != 3u) | 100 if (converted.size() != 3u) |
| 98 throw std::runtime_error("GET requires exactly 3 arguments"); | 101 throw std::runtime_error("GET requires exactly 3 arguments"); |
| 99 thread = new WebRequestThread(jsEngine, converted); | 102 thread = new WebRequestThread(jsEngine, converted); |
| 100 } | 103 } |
| 101 catch (const std::exception& e) | 104 catch (const std::exception& e) |
| 102 { | 105 { |
| 103 return v8::ThrowException(v8::String::New(e.what())); | 106 using AdblockPlus::Utils::ToV8String; |
| 107 return v8::ThrowException(ToV8String(isolate, e.what())); |
| 104 } | 108 } |
| 105 thread->Start(); | 109 thread->Start(); |
| 106 return v8::Undefined(); | 110 return v8::Undefined(); |
| 107 } | 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( | 114 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( |
| 111 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) | 115 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) |
| 112 { | 116 { |
| 113 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); | 117 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); |
| 114 return obj; | 118 return obj; |
| 115 } | 119 } |
| OLD | NEW |