OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/api/web_request/web_request_event_details.h" | 5 #include "extensions/browser/api/web_request/web_request_event_details.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ptr_util.h" | |
8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
9 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
12 #include "content/public/browser/websocket_handshake_request_info.h" | 15 #include "content/public/browser/websocket_handshake_request_info.h" |
13 #include "content/public/common/child_process_host.h" | 16 #include "content/public/common/child_process_host.h" |
14 #include "extensions/browser/api/web_request/upload_data_presenter.h" | 17 #include "extensions/browser/api/web_request/upload_data_presenter.h" |
15 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 18 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
16 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 19 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
17 #include "extensions/browser/api/web_request/web_request_resource_type.h" | 20 #include "extensions/browser/api/web_request/web_request_resource_type.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 request_headers_.reset(headers); | 122 request_headers_.reset(headers); |
120 } | 123 } |
121 | 124 |
122 void WebRequestEventDetails::SetAuthInfo( | 125 void WebRequestEventDetails::SetAuthInfo( |
123 const net::AuthChallengeInfo& auth_info) { | 126 const net::AuthChallengeInfo& auth_info) { |
124 dict_.SetBoolean(keys::kIsProxyKey, auth_info.is_proxy); | 127 dict_.SetBoolean(keys::kIsProxyKey, auth_info.is_proxy); |
125 if (!auth_info.scheme.empty()) | 128 if (!auth_info.scheme.empty()) |
126 dict_.SetString(keys::kSchemeKey, auth_info.scheme); | 129 dict_.SetString(keys::kSchemeKey, auth_info.scheme); |
127 if (!auth_info.realm.empty()) | 130 if (!auth_info.realm.empty()) |
128 dict_.SetString(keys::kRealmKey, auth_info.realm); | 131 dict_.SetString(keys::kRealmKey, auth_info.realm); |
129 base::DictionaryValue* challenger = new base::DictionaryValue(); | 132 auto challenger = base::MakeUnique<base::DictionaryValue>(); |
130 challenger->SetString(keys::kHostKey, auth_info.challenger.host()); | 133 challenger->SetString(keys::kHostKey, auth_info.challenger.host()); |
131 challenger->SetInteger(keys::kPortKey, auth_info.challenger.port()); | 134 challenger->SetInteger(keys::kPortKey, auth_info.challenger.port()); |
132 dict_.Set(keys::kChallengerKey, challenger); | 135 dict_.Set(keys::kChallengerKey, std::move(challenger)); |
133 } | 136 } |
134 | 137 |
135 void WebRequestEventDetails::SetResponseHeaders( | 138 void WebRequestEventDetails::SetResponseHeaders( |
136 const net::URLRequest* request, | 139 const net::URLRequest* request, |
137 const net::HttpResponseHeaders* response_headers) { | 140 const net::HttpResponseHeaders* response_headers) { |
138 if (!response_headers) { | 141 if (!response_headers) { |
139 // Not all URLRequestJobs specify response headers. E.g. URLRequestFTPJob, | 142 // Not all URLRequestJobs specify response headers. E.g. URLRequestFTPJob, |
140 // URLRequestFileJob and some redirects. | 143 // URLRequestFileJob and some redirects. |
141 dict_.SetInteger(keys::kStatusCodeKey, request->GetResponseCode()); | 144 dict_.SetInteger(keys::kStatusCodeKey, request->GetResponseCode()); |
142 dict_.SetString(keys::kStatusLineKey, ""); | 145 dict_.SetString(keys::kStatusLineKey, ""); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 std::unique_ptr<WebRequestEventDetails> self(this); | 189 std::unique_ptr<WebRequestEventDetails> self(this); |
187 ExtensionApiFrameIdMap::Get()->GetFrameDataOnIO( | 190 ExtensionApiFrameIdMap::Get()->GetFrameDataOnIO( |
188 render_process_id_, render_frame_id_, | 191 render_process_id_, render_frame_id_, |
189 base::Bind(&WebRequestEventDetails::OnDeterminedFrameData, | 192 base::Bind(&WebRequestEventDetails::OnDeterminedFrameData, |
190 base::Unretained(this), base::Passed(&self), callback)); | 193 base::Unretained(this), base::Passed(&self), callback)); |
191 } | 194 } |
192 | 195 |
193 std::unique_ptr<base::DictionaryValue> WebRequestEventDetails::GetFilteredDict( | 196 std::unique_ptr<base::DictionaryValue> WebRequestEventDetails::GetFilteredDict( |
194 int extra_info_spec) const { | 197 int extra_info_spec) const { |
195 std::unique_ptr<base::DictionaryValue> result = dict_.CreateDeepCopy(); | 198 std::unique_ptr<base::DictionaryValue> result = dict_.CreateDeepCopy(); |
196 if ((extra_info_spec & ExtraInfoSpec::REQUEST_BODY) && request_body_) | 199 if ((extra_info_spec & ExtraInfoSpec::REQUEST_BODY) && request_body_) |
Devlin
2017/06/02 15:38:48
since the bodies of these if's are now multi-line,
jdoerrie
2017/06/06 12:40:23
Done.
| |
197 result->Set(keys::kRequestBodyKey, request_body_->CreateDeepCopy()); | 200 result->Set(keys::kRequestBodyKey, |
201 base::MakeUnique<base::Value>(*request_body_)); | |
Devlin
2017/06/02 15:38:48
Is the copy-constructor preferred over CreateDeepC
vabr (Chromium)
2017/06/03 11:14:52
Indeed, CreateDeepCopy is deprecated in favour of
Devlin
2017/06/05 13:27:33
SG. Can we add a comment to DictionaryValue::Crea
jdoerrie
2017/06/06 12:40:23
Done: http://crrev.com/c/525792
| |
198 if ((extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) && request_headers_) | 202 if ((extra_info_spec & ExtraInfoSpec::REQUEST_HEADERS) && request_headers_) |
199 result->Set(keys::kRequestHeadersKey, request_headers_->CreateDeepCopy()); | 203 result->Set(keys::kRequestHeadersKey, |
204 base::MakeUnique<base::Value>(*request_headers_)); | |
200 if ((extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) && response_headers_) | 205 if ((extra_info_spec & ExtraInfoSpec::RESPONSE_HEADERS) && response_headers_) |
201 result->Set(keys::kResponseHeadersKey, response_headers_->CreateDeepCopy()); | 206 result->Set(keys::kResponseHeadersKey, |
207 base::MakeUnique<base::Value>(*response_headers_)); | |
202 return result; | 208 return result; |
203 } | 209 } |
204 | 210 |
205 std::unique_ptr<base::DictionaryValue> | 211 std::unique_ptr<base::DictionaryValue> |
206 WebRequestEventDetails::GetAndClearDict() { | 212 WebRequestEventDetails::GetAndClearDict() { |
207 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 213 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
208 dict_.Swap(result.get()); | 214 dict_.Swap(result.get()); |
209 return result; | 215 return result; |
210 } | 216 } |
211 | 217 |
(...skipping 29 matching lines...) Expand all Loading... | |
241 | 247 |
242 void WebRequestEventDetails::OnDeterminedFrameData( | 248 void WebRequestEventDetails::OnDeterminedFrameData( |
243 std::unique_ptr<WebRequestEventDetails> self, | 249 std::unique_ptr<WebRequestEventDetails> self, |
244 const DeterminedFrameDataCallback& callback, | 250 const DeterminedFrameDataCallback& callback, |
245 const ExtensionApiFrameIdMap::FrameData& frame_data) { | 251 const ExtensionApiFrameIdMap::FrameData& frame_data) { |
246 SetFrameData(frame_data); | 252 SetFrameData(frame_data); |
247 callback.Run(std::move(self)); | 253 callback.Run(std::move(self)); |
248 } | 254 } |
249 | 255 |
250 } // namespace extensions | 256 } // namespace extensions |
OLD | NEW |