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