Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49707da

Browse files
committed
Core - CefResourceRequestHandlerAdapter.GetCookieAccessFilter object 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
1 parent e31faa6 commit 49707da

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

CefSharp.Core.Runtime/Internals/CefResourceRequestHandlerAdapter.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ namespace CefSharp
3131
private:
3232
gcroot<IResourceRequestHandler^> _handler;
3333
gcroot<IWebBrowser^> _browserControl;
34+
//For resource requests that are handled by CefRequestContextHandlerAdapter::GetResourceRequestHandler
35+
//this will be false
36+
bool _hasAssociatedBrowserControl;
3437

3538
public:
3639
CefResourceRequestHandlerAdapter(IWebBrowser^ browserControl, IResourceRequestHandler^ handler) :
3740
_handler(handler), _browserControl(browserControl)
3841
{
39-
42+
_hasAssociatedBrowserControl = !Object::ReferenceEquals(_browserControl, nullptr);
4043
}
4144

4245
~CefResourceRequestHandlerAdapter()
@@ -59,7 +62,7 @@ namespace CefSharp
5962
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
6063
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
6164
// have a IBrowser reference already ready to use.
62-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
65+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
6366
{
6467
accessFilter = _handler->GetCookieAccessFilter(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
6568
}
@@ -98,7 +101,7 @@ namespace CefSharp
98101
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
99102
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
100103
// have a IBrowser reference already ready to use.
101-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
104+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
102105
{
103106
return (cef_return_value_t)_handler->OnBeforeResourceLoad(_browserControl, existingBrowserWrapper, frameWrapper, requestWrapper, requestCallback);
104107
}
@@ -128,7 +131,7 @@ namespace CefSharp
128131
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
129132
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
130133
// have a IBrowser reference already ready to use.
131-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
134+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
132135
{
133136
resourceHandler = _handler->GetResourceHandler(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
134137
}
@@ -198,7 +201,7 @@ namespace CefSharp
198201
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
199202
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
200203
// have a IBrowser reference already ready to use.
201-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
204+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
202205
{
203206
_handler->OnResourceRedirect(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, managedNewUrl);
204207
}
@@ -232,7 +235,7 @@ namespace CefSharp
232235
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
233236
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
234237
// have a IBrowser reference already ready to use.
235-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
238+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
236239
{
237240
return _handler->OnResourceResponse(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
238241
}
@@ -260,7 +263,7 @@ namespace CefSharp
260263
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
261264
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
262265
// have a IBrowser reference already ready to use.
263-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
266+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
264267
{
265268
responseFilter = _handler->GetResourceResponseFilter(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
266269
}
@@ -298,7 +301,7 @@ namespace CefSharp
298301
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
299302
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
300303
// have a IBrowser reference already ready to use.
301-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
304+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
302305
{
303306
_handler->OnResourceLoadComplete(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, (UrlRequestStatus)status, receivedContentLength);
304307
}
@@ -328,7 +331,7 @@ namespace CefSharp
328331
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
329332
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
330333
// have a IBrowser reference already ready to use.
331-
if (_browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
334+
if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById(browser->GetIdentifier(), existingBrowserWrapper))
332335
{
333336
allowOSExecution = _handler->OnProtocolExecution(_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
334337
}

0 commit comments

Comments
 (0)