| 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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 |
| 22 #include "JsContext.h" |
| 23 #include "Thread.h" |
| 21 #include "WebRequestJsObject.h" | 24 #include "WebRequestJsObject.h" |
| 22 #include "Thread.h" | |
| 23 | 25 |
| 24 namespace | 26 namespace |
| 25 { | 27 { |
| 26 class WebRequestThread : public AdblockPlus::Thread | 28 class WebRequestThread : public AdblockPlus::Thread |
| 27 { | 29 { |
| 28 public: | 30 public: |
| 29 WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList
& arguments) | 31 WebRequestThread(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList
& arguments) |
| 30 : jsEngine(jsEngine), url(arguments[0]->AsString()) | 32 : jsEngine(jsEngine), url(arguments[0]->AsString()) |
| 31 { | 33 { |
| 32 if (!url.length()) | 34 if (!url.length()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 | 52 |
| 51 callback = arguments[2]; | 53 callback = arguments[2]; |
| 52 if (!callback->IsFunction()) | 54 if (!callback->IsFunction()) |
| 53 throw std::runtime_error("Third argument to GET must be a function"); | 55 throw std::runtime_error("Third argument to GET must be a function"); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void Run() | 58 void Run() |
| 57 { | 59 { |
| 58 AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, h
eaders); | 60 AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, h
eaders); |
| 59 | 61 |
| 60 AdblockPlus::JsEngine::Context context(jsEngine); | 62 AdblockPlus::JsContext context(jsEngine); |
| 61 | 63 |
| 62 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); | 64 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); |
| 63 resultObject->SetProperty("status", result.status); | 65 resultObject->SetProperty("status", result.status); |
| 64 resultObject->SetProperty("responseStatus", result.responseStatus); | 66 resultObject->SetProperty("responseStatus", result.responseStatus); |
| 65 resultObject->SetProperty("responseText", result.responseText); | 67 resultObject->SetProperty("responseText", result.responseText); |
| 66 | 68 |
| 67 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); | 69 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); |
| 68 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin()
; | 70 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin()
; |
| 69 it != result.responseHeaders.end(); ++it) | 71 it != result.responseHeaders.end(); ++it) |
| 70 { | 72 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 return v8::Undefined(); | 106 return v8::Undefined(); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( | 110 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( |
| 109 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) | 111 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) |
| 110 { | 112 { |
| 111 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); | 113 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); |
| 112 return obj; | 114 return obj; |
| 113 } | 115 } |
| OLD | NEW |