Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-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 |
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 * |
(...skipping 20 matching lines...) Expand all Loading... | |
34 { | 34 { |
35 if (!url.length()) | 35 if (!url.length()) |
36 throw std::runtime_error("Invalid string passed as first argument to GET "); | 36 throw std::runtime_error("Invalid string passed as first argument to GET "); |
37 | 37 |
38 { | 38 { |
39 AdblockPlus::JsValuePtr headersObj = arguments[1]; | 39 AdblockPlus::JsValuePtr headersObj = arguments[1]; |
40 if (!headersObj->IsObject()) | 40 if (!headersObj->IsObject()) |
41 throw std::runtime_error("Second argument to GET must be an object"); | 41 throw std::runtime_error("Second argument to GET must be an object"); |
42 | 42 |
43 std::vector<std::string> properties = headersObj->GetOwnPropertyNames(); | 43 std::vector<std::string> properties = headersObj->GetOwnPropertyNames(); |
44 for (auto it = properties.cbegin(); it != properties.cend(); ++it) | 44 for (const auto& header : properties) |
45 { | 45 { |
46 const std::string & header = *it; | |
sergei
2017/03/22 15:44:00
please no space before & here
hub
2017/03/22 18:16:59
This is gone as I now use the range iterator.
And
| |
47 std::string headerValue = headersObj->GetProperty(header)->AsString(); | 46 std::string headerValue = headersObj->GetProperty(header)->AsString(); |
48 if (header.length() && headerValue.length()) | 47 if (header.length() && headerValue.length()) |
49 headers.push_back(std::pair<std::string, std::string>(header, header Value)); | 48 headers.push_back(std::pair<std::string, std::string>(header, header Value)); |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
53 callback = arguments[2]; | 52 callback = arguments[2]; |
54 if (!callback->IsFunction()) | 53 if (!callback->IsFunction()) |
55 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"); |
56 } | 55 } |
(...skipping 12 matching lines...) Expand all Loading... | |
69 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse(); | 68 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse(); |
70 | 69 |
71 AdblockPlus::JsContext context(jsEngine); | 70 AdblockPlus::JsContext context(jsEngine); |
72 | 71 |
73 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); | 72 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); |
74 resultObject->SetProperty("status", result.status); | 73 resultObject->SetProperty("status", result.status); |
75 resultObject->SetProperty("responseStatus", result.responseStatus); | 74 resultObject->SetProperty("responseStatus", result.responseStatus); |
76 resultObject->SetProperty("responseText", result.responseText); | 75 resultObject->SetProperty("responseText", result.responseText); |
77 | 76 |
78 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); | 77 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); |
79 for (auto it = result.responseHeaders.cbegin(); | 78 for (const auto& header : result.responseHeaders) |
80 it != result.responseHeaders.cend(); ++it) | |
81 { | 79 { |
82 headersObject->SetProperty(it->first, it->second); | 80 headersObject->SetProperty(header.first, header.second); |
83 } | 81 } |
84 resultObject->SetProperty("responseHeaders", headersObject); | 82 resultObject->SetProperty("responseHeaders", headersObject); |
85 | 83 |
86 AdblockPlus::JsValueList params; | 84 AdblockPlus::JsValueList params; |
87 params.push_back(resultObject); | 85 params.push_back(resultObject); |
88 callback->Call(params); | 86 callback->Call(params); |
89 } | 87 } |
90 | 88 |
91 private: | 89 private: |
92 AdblockPlus::JsEnginePtr jsEngine; | 90 AdblockPlus::JsEnginePtr jsEngine; |
(...skipping 23 matching lines...) Expand all Loading... | |
116 return v8::Undefined(); | 114 return v8::Undefined(); |
117 } | 115 } |
118 } | 116 } |
119 | 117 |
120 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( | 118 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( |
121 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) | 119 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) |
122 { | 120 { |
123 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); | 121 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); |
124 return obj; | 122 return obj; |
125 } | 123 } |
LEFT | RIGHT |