@@ -31,12 +31,15 @@ namespace CefSharp
31
31
private:
32
32
gcroot<IResourceRequestHandler^> _handler;
33
33
gcroot<IWebBrowser^> _browserControl;
34
+ // For resource requests that are handled by CefRequestContextHandlerAdapter::GetResourceRequestHandler
35
+ // this will be false
36
+ bool _hasAssociatedBrowserControl;
34
37
35
38
public:
36
39
CefResourceRequestHandlerAdapter (IWebBrowser^ browserControl, IResourceRequestHandler^ handler) :
37
40
_handler (handler), _browserControl(browserControl)
38
41
{
39
-
42
+ _hasAssociatedBrowserControl = ! Object::ReferenceEquals (_browserControl, nullptr );
40
43
}
41
44
42
45
~CefResourceRequestHandlerAdapter ()
@@ -59,7 +62,7 @@ namespace CefSharp
59
62
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
60
63
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
61
64
// have a IBrowser reference already ready to use.
62
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
65
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
63
66
{
64
67
accessFilter = _handler->GetCookieAccessFilter (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
65
68
}
@@ -98,7 +101,7 @@ namespace CefSharp
98
101
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
99
102
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
100
103
// have a IBrowser reference already ready to use.
101
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
104
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
102
105
{
103
106
return (cef_return_value_t )_handler->OnBeforeResourceLoad (_browserControl, existingBrowserWrapper, frameWrapper, requestWrapper, requestCallback);
104
107
}
@@ -128,7 +131,7 @@ namespace CefSharp
128
131
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
129
132
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
130
133
// have a IBrowser reference already ready to use.
131
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
134
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
132
135
{
133
136
resourceHandler = _handler->GetResourceHandler (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
134
137
}
@@ -198,7 +201,7 @@ namespace CefSharp
198
201
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
199
202
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
200
203
// have a IBrowser reference already ready to use.
201
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
204
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
202
205
{
203
206
_handler->OnResourceRedirect (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, managedNewUrl);
204
207
}
@@ -232,7 +235,7 @@ namespace CefSharp
232
235
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
233
236
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
234
237
// have a IBrowser reference already ready to use.
235
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
238
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
236
239
{
237
240
return _handler->OnResourceResponse (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
238
241
}
@@ -260,7 +263,7 @@ namespace CefSharp
260
263
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
261
264
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
262
265
// have a IBrowser reference already ready to use.
263
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
266
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
264
267
{
265
268
responseFilter = _handler->GetResourceResponseFilter (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper);
266
269
}
@@ -298,7 +301,7 @@ namespace CefSharp
298
301
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
299
302
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
300
303
// have a IBrowser reference already ready to use.
301
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
304
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
302
305
{
303
306
_handler->OnResourceLoadComplete (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper, %responseWrapper, (UrlRequestStatus)status, receivedContentLength);
304
307
}
@@ -328,7 +331,7 @@ namespace CefSharp
328
331
// If we already have an IBrowser instance then use it, otherwise we'll pass in a scoped instance
329
332
// which cannot be accessed outside the scope of the method. We should under normal circumstanaces
330
333
// have a IBrowser reference already ready to use.
331
- if (_browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
334
+ if (_hasAssociatedBrowserControl && _browserControl->TryGetBrowserCoreById (browser->GetIdentifier (), existingBrowserWrapper))
332
335
{
333
336
allowOSExecution = _handler->OnProtocolExecution (_browserControl, existingBrowserWrapper, %frameWrapper, %requestWrapper);
334
337
}
0 commit comments