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

Delta Between Two Patch Sets: src/WebRequestJsObject.cpp

Issue 29393589: Issue 5013 - Make more methods const.- introduced JsConstValuePtr and JsConstValueList- JsValue:… (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Created March 23, 2017, 6:12 p.m.
Right Patch Set: Rebased on master Created March 24, 2017, 2:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/Notification.cpp ('k') | test/JsValue.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 23 matching lines...) Expand all
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 (std::vector<std::string>::iterator it = properties.begin(); 44 for (const auto& header : properties)
45 it != properties.end(); ++it)
46 { 45 {
47 std::string header = *it;
48 std::string headerValue = headersObj->GetProperty(header)->AsString(); 46 std::string headerValue = headersObj->GetProperty(header)->AsString();
49 if (header.length() && headerValue.length()) 47 if (header.length() && headerValue.length())
50 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));
51 } 49 }
52 } 50 }
53 51
54 callback = arguments[2]; 52 callback = arguments[2];
55 if (!callback->IsFunction()) 53 if (!callback->IsFunction())
56 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");
57 } 55 }
(...skipping 12 matching lines...) Expand all
70 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse(); 68 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse();
71 69
72 AdblockPlus::JsContext context(jsEngine); 70 AdblockPlus::JsContext context(jsEngine);
73 71
74 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); 72 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject();
75 resultObject->SetProperty("status", result.status); 73 resultObject->SetProperty("status", result.status);
76 resultObject->SetProperty("responseStatus", result.responseStatus); 74 resultObject->SetProperty("responseStatus", result.responseStatus);
77 resultObject->SetProperty("responseText", result.responseText); 75 resultObject->SetProperty("responseText", result.responseText);
78 76
79 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); 77 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject();
80 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin() ; 78 for (const auto& header : result.responseHeaders)
81 it != result.responseHeaders.end(); ++it)
82 { 79 {
83 headersObject->SetProperty(it->first, it->second); 80 headersObject->SetProperty(header.first, header.second);
84 } 81 }
85 resultObject->SetProperty("responseHeaders", headersObject); 82 resultObject->SetProperty("responseHeaders", headersObject);
86 83
87 AdblockPlus::JsConstValueList params; 84 AdblockPlus::JsConstValueList params;
88 params.push_back(resultObject); 85 params.push_back(resultObject);
89 callback->Call(params); 86 callback->Call(params);
90 } 87 }
91 88
92 private: 89 private:
93 AdblockPlus::JsEnginePtr jsEngine; 90 AdblockPlus::JsEnginePtr jsEngine;
(...skipping 23 matching lines...) Expand all
117 return v8::Undefined(); 114 return v8::Undefined();
118 } 115 }
119 } 116 }
120 117
121 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( 118 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup(
122 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) 119 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
123 { 120 {
124 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); 121 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback));
125 return obj; 122 return obj;
126 } 123 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld