| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 if (header.length() && headerValue.length()) | 49 if (header.length() && headerValue.length()) |
| 50 headers.push_back(std::pair<std::string, std::string>(header, header
Value)); | 50 headers.push_back(std::pair<std::string, std::string>(header, header
Value)); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 callback = arguments[2]; | 54 callback = arguments[2]; |
| 55 if (!callback->IsFunction()) | 55 if (!callback->IsFunction()) |
| 56 throw std::runtime_error("Third argument to GET must be a function"); | 56 throw std::runtime_error("Third argument to GET must be a function"); |
| 57 } | 57 } |
| 58 | 58 |
| 59 AdblockPlus::ServerResponse NotAllowedResponse() |
| 60 { |
| 61 AdblockPlus::ServerResponse result; |
| 62 result.status = AdblockPlus::WebRequest::NS_ERROR_CONNECTION_REFUSED; |
| 63 result.responseStatus = 0; |
| 64 return result; |
| 65 } |
| 66 |
| 59 void Run() | 67 void Run() |
| 60 { | 68 { |
| 61 AdblockPlus::ServerResponse result = jsEngine->GetWebRequest()->GET(url, h
eaders); | 69 AdblockPlus::ServerResponse result = jsEngine->IsConnectionAllowed() ? |
| 70 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse(); |
| 62 | 71 |
| 63 AdblockPlus::JsContext context(jsEngine); | 72 AdblockPlus::JsContext context(jsEngine); |
| 64 | 73 |
| 65 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); | 74 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); |
| 66 resultObject->SetProperty("status", result.status); | 75 resultObject->SetProperty("status", result.status); |
| 67 resultObject->SetProperty("responseStatus", result.responseStatus); | 76 resultObject->SetProperty("responseStatus", result.responseStatus); |
| 68 resultObject->SetProperty("responseText", result.responseText); | 77 resultObject->SetProperty("responseText", result.responseText); |
| 69 | 78 |
| 70 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); | 79 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); |
| 71 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin()
; | 80 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin()
; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return v8::Undefined(); | 117 return v8::Undefined(); |
| 109 } | 118 } |
| 110 } | 119 } |
| 111 | 120 |
| 112 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( | 121 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( |
| 113 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) | 122 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) |
| 114 { | 123 { |
| 115 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); | 124 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); |
| 116 return obj; | 125 return obj; |
| 117 } | 126 } |
| OLD | NEW |