Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/WebRequestJsObject.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 28, 2017, 12:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/IWebRequest.h> 19 #include <AdblockPlus/IWebRequest.h>
20 20
21 #include "JsContext.h" 21 #include "JsContext.h"
22 #include "Utils.h" 22 #include "Utils.h"
23 #include "WebRequestJsObject.h" 23 #include "WebRequestJsObject.h"
24 #include <thread> // TODO: remove with removing of JsEngine::webRequestLegacy 24 #include <AdblockPlus/Platform.h>
25 25
26 using namespace AdblockPlus; 26 using namespace AdblockPlus;
27 27
28 void JsEngine::ScheduleWebRequest(const v8::FunctionCallbackInfo<v8::Value>& arg uments) 28 void JsEngine::ScheduleWebRequest(const v8::FunctionCallbackInfo<v8::Value>& arg uments)
29 { 29 {
30 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents); 30 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::FromArguments(argum ents);
31 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments); 31 AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
32 if (converted.size() != 3u) 32 if (converted.size() != 3u)
33 throw std::runtime_error("GET requires exactly 3 arguments"); 33 throw std::runtime_error("GET requires exactly 3 arguments");
34 34
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 jsEngine->webRequest->GET(url, headers, getCallback); 83 jsEngine->GetPlatform().GetWebRequest().GET(url, headers, getCallback);
84 } 84 }
85 85
86 namespace 86 namespace
87 { 87 {
88 void GETCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments) 88 void GETCallback(const v8::FunctionCallbackInfo<v8::Value>& arguments)
89 { 89 {
90 try 90 try
91 { 91 {
92 AdblockPlus::JsEngine::ScheduleWebRequest(arguments); 92 AdblockPlus::JsEngine::ScheduleWebRequest(arguments);
93 } catch (const std::exception& e) 93 } catch (const std::exception& e)
94 { 94 {
95 return AdblockPlus::Utils::ThrowExceptionInJS(arguments.GetIsolate(), e.wh at()); 95 return AdblockPlus::Utils::ThrowExceptionInJS(arguments.GetIsolate(), e.wh at());
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup( 100 AdblockPlus::JsValue& AdblockPlus::WebRequestJsObject::Setup(
101 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj) 101 AdblockPlus::JsEngine& jsEngine, AdblockPlus::JsValue& obj)
102 { 102 {
103 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback)); 103 obj.SetProperty("GET", jsEngine.NewCallback(::GETCallback));
104 return obj; 104 return obj;
105 } 105 }
OLDNEW
« include/AdblockPlus/JsEngine.h ('K') | « src/Platform.cpp ('k') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld