OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 5 #include "content/browser/renderer_host/resource_request_info_impl.h" |
6 | 6 |
7 #include "content/browser/renderer_host/resource_handler.h" | 7 #include "content/browser/renderer_host/resource_handler.h" |
8 #include "content/browser/ssl/ssl_client_auth_handler.h" | 8 #include "content/browser/ssl/ssl_client_auth_handler.h" |
| 9 #include "content/browser/worker_host/worker_service_impl.h" |
9 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 10 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
10 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
11 #include "webkit/blob/blob_data.h" | 12 #include "webkit/blob/blob_data.h" |
12 | 13 |
13 ResourceDispatcherHostRequestInfo::ResourceDispatcherHostRequestInfo( | 14 namespace content { |
| 15 |
| 16 // static |
| 17 const ResourceRequestInfo* ResourceRequestInfo::ForRequest( |
| 18 const net::URLRequest* request) { |
| 19 return static_cast<const ResourceRequestInfoImpl*>( |
| 20 request->GetUserData(NULL)); |
| 21 } |
| 22 |
| 23 // static |
| 24 void ResourceRequestInfo::AllocateForTesting( |
| 25 net::URLRequest* request, |
| 26 ResourceContext* context) { |
| 27 ResourceRequestInfoImpl* info = |
| 28 new ResourceRequestInfoImpl( |
| 29 NULL, // handler |
| 30 PROCESS_TYPE_RENDERER, // process_type |
| 31 -1, // child_id |
| 32 MSG_ROUTING_NONE, // route_id |
| 33 0, // origin_pid |
| 34 0, // request_id |
| 35 true, // is_main_frame |
| 36 0, // frame_id |
| 37 false, // parent_is_main_frame |
| 38 0, // parent_frame_id |
| 39 ResourceType::MAIN_FRAME, // resource_type |
| 40 PAGE_TRANSITION_LINK, // transition_type |
| 41 0, // upload_size |
| 42 false, // is_download |
| 43 true, // allow_download |
| 44 false, // has_user_gesture |
| 45 WebKit::WebReferrerPolicyDefault, // referrer_policy |
| 46 context); // context |
| 47 info->AssociateWithRequest(request); |
| 48 } |
| 49 |
| 50 ResourceRequestInfoImpl::ResourceRequestInfoImpl( |
14 ResourceHandler* handler, | 51 ResourceHandler* handler, |
15 content::ProcessType process_type, | 52 ProcessType process_type, |
16 int child_id, | 53 int child_id, |
17 int route_id, | 54 int route_id, |
18 int origin_pid, | 55 int origin_pid, |
19 int request_id, | 56 int request_id, |
20 bool is_main_frame, | 57 bool is_main_frame, |
21 int64 frame_id, | 58 int64 frame_id, |
22 bool parent_is_main_frame, | 59 bool parent_is_main_frame, |
23 int64 parent_frame_id, | 60 int64 parent_frame_id, |
24 ResourceType::Type resource_type, | 61 ResourceType::Type resource_type, |
25 content::PageTransition transition_type, | 62 PageTransition transition_type, |
26 uint64 upload_size, | 63 uint64 upload_size, |
27 bool is_download, | 64 bool is_download, |
28 bool allow_download, | 65 bool allow_download, |
29 bool has_user_gesture, | 66 bool has_user_gesture, |
30 WebKit::WebReferrerPolicy referrer_policy, | 67 WebKit::WebReferrerPolicy referrer_policy, |
31 content::ResourceContext* context) | 68 ResourceContext* context) |
32 : resource_handler_(handler), | 69 : resource_handler_(handler), |
33 cross_site_handler_(NULL), | 70 cross_site_handler_(NULL), |
34 process_type_(process_type), | 71 process_type_(process_type), |
35 child_id_(child_id), | 72 child_id_(child_id), |
36 route_id_(route_id), | 73 route_id_(route_id), |
37 origin_pid_(origin_pid), | 74 origin_pid_(origin_pid), |
38 request_id_(request_id), | 75 request_id_(request_id), |
39 is_main_frame_(is_main_frame), | 76 is_main_frame_(is_main_frame), |
40 frame_id_(frame_id), | 77 frame_id_(frame_id), |
41 parent_is_main_frame_(parent_is_main_frame), | 78 parent_is_main_frame_(parent_is_main_frame), |
(...skipping 10 matching lines...) Expand all Loading... |
52 waiting_for_upload_progress_ack_(false), | 89 waiting_for_upload_progress_ack_(false), |
53 memory_cost_(0), | 90 memory_cost_(0), |
54 referrer_policy_(referrer_policy), | 91 referrer_policy_(referrer_policy), |
55 context_(context), | 92 context_(context), |
56 is_paused_(false), | 93 is_paused_(false), |
57 called_on_response_started_(false), | 94 called_on_response_started_(false), |
58 has_started_reading_(false), | 95 has_started_reading_(false), |
59 paused_read_bytes_(0) { | 96 paused_read_bytes_(0) { |
60 } | 97 } |
61 | 98 |
62 ResourceDispatcherHostRequestInfo::~ResourceDispatcherHostRequestInfo() { | 99 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() { |
63 resource_handler_->OnRequestClosed(); | 100 if (resource_handler_) |
| 101 resource_handler_->OnRequestClosed(); |
64 } | 102 } |
65 | 103 |
66 void ResourceDispatcherHostRequestInfo::set_resource_handler( | 104 ResourceContext* ResourceRequestInfoImpl::GetContext() const { |
| 105 return context_; |
| 106 } |
| 107 |
| 108 int ResourceRequestInfoImpl::GetChildID() const { |
| 109 return child_id_; |
| 110 } |
| 111 |
| 112 int ResourceRequestInfoImpl::GetRouteID() const { |
| 113 return route_id_; |
| 114 } |
| 115 |
| 116 int ResourceRequestInfoImpl::GetOriginPID() const { |
| 117 return origin_pid_; |
| 118 } |
| 119 |
| 120 int ResourceRequestInfoImpl::GetRequestID() const { |
| 121 return request_id_; |
| 122 } |
| 123 |
| 124 bool ResourceRequestInfoImpl::IsMainFrame() const { |
| 125 return is_main_frame_; |
| 126 } |
| 127 |
| 128 int64 ResourceRequestInfoImpl::GetFrameID() const { |
| 129 return frame_id_; |
| 130 } |
| 131 |
| 132 bool ResourceRequestInfoImpl::ParentIsMainFrame() const { |
| 133 return parent_is_main_frame_; |
| 134 } |
| 135 |
| 136 int64 ResourceRequestInfoImpl::GetParentFrameID() const { |
| 137 return parent_frame_id_; |
| 138 } |
| 139 |
| 140 ResourceType::Type ResourceRequestInfoImpl::GetResourceType() const { |
| 141 return resource_type_; |
| 142 } |
| 143 |
| 144 WebKit::WebReferrerPolicy ResourceRequestInfoImpl::GetReferrerPolicy() const { |
| 145 return referrer_policy_; |
| 146 } |
| 147 |
| 148 uint64 ResourceRequestInfoImpl::GetUploadSize() const { |
| 149 return upload_size_; |
| 150 } |
| 151 |
| 152 bool ResourceRequestInfoImpl::GetAssociatedRenderView( |
| 153 int* render_process_id, |
| 154 int* render_view_id) const { |
| 155 // If the request is from the worker process, find a tab that owns the worker. |
| 156 if (process_type_ == PROCESS_TYPE_WORKER) { |
| 157 // Need to display some related UI for this network request - pick an |
| 158 // arbitrary parent to do so. |
| 159 if (!WorkerServiceImpl::GetInstance()->GetRendererForWorker( |
| 160 child_id_, render_process_id, render_view_id)) { |
| 161 *render_process_id = -1; |
| 162 *render_view_id = -1; |
| 163 return false; |
| 164 } |
| 165 } else { |
| 166 *render_process_id = child_id_; |
| 167 *render_view_id = route_id_; |
| 168 } |
| 169 return true; |
| 170 } |
| 171 |
| 172 void ResourceRequestInfoImpl::AssociateWithRequest(net::URLRequest* request) { |
| 173 request->SetUserData(NULL, this); |
| 174 } |
| 175 |
| 176 void ResourceRequestInfoImpl::set_resource_handler( |
67 ResourceHandler* resource_handler) { | 177 ResourceHandler* resource_handler) { |
68 resource_handler_ = resource_handler; | 178 resource_handler_ = resource_handler; |
69 } | 179 } |
70 | 180 |
71 void ResourceDispatcherHostRequestInfo::set_login_delegate( | 181 void ResourceRequestInfoImpl::set_login_delegate( |
72 content::ResourceDispatcherHostLoginDelegate* ld) { | 182 ResourceDispatcherHostLoginDelegate* ld) { |
73 login_delegate_ = ld; | 183 login_delegate_ = ld; |
74 } | 184 } |
75 | 185 |
76 void ResourceDispatcherHostRequestInfo::set_ssl_client_auth_handler( | 186 void ResourceRequestInfoImpl::set_ssl_client_auth_handler( |
77 SSLClientAuthHandler* s) { | 187 SSLClientAuthHandler* s) { |
78 ssl_client_auth_handler_ = s; | 188 ssl_client_auth_handler_ = s; |
79 } | 189 } |
80 | 190 |
81 void ResourceDispatcherHostRequestInfo::set_requested_blob_data( | 191 void ResourceRequestInfoImpl::set_requested_blob_data( |
82 webkit_blob::BlobData* data) { | 192 webkit_blob::BlobData* data) { |
83 requested_blob_data_ = data; | 193 requested_blob_data_ = data; |
84 } | 194 } |
| 195 |
| 196 } // namespace content |
OLD | NEW |