| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/resource_dispatcher.h" | 7 #include "chrome/common/resource_dispatcher.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 namespace webkit_glue { | 41 namespace webkit_glue { |
| 42 | 42 |
| 43 class IPCResourceLoaderBridge : public ResourceLoaderBridge { | 43 class IPCResourceLoaderBridge : public ResourceLoaderBridge { |
| 44 public: | 44 public: |
| 45 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, | 45 IPCResourceLoaderBridge(ResourceDispatcher* dispatcher, |
| 46 const std::string& method, | 46 const std::string& method, |
| 47 const GURL& url, | 47 const GURL& url, |
| 48 const GURL& policy_url, | 48 const GURL& policy_url, |
| 49 const GURL& referrer, | 49 const GURL& referrer, |
| 50 const std::string& frame_origin, |
| 51 const std::string& main_frame_origin, |
| 50 const std::string& headers, | 52 const std::string& headers, |
| 51 int load_flags, | 53 int load_flags, |
| 52 int origin_pid, | 54 int origin_pid, |
| 53 ResourceType::Type resource_type, | 55 ResourceType::Type resource_type, |
| 54 bool mixed_content, | |
| 55 uint32 request_context, | 56 uint32 request_context, |
| 56 int route_id); | 57 int route_id); |
| 57 virtual ~IPCResourceLoaderBridge(); | 58 virtual ~IPCResourceLoaderBridge(); |
| 58 | 59 |
| 59 // ResourceLoaderBridge | 60 // ResourceLoaderBridge |
| 60 virtual void AppendDataToUpload(const char* data, int data_len); | 61 virtual void AppendDataToUpload(const char* data, int data_len); |
| 61 virtual void AppendFileRangeToUpload(const std::wstring& path, | 62 virtual void AppendFileRangeToUpload(const std::wstring& path, |
| 62 uint64 offset, uint64 length); | 63 uint64 offset, uint64 length); |
| 63 virtual bool Start(Peer* peer); | 64 virtual bool Start(Peer* peer); |
| 64 virtual void Cancel(); | 65 virtual void Cancel(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 91 std::string url_; | 92 std::string url_; |
| 92 #endif | 93 #endif |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 IPCResourceLoaderBridge::IPCResourceLoaderBridge( | 96 IPCResourceLoaderBridge::IPCResourceLoaderBridge( |
| 96 ResourceDispatcher* dispatcher, | 97 ResourceDispatcher* dispatcher, |
| 97 const std::string& method, | 98 const std::string& method, |
| 98 const GURL& url, | 99 const GURL& url, |
| 99 const GURL& policy_url, | 100 const GURL& policy_url, |
| 100 const GURL& referrer, | 101 const GURL& referrer, |
| 102 const std::string& frame_origin, |
| 103 const std::string& main_frame_origin, |
| 101 const std::string& headers, | 104 const std::string& headers, |
| 102 int load_flags, | 105 int load_flags, |
| 103 int origin_pid, | 106 int origin_pid, |
| 104 ResourceType::Type resource_type, | 107 ResourceType::Type resource_type, |
| 105 bool mixed_content, | |
| 106 uint32 request_context, | 108 uint32 request_context, |
| 107 int route_id) | 109 int route_id) |
| 108 : peer_(NULL), | 110 : peer_(NULL), |
| 109 dispatcher_(dispatcher), | 111 dispatcher_(dispatcher), |
| 110 request_id_(-1), | 112 request_id_(-1), |
| 111 route_id_(route_id) { | 113 route_id_(route_id) { |
| 112 DCHECK(dispatcher_) << "no resource dispatcher"; | 114 DCHECK(dispatcher_) << "no resource dispatcher"; |
| 113 request_.method = method; | 115 request_.method = method; |
| 114 request_.url = url; | 116 request_.url = url; |
| 115 request_.policy_url = policy_url; | 117 request_.policy_url = policy_url; |
| 116 request_.referrer = referrer; | 118 request_.referrer = referrer; |
| 119 request_.frame_origin = frame_origin; |
| 120 request_.main_frame_origin = main_frame_origin; |
| 117 request_.headers = headers; | 121 request_.headers = headers; |
| 118 request_.load_flags = load_flags; | 122 request_.load_flags = load_flags; |
| 119 request_.origin_pid = origin_pid; | 123 request_.origin_pid = origin_pid; |
| 120 request_.resource_type = resource_type; | 124 request_.resource_type = resource_type; |
| 121 request_.mixed_content = mixed_content; | |
| 122 request_.request_context = request_context; | 125 request_.request_context = request_context; |
| 123 | 126 |
| 124 #ifdef LOG_RESOURCE_REQUESTS | 127 #ifdef LOG_RESOURCE_REQUESTS |
| 125 url_ = url.possibly_invalid_spec(); | 128 url_ = url.possibly_invalid_spec(); |
| 126 #endif | 129 #endif |
| 127 } | 130 } |
| 128 | 131 |
| 129 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() { | 132 IPCResourceLoaderBridge::~IPCResourceLoaderBridge() { |
| 130 // we remove our hook for the resource dispatcher only when going away, since | 133 // we remove our hook for the resource dispatcher only when going away, since |
| 131 // it doesn't keep track of whether we've force terminated the request | 134 // it doesn't keep track of whether we've force terminated the request |
| (...skipping 29 matching lines...) Expand all Loading... |
| 161 if (request_id_ != -1) { | 164 if (request_id_ != -1) { |
| 162 NOTREACHED() << "Starting a request twice"; | 165 NOTREACHED() << "Starting a request twice"; |
| 163 return false; | 166 return false; |
| 164 } | 167 } |
| 165 | 168 |
| 166 RESOURCE_LOG("Starting request for " << url_); | 169 RESOURCE_LOG("Starting request for " << url_); |
| 167 | 170 |
| 168 peer_ = peer; | 171 peer_ = peer; |
| 169 | 172 |
| 170 // generate the request ID, and append it to the message | 173 // generate the request ID, and append it to the message |
| 171 request_id_ = dispatcher_->AddPendingRequest(peer_, request_.resource_type, | 174 request_id_ = dispatcher_->AddPendingRequest(peer_, request_.resource_type); |
| 172 request_.mixed_content); | |
| 173 | 175 |
| 174 return dispatcher_->message_sender()->Send( | 176 return dispatcher_->message_sender()->Send( |
| 175 new ViewHostMsg_RequestResource(route_id_, request_id_, request_)); | 177 new ViewHostMsg_RequestResource(route_id_, request_id_, request_)); |
| 176 } | 178 } |
| 177 | 179 |
| 178 void IPCResourceLoaderBridge::Cancel() { | 180 void IPCResourceLoaderBridge::Cancel() { |
| 179 if (request_id_ < 0) { | 181 if (request_id_ < 0) { |
| 180 NOTREACHED() << "Trying to cancel an unstarted request"; | 182 NOTREACHED() << "Trying to cancel an unstarted request"; |
| 181 return; | 183 return; |
| 182 } | 184 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // The request ID will be removed from our pending list in the destructor. | 434 // The request ID will be removed from our pending list in the destructor. |
| 433 // Normally, dispatching this message causes the reference-counted request to | 435 // Normally, dispatching this message causes the reference-counted request to |
| 434 // die immediately. | 436 // die immediately. |
| 435 peer->OnCompletedRequest(status, security_info); | 437 peer->OnCompletedRequest(status, security_info); |
| 436 | 438 |
| 437 webkit_glue::NotifyCacheStats(); | 439 webkit_glue::NotifyCacheStats(); |
| 438 } | 440 } |
| 439 | 441 |
| 440 int ResourceDispatcher::AddPendingRequest( | 442 int ResourceDispatcher::AddPendingRequest( |
| 441 webkit_glue::ResourceLoaderBridge::Peer* callback, | 443 webkit_glue::ResourceLoaderBridge::Peer* callback, |
| 442 ResourceType::Type resource_type, | 444 ResourceType::Type resource_type) { |
| 443 bool mixed_content) { | |
| 444 // Compute a unique request_id for this renderer process. | 445 // Compute a unique request_id for this renderer process. |
| 445 int id = MakeRequestID(); | 446 int id = MakeRequestID(); |
| 446 pending_requests_[id] = PendingRequestInfo(callback, resource_type, | 447 pending_requests_[id] = PendingRequestInfo(callback, resource_type); |
| 447 mixed_content); | |
| 448 return id; | 448 return id; |
| 449 } | 449 } |
| 450 | 450 |
| 451 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 451 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
| 452 PendingRequestList::iterator it = pending_requests_.find(request_id); | 452 PendingRequestList::iterator it = pending_requests_.find(request_id); |
| 453 if (it == pending_requests_.end()) | 453 if (it == pending_requests_.end()) |
| 454 return false; | 454 return false; |
| 455 pending_requests_.erase(it); | 455 pending_requests_.erase(it); |
| 456 return true; | 456 return true; |
| 457 } | 457 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 DispatchMessage(*m); | 501 DispatchMessage(*m); |
| 502 delete m; | 502 delete m; |
| 503 } | 503 } |
| 504 } | 504 } |
| 505 | 505 |
| 506 webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( | 506 webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge( |
| 507 const std::string& method, | 507 const std::string& method, |
| 508 const GURL& url, | 508 const GURL& url, |
| 509 const GURL& policy_url, | 509 const GURL& policy_url, |
| 510 const GURL& referrer, | 510 const GURL& referrer, |
| 511 const std::string& frame_origin, |
| 512 const std::string& main_frame_origin, |
| 511 const std::string& headers, | 513 const std::string& headers, |
| 512 int flags, | 514 int flags, |
| 513 int origin_pid, | 515 int origin_pid, |
| 514 ResourceType::Type resource_type, | 516 ResourceType::Type resource_type, |
| 515 bool mixed_content, | |
| 516 uint32 request_context, | 517 uint32 request_context, |
| 517 int route_id) { | 518 int route_id) { |
| 518 return new webkit_glue::IPCResourceLoaderBridge(this, method, url, policy_url, | 519 return new webkit_glue::IPCResourceLoaderBridge(this, method, url, policy_url, |
| 519 referrer, headers, flags, | 520 referrer, frame_origin, |
| 520 origin_pid, resource_type, | 521 main_frame_origin, headers, |
| 521 mixed_content, | 522 flags, origin_pid, |
| 522 request_context, | 523 resource_type, |
| 523 route_id); | 524 request_context, route_id); |
| 524 } | 525 } |
| 525 | 526 |
| 526 | 527 |
| 527 bool ResourceDispatcher::IsResourceMessage(const IPC::Message& message) const { | 528 bool ResourceDispatcher::IsResourceMessage(const IPC::Message& message) const { |
| 528 switch (message.type()) { | 529 switch (message.type()) { |
| 529 case ViewMsg_Resource_DownloadProgress::ID: | 530 case ViewMsg_Resource_DownloadProgress::ID: |
| 530 case ViewMsg_Resource_UploadProgress::ID: | 531 case ViewMsg_Resource_UploadProgress::ID: |
| 531 case ViewMsg_Resource_ReceivedResponse::ID: | 532 case ViewMsg_Resource_ReceivedResponse::ID: |
| 532 case ViewMsg_Resource_ReceivedRedirect::ID: | 533 case ViewMsg_Resource_ReceivedRedirect::ID: |
| 533 case ViewMsg_Resource_DataReceived::ID: | 534 case ViewMsg_Resource_DataReceived::ID: |
| 534 case ViewMsg_Resource_RequestComplete::ID: | 535 case ViewMsg_Resource_RequestComplete::ID: |
| 535 return true; | 536 return true; |
| 536 | 537 |
| 537 default: | 538 default: |
| 538 break; | 539 break; |
| 539 } | 540 } |
| 540 | 541 |
| 541 return false; | 542 return false; |
| 542 } | 543 } |
| OLD | NEW |