1818bool CefFrameWrapper::IsValid::get ()
1919{
2020 ThrowIfDisposed ();
21+
2122 return _frame->IsValid ();
2223}
2324
@@ -28,6 +29,8 @@ bool CefFrameWrapper::IsValid::get()
2829void CefFrameWrapper::Undo ()
2930{
3031 ThrowIfDisposed ();
32+ ThrowIfFrameInvalid ();
33+
3134 _frame->Undo ();
3235}
3336
@@ -38,6 +41,8 @@ void CefFrameWrapper::Undo()
3841void CefFrameWrapper::Redo ()
3942{
4043 ThrowIfDisposed ();
44+ ThrowIfFrameInvalid ();
45+
4146 _frame->Redo ();
4247}
4348
@@ -48,6 +53,8 @@ void CefFrameWrapper::Redo()
4853void CefFrameWrapper::Cut ()
4954{
5055 ThrowIfDisposed ();
56+ ThrowIfFrameInvalid ();
57+
5158 _frame->Cut ();
5259}
5360
@@ -58,6 +65,8 @@ void CefFrameWrapper::Cut()
5865void CefFrameWrapper::Copy ()
5966{
6067 ThrowIfDisposed ();
68+ ThrowIfFrameInvalid ();
69+
6170 _frame->Copy ();
6271}
6372
@@ -68,6 +77,8 @@ void CefFrameWrapper::Copy()
6877void CefFrameWrapper::Paste ()
6978{
7079 ThrowIfDisposed ();
80+ ThrowIfFrameInvalid ();
81+
7182 _frame->Paste ();
7283}
7384
@@ -78,6 +89,8 @@ void CefFrameWrapper::Paste()
7889void CefFrameWrapper::Delete ()
7990{
8091 ThrowIfDisposed ();
92+ ThrowIfFrameInvalid ();
93+
8194 _frame->Delete ();
8295}
8396
@@ -88,6 +101,8 @@ void CefFrameWrapper::Delete()
88101void CefFrameWrapper::SelectAll ()
89102{
90103 ThrowIfDisposed ();
104+ ThrowIfFrameInvalid ();
105+
91106 _frame->SelectAll ();
92107}
93108
@@ -100,6 +115,8 @@ void CefFrameWrapper::SelectAll()
100115void CefFrameWrapper::ViewSource ()
101116{
102117 ThrowIfDisposed ();
118+ ThrowIfFrameInvalid ();
119+
103120 _frame->ViewSource ();
104121}
105122
@@ -111,6 +128,8 @@ void CefFrameWrapper::ViewSource()
111128Task<String^>^ CefFrameWrapper::GetSourceAsync()
112129{
113130 ThrowIfDisposed ();
131+ ThrowIfFrameInvalid ();
132+
114133 auto taskStringVisitor = gcnew TaskStringVisitor ();
115134 _frame->GetSource (new StringVisitor (taskStringVisitor));
116135 return taskStringVisitor->Task ;
@@ -124,6 +143,8 @@ Task<String^>^ CefFrameWrapper::GetSourceAsync()
124143Task<String^>^ CefFrameWrapper::GetTextAsync()
125144{
126145 ThrowIfDisposed ();
146+ ThrowIfFrameInvalid ();
147+
127148 auto taskStringVisitor = gcnew TaskStringVisitor ();
128149 _frame->GetText (new StringVisitor (taskStringVisitor));
129150 return taskStringVisitor->Task ;
@@ -137,6 +158,8 @@ Task<String^>^ CefFrameWrapper::GetTextAsync()
137158void CefFrameWrapper::LoadRequest (IRequest^ request)
138159{
139160 ThrowIfDisposed ();
161+ ThrowIfFrameInvalid ();
162+
140163 auto requestWrapper = (CefRequestWrapper^)request;
141164 _frame->LoadRequest (requestWrapper);
142165}
@@ -148,6 +171,8 @@ void CefFrameWrapper::LoadRequest(IRequest^ request)
148171void CefFrameWrapper::LoadUrl (String^ url)
149172{
150173 ThrowIfDisposed ();
174+ ThrowIfFrameInvalid ();
175+
151176 _frame->LoadURL (StringUtils::ToNative (url));
152177}
153178
@@ -160,6 +185,8 @@ void CefFrameWrapper::LoadUrl(String^ url)
160185void CefFrameWrapper::LoadStringForUrl (String^ html, String^ url)
161186{
162187 ThrowIfDisposed ();
188+ ThrowIfFrameInvalid ();
189+
163190 _frame->LoadString (StringUtils::ToNative (html), StringUtils::ToNative (url));
164191}
165192
@@ -174,12 +201,15 @@ void CefFrameWrapper::LoadStringForUrl(String^ html, String^ url)
174201void CefFrameWrapper::ExecuteJavaScriptAsync (String^ code, String^ scriptUrl, int startLine)
175202{
176203 ThrowIfDisposed ();
204+ ThrowIfFrameInvalid ();
205+
177206 _frame->ExecuteJavaScript (StringUtils::ToNative (code), StringUtils::ToNative (scriptUrl), startLine);
178207}
179208
180209Task<JavascriptResponse^>^ CefFrameWrapper::EvaluateScriptAsync(String^ script, Nullable<TimeSpan> timeout)
181210{
182211 ThrowIfDisposed ();
212+ ThrowIfFrameInvalid ();
183213
184214 auto browser = _frame->GetBrowser ();
185215 auto host = browser->GetHost ();
@@ -196,6 +226,8 @@ Task<JavascriptResponse^>^ CefFrameWrapper::EvaluateScriptAsync(String^ script,
196226bool CefFrameWrapper::IsMain::get ()
197227{
198228 ThrowIfDisposed ();
229+ ThrowIfFrameInvalid ();
230+
199231 return _frame->IsMain ();
200232}
201233
@@ -206,6 +238,8 @@ bool CefFrameWrapper::IsMain::get()
206238bool CefFrameWrapper::IsFocused::get ()
207239{
208240 ThrowIfDisposed ();
241+ ThrowIfFrameInvalid ();
242+
209243 return _frame->IsFocused ();
210244}
211245
@@ -220,6 +254,8 @@ bool CefFrameWrapper::IsFocused::get()
220254String^ CefFrameWrapper::Name::get()
221255{
222256 ThrowIfDisposed ();
257+ ThrowIfFrameInvalid ();
258+
223259 return StringUtils::ToClr (_frame->GetName ());
224260}
225261
@@ -230,6 +266,8 @@ String^ CefFrameWrapper::Name::get()
230266Int64 CefFrameWrapper::Identifier::get ()
231267{
232268 ThrowIfDisposed ();
269+ ThrowIfFrameInvalid ();
270+
233271 return _frame->GetIdentifier ();
234272}
235273
@@ -241,6 +279,8 @@ Int64 CefFrameWrapper::Identifier::get()
241279IFrame^ CefFrameWrapper::Parent::get()
242280{
243281 ThrowIfDisposed ();
282+ ThrowIfFrameInvalid ();
283+
244284 if (_parentFrame != nullptr )
245285 {
246286 // Be paranoid about creating the cached IBrowser.
@@ -270,6 +310,8 @@ IFrame^ CefFrameWrapper::Parent::get()
270310String^ CefFrameWrapper::Url::get()
271311{
272312 ThrowIfDisposed ();
313+ ThrowIfFrameInvalid ();
314+
273315 return StringUtils::ToClr (_frame->GetURL ());
274316}
275317
@@ -280,6 +322,8 @@ String^ CefFrameWrapper::Url::get()
280322IBrowser^ CefFrameWrapper::Browser::get()
281323{
282324 ThrowIfDisposed ();
325+ ThrowIfFrameInvalid ();
326+
283327 if (_owningBrowser != nullptr )
284328 {
285329 return _owningBrowser;
@@ -307,4 +351,12 @@ IRequest^ CefFrameWrapper::CreateRequest(bool initializePostData)
307351 }
308352
309353 return gcnew CefRequestWrapper (request);
354+ }
355+
356+ void CefFrameWrapper::ThrowIfFrameInvalid ()
357+ {
358+ if (_frame->IsValid () == false )
359+ {
360+ throw gcnew Exception (L" The underlying frame is no longer valid - please check the IsValid property before calling!" );
361+ }
310362}
0 commit comments