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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 auto headersObject = jsEngine->NewObject(); | 73 auto headersObject = jsEngine->NewObject(); |
74 for (const auto& header : response.responseHeaders) | 74 for (const auto& header : response.responseHeaders) |
75 { | 75 { |
76 headersObject.SetProperty(header.first, header.second); | 76 headersObject.SetProperty(header.first, header.second); |
77 } | 77 } |
78 resultObject.SetProperty("responseHeaders", headersObject); | 78 resultObject.SetProperty("responseHeaders", headersObject); |
79 | 79 |
80 webRequestParams[2].Call(resultObject); | 80 webRequestParams[2].Call(resultObject); |
81 }; | 81 }; |
82 | 82 |
83 if (jsEngine->webRequestLegacy) | |
84 { | |
85 std::thread([jsEngine, url, headers, getCallback] | |
86 { | |
87 getCallback(jsEngine->webRequestLegacy->GET(url, headers)); | |
88 }).detach(); | |
89 return; | |
90 } | |
91 | |
92 jsEngine->webRequest->GET(url, headers, getCallback); | 83 jsEngine->webRequest->GET(url, headers, getCallback); |
93 } | 84 } |
94 | 85 |
95 namespace | 86 namespace |
96 { | 87 { |
97 void GETCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) | 88 void GETCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) |
98 { | 89 { |
99 try | 90 try |
100 { | 91 { |
101 AdblockPlus::JsEngine::ScheduleWebRequest(arguments); | 92 AdblockPlus::JsEngine::ScheduleWebRequest(arguments); |
102 } catch (const std::exception& e) | 93 } catch (const std::exception& e) |
103 { | 94 { |
104 return AdblockPlus::Utils::ThrowExceptionInJS(arguments.GetIsolate(), e.wh
at()); | 95 return AdblockPlus::Utils::ThrowExceptionInJS(arguments.GetIsolate(), e.wh
at()); |
105 } | 96 } |
106 } | 97 } |
107 } | 98 } |
108 | 99 |
109 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup( | 100 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup( |
110 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) | 101 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) |
111 { | 102 { |
112 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback)); | 103 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback)); |
113 return obj; | 104 return obj; |
114 } | 105 } |
OLD | NEW |