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"
|
2015-12-05 03:58:56 +01:00
|
|
|
#include "libcef/browser/net/response_filter_wrapper.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"
|
2016-06-07 20:44:59 +02:00
|
|
|
#include "chrome/browser/net/safe_search_util.h"
|
|
|
|
#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-12-05 03:58:56 +01:00
|
|
|
#include "net/filter/filter.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-12-05 03:58:56 +01:00
|
|
|
// Buffer size allocated when filtering data.
|
|
|
|
// Should match the value in net/filter/filter.cc.
|
|
|
|
const int kFilterBufSize = 32 * 1024;
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback {
|
|
|
|
public:
|
|
|
|
typedef net::CompletionCallback CallbackType;
|
|
|
|
|
|
|
|
CefBeforeResourceLoadCallbackImpl(
|
|
|
|
CefRefPtr<CefRequestImpl> cef_request,
|
|
|
|
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
|
|
|
const CallbackType& callback)
|
|
|
|
: 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),
|
2015-04-02 17:21:46 +02:00
|
|
|
callback_(callback) {
|
|
|
|
DCHECK(new_url);
|
|
|
|
DCHECK(url_request_);
|
|
|
|
|
|
|
|
// Add an association between the URLRequest and this object.
|
|
|
|
url_request_->SetUserData(UserDataKey(), new Disconnector(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
~CefBeforeResourceLoadCallbackImpl() {
|
|
|
|
if (!callback_.is_null()) {
|
|
|
|
// The callback is still pending. Cancel it now.
|
|
|
|
if (CEF_CURRENTLY_ON_IOT()) {
|
2016-06-07 20:44:59 +02:00
|
|
|
RunNow(cef_request_, new_url_, url_request_, callback_,
|
|
|
|
force_google_safesearch_, false);
|
2015-04-02 17:21:46 +02:00
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefBeforeResourceLoadCallbackImpl::RunNow,
|
2016-06-07 20:44:59 +02:00
|
|
|
cef_request_, new_url_, url_request_, 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,
|
|
|
|
base::Bind(&CefBeforeResourceLoadCallbackImpl::ContinueNow,
|
|
|
|
this, allow));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel() override {
|
|
|
|
Continue(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContinueNow(bool allow) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
if (!callback_.is_null()) {
|
2016-06-07 20:44:59 +02:00
|
|
|
RunNow(cef_request_, new_url_, url_request_, callback_,
|
|
|
|
force_google_safesearch_, allow);
|
2015-04-02 17:21:46 +02:00
|
|
|
Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect() {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
cef_request_ = nullptr;
|
|
|
|
new_url_ = nullptr;
|
|
|
|
url_request_ = nullptr;
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Used to disconnect the callback when the associated URLRequest is
|
|
|
|
// destroyed.
|
|
|
|
class Disconnector : public base::SupportsUserData::Data {
|
|
|
|
public:
|
|
|
|
explicit Disconnector(CefBeforeResourceLoadCallbackImpl* callback)
|
|
|
|
: callback_(callback) {
|
|
|
|
}
|
|
|
|
~Disconnector() override {
|
|
|
|
if (callback_)
|
|
|
|
callback_->Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect() {
|
|
|
|
callback_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefBeforeResourceLoadCallbackImpl* callback_;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void RunNow(CefRefPtr<CefRequestImpl> cef_request,
|
|
|
|
GURL* new_url,
|
|
|
|
net::URLRequest* request,
|
|
|
|
const 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())
|
|
|
|
safe_search_util::ForceGoogleSafeSearch(request, new_url);
|
|
|
|
|
2015-08-20 23:05:14 +02:00
|
|
|
callback.Run(allow ? net::OK : net::ERR_ABORTED);
|
2016-06-07 20:44:59 +02:00
|
|
|
}
|
2015-04-02 17:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void* UserDataKey() {
|
|
|
|
return &kLocatorKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
CefAuthCallbackImpl(const net::NetworkDelegate::AuthCallback& callback,
|
|
|
|
net::AuthCredentials* credentials)
|
|
|
|
: callback_(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()) {
|
|
|
|
CancelNow(callback_);
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
2012-04-16 23:15:27 +02:00
|
|
|
base::Bind(&CefAuthCallbackImpl::CancelNow, callback_));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01: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);
|
|
|
|
callback_.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT,
|
|
|
|
base::Bind(&CefAuthCallbackImpl::Continue, this, username, password));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
CancelNow(callback_);
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CEF_POST_TASK(CEF_IOT, base::Bind(&CefAuthCallbackImpl::Cancel, this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disconnect() {
|
|
|
|
callback_.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void CancelNow(const net::NetworkDelegate::AuthCallback& callback) {
|
|
|
|
CEF_REQUIRE_IOT();
|
|
|
|
callback.Run(net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
net::NetworkDelegate::AuthCallback callback_;
|
|
|
|
net::AuthCredentials* credentials_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefAuthCallbackImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-06-07 20:44:59 +02:00
|
|
|
CefNetworkDelegate::CefNetworkDelegate()
|
|
|
|
: force_google_safesearch_(nullptr) {
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefNetworkDelegate::~CefNetworkDelegate() {
|
|
|
|
}
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
// static
|
|
|
|
bool CefNetworkDelegate::AreExperimentalCookieFeaturesEnabled() {
|
|
|
|
static bool initialized = false;
|
|
|
|
static bool enabled = false;
|
|
|
|
if (!initialized) {
|
|
|
|
enabled = base::CommandLine::ForCurrentProcess()->
|
|
|
|
HasSwitch(switches::kEnableExperimentalWebPlatformFeatures);
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CefNetworkDelegate::AreStrictSecureCookiesEnabled() {
|
|
|
|
const std::string enforce_strict_secure_group =
|
|
|
|
base::FieldTrialList::FindFullName("StrictSecureCookies");
|
|
|
|
return AreExperimentalCookieFeaturesEnabled() ||
|
|
|
|
base::StartsWith(enforce_strict_secure_group, "Enabled",
|
|
|
|
base::CompareCase::INSENSITIVE_ASCII);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
int CefNetworkDelegate::OnBeforeURLRequest(
|
|
|
|
net::URLRequest* request,
|
|
|
|
const net::CompletionCallback& callback,
|
|
|
|
GURL* new_url) {
|
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,
|
2015-04-02 17:21:46 +02:00
|
|
|
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())
|
|
|
|
safe_search_util::ForceGoogleSafeSearch(request, new_url);
|
|
|
|
|
2015-04-02 17:21:46 +02:00
|
|
|
// Continue the request immediately.
|
2012-04-03 03:34:16 +02:00
|
|
|
return net::OK;
|
|
|
|
}
|
|
|
|
|
2015-12-04 19:59:14 +01:00
|
|
|
void CefNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
|
|
|
|
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();
|
|
|
|
handler->OnResourceLoadComplete(browser.get(),
|
|
|
|
frame,
|
|
|
|
cefRequest.get(),
|
|
|
|
cefResponse.get(),
|
|
|
|
status,
|
|
|
|
received_content_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
|
|
|
|
net::URLRequest* request,
|
|
|
|
const net::AuthChallengeInfo& auth_info,
|
|
|
|
const AuthCallback& callback,
|
|
|
|
net::AuthCredentials* credentials) {
|
|
|
|
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(
|
|
|
|
new CefAuthCallbackImpl(callback, credentials));
|
|
|
|
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())) {
|
|
|
|
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
|
|
|
} else {
|
|
|
|
callbackPtr->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
new CefAuthCallbackImpl(callback, credentials));
|
|
|
|
if (client->GetAuthCredentials(auth_info.is_proxy,
|
|
|
|
auth_info.challenger.host(),
|
|
|
|
auth_info.challenger.port(),
|
|
|
|
auth_info.realm,
|
|
|
|
auth_info.scheme,
|
|
|
|
callbackPtr.get())) {
|
|
|
|
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
|
|
|
|
} else {
|
|
|
|
callbackPtr->Disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
|
|
|
|
}
|
2014-04-09 19:58:31 +02:00
|
|
|
|
|
|
|
bool CefNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
|
|
|
|
const base::FilePath& path) const {
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-05 03:58:56 +01:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
bool CefNetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const {
|
|
|
|
return AreExperimentalCookieFeaturesEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefNetworkDelegate::OnAreStrictSecureCookiesEnabled() const {
|
|
|
|
return AreStrictSecureCookiesEnabled();
|
|
|
|
}
|
|
|
|
|
2015-12-05 03:58:56 +01:00
|
|
|
net::Filter* CefNetworkDelegate::SetupFilter(net::URLRequest* request,
|
|
|
|
net::Filter* filter_list) {
|
|
|
|
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);
|
|
|
|
|
|
|
|
cef_filter = handler->GetResourceResponseFilter(browser.get(), frame,
|
|
|
|
cefRequest.get(),
|
|
|
|
cefResponse.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cef_filter.get() && cef_filter->InitFilter()) {
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefResponseFilterWrapper> wrapper(
|
2015-12-05 03:58:56 +01:00
|
|
|
new CefResponseFilterWrapper(cef_filter, filter_list != nullptr));
|
|
|
|
wrapper->InitBuffer(kFilterBufSize);
|
|
|
|
|
|
|
|
if (filter_list) {
|
|
|
|
// Install the wrapper at the end of the filter list.
|
|
|
|
net::Filter* last_filter = filter_list;
|
|
|
|
do {
|
|
|
|
if (!last_filter->next_filter_.get()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
last_filter->next_filter_ = std::move(wrapper);
|
2015-12-05 03:58:56 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_filter = last_filter->next_filter_.get();
|
|
|
|
} while (last_filter);
|
|
|
|
} else {
|
|
|
|
// Only the wrapper exists.
|
|
|
|
filter_list = wrapper.release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filter_list;
|
|
|
|
}
|