2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/network_delegate.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include <string>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-08-27 20:58:08 +02:00
|
|
|
#include "include/cef_urlrequest.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2018-02-06 01:21:14 +01:00
|
|
|
#include "libcef/browser/cookie_manager_impl.h"
|
2017-11-29 00:00:50 +01:00
|
|
|
#include "libcef/browser/net/net_util.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "libcef/browser/net/source_stream.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/url_request_user_data.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/common/request_impl.h"
|
2015-12-04 19:59:14 +01:00
|
|
|
#include "libcef/common/response_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/metrics/field_trial.h"
|
|
|
|
#include "base/strings/string_util.h"
|
2018-08-09 22:18:24 +02:00
|
|
|
#include "chrome/common/net/safe_search_util.h"
|
2016-06-07 20:44:59 +02:00
|
|
|
#include "components/prefs/pref_member.h"
|
|
|
|
#include "components/prefs/pref_service.h"
|
2015-12-09 17:10:16 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2012-04-04 20:18:09 +02:00
|
|
|
#include "net/base/net_errors.h"
|
2015-02-18 18:28:56 +01:00
|
|
|
#include "net/http/http_util.h"
|
2012-04-11 20:00:55 +02:00
|
|
|
#include "net/url_request/url_request.h"
|
2012-04-04 20:18:09 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
namespace {
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback {
|
|
|
|
public:
|
2018-06-19 00:08:20 +02:00
|
|
|
typedef net::CompletionOnceCallback CallbackType;
|
2015-04-02 17:21:46 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBeforeResourceLoadCallbackImpl(CefRefPtr<CefRequestImpl> cef_request,
|
|
|
|
GURL* new_url,
|
|
|
|
net::URLRequest* url_request,
|
|
|
|
bool force_google_safesearch,
|
2018-06-19 00:08:20 +02:00
|
|
|
CallbackType callback)
|
2015-04-02 17:21:46 +02:00
|
|
|
: cef_request_(cef_request),
|
|
|
|
new_url_(new_url),
|
|
|
|
url_request_(url_request),
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch_(force_google_safesearch),
|
2018-06-19 00:08:20 +02:00
|
|
|
callback_(std::move(callback)) {
|
2015-04-02 17:21:46 +02:00
|
|
|
DCHECK(new_url);
|
|
|
|
DCHECK(url_request_);
|
|
|
|
|
|
|
|
// Add an association between the URLRequest and this object.
|
2017-05-31 17:33:30 +02:00
|
|
|
url_request_->SetUserData(UserDataKey(),
|
|
|
|
base::WrapUnique(new Disconnector(this)));
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~CefBeforeResourceLoadCallbackImpl() {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
RunNow(cef_request_, new_url_, url_request_, std::move(callback_),
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch_, false);
|
2015-04-02 17:21:46 +02:00
|
|
|
} else {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefBeforeResourceLoadCallbackImpl::RunNow,
|
|
|
|
cef_request_, new_url_, url_request_,
|
|
|
|
base::Passed(std::move(callback_)),
|
|
|
|
force_google_safesearch_, false));
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Continue(bool allow) override {
|
|
|
|
// Always continue asynchronously.
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2017-05-17 11:29:28 +02:00
|
|
|
base::Bind(&CefBeforeResourceLoadCallbackImpl::ContinueNow,
|
|
|
|
this, allow));
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Cancel() override { Continue(false); }
|
2015-04-02 17:21:46 +02:00
|
|
|
|
|
|
|
void ContinueNow(bool allow) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
if (!callback_.is_null()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
RunNow(cef_request_, new_url_, url_request_, std::move(callback_),
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch_, allow);
|
2015-04-02 17:21:46 +02:00
|
|
|
Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
private:
|
2015-04-02 17:21:46 +02:00
|
|
|
void Disconnect() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
cef_request_ = nullptr;
|
|
|
|
new_url_ = nullptr;
|
|
|
|
url_request_ = nullptr;
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used to disconnect the callback when the associated URLRequest is
|
|
|
|
// destroyed.
|
|
|
|
class Disconnector : public base::SupportsUserData::Data {
|
|
|
|
public:
|
|
|
|
explicit Disconnector(CefBeforeResourceLoadCallbackImpl* callback)
|
2017-05-17 11:29:28 +02:00
|
|
|
: callback_(callback) {}
|
2015-04-02 17:21:46 +02:00
|
|
|
~Disconnector() override {
|
|
|
|
if (callback_)
|
|
|
|
callback_->Disconnect();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Disconnect() { callback_ = NULL; }
|
2015-04-02 17:21:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
CefBeforeResourceLoadCallbackImpl* callback_;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void RunNow(CefRefPtr<CefRequestImpl> cef_request,
|
|
|
|
GURL* new_url,
|
|
|
|
net::URLRequest* request,
|
2018-06-19 00:08:20 +02:00
|
|
|
CallbackType callback,
|
2016-06-07 20:44:59 +02:00
|
|
|
bool force_google_safesearch,
|
2015-04-02 17:21:46 +02:00
|
|
|
bool allow) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
|
|
|
|
if (allow) {
|
2015-11-16 23:20:34 +01:00
|
|
|
// Update the URLRequest with only the values that have been changed by
|
|
|
|
// the client.
|
|
|
|
cef_request->Get(request, true);
|
|
|
|
|
|
|
|
if (!!(cef_request->GetChanges() & CefRequestImpl::kChangedUrl)) {
|
|
|
|
// If the URL was changed then redirect the request.
|
|
|
|
GURL url = GURL(cef_request->GetURL().ToString());
|
|
|
|
DCHECK_NE(url, request->url());
|
2015-04-02 17:21:46 +02:00
|
|
|
new_url->Swap(&url);
|
2015-11-16 23:20:34 +01:00
|
|
|
}
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the association between the URLRequest and this object.
|
|
|
|
Disconnector* disconnector =
|
|
|
|
static_cast<Disconnector*>(request->GetUserData(UserDataKey()));
|
|
|
|
DCHECK(disconnector);
|
|
|
|
disconnector->Disconnect();
|
|
|
|
request->RemoveUserData(UserDataKey());
|
|
|
|
|
2015-08-20 23:05:14 +02:00
|
|
|
// Only execute the callback if the request has not been canceled.
|
2016-06-07 20:44:59 +02:00
|
|
|
if (request->status().status() != net::URLRequestStatus::CANCELED) {
|
|
|
|
if (force_google_safesearch && allow && new_url->is_empty())
|
2018-08-09 22:18:24 +02:00
|
|
|
safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
|
2016-06-07 20:44:59 +02:00
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
std::move(callback).Run(allow ? net::OK : net::ERR_ABORTED);
|
2016-06-07 20:44:59 +02:00
|
|
|
}
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static inline void* UserDataKey() { return &kLocatorKey; }
|
2015-04-02 17:21:46 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRequestImpl> cef_request_;
|
|
|
|
const GURL old_url_;
|
|
|
|
GURL* new_url_;
|
|
|
|
net::URLRequest* url_request_;
|
2016-06-07 20:44:59 +02:00
|
|
|
bool force_google_safesearch_;
|
2015-04-02 17:21:46 +02:00
|
|
|
CallbackType callback_;
|
|
|
|
|
|
|
|
// The user data key.
|
|
|
|
static int kLocatorKey;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBeforeResourceLoadCallbackImpl);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBeforeResourceLoadCallbackImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
int CefBeforeResourceLoadCallbackImpl::kLocatorKey = 0;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
class CefAuthCallbackImpl : public CefAuthCallback {
|
|
|
|
public:
|
2018-06-19 00:08:20 +02:00
|
|
|
typedef net::NetworkDelegate::AuthCallback CallbackType;
|
|
|
|
|
|
|
|
CefAuthCallbackImpl(CallbackType callback, net::AuthCredentials* credentials)
|
|
|
|
: callback_(std::move(callback)), credentials_(credentials) {}
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefAuthCallbackImpl() override {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The auth callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CancelNow(std::move(callback_));
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2018-06-19 00:08:20 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::CancelNow,
|
|
|
|
base::Passed(std::move(callback_))));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void Continue(const CefString& username, const CefString& password) override {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
credentials_->Set(username, password);
|
2018-06-19 00:08:20 +02:00
|
|
|
std::move(callback_).Run(
|
|
|
|
net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::Continue, this,
|
|
|
|
username, password));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void Cancel() override {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
|
|
|
if (!callback_.is_null()) {
|
2018-06-19 00:08:20 +02:00
|
|
|
CancelNow(std::move(callback_));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::Cancel, this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
CallbackType Disconnect() WARN_UNUSED_RESULT { return std::move(callback_); }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
private:
|
2018-06-19 00:08:20 +02:00
|
|
|
static void CancelNow(CallbackType callback) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_REQUIRE_IOT();
|
2018-06-19 00:08:20 +02:00
|
|
|
std::move(callback).Run(
|
|
|
|
net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
CallbackType callback_;
|
2012-04-03 03:34:16 +02:00
|
|
|
net::AuthCredentials* credentials_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefAuthCallbackImpl);
|
|
|
|
};
|
|
|
|
|
2017-11-29 00:00:50 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefNetworkDelegate::CefNetworkDelegate() : force_google_safesearch_(nullptr) {}
|
|
|
|
|
|
|
|
CefNetworkDelegate::~CefNetworkDelegate() {}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
std::unique_ptr<net::SourceStream> CefNetworkDelegate::CreateSourceStream(
|
|
|
|
net::URLRequest* request,
|
|
|
|
std::unique_ptr<net::SourceStream> upstream) {
|
2017-11-29 00:00:50 +01:00
|
|
|
if (net_util::IsInternalRequest(request))
|
|
|
|
return upstream;
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
CefRefPtr<CefResponseFilter> cef_filter;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestImpl> cefRequest = new CefRequestImpl();
|
|
|
|
cefRequest->Set(request);
|
|
|
|
cefRequest->SetReadOnly(true);
|
|
|
|
|
|
|
|
CefRefPtr<CefResponseImpl> cefResponse = new CefResponseImpl();
|
|
|
|
cefResponse->Set(request);
|
|
|
|
cefResponse->SetReadOnly(true);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
cef_filter = handler->GetResourceResponseFilter(
|
|
|
|
browser.get(), frame, cefRequest.get(), cefResponse.get());
|
2016-11-23 21:54:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cef_filter && cef_filter->InitFilter())
|
2018-03-20 21:15:08 +01:00
|
|
|
return std::make_unique<CefSourceStream>(cef_filter, std::move(upstream));
|
2016-11-23 21:54:29 +01:00
|
|
|
|
|
|
|
return upstream;
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
int CefNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request,
|
|
|
|
net::CompletionOnceCallback callback,
|
|
|
|
GURL* new_url) {
|
2017-11-29 00:00:50 +01:00
|
|
|
if (net_util::IsInternalRequest(request))
|
|
|
|
return net::OK;
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
const bool force_google_safesearch =
|
|
|
|
(force_google_safesearch_ && force_google_safesearch_->GetValue());
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
|
|
if (browser.get()) {
|
2015-02-18 18:28:56 +01:00
|
|
|
const CefBrowserSettings& browser_settings = browser->settings();
|
|
|
|
if (browser_settings.accept_language_list.length > 0) {
|
|
|
|
const std::string& accept_language =
|
|
|
|
net::HttpUtil::GenerateAcceptLanguageHeader(
|
|
|
|
CefString(&browser_settings.accept_language_list));
|
|
|
|
request->SetExtraRequestHeaderByName(
|
|
|
|
net::HttpRequestHeaders::kAcceptLanguage, accept_language, false);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
|
|
|
|
// Populate the request data.
|
|
|
|
CefRefPtr<CefRequestImpl> requestPtr(new CefRequestImpl());
|
|
|
|
requestPtr->Set(request);
|
2015-11-16 23:20:34 +01:00
|
|
|
requestPtr->SetTrackChanges(true);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
CefRefPtr<CefBeforeResourceLoadCallbackImpl> callbackImpl(
|
|
|
|
new CefBeforeResourceLoadCallbackImpl(requestPtr, new_url, request,
|
2016-06-07 20:44:59 +02:00
|
|
|
force_google_safesearch,
|
2018-06-19 00:08:20 +02:00
|
|
|
std::move(callback)));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
// Give the client an opportunity to evaluate the request.
|
|
|
|
cef_return_value_t retval = handler->OnBeforeResourceLoad(
|
|
|
|
browser.get(), frame, requestPtr.get(), callbackImpl.get());
|
|
|
|
if (retval == RV_CANCEL) {
|
|
|
|
// Cancel the request.
|
|
|
|
callbackImpl->Continue(false);
|
|
|
|
} else if (retval == RV_CONTINUE) {
|
|
|
|
// Continue the request.
|
|
|
|
callbackImpl->Continue(true);
|
|
|
|
}
|
2012-04-11 20:00:55 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
// Continue or cancel the request asynchronously.
|
|
|
|
return net::ERR_IO_PENDING;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
if (force_google_safesearch && new_url->is_empty())
|
2018-08-09 22:18:24 +02:00
|
|
|
safe_search_util::ForceGoogleSafeSearch(request->url(), new_url);
|
2016-06-07 20:44:59 +02:00
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
// Continue the request immediately.
|
2012-04-03 03:34:16 +02:00
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
void CefNetworkDelegate::OnCompleted(net::URLRequest* request,
|
|
|
|
bool started,
|
|
|
|
int net_error) {
|
2017-11-29 00:00:50 +01:00
|
|
|
if (net_util::IsInternalRequest(request))
|
|
|
|
return;
|
|
|
|
|
2015-12-04 19:59:14 +01:00
|
|
|
if (!started)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestImpl> cefRequest = new CefRequestImpl();
|
|
|
|
cefRequest->Set(request);
|
|
|
|
cefRequest->SetReadOnly(true);
|
|
|
|
|
|
|
|
CefRefPtr<CefResponseImpl> cefResponse = new CefResponseImpl();
|
|
|
|
cefResponse->Set(request);
|
|
|
|
cefResponse->SetReadOnly(true);
|
|
|
|
|
|
|
|
cef_urlrequest_status_t status = UR_UNKNOWN;
|
|
|
|
switch (request->status().status()) {
|
|
|
|
case net::URLRequestStatus::SUCCESS:
|
|
|
|
status = UR_SUCCESS;
|
|
|
|
break;
|
|
|
|
case net::URLRequestStatus::CANCELED:
|
|
|
|
status = UR_CANCELED;
|
|
|
|
break;
|
|
|
|
case net::URLRequestStatus::FAILED:
|
|
|
|
status = UR_FAILED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int64 received_content_length =
|
|
|
|
request->received_response_content_length();
|
2017-05-17 11:29:28 +02:00
|
|
|
handler->OnResourceLoadComplete(browser.get(), frame, cefRequest.get(),
|
|
|
|
cefResponse.get(), status,
|
2015-12-04 19:59:14 +01:00
|
|
|
received_content_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
|
|
|
|
net::URLRequest* request,
|
|
|
|
const net::AuthChallengeInfo& auth_info,
|
2018-06-19 00:08:20 +02:00
|
|
|
AuthCallback callback,
|
2012-04-03 03:34:16 +02:00
|
|
|
net::AuthCredentials* credentials) {
|
2017-11-29 00:00:50 +01:00
|
|
|
if (net_util::IsInternalRequest(request))
|
|
|
|
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(request);
|
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(request);
|
|
|
|
|
|
|
|
CefRefPtr<CefAuthCallbackImpl> callbackPtr(
|
2018-06-19 00:08:20 +02:00
|
|
|
new CefAuthCallbackImpl(std::move(callback), credentials));
|
2017-05-17 11:29:28 +02:00
|
|
|
if (handler->GetAuthCredentials(
|
|
|
|
browser.get(), frame, auth_info.is_proxy,
|
|
|
|
auth_info.challenger.host(), auth_info.challenger.port(),
|
|
|
|
auth_info.realm, auth_info.scheme, callbackPtr.get())) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
|
|
|
} else {
|
2018-06-19 00:08:20 +02:00
|
|
|
callback = callbackPtr->Disconnect();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 20:58:08 +02:00
|
|
|
CefURLRequestUserData* user_data =
|
|
|
|
(CefURLRequestUserData*)request->GetUserData(
|
|
|
|
CefURLRequestUserData::kUserDataKey);
|
|
|
|
if (user_data) {
|
|
|
|
CefRefPtr<CefURLRequestClient> client = user_data->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefAuthCallbackImpl> callbackPtr(
|
2018-06-19 00:08:20 +02:00
|
|
|
new CefAuthCallbackImpl(std::move(callback), credentials));
|
2017-05-17 11:29:28 +02:00
|
|
|
if (client->GetAuthCredentials(
|
|
|
|
auth_info.is_proxy, auth_info.challenger.host(),
|
|
|
|
auth_info.challenger.port(), auth_info.realm, auth_info.scheme,
|
|
|
|
callbackPtr.get())) {
|
2013-08-27 20:58:08 +02:00
|
|
|
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
|
|
|
} else {
|
2018-06-19 00:08:20 +02:00
|
|
|
callback = callbackPtr->Disconnect();
|
2013-08-27 20:58:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
|
|
|
}
|
2014-04-09 19:58:31 +02:00
|
|
|
|
2018-02-06 01:21:14 +01:00
|
|
|
bool CefNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
2018-10-02 14:14:11 +02:00
|
|
|
const net::CookieList& cookie_list,
|
|
|
|
bool allowed_from_caller) {
|
|
|
|
if (!allowed_from_caller)
|
|
|
|
return false;
|
2018-02-06 01:21:14 +01:00
|
|
|
if (net_util::IsInternalRequest(&request))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(&request);
|
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(&request);
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestImpl> cefRequest = new CefRequestImpl();
|
|
|
|
cefRequest->Set(&request);
|
|
|
|
cefRequest->SetReadOnly(true);
|
|
|
|
|
|
|
|
return handler->CanGetCookies(browser.get(), frame, cefRequest.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
|
|
|
|
const net::CanonicalCookie& cookie,
|
2018-10-02 14:14:11 +02:00
|
|
|
net::CookieOptions* options,
|
|
|
|
bool allowed_from_caller) {
|
|
|
|
if (!allowed_from_caller)
|
|
|
|
return false;
|
2018-02-06 01:21:14 +01:00
|
|
|
if (net_util::IsInternalRequest(&request))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserHostImpl> browser =
|
|
|
|
CefBrowserHostImpl::GetBrowserForRequest(&request);
|
|
|
|
if (browser.get()) {
|
|
|
|
CefRefPtr<CefClient> client = browser->GetClient();
|
|
|
|
if (client.get()) {
|
|
|
|
CefRefPtr<CefRequestHandler> handler = client->GetRequestHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefFrame> frame = browser->GetFrameForRequest(&request);
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestImpl> cefRequest = new CefRequestImpl();
|
|
|
|
cefRequest->Set(&request);
|
|
|
|
cefRequest->SetReadOnly(true);
|
|
|
|
|
|
|
|
CefCookie cefCookie;
|
|
|
|
if (!CefCookieManagerImpl::GetCefCookie(cookie, cefCookie))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return handler->CanSetCookie(browser.get(), frame, cefRequest.get(),
|
|
|
|
cefCookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
bool CefNetworkDelegate::OnCanAccessFile(
|
|
|
|
const net::URLRequest& request,
|
|
|
|
const base::FilePath& original_path,
|
|
|
|
const base::FilePath& absolute_path) const {
|
2014-04-09 19:58:31 +02:00
|
|
|
return true;
|
|
|
|
}
|