2011-02-15 19:07:24 +01:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
|
2010-10-03 23:04:50 +02:00
|
|
|
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
//
|
|
|
|
// This file contains an implementation of the ResourceLoaderBridge class.
|
2011-01-06 20:26:45 +01:00
|
|
|
// The class is implemented using net::URLRequest, meaning it is a "simple"
|
|
|
|
// version that directly issues requests. The more complicated one used in the
|
2010-10-03 23:04:50 +02:00
|
|
|
// browser uses IPC.
|
|
|
|
//
|
2011-01-06 20:26:45 +01:00
|
|
|
// Because net::URLRequest only provides an asynchronous resource loading API,
|
|
|
|
// this file makes use of net::URLRequest from a background IO thread. Requests
|
|
|
|
// for cookies and synchronously loaded resources result in the main thread of
|
|
|
|
// the application blocking until the IO thread completes the operation. (See
|
2010-10-03 23:04:50 +02:00
|
|
|
// GetCookies and SyncLoad)
|
|
|
|
//
|
|
|
|
// Main thread IO thread
|
|
|
|
// ----------- ---------
|
|
|
|
// ResourceLoaderBridge <---o---------> RequestProxy (normal case)
|
2010-12-16 22:54:42 +01:00
|
|
|
// \ -> net::URLRequest
|
2010-10-03 23:04:50 +02:00
|
|
|
// o-------> SyncRequestProxy (synchronous case)
|
2010-12-16 22:54:42 +01:00
|
|
|
// -> net::URLRequest
|
2010-10-03 23:04:50 +02:00
|
|
|
//
|
|
|
|
// NOTE: The implementation in this file may be used to have WebKit fetch
|
|
|
|
// resources in-process. For example, it is handy for building a single-
|
2010-12-16 22:54:42 +01:00
|
|
|
// process WebKit embedding (e.g., test_shell) that can use net::URLRequest to
|
2010-10-03 23:04:50 +02:00
|
|
|
// perform URL loads. See renderer/resource_dispatcher.h for details on an
|
|
|
|
// alternate implementation that defers fetching to another process.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/browser_resource_loader_bridge.h"
|
|
|
|
#include "libcef/browser_appcache_system.h"
|
|
|
|
#include "libcef/browser_request_context.h"
|
|
|
|
#include "libcef/browser_socket_stream_bridge.h"
|
|
|
|
#include "libcef/browser_webkit_glue.h"
|
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/cef_process.h"
|
|
|
|
#include "libcef/cef_process_io_thread.h"
|
|
|
|
#include "libcef/external_protocol_handler.h"
|
|
|
|
#include "libcef/request_impl.h"
|
|
|
|
#include "libcef/response_impl.h"
|
|
|
|
#include "libcef/http_header_utils.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-09-23 02:16:03 +02:00
|
|
|
#include "base/bind.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/file_path.h"
|
|
|
|
#include "base/file_util.h"
|
2011-04-05 18:17:33 +02:00
|
|
|
#include "base/memory/ref_counted.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/message_loop_proxy.h"
|
|
|
|
#include "base/time.h"
|
|
|
|
#include "base/timer.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "base/threading/thread.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "base/utf_string_conversions.h"
|
2011-01-07 02:24:17 +01:00
|
|
|
#include "net/base/auth.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/base/file_stream.h"
|
|
|
|
#include "net/base/io_buffer.h"
|
|
|
|
#include "net/base/load_flags.h"
|
|
|
|
#include "net/base/net_errors.h"
|
|
|
|
#include "net/base/net_util.h"
|
|
|
|
#include "net/base/static_cookie_policy.h"
|
|
|
|
#include "net/base/upload_data.h"
|
|
|
|
#include "net/http/http_cache.h"
|
|
|
|
#include "net/http/http_request_headers.h"
|
|
|
|
#include "net/http/http_response_headers.h"
|
|
|
|
#include "net/proxy/proxy_service.h"
|
|
|
|
#include "net/url_request/url_request.h"
|
2011-12-15 15:47:23 +01:00
|
|
|
#include "net/url_request/url_request_job_manager.h"
|
|
|
|
#include "net/url_request/url_request_redirect_job.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/appcache/appcache_interfaces.h"
|
|
|
|
#include "webkit/blob/blob_storage_controller.h"
|
2012-04-05 00:32:24 +02:00
|
|
|
#include "webkit/blob/shareable_file_reference.h"
|
2011-04-05 18:17:33 +02:00
|
|
|
#include "webkit/fileapi/file_system_context.h"
|
|
|
|
#include "webkit/fileapi/file_system_dir_url_request_job.h"
|
|
|
|
#include "webkit/fileapi/file_system_url_request_job.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/resource_loader_bridge.h"
|
2012-05-23 21:01:04 +02:00
|
|
|
#include "webkit/glue/webkit_glue.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-16 18:56:12 +02:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_WIN)
|
|
|
|
#include "crypto/nss_util.h"
|
|
|
|
#endif
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
using net::HttpResponseHeaders;
|
|
|
|
using net::StaticCookiePolicy;
|
2011-02-15 19:07:24 +01:00
|
|
|
using net::URLRequestStatus;
|
2012-04-05 00:32:24 +02:00
|
|
|
using webkit_blob::ShareableFileReference;
|
2010-10-03 23:04:50 +02:00
|
|
|
using webkit_glue::ResourceLoaderBridge;
|
2010-10-15 20:37:25 +02:00
|
|
|
using webkit_glue::ResourceResponseInfo;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2011-12-15 15:47:23 +01:00
|
|
|
static const char kCefUserData[] = "cef_userdata";
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
struct RequestParams {
|
|
|
|
std::string method;
|
|
|
|
GURL url;
|
|
|
|
GURL first_party_for_cookies;
|
|
|
|
GURL referrer;
|
2012-05-23 21:01:04 +02:00
|
|
|
WebKit::WebReferrerPolicy referrer_policy;
|
2010-10-03 23:04:50 +02:00
|
|
|
std::string headers;
|
|
|
|
int load_flags;
|
|
|
|
ResourceType::Type request_type;
|
|
|
|
int appcache_host_id;
|
|
|
|
bool download_to_file;
|
|
|
|
scoped_refptr<net::UploadData> upload;
|
2011-07-15 22:31:21 +02:00
|
|
|
net::RequestPriority priority;
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// The interval for calls to RequestProxy::MaybeUpdateUploadProgress
|
|
|
|
static const int kUpdateUploadProgressIntervalMsec = 100;
|
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
class ExtraRequestInfo : public net::URLRequest::Data {
|
2012-01-10 00:46:23 +01:00
|
|
|
public:
|
2012-03-22 23:08:05 +01:00
|
|
|
ExtraRequestInfo(CefBrowserImpl* browser, ResourceType::Type resource_type)
|
2011-10-07 12:13:04 +02:00
|
|
|
: browser_(browser),
|
|
|
|
resource_type_(resource_type),
|
2012-01-10 00:46:23 +01:00
|
|
|
allow_download_(resource_type == ResourceType::MAIN_FRAME ||
|
|
|
|
resource_type == ResourceType::SUB_FRAME) {
|
|
|
|
}
|
2011-01-06 20:26:45 +01:00
|
|
|
|
2011-10-07 12:13:04 +02:00
|
|
|
// The browser pointer is guaranteed to be valid for the lifespan of the
|
|
|
|
// request. The pointer will be NULL in cases where the request was
|
|
|
|
// initiated via the CefWebURLRequest API instead of by a browser window.
|
2012-03-22 23:08:05 +01:00
|
|
|
CefBrowserImpl* browser() const { return browser_; }
|
2011-10-07 12:13:04 +02:00
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
// Identifies the type of resource, such as subframe, media, etc.
|
|
|
|
ResourceType::Type resource_type() const { return resource_type_; }
|
|
|
|
bool allow_download() const { return allow_download_; }
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
private:
|
2012-03-22 23:08:05 +01:00
|
|
|
CefBrowserImpl* browser_;
|
2011-01-06 20:26:45 +01:00
|
|
|
ResourceType::Type resource_type_;
|
|
|
|
bool allow_download_;
|
|
|
|
};
|
|
|
|
|
2011-12-15 15:47:23 +01:00
|
|
|
// Used to intercept redirect requests.
|
2012-01-10 00:46:23 +01:00
|
|
|
class RequestInterceptor : public net::URLRequest::Interceptor {
|
|
|
|
public:
|
2011-12-15 15:47:23 +01:00
|
|
|
RequestInterceptor() {
|
|
|
|
REQUIRE_IOT();
|
|
|
|
net::URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(this);
|
|
|
|
}
|
|
|
|
~RequestInterceptor() {
|
|
|
|
REQUIRE_IOT();
|
2012-01-10 00:46:23 +01:00
|
|
|
net::URLRequestJobManager::GetInstance()->
|
|
|
|
UnregisterRequestInterceptor(this);
|
2011-12-15 15:47:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request)
|
|
|
|
OVERRIDE {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual net::URLRequestJob* MaybeInterceptRedirect(net::URLRequest* request,
|
|
|
|
const GURL& location) OVERRIDE {
|
|
|
|
REQUIRE_IOT();
|
|
|
|
|
|
|
|
ExtraRequestInfo* info =
|
|
|
|
static_cast<ExtraRequestInfo*>(request->GetUserData(kCefUserData));
|
|
|
|
if (!info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> browser = info->browser();
|
2011-12-15 17:42:28 +01:00
|
|
|
if (!browser.get())
|
|
|
|
return NULL;
|
2011-12-15 15:47:23 +01:00
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
CefRefPtr<CefRequestHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetRequestHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CefString newUrlStr = location.spec();
|
|
|
|
handler->OnResourceRedirect(browser, request->url().spec(), newUrlStr);
|
|
|
|
if (newUrlStr != location.spec()) {
|
|
|
|
GURL new_url = GURL(std::string(newUrlStr));
|
|
|
|
if (!new_url.is_empty() && new_url.is_valid())
|
|
|
|
return new net::URLRequestRedirectJob(request, new_url);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RequestInterceptor);
|
|
|
|
};
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// The RequestProxy does most of its work on the IO thread. The Start and
|
2011-01-06 20:26:45 +01:00
|
|
|
// Cancel methods are proxied over to the IO thread, where an net::URLRequest
|
|
|
|
// object is instantiated.
|
2010-12-16 22:54:42 +01:00
|
|
|
class RequestProxy : public net::URLRequest::Delegate,
|
2010-10-03 23:04:50 +02:00
|
|
|
public base::RefCountedThreadSafe<RequestProxy> {
|
|
|
|
public:
|
|
|
|
// Takes ownership of the params.
|
2012-03-22 23:08:05 +01:00
|
|
|
explicit RequestProxy(CefRefPtr<CefBrowserImpl> browser)
|
2010-10-10 02:16:24 +02:00
|
|
|
: download_to_file_(false),
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_(NULL),
|
2010-10-03 23:04:50 +02:00
|
|
|
buf_(new net::IOBuffer(kDataSize)),
|
2010-10-10 02:16:24 +02:00
|
|
|
browser_(browser),
|
2012-05-25 22:44:34 +02:00
|
|
|
owner_loop_(NULL),
|
|
|
|
peer_(NULL),
|
2011-12-06 11:37:43 +01:00
|
|
|
last_upload_position_(0),
|
|
|
|
defers_loading_(false),
|
2012-01-10 00:46:23 +01:00
|
|
|
defers_loading_want_read_(false) {
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DropPeer() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
2010-10-03 23:04:50 +02:00
|
|
|
peer_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Start(ResourceLoaderBridge::Peer* peer, RequestParams* params) {
|
|
|
|
peer_ = peer;
|
|
|
|
owner_loop_ = MessageLoop::current();
|
|
|
|
|
2011-07-15 22:31:21 +02:00
|
|
|
InitializeParams(params);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// proxy over to the io thread
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncStart, this, params));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (download_handler_.get()) {
|
2010-10-16 21:10:11 +02:00
|
|
|
// WebKit will try to cancel the download but we won't allow it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// proxy over to the io thread
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncCancel, this));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 11:37:43 +01:00
|
|
|
void SetDefersLoading(bool defer) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2011-12-06 11:37:43 +01:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncSetDefersLoading, this, defer));
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
protected:
|
|
|
|
friend class base::RefCountedThreadSafe<RequestProxy>;
|
|
|
|
|
|
|
|
virtual ~RequestProxy() {
|
|
|
|
// If we have a request, then we'd better be on the io thread!
|
|
|
|
DCHECK(!request_.get() || CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
}
|
|
|
|
|
2011-07-15 22:31:21 +02:00
|
|
|
virtual void InitializeParams(RequestParams* params) {
|
|
|
|
params->priority = net::MEDIUM;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// The following methods are called on the owner's thread in response to
|
2010-12-16 22:54:42 +01:00
|
|
|
// various net::URLRequest callbacks. The event hooks, defined below, trigger
|
2010-10-03 23:04:50 +02:00
|
|
|
// these methods asynchronously.
|
|
|
|
|
|
|
|
void NotifyReceivedRedirect(const GURL& new_url,
|
2010-10-15 20:37:25 +02:00
|
|
|
const ResourceResponseInfo& info) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
bool has_new_first_party_for_cookies = false;
|
|
|
|
GURL new_first_party_for_cookies;
|
|
|
|
if (peer_ && peer_->OnReceivedRedirect(new_url, info,
|
|
|
|
&has_new_first_party_for_cookies,
|
|
|
|
&new_first_party_for_cookies)) {
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncFollowDeferredRedirect, this,
|
2010-10-03 23:04:50 +02:00
|
|
|
has_new_first_party_for_cookies, new_first_party_for_cookies));
|
|
|
|
} else {
|
|
|
|
Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
void NotifyReceivedResponse(const ResourceResponseInfo& info,
|
2011-01-06 20:26:45 +01:00
|
|
|
const GURL& url, bool allow_download) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
if (browser_.get() && info.headers.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefRequestHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetRequestHandler();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-16 21:10:11 +02:00
|
|
|
if (handler.get()) {
|
2011-05-24 01:39:07 +02:00
|
|
|
CefRefPtr<CefResponse> response = new CefResponseImpl();
|
|
|
|
// Transfer response headers
|
|
|
|
if (info.headers) {
|
|
|
|
CefResponse::HeaderMap headerMap;
|
|
|
|
void* header_index = NULL;
|
|
|
|
std::string name, value;
|
|
|
|
while (info.headers->EnumerateHeaderLines(&header_index, &name,
|
|
|
|
&value)) {
|
|
|
|
if (!name.empty() && !value.empty())
|
2011-10-28 23:31:26 +02:00
|
|
|
headerMap.insert(std::make_pair(name, value));
|
2011-05-24 01:39:07 +02:00
|
|
|
}
|
|
|
|
response->SetHeaderMap(headerMap);
|
|
|
|
response->SetStatusText(info.headers->GetStatusText());
|
|
|
|
response->SetStatus(info.headers->response_code());
|
|
|
|
}
|
|
|
|
response->SetMimeType(info.mime_type);
|
2012-03-22 23:08:05 +01:00
|
|
|
handler->OnResourceResponse(browser_.get(), url.spec(), response,
|
2011-05-24 01:39:07 +02:00
|
|
|
content_filter_);
|
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
std::string content_disposition;
|
|
|
|
info.headers->GetNormalizedHeader("Content-Disposition",
|
|
|
|
&content_disposition);
|
|
|
|
|
|
|
|
if (allow_download &&
|
|
|
|
webkit_glue::ShouldDownload(content_disposition, info.mime_type)) {
|
2011-02-16 04:19:07 +01:00
|
|
|
string16 filename = net::GetSuggestedFilename(url,
|
2011-09-10 21:40:03 +02:00
|
|
|
content_disposition, info.charset, "", info.mime_type,
|
2011-10-20 22:34:13 +02:00
|
|
|
"download");
|
2011-01-06 20:26:45 +01:00
|
|
|
CefRefPtr<CefDownloadHandler> dl_handler;
|
2012-03-22 23:08:05 +01:00
|
|
|
if (handler->GetDownloadHandler(browser_.get(), info.mime_type,
|
2011-05-20 16:42:25 +02:00
|
|
|
filename, info.content_length,
|
|
|
|
dl_handler)) {
|
2011-01-06 20:26:45 +01:00
|
|
|
download_handler_ = dl_handler;
|
|
|
|
}
|
2010-10-16 21:10:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (peer_)
|
2011-04-05 18:17:33 +02:00
|
|
|
peer_->OnReceivedResponse(info);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyReceivedData(int bytes_read) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!peer_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Make a local copy of buf_, since AsyncReadData reuses it.
|
|
|
|
scoped_array<char> buf_copy(new char[bytes_read]);
|
|
|
|
memcpy(buf_copy.get(), buf_->data(), bytes_read);
|
|
|
|
|
|
|
|
// Continue reading more data into buf_
|
|
|
|
// Note: Doing this before notifying our peer ensures our load events get
|
|
|
|
// dispatched in a manner consistent with DumpRenderTree (and also avoids a
|
|
|
|
// race condition). If the order of the next 2 functions were reversed, the
|
2011-07-02 19:57:00 +02:00
|
|
|
// peer could generate new requests in response to the received data, which
|
2010-10-03 23:04:50 +02:00
|
|
|
// when run on the io thread, could race against this function in doing
|
|
|
|
// another InvokeLater. See bug 769249.
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncReadData, this));
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-24 01:39:07 +02:00
|
|
|
CefRefPtr<CefStreamReader> resourceStream;
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (content_filter_.get())
|
2011-05-24 01:39:07 +02:00
|
|
|
content_filter_->ProcessData(buf_copy.get(), bytes_read, resourceStream);
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-05-24 01:39:07 +02:00
|
|
|
if (resourceStream.get()) {
|
|
|
|
// The filter made some changes to the data in the buffer.
|
|
|
|
resourceStream->Seek(0, SEEK_END);
|
|
|
|
bytes_read = resourceStream->Tell();
|
|
|
|
resourceStream->Seek(0, SEEK_SET);
|
|
|
|
|
|
|
|
buf_copy.reset(new char[bytes_read]);
|
|
|
|
resourceStream->Read(buf_copy.get(), 1, bytes_read);
|
|
|
|
}
|
|
|
|
|
2010-10-16 21:10:11 +02:00
|
|
|
if (download_handler_.get() &&
|
|
|
|
!download_handler_->ReceivedData(buf_copy.get(), bytes_read)) {
|
|
|
|
// Cancel loading by proxying over to the io thread.
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncCancel, this));
|
2010-10-16 21:10:11 +02:00
|
|
|
}
|
|
|
|
|
2011-05-16 18:56:12 +02:00
|
|
|
peer_->OnReceivedData(buf_copy.get(), bytes_read, -1);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyDownloadedData(int bytes_read) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!peer_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Continue reading more data, see the comment in NotifyReceivedData.
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncReadData, this));
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
peer_->OnDownloadedData(bytes_read);
|
|
|
|
}
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
void NotifyCompletedRequest(const net::URLRequestStatus& status,
|
2010-10-03 23:04:50 +02:00
|
|
|
const std::string& security_info,
|
2011-12-21 19:35:55 +01:00
|
|
|
const base::TimeTicks& complete_time) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
// Drain the content filter of all remaining data
|
2011-05-24 01:39:07 +02:00
|
|
|
if (content_filter_.get()) {
|
|
|
|
CefRefPtr<CefStreamReader> remainder;
|
|
|
|
content_filter_->Drain(remainder);
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (remainder.get()) {
|
2011-05-24 01:39:07 +02:00
|
|
|
remainder->Seek(0, SEEK_END);
|
2012-01-10 00:46:23 +01:00
|
|
|
int size = static_cast<int>(remainder->Tell());
|
|
|
|
if (size > 0) {
|
2011-05-24 01:39:07 +02:00
|
|
|
remainder->Seek(0, SEEK_SET);
|
|
|
|
scoped_array<char> buf(new char[size]);
|
|
|
|
remainder->Read(buf.get(), 1, size);
|
|
|
|
|
|
|
|
if (download_handler_.get() &&
|
|
|
|
!download_handler_->ReceivedData(buf.get(), size)) {
|
|
|
|
// Cancel loading by proxying over to the io thread.
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::AsyncCancel, this));
|
2011-05-24 01:39:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer_)
|
|
|
|
peer_->OnReceivedData(buf.get(), size, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content_filter_ = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-16 21:10:11 +02:00
|
|
|
if (download_handler_.get()) {
|
|
|
|
download_handler_->Complete();
|
|
|
|
download_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (peer_) {
|
|
|
|
peer_->OnCompletedRequest(status, security_info, complete_time);
|
|
|
|
DropPeer(); // ensure no further notifications
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyUploadProgress(uint64 position, uint64 size) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(MessageLoop::current() == owner_loop_);
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (peer_)
|
|
|
|
peer_->OnUploadProgress(position, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// The following methods are called on the io thread. They correspond to
|
|
|
|
// actions performed on the owner's thread.
|
|
|
|
|
|
|
|
void AsyncStart(RequestParams* params) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
if (browser_.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
CefRefPtr<CefRequestHandler> handler;
|
|
|
|
if (client.get())
|
|
|
|
handler = client->GetRequestHandler();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
|
|
|
if (handler.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Build the request object for passing to the handler
|
|
|
|
CefRefPtr<CefRequest> request(new CefRequestImpl());
|
2011-01-06 20:26:45 +01:00
|
|
|
CefRequestImpl* requestimpl =
|
|
|
|
static_cast<CefRequestImpl*>(request.get());
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
std::string originalUrl(params->url.spec());
|
2010-10-03 23:04:50 +02:00
|
|
|
requestimpl->SetURL(originalUrl);
|
2010-11-22 18:49:46 +01:00
|
|
|
requestimpl->SetMethod(params->method);
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Transfer request headers
|
|
|
|
CefRequest::HeaderMap headerMap;
|
2011-02-09 23:04:35 +01:00
|
|
|
HttpHeaderUtils::ParseHeaders(params->headers, headerMap);
|
2012-06-01 19:42:20 +02:00
|
|
|
headerMap.insert(std::make_pair("Referer", params->referrer.spec()));
|
2010-10-03 23:04:50 +02:00
|
|
|
requestimpl->SetHeaderMap(headerMap);
|
|
|
|
|
|
|
|
// Transfer post data, if any
|
|
|
|
scoped_refptr<net::UploadData> upload = params->upload;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (upload.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefPostData> postdata(new CefPostDataImpl());
|
|
|
|
static_cast<CefPostDataImpl*>(postdata.get())->Set(*upload.get());
|
|
|
|
requestimpl->SetPostData(postdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
int loadFlags = params->load_flags;
|
|
|
|
|
|
|
|
// Handler output will be returned in these variables
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString redirectUrl;
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefStreamReader> resourceStream;
|
2011-04-21 18:46:16 +02:00
|
|
|
CefRefPtr<CefResponse> response(new CefResponseImpl());
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
handled = handler->OnBeforeResourceLoad(browser_.get(), request,
|
|
|
|
redirectUrl, resourceStream, response, loadFlags);
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled) {
|
|
|
|
// Observe URL from request.
|
|
|
|
const std::string requestUrl(request->GetURL());
|
2012-02-16 21:13:07 +01:00
|
|
|
if (requestUrl != originalUrl)
|
2011-05-20 16:42:25 +02:00
|
|
|
params->url = GURL(requestUrl);
|
2012-02-16 21:13:07 +01:00
|
|
|
else if (!redirectUrl.empty())
|
|
|
|
params->url = GURL(std::string(redirectUrl));
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Observe method from request.
|
|
|
|
params->method = request->GetMethod();
|
|
|
|
|
|
|
|
// Observe headers from request.
|
|
|
|
request->GetHeaderMap(headerMap);
|
|
|
|
CefString referrerStr;
|
2012-06-01 19:42:20 +02:00
|
|
|
referrerStr.FromASCII("Referer");
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRequest::HeaderMap::iterator referrer =
|
|
|
|
headerMap.find(referrerStr);
|
|
|
|
if (referrer == headerMap.end()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
params->referrer = GURL();
|
|
|
|
} else {
|
|
|
|
params->referrer = GURL(std::string(referrer->second));
|
|
|
|
headerMap.erase(referrer);
|
|
|
|
}
|
|
|
|
params->headers = HttpHeaderUtils::GenerateHeaders(headerMap);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Observe post data from request.
|
|
|
|
CefRefPtr<CefPostData> postData = request->GetPostData();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (postData.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
params->upload = new net::UploadData();
|
|
|
|
static_cast<CefPostDataImpl*>(postData.get())->Get(*params->upload);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (handled) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// cancel the resource load
|
|
|
|
OnCompletedRequest(
|
|
|
|
URLRequestStatus(URLRequestStatus::CANCELED, net::ERR_ABORTED),
|
2011-12-21 19:35:55 +01:00
|
|
|
std::string(), base::TimeTicks());
|
2011-05-20 16:42:25 +02:00
|
|
|
} else if (resourceStream.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// load from the provided resource stream
|
|
|
|
handled = true;
|
|
|
|
|
|
|
|
resourceStream->Seek(0, SEEK_END);
|
2012-01-10 00:46:23 +01:00
|
|
|
int64 offset = resourceStream->Tell();
|
2010-10-03 23:04:50 +02:00
|
|
|
resourceStream->Seek(0, SEEK_SET);
|
|
|
|
|
|
|
|
resource_stream_ = resourceStream;
|
|
|
|
|
2011-04-21 18:46:16 +02:00
|
|
|
CefResponseImpl* responseImpl =
|
|
|
|
static_cast<CefResponseImpl*>(response.get());
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
ResourceResponseInfo info;
|
2012-01-10 00:46:23 +01:00
|
|
|
info.content_length = offset;
|
2011-04-21 18:46:16 +02:00
|
|
|
info.mime_type = response->GetMimeType();
|
2011-05-26 20:11:56 +02:00
|
|
|
info.headers = responseImpl->GetResponseHeaders();
|
2011-05-24 01:39:07 +02:00
|
|
|
OnReceivedResponse(info, params->url);
|
2011-04-21 18:46:16 +02:00
|
|
|
AsyncReadData();
|
|
|
|
} else if (response->GetStatus() != 0) {
|
|
|
|
// status set, but no resource stream
|
|
|
|
handled = true;
|
|
|
|
|
|
|
|
CefResponseImpl* responseImpl =
|
|
|
|
static_cast<CefResponseImpl*>(response.get());
|
|
|
|
|
|
|
|
ResourceResponseInfo info;
|
|
|
|
info.content_length = 0;
|
|
|
|
info.mime_type = response->GetMimeType();
|
2011-05-26 20:11:56 +02:00
|
|
|
info.headers = responseImpl->GetResponseHeaders();
|
2011-05-24 01:39:07 +02:00
|
|
|
OnReceivedResponse(info, params->url);
|
2010-10-03 23:04:50 +02:00
|
|
|
AsyncReadData();
|
|
|
|
}
|
2011-01-12 02:33:03 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled && ResourceType::IsFrame(params->request_type) &&
|
|
|
|
!net::URLRequest::IsHandledProtocol(params->url.scheme())) {
|
2011-01-12 02:33:03 +01:00
|
|
|
bool allow_os_execution = false;
|
2012-03-22 23:08:05 +01:00
|
|
|
handled = handler->OnProtocolExecution(browser_.get(),
|
|
|
|
params->url.spec(), allow_os_execution);
|
2011-05-20 16:42:25 +02:00
|
|
|
if (!handled && allow_os_execution &&
|
2011-04-09 03:05:30 +02:00
|
|
|
ExternalProtocolHandler::HandleExternalProtocol(params->url)) {
|
2011-01-12 02:33:03 +01:00
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
OnCompletedRequest(
|
|
|
|
URLRequestStatus(URLRequestStatus::HANDLED_EXTERNALLY, net::OK),
|
2012-01-10 00:46:23 +01:00
|
|
|
std::string(), base::TimeTicks());
|
2011-01-12 02:33:03 +01:00
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (!handled) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Might need to resolve the blob references in the upload data.
|
|
|
|
if (params->upload) {
|
|
|
|
_Context->request_context()->blob_storage_controller()->
|
|
|
|
ResolveBlobReferencesInUploadData(params->upload.get());
|
|
|
|
}
|
|
|
|
|
2012-08-07 15:58:35 +02:00
|
|
|
net::URLRequestContext* context = browser_.get() ?
|
|
|
|
browser_->request_context_proxy() : _Context->request_context();
|
|
|
|
|
|
|
|
request_.reset(new net::URLRequest(params->url, this, context));
|
2011-07-15 22:31:21 +02:00
|
|
|
request_->set_priority(params->priority);
|
2010-10-03 23:04:50 +02:00
|
|
|
request_->set_method(params->method);
|
|
|
|
request_->set_first_party_for_cookies(params->first_party_for_cookies);
|
|
|
|
request_->set_referrer(params->referrer.spec());
|
2012-05-23 21:01:04 +02:00
|
|
|
webkit_glue::ConfigureURLRequestForReferrerPolicy(
|
|
|
|
request_.get(), params->referrer_policy);
|
2010-10-03 23:04:50 +02:00
|
|
|
net::HttpRequestHeaders headers;
|
|
|
|
headers.AddHeadersFromString(params->headers);
|
|
|
|
request_->SetExtraRequestHeaders(headers);
|
|
|
|
request_->set_load_flags(params->load_flags);
|
|
|
|
request_->set_upload(params->upload.get());
|
2011-12-15 15:47:23 +01:00
|
|
|
request_->SetUserData(kCefUserData,
|
2011-10-07 12:13:04 +02:00
|
|
|
new ExtraRequestInfo(browser_.get(), params->request_type));
|
2010-10-03 23:04:50 +02:00
|
|
|
BrowserAppCacheSystem::SetExtraRequestInfo(
|
|
|
|
request_.get(), params->appcache_host_id, params->request_type);
|
|
|
|
|
|
|
|
download_to_file_ = params->download_to_file;
|
|
|
|
if (download_to_file_) {
|
|
|
|
FilePath path;
|
|
|
|
if (file_util::CreateTemporaryFile(&path)) {
|
2012-04-05 00:32:24 +02:00
|
|
|
downloaded_file_ = ShareableFileReference::GetOrCreate(
|
|
|
|
path, ShareableFileReference::DELETE_ON_FINAL_RELEASE,
|
|
|
|
base::MessageLoopProxy::current());
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_.OpenSync(
|
2010-10-03 23:04:50 +02:00
|
|
|
path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request_->Start();
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
if (request_.get() && request_->has_upload() &&
|
2010-10-03 23:04:50 +02:00
|
|
|
params->load_flags & net::LOAD_ENABLE_UPLOAD_PROGRESS) {
|
2011-09-10 21:40:03 +02:00
|
|
|
upload_progress_timer_.Start(FROM_HERE,
|
2011-01-06 20:26:45 +01:00
|
|
|
base::TimeDelta::FromMilliseconds(
|
|
|
|
kUpdateUploadProgressIntervalMsec),
|
2010-10-03 23:04:50 +02:00
|
|
|
this, &RequestProxy::MaybeUpdateUploadProgress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete params;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncCancel() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// This can be null in cases where the request is already done.
|
|
|
|
if (!resource_stream_.get() && !request_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (request_.get())
|
|
|
|
request_->Cancel();
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncFollowDeferredRedirect(bool has_new_first_party_for_cookies,
|
|
|
|
const GURL& new_first_party_for_cookies) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// This can be null in cases where the request is already done.
|
|
|
|
if (!request_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (has_new_first_party_for_cookies)
|
|
|
|
request_->set_first_party_for_cookies(new_first_party_for_cookies);
|
|
|
|
request_->FollowDeferredRedirect();
|
|
|
|
}
|
|
|
|
|
2011-12-06 11:37:43 +01:00
|
|
|
void AsyncSetDefersLoading(bool defer) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2011-12-06 11:37:43 +01:00
|
|
|
if (defers_loading_ != defer) {
|
|
|
|
defers_loading_ = defer;
|
|
|
|
if (!defers_loading_ && defers_loading_want_read_) {
|
|
|
|
// Perform the pending AsyncReadData now.
|
|
|
|
defers_loading_want_read_ = false;
|
|
|
|
AsyncReadData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void AsyncReadData() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2011-12-06 11:37:43 +01:00
|
|
|
// Pause downloading if we're in deferred mode.
|
|
|
|
if (defers_loading_) {
|
|
|
|
defers_loading_want_read_ = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (resource_stream_.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Read from the handler-provided resource stream
|
|
|
|
int bytes_read = resource_stream_->Read(buf_->data(), 1, kDataSize);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (bytes_read > 0) {
|
2010-10-03 23:04:50 +02:00
|
|
|
OnReceivedData(bytes_read);
|
|
|
|
} else {
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This can be null in cases where the request is already done.
|
|
|
|
if (!request_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (request_->status().is_success()) {
|
|
|
|
int bytes_read;
|
|
|
|
if (request_->Read(buf_, kDataSize, &bytes_read) && bytes_read) {
|
|
|
|
OnReceivedData(bytes_read);
|
|
|
|
} else if (!request_->status().is_io_pending()) {
|
|
|
|
Done();
|
|
|
|
} // else wait for OnReadCompleted
|
|
|
|
} else {
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
2010-12-16 22:54:42 +01:00
|
|
|
// The following methods are event hooks (corresponding to net::URLRequest
|
2010-10-03 23:04:50 +02:00
|
|
|
// callbacks) that run on the IO thread. They are designed to be overridden
|
|
|
|
// by the SyncRequestProxy subclass.
|
|
|
|
|
|
|
|
virtual void OnReceivedRedirect(
|
|
|
|
const GURL& new_url,
|
2010-10-15 20:37:25 +02:00
|
|
|
const ResourceResponseInfo& info,
|
2010-10-03 23:04:50 +02:00
|
|
|
bool* defer_redirect) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
*defer_redirect = true; // See AsyncFollowDeferredRedirect
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
2011-12-15 15:47:23 +01:00
|
|
|
&RequestProxy::NotifyReceivedRedirect, this, new_url, info));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnReceivedResponse(
|
2011-05-24 01:39:07 +02:00
|
|
|
const ResourceResponseInfo& info,
|
|
|
|
// only used when loading from a resource stream
|
|
|
|
const GURL& simulated_url) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
GURL url;
|
|
|
|
bool allow_download(false);
|
2012-01-10 00:46:23 +01:00
|
|
|
if (request_.get()) {
|
2011-01-06 20:26:45 +01:00
|
|
|
url = request_->url();
|
|
|
|
ExtraRequestInfo* info =
|
2011-12-15 15:47:23 +01:00
|
|
|
static_cast<ExtraRequestInfo*>(request_->GetUserData(kCefUserData));
|
2011-01-06 20:26:45 +01:00
|
|
|
if (info)
|
|
|
|
allow_download = info->allow_download();
|
2011-05-24 01:39:07 +02:00
|
|
|
} else if (!simulated_url.is_empty() && simulated_url.is_valid()) {
|
|
|
|
url = simulated_url;
|
2011-01-06 20:26:45 +01:00
|
|
|
}
|
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::NotifyReceivedResponse, this, info, url,
|
2011-04-05 18:17:33 +02:00
|
|
|
allow_download));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnReceivedData(int bytes_read) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (download_to_file_) {
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_.WriteSync(buf_->data(), bytes_read);
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::NotifyDownloadedData, this, bytes_read));
|
2010-10-03 23:04:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::NotifyReceivedData, this, bytes_read));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
virtual void OnCompletedRequest(const net::URLRequestStatus& status,
|
2010-10-03 23:04:50 +02:00
|
|
|
const std::string& security_info,
|
2011-12-21 19:35:55 +01:00
|
|
|
const base::TimeTicks& complete_time) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (download_to_file_)
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_.CloseSync();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::NotifyCompletedRequest, this, status, security_info,
|
2010-10-03 23:04:50 +02:00
|
|
|
complete_time));
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
2010-12-16 22:54:42 +01:00
|
|
|
// net::URLRequest::Delegate implementation:
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
virtual void OnReceivedRedirect(net::URLRequest* request,
|
2010-10-03 23:04:50 +02:00
|
|
|
const GURL& new_url,
|
2011-09-10 21:40:03 +02:00
|
|
|
bool* defer_redirect) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(request->status().is_success());
|
2010-10-15 20:37:25 +02:00
|
|
|
ResourceResponseInfo info;
|
2010-10-03 23:04:50 +02:00
|
|
|
PopulateResponseInfo(request, &info);
|
2011-12-15 15:47:23 +01:00
|
|
|
OnReceivedRedirect(new_url, info, defer_redirect);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (request->status().is_success()) {
|
2010-10-15 20:37:25 +02:00
|
|
|
ResourceResponseInfo info;
|
2010-10-03 23:04:50 +02:00
|
|
|
PopulateResponseInfo(request, &info);
|
2011-05-24 01:39:07 +02:00
|
|
|
OnReceivedResponse(info, GURL::EmptyGURL());
|
2010-10-03 23:04:50 +02:00
|
|
|
AsyncReadData(); // start reading
|
|
|
|
} else {
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 02:24:17 +01:00
|
|
|
virtual void OnAuthRequired(net::URLRequest* request,
|
2011-09-10 21:40:03 +02:00
|
|
|
net::AuthChallengeInfo* auth_info) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2011-01-07 02:24:17 +01:00
|
|
|
if (browser_.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefRefPtr<CefClient> client = browser_->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
2012-01-10 00:46:23 +01:00
|
|
|
if (handler.get()) {
|
2011-05-20 16:42:25 +02:00
|
|
|
CefString username, password;
|
2012-03-22 23:08:05 +01:00
|
|
|
if (handler->GetAuthCredentials(browser_.get(),
|
2011-09-23 02:16:03 +02:00
|
|
|
auth_info->is_proxy,
|
|
|
|
auth_info->challenger.host(),
|
|
|
|
auth_info->challenger.port(),
|
|
|
|
auth_info->realm,
|
|
|
|
auth_info->scheme,
|
2011-05-20 16:42:25 +02:00
|
|
|
username, password)) {
|
2011-11-05 00:12:18 +01:00
|
|
|
request->SetAuth(net::AuthCredentials(username, password));
|
2011-05-20 16:42:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-01-07 02:24:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request->CancelAuth();
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
virtual void OnSSLCertificateError(net::URLRequest* request,
|
2011-10-12 21:09:15 +02:00
|
|
|
const net::SSLInfo& ssl_info,
|
2012-02-17 15:51:20 +01:00
|
|
|
bool fatal) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Allow all certificate errors.
|
|
|
|
request->ContinueDespiteLastError();
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void OnReadCompleted(net::URLRequest* request,
|
|
|
|
int bytes_read) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (request->status().is_success() && bytes_read > 0) {
|
|
|
|
OnReceivedData(bytes_read);
|
|
|
|
} else {
|
|
|
|
Done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Helpers and data:
|
|
|
|
|
|
|
|
void Done() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
if (resource_stream_.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
// Resource stream reads always complete successfully
|
|
|
|
OnCompletedRequest(URLRequestStatus(URLRequestStatus::SUCCESS, 0),
|
2011-12-21 19:35:55 +01:00
|
|
|
std::string(), base::TimeTicks());
|
2010-10-03 23:04:50 +02:00
|
|
|
resource_stream_ = NULL;
|
2012-01-10 00:46:23 +01:00
|
|
|
} else if (request_.get()) {
|
2010-10-03 23:04:50 +02:00
|
|
|
if (upload_progress_timer_.IsRunning()) {
|
|
|
|
MaybeUpdateUploadProgress();
|
|
|
|
upload_progress_timer_.Stop();
|
|
|
|
}
|
|
|
|
DCHECK(request_.get());
|
2011-12-21 19:35:55 +01:00
|
|
|
OnCompletedRequest(request_->status(), std::string(), base::TimeTicks());
|
2010-10-03 23:04:50 +02:00
|
|
|
request_.reset(); // destroy on the io thread
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaybeUpdateUploadProgress() {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2011-01-06 20:26:45 +01:00
|
|
|
// If a redirect is received upload is cancelled in net::URLRequest, we
|
|
|
|
// should try to stop the |upload_progress_timer_| timer and return.
|
2010-10-03 23:04:50 +02:00
|
|
|
if (!request_->has_upload()) {
|
|
|
|
if (upload_progress_timer_.IsRunning())
|
|
|
|
upload_progress_timer_.Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-18 01:19:52 +01:00
|
|
|
// GetContentLengthSync() may perform file IO, but it's ok here, as file
|
|
|
|
// IO is not prohibited in IOThread defined in the file.
|
2012-08-07 15:58:35 +02:00
|
|
|
uint64 size = request_->get_upload_mutable()->GetContentLengthSync();
|
2010-10-03 23:04:50 +02:00
|
|
|
uint64 position = request_->GetUploadProgress();
|
|
|
|
if (position == last_upload_position_)
|
|
|
|
return; // no progress made since last time
|
|
|
|
|
|
|
|
const uint64 kHalfPercentIncrements = 200;
|
|
|
|
const base::TimeDelta kOneSecond = base::TimeDelta::FromMilliseconds(1000);
|
|
|
|
|
|
|
|
uint64 amt_since_last = position - last_upload_position_;
|
|
|
|
base::TimeDelta time_since_last = base::TimeTicks::Now() -
|
|
|
|
last_upload_ticks_;
|
|
|
|
|
|
|
|
bool is_finished = (size == position);
|
|
|
|
bool enough_new_progress = (amt_since_last > (size /
|
|
|
|
kHalfPercentIncrements));
|
|
|
|
bool too_much_time_passed = time_since_last > kOneSecond;
|
|
|
|
|
|
|
|
if (is_finished || enough_new_progress || too_much_time_passed) {
|
2011-10-12 21:09:15 +02:00
|
|
|
owner_loop_->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&RequestProxy::NotifyUploadProgress, this, position, size));
|
2010-10-03 23:04:50 +02:00
|
|
|
last_upload_ticks_ = base::TimeTicks::Now();
|
|
|
|
last_upload_position_ = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
void PopulateResponseInfo(net::URLRequest* request,
|
2010-10-15 20:37:25 +02:00
|
|
|
ResourceResponseInfo* info) const {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
info->request_time = request->request_time();
|
|
|
|
info->response_time = request->response_time();
|
|
|
|
info->headers = request->response_headers();
|
|
|
|
request->GetMimeType(&info->mime_type);
|
|
|
|
request->GetCharset(&info->charset);
|
|
|
|
info->content_length = request->GetExpectedContentSize();
|
|
|
|
if (downloaded_file_)
|
|
|
|
info->download_file_path = downloaded_file_->path();
|
|
|
|
BrowserAppCacheSystem::GetExtraResponseInfo(
|
|
|
|
request,
|
|
|
|
&info->appcache_id,
|
|
|
|
&info->appcache_manifest_url);
|
|
|
|
}
|
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
scoped_ptr<net::URLRequest> request_;
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefStreamReader> resource_stream_;
|
|
|
|
|
|
|
|
// Support for request.download_to_file behavior.
|
|
|
|
bool download_to_file_;
|
|
|
|
net::FileStream file_stream_;
|
2012-04-05 00:32:24 +02:00
|
|
|
scoped_refptr<ShareableFileReference> downloaded_file_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-10-03 18:00:51 +02:00
|
|
|
// Size of our async IO data buffers. Limited by the sanity check in
|
|
|
|
// URLRequestJob::Read().
|
|
|
|
static const int kDataSize = 1000000-1;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// read buffer for async IO
|
|
|
|
scoped_refptr<net::IOBuffer> buf_;
|
|
|
|
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> browser_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
MessageLoop* owner_loop_;
|
|
|
|
|
|
|
|
// This is our peer in WebKit (implemented as ResourceHandleInternal). We do
|
|
|
|
// not manage its lifetime, and we may only access it from the owner's
|
|
|
|
// message loop (owner_loop_).
|
|
|
|
ResourceLoaderBridge::Peer* peer_;
|
|
|
|
|
|
|
|
// Timer used to pull upload progress info.
|
|
|
|
base::RepeatingTimer<RequestProxy> upload_progress_timer_;
|
|
|
|
|
|
|
|
// Info used to determine whether or not to send an upload progress update.
|
|
|
|
uint64 last_upload_position_;
|
|
|
|
base::TimeTicks last_upload_ticks_;
|
2010-10-16 21:10:11 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefDownloadHandler> download_handler_;
|
2011-05-24 01:39:07 +02:00
|
|
|
CefRefPtr<CefContentFilter> content_filter_;
|
2011-12-06 11:37:43 +01:00
|
|
|
|
|
|
|
// True if loading of data is currently deferred.
|
|
|
|
bool defers_loading_;
|
|
|
|
|
|
|
|
// True if an AsyncReadData was scheduled while we were deferred.
|
|
|
|
bool defers_loading_want_read_;
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SyncRequestProxy : public RequestProxy {
|
|
|
|
public:
|
2012-03-22 23:08:05 +01:00
|
|
|
explicit SyncRequestProxy(CefRefPtr<CefBrowserImpl> browser,
|
2010-10-03 23:04:50 +02:00
|
|
|
ResourceLoaderBridge::SyncLoadResponse* result)
|
|
|
|
: RequestProxy(browser), result_(result), event_(true, false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitForCompletion() {
|
2011-10-12 21:09:15 +02:00
|
|
|
event_.Wait();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Event hooks that run on the IO thread:
|
|
|
|
|
|
|
|
virtual void OnReceivedRedirect(
|
|
|
|
const GURL& new_url,
|
2010-10-15 20:37:25 +02:00
|
|
|
const ResourceResponseInfo& info,
|
2011-12-15 15:47:23 +01:00
|
|
|
bool* defer_redirect) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// TODO(darin): It would be much better if this could live in WebCore, but
|
|
|
|
// doing so requires API changes at all levels. Similar code exists in
|
|
|
|
// WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
|
|
|
|
if (new_url.GetOrigin() != result_->url.GetOrigin()) {
|
|
|
|
DLOG(WARNING) << "Cross origin redirect denied";
|
|
|
|
Cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result_->url = new_url;
|
|
|
|
}
|
|
|
|
|
2011-05-24 01:39:07 +02:00
|
|
|
virtual void OnReceivedResponse(const ResourceResponseInfo& info,
|
2011-12-15 15:47:23 +01:00
|
|
|
const GURL&) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
*static_cast<ResourceResponseInfo*>(result_) = info;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-12-15 15:47:23 +01:00
|
|
|
virtual void OnReceivedData(int bytes_read) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (download_to_file_)
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_.WriteSync(buf_->data(), bytes_read);
|
2010-10-03 23:04:50 +02:00
|
|
|
else
|
|
|
|
result_->data.append(buf_->data(), bytes_read);
|
|
|
|
AsyncReadData(); // read more (may recurse)
|
|
|
|
}
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
virtual void OnCompletedRequest(const net::URLRequestStatus& status,
|
2010-10-03 23:04:50 +02:00
|
|
|
const std::string& security_info,
|
2011-12-21 19:35:55 +01:00
|
|
|
const base::TimeTicks& complete_time) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::IO));
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
if (download_to_file_)
|
2012-02-18 01:19:52 +01:00
|
|
|
file_stream_.CloseSync();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
result_->status = status;
|
|
|
|
event_.Signal();
|
|
|
|
}
|
|
|
|
|
2011-07-15 22:31:21 +02:00
|
|
|
protected:
|
2011-12-15 15:47:23 +01:00
|
|
|
virtual void InitializeParams(RequestParams* params) {
|
2011-07-15 22:31:21 +02:00
|
|
|
// For synchronous requests ignore load limits to avoid a deadlock problem
|
|
|
|
// in SyncRequestProxy (issue #192).
|
|
|
|
params->load_flags |= net::LOAD_IGNORE_LIMITS;
|
|
|
|
params->priority = net::HIGHEST;
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
private:
|
|
|
|
ResourceLoaderBridge::SyncLoadResponse* result_;
|
|
|
|
base::WaitableEvent event_;
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-05-25 22:44:34 +02:00
|
|
|
class ResourceLoaderBridgeImpl : public ResourceLoaderBridge,
|
|
|
|
public base::NonThreadSafe {
|
2010-10-03 23:04:50 +02:00
|
|
|
public:
|
2012-03-22 23:08:05 +01:00
|
|
|
ResourceLoaderBridgeImpl(CefRefPtr<CefBrowserImpl> browser,
|
2010-10-03 23:04:50 +02:00
|
|
|
const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info)
|
|
|
|
: browser_(browser),
|
|
|
|
params_(new RequestParams),
|
|
|
|
proxy_(NULL) {
|
|
|
|
params_->method = request_info.method;
|
|
|
|
params_->url = request_info.url;
|
|
|
|
params_->first_party_for_cookies = request_info.first_party_for_cookies;
|
|
|
|
params_->referrer = request_info.referrer;
|
2012-05-23 21:01:04 +02:00
|
|
|
params_->referrer_policy = request_info.referrer_policy;
|
2010-10-03 23:04:50 +02:00
|
|
|
params_->headers = request_info.headers;
|
|
|
|
params_->load_flags = request_info.load_flags;
|
|
|
|
params_->request_type = request_info.request_type;
|
|
|
|
params_->appcache_host_id = request_info.appcache_host_id;
|
|
|
|
params_->download_to_file = request_info.download_to_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ResourceLoaderBridgeImpl() {
|
|
|
|
if (proxy_) {
|
|
|
|
proxy_->DropPeer();
|
|
|
|
// Let the proxy die on the IO thread
|
2012-05-25 22:44:34 +02:00
|
|
|
CefThread::ReleaseSoon(CefThread::IO, FROM_HERE, proxy_.release());
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// ResourceLoaderBridge implementation:
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void AppendDataToUpload(const char* data, int data_len) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(params_.get());
|
|
|
|
if (!params_->upload)
|
|
|
|
params_->upload = new net::UploadData();
|
|
|
|
params_->upload->AppendBytes(data, data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void AppendFileRangeToUpload(
|
|
|
|
const FilePath& file_path,
|
|
|
|
uint64 offset,
|
|
|
|
uint64 length,
|
2011-09-10 21:40:03 +02:00
|
|
|
const base::Time& expected_modification_time) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(params_.get());
|
|
|
|
if (!params_->upload)
|
|
|
|
params_->upload = new net::UploadData();
|
|
|
|
params_->upload->AppendFileRange(file_path, offset, length,
|
|
|
|
expected_modification_time);
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void AppendBlobToUpload(const GURL& blob_url) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(params_.get());
|
|
|
|
if (!params_->upload)
|
|
|
|
params_->upload = new net::UploadData();
|
|
|
|
params_->upload->AppendBlob(blob_url);
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void SetUploadIdentifier(int64 identifier) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(params_.get());
|
|
|
|
if (!params_->upload)
|
|
|
|
params_->upload = new net::UploadData();
|
|
|
|
params_->upload->set_identifier(identifier);
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual bool Start(Peer* peer) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(!proxy_);
|
|
|
|
|
|
|
|
proxy_ = new RequestProxy(browser_);
|
|
|
|
proxy_->Start(peer, params_.release());
|
|
|
|
|
|
|
|
return true; // Any errors will be reported asynchronously.
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void Cancel() OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(proxy_);
|
|
|
|
proxy_->Cancel();
|
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void SetDefersLoading(bool value) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2011-12-06 11:37:43 +01:00
|
|
|
DCHECK(proxy_);
|
|
|
|
proxy_->SetDefersLoading(value);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CalledOnValidThread());
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK(!proxy_);
|
|
|
|
|
|
|
|
// this may change as the result of a redirect
|
|
|
|
response->url = params_->url;
|
|
|
|
|
|
|
|
proxy_ = new SyncRequestProxy(browser_, response);
|
|
|
|
proxy_->Start(NULL, params_.release());
|
|
|
|
|
2012-05-25 22:44:34 +02:00
|
|
|
static_cast<SyncRequestProxy*>(proxy_.get())->WaitForCompletion();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> browser_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Ownership of params_ is transfered to the proxy when the proxy is created.
|
|
|
|
scoped_ptr<RequestParams> params_;
|
|
|
|
|
|
|
|
// The request proxy is allocated when we start the request, and then it
|
|
|
|
// sticks around until this ResourceLoaderBridge is destroyed.
|
2012-05-25 22:44:34 +02:00
|
|
|
scoped_refptr<RequestProxy> proxy_;
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-12-16 15:51:10 +01:00
|
|
|
// static
|
|
|
|
webkit_glue::ResourceLoaderBridge* BrowserResourceLoaderBridge::Create(
|
2010-10-03 23:04:50 +02:00
|
|
|
const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) {
|
2012-05-25 22:44:34 +02:00
|
|
|
DCHECK(CefThread::CurrentlyOn(CefThread::UI));
|
|
|
|
|
2010-10-10 02:16:24 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
2010-10-03 23:04:50 +02:00
|
|
|
_Context->GetBrowserByID(request_info.routing_id);
|
2010-10-10 02:16:24 +02:00
|
|
|
return new ResourceLoaderBridgeImpl(browser.get(), request_info);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-03-21 17:14:14 +01:00
|
|
|
// static
|
2012-03-22 23:08:05 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> BrowserResourceLoaderBridge::GetBrowserForRequest(
|
2011-10-07 12:13:04 +02:00
|
|
|
net::URLRequest* request) {
|
|
|
|
REQUIRE_IOT();
|
|
|
|
ExtraRequestInfo* extra_info =
|
2011-12-15 15:47:23 +01:00
|
|
|
static_cast<ExtraRequestInfo*>(request->GetUserData(kCefUserData));
|
2011-10-07 12:13:04 +02:00
|
|
|
if (extra_info)
|
|
|
|
return extra_info->browser();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
// static
|
2010-10-03 23:04:50 +02:00
|
|
|
scoped_refptr<base::MessageLoopProxy>
|
2011-12-15 15:47:23 +01:00
|
|
|
BrowserResourceLoaderBridge::GetCacheThread() {
|
2010-10-03 23:04:50 +02:00
|
|
|
return CefThread::GetMessageLoopProxyForThread(CefThread::FILE);
|
|
|
|
}
|
2011-12-15 15:47:23 +01:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
// static
|
2011-12-15 15:47:23 +01:00
|
|
|
net::URLRequest::Interceptor*
|
|
|
|
BrowserResourceLoaderBridge::CreateRequestInterceptor() {
|
|
|
|
return new RequestInterceptor();
|
|
|
|
}
|