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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/child/resource_dispatcher.h" | 7 #include "content/child/resource_dispatcher.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/child/sync_load_response.h" | 21 #include "content/child/sync_load_response.h" |
22 #include "content/common/inter_process_time_ticks_converter.h" | 22 #include "content/common/inter_process_time_ticks_converter.h" |
23 #include "content/common/resource_messages.h" | 23 #include "content/common/resource_messages.h" |
24 #include "content/public/child/request_peer.h" | 24 #include "content/public/child/request_peer.h" |
25 #include "content/public/child/resource_dispatcher_delegate.h" | 25 #include "content/public/child/resource_dispatcher_delegate.h" |
26 #include "content/public/common/resource_response.h" | 26 #include "content/public/common/resource_response.h" |
27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
29 #include "net/base/request_priority.h" | 29 #include "net/base/request_priority.h" |
30 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
31 #include "webkit/child/resource_loader_bridge.h" | |
32 #include "webkit/common/resource_type.h" | 31 #include "webkit/common/resource_type.h" |
33 | 32 |
34 using webkit_glue::ResourceLoaderBridge; | 33 using webkit_glue::ResourceLoaderBridge; |
35 using webkit_glue::ResourceResponseInfo; | 34 using webkit_glue::ResourceResponseInfo; |
36 | 35 |
37 namespace content { | 36 namespace content { |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
41 // Converts |time| from a remote to local TimeTicks, overwriting the original | 40 // Converts |time| from a remote to local TimeTicks, overwriting the original |
42 // value. | 41 // value. |
43 void RemoteToLocalTimeTicks( | 42 void RemoteToLocalTimeTicks( |
44 const InterProcessTimeTicksConverter& converter, | 43 const InterProcessTimeTicksConverter& converter, |
45 base::TimeTicks* time) { | 44 base::TimeTicks* time) { |
46 RemoteTimeTicks remote_time = RemoteTimeTicks::FromTimeTicks(*time); | 45 RemoteTimeTicks remote_time = RemoteTimeTicks::FromTimeTicks(*time); |
47 *time = converter.ToLocalTimeTicks(remote_time).ToTimeTicks(); | 46 *time = converter.ToLocalTimeTicks(remote_time).ToTimeTicks(); |
48 } | 47 } |
49 | 48 |
50 | 49 void CrashOnMapFailure() { |
51 } // namespace | |
52 | |
53 static void CrashOnMapFailure() { | |
54 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
55 DWORD last_err = GetLastError(); | 51 DWORD last_err = GetLastError(); |
56 base::debug::Alias(&last_err); | 52 base::debug::Alias(&last_err); |
57 #endif | 53 #endif |
58 CHECK(false); | 54 CHECK(false); |
59 } | 55 } |
60 | 56 |
61 // Each resource request is assigned an ID scoped to this process. | 57 // Each resource request is assigned an ID scoped to this process. |
62 static int MakeRequestID() { | 58 int MakeRequestID() { |
63 // NOTE: The resource_dispatcher_host also needs probably unique | 59 // NOTE: The resource_dispatcher_host also needs probably unique |
64 // request_ids, so they count down from -2 (-1 is a special we're | 60 // request_ids, so they count down from -2 (-1 is a special we're |
65 // screwed value), while the renderer process counts up. | 61 // screwed value), while the renderer process counts up. |
66 static int next_request_id = 0; | 62 static int next_request_id = 0; |
67 return next_request_id++; | 63 return next_request_id++; |
68 } | 64 } |
69 | 65 |
70 // ResourceLoaderBridge implementation ---------------------------------------- | 66 } // namespace |
71 | |
72 class IPCResourceLoaderBridge : public ResourceLoaderBridge { | |
73 public: | |
74 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | |
75 const RequestInfo& request_info); | |
76 virtual ~IPCResourceLoaderBridge(); | |
77 | |
78 // ResourceLoaderBridge | |
79 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; | |
80 virtual bool Start(RequestPeer* peer) OVERRIDE; | |
81 virtual void Cancel() OVERRIDE; | |
82 virtual void SetDefersLoading(bool value) OVERRIDE; | |
83 virtual void DidChangePriority(net::RequestPriority new_priority, | |
84 int intra_priority_value) OVERRIDE; | |
85 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; | |
86 | |
87 private: | |
88 RequestPeer* peer_; | |
89 | |
90 // The resource dispatcher for this loader. The bridge doesn't own it, but | |
91 // it's guaranteed to outlive the bridge. | |
92 ResourceDispatcher* dispatcher_; | |
93 | |
94 // The request to send, created on initialization for modification and | |
95 // appending data. | |
96 ResourceHostMsg_Request request_; | |
97 | |
98 // ID for the request, valid once Start()ed, -1 if not valid yet. | |
99 int request_id_; | |
100 | |
101 // The routing id used when sending IPC messages. | |
102 int routing_id_; | |
103 | |
104 // The security origin of the frame that initiates this request. | |
105 GURL frame_origin_; | |
106 | |
107 bool is_synchronous_request_; | |
108 }; | |
109 | |
110 IPCResourceLoaderBridge::IPCResourceLoaderBridge( | |
111 ResourceDispatcher* dispatcher, | |
112 const RequestInfo& request_info) | |
113 : peer_(NULL), | |
114 dispatcher_(dispatcher), | |
115 request_id_(-1), | |
116 routing_id_(request_info.routing_id), | |
117 is_synchronous_request_(false) { | |
118 DCHECK(dispatcher_) << "no resource dispatcher"; | |
119 request_.method = request_info.method; | |
120 request_.url = request_info.url; | |
121 request_.first_party_for_cookies = request_info.first_party_for_cookies; | |
122 request_.referrer = request_info.referrer; | |
123 request_.referrer_policy = request_info.referrer_policy; | |
124 request_.headers = request_info.headers; | |
125 request_.load_flags = request_info.load_flags; | |
126 request_.origin_pid = request_info.requestor_pid; | |
127 request_.resource_type = request_info.request_type; | |
128 request_.priority = request_info.priority; | |
129 request_.request_context = request_info.request_context; | |
130 request_.appcache_host_id = request_info.appcache_host_id; | |
131 request_.download_to_file = request_info.download_to_file; | |
132 request_.has_user_gesture = request_info.has_user_gesture; | |
133 | |
134 const RequestExtraData kEmptyData; | |
135 const RequestExtraData* extra_data; | |
136 if (request_info.extra_data) | |
137 extra_data = static_cast<RequestExtraData*>(request_info.extra_data); | |
138 else | |
139 extra_data = &kEmptyData; | |
140 request_.visiblity_state = extra_data->visibility_state(); | |
141 request_.render_frame_id = extra_data->render_frame_id(); | |
142 request_.is_main_frame = extra_data->is_main_frame(); | |
143 request_.parent_is_main_frame = extra_data->parent_is_main_frame(); | |
144 request_.parent_render_frame_id = extra_data->parent_render_frame_id(); | |
145 request_.allow_download = extra_data->allow_download(); | |
146 request_.transition_type = extra_data->transition_type(); | |
147 request_.should_replace_current_entry = | |
148 extra_data->should_replace_current_entry(); | |
149 request_.transferred_request_child_id = | |
150 extra_data->transferred_request_child_id(); | |
151 request_.transferred_request_request_id = | |
152 extra_data->transferred_request_request_id(); | |
153 request_.service_worker_provider_id = | |
154 extra_data->service_worker_provider_id(); | |
155 frame_origin_ = extra_data->frame_origin(); | |
156 } | |
157 | |
158 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() { | |
159 // we remove our hook for the resource dispatcher only when going away, since | |
160 // it doesn't keep track of whether we've force terminated the request | |
161 if (request_id_ >= 0) { | |
162 // this operation may fail, as the dispatcher will have preemptively | |
163 // removed us when the renderer sends the ReceivedAllData message. | |
164 dispatcher_->RemovePendingRequest(request_id_); | |
165 | |
166 if (request_.download_to_file) { | |
167 dispatcher_->message_sender()->Send( | |
168 new ResourceHostMsg_ReleaseDownloadedFile(request_id_)); | |
169 } | |
170 } | |
171 } | |
172 | |
173 void IPCResourceLoaderBridge::SetRequestBody( | |
174 ResourceRequestBody* request_body) { | |
175 DCHECK(request_id_ == -1) << "request already started"; | |
176 request_.request_body = request_body; | |
177 } | |
178 | |
179 // Writes a footer on the message and sends it | |
180 bool IPCResourceLoaderBridge::Start(RequestPeer* peer) { | |
181 if (request_id_ != -1) { | |
182 NOTREACHED() << "Starting a request twice"; | |
183 return false; | |
184 } | |
185 | |
186 peer_ = peer; | |
187 | |
188 // generate the request ID, and append it to the message | |
189 request_id_ = dispatcher_->AddPendingRequest(peer_, | |
190 request_.resource_type, | |
191 request_.origin_pid, | |
192 frame_origin_, | |
193 request_.url); | |
194 | |
195 return dispatcher_->message_sender()->Send( | |
196 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_)); | |
197 } | |
198 | |
199 void IPCResourceLoaderBridge::Cancel() { | |
200 if (request_id_ < 0) { | |
201 NOTREACHED() << "Trying to cancel an unstarted request"; | |
202 return; | |
203 } | |
204 | |
205 if (!is_synchronous_request_) | |
206 dispatcher_->CancelPendingRequest(request_id_); | |
207 | |
208 // We can't remove the request ID from the resource dispatcher because more | |
209 // data might be pending. Sending the cancel message may cause more data | |
210 // to be flushed, and will then cause a complete message to be sent. | |
211 } | |
212 | |
213 void IPCResourceLoaderBridge::SetDefersLoading(bool value) { | |
214 if (request_id_ < 0) { | |
215 NOTREACHED() << "Trying to (un)defer an unstarted request"; | |
216 return; | |
217 } | |
218 | |
219 dispatcher_->SetDefersLoading(request_id_, value); | |
220 } | |
221 | |
222 void IPCResourceLoaderBridge::DidChangePriority( | |
223 net::RequestPriority new_priority, int intra_priority_value) { | |
224 if (request_id_ < 0) { | |
225 NOTREACHED() << "Trying to change priority of an unstarted request"; | |
226 return; | |
227 } | |
228 | |
229 dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority, | |
230 intra_priority_value); | |
231 } | |
232 | |
233 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { | |
234 if (request_id_ != -1) { | |
235 NOTREACHED() << "Starting a request twice"; | |
236 response->error_code = net::ERR_FAILED; | |
237 return; | |
238 } | |
239 | |
240 request_id_ = MakeRequestID(); | |
241 is_synchronous_request_ = true; | |
242 | |
243 SyncLoadResult result; | |
244 IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad(routing_id_, request_id_, | |
245 request_, &result); | |
246 // NOTE: This may pump events (see RenderThread::Send). | |
247 if (!dispatcher_->message_sender()->Send(msg)) { | |
248 response->error_code = net::ERR_FAILED; | |
249 return; | |
250 } | |
251 | |
252 response->error_code = result.error_code; | |
253 response->url = result.final_url; | |
254 response->headers = result.headers; | |
255 response->mime_type = result.mime_type; | |
256 response->charset = result.charset; | |
257 response->request_time = result.request_time; | |
258 response->response_time = result.response_time; | |
259 response->encoded_data_length = result.encoded_data_length; | |
260 response->load_timing = result.load_timing; | |
261 response->devtools_info = result.devtools_info; | |
262 response->data.swap(result.data); | |
263 response->download_file_path = result.download_file_path; | |
264 } | |
265 | |
266 // ResourceDispatcher --------------------------------------------------------- | |
267 | 67 |
268 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) | 68 ResourceDispatcher::ResourceDispatcher(IPC::Sender* sender) |
269 : message_sender_(sender), | 69 : message_sender_(sender), |
270 weak_factory_(this), | 70 weak_factory_(this), |
271 delegate_(NULL), | 71 delegate_(NULL), |
272 io_timestamp_(base::TimeTicks()) { | 72 io_timestamp_(base::TimeTicks()) { |
273 } | 73 } |
274 | 74 |
275 ResourceDispatcher::~ResourceDispatcher() { | 75 ResourceDispatcher::~ResourceDispatcher() { |
276 } | 76 } |
277 | 77 |
278 // ResourceDispatcher implementation ------------------------------------------ | |
279 | |
280 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { | 78 bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) { |
281 if (!IsResourceDispatcherMessage(message)) { | 79 if (!IsResourceDispatcherMessage(message)) { |
282 return false; | 80 return false; |
283 } | 81 } |
284 | 82 |
285 int request_id; | 83 int request_id; |
286 | 84 |
287 PickleIterator iter(message); | 85 PickleIterator iter(message); |
288 if (!message.ReadInt(&iter, &request_id)) { | 86 if (!message.ReadInt(&iter, &request_id)) { |
289 NOTREACHED() << "malformed resource message"; | 87 NOTREACHED() << "malformed resource message"; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 int data_length, | 211 int data_length, |
414 int encoded_data_length) { | 212 int encoded_data_length) { |
415 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); | 213 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); |
416 DCHECK_GT(data_length, 0); | 214 DCHECK_GT(data_length, 0); |
417 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 215 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
418 if (request_info && data_length > 0) { | 216 if (request_info && data_length > 0) { |
419 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); | 217 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); |
420 CHECK_GE(request_info->buffer_size, data_offset + data_length); | 218 CHECK_GE(request_info->buffer_size, data_offset + data_length); |
421 | 219 |
422 // Ensure that the SHM buffer remains valid for the duration of this scope. | 220 // Ensure that the SHM buffer remains valid for the duration of this scope. |
423 // It is possible for CancelPendingRequest() to be called before we exit | 221 // It is possible for Cancel() to be called before we exit this scope. |
424 // this scope. | |
425 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); | 222 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); |
426 | 223 |
427 base::TimeTicks time_start = base::TimeTicks::Now(); | 224 base::TimeTicks time_start = base::TimeTicks::Now(); |
428 | 225 |
429 const char* data_ptr = static_cast<char*>(request_info->buffer->memory()); | 226 const char* data_ptr = static_cast<char*>(request_info->buffer->memory()); |
430 CHECK(data_ptr); | 227 CHECK(data_ptr); |
431 CHECK(data_ptr + data_offset); | 228 CHECK(data_ptr + data_offset); |
432 | 229 |
433 // Check whether this response data is compliant with our cross-site | 230 // Check whether this response data is compliant with our cross-site |
434 // document blocking policy. We only do this for the first packet. | 231 // document blocking policy. We only do this for the first packet. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // SiteIsolationPolicy later when OnReceivedResponse is called. | 299 // SiteIsolationPolicy later when OnReceivedResponse is called. |
503 request_info->response_url = new_url; | 300 request_info->response_url = new_url; |
504 request_info->pending_redirect_message.reset( | 301 request_info->pending_redirect_message.reset( |
505 new ResourceHostMsg_FollowRedirect(request_id, | 302 new ResourceHostMsg_FollowRedirect(request_id, |
506 has_new_first_party_for_cookies, | 303 has_new_first_party_for_cookies, |
507 new_first_party_for_cookies)); | 304 new_first_party_for_cookies)); |
508 if (!request_info->is_deferred) { | 305 if (!request_info->is_deferred) { |
509 FollowPendingRedirect(request_id, *request_info); | 306 FollowPendingRedirect(request_id, *request_info); |
510 } | 307 } |
511 } else { | 308 } else { |
512 CancelPendingRequest(request_id); | 309 Cancel(request_id); |
513 } | 310 } |
514 } | 311 } |
515 | 312 |
516 void ResourceDispatcher::FollowPendingRedirect( | 313 void ResourceDispatcher::FollowPendingRedirect( |
517 int request_id, | 314 int request_id, |
518 PendingRequestInfo& request_info) { | 315 PendingRequestInfo& request_info) { |
519 IPC::Message* msg = request_info.pending_redirect_message.release(); | 316 IPC::Message* msg = request_info.pending_redirect_message.release(); |
520 if (msg) | 317 if (msg) |
521 message_sender()->Send(msg); | 318 message_sender()->Send(msg); |
522 } | 319 } |
(...skipping 27 matching lines...) Expand all Loading... |
550 // Normally, dispatching this message causes the reference-counted request to | 347 // Normally, dispatching this message causes the reference-counted request to |
551 // die immediately. | 348 // die immediately. |
552 peer->OnCompletedRequest(request_complete_data.error_code, | 349 peer->OnCompletedRequest(request_complete_data.error_code, |
553 request_complete_data.was_ignored_by_handler, | 350 request_complete_data.was_ignored_by_handler, |
554 request_complete_data.exists_in_cache, | 351 request_complete_data.exists_in_cache, |
555 request_complete_data.security_info, | 352 request_complete_data.security_info, |
556 renderer_completion_time, | 353 renderer_completion_time, |
557 request_complete_data.encoded_data_length); | 354 request_complete_data.encoded_data_length); |
558 } | 355 } |
559 | 356 |
560 int ResourceDispatcher::AddPendingRequest(RequestPeer* callback, | |
561 ResourceType::Type resource_type, | |
562 int origin_pid, | |
563 const GURL& frame_origin, | |
564 const GURL& request_url) { | |
565 // Compute a unique request_id for this renderer process. | |
566 int id = MakeRequestID(); | |
567 pending_requests_[id] = PendingRequestInfo( | |
568 callback, resource_type, origin_pid, frame_origin, request_url); | |
569 return id; | |
570 } | |
571 | |
572 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 357 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
573 PendingRequestList::iterator it = pending_requests_.find(request_id); | 358 PendingRequestList::iterator it = pending_requests_.find(request_id); |
574 if (it == pending_requests_.end()) | 359 if (it == pending_requests_.end()) |
575 return false; | 360 return false; |
576 | 361 |
577 PendingRequestInfo& request_info = it->second; | 362 PendingRequestInfo& request_info = it->second; |
578 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); | 363 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); |
579 pending_requests_.erase(it); | 364 pending_requests_.erase(it); |
580 | 365 |
581 return true; | 366 return true; |
582 } | 367 } |
583 | 368 |
584 void ResourceDispatcher::CancelPendingRequest(int request_id) { | 369 void ResourceDispatcher::Cancel(int request_id) { |
585 PendingRequestList::iterator it = pending_requests_.find(request_id); | 370 PendingRequestList::iterator it = pending_requests_.find(request_id); |
586 if (it == pending_requests_.end()) { | 371 if (it == pending_requests_.end()) { |
587 DVLOG(1) << "unknown request"; | 372 DVLOG(1) << "unknown request"; |
588 return; | 373 return; |
589 } | 374 } |
590 | 375 |
591 // |request_id| will be removed from |pending_requests_| when | 376 // |request_id| will be removed from |pending_requests_| when |
592 // OnRequestComplete returns with ERR_ABORTED. | 377 // OnRequestComplete returns with ERR_ABORTED. |
593 message_sender()->Send(new ResourceHostMsg_CancelRequest(request_id)); | 378 message_sender()->Send(new ResourceHostMsg_CancelRequest(request_id)); |
594 } | 379 } |
(...skipping 13 matching lines...) Expand all Loading... |
608 FollowPendingRedirect(request_id, request_info); | 393 FollowPendingRedirect(request_id, request_info); |
609 | 394 |
610 base::MessageLoop::current()->PostTask( | 395 base::MessageLoop::current()->PostTask( |
611 FROM_HERE, | 396 FROM_HERE, |
612 base::Bind(&ResourceDispatcher::FlushDeferredMessages, | 397 base::Bind(&ResourceDispatcher::FlushDeferredMessages, |
613 weak_factory_.GetWeakPtr(), | 398 weak_factory_.GetWeakPtr(), |
614 request_id)); | 399 request_id)); |
615 } | 400 } |
616 } | 401 } |
617 | 402 |
618 void ResourceDispatcher::DidChangePriority( | 403 void ResourceDispatcher::DidChangePriority(int request_id, |
619 int routing_id, int request_id, net::RequestPriority new_priority, | 404 net::RequestPriority new_priority, |
620 int intra_priority_value) { | 405 int intra_priority_value) { |
621 DCHECK(ContainsKey(pending_requests_, request_id)); | 406 DCHECK(ContainsKey(pending_requests_, request_id)); |
622 message_sender()->Send(new ResourceHostMsg_DidChangePriority( | 407 message_sender()->Send(new ResourceHostMsg_DidChangePriority( |
623 request_id, new_priority, intra_priority_value)); | 408 request_id, new_priority, intra_priority_value)); |
624 } | 409 } |
625 | 410 |
626 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() | 411 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() |
627 : peer(NULL), | 412 : peer(NULL), |
628 resource_type(ResourceType::SUB_RESOURCE), | 413 resource_type(ResourceType::SUB_RESOURCE), |
629 is_deferred(false), | 414 is_deferred(false), |
630 blocked_response(false), | 415 blocked_response(false), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 if (index != pending_requests_.end()) { | 472 if (index != pending_requests_.end()) { |
688 PendingRequestInfo& pending_request = index->second; | 473 PendingRequestInfo& pending_request = index->second; |
689 if (pending_request.is_deferred) { | 474 if (pending_request.is_deferred) { |
690 pending_request.deferred_message_queue.swap(q); | 475 pending_request.deferred_message_queue.swap(q); |
691 return; | 476 return; |
692 } | 477 } |
693 } | 478 } |
694 } | 479 } |
695 } | 480 } |
696 | 481 |
697 ResourceLoaderBridge* ResourceDispatcher::CreateBridge( | 482 void ResourceDispatcher::StartSync(const RequestInfo& request_info, |
698 const RequestInfo& request_info) { | 483 ResourceRequestBody* request_body, |
699 return new IPCResourceLoaderBridge(this, request_info); | 484 SyncLoadResponse* response) { |
| 485 scoped_ptr<ResourceHostMsg_Request> request = |
| 486 CreateRequest(request_info, request_body, NULL); |
| 487 |
| 488 SyncLoadResult result; |
| 489 IPC::SyncMessage* msg = new ResourceHostMsg_SyncLoad( |
| 490 request_info.routing_id, MakeRequestID(), *request, &result); |
| 491 |
| 492 // NOTE: This may pump events (see RenderThread::Send). |
| 493 if (!message_sender_->Send(msg)) { |
| 494 response->error_code = net::ERR_FAILED; |
| 495 return; |
| 496 } |
| 497 |
| 498 response->error_code = result.error_code; |
| 499 response->url = result.final_url; |
| 500 response->headers = result.headers; |
| 501 response->mime_type = result.mime_type; |
| 502 response->charset = result.charset; |
| 503 response->request_time = result.request_time; |
| 504 response->response_time = result.response_time; |
| 505 response->encoded_data_length = result.encoded_data_length; |
| 506 response->load_timing = result.load_timing; |
| 507 response->devtools_info = result.devtools_info; |
| 508 response->data.swap(result.data); |
| 509 response->download_file_path = result.download_file_path; |
| 510 } |
| 511 |
| 512 int ResourceDispatcher::StartAsync(const RequestInfo& request_info, |
| 513 ResourceRequestBody* request_body, |
| 514 RequestPeer* peer) { |
| 515 GURL frame_origin; |
| 516 scoped_ptr<ResourceHostMsg_Request> request = |
| 517 CreateRequest(request_info, request_body, &frame_origin); |
| 518 |
| 519 // Compute a unique request_id for this renderer process. |
| 520 int request_id = MakeRequestID(); |
| 521 pending_requests_[request_id] = PendingRequestInfo(peer, |
| 522 request->resource_type, |
| 523 request->origin_pid, |
| 524 frame_origin, |
| 525 request->url); |
| 526 |
| 527 message_sender_->Send(new ResourceHostMsg_RequestResource( |
| 528 request_info.routing_id, request_id, *request)); |
| 529 |
| 530 return request_id; |
700 } | 531 } |
701 | 532 |
702 void ResourceDispatcher::ToResourceResponseInfo( | 533 void ResourceDispatcher::ToResourceResponseInfo( |
703 const PendingRequestInfo& request_info, | 534 const PendingRequestInfo& request_info, |
704 const ResourceResponseHead& browser_info, | 535 const ResourceResponseHead& browser_info, |
705 ResourceResponseInfo* renderer_info) const { | 536 ResourceResponseInfo* renderer_info) const { |
706 *renderer_info = browser_info; | 537 *renderer_info = browser_info; |
707 if (request_info.request_start.is_null() || | 538 if (request_info.request_start.is_null() || |
708 request_info.response_start.is_null() || | 539 request_info.response_start.is_null() || |
709 browser_info.request_start.is_null() || | 540 browser_info.request_start.is_null() || |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 // static | 635 // static |
805 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 636 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
806 while (!queue->empty()) { | 637 while (!queue->empty()) { |
807 IPC::Message* message = queue->front(); | 638 IPC::Message* message = queue->front(); |
808 ReleaseResourcesInDataMessage(*message); | 639 ReleaseResourcesInDataMessage(*message); |
809 queue->pop_front(); | 640 queue->pop_front(); |
810 delete message; | 641 delete message; |
811 } | 642 } |
812 } | 643 } |
813 | 644 |
| 645 scoped_ptr<ResourceHostMsg_Request> ResourceDispatcher::CreateRequest( |
| 646 const RequestInfo& request_info, |
| 647 ResourceRequestBody* request_body, |
| 648 GURL* frame_origin) { |
| 649 scoped_ptr<ResourceHostMsg_Request> request(new ResourceHostMsg_Request); |
| 650 request->method = request_info.method; |
| 651 request->url = request_info.url; |
| 652 request->first_party_for_cookies = request_info.first_party_for_cookies; |
| 653 request->referrer = request_info.referrer; |
| 654 request->referrer_policy = request_info.referrer_policy; |
| 655 request->headers = request_info.headers; |
| 656 request->load_flags = request_info.load_flags; |
| 657 request->origin_pid = request_info.requestor_pid; |
| 658 request->resource_type = request_info.request_type; |
| 659 request->priority = request_info.priority; |
| 660 request->request_context = request_info.request_context; |
| 661 request->appcache_host_id = request_info.appcache_host_id; |
| 662 request->download_to_file = request_info.download_to_file; |
| 663 request->has_user_gesture = request_info.has_user_gesture; |
| 664 |
| 665 const RequestExtraData kEmptyData; |
| 666 const RequestExtraData* extra_data; |
| 667 if (request_info.extra_data) |
| 668 extra_data = static_cast<RequestExtraData*>(request_info.extra_data); |
| 669 else |
| 670 extra_data = &kEmptyData; |
| 671 request->visiblity_state = extra_data->visibility_state(); |
| 672 request->render_frame_id = extra_data->render_frame_id(); |
| 673 request->is_main_frame = extra_data->is_main_frame(); |
| 674 request->parent_is_main_frame = extra_data->parent_is_main_frame(); |
| 675 request->parent_render_frame_id = extra_data->parent_render_frame_id(); |
| 676 request->allow_download = extra_data->allow_download(); |
| 677 request->transition_type = extra_data->transition_type(); |
| 678 request->should_replace_current_entry = |
| 679 extra_data->should_replace_current_entry(); |
| 680 request->transferred_request_child_id = |
| 681 extra_data->transferred_request_child_id(); |
| 682 request->transferred_request_request_id = |
| 683 extra_data->transferred_request_request_id(); |
| 684 request->service_worker_provider_id = |
| 685 extra_data->service_worker_provider_id(); |
| 686 request->request_body = request_body; |
| 687 if (frame_origin) |
| 688 *frame_origin = extra_data->frame_origin(); |
| 689 return request.Pass(); |
| 690 } |
| 691 |
814 } // namespace content | 692 } // namespace content |
OLD | NEW |