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" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/common/extensions/extension_message_filter_peer.h" |
15 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
16 #include "chrome/common/security_filter_peer.h" | 17 #include "chrome/common/security_filter_peer.h" |
17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
19 #include "webkit/glue/resource_type.h" | 20 #include "webkit/glue/resource_type.h" |
20 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
21 | 22 |
22 // Uncomment to enable logging of request traffic | 23 // Uncomment to enable logging of request traffic |
23 // #define LOG_RESOURCE_REQUESTS | 24 // #define LOG_RESOURCE_REQUESTS |
24 | 25 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 if (request_id_ != -1) { | 173 if (request_id_ != -1) { |
173 NOTREACHED() << "Starting a request twice"; | 174 NOTREACHED() << "Starting a request twice"; |
174 return false; | 175 return false; |
175 } | 176 } |
176 | 177 |
177 RESOURCE_LOG("Starting request for " << url_); | 178 RESOURCE_LOG("Starting request for " << url_); |
178 | 179 |
179 peer_ = peer; | 180 peer_ = peer; |
180 | 181 |
181 // generate the request ID, and append it to the message | 182 // generate the request ID, and append it to the message |
182 request_id_ = dispatcher_->AddPendingRequest(peer_, request_.resource_type); | 183 request_id_ = dispatcher_->AddPendingRequest( |
| 184 peer_, request_.resource_type, request_.url); |
183 | 185 |
184 return dispatcher_->message_sender()->Send( | 186 return dispatcher_->message_sender()->Send( |
185 new ViewHostMsg_RequestResource(routing_id_, request_id_, request_)); | 187 new ViewHostMsg_RequestResource(routing_id_, request_id_, request_)); |
186 } | 188 } |
187 | 189 |
188 void IPCResourceLoaderBridge::Cancel() { | 190 void IPCResourceLoaderBridge::Cancel() { |
189 if (request_id_ < 0) { | 191 if (request_id_ < 0) { |
190 NOTREACHED() << "Trying to cancel an unstarted request"; | 192 NOTREACHED() << "Trying to cancel an unstarted request"; |
191 return; | 193 return; |
192 } | 194 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 if (it == pending_requests_.end()) { | 325 if (it == pending_requests_.end()) { |
324 // This might happen for kill()ed requests on the webkit end, so perhaps it | 326 // This might happen for kill()ed requests on the webkit end, so perhaps it |
325 // shouldn't be a warning... | 327 // shouldn't be a warning... |
326 DLOG(WARNING) << "Got response for a nonexistant or finished request"; | 328 DLOG(WARNING) << "Got response for a nonexistant or finished request"; |
327 return; | 329 return; |
328 } | 330 } |
329 | 331 |
330 PendingRequestInfo& request_info = it->second; | 332 PendingRequestInfo& request_info = it->second; |
331 request_info.filter_policy = response_head.filter_policy; | 333 request_info.filter_policy = response_head.filter_policy; |
332 webkit_glue::ResourceLoaderBridge::Peer* peer = request_info.peer; | 334 webkit_glue::ResourceLoaderBridge::Peer* peer = request_info.peer; |
333 if (request_info.filter_policy != FilterPolicy::DONT_FILTER) { | 335 webkit_glue::ResourceLoaderBridge::Peer* new_peer = NULL; |
| 336 if (request_info.filter_policy == FilterPolicy::FILTER_EXTENSION_MESSAGES) { |
| 337 new_peer = ExtensionMessageFilterPeer::CreateExtensionMessageFilterPeer( |
| 338 peer, |
| 339 message_sender(), |
| 340 response_head.mime_type, |
| 341 request_info.filter_policy, |
| 342 request_info.url); |
| 343 } else if (request_info.filter_policy != FilterPolicy::DONT_FILTER) { |
334 // TODO(jcampan): really pass the loader bridge. | 344 // TODO(jcampan): really pass the loader bridge. |
335 webkit_glue::ResourceLoaderBridge::Peer* new_peer = | 345 new_peer = SecurityFilterPeer::CreateSecurityFilterPeer( |
336 SecurityFilterPeer::CreateSecurityFilterPeer( | 346 NULL, |
337 NULL, peer, | 347 peer, |
338 request_info.resource_type, response_head.mime_type, | 348 request_info.resource_type, |
339 request_info.filter_policy, | 349 response_head.mime_type, |
340 net::ERR_INSECURE_RESPONSE); | 350 request_info.filter_policy, |
341 if (new_peer) { | 351 net::ERR_INSECURE_RESPONSE); |
342 request_info.peer = new_peer; | 352 } |
343 peer = new_peer; | 353 |
344 } | 354 if (new_peer) { |
| 355 request_info.peer = new_peer; |
| 356 peer = new_peer; |
345 } | 357 } |
346 | 358 |
347 RESOURCE_LOG("Dispatching response for " << | 359 RESOURCE_LOG("Dispatching response for " << |
348 peer->GetURLForDebugging().possibly_invalid_spec()); | 360 peer->GetURLForDebugging().possibly_invalid_spec()); |
349 peer->OnReceivedResponse(response_head, false); | 361 peer->OnReceivedResponse(response_head, false); |
350 } | 362 } |
351 | 363 |
352 void ResourceDispatcher::OnReceivedData(const IPC::Message& message, | 364 void ResourceDispatcher::OnReceivedData(const IPC::Message& message, |
353 int request_id, | 365 int request_id, |
354 base::SharedMemoryHandle shm_handle, | 366 base::SharedMemoryHandle shm_handle, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // The request ID will be removed from our pending list in the destructor. | 457 // The request ID will be removed from our pending list in the destructor. |
446 // Normally, dispatching this message causes the reference-counted request to | 458 // Normally, dispatching this message causes the reference-counted request to |
447 // die immediately. | 459 // die immediately. |
448 peer->OnCompletedRequest(status, security_info); | 460 peer->OnCompletedRequest(status, security_info); |
449 | 461 |
450 webkit_glue::NotifyCacheStats(); | 462 webkit_glue::NotifyCacheStats(); |
451 } | 463 } |
452 | 464 |
453 int ResourceDispatcher::AddPendingRequest( | 465 int ResourceDispatcher::AddPendingRequest( |
454 webkit_glue::ResourceLoaderBridge::Peer* callback, | 466 webkit_glue::ResourceLoaderBridge::Peer* callback, |
455 ResourceType::Type resource_type) { | 467 ResourceType::Type resource_type, |
| 468 const GURL& request_url) { |
456 // Compute a unique request_id for this renderer process. | 469 // Compute a unique request_id for this renderer process. |
457 int id = MakeRequestID(); | 470 int id = MakeRequestID(); |
458 pending_requests_[id] = PendingRequestInfo(callback, resource_type); | 471 pending_requests_[id] = |
| 472 PendingRequestInfo(callback, resource_type, request_url); |
459 return id; | 473 return id; |
460 } | 474 } |
461 | 475 |
462 bool ResourceDispatcher::RemovePendingRequest(int request_id) { | 476 bool ResourceDispatcher::RemovePendingRequest(int request_id) { |
463 PendingRequestList::iterator it = pending_requests_.find(request_id); | 477 PendingRequestList::iterator it = pending_requests_.find(request_id); |
464 if (it == pending_requests_.end()) | 478 if (it == pending_requests_.end()) |
465 return false; | 479 return false; |
466 | 480 |
467 // Iterate through the deferred message queue and clean up the messages. | 481 // Iterate through the deferred message queue and clean up the messages. |
468 PendingRequestInfo& request_info = it->second; | 482 PendingRequestInfo& request_info = it->second; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 // handle or there will be a memory leak. | 605 // handle or there will be a memory leak. |
592 if (message.type() == ViewMsg_Resource_DataReceived::ID) { | 606 if (message.type() == ViewMsg_Resource_DataReceived::ID) { |
593 base::SharedMemoryHandle shm_handle; | 607 base::SharedMemoryHandle shm_handle; |
594 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, | 608 if (IPC::ParamTraits<base::SharedMemoryHandle>::Read(&message, |
595 &iter, | 609 &iter, |
596 &shm_handle)) { | 610 &shm_handle)) { |
597 base::SharedMemory::CloseHandle(shm_handle); | 611 base::SharedMemory::CloseHandle(shm_handle); |
598 } | 612 } |
599 } | 613 } |
600 } | 614 } |
OLD | NEW |