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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/resource_request_info.h" | 11 #include "content/public/browser/resource_request_info.h" |
12 #include "content/public/browser/websocket_handshake_request_info.h" | |
12 #include "content/public/common/child_process_host.h" | 13 #include "content/public/common/child_process_host.h" |
13 #include "extensions/browser/api/web_request/upload_data_presenter.h" | 14 #include "extensions/browser/api/web_request/upload_data_presenter.h" |
14 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 15 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
15 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 16 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 #include "net/base/auth.h" | 18 #include "net/base/auth.h" |
18 #include "net/base/upload_data_stream.h" | 19 #include "net/base/upload_data_stream.h" |
19 #include "net/http/http_request_headers.h" | 20 #include "net/http/http_request_headers.h" |
20 #include "net/http/http_response_headers.h" | 21 #include "net/http/http_response_headers.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 | 23 |
23 using extension_web_request_api_helpers::ExtraInfoSpec; | 24 using extension_web_request_api_helpers::ExtraInfoSpec; |
24 | 25 |
25 namespace helpers = extension_web_request_api_helpers; | 26 namespace helpers = extension_web_request_api_helpers; |
26 namespace keys = extension_web_request_api_constants; | 27 namespace keys = extension_web_request_api_constants; |
27 | 28 |
28 namespace extensions { | 29 namespace extensions { |
29 | 30 |
30 WebRequestEventDetails::WebRequestEventDetails(const net::URLRequest* request, | 31 WebRequestEventDetails::WebRequestEventDetails(const net::URLRequest* request, |
31 int extra_info_spec) | 32 int extra_info_spec) |
32 : extra_info_spec_(extra_info_spec), | 33 : extra_info_spec_(extra_info_spec), |
33 render_process_id_(content::ChildProcessHost::kInvalidUniqueID), | 34 render_process_id_(content::ChildProcessHost::kInvalidUniqueID), |
34 render_frame_id_(MSG_ROUTING_NONE) { | 35 render_frame_id_(MSG_ROUTING_NONE) { |
36 DCHECK(request); | |
37 | |
35 content::ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 38 content::ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; |
36 const content::ResourceRequestInfo* info = | 39 const content::ResourceRequestInfo* info = |
37 content::ResourceRequestInfo::ForRequest(request); | 40 content::ResourceRequestInfo::ForRequest(request); |
38 if (info) { | 41 if (info) { |
39 render_process_id_ = info->GetChildID(); | 42 render_process_id_ = info->GetChildID(); |
40 render_frame_id_ = info->GetRenderFrameID(); | 43 render_frame_id_ = info->GetRenderFrameID(); |
41 resource_type = info->GetResourceType(); | 44 resource_type = info->GetResourceType(); |
42 } else { | 45 } else { |
43 // Fallback for requests that are not allocated by a ResourceDispatcherHost, | 46 // TODO(pkalinnikov): Consider embedding WebSocketHandshakeRequestInfo into |
44 // such as the TemplateURLFetcher. | 47 // UrlRequestUserData. |
45 content::ResourceRequestInfo::GetRenderFrameForRequest( | 48 if (request->url().SchemeIsWSOrWSS()) { |
Devlin
2017/02/14 01:21:38
Can we put this if on line 45?
if (info) {
...
}
pkalinnikov
2017/02/14 13:49:51
Done.
| |
46 request, &render_process_id_, &render_frame_id_); | 49 const content::WebSocketHandshakeRequestInfo* ws_info = |
50 content::WebSocketHandshakeRequestInfo::ForRequest(request); | |
51 if (ws_info) { | |
52 render_process_id_ = ws_info->GetChildId(); | |
53 render_frame_id_ = ws_info->GetRenderFrameId(); | |
54 } | |
55 } else { | |
56 // Fallback for requests that are not allocated by a | |
57 // ResourceDispatcherHost, such as the TemplateURLFetcher. | |
58 content::ResourceRequestInfo::GetRenderFrameForRequest( | |
59 request, &render_process_id_, &render_frame_id_); | |
60 } | |
47 } | 61 } |
48 | 62 |
49 dict_.SetString(keys::kMethodKey, request->method()); | 63 dict_.SetString(keys::kMethodKey, request->method()); |
50 dict_.SetString(keys::kRequestIdKey, | 64 dict_.SetString(keys::kRequestIdKey, |
51 base::Uint64ToString(request->identifier())); | 65 base::Uint64ToString(request->identifier())); |
52 dict_.SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); | 66 dict_.SetDouble(keys::kTimeStampKey, base::Time::Now().ToDoubleT() * 1000); |
53 dict_.SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); | 67 dict_.SetString(keys::kTypeKey, helpers::ResourceTypeToString(resource_type)); |
54 dict_.SetString(keys::kUrlKey, request->url().spec()); | 68 dict_.SetString(keys::kUrlKey, request->url().spec()); |
55 } | 69 } |
56 | 70 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 244 |
231 void WebRequestEventDetails::OnDeterminedFrameData( | 245 void WebRequestEventDetails::OnDeterminedFrameData( |
232 std::unique_ptr<WebRequestEventDetails> self, | 246 std::unique_ptr<WebRequestEventDetails> self, |
233 const DeterminedFrameDataCallback& callback, | 247 const DeterminedFrameDataCallback& callback, |
234 const ExtensionApiFrameIdMap::FrameData& frame_data) { | 248 const ExtensionApiFrameIdMap::FrameData& frame_data) { |
235 SetFrameData(frame_data); | 249 SetFrameData(frame_data); |
236 callback.Run(std::move(self)); | 250 callback.Run(std::move(self)); |
237 } | 251 } |
238 | 252 |
239 } // namespace extensions | 253 } // namespace extensions |
OLD | NEW |