Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/child/resource_dispatcher.cc

Issue 22254005: UMA data collector for cross-site documents(XSD) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: fix compile error Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "content/child/request_extra_data.h" 18 #include "content/child/request_extra_data.h"
19 #include "content/child/site_isolation_policy.h"
19 #include "content/common/inter_process_time_ticks_converter.h" 20 #include "content/common/inter_process_time_ticks_converter.h"
20 #include "content/common/resource_messages.h" 21 #include "content/common/resource_messages.h"
21 #include "content/public/child/resource_dispatcher_delegate.h" 22 #include "content/public/child/resource_dispatcher_delegate.h"
22 #include "content/public/common/resource_response.h" 23 #include "content/public/common/resource_response.h"
23 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
24 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
25 #include "net/base/request_priority.h" 26 #include "net/base/request_priority.h"
26 #include "net/http/http_response_headers.h" 27 #include "net/http/http_response_headers.h"
27 #include "webkit/common/resource_type.h" 28 #include "webkit/common/resource_type.h"
28 29
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // The request to send, created on initialization for modification and 90 // The request to send, created on initialization for modification and
90 // appending data. 91 // appending data.
91 ResourceHostMsg_Request request_; 92 ResourceHostMsg_Request request_;
92 93
93 // ID for the request, valid once Start()ed, -1 if not valid yet. 94 // ID for the request, valid once Start()ed, -1 if not valid yet.
94 int request_id_; 95 int request_id_;
95 96
96 // The routing id used when sending IPC messages. 97 // The routing id used when sending IPC messages.
97 int routing_id_; 98 int routing_id_;
98 99
100 // The security origin of the frame that initiates this request.
101 GURL frame_origin_;
102
99 bool is_synchronous_request_; 103 bool is_synchronous_request_;
100 }; 104 };
101 105
102 IPCResourceLoaderBridge::IPCResourceLoaderBridge( 106 IPCResourceLoaderBridge::IPCResourceLoaderBridge(
103 ResourceDispatcher* dispatcher, 107 ResourceDispatcher* dispatcher,
104 const ResourceLoaderBridge::RequestInfo& request_info) 108 const ResourceLoaderBridge::RequestInfo& request_info)
105 : peer_(NULL), 109 : peer_(NULL),
106 dispatcher_(dispatcher), 110 dispatcher_(dispatcher),
107 request_id_(-1), 111 request_id_(-1),
108 routing_id_(request_info.routing_id), 112 routing_id_(request_info.routing_id),
(...skipping 19 matching lines...) Expand all
128 request_.is_main_frame = extra_data->is_main_frame(); 132 request_.is_main_frame = extra_data->is_main_frame();
129 request_.frame_id = extra_data->frame_id(); 133 request_.frame_id = extra_data->frame_id();
130 request_.parent_is_main_frame = extra_data->parent_is_main_frame(); 134 request_.parent_is_main_frame = extra_data->parent_is_main_frame();
131 request_.parent_frame_id = extra_data->parent_frame_id(); 135 request_.parent_frame_id = extra_data->parent_frame_id();
132 request_.allow_download = extra_data->allow_download(); 136 request_.allow_download = extra_data->allow_download();
133 request_.transition_type = extra_data->transition_type(); 137 request_.transition_type = extra_data->transition_type();
134 request_.transferred_request_child_id = 138 request_.transferred_request_child_id =
135 extra_data->transferred_request_child_id(); 139 extra_data->transferred_request_child_id();
136 request_.transferred_request_request_id = 140 request_.transferred_request_request_id =
137 extra_data->transferred_request_request_id(); 141 extra_data->transferred_request_request_id();
142 frame_origin_ = extra_data->frame_origin();
138 } else { 143 } else {
139 request_.is_main_frame = false; 144 request_.is_main_frame = false;
140 request_.frame_id = -1; 145 request_.frame_id = -1;
141 request_.parent_is_main_frame = false; 146 request_.parent_is_main_frame = false;
142 request_.parent_frame_id = -1; 147 request_.parent_frame_id = -1;
143 request_.allow_download = true; 148 request_.allow_download = true;
144 request_.transition_type = PAGE_TRANSITION_LINK; 149 request_.transition_type = PAGE_TRANSITION_LINK;
145 request_.transferred_request_child_id = -1; 150 request_.transferred_request_child_id = -1;
146 request_.transferred_request_request_id = -1; 151 request_.transferred_request_request_id = -1;
147 } 152 }
(...skipping 24 matching lines...) Expand all
172 bool IPCResourceLoaderBridge::Start(Peer* peer) { 177 bool IPCResourceLoaderBridge::Start(Peer* peer) {
173 if (request_id_ != -1) { 178 if (request_id_ != -1) {
174 NOTREACHED() << "Starting a request twice"; 179 NOTREACHED() << "Starting a request twice";
175 return false; 180 return false;
176 } 181 }
177 182
178 peer_ = peer; 183 peer_ = peer;
179 184
180 // generate the request ID, and append it to the message 185 // generate the request ID, and append it to the message
181 request_id_ = dispatcher_->AddPendingRequest( 186 request_id_ = dispatcher_->AddPendingRequest(
182 peer_, request_.resource_type, request_.url); 187 peer_, request_.resource_type, frame_origin_, request_.url);
183 188
184 return dispatcher_->message_sender()->Send( 189 return dispatcher_->message_sender()->Send(
185 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_)); 190 new ResourceHostMsg_RequestResource(routing_id_, request_id_, request_));
186 } 191 }
187 192
188 void IPCResourceLoaderBridge::Cancel() { 193 void IPCResourceLoaderBridge::Cancel() {
189 if (request_id_ < 0) { 194 if (request_id_ < 0) {
190 NOTREACHED() << "Trying to cancel an unstarted request"; 195 NOTREACHED() << "Trying to cancel an unstarted request";
191 return; 196 return;
192 } 197 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 if (delegate_) { 344 if (delegate_) {
340 ResourceLoaderBridge::Peer* new_peer = 345 ResourceLoaderBridge::Peer* new_peer =
341 delegate_->OnReceivedResponse( 346 delegate_->OnReceivedResponse(
342 request_info->peer, response_head.mime_type, request_info->url); 347 request_info->peer, response_head.mime_type, request_info->url);
343 if (new_peer) 348 if (new_peer)
344 request_info->peer = new_peer; 349 request_info->peer = new_peer;
345 } 350 }
346 351
347 ResourceResponseInfo renderer_response_info; 352 ResourceResponseInfo renderer_response_info;
348 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); 353 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info);
354 SiteIsolationPolicy::OnReceivedResponse(request_id,
355 request_info->frame_origin,
356 request_info->response_url,
357 request_info->resource_type,
358 renderer_response_info);
349 request_info->peer->OnReceivedResponse(renderer_response_info); 359 request_info->peer->OnReceivedResponse(renderer_response_info);
350 } 360 }
351 361
352 void ResourceDispatcher::OnReceivedCachedMetadata( 362 void ResourceDispatcher::OnReceivedCachedMetadata(
353 int request_id, const std::vector<char>& data) { 363 int request_id, const std::vector<char>& data) {
354 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 364 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
355 if (!request_info) 365 if (!request_info)
356 return; 366 return;
357 367
358 if (data.size()) 368 if (data.size())
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // It is possible for CancelPendingRequest() to be called before we exit 414 // It is possible for CancelPendingRequest() to be called before we exit
405 // this scope. 415 // this scope.
406 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); 416 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer);
407 417
408 base::TimeTicks time_start = base::TimeTicks::Now(); 418 base::TimeTicks time_start = base::TimeTicks::Now();
409 419
410 const char* data_ptr = static_cast<char*>(request_info->buffer->memory()); 420 const char* data_ptr = static_cast<char*>(request_info->buffer->memory());
411 CHECK(data_ptr); 421 CHECK(data_ptr);
412 CHECK(data_ptr + data_offset); 422 CHECK(data_ptr + data_offset);
413 423
414 request_info->peer->OnReceivedData( 424 // Check whether this response data is compliant with our cross-site
415 data_ptr + data_offset, 425 // document blocking policy.
416 data_length, 426 std::string alternative_data;
417 encoded_data_length); 427 bool blocked_response = SiteIsolationPolicy::ShouldBlockResponse(
428 request_id, data_ptr + data_offset, data_length, &alternative_data);
429
430 // When the response is not blocked.
431 if (!blocked_response) {
432 request_info->peer->OnReceivedData(
433 data_ptr + data_offset, data_length, encoded_data_length);
434 } else if (alternative_data.size() > 0) {
435 // When the response is blocked, and when we have any alternative data to
436 // send to the renderer. When |alternative_data| is zero-sized, we do not
437 // call peer's callback.
438 request_info->peer->OnReceivedData(alternative_data.data(),
439 alternative_data.size(),
440 alternative_data.size());
441 }
418 442
419 UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime", 443 UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime",
420 base::TimeTicks::Now() - time_start); 444 base::TimeTicks::Now() - time_start);
421 } 445 }
422 446
423 // Acknowledge the reception of this data. 447 // Acknowledge the reception of this data.
424 message_sender()->Send( 448 message_sender()->Send(
425 new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id)); 449 new ResourceHostMsg_DataReceived_ACK(message.routing_id(), request_id));
426 } 450 }
427 451
(...skipping 27 matching lines...) Expand all
455 ResourceResponseInfo renderer_response_info; 479 ResourceResponseInfo renderer_response_info;
456 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); 480 ToResourceResponseInfo(*request_info, response_head, &renderer_response_info);
457 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info, 481 if (request_info->peer->OnReceivedRedirect(new_url, renderer_response_info,
458 &has_new_first_party_for_cookies, 482 &has_new_first_party_for_cookies,
459 &new_first_party_for_cookies)) { 483 &new_first_party_for_cookies)) {
460 // Double-check if the request is still around. The call above could 484 // Double-check if the request is still around. The call above could
461 // potentially remove it. 485 // potentially remove it.
462 request_info = GetPendingRequestInfo(request_id); 486 request_info = GetPendingRequestInfo(request_id);
463 if (!request_info) 487 if (!request_info)
464 return; 488 return;
489 // We update the response_url here so that we can send it to
490 // SiteIsolationPolicy later when OnReceivedResponse is called.
491 request_info->response_url = new_url;
465 request_info->pending_redirect_message.reset( 492 request_info->pending_redirect_message.reset(
466 new ResourceHostMsg_FollowRedirect(routing_id, request_id, 493 new ResourceHostMsg_FollowRedirect(routing_id, request_id,
467 has_new_first_party_for_cookies, 494 has_new_first_party_for_cookies,
468 new_first_party_for_cookies)); 495 new_first_party_for_cookies));
469 if (!request_info->is_deferred) { 496 if (!request_info->is_deferred) {
470 FollowPendingRedirect(request_id, *request_info); 497 FollowPendingRedirect(request_id, *request_info);
471 } 498 }
472 } else { 499 } else {
473 CancelPendingRequest(routing_id, request_id); 500 CancelPendingRequest(routing_id, request_id);
474 } 501 }
475 } 502 }
476 503
477 void ResourceDispatcher::FollowPendingRedirect( 504 void ResourceDispatcher::FollowPendingRedirect(
478 int request_id, 505 int request_id,
479 PendingRequestInfo& request_info) { 506 PendingRequestInfo& request_info) {
480 IPC::Message* msg = request_info.pending_redirect_message.release(); 507 IPC::Message* msg = request_info.pending_redirect_message.release();
481 if (msg) 508 if (msg)
482 message_sender()->Send(msg); 509 message_sender()->Send(msg);
483 } 510 }
484 511
485 void ResourceDispatcher::OnRequestComplete( 512 void ResourceDispatcher::OnRequestComplete(
486 int request_id, 513 int request_id,
487 int error_code, 514 int error_code,
488 bool was_ignored_by_handler, 515 bool was_ignored_by_handler,
489 const std::string& security_info, 516 const std::string& security_info,
490 const base::TimeTicks& browser_completion_time) { 517 const base::TimeTicks& browser_completion_time) {
518 SiteIsolationPolicy::OnRequestComplete(request_id);
519
491 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 520 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
492 if (!request_info) 521 if (!request_info)
493 return; 522 return;
494 request_info->completion_time = ConsumeIOTimestamp(); 523 request_info->completion_time = ConsumeIOTimestamp();
495 request_info->buffer.reset(); 524 request_info->buffer.reset();
496 request_info->buffer_size = 0; 525 request_info->buffer_size = 0;
497 526
498 ResourceLoaderBridge::Peer* peer = request_info->peer; 527 ResourceLoaderBridge::Peer* peer = request_info->peer;
499 528
500 if (delegate_) { 529 if (delegate_) {
501 ResourceLoaderBridge::Peer* new_peer = 530 ResourceLoaderBridge::Peer* new_peer =
502 delegate_->OnRequestComplete( 531 delegate_->OnRequestComplete(
503 request_info->peer, request_info->resource_type, error_code); 532 request_info->peer, request_info->resource_type, error_code);
504 if (new_peer) 533 if (new_peer)
505 request_info->peer = new_peer; 534 request_info->peer = new_peer;
506 } 535 }
507 536
508 base::TimeTicks renderer_completion_time = ToRendererCompletionTime( 537 base::TimeTicks renderer_completion_time = ToRendererCompletionTime(
509 *request_info, browser_completion_time); 538 *request_info, browser_completion_time);
510 // The request ID will be removed from our pending list in the destructor. 539 // The request ID will be removed from our pending list in the destructor.
511 // Normally, dispatching this message causes the reference-counted request to 540 // Normally, dispatching this message causes the reference-counted request to
512 // die immediately. 541 // die immediately.
513 peer->OnCompletedRequest(error_code, was_ignored_by_handler, security_info, 542 peer->OnCompletedRequest(error_code, was_ignored_by_handler, security_info,
514 renderer_completion_time); 543 renderer_completion_time);
515 } 544 }
516 545
517 int ResourceDispatcher::AddPendingRequest( 546 int ResourceDispatcher::AddPendingRequest(
518 ResourceLoaderBridge::Peer* callback, 547 ResourceLoaderBridge::Peer* callback,
519 ResourceType::Type resource_type, 548 ResourceType::Type resource_type,
549 const GURL& frame_origin,
520 const GURL& request_url) { 550 const GURL& request_url) {
521 // Compute a unique request_id for this renderer process. 551 // Compute a unique request_id for this renderer process.
522 int id = MakeRequestID(); 552 int id = MakeRequestID();
523 pending_requests_[id] = 553 pending_requests_[id] =
524 PendingRequestInfo(callback, resource_type, request_url); 554 PendingRequestInfo(callback, resource_type, frame_origin, request_url);
525 return id; 555 return id;
526 } 556 }
527 557
528 bool ResourceDispatcher::RemovePendingRequest(int request_id) { 558 bool ResourceDispatcher::RemovePendingRequest(int request_id) {
529 PendingRequestList::iterator it = pending_requests_.find(request_id); 559 PendingRequestList::iterator it = pending_requests_.find(request_id);
530 if (it == pending_requests_.end()) 560 if (it == pending_requests_.end())
531 return false; 561 return false;
532 562
563 SiteIsolationPolicy::OnRequestComplete(request_id);
533 PendingRequestInfo& request_info = it->second; 564 PendingRequestInfo& request_info = it->second;
534 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); 565 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
535 pending_requests_.erase(it); 566 pending_requests_.erase(it);
536 567
537 return true; 568 return true;
538 } 569 }
539 570
540 void ResourceDispatcher::CancelPendingRequest(int routing_id, 571 void ResourceDispatcher::CancelPendingRequest(int routing_id,
541 int request_id) { 572 int request_id) {
542 PendingRequestList::iterator it = pending_requests_.find(request_id); 573 PendingRequestList::iterator it = pending_requests_.find(request_id);
543 if (it == pending_requests_.end()) { 574 if (it == pending_requests_.end()) {
544 DVLOG(1) << "unknown request"; 575 DVLOG(1) << "unknown request";
545 return; 576 return;
546 } 577 }
547 578
579 SiteIsolationPolicy::OnRequestComplete(request_id);
548 PendingRequestInfo& request_info = it->second; 580 PendingRequestInfo& request_info = it->second;
549 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue); 581 ReleaseResourcesInMessageQueue(&request_info.deferred_message_queue);
550 pending_requests_.erase(it); 582 pending_requests_.erase(it);
551 583
552 message_sender()->Send( 584 message_sender()->Send(
553 new ResourceHostMsg_CancelRequest(routing_id, request_id)); 585 new ResourceHostMsg_CancelRequest(routing_id, request_id));
554 } 586 }
555 587
556 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) { 588 void ResourceDispatcher::SetDefersLoading(int request_id, bool value) {
557 PendingRequestList::iterator it = pending_requests_.find(request_id); 589 PendingRequestList::iterator it = pending_requests_.find(request_id);
(...skipping 27 matching lines...) Expand all
585 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() 617 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo()
586 : peer(NULL), 618 : peer(NULL),
587 resource_type(ResourceType::SUB_RESOURCE), 619 resource_type(ResourceType::SUB_RESOURCE),
588 is_deferred(false), 620 is_deferred(false),
589 buffer_size(0) { 621 buffer_size(0) {
590 } 622 }
591 623
592 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( 624 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
593 webkit_glue::ResourceLoaderBridge::Peer* peer, 625 webkit_glue::ResourceLoaderBridge::Peer* peer,
594 ResourceType::Type resource_type, 626 ResourceType::Type resource_type,
627 const GURL& frame_origin,
595 const GURL& request_url) 628 const GURL& request_url)
596 : peer(peer), 629 : peer(peer),
597 resource_type(resource_type), 630 resource_type(resource_type),
598 is_deferred(false), 631 is_deferred(false),
599 url(request_url), 632 url(request_url),
633 frame_origin(frame_origin),
634 response_url(request_url),
600 request_start(base::TimeTicks::Now()) { 635 request_start(base::TimeTicks::Now()) {
601 } 636 }
602 637
603 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {} 638 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
604 639
605 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { 640 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
606 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) 641 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)
607 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) 642 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress)
608 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) 643 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse)
609 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, 644 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { 793 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
759 while (!queue->empty()) { 794 while (!queue->empty()) {
760 IPC::Message* message = queue->front(); 795 IPC::Message* message = queue->front();
761 ReleaseResourcesInDataMessage(*message); 796 ReleaseResourcesInDataMessage(*message);
762 queue->pop_front(); 797 queue->pop_front();
763 delete message; 798 delete message;
764 } 799 }
765 } 800 }
766 801
767 } // namespace content 802 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698