-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CefBrowserWrapper.cpp
290 lines (245 loc) · 5.57 KB
/
CefBrowserWrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Copyright © 2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "Stdafx.h"
#include "Internals\CefFrameWrapper.h"
#include "Internals\CefBrowserWrapper.h"
#include "Internals\CefBrowserHostWrapper.h"
bool CefBrowserWrapper::IsValid::get()
{
ThrowIfDisposed();
return _browser->IsValid();
}
///
// Returns the browser host object. This method can only be called in the
// browser process.
///
/*--cef()--*/
IBrowserHost^ CefBrowserWrapper::GetHost()
{
ThrowIfDisposed();
if (_browserHost == nullptr)
{
_browserHost = gcnew CefBrowserHostWrapper(_browser->GetHost());
}
return _browserHost;
}
///
// Returns true if the browser can navigate backwards.
///
/*--cef()--*/
bool CefBrowserWrapper::CanGoBack::get()
{
ThrowIfDisposed();
return _browser->CanGoBack();
}
///
// Navigate backwards.
///
/*--cef()--*/
void CefBrowserWrapper::GoBack()
{
ThrowIfDisposed();
_browser->GoBack();
}
///
// Returns true if the browser can navigate forwards.
///
/*--cef()--*/
bool CefBrowserWrapper::CanGoForward::get()
{
ThrowIfDisposed();
return _browser->CanGoForward();
}
///
// Navigate forwards.
///
/*--cef()--*/
void CefBrowserWrapper::GoForward()
{
ThrowIfDisposed();
_browser->GoForward();
}
///
// Returns true if the browser is currently loading.
///
/*--cef()--*/
bool CefBrowserWrapper::IsLoading::get()
{
ThrowIfDisposed();
return _browser->IsLoading();
}
void CefBrowserWrapper::CloseBrowser(bool forceClose)
{
ThrowIfDisposed();
_browser->GetHost()->CloseBrowser(forceClose);
}
///
// Reload the current page.
///
/*--cef()--*/
void CefBrowserWrapper::Reload(bool ignoreCache)
{
ThrowIfDisposed();
if (ignoreCache)
{
_browser->ReloadIgnoreCache();
}
else
{
_browser->Reload();
}
}
///
// Stop loading the page.
///
/*--cef()--*/
void CefBrowserWrapper::StopLoad()
{
ThrowIfDisposed();
_browser->StopLoad();
}
///
// Returns the globally unique identifier for this browser.
///
/*--cef()--*/
int CefBrowserWrapper::Identifier::get()
{
ThrowIfDisposed();
return _browser->GetIdentifier();
}
///
// Returns true if this object is pointing to the same handle as |that|
// object.
///
/*--cef()--*/
bool CefBrowserWrapper::IsSame(IBrowser^ that)
{
ThrowIfDisposed();
return _browser->IsSame(dynamic_cast<CefBrowserWrapper^>(that)->_browser.get());
}
///
// Returns true if the window is a popup window.
///
/*--cef()--*/
bool CefBrowserWrapper::IsPopup::get()
{
ThrowIfDisposed();
return _browser->IsPopup();
}
///
// Returns true if a document has been loaded in the browser.
///
/*--cef()--*/
bool CefBrowserWrapper::HasDocument::get()
{
ThrowIfDisposed();
return _browser->HasDocument();
}
IFrame^ CefBrowserWrapper::MainFrame::get()
{
ThrowIfDisposed();
auto frame = _browser->GetMainFrame();
if (frame.get())
{
return gcnew CefFrameWrapper(frame);
}
return nullptr;
}
///
// Returns the focused frame for the browser window.
///
/*--cef()--*/
IFrame^ CefBrowserWrapper::FocusedFrame::get()
{
ThrowIfDisposed();
auto frame = _browser->GetFocusedFrame();
if (frame.get())
{
return gcnew CefFrameWrapper(frame);
}
return nullptr;
}
///
// Returns the frame with the specified identifier, or NULL if not found.
///
/*--cef(capi_name=get_frame_byident)--*/
IFrame^ CefBrowserWrapper::GetFrameByIdentifier(String^ identifier)
{
ThrowIfDisposed();
auto frame = _browser->GetFrameByIdentifier(StringUtils::ToNative(identifier));
if (frame.get())
{
return gcnew CefFrameWrapper(frame);
}
return nullptr;
}
///
// Returns the frame with the specified name, or NULL if not found.
///
/*--cef(optional_param=name)--*/
IFrame^ CefBrowserWrapper::GetFrameByName(String^ name)
{
ThrowIfDisposed();
auto frame = _browser->GetFrameByName(StringUtils::ToNative(name));
if (frame.get())
{
return gcnew CefFrameWrapper(frame);
}
return nullptr;
}
///
// Returns the number of frames that currently exist.
///
/*--cef()--*/
int CefBrowserWrapper::GetFrameCount()
{
ThrowIfDisposed();
return static_cast<int>(_browser->GetFrameCount());
}
///
// Returns the identifiers of all existing frames.
///
/*--cef(count_func=identifiers:GetFrameCount)--*/
List<String^>^ CefBrowserWrapper::GetFrameIdentifiers()
{
ThrowIfDisposed();
std::vector<CefString> identifiers;
_browser->GetFrameIdentifiers(identifiers);
List<String^>^ results = gcnew List<String^>(static_cast<int>(identifiers.size()));
for (UINT i = 0; i < identifiers.size(); i++)
{
results->Add(StringUtils::ToClr(identifiers[i]));
}
return results;
}
///
// Returns the names of all existing frames.
///
/*--cef()--*/
List<String^>^ CefBrowserWrapper::GetFrameNames()
{
ThrowIfDisposed();
std::vector<CefString> names;
_browser->GetFrameNames(names);
return StringUtils::ToClr(names);
}
IReadOnlyCollection<IFrame^>^ CefBrowserWrapper::GetAllFrames()
{
std::vector<CefString> identifiers;
_browser->GetFrameIdentifiers(identifiers);
auto results = gcnew List<IFrame^>(static_cast<int>(identifiers.size()));
for (UINT i = 0; i < identifiers.size(); i++)
{
auto frame = _browser->GetFrameByIdentifier(identifiers[i]);
if (frame.get())
{
results->Add(gcnew CefFrameWrapper(frame));
}
}
return results;
}
MCefRefPtr<CefBrowser> CefBrowserWrapper::Browser::get()
{
return _browser;
}