mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-02 20:26:59 +01:00
Cancel NetworkService requests when the browser is destroyed (see issue #2622).
Pending requests that are associated with a browser will be canceled when that browser is destroyed. Pending requests that are not associated with a browser (e.g. created using CefURLRequest::Create), and that use the global context, may still be pending when CefShutdown is called. For this reason the no_debugct_check attribute has been added for CefResourceRequestHandler and CefCookieAccessFilter interfaces. To test: Load a YouTube video or other long-loading content in cefclient and close the application. No assertions trigger for leaked CefFrame objects.
This commit is contained in:
parent
ba0e1b5719
commit
2ea173a254
@ -55,7 +55,7 @@ class CefCookieAccessFilter;
|
||||
// methods of this class will be called on the IO thread unless otherwise
|
||||
// indicated.
|
||||
///
|
||||
/*--cef(source=client)--*/
|
||||
/*--cef(source=client,no_debugct_check)--*/
|
||||
class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
public:
|
||||
typedef cef_return_value_t ReturnValue;
|
||||
@ -205,7 +205,7 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
|
||||
// resource requests. The methods of this class will be called on the IO thread
|
||||
// unless otherwise indicated.
|
||||
///
|
||||
/*--cef(source=client)--*/
|
||||
/*--cef(source=client,no_debugct_check)--*/
|
||||
class CefCookieAccessFilter : public virtual CefBaseRefCounted {
|
||||
public:
|
||||
///
|
||||
|
@ -157,8 +157,7 @@ class InterceptedRequest : public network::mojom::URLLoader,
|
||||
bool intercept_request,
|
||||
bool intercept_only);
|
||||
void InterceptResponseReceived(const GURL& original_url,
|
||||
std::unique_ptr<ResourceResponse> response,
|
||||
bool cancel_request);
|
||||
std::unique_ptr<ResourceResponse> response);
|
||||
void ContinueAfterIntercept();
|
||||
void ContinueAfterInterceptWithOverride(
|
||||
std::unique_ptr<ResourceResponse> response);
|
||||
@ -351,7 +350,9 @@ void InterceptedRequest::Restart() {
|
||||
factory_->request_handler_->OnBeforeRequest(
|
||||
id_, &request_, request_was_redirected_,
|
||||
base::BindOnce(&InterceptedRequest::BeforeRequestReceived,
|
||||
weak_factory_.GetWeakPtr(), original_url));
|
||||
weak_factory_.GetWeakPtr(), original_url),
|
||||
base::BindOnce(&InterceptedRequest::SendErrorAndCompleteImmediately,
|
||||
weak_factory_.GetWeakPtr(), net::ERR_ABORTED));
|
||||
}
|
||||
|
||||
void InterceptedRequest::OnLoaderCreated(
|
||||
@ -589,8 +590,7 @@ void InterceptedRequest::BeforeRequestReceived(const GURL& original_url,
|
||||
|
||||
if (input_stream_previously_failed_ || !intercept_request_) {
|
||||
// Equivalent to no interception.
|
||||
InterceptResponseReceived(original_url, nullptr,
|
||||
false /* cancel_request */);
|
||||
InterceptResponseReceived(original_url, nullptr);
|
||||
} else {
|
||||
if (request_.referrer.is_valid()) {
|
||||
// Intentionally override if referrer header already exists.
|
||||
@ -610,16 +610,7 @@ void InterceptedRequest::BeforeRequestReceived(const GURL& original_url,
|
||||
|
||||
void InterceptedRequest::InterceptResponseReceived(
|
||||
const GURL& original_url,
|
||||
std::unique_ptr<ResourceResponse> response,
|
||||
bool cancel_request) {
|
||||
if (cancel_request) {
|
||||
// A response object shouldn't be created if we're canceling.
|
||||
DCHECK(!response);
|
||||
|
||||
SendErrorAndCompleteImmediately(net::ERR_ABORTED);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<ResourceResponse> response) {
|
||||
if (request_.url != original_url) {
|
||||
// A response object shouldn't be created if we're redirecting.
|
||||
DCHECK(!response);
|
||||
@ -974,7 +965,8 @@ void InterceptedRequestHandler::OnBeforeRequest(
|
||||
const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
bool request_was_redirected,
|
||||
OnBeforeRequestResultCallback callback) {
|
||||
OnBeforeRequestResultCallback callback,
|
||||
CancelRequestCallback cancel_callback) {
|
||||
std::move(callback).Run(false, false);
|
||||
}
|
||||
|
||||
@ -982,7 +974,7 @@ void InterceptedRequestHandler::ShouldInterceptRequest(
|
||||
const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
ShouldInterceptRequestResultCallback callback) {
|
||||
std::move(callback).Run(nullptr, false);
|
||||
std::move(callback).Run(nullptr);
|
||||
}
|
||||
|
||||
void InterceptedRequestHandler::OnRequestResponse(
|
||||
|
@ -25,30 +25,31 @@ class InterceptedRequest;
|
||||
class ResourceContextData;
|
||||
|
||||
// Implement this interface to to evaluate requests. All methods are called on
|
||||
// the IO thread.
|
||||
// the IO thread, and all callbacks must be executed on the IO thread.
|
||||
class InterceptedRequestHandler {
|
||||
public:
|
||||
InterceptedRequestHandler();
|
||||
virtual ~InterceptedRequestHandler();
|
||||
|
||||
// Optionally modify |request| and return true to proceed. Set
|
||||
// |intercept_request| to false if the request will not be intercepted.
|
||||
// Set |intercept_only| to true if the loader should not proceed unless
|
||||
// the request is intercepted. Return false to abort the request with
|
||||
// net::ERR_ACCESS_DENIED.
|
||||
// Optionally modify |request| and execute |callback| to continue the request.
|
||||
// Set |intercept_request| to false if the request will not be intercepted.
|
||||
// Set |intercept_only| to true if the loader should not proceed unless the
|
||||
// request is intercepted. Keep a reference to |cancel_callback| and execute
|
||||
// at any time to cancel the request.
|
||||
using OnBeforeRequestResultCallback =
|
||||
base::OnceCallback<void(bool /* intercept_request */,
|
||||
bool /* intercept_only */)>;
|
||||
using CancelRequestCallback = base::OnceClosure;
|
||||
virtual void OnBeforeRequest(const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
bool request_was_redirected,
|
||||
OnBeforeRequestResultCallback callback);
|
||||
OnBeforeRequestResultCallback callback,
|
||||
CancelRequestCallback cancel_callback);
|
||||
|
||||
// Optionally modify |request| and execute |callback| on the IO thread after
|
||||
// determining if the request hould be intercepted.
|
||||
// Optionally modify |request| and execute |callback| after determining if the
|
||||
// request hould be intercepted.
|
||||
using ShouldInterceptRequestResultCallback =
|
||||
base::OnceCallback<void(std::unique_ptr<ResourceResponse>,
|
||||
bool /* cancel_request */)>;
|
||||
base::OnceCallback<void(std::unique_ptr<ResourceResponse>)>;
|
||||
virtual void ShouldInterceptRequest(
|
||||
const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
|
@ -104,7 +104,8 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
void Reset(CefRefPtr<CefResourceRequestHandler> handler,
|
||||
CefRefPtr<CefSchemeHandlerFactory> scheme_factory,
|
||||
CefRefPtr<CefRequestImpl> request,
|
||||
bool request_was_redirected) {
|
||||
bool request_was_redirected,
|
||||
CancelRequestCallback cancel_callback) {
|
||||
handler_ = handler;
|
||||
scheme_factory_ = scheme_factory;
|
||||
cookie_filter_ = nullptr;
|
||||
@ -112,6 +113,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
pending_response_ = nullptr;
|
||||
request_was_redirected_ = request_was_redirected;
|
||||
was_custom_handled_ = false;
|
||||
cancel_callback_ = std::move(cancel_callback);
|
||||
}
|
||||
|
||||
CefRefPtr<CefResourceRequestHandler> handler_;
|
||||
@ -121,31 +123,75 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
CefRefPtr<CefResponseImpl> pending_response_;
|
||||
bool request_was_redirected_ = false;
|
||||
bool was_custom_handled_ = false;
|
||||
CancelRequestCallback cancel_callback_;
|
||||
};
|
||||
|
||||
struct PendingRequest {
|
||||
PendingRequest(const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
bool request_was_redirected,
|
||||
OnBeforeRequestResultCallback callback)
|
||||
OnBeforeRequestResultCallback callback,
|
||||
CancelRequestCallback cancel_callback)
|
||||
: id_(id),
|
||||
request_(request),
|
||||
request_was_redirected_(request_was_redirected),
|
||||
callback_(std::move(callback)) {}
|
||||
callback_(std::move(callback)),
|
||||
cancel_callback_(std::move(cancel_callback)) {}
|
||||
|
||||
void Run(InterceptedRequestHandlerWrapper* self) {
|
||||
self->OnBeforeRequest(id_, request_, request_was_redirected_,
|
||||
std::move(callback_));
|
||||
std::move(callback_), std::move(cancel_callback_));
|
||||
}
|
||||
|
||||
const RequestId id_;
|
||||
network::ResourceRequest* const request_;
|
||||
const bool request_was_redirected_;
|
||||
OnBeforeRequestResultCallback callback_;
|
||||
CancelRequestCallback cancel_callback_;
|
||||
};
|
||||
|
||||
class BrowserObserver : public CefBrowserHostImpl::Observer {
|
||||
public:
|
||||
BrowserObserver() = default;
|
||||
|
||||
void SetWrapper(base::WeakPtr<InterceptedRequestHandlerWrapper> wrapper) {
|
||||
CEF_REQUIRE_IOT();
|
||||
wrapper_ = wrapper;
|
||||
}
|
||||
|
||||
void OnBrowserDestroyed(CefBrowserHostImpl* browser) override {
|
||||
CEF_REQUIRE_UIT();
|
||||
browser->RemoveObserver(this);
|
||||
CEF_POST_TASK(
|
||||
CEF_IOT,
|
||||
base::BindOnce(&InterceptedRequestHandlerWrapper::OnBrowserDestroyed,
|
||||
wrapper_));
|
||||
}
|
||||
|
||||
private:
|
||||
base::WeakPtr<InterceptedRequestHandlerWrapper> wrapper_;
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserObserver);
|
||||
};
|
||||
|
||||
InterceptedRequestHandlerWrapper() : weak_ptr_factory_(this) {}
|
||||
~InterceptedRequestHandlerWrapper() override {}
|
||||
|
||||
~InterceptedRequestHandlerWrapper() override {
|
||||
if (browser_observer_) {
|
||||
CEF_POST_TASK(
|
||||
CEF_UIT, base::BindOnce(&InterceptedRequestHandlerWrapper::
|
||||
RemoveBrowserObserverOnUIThread,
|
||||
browser_info_, std::move(browser_observer_)));
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveBrowserObserverOnUIThread(
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
std::unique_ptr<BrowserObserver> observer) {
|
||||
// The browser may already have been destroyed when this method is executed.
|
||||
auto browser = browser_info->browser();
|
||||
if (browser)
|
||||
browser->RemoveObserver(observer.get());
|
||||
}
|
||||
|
||||
void Initialize(content::BrowserContext* browser_context,
|
||||
CefRefPtr<CefBrowserHostImpl> browser,
|
||||
@ -165,8 +211,12 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
DCHECK(resource_context_);
|
||||
|
||||
// Don't hold a RefPtr to the CefBrowserHostImpl.
|
||||
if (browser)
|
||||
if (browser) {
|
||||
browser_info_ = browser->browser_info();
|
||||
|
||||
browser_observer_.reset(new BrowserObserver());
|
||||
browser->AddObserver(browser_observer_.get());
|
||||
}
|
||||
frame_ = frame;
|
||||
|
||||
render_process_id_ = render_process_id;
|
||||
@ -194,6 +244,10 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
CEF_REQUIRE_IOT();
|
||||
initialized_ = true;
|
||||
|
||||
if (browser_observer_) {
|
||||
browser_observer_->SetWrapper(weak_ptr_factory_.GetWeakPtr());
|
||||
}
|
||||
|
||||
// Continue any pending requests.
|
||||
if (!pending_requests_.empty()) {
|
||||
for (const auto& request : pending_requests_)
|
||||
@ -206,13 +260,15 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
void OnBeforeRequest(const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
bool request_was_redirected,
|
||||
OnBeforeRequestResultCallback callback) override {
|
||||
OnBeforeRequestResultCallback callback,
|
||||
CancelRequestCallback cancel_callback) override {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
if (!initialized_) {
|
||||
// Queue requests until we're initialized.
|
||||
pending_requests_.push_back(std::make_unique<PendingRequest>(
|
||||
id, request, request_was_redirected, std::move(callback)));
|
||||
id, request, request_was_redirected, std::move(callback),
|
||||
std::move(cancel_callback)));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -244,7 +300,8 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
requestPtr = nullptr;
|
||||
|
||||
// May have a handler and/or scheme factory.
|
||||
state->Reset(handler, scheme_factory, requestPtr, request_was_redirected);
|
||||
state->Reset(handler, scheme_factory, requestPtr, request_was_redirected,
|
||||
std::move(cancel_callback));
|
||||
|
||||
if (handler) {
|
||||
state->cookie_filter_ = handler->GetCookieAccessFilter(
|
||||
@ -261,10 +318,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
MaybeLoadCookies(state, request, std::move(exec_callback));
|
||||
MaybeLoadCookies(id, state, request, std::move(exec_callback));
|
||||
}
|
||||
|
||||
void MaybeLoadCookies(RequestState* state,
|
||||
void MaybeLoadCookies(const RequestId& id,
|
||||
RequestState* state,
|
||||
network::ResourceRequest* request,
|
||||
base::OnceClosure callback) {
|
||||
CEF_REQUIRE_IOT();
|
||||
@ -272,25 +330,38 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
// We need to load/save cookies ourselves for custom-handled requests, or
|
||||
// if we're using a cookie filter.
|
||||
auto allow_cookie_callback =
|
||||
base::BindRepeating(&InterceptedRequestHandlerWrapper::AllowCookieLoad,
|
||||
weak_ptr_factory_.GetWeakPtr(), state);
|
||||
state->cookie_filter_
|
||||
? base::BindRepeating(
|
||||
&InterceptedRequestHandlerWrapper::AllowCookieLoad,
|
||||
weak_ptr_factory_.GetWeakPtr(), id)
|
||||
: base::BindRepeating(
|
||||
&InterceptedRequestHandlerWrapper::AllowCookieAlways);
|
||||
auto done_cookie_callback = base::BindOnce(
|
||||
&InterceptedRequestHandlerWrapper::ContinueWithLoadedCookies,
|
||||
weak_ptr_factory_.GetWeakPtr(), state, request, std::move(callback));
|
||||
weak_ptr_factory_.GetWeakPtr(), id, request, std::move(callback));
|
||||
net_service::LoadCookies(browser_context_, *request, allow_cookie_callback,
|
||||
std::move(done_cookie_callback));
|
||||
}
|
||||
|
||||
void AllowCookieLoad(RequestState* state,
|
||||
static void AllowCookieAlways(const net::CanonicalCookie& cookie,
|
||||
bool* allow) {
|
||||
*allow = true;
|
||||
}
|
||||
|
||||
void AllowCookieLoad(const RequestId& id,
|
||||
const net::CanonicalCookie& cookie,
|
||||
bool* allow) {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
if (!state->cookie_filter_) {
|
||||
*allow = true;
|
||||
RequestState* state = GetState(id);
|
||||
if (!state) {
|
||||
// The request may have been canceled while the async callback was
|
||||
// pending.
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(state->cookie_filter_);
|
||||
|
||||
CefCookie cef_cookie;
|
||||
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
|
||||
*allow = state->cookie_filter_->CanSendCookie(
|
||||
@ -298,13 +369,20 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
void ContinueWithLoadedCookies(RequestState* state,
|
||||
void ContinueWithLoadedCookies(const RequestId& id,
|
||||
network::ResourceRequest* request,
|
||||
base::OnceClosure callback,
|
||||
int total_count,
|
||||
net::CookieList allowed_cookies) {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
RequestState* state = GetState(id);
|
||||
if (!state) {
|
||||
// The request may have been canceled while the async callback was
|
||||
// pending.
|
||||
return;
|
||||
}
|
||||
|
||||
if (state->cookie_filter_) {
|
||||
// Also add/save cookies ourselves for default-handled network requests
|
||||
// so that we can filter them. This will be a no-op for custom-handled
|
||||
@ -372,7 +450,12 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
RequestState* state = GetState(id);
|
||||
DCHECK(state);
|
||||
if (!state) {
|
||||
// The request may have been canceled while the async callback was
|
||||
// pending.
|
||||
return;
|
||||
}
|
||||
|
||||
// Must have a handler and/or scheme factory.
|
||||
DCHECK(state->handler_ || state->scheme_factory_);
|
||||
DCHECK(state->pending_request_);
|
||||
@ -395,13 +478,13 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
|
||||
if (!allow) {
|
||||
// Cancel the request.
|
||||
std::move(callback).Run(nullptr, true /* cancel_request */);
|
||||
std::move(state->cancel_callback_).Run();
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect) {
|
||||
// Performing a redirect.
|
||||
std::move(callback).Run(nullptr, false /* cancel_request */);
|
||||
std::move(callback).Run(nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -429,8 +512,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
}
|
||||
|
||||
// Continue the request.
|
||||
std::move(callback).Run(std::move(resource_response),
|
||||
false /* cancel_request */);
|
||||
std::move(callback).Run(std::move(resource_response));
|
||||
}
|
||||
|
||||
void ProcessResponseHeaders(
|
||||
@ -468,7 +550,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
if (!state->handler_) {
|
||||
// Cookies may come from a scheme handler.
|
||||
MaybeSaveCookies(
|
||||
state, request, head,
|
||||
id, state, request, head,
|
||||
base::BindOnce(
|
||||
std::move(callback), ResponseMode::CONTINUE, nullptr,
|
||||
redirect_info.has_value() ? redirect_info->new_url : GURL()));
|
||||
@ -479,13 +561,15 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
DCHECK(state->pending_response_);
|
||||
|
||||
if (redirect_info.has_value()) {
|
||||
HandleRedirect(state, request, head, *redirect_info, std::move(callback));
|
||||
HandleRedirect(id, state, request, head, *redirect_info,
|
||||
std::move(callback));
|
||||
} else {
|
||||
HandleResponse(state, request, head, std::move(callback));
|
||||
HandleResponse(id, state, request, head, std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
void HandleRedirect(RequestState* state,
|
||||
void HandleRedirect(const RequestId& id,
|
||||
RequestState* state,
|
||||
network::ResourceRequest* request,
|
||||
const network::ResourceResponseHead& head,
|
||||
const net::RedirectInfo& redirect_info,
|
||||
@ -517,10 +601,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
auto exec_callback = base::BindOnce(
|
||||
std::move(callback), ResponseMode::CONTINUE, nullptr, new_url);
|
||||
|
||||
MaybeSaveCookies(state, request, head, std::move(exec_callback));
|
||||
MaybeSaveCookies(id, state, request, head, std::move(exec_callback));
|
||||
}
|
||||
|
||||
void HandleResponse(RequestState* state,
|
||||
void HandleResponse(const RequestId& id,
|
||||
RequestState* state,
|
||||
network::ResourceRequest* request,
|
||||
const network::ResourceResponseHead& head,
|
||||
OnRequestResponseResultCallback callback) {
|
||||
@ -565,10 +650,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
MaybeSaveCookies(state, request, head, std::move(exec_callback));
|
||||
MaybeSaveCookies(id, state, request, head, std::move(exec_callback));
|
||||
}
|
||||
|
||||
void MaybeSaveCookies(RequestState* state,
|
||||
void MaybeSaveCookies(const RequestId& id,
|
||||
RequestState* state,
|
||||
network::ResourceRequest* request,
|
||||
const network::ResourceResponseHead& head,
|
||||
base::OnceClosure callback) {
|
||||
@ -583,26 +669,34 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
// We need to load/save cookies ourselves for custom-handled requests, or
|
||||
// if we're using a cookie filter.
|
||||
auto allow_cookie_callback =
|
||||
base::BindRepeating(&InterceptedRequestHandlerWrapper::AllowCookieSave,
|
||||
weak_ptr_factory_.GetWeakPtr(), state);
|
||||
state->cookie_filter_
|
||||
? base::BindRepeating(
|
||||
&InterceptedRequestHandlerWrapper::AllowCookieSave,
|
||||
weak_ptr_factory_.GetWeakPtr(), id)
|
||||
: base::BindRepeating(
|
||||
&InterceptedRequestHandlerWrapper::AllowCookieAlways);
|
||||
auto done_cookie_callback = base::BindOnce(
|
||||
&InterceptedRequestHandlerWrapper::ContinueWithSavedCookies,
|
||||
weak_ptr_factory_.GetWeakPtr(), state, std::move(callback));
|
||||
weak_ptr_factory_.GetWeakPtr(), id, std::move(callback));
|
||||
net_service::SaveCookies(browser_context_, *request, head,
|
||||
allow_cookie_callback,
|
||||
std::move(done_cookie_callback));
|
||||
}
|
||||
|
||||
void AllowCookieSave(RequestState* state,
|
||||
void AllowCookieSave(const RequestId& id,
|
||||
const net::CanonicalCookie& cookie,
|
||||
bool* allow) {
|
||||
CEF_REQUIRE_IOT();
|
||||
|
||||
if (!state->cookie_filter_) {
|
||||
*allow = true;
|
||||
RequestState* state = GetState(id);
|
||||
if (!state) {
|
||||
// The request may have been canceled while the async callback was
|
||||
// pending.
|
||||
return;
|
||||
}
|
||||
|
||||
DCHECK(state->cookie_filter_);
|
||||
|
||||
CefCookie cef_cookie;
|
||||
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
|
||||
*allow = state->cookie_filter_->CanSaveCookie(
|
||||
@ -611,7 +705,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
void ContinueWithSavedCookies(RequestState* state,
|
||||
void ContinueWithSavedCookies(const RequestId& id,
|
||||
base::OnceClosure callback,
|
||||
int total_count,
|
||||
net::CookieList allowed_cookies) {
|
||||
@ -747,6 +841,21 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Called when the associated browser, if any, is destroyed.
|
||||
void OnBrowserDestroyed() {
|
||||
CEF_REQUIRE_IOT();
|
||||
DCHECK(initialized_);
|
||||
|
||||
DCHECK(browser_observer_);
|
||||
browser_observer_.reset();
|
||||
|
||||
// Cancel any pending requests.
|
||||
while (!request_map_.empty()) {
|
||||
// Results in a call to RemoveState().
|
||||
std::move(request_map_.begin()->second->cancel_callback_).Run();
|
||||
}
|
||||
}
|
||||
|
||||
static CefRefPtr<CefRequestImpl> MakeRequest(
|
||||
const network::ResourceRequest* request,
|
||||
int64 request_id,
|
||||
@ -786,6 +895,9 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
|
||||
using PendingRequests = std::vector<std::unique_ptr<PendingRequest>>;
|
||||
PendingRequests pending_requests_;
|
||||
|
||||
// Used to recieve notification of browser destruction.
|
||||
std::unique_ptr<BrowserObserver> browser_observer_;
|
||||
|
||||
base::WeakPtrFactory<InterceptedRequestHandlerWrapper> weak_ptr_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(InterceptedRequestHandlerWrapper);
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=c9c6c2cd02b565596a1173e95654655da80e1ef2$
|
||||
// $hash=86c8103564d3acb6cc76510c7c0b015fc0605d80$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/cookie_access_filter_cpptoc.h"
|
||||
@ -17,7 +17,6 @@
|
||||
#include "libcef_dll/ctocpp/frame_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/response_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -29,8 +28,6 @@ cookie_access_filter_can_send_cookie(struct _cef_cookie_access_filter_t* self,
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request,
|
||||
const struct _cef_cookie_t* cookie) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -67,8 +64,6 @@ cookie_access_filter_can_save_cookie(struct _cef_cookie_access_filter_t* self,
|
||||
cef_request_t* request,
|
||||
struct _cef_response_t* response,
|
||||
const struct _cef_cookie_t* cookie) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -114,9 +109,7 @@ CefCookieAccessFilterCppToC::CefCookieAccessFilterCppToC() {
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefCookieAccessFilterCppToC::~CefCookieAccessFilterCppToC() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
CefCookieAccessFilterCppToC::~CefCookieAccessFilterCppToC() {}
|
||||
|
||||
template <>
|
||||
CefRefPtr<CefCookieAccessFilter> CefCppToCRefCounted<
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=533f1f8905a3079efe14fba7cb4e20ab59ea667f$
|
||||
// $hash=70457d6e92ff60ee9955d451f5d3d78b70535510$
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/resource_request_handler_cpptoc.h"
|
||||
@ -21,7 +21,6 @@
|
||||
#include "libcef_dll/ctocpp/request_callback_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/request_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/response_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -33,8 +32,6 @@ resource_request_handler_get_cookie_access_filter(
|
||||
cef_browser_t* browser,
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -63,8 +60,6 @@ resource_request_handler_on_before_resource_load(
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request,
|
||||
cef_request_callback_t* callback) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -97,8 +92,6 @@ resource_request_handler_get_resource_handler(
|
||||
cef_browser_t* browser,
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -127,8 +120,6 @@ void CEF_CALLBACK resource_request_handler_on_resource_redirect(
|
||||
cef_request_t* request,
|
||||
struct _cef_response_t* response,
|
||||
cef_string_t* new_url) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -164,8 +155,6 @@ int CEF_CALLBACK resource_request_handler_on_resource_response(
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request,
|
||||
struct _cef_response_t* response) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -197,8 +186,6 @@ resource_request_handler_get_resource_response_filter(
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request,
|
||||
struct _cef_response_t* response) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -232,8 +219,6 @@ void CEF_CALLBACK resource_request_handler_on_resource_load_complete(
|
||||
struct _cef_response_t* response,
|
||||
cef_urlrequest_status_t status,
|
||||
int64 received_content_length) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -262,8 +247,6 @@ void CEF_CALLBACK resource_request_handler_on_protocol_execution(
|
||||
cef_frame_t* frame,
|
||||
cef_request_t* request,
|
||||
int* allow_os_execution) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
@ -318,9 +301,7 @@ CefResourceRequestHandlerCppToC::CefResourceRequestHandlerCppToC() {
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefResourceRequestHandlerCppToC::~CefResourceRequestHandlerCppToC() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
CefResourceRequestHandlerCppToC::~CefResourceRequestHandlerCppToC() {}
|
||||
|
||||
template <>
|
||||
CefRefPtr<CefResourceRequestHandler>
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=f79e09e667e0fd7447f63a5b02c17ba6f287d8d9$
|
||||
// $hash=09b3c8fb5fae6f4e8e47f8056a0ce1b98f8e38e0$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/cookie_access_filter_ctocpp.h"
|
||||
@ -17,7 +17,6 @@
|
||||
#include "libcef_dll/cpptoc/frame_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/response_cpptoc.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
@ -26,8 +25,6 @@ bool CefCookieAccessFilterCToCpp::CanSendCookie(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
const CefCookie& cookie) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_cookie_access_filter_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, can_send_cookie))
|
||||
return false;
|
||||
@ -55,8 +52,6 @@ bool CefCookieAccessFilterCToCpp::CanSaveCookie(CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
const CefCookie& cookie) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_cookie_access_filter_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, can_save_cookie))
|
||||
return false;
|
||||
@ -89,9 +84,7 @@ CefCookieAccessFilterCToCpp::CefCookieAccessFilterCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefCookieAccessFilterCToCpp::~CefCookieAccessFilterCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
CefCookieAccessFilterCToCpp::~CefCookieAccessFilterCToCpp() {}
|
||||
|
||||
template <>
|
||||
cef_cookie_access_filter_t* CefCToCppRefCounted<
|
||||
|
@ -9,7 +9,7 @@
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
// $hash=217e200e9197054500554d62765c3c145bebfea7$
|
||||
// $hash=ad04f871a623e36f715e7742bda6c0bb3d0eb28e$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/resource_request_handler_ctocpp.h"
|
||||
@ -21,7 +21,6 @@
|
||||
#include "libcef_dll/ctocpp/cookie_access_filter_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/resource_handler_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/response_filter_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
@ -31,8 +30,6 @@ CefResourceRequestHandlerCToCpp::GetCookieAccessFilter(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, get_cookie_access_filter))
|
||||
return NULL;
|
||||
@ -61,8 +58,6 @@ CefResourceRequestHandlerCToCpp::OnBeforeResourceLoad(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefRequestCallback> callback) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_before_resource_load))
|
||||
return RV_CONTINUE;
|
||||
@ -95,8 +90,6 @@ CefResourceRequestHandlerCToCpp::GetResourceHandler(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, get_resource_handler))
|
||||
return NULL;
|
||||
@ -125,8 +118,6 @@ void CefResourceRequestHandlerCToCpp::OnResourceRedirect(
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response,
|
||||
CefString& new_url) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_resource_redirect))
|
||||
return;
|
||||
@ -156,8 +147,6 @@ bool CefResourceRequestHandlerCToCpp::OnResourceResponse(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_resource_response))
|
||||
return false;
|
||||
@ -190,8 +179,6 @@ CefResourceRequestHandlerCToCpp::GetResourceResponseFilter(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefResponse> response) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, get_resource_response_filter))
|
||||
return NULL;
|
||||
@ -225,8 +212,6 @@ void CefResourceRequestHandlerCToCpp::OnResourceLoadComplete(
|
||||
CefRefPtr<CefResponse> response,
|
||||
URLRequestStatus status,
|
||||
int64 received_content_length) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_resource_load_complete))
|
||||
return;
|
||||
@ -256,8 +241,6 @@ void CefResourceRequestHandlerCToCpp::OnProtocolExecution(
|
||||
CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request,
|
||||
bool& allow_os_execution) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_resource_request_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_protocol_execution))
|
||||
return;
|
||||
@ -288,9 +271,7 @@ CefResourceRequestHandlerCToCpp::CefResourceRequestHandlerCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefResourceRequestHandlerCToCpp::~CefResourceRequestHandlerCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
CefResourceRequestHandlerCToCpp::~CefResourceRequestHandlerCToCpp() {}
|
||||
|
||||
template <>
|
||||
cef_resource_request_handler_t* CefCToCppRefCounted<
|
||||
|
Loading…
x
Reference in New Issue
Block a user