1111#include " RequestContextHandler.h"
1212#include " Internals\CefCompletionCallbackAdapter.h"
1313#include " Internals\CookieManager.h"
14+ #include " Internals\CefWrapper.h"
1415
1516using namespace System ::Runtime::InteropServices;
1617
@@ -29,7 +30,7 @@ namespace CefSharp
2930 // / This will be the first request context passed into a CefBrowserHost static factory method
3031 // / and all other request context objects will be ignored.
3132 // / </summary>
32- public ref class RequestContext : public IRequestContext
33+ public ref class RequestContext : public IRequestContext , public CefWrapper
3334 {
3435 private:
3536 MCefRefPtr<CefRequestContext> _requestContext;
@@ -74,24 +75,32 @@ namespace CefSharp
7475 this ->!RequestContext ();
7576
7677 delete _settings;
78+
79+ _disposed = true ;
7780 }
7881
7982 virtual bool IsSame (IRequestContext^ context)
8083 {
84+ ThrowIfDisposed ();
85+
8186 auto requestContext = (RequestContext^)context;
8287
8388 return _requestContext->IsSame (requestContext);
8489 }
8590
8691 virtual bool IsSharingWith (IRequestContext^ context)
8792 {
93+ ThrowIfDisposed ();
94+
8895 auto requestContext = (RequestContext^)context;
8996
9097 return _requestContext->IsSharingWith (requestContext);
9198 }
9299
93100 virtual ICookieManager^ GetDefaultCookieManager(ICompletionCallback^ callback)
94101 {
102+ ThrowIfDisposed ();
103+
95104 CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter (callback);
96105
97106 auto cookieManager = _requestContext->GetDefaultCookieManager (wrapper);
@@ -104,17 +113,25 @@ namespace CefSharp
104113
105114 virtual property bool IsGlobal
106115 {
107- bool get () { return _requestContext->IsGlobal (); }
116+ bool get ()
117+ {
118+ ThrowIfDisposed ();
119+ return _requestContext->IsGlobal ();
120+ }
108121 }
109122
110123 virtual bool RegisterSchemeHandlerFactory (String^ schemeName, String^ domainName, ISchemeHandlerFactory^ factory)
111124 {
125+ ThrowIfDisposed ();
126+
112127 auto wrapper = new SchemeHandlerFactoryWrapper (factory);
113128 return _requestContext->RegisterSchemeHandlerFactory (StringUtils::ToNative (schemeName), StringUtils::ToNative (domainName), wrapper);
114129 }
115130
116131 virtual bool ClearSchemeHandlerFactories ()
117132 {
133+ ThrowIfDisposed ();
134+
118135 return _requestContext->ClearSchemeHandlerFactories ();
119136 }
120137
@@ -125,7 +142,12 @@ namespace CefSharp
125142 /* --cef()--*/
126143 virtual property String^ CachePath
127144 {
128- String^ get () { return StringUtils::ToClr (_requestContext->GetCachePath ()); }
145+ String^ get ()
146+ {
147+ ThrowIfDisposed ();
148+
149+ return StringUtils::ToClr (_requestContext->GetCachePath ());
150+ }
129151 }
130152
131153 // /
@@ -137,6 +159,8 @@ namespace CefSharp
137159 /* --cef()--*/
138160 virtual void PurgePluginListCache (bool reloadPages)
139161 {
162+ ThrowIfDisposed ();
163+
140164 _requestContext->PurgePluginListCache (reloadPages);
141165 }
142166
@@ -147,6 +171,8 @@ namespace CefSharp
147171 /* --cef()--*/
148172 virtual bool HasPreference (String^ name)
149173 {
174+ ThrowIfDisposed ();
175+
150176 return _requestContext->HasPreference (StringUtils::ToNative (name));
151177 }
152178
@@ -160,6 +186,8 @@ namespace CefSharp
160186 /* --cef()--*/
161187 virtual Object^ GetPreference(String^ name)
162188 {
189+ ThrowIfDisposed ();
190+
163191 return TypeConversion::FromNative (_requestContext->GetPreference (StringUtils::ToNative (name)));
164192 }
165193
@@ -174,6 +202,8 @@ namespace CefSharp
174202 /* --cef()--*/
175203 virtual IDictionary<String^, Object^>^ GetAllPreferences(bool includeDefaults)
176204 {
205+ ThrowIfDisposed ();
206+
177207 auto preferences = _requestContext->GetAllPreferences (includeDefaults);
178208
179209 return TypeConversion::FromNative (preferences);
@@ -188,6 +218,8 @@ namespace CefSharp
188218 /* --cef()--*/
189219 virtual bool CanSetPreference (String^ name)
190220 {
221+ ThrowIfDisposed ();
222+
191223 return _requestContext->CanSetPreference (StringUtils::ToNative (name));
192224 }
193225
@@ -202,6 +234,8 @@ namespace CefSharp
202234 /* --cef(optional_param=value)--*/
203235 virtual bool SetPreference (String^ name, Object^ value, [Out] String^ %error)
204236 {
237+ ThrowIfDisposed ();
238+
205239 CefString cefError;
206240
207241 auto success = _requestContext->SetPreference (StringUtils::ToNative (name), TypeConversion::ToNative (value), cefError);
@@ -222,6 +256,8 @@ namespace CefSharp
222256 /* --cef(optional_param=callback)--*/
223257 virtual void ClearCertificateExceptions (ICompletionCallback^ callback)
224258 {
259+ ThrowIfDisposed ();
260+
225261 CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter (callback);
226262
227263 _requestContext->ClearCertificateExceptions (wrapper);
@@ -236,6 +272,8 @@ namespace CefSharp
236272 /* --cef(optional_param=callback)--*/
237273 virtual void CloseAllConnections (ICompletionCallback^ callback)
238274 {
275+ ThrowIfDisposed ();
276+
239277 CefRefPtr<CefCompletionCallback> wrapper = callback == nullptr ? NULL : new CefCompletionCallbackAdapter (callback);
240278
241279 _requestContext->CloseAllConnections (wrapper);
0 commit comments