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