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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (delegate_) { | 352 if (delegate_) { |
353 ResourceLoaderBridge::Peer* new_peer = | 353 ResourceLoaderBridge::Peer* new_peer = |
354 delegate_->OnReceivedResponse( | 354 delegate_->OnReceivedResponse( |
355 request_info->peer, response_head.mime_type, request_info->url); | 355 request_info->peer, response_head.mime_type, request_info->url); |
356 if (new_peer) | 356 if (new_peer) |
357 request_info->peer = new_peer; | 357 request_info->peer = new_peer; |
358 } | 358 } |
359 | 359 |
360 ResourceResponseInfo renderer_response_info; | 360 ResourceResponseInfo renderer_response_info; |
361 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); | 361 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); |
362 SiteIsolationPolicy::OnReceivedResponse(request_id, | 362 request_info->site_isolation_metadata = |
363 request_info->frame_origin, | 363 SiteIsolationPolicy::OnReceivedResponse(request_info->frame_origin, |
364 request_info->response_url, | 364 request_info->response_url, |
365 request_info->resource_type, | 365 request_info->resource_type, |
366 request_info->origin_pid, | 366 request_info->origin_pid, |
367 renderer_response_info); | 367 renderer_response_info); |
368 request_info->peer->OnReceivedResponse(renderer_response_info); | 368 request_info->peer->OnReceivedResponse(renderer_response_info); |
369 } | 369 } |
370 | 370 |
371 void ResourceDispatcher::OnReceivedCachedMetadata( | 371 void ResourceDispatcher::OnReceivedCachedMetadata( |
372 int request_id, const std::vector<char>& data) { | 372 int request_id, const std::vector<char>& data) { |
373 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 373 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
374 if (!request_info) | 374 if (!request_info) |
375 return; | 375 return; |
376 | 376 |
377 if (data.size()) | 377 if (data.size()) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // this scope. | 425 // this scope. |
426 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); | 426 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); |
427 | 427 |
428 base::TimeTicks time_start = base::TimeTicks::Now(); | 428 base::TimeTicks time_start = base::TimeTicks::Now(); |
429 | 429 |
430 const char* data_ptr = static_cast<char*>(request_info->buffer->memory()); | 430 const char* data_ptr = static_cast<char*>(request_info->buffer->memory()); |
431 CHECK(data_ptr); | 431 CHECK(data_ptr); |
432 CHECK(data_ptr + data_offset); | 432 CHECK(data_ptr + data_offset); |
433 | 433 |
434 // Check whether this response data is compliant with our cross-site | 434 // Check whether this response data is compliant with our cross-site |
435 // document blocking policy. | 435 // document blocking policy. We only do this for the first packet. |
436 std::string alternative_data; | 436 std::string alternative_data; |
437 bool blocked_response = SiteIsolationPolicy::ShouldBlockResponse( | 437 if (request_info->site_isolation_metadata.get()) { |
438 request_id, data_ptr + data_offset, data_length, &alternative_data); | 438 request_info->blocked_response = |
| 439 SiteIsolationPolicy::ShouldBlockResponse( |
| 440 request_info->site_isolation_metadata, data_ptr + data_offset, |
| 441 data_length, &alternative_data); |
| 442 request_info->site_isolation_metadata.reset(); |
| 443 } |
439 | 444 |
440 // When the response is not blocked. | 445 // When the response is not blocked. |
441 if (!blocked_response) { | 446 if (!request_info->blocked_response) { |
442 request_info->peer->OnReceivedData( | 447 request_info->peer->OnReceivedData( |
443 data_ptr + data_offset, data_length, encoded_data_length); | 448 data_ptr + data_offset, data_length, encoded_data_length); |
444 } else if (alternative_data.size() > 0) { | 449 } else if (alternative_data.size() > 0) { |
445 // When the response is blocked, and when we have any alternative data to | 450 // When the response is blocked, and when we have any alternative data to |
446 // send to the renderer. When |alternative_data| is zero-sized, we do not | 451 // send to the renderer. When |alternative_data| is zero-sized, we do not |
447 // call peer's callback. | 452 // call peer's callback. |
448 request_info->peer->OnReceivedData(alternative_data.data(), | 453 request_info->peer->OnReceivedData(alternative_data.data(), |
449 alternative_data.size(), | 454 alternative_data.size(), |
450 alternative_data.size()); | 455 alternative_data.size()); |
451 } | 456 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 PendingRequestInfo& request_info) { | 519 PendingRequestInfo& request_info) { |
515 IPC::Message* msg = request_info.pending_redirect_message.release(); | 520 IPC::Message* msg = request_info.pending_redirect_message.release(); |
516 if (msg) | 521 if (msg) |
517 message_sender()->Send(msg); | 522 message_sender()->Send(msg); |
518 } | 523 } |
519 | 524 |
520 void ResourceDispatcher::OnRequestComplete( | 525 void ResourceDispatcher::OnRequestComplete( |
521 int request_id, | 526 int request_id, |
522 const ResourceMsg_RequestCompleteData& request_complete_data) { | 527 const ResourceMsg_RequestCompleteData& request_complete_data) { |
523 TRACE_EVENT0("loader", "ResourceDispatcher::OnRequestComplete"); | 528 TRACE_EVENT0("loader", "ResourceDispatcher::OnRequestComplete"); |
524 SiteIsolationPolicy::OnRequestComplete(request_id); | |
525 | 529 |
526 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 530 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
527 if (!request_info) | 531 if (!request_info) |
528 return; | 532 return; |
529 request_info->completion_time = ConsumeIOTimestamp(); | 533 request_info->completion_time = ConsumeIOTimestamp(); |
530 request_info->buffer.reset(); | 534 request_info->buffer.reset(); |
531 request_info->buffer_size = 0; | 535 request_info->buffer_size = 0; |
532 | 536 |
533 ResourceLoaderBridge::Peer* peer = request_info->peer; | 537 ResourceLoaderBridge::Peer* peer = request_info->peer; |
534 | 538 |
(...skipping 30 matching lines...) Expand all Loading... |
565 pending_requests_[id] = PendingRequestInfo( | 569 pending_requests_[id] = PendingRequestInfo( |
566 callback, resource_type, origin_pid, frame_origin, request_url); | 570 callback, resource_type, origin_pid, frame_origin, request_url); |
567 return id; | 571 return id; |
568 } | 572 } |
569 | 573 |
570 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 574 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
571 PendingRequestList::iterator it = pending_requests_.find(request_id); | 575 PendingRequestList::iterator it = pending_requests_.find(request_id); |
572 if (it == pending_requests_.end()) | 576 if (it == pending_requests_.end()) |
573 return false; | 577 return false; |
574 | 578 |
575 SiteIsolationPolicy::OnRequestComplete(request_id); | |
576 PendingRequestInfo& request_info = it->second; | 579 PendingRequestInfo& request_info = it->second; |
577 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); | 580 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); |
578 pending_requests_.erase(it); | 581 pending_requests_.erase(it); |
579 | 582 |
580 return true; | 583 return true; |
581 } | 584 } |
582 | 585 |
583 void ResourceDispatcher::CancelPendingRequest(int request_id) { | 586 void ResourceDispatcher::CancelPendingRequest(int request_id) { |
584 PendingRequestList::iterator it = pending_requests_.find(request_id); | 587 PendingRequestList::iterator it = pending_requests_.find(request_id); |
585 if (it == pending_requests_.end()) { | 588 if (it == pending_requests_.end()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 int routing_id, int request_id, net::RequestPriority new_priority) { | 621 int routing_id, int request_id, net::RequestPriority new_priority) { |
619 DCHECK(ContainsKey(pending_requests_, request_id)); | 622 DCHECK(ContainsKey(pending_requests_, request_id)); |
620 message_sender()->Send(new ResourceHostMsg_DidChangePriority( | 623 message_sender()->Send(new ResourceHostMsg_DidChangePriority( |
621 request_id, new_priority)); | 624 request_id, new_priority)); |
622 } | 625 } |
623 | 626 |
624 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() | 627 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() |
625 : peer(NULL), | 628 : peer(NULL), |
626 resource_type(ResourceType::SUB_RESOURCE), | 629 resource_type(ResourceType::SUB_RESOURCE), |
627 is_deferred(false), | 630 is_deferred(false), |
| 631 blocked_response(false), |
628 buffer_size(0) { | 632 buffer_size(0) { |
629 } | 633 } |
630 | 634 |
631 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( | 635 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( |
632 webkit_glue::ResourceLoaderBridge::Peer* peer, | 636 webkit_glue::ResourceLoaderBridge::Peer* peer, |
633 ResourceType::Type resource_type, | 637 ResourceType::Type resource_type, |
634 int origin_pid, | 638 int origin_pid, |
635 const GURL& frame_origin, | 639 const GURL& frame_origin, |
636 const GURL& request_url) | 640 const GURL& request_url) |
637 : peer(peer), | 641 : peer(peer), |
638 resource_type(resource_type), | 642 resource_type(resource_type), |
639 origin_pid(origin_pid), | 643 origin_pid(origin_pid), |
640 is_deferred(false), | 644 is_deferred(false), |
641 url(request_url), | 645 url(request_url), |
642 frame_origin(frame_origin), | 646 frame_origin(frame_origin), |
643 response_url(request_url), | 647 response_url(request_url), |
644 request_start(base::TimeTicks::Now()) { | 648 request_start(base::TimeTicks::Now()), |
| 649 blocked_response(false) { |
645 } | 650 } |
646 | 651 |
647 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} | 652 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} |
648 | 653 |
649 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { | 654 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { |
650 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) | 655 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) |
651 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) | 656 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) |
652 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) | 657 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) |
653 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, | 658 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, |
654 OnReceivedCachedMetadata) | 659 OnReceivedCachedMetadata) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { | 807 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { |
803 while (!queue->empty()) { | 808 while (!queue->empty()) { |
804 IPC::Message* message = queue->front(); | 809 IPC::Message* message = queue->front(); |
805 ReleaseResourcesInDataMessage(*message); | 810 ReleaseResourcesInDataMessage(*message); |
806 queue->pop_front(); | 811 queue->pop_front(); |
807 delete message; | 812 delete message; |
808 } | 813 } |
809 } | 814 } |
810 | 815 |
811 } // namespace content | 816 } // namespace content |
OLD | NEW |