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

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

Issue 10640019: Remove the HANDLED_EXTERNALLY status code. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: revert removing DCHECK from URLRequest::DoCancel Created 8 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 // 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/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 private: 115 private:
116 int load_flags_; 116 int load_flags_;
117 std::string buffer_; 117 std::string buffer_;
118 bool has_accept_header_; 118 bool has_accept_header_;
119 }; 119 };
120 120
121 // Extracts the information from a data: url. 121 // Extracts the information from a data: url.
122 bool GetInfoFromDataURL(const GURL& url, 122 bool GetInfoFromDataURL(const GURL& url,
123 ResourceResponseInfo* info, 123 ResourceResponseInfo* info,
124 std::string* data, 124 std::string* data,
125 net::URLRequestStatus* status) { 125 int* error_code) {
126 std::string mime_type; 126 std::string mime_type;
127 std::string charset; 127 std::string charset;
128 if (net::DataURL::Parse(url, &mime_type, &charset, data)) { 128 if (net::DataURL::Parse(url, &mime_type, &charset, data)) {
129 *status = net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0); 129 *error_code = net::OK;
130 // Assure same time for all time fields of data: URLs. 130 // Assure same time for all time fields of data: URLs.
131 Time now = Time::Now(); 131 Time now = Time::Now();
132 info->load_timing.base_time = now; 132 info->load_timing.base_time = now;
133 info->load_timing.base_ticks = TimeTicks::Now(); 133 info->load_timing.base_ticks = TimeTicks::Now();
134 info->request_time = now; 134 info->request_time = now;
135 info->response_time = now; 135 info->response_time = now;
136 info->headers = NULL; 136 info->headers = NULL;
137 info->mime_type.swap(mime_type); 137 info->mime_type.swap(mime_type);
138 info->charset.swap(charset); 138 info->charset.swap(charset);
139 info->security_info.clear(); 139 info->security_info.clear();
140 info->content_length = data->length(); 140 info->content_length = data->length();
141 info->encoded_data_length = 0; 141 info->encoded_data_length = 0;
142 142
143 return true; 143 return true;
144 } 144 }
145 145
146 *status = net::URLRequestStatus(net::URLRequestStatus::FAILED, 146 *error_code = net::ERR_INVALID_URL;
147 net::ERR_INVALID_URL);
148 return false; 147 return false;
149 } 148 }
150 149
151 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; 150 typedef ResourceDevToolsInfo::HeadersVector HeadersVector;
152 151
153 void PopulateURLResponse( 152 void PopulateURLResponse(
154 const GURL& url, 153 const GURL& url,
155 const ResourceResponseInfo& info, 154 const ResourceResponseInfo& info,
156 WebURLResponse* response) { 155 WebURLResponse* response) {
157 response->setURL(url); 156 response->setURL(url);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 const GURL& new_url, 290 const GURL& new_url,
292 const ResourceResponseInfo& info, 291 const ResourceResponseInfo& info,
293 bool* has_new_first_party_for_cookies, 292 bool* has_new_first_party_for_cookies,
294 GURL* new_first_party_for_cookies); 293 GURL* new_first_party_for_cookies);
295 virtual void OnReceivedResponse(const ResourceResponseInfo& info); 294 virtual void OnReceivedResponse(const ResourceResponseInfo& info);
296 virtual void OnDownloadedData(int len); 295 virtual void OnDownloadedData(int len);
297 virtual void OnReceivedData(const char* data, 296 virtual void OnReceivedData(const char* data,
298 int data_length, 297 int data_length,
299 int encoded_data_length); 298 int encoded_data_length);
300 virtual void OnReceivedCachedMetadata(const char* data, int len); 299 virtual void OnReceivedCachedMetadata(const char* data, int len);
301 virtual void OnCompletedRequest(const net::URLRequestStatus& status, 300 virtual void OnCompletedRequest(int error_code,
301 bool is_handled_externally,
302 const std::string& security_info, 302 const std::string& security_info,
303 const base::TimeTicks& completion_time); 303 const base::TimeTicks& completion_time);
304 304
305 private: 305 private:
306 friend class base::RefCounted<Context>; 306 friend class base::RefCounted<Context>;
307 ~Context() {} 307 ~Context() {}
308 308
309 // We can optimize the handling of data URLs in most cases. 309 // We can optimize the handling of data URLs in most cases.
310 bool CanHandleDataURL(const GURL& url) const; 310 bool CanHandleDataURL(const GURL& url) const;
311 void HandleDataURL(); 311 void HandleDataURL();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 request_ = request; // Save the request. 356 request_ = request; // Save the request.
357 357
358 GURL url = request.url(); 358 GURL url = request.url();
359 if (url.SchemeIs("data") && CanHandleDataURL(url)) { 359 if (url.SchemeIs("data") && CanHandleDataURL(url)) {
360 if (sync_load_response) { 360 if (sync_load_response) {
361 // This is a sync load. Do the work now. 361 // This is a sync load. Do the work now.
362 sync_load_response->url = url; 362 sync_load_response->url = url;
363 std::string data; 363 std::string data;
364 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 364 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
365 &sync_load_response->data, 365 &sync_load_response->data,
366 &sync_load_response->status); 366 &sync_load_response->error_code);
367 } else { 367 } else {
368 AddRef(); // Balanced in OnCompletedRequest 368 AddRef(); // Balanced in OnCompletedRequest
369 MessageLoop::current()->PostTask(FROM_HERE, 369 MessageLoop::current()->PostTask(FROM_HERE,
370 base::Bind(&Context::HandleDataURL, this)); 370 base::Bind(&Context::HandleDataURL, this));
371 } 371 }
372 return; 372 return;
373 } 373 }
374 374
375 GURL referrer_url( 375 GURL referrer_url(
376 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); 376 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8());
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 616 }
617 } 617 }
618 618
619 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( 619 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata(
620 const char* data, int len) { 620 const char* data, int len) {
621 if (client_) 621 if (client_)
622 client_->didReceiveCachedMetadata(loader_, data, len); 622 client_->didReceiveCachedMetadata(loader_, data, len);
623 } 623 }
624 624
625 void WebURLLoaderImpl::Context::OnCompletedRequest( 625 void WebURLLoaderImpl::Context::OnCompletedRequest(
626 const net::URLRequestStatus& status, 626 int error_code,
627 bool is_handled_externally,
627 const std::string& security_info, 628 const std::string& security_info,
628 const base::TimeTicks& completion_time) { 629 const base::TimeTicks& completion_time) {
629 if (ftp_listing_delegate_.get()) { 630 if (ftp_listing_delegate_.get()) {
630 ftp_listing_delegate_->OnCompletedRequest(); 631 ftp_listing_delegate_->OnCompletedRequest();
631 ftp_listing_delegate_.reset(NULL); 632 ftp_listing_delegate_.reset(NULL);
632 } else if (multipart_delegate_.get()) { 633 } else if (multipart_delegate_.get()) {
633 multipart_delegate_->OnCompletedRequest(); 634 multipart_delegate_->OnCompletedRequest();
634 multipart_delegate_.reset(NULL); 635 multipart_delegate_.reset(NULL);
635 } 636 }
636 637
637 // Prevent any further IPC to the browser now that we're complete, but 638 // Prevent any further IPC to the browser now that we're complete, but
638 // don't delete it to keep any downloaded temp files alive. 639 // don't delete it to keep any downloaded temp files alive.
639 DCHECK(!completed_bridge_.get()); 640 DCHECK(!completed_bridge_.get());
640 completed_bridge_.swap(bridge_); 641 completed_bridge_.swap(bridge_);
641 642
642 if (client_) { 643 if (client_) {
643 if (status.status() != net::URLRequestStatus::SUCCESS) { 644 if (!net::IsSuccess(error_code) || is_handled_externally) {
darin (slow to review) 2012/08/10 18:03:02 I think you should just compare error_code against
mkosiba (inactive) 2012/08/29 15:53:01 Positive error codes support was dropped in one of
644 int error_code;
645 if (status.status() == net::URLRequestStatus::HANDLED_EXTERNALLY) {
646 // By marking this request as aborted we insure that we don't navigate
647 // to an error page.
648 error_code = net::ERR_ABORTED;
649 } else {
650 error_code = status.error();
651 }
652 WebURLError error; 645 WebURLError error;
653 if (error_code == net::ERR_ABORTED) { 646 if (error_code == net::ERR_ABORTED) {
654 error.isCancellation = true; 647 error.isCancellation = true;
655 } else if (error_code == net::ERR_TEMPORARILY_THROTTLED) { 648 } else if (error_code == net::ERR_TEMPORARILY_THROTTLED) {
656 error.localizedDescription = WebString::fromUTF8( 649 error.localizedDescription = WebString::fromUTF8(
657 kThrottledErrorDescription); 650 kThrottledErrorDescription);
658 } 651 }
659 error.domain = WebString::fromUTF8(net::kErrorDomain); 652 error.domain = WebString::fromUTF8(net::kErrorDomain);
660 error.reason = error_code; 653 error.reason = error_code;
661 error.unreachableURL = request_.url(); 654 error.unreachableURL = request_.url();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 std::string mime_type, unused_charset; 690 std::string mime_type, unused_charset;
698 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && 691 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) &&
699 net::IsSupportedMimeType(mime_type)) 692 net::IsSupportedMimeType(mime_type))
700 return true; 693 return true;
701 694
702 return false; 695 return false;
703 } 696 }
704 697
705 void WebURLLoaderImpl::Context::HandleDataURL() { 698 void WebURLLoaderImpl::Context::HandleDataURL() {
706 ResourceResponseInfo info; 699 ResourceResponseInfo info;
707 net::URLRequestStatus status; 700 int error_code;
708 std::string data; 701 std::string data;
709 702
710 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { 703 if (GetInfoFromDataURL(request_.url(), &info, &data, &error_code)) {
711 OnReceivedResponse(info); 704 OnReceivedResponse(info);
712 if (!data.empty()) 705 if (!data.empty())
713 OnReceivedData(data.data(), data.size(), 0); 706 OnReceivedData(data.data(), data.size(), 0);
714 } 707 }
715 708
716 OnCompletedRequest(status, info.security_info, base::TimeTicks::Now()); 709 OnCompletedRequest(error_code, false, info.security_info,
710 base::TimeTicks::Now());
717 } 711 }
718 712
719 // WebURLLoaderImpl ----------------------------------------------------------- 713 // WebURLLoaderImpl -----------------------------------------------------------
720 714
721 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) 715 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform)
722 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), 716 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))),
723 platform_(platform) { 717 platform_(platform) {
724 } 718 }
725 719
726 WebURLLoaderImpl::~WebURLLoaderImpl() { 720 WebURLLoaderImpl::~WebURLLoaderImpl() {
727 cancel(); 721 cancel();
728 } 722 }
729 723
730 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, 724 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request,
731 WebURLResponse& response, 725 WebURLResponse& response,
732 WebURLError& error, 726 WebURLError& error,
733 WebData& data) { 727 WebData& data) {
734 ResourceLoaderBridge::SyncLoadResponse sync_load_response; 728 ResourceLoaderBridge::SyncLoadResponse sync_load_response;
735 context_->Start(request, &sync_load_response, platform_); 729 context_->Start(request, &sync_load_response, platform_);
736 730
737 const GURL& final_url = sync_load_response.url; 731 const GURL& final_url = sync_load_response.url;
738 732
739 // TODO(tc): For file loads, we may want to include a more descriptive 733 // TODO(tc): For file loads, we may want to include a more descriptive
740 // status code or status text. 734 // status code or status text.
741 const net::URLRequestStatus::Status& status = 735 int error_code = sync_load_response.error_code;
742 sync_load_response.status.status(); 736 if (!net::IsSuccess(error_code)) {
743 if (status != net::URLRequestStatus::SUCCESS &&
744 status != net::URLRequestStatus::HANDLED_EXTERNALLY) {
745 response.setURL(final_url); 737 response.setURL(final_url);
746 error.domain = WebString::fromUTF8(net::kErrorDomain); 738 error.domain = WebString::fromUTF8(net::kErrorDomain);
747 error.reason = sync_load_response.status.error(); 739 error.reason = error_code;
748 error.unreachableURL = final_url; 740 error.unreachableURL = final_url;
749 return; 741 return;
750 } 742 }
751 743
752 PopulateURLResponse(final_url, sync_load_response, &response); 744 PopulateURLResponse(final_url, sync_load_response, &response);
753 745
754 data.assign(sync_load_response.data.data(), 746 data.assign(sync_load_response.data.data(),
755 sync_load_response.data.size()); 747 sync_load_response.data.size());
756 } 748 }
757 749
758 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, 750 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request,
759 WebURLLoaderClient* client) { 751 WebURLLoaderClient* client) {
760 DCHECK(!context_->client()); 752 DCHECK(!context_->client());
761 753
762 context_->set_client(client); 754 context_->set_client(client);
763 context_->Start(request, NULL, platform_); 755 context_->Start(request, NULL, platform_);
764 } 756 }
765 757
766 void WebURLLoaderImpl::cancel() { 758 void WebURLLoaderImpl::cancel() {
767 context_->Cancel(); 759 context_->Cancel();
768 } 760 }
769 761
770 void WebURLLoaderImpl::setDefersLoading(bool value) { 762 void WebURLLoaderImpl::setDefersLoading(bool value) {
771 context_->SetDefersLoading(value); 763 context_->SetDefersLoading(value);
772 } 764 }
773 765
774 } // namespace webkit_glue 766 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698