From 8ac34699f6ca5b92fa20d8fd3e76ce3bb35a888d Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 27 Aug 2013 19:16:24 +0000 Subject: [PATCH] Make CefURLRequest::GetResponse() data available before download completion (issue #956). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1418 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser/browser_urlrequest_impl.cc | 32 ++++++++++++++++------- tests/unittests/urlrequest_unittest.cc | 6 +++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/libcef/browser/browser_urlrequest_impl.cc b/libcef/browser/browser_urlrequest_impl.cc index 9261b8d49..d5e1b1507 100644 --- a/libcef/browser/browser_urlrequest_impl.cc +++ b/libcef/browser/browser_urlrequest_impl.cc @@ -264,15 +264,8 @@ class CefBrowserURLRequest::Context error_code_ = static_cast(status.error()); - response_ = new CefResponseImpl(); - CefResponseImpl* responseImpl = - static_cast(response_.get()); - - net::HttpResponseHeaders* headers = fetcher_->GetResponseHeaders(); - if (headers) - responseImpl->SetResponseHeaders(*headers); - - responseImpl->SetReadOnly(true); + if(!response_.get()) + OnResponse(); } DCHECK(url_request_.get()); @@ -289,6 +282,9 @@ class CefBrowserURLRequest::Context DCHECK(CalledOnValidThread()); DCHECK(url_request_.get()); + if(!response_.get()) + OnResponse(); + NotifyUploadProgressIfNecessary(); client_->OnDownloadProgress(url_request_.get(), current, total); @@ -297,6 +293,10 @@ class CefBrowserURLRequest::Context void OnDownloadData(scoped_ptr download_data) { DCHECK(CalledOnValidThread()); DCHECK(url_request_.get()); + + if(!response_.get()) + OnResponse(); + client_->OnDownloadData(url_request_.get(), download_data->c_str(), download_data->length()); } @@ -327,6 +327,20 @@ class CefBrowserURLRequest::Context } } + void OnResponse() { + if (fetcher_.get()) { + response_ = new CefResponseImpl(); + CefResponseImpl* responseImpl = + static_cast(response_.get()); + + net::HttpResponseHeaders* headers = fetcher_->GetResponseHeaders(); + if (headers) + responseImpl->SetResponseHeaders(*headers); + + responseImpl->SetReadOnly(true); + } + } + // Members only accessed on the initialization thread. CefRefPtr url_request_; CefRefPtr request_; diff --git a/tests/unittests/urlrequest_unittest.cc b/tests/unittests/urlrequest_unittest.cc index a690e69d5..22c8eaa26 100644 --- a/tests/unittests/urlrequest_unittest.cc +++ b/tests/unittests/urlrequest_unittest.cc @@ -436,6 +436,9 @@ class RequestClient : public CefURLRequestClient { virtual void OnDownloadProgress(CefRefPtr request, uint64 current, uint64 total) OVERRIDE { + response_ = request->GetResponse(); + EXPECT_TRUE(response_); + EXPECT_TRUE(response_->IsReadOnly()); download_progress_ct_++; download_total_ = total; } @@ -443,6 +446,9 @@ class RequestClient : public CefURLRequestClient { virtual void OnDownloadData(CefRefPtr request, const void* data, size_t data_length) OVERRIDE { + response_ = request->GetResponse(); + EXPECT_TRUE(response_); + EXPECT_TRUE(response_->IsReadOnly()); download_data_ct_++; download_data_ += std::string(static_cast(data), data_length); }