2011-05-27 18:20:32 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors.
|
2010-10-03 23:04:50 +02:00
|
|
|
// Portions copyright (c) 2006-2009 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.
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
#include <map>
|
2011-05-27 18:20:32 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
#include "include/cef.h"
|
|
|
|
#include "libcef/browser_devtools_scheme_handler.h"
|
|
|
|
#include "libcef/browser_impl.h"
|
|
|
|
#include "libcef/browser_resource_loader_bridge.h"
|
|
|
|
#include "libcef/cef_context.h"
|
|
|
|
#include "libcef/cef_thread.h"
|
|
|
|
#include "libcef/request_impl.h"
|
|
|
|
#include "libcef/response_impl.h"
|
|
|
|
|
|
|
|
#include "base/bind.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/lazy_instance.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
#include "base/message_loop.h"
|
2011-05-27 18:20:32 +02:00
|
|
|
#include "base/string_util.h"
|
|
|
|
#include "base/synchronization/lock.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "googleurl/src/url_util.h"
|
|
|
|
#include "net/base/completion_callback.h"
|
2012-03-22 23:10:49 +01:00
|
|
|
#include "net/base/cookie_monster.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/base/io_buffer.h"
|
|
|
|
#include "net/base/upload_data.h"
|
2011-04-21 18:46:16 +02:00
|
|
|
#include "net/http/http_response_headers.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/http/http_util.h"
|
|
|
|
#include "net/url_request/url_request.h"
|
2011-05-27 18:20:32 +02:00
|
|
|
#include "net/url_request/url_request_about_job.h"
|
|
|
|
#include "net/url_request/url_request_data_job.h"
|
|
|
|
#include "net/url_request/url_request_error_job.h"
|
|
|
|
#include "net/url_request/url_request_file_job.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/url_request/url_request_filter.h"
|
2011-05-27 18:20:32 +02:00
|
|
|
#include "net/url_request/url_request_ftp_job.h"
|
|
|
|
#include "net/url_request/url_request_http_job.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "net/url_request/url_request_job.h"
|
2011-09-10 21:40:03 +02:00
|
|
|
#include "net/url_request/url_request_job_factory.h"
|
2011-05-27 18:20:32 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
using net::URLRequestStatus;
|
2011-05-27 18:20:32 +02:00
|
|
|
using WebKit::WebSecurityPolicy;
|
|
|
|
using WebKit::WebString;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
namespace {
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
bool IsStandardScheme(const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
url_parse::Component scheme_comp(0, scheme.length());
|
|
|
|
return url_util::IsStandard(scheme.c_str(), scheme_comp);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
void RegisterStandardScheme(const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
REQUIRE_UIT();
|
|
|
|
url_parse::Component scheme_comp(0, scheme.length());
|
|
|
|
if (!url_util::IsStandard(scheme.c_str(), scheme_comp))
|
|
|
|
url_util::AddStandardScheme(scheme.c_str());
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Copied from net/url_request/url_request_job_manager.cc.
|
|
|
|
struct SchemeToFactory {
|
|
|
|
const char* scheme;
|
|
|
|
net::URLRequest::ProtocolFactory* factory;
|
|
|
|
};
|
|
|
|
static const SchemeToFactory kBuiltinFactories[] = {
|
|
|
|
{ "http", net::URLRequestHttpJob::Factory },
|
|
|
|
{ "https", net::URLRequestHttpJob::Factory },
|
|
|
|
{ "file", net::URLRequestFileJob::Factory },
|
|
|
|
{ "ftp", net::URLRequestFtpJob::Factory },
|
|
|
|
{ "about", net::URLRequestAboutJob::Factory },
|
|
|
|
{ "data", net::URLRequestDataJob::Factory },
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
bool IsBuiltinScheme(const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i)
|
|
|
|
if (LowerCaseEqualsASCII(scheme, kBuiltinFactories[i].scheme))
|
|
|
|
return true;
|
|
|
|
return false;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
net::URLRequestJob* GetBuiltinSchemeRequestJob(net::URLRequest* request,
|
2012-03-22 23:10:49 +01:00
|
|
|
const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
// See if the request should be handled by a built-in protocol factory.
|
|
|
|
for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) {
|
|
|
|
if (scheme == kBuiltinFactories[i].scheme) {
|
|
|
|
net::URLRequestJob* job = (kBuiltinFactories[i].factory)(request, scheme);
|
|
|
|
DCHECK(job); // The built-in factories are not expected to fail!
|
|
|
|
return job;
|
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
std::string ToLower(const std::string& str) {
|
2011-05-27 18:20:32 +02:00
|
|
|
std::string str_lower = str;
|
|
|
|
std::transform(str_lower.begin(), str_lower.end(), str_lower.begin(),
|
|
|
|
towlower);
|
|
|
|
return str;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// net::URLRequestJob implementation.
|
2010-12-16 22:54:42 +01:00
|
|
|
class CefUrlRequestJob : public net::URLRequestJob {
|
2012-03-22 23:10:49 +01:00
|
|
|
public:
|
2011-05-27 18:20:32 +02:00
|
|
|
CefUrlRequestJob(net::URLRequest* request,
|
|
|
|
CefRefPtr<CefSchemeHandler> handler)
|
2010-12-16 22:54:42 +01:00
|
|
|
: net::URLRequestJob(request),
|
2011-08-17 03:55:07 +02:00
|
|
|
handler_(handler),
|
2012-03-22 23:10:49 +01:00
|
|
|
remaining_bytes_(0),
|
|
|
|
response_cookies_save_index_(0),
|
|
|
|
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual ~CefUrlRequestJob() {
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void Start() OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
cef_request_ = CefRequest::CreateRequest();
|
|
|
|
|
|
|
|
// Populate the request data.
|
|
|
|
static_cast<CefRequestImpl*>(cef_request_.get())->Set(request_);
|
|
|
|
|
|
|
|
// Add default headers if not already specified.
|
|
|
|
const net::URLRequestContext* context = request_->context();
|
|
|
|
if (context) {
|
|
|
|
CefRequest::HeaderMap::const_iterator it;
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
cef_request_->GetHeaderMap(headerMap);
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
if (!context->accept_language().empty()) {
|
|
|
|
it = headerMap.find(net::HttpRequestHeaders::kAcceptLanguage);
|
|
|
|
if (it == headerMap.end()) {
|
|
|
|
headerMap.insert(
|
|
|
|
std::make_pair(net::HttpRequestHeaders::kAcceptLanguage,
|
|
|
|
context->accept_language()));
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!context->accept_charset().empty()) {
|
|
|
|
it = headerMap.find(net::HttpRequestHeaders::kAcceptCharset);
|
|
|
|
if (it == headerMap.end()) {
|
|
|
|
headerMap.insert(
|
|
|
|
std::make_pair(net::HttpRequestHeaders::kAcceptCharset,
|
|
|
|
context->accept_charset()));
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
it = headerMap.find(net::HttpRequestHeaders::kUserAgent);
|
|
|
|
if (it == headerMap.end()) {
|
|
|
|
headerMap.insert(
|
|
|
|
std::make_pair(net::HttpRequestHeaders::kUserAgent,
|
|
|
|
context->GetUserAgent(request_->url())));
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
cef_request_->SetHeaderMap(headerMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddCookieHeaderAndStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddCookieHeaderAndStart() {
|
|
|
|
// No matter what, we want to report our status as IO pending since we will
|
|
|
|
// be notifying our consumer asynchronously via OnStartCompleted.
|
|
|
|
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
|
|
|
|
|
|
|
|
// If the request was destroyed, then there is no more work to do.
|
|
|
|
if (!request_)
|
|
|
|
return;
|
|
|
|
|
2012-05-03 22:59:30 +02:00
|
|
|
scoped_refptr<net::CookieStore> cookie_store =
|
2012-03-22 23:10:49 +01:00
|
|
|
request_->context()->cookie_store();
|
|
|
|
if (cookie_store) {
|
|
|
|
net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster();
|
|
|
|
if (cookie_monster) {
|
|
|
|
cookie_monster->GetAllCookiesForURLAsync(
|
|
|
|
request_->url(),
|
|
|
|
base::Bind(&CefUrlRequestJob::CheckCookiePolicyAndLoad,
|
|
|
|
weak_factory_.GetWeakPtr()));
|
|
|
|
} else {
|
|
|
|
DoLoadCookies();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DoStartTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoLoadCookies() {
|
|
|
|
net::CookieOptions options;
|
|
|
|
options.set_include_httponly();
|
2012-05-03 22:59:30 +02:00
|
|
|
scoped_refptr<net::CookieStore> cookie_store =
|
|
|
|
request_->context()->cookie_store();
|
|
|
|
if (cookie_store) {
|
|
|
|
cookie_store->GetCookiesWithInfoAsync(
|
|
|
|
request_->url(), options,
|
|
|
|
base::Bind(&CefUrlRequestJob::OnCookiesLoaded,
|
|
|
|
weak_factory_.GetWeakPtr()));
|
|
|
|
}
|
2012-03-22 23:10:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckCookiePolicyAndLoad(
|
|
|
|
const net::CookieList& cookie_list) {
|
|
|
|
if (CanGetCookies(cookie_list))
|
|
|
|
DoLoadCookies();
|
|
|
|
else
|
|
|
|
DoStartTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnCookiesLoaded(
|
|
|
|
const std::string& cookie_line,
|
|
|
|
const std::vector<net::CookieStore::CookieInfo>& cookie_infos) {
|
|
|
|
if (!cookie_line.empty()) {
|
|
|
|
CefRequest::HeaderMap headerMap;
|
|
|
|
cef_request_->GetHeaderMap(headerMap);
|
|
|
|
headerMap.insert(
|
|
|
|
std::make_pair(net::HttpRequestHeaders::kCookie, cookie_line));
|
|
|
|
cef_request_->SetHeaderMap(headerMap);
|
|
|
|
}
|
|
|
|
DoStartTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoStartTransaction() {
|
|
|
|
// We may have been canceled while retrieving cookies.
|
|
|
|
if (GetStatus().is_success()) {
|
|
|
|
StartTransaction();
|
|
|
|
} else {
|
|
|
|
NotifyCanceled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartTransaction() {
|
2011-08-17 03:55:07 +02:00
|
|
|
if (!callback_)
|
|
|
|
callback_ = new Callback(this);
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
// Protect against deletion of this object.
|
|
|
|
base::WeakPtr<CefUrlRequestJob> weak_ptr(weak_factory_.GetWeakPtr());
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
// Handler can decide whether to process the request.
|
2012-03-22 23:10:49 +01:00
|
|
|
bool rv = handler_->ProcessRequest(cef_request_, callback_.get());
|
|
|
|
if (weak_ptr.get() && !rv) {
|
2011-08-17 03:55:07 +02:00
|
|
|
// Cancel the request.
|
2012-03-22 23:10:49 +01:00
|
|
|
NotifyCanceled();
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void Kill() OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
|
|
|
// Notify the handler that the request has been canceled.
|
|
|
|
handler_->Cancel();
|
|
|
|
|
|
|
|
if (callback_) {
|
|
|
|
callback_->Detach();
|
|
|
|
callback_ = NULL;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2010-12-16 22:54:42 +01:00
|
|
|
net::URLRequestJob::Kill();
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool ReadRawData(net::IOBuffer* dest, int dest_size, int *bytes_read)
|
2012-03-22 23:10:49 +01:00
|
|
|
OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
DCHECK_NE(dest_size, 0);
|
|
|
|
DCHECK(bytes_read);
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
if (remaining_bytes_ == 0) {
|
|
|
|
// No more data to read.
|
|
|
|
*bytes_read = 0;
|
2010-10-03 23:04:50 +02:00
|
|
|
return true;
|
2011-08-17 03:55:07 +02:00
|
|
|
} else if (remaining_bytes_ > 0 && remaining_bytes_ < dest_size) {
|
|
|
|
// The handler knows the content size beforehand.
|
|
|
|
dest_size = static_cast<int>(remaining_bytes_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read response data from the handler.
|
|
|
|
bool rv = handler_->ReadResponse(dest->data(), dest_size, *bytes_read,
|
|
|
|
callback_.get());
|
|
|
|
if (!rv) {
|
|
|
|
// The handler has indicated completion of the request.
|
|
|
|
*bytes_read = 0;
|
2010-10-03 23:04:50 +02:00
|
|
|
return true;
|
2012-03-22 23:10:49 +01:00
|
|
|
} else if (*bytes_read == 0) {
|
2011-08-17 03:55:07 +02:00
|
|
|
if (!GetStatus().is_io_pending()) {
|
|
|
|
// Report our status as IO pending.
|
|
|
|
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
|
|
|
|
callback_->SetDestination(dest, dest_size);
|
|
|
|
}
|
|
|
|
return false;
|
2012-03-22 23:10:49 +01:00
|
|
|
} else if (*bytes_read > dest_size) {
|
2011-08-17 03:55:07 +02:00
|
|
|
// Normalize the return value.
|
|
|
|
*bytes_read = dest_size;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-08-17 03:55:07 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
if (remaining_bytes_ > 0)
|
2011-08-17 03:55:07 +02:00
|
|
|
remaining_bytes_ -= *bytes_read;
|
|
|
|
|
|
|
|
// Continue calling this method.
|
|
|
|
return true;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
info->headers = GetResponseHeaders();
|
2011-04-21 18:46:16 +02:00
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
virtual bool IsRedirectResponse(GURL* location, int* http_status_code)
|
2012-03-22 23:10:49 +01:00
|
|
|
OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
2011-04-21 20:17:46 +02:00
|
|
|
if (redirect_url_.is_valid()) {
|
|
|
|
// Redirect to the new URL.
|
|
|
|
*http_status_code = 303;
|
|
|
|
location->Swap(&redirect_url_);
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-15 15:47:23 +01:00
|
|
|
|
|
|
|
if (response_.get()) {
|
|
|
|
// Check for HTTP 302 or HTTP 303 redirect.
|
|
|
|
int status = response_->GetStatus();
|
|
|
|
if (status == 302 || status == 303) {
|
|
|
|
CefResponse::HeaderMap headerMap;
|
|
|
|
response_->GetHeaderMap(headerMap);
|
|
|
|
CefRequest::HeaderMap::iterator iter = headerMap.find("Location");
|
2012-03-22 23:10:49 +01:00
|
|
|
if (iter != headerMap.end()) {
|
2011-12-15 15:47:23 +01:00
|
|
|
GURL new_url = GURL(std::string(iter->second));
|
|
|
|
*http_status_code = status;
|
|
|
|
location->Swap(&new_url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
|
|
|
if (response_.get())
|
|
|
|
*mime_type = response_->GetMimeType();
|
2010-10-03 23:04:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefSchemeHandler> handler_;
|
2011-04-21 18:46:16 +02:00
|
|
|
CefRefPtr<CefResponse> response_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
private:
|
|
|
|
void SendHeaders() {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// We may have been orphaned...
|
2011-08-17 03:55:07 +02:00
|
|
|
if (!request())
|
2010-10-03 23:04:50 +02:00
|
|
|
return;
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
response_ = new CefResponseImpl();
|
|
|
|
remaining_bytes_ = 0;
|
|
|
|
|
2011-11-07 23:23:51 +01:00
|
|
|
CefString redirectUrl;
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
// Get header information from the handler.
|
2011-11-07 23:23:51 +01:00
|
|
|
handler_->GetResponseHeaders(response_, remaining_bytes_, redirectUrl);
|
|
|
|
if (!redirectUrl.empty()) {
|
|
|
|
std::string redirectUrlStr = redirectUrl;
|
|
|
|
redirect_url_ = GURL(redirectUrlStr);
|
|
|
|
}
|
2011-08-17 03:55:07 +02:00
|
|
|
|
|
|
|
if (remaining_bytes_ > 0)
|
2010-10-03 23:04:50 +02:00
|
|
|
set_expected_content_size(remaining_bytes_);
|
2011-08-17 03:55:07 +02:00
|
|
|
|
|
|
|
// Continue processing the request.
|
2012-03-22 23:10:49 +01:00
|
|
|
SaveCookiesAndNotifyHeadersComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
net::HttpResponseHeaders* GetResponseHeaders() {
|
|
|
|
DCHECK(response_);
|
|
|
|
if (!response_headers_.get()) {
|
|
|
|
CefResponseImpl* responseImpl =
|
|
|
|
static_cast<CefResponseImpl*>(response_.get());
|
|
|
|
response_headers_ = responseImpl->GetResponseHeaders();
|
|
|
|
}
|
|
|
|
return response_headers_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveCookiesAndNotifyHeadersComplete() {
|
|
|
|
response_cookies_.clear();
|
|
|
|
response_cookies_save_index_ = 0;
|
|
|
|
|
|
|
|
FetchResponseCookies(&response_cookies_);
|
|
|
|
|
|
|
|
// Now, loop over the response cookies, and attempt to persist each.
|
|
|
|
SaveNextCookie();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveNextCookie() {
|
|
|
|
if (response_cookies_save_index_ == response_cookies_.size()) {
|
|
|
|
response_cookies_.clear();
|
|
|
|
response_cookies_save_index_ = 0;
|
|
|
|
SetStatus(URLRequestStatus()); // Clear the IO_PENDING status
|
|
|
|
NotifyHeadersComplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matter what, we want to report our status as IO pending since we will
|
|
|
|
// be notifying our consumer asynchronously via OnStartCompleted.
|
|
|
|
SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
|
|
|
|
|
|
|
|
net::CookieOptions options;
|
|
|
|
options.set_include_httponly();
|
|
|
|
if (CanSetCookie(
|
|
|
|
response_cookies_[response_cookies_save_index_], &options)) {
|
2012-05-03 22:59:30 +02:00
|
|
|
scoped_refptr<net::CookieStore> cookie_store =
|
|
|
|
request_->context()->cookie_store();
|
|
|
|
if (cookie_store) {
|
|
|
|
cookie_store->SetCookieWithOptionsAsync(
|
|
|
|
request_->url(), response_cookies_[response_cookies_save_index_],
|
|
|
|
options, base::Bind(&CefUrlRequestJob::OnCookieSaved,
|
|
|
|
weak_factory_.GetWeakPtr()));
|
|
|
|
}
|
2012-03-22 23:10:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CookieHandled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnCookieSaved(bool cookie_status) {
|
|
|
|
CookieHandled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CookieHandled() {
|
|
|
|
response_cookies_save_index_++;
|
|
|
|
// We may have been canceled within OnSetCookie.
|
|
|
|
if (GetStatus().is_success()) {
|
|
|
|
SaveNextCookie();
|
|
|
|
} else {
|
|
|
|
NotifyCanceled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FetchResponseCookies(
|
|
|
|
std::vector<std::string>* cookies) {
|
|
|
|
const std::string name = "Set-Cookie";
|
|
|
|
std::string value;
|
|
|
|
|
|
|
|
void* iter = NULL;
|
|
|
|
net::HttpResponseHeaders* headers = GetResponseHeaders();
|
|
|
|
while (headers->EnumerateHeader(&iter, name, &value)) {
|
|
|
|
if (!value.empty())
|
|
|
|
cookies->push_back(value);
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
// Client callback for asynchronous response continuation.
|
2012-03-22 23:10:49 +01:00
|
|
|
class Callback : public CefSchemeHandlerCallback {
|
|
|
|
public:
|
|
|
|
explicit Callback(CefUrlRequestJob* job)
|
2011-08-17 03:55:07 +02:00
|
|
|
: job_(job),
|
|
|
|
dest_(NULL),
|
|
|
|
dest_size_() {}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void HeadersAvailable() OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
|
|
|
// Currently on IO thread.
|
|
|
|
if (job_ && !job_->has_response_started()) {
|
|
|
|
// Send header information.
|
|
|
|
job_->SendHeaders();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Execute this method on the IO thread.
|
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(&Callback::HeadersAvailable, this));
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void BytesAvailable() OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
|
|
|
// Currently on IO thread.
|
|
|
|
if (job_ && job_->has_response_started() &&
|
|
|
|
job_->GetStatus().is_io_pending()) {
|
|
|
|
// Read the bytes. They should be available but, if not, wait again.
|
|
|
|
int bytes_read = 0;
|
|
|
|
if (job_->ReadRawData(dest_, dest_size_, &bytes_read)) {
|
|
|
|
if (bytes_read > 0) {
|
|
|
|
// Clear the IO_PENDING status.
|
|
|
|
job_->SetStatus(URLRequestStatus());
|
|
|
|
|
|
|
|
// Notify about the available bytes.
|
|
|
|
job_->NotifyReadComplete(bytes_read);
|
|
|
|
|
|
|
|
dest_ = NULL;
|
2011-10-24 22:20:52 +02:00
|
|
|
dest_size_ = 0;
|
2012-05-04 20:35:09 +02:00
|
|
|
} else {
|
|
|
|
// All done.
|
|
|
|
job_->NotifyDone(URLRequestStatus());
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2012-05-04 20:35:09 +02:00
|
|
|
} else if (!job_->GetStatus().is_io_pending()) {
|
|
|
|
// Failed due to an error.
|
|
|
|
NOTREACHED() <<
|
|
|
|
"ReadRawData returned false without setting IO as pending";
|
2011-08-17 03:55:07 +02:00
|
|
|
job_->NotifyDone(URLRequestStatus());
|
|
|
|
}
|
2011-04-21 20:17:46 +02:00
|
|
|
}
|
2011-08-17 03:55:07 +02:00
|
|
|
} else {
|
|
|
|
// Execute this method on the IO thread.
|
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(&Callback::BytesAvailable, this));
|
2011-04-21 20:17:46 +02:00
|
|
|
}
|
2011-08-17 03:55:07 +02:00
|
|
|
}
|
2011-04-21 18:46:16 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
virtual void Cancel() OVERRIDE {
|
2011-08-17 03:55:07 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
|
|
|
// Currently on IO thread.
|
|
|
|
if (job_)
|
|
|
|
job_->Kill();
|
|
|
|
} else {
|
|
|
|
// Execute this method on the IO thread.
|
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(&Callback::Cancel, this));
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
void Detach() {
|
2011-08-17 03:55:07 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
job_ = NULL;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
void SetDestination(net::IOBuffer* dest, int dest_size) {
|
2011-08-17 03:55:07 +02:00
|
|
|
dest_ = dest;
|
|
|
|
dest_size_ = dest_size;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
static bool ImplementsThreadSafeReferenceCounting() { return true; }
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
private:
|
2011-08-17 03:55:07 +02:00
|
|
|
CefUrlRequestJob* job_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
net::IOBuffer* dest_;
|
|
|
|
int dest_size_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
IMPLEMENT_REFCOUNTING(Callback);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2011-08-17 03:55:07 +02:00
|
|
|
GURL redirect_url_;
|
|
|
|
int64 remaining_bytes_;
|
2012-03-22 23:10:49 +01:00
|
|
|
CefRefPtr<CefRequest> cef_request_;
|
2011-08-17 03:55:07 +02:00
|
|
|
CefRefPtr<Callback> callback_;
|
2012-03-22 23:10:49 +01:00
|
|
|
scoped_refptr<net::HttpResponseHeaders> response_headers_;
|
|
|
|
std::vector<std::string> response_cookies_;
|
|
|
|
size_t response_cookies_save_index_;
|
|
|
|
base::WeakPtrFactory<CefUrlRequestJob> weak_factory_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefUrlRequestJob);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Class that manages the CefSchemeHandlerFactory instances.
|
|
|
|
class CefUrlRequestManager {
|
2012-03-22 23:10:49 +01:00
|
|
|
protected:
|
2011-09-10 21:40:03 +02:00
|
|
|
// Class used for creating URLRequestJob instances. The lifespan of this
|
|
|
|
// object is managed by URLRequestJobFactory.
|
|
|
|
class ProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
2012-03-22 23:10:49 +01:00
|
|
|
public:
|
|
|
|
explicit ProtocolHandler(const std::string& scheme)
|
2011-09-10 21:40:03 +02:00
|
|
|
: scheme_(scheme) {}
|
|
|
|
|
|
|
|
// From net::URLRequestJobFactory::ProtocolHandler
|
|
|
|
virtual net::URLRequestJob* MaybeCreateJob(
|
2012-03-22 23:10:49 +01:00
|
|
|
net::URLRequest* request) const OVERRIDE {
|
2011-09-10 21:40:03 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
return CefUrlRequestManager::GetInstance()->GetRequestJob(request,
|
|
|
|
scheme_);
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
private:
|
2011-09-10 21:40:03 +02:00
|
|
|
std::string scheme_;
|
|
|
|
};
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
public:
|
2011-05-27 18:20:32 +02:00
|
|
|
CefUrlRequestManager() {}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Retrieve the singleton instance.
|
|
|
|
static CefUrlRequestManager* GetInstance();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
bool AddFactory(const std::string& scheme,
|
|
|
|
const std::string& domain,
|
2012-03-22 23:10:49 +01:00
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory) {
|
2011-05-27 18:20:32 +02:00
|
|
|
if (!factory.get()) {
|
|
|
|
RemoveFactory(scheme, domain);
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
|
|
|
std::string scheme_lower = ToLower(scheme);
|
|
|
|
std::string domain_lower = ToLower(domain);
|
|
|
|
|
|
|
|
// Hostname is only supported for standard schemes.
|
|
|
|
if (!IsStandardScheme(scheme_lower))
|
|
|
|
domain_lower.clear();
|
|
|
|
|
|
|
|
handler_map_[make_pair(scheme_lower, domain_lower)] = factory;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
net::URLRequestJobFactory* job_factory =
|
|
|
|
const_cast<net::URLRequestJobFactory*>(
|
|
|
|
_Context->request_context()->job_factory());
|
|
|
|
|
|
|
|
job_factory->SetProtocolHandler(scheme_lower,
|
|
|
|
new ProtocolHandler(scheme_lower));
|
2011-05-27 18:20:32 +02:00
|
|
|
|
|
|
|
return true;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
void RemoveFactory(const std::string& scheme,
|
2012-03-22 23:10:49 +01:00
|
|
|
const std::string& domain) {
|
2011-05-27 18:20:32 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
|
|
|
std::string scheme_lower = ToLower(scheme);
|
|
|
|
std::string domain_lower = ToLower(domain);
|
|
|
|
|
|
|
|
// Hostname is only supported for standard schemes.
|
|
|
|
if (!IsStandardScheme(scheme_lower))
|
|
|
|
domain_lower.clear();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
HandlerMap::iterator iter =
|
|
|
|
handler_map_.find(make_pair(scheme_lower, domain_lower));
|
|
|
|
if (iter != handler_map_.end())
|
|
|
|
handler_map_.erase(iter);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Clear all the existing URL handlers and unregister the ProtocolFactory.
|
2012-03-22 23:10:49 +01:00
|
|
|
void ClearFactories() {
|
2011-05-27 18:20:32 +02:00
|
|
|
REQUIRE_IOT();
|
|
|
|
|
2011-09-10 21:40:03 +02:00
|
|
|
net::URLRequestJobFactory* job_factory =
|
|
|
|
const_cast<net::URLRequestJobFactory*>(
|
|
|
|
_Context->request_context()->job_factory());
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
// Unregister with the ProtocolFactory.
|
|
|
|
std::set<std::string> schemes;
|
|
|
|
for (HandlerMap::const_iterator i = handler_map_.begin();
|
|
|
|
i != handler_map_.end(); ++i) {
|
|
|
|
schemes.insert(i->first.first);
|
|
|
|
}
|
|
|
|
for (std::set<std::string>::const_iterator scheme = schemes.begin();
|
|
|
|
scheme != schemes.end(); ++scheme) {
|
2011-09-10 21:40:03 +02:00
|
|
|
job_factory->SetProtocolHandler(*scheme, NULL);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handler_map_.clear();
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Check if a scheme has already been registered.
|
2012-03-22 23:10:49 +01:00
|
|
|
bool HasRegisteredScheme(const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
std::string scheme_lower = ToLower(scheme);
|
|
|
|
|
|
|
|
// Don't register builtin schemes.
|
|
|
|
if (IsBuiltinScheme(scheme_lower))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
scheme_set_lock_.Acquire();
|
|
|
|
bool registered = (scheme_set_.find(scheme_lower) != scheme_set_.end());
|
|
|
|
scheme_set_lock_.Release();
|
|
|
|
return registered;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register a scheme.
|
|
|
|
bool RegisterScheme(const std::string& scheme,
|
|
|
|
bool is_standard,
|
|
|
|
bool is_local,
|
2012-03-22 23:10:49 +01:00
|
|
|
bool is_display_isolated) {
|
2011-05-27 18:20:32 +02:00
|
|
|
if (HasRegisteredScheme(scheme)) {
|
|
|
|
NOTREACHED() << "Scheme already registered: " << scheme;
|
|
|
|
return false;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
std::string scheme_lower = ToLower(scheme);
|
|
|
|
|
|
|
|
scheme_set_lock_.Acquire();
|
|
|
|
scheme_set_.insert(scheme_lower);
|
|
|
|
scheme_set_lock_.Release();
|
|
|
|
|
|
|
|
if (is_standard)
|
|
|
|
RegisterStandardScheme(scheme_lower);
|
|
|
|
if (is_local) {
|
|
|
|
WebSecurityPolicy::registerURLSchemeAsLocal(
|
|
|
|
WebString::fromUTF8(scheme_lower));
|
|
|
|
}
|
|
|
|
if (is_display_isolated) {
|
|
|
|
WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(
|
|
|
|
WebString::fromUTF8(scheme_lower));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
private:
|
2011-05-27 18:20:32 +02:00
|
|
|
// Retrieve the matching handler factory, if any. |scheme| will already be in
|
|
|
|
// lower case.
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> GetHandlerFactory(
|
2012-03-22 23:10:49 +01:00
|
|
|
net::URLRequest* request, const std::string& scheme) {
|
2011-05-27 18:20:32 +02:00
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory;
|
|
|
|
|
|
|
|
if (request->url().is_valid() && IsStandardScheme(scheme)) {
|
|
|
|
// Check for a match with a domain first.
|
|
|
|
const std::string& domain = request->url().host();
|
|
|
|
|
|
|
|
HandlerMap::iterator i = handler_map_.find(make_pair(scheme, domain));
|
2010-10-03 23:04:50 +02:00
|
|
|
if (i != handler_map_.end())
|
|
|
|
factory = i->second;
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
if (!factory.get()) {
|
|
|
|
// Check for a match with no specified domain.
|
2010-10-03 23:04:50 +02:00
|
|
|
HandlerMap::iterator i =
|
|
|
|
handler_map_.find(make_pair(scheme, std::string()));
|
|
|
|
if (i != handler_map_.end())
|
|
|
|
factory = i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return factory;
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Create the job that will handle the request. |scheme| will already be in
|
|
|
|
// lower case.
|
|
|
|
net::URLRequestJob* GetRequestJob(net::URLRequest* request,
|
2012-03-22 23:10:49 +01:00
|
|
|
const std::string& scheme) {
|
2010-12-16 22:54:42 +01:00
|
|
|
net::URLRequestJob* job = NULL;
|
2011-05-27 18:20:32 +02:00
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory =
|
|
|
|
GetHandlerFactory(request, scheme);
|
2010-10-03 23:04:50 +02:00
|
|
|
if (factory) {
|
2011-05-27 18:20:32 +02:00
|
|
|
// Call the handler factory to create the handler for the request.
|
|
|
|
CefRefPtr<CefRequest> requestPtr(new CefRequestImpl());
|
|
|
|
static_cast<CefRequestImpl*>(requestPtr.get())->Set(request);
|
2012-03-22 23:10:49 +01:00
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
2011-10-07 12:13:04 +02:00
|
|
|
BrowserResourceLoaderBridge::GetBrowserForRequest(request);
|
|
|
|
CefRefPtr<CefSchemeHandler> handler =
|
2012-03-22 23:10:49 +01:00
|
|
|
factory->Create(browser.get(), scheme, requestPtr);
|
2010-10-03 23:04:50 +02:00
|
|
|
if (handler.get())
|
|
|
|
job = new CefUrlRequestJob(request, handler);
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
if (!job && IsBuiltinScheme(scheme)) {
|
|
|
|
// Give the built-in scheme handler a chance to handle the request.
|
|
|
|
job = GetBuiltinSchemeRequestJob(request, scheme);
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
2011-05-27 18:20:32 +02:00
|
|
|
|
2011-10-31 18:56:35 +01:00
|
|
|
#ifndef NDEBUG
|
2011-05-27 18:20:32 +02:00
|
|
|
if (job)
|
|
|
|
DLOG(INFO) << "CefUrlRequestManager hit for " << request->url().spec();
|
2011-10-31 18:56:35 +01:00
|
|
|
#endif
|
2012-03-22 23:10:49 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
return job;
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Map (scheme, domain) to factories. This map will only be accessed on the IO
|
|
|
|
// thread.
|
|
|
|
typedef std::map<std::pair<std::string, std::string>,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> > HandlerMap;
|
|
|
|
HandlerMap handler_map_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
// Set of registered schemes. This set may be accessed from multiple threads.
|
|
|
|
typedef std::set<std::string> SchemeSet;
|
|
|
|
SchemeSet scheme_set_;
|
|
|
|
base::Lock scheme_set_lock_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(CefUrlRequestManager);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2011-11-18 23:10:53 +01:00
|
|
|
base::LazyInstance<CefUrlRequestManager> g_manager = LAZY_INSTANCE_INITIALIZER;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
CefUrlRequestManager* CefUrlRequestManager::GetInstance() {
|
2011-05-27 18:20:32 +02:00
|
|
|
return g_manager.Pointer();
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
} // namespace
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
bool CefRegisterCustomScheme(const CefString& scheme_name,
|
|
|
|
bool is_standard,
|
|
|
|
bool is_local,
|
2012-03-22 23:10:49 +01:00
|
|
|
bool is_display_isolated) {
|
2011-05-27 18:20:32 +02:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2011-10-31 18:56:35 +01:00
|
|
|
NOTREACHED() << "context not valid";
|
2011-05-27 18:20:32 +02:00
|
|
|
return false;
|
2010-10-03 23:04:50 +02:00
|
|
|
}
|
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::UI)) {
|
|
|
|
// Must be executed on the UI thread because it calls WebKit APIs.
|
|
|
|
return CefUrlRequestManager::GetInstance()->RegisterScheme(scheme_name,
|
|
|
|
is_standard, is_local, is_display_isolated);
|
|
|
|
} else {
|
|
|
|
// Verify that the scheme has not already been registered.
|
|
|
|
if (CefUrlRequestManager::GetInstance()->HasRegisteredScheme(scheme_name)) {
|
|
|
|
NOTREACHED() << "Scheme already registered: " << scheme_name;
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-22 23:10:49 +01:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(base::IgnoreResult(&CefRegisterCustomScheme), scheme_name,
|
|
|
|
is_standard, is_local, is_display_isolated));
|
2011-05-27 18:20:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
bool CefRegisterSchemeHandlerFactory(
|
|
|
|
const CefString& scheme_name,
|
|
|
|
const CefString& domain_name,
|
|
|
|
CefRefPtr<CefSchemeHandlerFactory> factory) {
|
2011-05-27 18:20:32 +02:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2011-10-31 18:56:35 +01:00
|
|
|
NOTREACHED() << "context not valid";
|
2011-05-27 18:20:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
|
|
|
return CefUrlRequestManager::GetInstance()->AddFactory(scheme_name,
|
|
|
|
domain_name,
|
|
|
|
factory);
|
|
|
|
} else {
|
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(base::IgnoreResult(&CefRegisterSchemeHandlerFactory),
|
|
|
|
scheme_name, domain_name, factory));
|
2011-05-27 18:20:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-03-22 23:10:49 +01:00
|
|
|
bool CefClearSchemeHandlerFactories() {
|
2011-01-07 02:06:10 +01:00
|
|
|
// Verify that the context is in a valid state.
|
|
|
|
if (!CONTEXT_STATE_VALID()) {
|
2011-10-31 18:56:35 +01:00
|
|
|
NOTREACHED() << "context not valid";
|
2010-10-03 23:04:50 +02:00
|
|
|
return false;
|
2011-01-07 02:06:10 +01:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-27 18:20:32 +02:00
|
|
|
if (CefThread::CurrentlyOn(CefThread::IO)) {
|
|
|
|
CefUrlRequestManager::GetInstance()->ClearFactories();
|
2011-10-31 18:56:35 +01:00
|
|
|
|
|
|
|
// Re-register the DevTools scheme handler.
|
|
|
|
RegisterDevToolsSchemeHandler(false);
|
2011-05-27 18:20:32 +02:00
|
|
|
} else {
|
|
|
|
CefThread::PostTask(CefThread::IO, FROM_HERE,
|
2012-03-22 23:10:49 +01:00
|
|
|
base::Bind(base::IgnoreResult(&CefClearSchemeHandlerFactories)));
|
2011-05-27 18:20:32 +02:00
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|