Merge revision 1418 changes:

- Make CefURLRequest::GetResponse() data available before download completion (issue #956).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1547@1419 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-08-27 19:17:12 +00:00
parent 65694f4b3b
commit 0f3da5f36b
2 changed files with 29 additions and 9 deletions

View File

@ -264,15 +264,8 @@ class CefBrowserURLRequest::Context
error_code_ = static_cast<CefURLRequest::ErrorCode>(status.error()); error_code_ = static_cast<CefURLRequest::ErrorCode>(status.error());
response_ = new CefResponseImpl(); if(!response_.get())
CefResponseImpl* responseImpl = OnResponse();
static_cast<CefResponseImpl*>(response_.get());
net::HttpResponseHeaders* headers = fetcher_->GetResponseHeaders();
if (headers)
responseImpl->SetResponseHeaders(*headers);
responseImpl->SetReadOnly(true);
} }
DCHECK(url_request_.get()); DCHECK(url_request_.get());
@ -289,6 +282,9 @@ class CefBrowserURLRequest::Context
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(url_request_.get()); DCHECK(url_request_.get());
if(!response_.get())
OnResponse();
NotifyUploadProgressIfNecessary(); NotifyUploadProgressIfNecessary();
client_->OnDownloadProgress(url_request_.get(), current, total); client_->OnDownloadProgress(url_request_.get(), current, total);
@ -297,6 +293,10 @@ class CefBrowserURLRequest::Context
void OnDownloadData(scoped_ptr<std::string> download_data) { void OnDownloadData(scoped_ptr<std::string> download_data) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(url_request_.get()); DCHECK(url_request_.get());
if(!response_.get())
OnResponse();
client_->OnDownloadData(url_request_.get(), download_data->c_str(), client_->OnDownloadData(url_request_.get(), download_data->c_str(),
download_data->length()); download_data->length());
} }
@ -327,6 +327,20 @@ class CefBrowserURLRequest::Context
} }
} }
void OnResponse() {
if (fetcher_.get()) {
response_ = new CefResponseImpl();
CefResponseImpl* responseImpl =
static_cast<CefResponseImpl*>(response_.get());
net::HttpResponseHeaders* headers = fetcher_->GetResponseHeaders();
if (headers)
responseImpl->SetResponseHeaders(*headers);
responseImpl->SetReadOnly(true);
}
}
// Members only accessed on the initialization thread. // Members only accessed on the initialization thread.
CefRefPtr<CefBrowserURLRequest> url_request_; CefRefPtr<CefBrowserURLRequest> url_request_;
CefRefPtr<CefRequest> request_; CefRefPtr<CefRequest> request_;

View File

@ -436,6 +436,9 @@ class RequestClient : public CefURLRequestClient {
virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request, virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request,
uint64 current, uint64 current,
uint64 total) OVERRIDE { uint64 total) OVERRIDE {
response_ = request->GetResponse();
EXPECT_TRUE(response_);
EXPECT_TRUE(response_->IsReadOnly());
download_progress_ct_++; download_progress_ct_++;
download_total_ = total; download_total_ = total;
} }
@ -443,6 +446,9 @@ class RequestClient : public CefURLRequestClient {
virtual void OnDownloadData(CefRefPtr<CefURLRequest> request, virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
const void* data, const void* data,
size_t data_length) OVERRIDE { size_t data_length) OVERRIDE {
response_ = request->GetResponse();
EXPECT_TRUE(response_);
EXPECT_TRUE(response_->IsReadOnly());
download_data_ct_++; download_data_ct_++;
download_data_ += std::string(static_cast<const char*>(data), data_length); download_data_ += std::string(static_cast<const char*>(data), data_length);
} }