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

Side by Side Diff: webkit/glue/weburlloader_impl.cc

Issue 210027: Move FTP LIST parsing code to the renderer process. (Closed)
Patch Set: fixes Created 11 years, 3 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge.
6 6
7 #include "webkit/glue/weburlloader_impl.h" 7 #include "webkit/glue/weburlloader_impl.h"
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "net/base/data_url.h" 13 #include "net/base/data_url.h"
14 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
18 #include "webkit/api/public/WebHTTPHeaderVisitor.h" 18 #include "webkit/api/public/WebHTTPHeaderVisitor.h"
19 #include "webkit/api/public/WebURL.h" 19 #include "webkit/api/public/WebURL.h"
20 #include "webkit/api/public/WebURLError.h" 20 #include "webkit/api/public/WebURLError.h"
21 #include "webkit/api/public/WebURLLoaderClient.h" 21 #include "webkit/api/public/WebURLLoaderClient.h"
22 #include "webkit/api/public/WebURLRequest.h" 22 #include "webkit/api/public/WebURLRequest.h"
23 #include "webkit/api/public/WebURLResponse.h" 23 #include "webkit/api/public/WebURLResponse.h"
24 #include "webkit/glue/ftp_directory_listing_response_delegate.h"
24 #include "webkit/glue/glue_util.h" 25 #include "webkit/glue/glue_util.h"
25 #include "webkit/glue/multipart_response_delegate.h" 26 #include "webkit/glue/multipart_response_delegate.h"
26 #include "webkit/glue/resource_loader_bridge.h" 27 #include "webkit/glue/resource_loader_bridge.h"
27 #include "webkit/glue/webkit_glue.h" 28 #include "webkit/glue/webkit_glue.h"
28 29
29 using base::Time; 30 using base::Time;
30 using base::TimeDelta; 31 using base::TimeDelta;
31 using WebKit::WebData; 32 using WebKit::WebData;
32 using WebKit::WebHTTPBody; 33 using WebKit::WebHTTPBody;
33 using WebKit::WebHTTPHeaderVisitor; 34 using WebKit::WebHTTPHeaderVisitor;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 private: 219 private:
219 friend class base::RefCounted<Context>; 220 friend class base::RefCounted<Context>;
220 ~Context() {} 221 ~Context() {}
221 222
222 void HandleDataURL(); 223 void HandleDataURL();
223 224
224 WebURLLoaderImpl* loader_; 225 WebURLLoaderImpl* loader_;
225 WebURLRequest request_; 226 WebURLRequest request_;
226 WebURLLoaderClient* client_; 227 WebURLLoaderClient* client_;
227 scoped_ptr<ResourceLoaderBridge> bridge_; 228 scoped_ptr<ResourceLoaderBridge> bridge_;
229 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
228 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 230 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
229 int64 expected_content_length_; 231 int64 expected_content_length_;
230 }; 232 };
231 233
232 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) 234 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader)
233 : loader_(loader), 235 : loader_(loader),
234 client_(NULL) { 236 client_(NULL) {
235 } 237 }
236 238
237 void WebURLLoaderImpl::Context::Cancel() { 239 void WebURLLoaderImpl::Context::Cancel() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (!client_) 422 if (!client_)
421 return; 423 return;
422 424
423 WebURLResponse response; 425 WebURLResponse response;
424 response.initialize(); 426 response.initialize();
425 PopulateURLResponse(request_.url(), info, &response); 427 PopulateURLResponse(request_.url(), info, &response);
426 response.setIsContentFiltered(content_filtered); 428 response.setIsContentFiltered(content_filtered);
427 429
428 expected_content_length_ = response.expectedContentLength(); 430 expected_content_length_ = response.expectedContentLength();
429 431
432 if (info.mime_type == "text/vnd.chromium.ftp-dir")
eroman 2009/09/23 21:14:49 I am still not convinced that we want to expose th
433 response.setMIMEType(WebString::fromUTF8("text/html"));
eroman 2009/09/23 21:14:49 should we additionally specify the charset? Or is
434
430 client_->didReceiveResponse(loader_, response); 435 client_->didReceiveResponse(loader_, response);
431 436
432 // we may have been cancelled after didReceiveResponse, which would leave us 437 // We may have been cancelled after didReceiveResponse, which would leave us
433 // without a client and therefore without much need to do multipart handling. 438 // without a client and therefore without much need to do further handling.
434 if (!client_) 439 if (!client_)
435 return; 440 return;
436 441
442 DCHECK(!ftp_listing_delegate_.get());
437 DCHECK(!multipart_delegate_.get()); 443 DCHECK(!multipart_delegate_.get());
438 if (info.headers && info.mime_type == "multipart/x-mixed-replace") { 444 if (info.headers && info.mime_type == "multipart/x-mixed-replace") {
439 std::string content_type; 445 std::string content_type;
440 info.headers->EnumerateHeader(NULL, "content-type", &content_type); 446 info.headers->EnumerateHeader(NULL, "content-type", &content_type);
441 447
442 std::string boundary = net::GetHeaderParamValue(content_type, "boundary"); 448 std::string boundary = net::GetHeaderParamValue(content_type, "boundary");
443 TrimString(boundary, " \"", &boundary); 449 TrimString(boundary, " \"", &boundary);
444 450
445 // If there's no boundary, just handle the request normally. In the gecko 451 // If there's no boundary, just handle the request normally. In the gecko
446 // code, nsMultiMixedConv::OnStartRequest throws an exception. 452 // code, nsMultiMixedConv::OnStartRequest throws an exception.
447 if (!boundary.empty()) { 453 if (!boundary.empty()) {
448 multipart_delegate_.reset( 454 multipart_delegate_.reset(
449 new MultipartResponseDelegate(client_, loader_, response, boundary)); 455 new MultipartResponseDelegate(client_, loader_, response, boundary));
450 } 456 }
457 } else if (info.mime_type == "text/vnd.chromium.ftp-dir") {
458 ftp_listing_delegate_.reset(
459 new FtpDirectoryListingResponseDelegate(client_, loader_, response));
451 } 460 }
452 } 461 }
453 462
454 void WebURLLoaderImpl::Context::OnReceivedData(const char* data, int len) { 463 void WebURLLoaderImpl::Context::OnReceivedData(const char* data, int len) {
455 if (!client_) 464 if (!client_)
456 return; 465 return;
457 466
458 if (multipart_delegate_.get()) { 467 if (ftp_listing_delegate_.get()) {
468 // The FTP listing delegate will make the appropriate calls to
469 // client_->didReceiveData and client_->didReceiveResponse.
470 ftp_listing_delegate_->OnReceivedData(data, len);
471 } else if (multipart_delegate_.get()) {
459 // The multipart delegate will make the appropriate calls to 472 // The multipart delegate will make the appropriate calls to
460 // client_->didReceiveData and client_->didReceiveResponse. 473 // client_->didReceiveData and client_->didReceiveResponse.
461 multipart_delegate_->OnReceivedData(data, len); 474 multipart_delegate_->OnReceivedData(data, len);
462 } else { 475 } else {
463 client_->didReceiveData(loader_, data, len, expected_content_length_); 476 client_->didReceiveData(loader_, data, len, expected_content_length_);
464 } 477 }
465 } 478 }
466 479
467 void WebURLLoaderImpl::Context::OnCompletedRequest( 480 void WebURLLoaderImpl::Context::OnCompletedRequest(
468 const URLRequestStatus& status, 481 const URLRequestStatus& status,
469 const std::string& security_info) { 482 const std::string& security_info) {
470 if (multipart_delegate_.get()) { 483 if (ftp_listing_delegate_.get()) {
484 ftp_listing_delegate_->OnCompletedRequest();
485 ftp_listing_delegate_.reset(NULL);
486 } else if (multipart_delegate_.get()) {
471 multipart_delegate_->OnCompletedRequest(); 487 multipart_delegate_->OnCompletedRequest();
472 multipart_delegate_.reset(NULL); 488 multipart_delegate_.reset(NULL);
473 } 489 }
474 490
475 // Prevent any further IPC to the browser now that we're complete. 491 // Prevent any further IPC to the browser now that we're complete.
476 bridge_.reset(); 492 bridge_.reset();
477 493
478 if (client_) { 494 if (client_) {
479 if (status.status() != URLRequestStatus::SUCCESS) { 495 if (status.status() != URLRequestStatus::SUCCESS) {
480 int error_code; 496 int error_code;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 582
567 void WebURLLoaderImpl::cancel() { 583 void WebURLLoaderImpl::cancel() {
568 context_->Cancel(); 584 context_->Cancel();
569 } 585 }
570 586
571 void WebURLLoaderImpl::setDefersLoading(bool value) { 587 void WebURLLoaderImpl::setDefersLoading(bool value) {
572 context_->SetDefersLoading(value); 588 context_->SetDefersLoading(value);
573 } 589 }
574 590
575 } // namespace webkit_glue 591 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698