Skip to content

Commit

Permalink
Core - CefResourceRequestHandlerAdapter.GetCookieAccessFilter object …
Browse files Browse the repository at this point in the history
…reference not set to an instance of an object.

For resource requests that are handled by CefRequestContextHandlerAdapter::GetResourceRequestHandler
then _browserControl field will be null, added additional checks before calling TryGetBrowserCoreById

Follow up to 4ade0b8

Issue #3967
  • Loading branch information
amaitland committed Jan 18, 2022
1 parent 5e16914 commit a4a6fb2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions CefSharp.Core.Runtime/Internals/CefResourceRequestHandlerAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ namespace CefSharp
private:
gcroot<IResourceRequestHandler^> _handler;
gcroot<IWebBrowser^> _browserControl;
//For resource requests that are handled by CefRequestContextHandlerAdapter::GetResourceRequestHandler
//this will be false
bool _hasAssociatedBrowserControl;

public:
CefResourceRequestHandlerAdapter(IWebBrowser^ browserControl, IResourceRequestHandler^ handler) :
_handler(handler), _browserControl(browserControl)
{

_hasAssociatedBrowserControl = !Object::ReferenceEquals(_browserControl, nullptr);
}

~CefResourceRequestHandlerAdapter()
Expand All @@ -59,7 +62,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
accessFilter = _handler->GetCookieAccessFilter(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
}
Expand Down Expand Up @@ -98,7 +101,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
return (cef_return_value_t)_handler->OnBeforeResourceLoad(_browserControl, existingBrowserWrapper, frameWrapper, requestWrapper, requestCallback);
}
Expand Down Expand Up @@ -128,7 +131,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
resourceHandler = _handler->GetResourceHandler(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
}
Expand Down Expand Up @@ -198,7 +201,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
_handler->OnResourceRedirect(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, managedNewUrl);
}
Expand Down Expand Up @@ -232,7 +235,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
return _handler->OnResourceResponse(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
}
Expand Down Expand Up @@ -260,7 +263,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
responseFilter = _handler->GetResourceResponseFilter(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
}
Expand Down Expand Up @@ -298,7 +301,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
_handler->OnResourceLoadComplete(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, (UrlRequestStatus)status, receivedContentLength);
}
Expand Down Expand Up @@ -328,7 +331,7 @@ namespace CefSharp
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
// have a IBrowser reference already ready to use.
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
{
allowOSExecution = _handler->OnProtocolExecution(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
}
Expand Down

0 comments on commit a4a6fb2

Please sign in to comment.