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

Side by Side Diff: src/WebRequestJsObject.cpp

Issue 29391775: Issue 5013 - Improve some const-correctness (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created March 22, 2017, 3:37 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/Notification.cpp ('k') | no next file » | 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 (auto it = properties.cbegin(); it != properties.cend(); ++it)
45 it != properties.end(); ++it)
46 { 45 {
47 std::string header = *it; 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
48 std::string headerValue = headersObj->GetProperty(header)->AsString(); 47 std::string headerValue = headersObj->GetProperty(header)->AsString();
49 if (header.length() && headerValue.length()) 48 if (header.length() && headerValue.length())
50 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));
51 } 50 }
52 } 51 }
53 52
54 callback = arguments[2]; 53 callback = arguments[2];
55 if (!callback->IsFunction()) 54 if (!callback->IsFunction())
56 throw std::runtime_error("Third argument to GET must be a function"); 55 throw std::runtime_error("Third argument to GET must be a function");
57 } 56 }
(...skipping 12 matching lines...) Expand all
70 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse(); 69 jsEngine->GetWebRequest()->GET(url, headers) : NotAllowedResponse();
71 70
72 AdblockPlus::JsContext context(jsEngine); 71 AdblockPlus::JsContext context(jsEngine);
73 72
74 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject(); 73 AdblockPlus::JsValuePtr resultObject = jsEngine->NewObject();
75 resultObject->SetProperty("status", result.status); 74 resultObject->SetProperty("status", result.status);
76 resultObject->SetProperty("responseStatus", result.responseStatus); 75 resultObject->SetProperty("responseStatus", result.responseStatus);
77 resultObject->SetProperty("responseText", result.responseText); 76 resultObject->SetProperty("responseText", result.responseText);
78 77
79 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject(); 78 AdblockPlus::JsValuePtr headersObject = jsEngine->NewObject();
80 for (AdblockPlus::HeaderList::iterator it = result.responseHeaders.begin() ; 79 for (auto it = result.responseHeaders.cbegin();
81 it != result.responseHeaders.end(); ++it) 80 it != result.responseHeaders.cend(); ++it)
82 { 81 {
83 headersObject->SetProperty(it->first, it->second); 82 headersObject->SetProperty(it->first, it->second);
84 } 83 }
85 resultObject->SetProperty("responseHeaders", headersObject); 84 resultObject->SetProperty("responseHeaders", headersObject);
86 85
87 AdblockPlus::JsValueList params; 86 AdblockPlus::JsValueList params;
88 params.push_back(resultObject); 87 params.push_back(resultObject);
89 callback->Call(params); 88 callback->Call(params);
90 } 89 }
91 90
(...skipping 25 matching lines...) Expand all
117 return v8::Undefined(); 116 return v8::Undefined();
118 } 117 }
119 } 118 }
120 119
121 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup( 120 AdblockPlus::JsValuePtr AdblockPlus::WebRequestJsObject::Setup(
122 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj) 121 AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValuePtr obj)
123 { 122 {
124 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback)); 123 obj->SetProperty("GET", jsEngine->NewCallback(::GETCallback));
125 return obj; 124 return obj;
126 } 125 }
OLDNEW
« no previous file with comments | « src/Notification.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld