2012-06-19 18:29:49 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_urlrequest_impl.h"
|
|
|
|
|
|
|
|
#include <string>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
#include "libcef/browser/browser_context.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_user_data.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/request_context_impl.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/common/request_impl.h"
|
|
|
|
#include "libcef/common/response_impl.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "content/public/common/url_fetcher.h"
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "net/base/io_buffer.h"
|
|
|
|
#include "net/base/net_errors.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "net/http/http_response_headers.h"
|
2012-08-04 02:59:58 +02:00
|
|
|
#include "net/url_request/url_fetcher.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "net/url_request/url_fetcher_delegate.h"
|
2013-10-29 18:53:18 +01:00
|
|
|
#include "net/url_request/url_fetcher_response_writer.h"
|
2012-06-19 18:29:49 +02:00
|
|
|
#include "net/url_request/url_request_status.h"
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
using content::BrowserThread;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CefURLFetcherDelegate : public net::URLFetcherDelegate {
|
|
|
|
public:
|
|
|
|
CefURLFetcherDelegate(CefBrowserURLRequest::Context* context,
|
|
|
|
int request_flags);
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefURLFetcherDelegate() override;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
// net::URLFetcherDelegate methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnURLFetchComplete(const net::URLFetcher* source) override;
|
|
|
|
void OnURLFetchDownloadProgress(const net::URLFetcher* source,
|
2016-10-21 21:52:29 +02:00
|
|
|
int64 current,
|
|
|
|
int64 total,
|
|
|
|
int64_t current_network_bytes) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void OnURLFetchUploadProgress(const net::URLFetcher* source,
|
|
|
|
int64 current, int64 total) override;
|
2012-06-19 18:29:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// The context_ pointer will outlive this object.
|
|
|
|
CefBrowserURLRequest::Context* context_;
|
|
|
|
int request_flags_;
|
|
|
|
};
|
|
|
|
|
2013-10-29 18:53:18 +01:00
|
|
|
class NET_EXPORT CefURLFetcherResponseWriter :
|
|
|
|
public net::URLFetcherResponseWriter {
|
|
|
|
public:
|
|
|
|
CefURLFetcherResponseWriter(
|
|
|
|
CefRefPtr<CefBrowserURLRequest> url_request,
|
2015-07-24 02:06:56 +02:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner)
|
2013-10-29 18:53:18 +01:00
|
|
|
: url_request_(url_request),
|
2015-07-24 02:06:56 +02:00
|
|
|
task_runner_(task_runner) {
|
2013-10-29 18:53:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// net::URLFetcherResponseWriter methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
int Initialize(const net::CompletionCallback& callback) override {
|
2013-10-29 18:53:18 +01:00
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
int Write(net::IOBuffer* buffer,
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) override {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (url_request_.get()) {
|
2015-07-24 02:06:56 +02:00
|
|
|
task_runner_->PostTask(FROM_HERE,
|
2013-10-29 18:53:18 +01:00
|
|
|
base::Bind(&CefURLFetcherResponseWriter::WriteOnClientThread,
|
2013-10-29 20:14:52 +01:00
|
|
|
url_request_, scoped_refptr<net::IOBuffer>(buffer),
|
|
|
|
num_bytes, callback,
|
2015-07-24 02:06:56 +02:00
|
|
|
base::MessageLoop::current()->task_runner()));
|
2013-10-29 18:53:18 +01:00
|
|
|
return net::ERR_IO_PENDING;
|
|
|
|
}
|
|
|
|
return num_bytes;
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
int Finish(int net_error, const net::CompletionCallback& callback) override {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (url_request_.get())
|
2013-10-29 18:53:18 +01:00
|
|
|
url_request_ = NULL;
|
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void WriteOnClientThread(
|
|
|
|
CefRefPtr<CefBrowserURLRequest> url_request,
|
2013-10-29 20:14:52 +01:00
|
|
|
scoped_refptr<net::IOBuffer> buffer,
|
2013-10-29 18:53:18 +01:00
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback,
|
2015-07-24 02:06:56 +02:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> source_message_loop_proxy) {
|
2013-10-29 18:53:18 +01:00
|
|
|
CefRefPtr<CefURLRequestClient> client = url_request->GetClient();
|
2014-09-27 01:48:19 +02:00
|
|
|
if (client.get())
|
2013-10-29 18:53:18 +01:00
|
|
|
client->OnDownloadData(url_request.get(), buffer->data(), num_bytes);
|
|
|
|
|
|
|
|
source_message_loop_proxy->PostTask(FROM_HERE,
|
|
|
|
base::Bind(&CefURLFetcherResponseWriter::ContinueOnSourceThread,
|
|
|
|
num_bytes, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ContinueOnSourceThread(
|
|
|
|
int num_bytes,
|
|
|
|
const net::CompletionCallback& callback) {
|
|
|
|
callback.Run(num_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserURLRequest> url_request_;
|
2015-07-24 02:06:56 +02:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
2013-10-29 18:53:18 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefURLFetcherResponseWriter);
|
|
|
|
};
|
|
|
|
|
2013-08-27 20:58:08 +02:00
|
|
|
base::SupportsUserData::Data* CreateURLRequestUserData(
|
|
|
|
CefRefPtr<CefURLRequestClient> client) {
|
|
|
|
return new CefURLRequestUserData(client);
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
// CefBrowserURLRequest::Context ----------------------------------------------
|
|
|
|
|
|
|
|
class CefBrowserURLRequest::Context
|
|
|
|
: public base::RefCountedThreadSafe<CefBrowserURLRequest::Context> {
|
|
|
|
public:
|
|
|
|
Context(CefRefPtr<CefBrowserURLRequest> url_request,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefURLRequestClient> client,
|
|
|
|
CefRefPtr<CefRequestContext> request_context)
|
2012-06-19 18:29:49 +02:00
|
|
|
: url_request_(url_request),
|
|
|
|
request_(request),
|
|
|
|
client_(client),
|
2015-03-02 21:25:14 +01:00
|
|
|
request_context_(request_context),
|
2015-07-24 02:06:56 +02:00
|
|
|
task_runner_(base::MessageLoop::current()->task_runner()),
|
2012-06-19 18:29:49 +02:00
|
|
|
status_(UR_IO_PENDING),
|
|
|
|
error_code_(ERR_NONE),
|
|
|
|
upload_data_size_(0),
|
|
|
|
got_upload_progress_complete_(false) {
|
|
|
|
// Mark the request as read-only.
|
|
|
|
static_cast<CefRequestImpl*>(request_.get())->SetReadOnly(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool CalledOnValidThread() {
|
2015-07-24 02:06:56 +02:00
|
|
|
return task_runner_->RunsTasksOnCurrentThread();
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Start() {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
|
2015-08-26 00:33:31 +02:00
|
|
|
const GURL& url = GURL(request_->GetURL().ToString());
|
2012-06-19 18:29:49 +02:00
|
|
|
if (!url.is_valid())
|
|
|
|
return false;
|
|
|
|
|
2015-08-26 00:33:31 +02:00
|
|
|
const std::string& method =
|
|
|
|
base::ToLowerASCII(request_->GetMethod().ToString());
|
2012-06-19 18:29:49 +02:00
|
|
|
net::URLFetcher::RequestType request_type = net::URLFetcher::GET;
|
2015-07-24 02:06:56 +02:00
|
|
|
if (base::LowerCaseEqualsASCII(method, "get")) {
|
|
|
|
} else if (base::LowerCaseEqualsASCII(method, "post")) {
|
2012-06-19 18:29:49 +02:00
|
|
|
request_type = net::URLFetcher::POST;
|
2015-07-24 02:06:56 +02:00
|
|
|
} else if (base::LowerCaseEqualsASCII(method, "head")) {
|
2012-06-19 18:29:49 +02:00
|
|
|
request_type = net::URLFetcher::HEAD;
|
2015-07-24 02:06:56 +02:00
|
|
|
} else if (base::LowerCaseEqualsASCII(method, "delete")) {
|
2012-06-19 18:29:49 +02:00
|
|
|
request_type = net::URLFetcher::DELETE_REQUEST;
|
2015-07-24 02:06:56 +02:00
|
|
|
} else if (base::LowerCaseEqualsASCII(method, "put")) {
|
2012-06-19 18:29:49 +02:00
|
|
|
request_type = net::URLFetcher::PUT;
|
|
|
|
} else {
|
|
|
|
NOTREACHED() << "invalid request type";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
BrowserThread::PostTaskAndReply(
|
|
|
|
BrowserThread::UI,
|
|
|
|
FROM_HERE,
|
|
|
|
base::Bind(&CefBrowserURLRequest::Context::GetRequestContextOnUIThread,
|
|
|
|
this),
|
|
|
|
base::Bind(&CefBrowserURLRequest::Context::ContinueOnOriginatingThread,
|
|
|
|
this, url, request_type));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetRequestContextOnUIThread() {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
|
|
|
|
// Get or create the request context and browser context.
|
|
|
|
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
2017-02-14 23:27:19 +01:00
|
|
|
CefRequestContextImpl::GetOrCreateForRequestContext(request_context_);
|
2015-03-02 21:25:14 +01:00
|
|
|
DCHECK(request_context_impl.get());
|
2017-02-14 23:27:19 +01:00
|
|
|
CefBrowserContext* browser_context =
|
2015-03-02 21:25:14 +01:00
|
|
|
request_context_impl->GetBrowserContext();
|
2017-02-14 23:27:19 +01:00
|
|
|
DCHECK(browser_context);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
if (!request_context_.get())
|
|
|
|
request_context_ = request_context_impl.get();
|
|
|
|
|
|
|
|
// The request context is created on the UI thread but accessed and
|
|
|
|
// destroyed on the IO thread.
|
|
|
|
url_request_getter_ = browser_context->GetRequestContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContinueOnOriginatingThread(const GURL& url,
|
|
|
|
net::URLFetcher::RequestType request_type) {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
int request_flags = request_->GetFlags();
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
fetcher_delegate_.reset(new CefURLFetcherDelegate(this, request_flags));
|
2015-06-06 00:06:48 +02:00
|
|
|
fetcher_ = net::URLFetcher::Create(url, request_type,
|
|
|
|
fetcher_delegate_.get());
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
DCHECK(url_request_getter_.get());
|
|
|
|
fetcher_->SetRequestContext(url_request_getter_.get());
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2015-12-01 19:22:28 +01:00
|
|
|
static_cast<CefRequestImpl*>(request_.get())->Get(*fetcher_,
|
|
|
|
upload_data_size_);
|
2012-06-19 18:29:49 +02:00
|
|
|
|
2013-08-27 20:58:08 +02:00
|
|
|
fetcher_->SetURLRequestUserData(
|
|
|
|
CefURLRequestUserData::kUserDataKey,
|
|
|
|
base::Bind(&CreateURLRequestUserData, client_));
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::URLFetcherResponseWriter> response_writer;
|
2015-12-01 19:22:28 +01:00
|
|
|
if (request_flags & UR_FLAG_NO_DOWNLOAD_DATA) {
|
2013-10-29 18:53:18 +01:00
|
|
|
response_writer.reset(new CefURLFetcherResponseWriter(NULL, NULL));
|
|
|
|
} else {
|
|
|
|
response_writer.reset(
|
2015-07-24 02:06:56 +02:00
|
|
|
new CefURLFetcherResponseWriter(url_request_, task_runner_));
|
2013-10-29 18:53:18 +01:00
|
|
|
}
|
2016-01-06 20:20:54 +01:00
|
|
|
fetcher_->SaveResponseWithWriter(std::move(response_writer));
|
2013-10-29 18:53:18 +01:00
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
fetcher_->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
|
|
|
|
// The request may already be complete.
|
|
|
|
if (!fetcher_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Cancel the fetch by deleting the fetcher.
|
|
|
|
fetcher_.reset(NULL);
|
|
|
|
|
|
|
|
status_ = UR_CANCELED;
|
|
|
|
error_code_ = ERR_ABORTED;
|
|
|
|
OnComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnComplete() {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
|
|
|
|
if (fetcher_.get()) {
|
|
|
|
const net::URLRequestStatus& status = fetcher_->GetStatus();
|
|
|
|
|
|
|
|
if (status.is_success())
|
|
|
|
NotifyUploadProgressIfNecessary();
|
|
|
|
|
|
|
|
switch (status.status()) {
|
|
|
|
case net::URLRequestStatus::SUCCESS:
|
|
|
|
status_ = UR_SUCCESS;
|
|
|
|
break;
|
|
|
|
case net::URLRequestStatus::IO_PENDING:
|
|
|
|
status_ = UR_IO_PENDING;
|
|
|
|
break;
|
|
|
|
case net::URLRequestStatus::CANCELED:
|
|
|
|
status_ = UR_CANCELED;
|
|
|
|
break;
|
|
|
|
case net::URLRequestStatus::FAILED:
|
|
|
|
status_ = UR_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_code_ = static_cast<CefURLRequest::ErrorCode>(status.error());
|
|
|
|
|
2013-08-27 21:16:24 +02:00
|
|
|
if(!response_.get())
|
|
|
|
OnResponse();
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(url_request_.get());
|
|
|
|
client_->OnRequestComplete(url_request_.get());
|
|
|
|
|
|
|
|
if (fetcher_.get())
|
|
|
|
fetcher_.reset(NULL);
|
|
|
|
|
|
|
|
// This may result in the Context object being deleted.
|
|
|
|
url_request_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDownloadProgress(int64 current, int64 total) {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
DCHECK(url_request_.get());
|
|
|
|
|
2013-08-27 21:16:24 +02:00
|
|
|
if(!response_.get())
|
|
|
|
OnResponse();
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
NotifyUploadProgressIfNecessary();
|
|
|
|
|
|
|
|
client_->OnDownloadProgress(url_request_.get(), current, total);
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
void OnDownloadData(std::unique_ptr<std::string> download_data) {
|
2012-06-19 18:29:49 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
DCHECK(url_request_.get());
|
2013-08-27 21:16:24 +02:00
|
|
|
|
|
|
|
if(!response_.get())
|
|
|
|
OnResponse();
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
client_->OnDownloadData(url_request_.get(), download_data->c_str(),
|
|
|
|
download_data->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnUploadProgress(int64 current, int64 total) {
|
|
|
|
DCHECK(CalledOnValidThread());
|
|
|
|
DCHECK(url_request_.get());
|
|
|
|
if (current == total)
|
|
|
|
got_upload_progress_complete_ = true;
|
|
|
|
client_->OnUploadProgress(url_request_.get(), current, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequest> request() { return request_; }
|
|
|
|
CefRefPtr<CefURLRequestClient> client() { return client_; }
|
|
|
|
CefURLRequest::Status status() { return status_; }
|
|
|
|
CefURLRequest::ErrorCode error_code() { return error_code_; }
|
|
|
|
CefRefPtr<CefResponse> response() { return response_; }
|
|
|
|
|
|
|
|
private:
|
2014-11-12 20:25:15 +01:00
|
|
|
friend class base::RefCountedThreadSafe<CefBrowserURLRequest::Context>;
|
|
|
|
|
|
|
|
~Context() {
|
|
|
|
if (fetcher_.get()) {
|
|
|
|
// Delete the fetcher object on the thread that created it.
|
2015-07-24 02:06:56 +02:00
|
|
|
task_runner_->DeleteSoon(FROM_HERE, fetcher_.release());
|
2014-11-12 20:25:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
void NotifyUploadProgressIfNecessary() {
|
|
|
|
if (!got_upload_progress_complete_ && upload_data_size_ > 0) {
|
|
|
|
// URLFetcher sends upload notifications using a timer and will not send
|
|
|
|
// a notification if the request completes too quickly. We therefore
|
|
|
|
// send the notification here if necessary.
|
|
|
|
client_->OnUploadProgress(url_request_.get(), upload_data_size_,
|
|
|
|
upload_data_size_);
|
|
|
|
got_upload_progress_complete_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 21:16:24 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 18:29:49 +02:00
|
|
|
// Members only accessed on the initialization thread.
|
|
|
|
CefRefPtr<CefBrowserURLRequest> url_request_;
|
|
|
|
CefRefPtr<CefRequest> request_;
|
|
|
|
CefRefPtr<CefURLRequestClient> client_;
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context_;
|
2015-07-24 02:06:56 +02:00
|
|
|
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<net::URLFetcher> fetcher_;
|
|
|
|
std::unique_ptr<CefURLFetcherDelegate> fetcher_delegate_;
|
2012-06-19 18:29:49 +02:00
|
|
|
CefURLRequest::Status status_;
|
|
|
|
CefURLRequest::ErrorCode error_code_;
|
|
|
|
CefRefPtr<CefResponse> response_;
|
|
|
|
int64 upload_data_size_;
|
|
|
|
bool got_upload_progress_complete_;
|
2015-03-02 21:25:14 +01:00
|
|
|
|
|
|
|
scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
|
2012-06-19 18:29:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CefURLFetcherDelegate ------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
CefURLFetcherDelegate::CefURLFetcherDelegate(
|
|
|
|
CefBrowserURLRequest::Context* context, int request_flags)
|
|
|
|
: context_(context),
|
|
|
|
request_flags_(request_flags) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLFetcherDelegate::~CefURLFetcherDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLFetcherDelegate::OnURLFetchComplete(
|
|
|
|
const net::URLFetcher* source) {
|
2013-10-24 23:43:47 +02:00
|
|
|
// Complete asynchronously so as not to delete the URLFetcher while it's still
|
|
|
|
// in the call stack.
|
2016-07-21 23:21:32 +02:00
|
|
|
base::MessageLoop::current()->task_runner()->PostTask(FROM_HERE,
|
2013-10-24 23:43:47 +02:00
|
|
|
base::Bind(&CefBrowserURLRequest::Context::OnComplete, context_));
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLFetcherDelegate::OnURLFetchDownloadProgress(
|
|
|
|
const net::URLFetcher* source,
|
2016-10-21 21:52:29 +02:00
|
|
|
int64 current,
|
|
|
|
int64 total,
|
|
|
|
int64_t current_network_bytes) {
|
2012-06-19 18:29:49 +02:00
|
|
|
context_->OnDownloadProgress(current, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefURLFetcherDelegate::OnURLFetchUploadProgress(
|
|
|
|
const net::URLFetcher* source,
|
|
|
|
int64 current, int64 total) {
|
|
|
|
if (request_flags_ & UR_FLAG_REPORT_UPLOAD_PROGRESS)
|
|
|
|
context_->OnUploadProgress(current, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
// CefBrowserURLRequest -------------------------------------------------------
|
|
|
|
|
|
|
|
CefBrowserURLRequest::CefBrowserURLRequest(
|
|
|
|
CefRefPtr<CefRequest> request,
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRefPtr<CefURLRequestClient> client,
|
|
|
|
CefRefPtr<CefRequestContext> request_context) {
|
|
|
|
context_ = new Context(this, request, client, request_context);
|
2012-06-19 18:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserURLRequest::~CefBrowserURLRequest() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserURLRequest::Start() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return false;
|
|
|
|
return context_->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRequest> CefBrowserURLRequest::GetRequest() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
return context_->request();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefURLRequestClient> CefBrowserURLRequest::GetClient() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
return context_->client();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLRequest::Status CefBrowserURLRequest::GetRequestStatus() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return UR_UNKNOWN;
|
|
|
|
return context_->status();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefURLRequest::ErrorCode CefBrowserURLRequest::GetRequestError() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return ERR_NONE;
|
|
|
|
return context_->error_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefResponse> CefBrowserURLRequest::GetResponse() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
return context_->response();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserURLRequest::Cancel() {
|
|
|
|
if (!VerifyContext())
|
|
|
|
return;
|
|
|
|
return context_->Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserURLRequest::VerifyContext() {
|
|
|
|
DCHECK(context_.get());
|
|
|
|
if (!context_->CalledOnValidThread()) {
|
|
|
|
NOTREACHED() << "called on invalid thread";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|