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

Side by Side Diff: src/WebRequestJsObject.cpp

Issue 29424786: Issue 5182 - fix IsConnectionAllowed (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 28, 2017, 2:42 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
« no previous file with comments | « src/JsEngine.cpp ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
OLDNEW
« no previous file with comments | « src/JsEngine.cpp ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld