|
6 | 6 | #include "CefBrowserHostWrapper.h"
|
7 | 7 |
|
8 | 8 | #include "include\cef_client.h"
|
| 9 | +#include "include\cef_parser.h" |
9 | 10 |
|
10 | 11 | #include "Cef.h"
|
11 | 12 | #include "CefExtensionWrapper.h"
|
|
14 | 15 | #include "CefRunFileDialogCallbackAdapter.h"
|
15 | 16 | #include "CefPdfPrintCallbackWrapper.h"
|
16 | 17 | #include "CefNavigationEntryVisitorAdapter.h"
|
| 18 | +#include "CefRegistrationWrapper.h" |
| 19 | +#include "CefDevToolsMessageObserverAdapter.h" |
17 | 20 | #include "RequestContext.h"
|
18 | 21 | #include "WindowInfo.h"
|
19 | 22 |
|
@@ -193,6 +196,79 @@ bool CefBrowserHostWrapper::HasDevTools::get()
|
193 | 196 | return _browserHost->HasDevTools();
|
194 | 197 | }
|
195 | 198 |
|
| 199 | +bool CefBrowserHostWrapper::SendDevToolsMessage(String^ messageAsJson) |
| 200 | +{ |
| 201 | + ThrowIfDisposed(); |
| 202 | + |
| 203 | + ThrowIfExecutedOnNonCefUiThread(); |
| 204 | + |
| 205 | + if (String::IsNullOrEmpty(messageAsJson)) |
| 206 | + { |
| 207 | + throw gcnew ArgumentNullException("messageAsJson"); |
| 208 | + } |
| 209 | + |
| 210 | + //NOTE: Prefix with cli:: namespace as VS2015 gets confused with std::array |
| 211 | + cli::array<Byte>^ buffer = System::Text::Encoding::UTF8->GetBytes(messageAsJson); |
| 212 | + pin_ptr<Byte> src = &buffer[0]; |
| 213 | + |
| 214 | + return _browserHost->SendDevToolsMessage(static_cast<void*>(src), buffer->Length); |
| 215 | +} |
| 216 | + |
| 217 | +int CefBrowserHostWrapper::ExecuteDevToolsMethod(int messageId, String^ method, IDictionary<String^, Object^>^ paramaters) |
| 218 | +{ |
| 219 | + ThrowIfDisposed(); |
| 220 | + |
| 221 | + ThrowIfExecutedOnNonCefUiThread(); |
| 222 | + |
| 223 | + if (paramaters == nullptr) |
| 224 | + { |
| 225 | + return _browserHost->ExecuteDevToolsMethod(messageId, StringUtils::ToNative(method), NULL); |
| 226 | + } |
| 227 | + |
| 228 | + auto val = TypeConversion::ToNative(paramaters); |
| 229 | + |
| 230 | + if (val && val->GetType() == VTYPE_DICTIONARY) |
| 231 | + { |
| 232 | + return _browserHost->ExecuteDevToolsMethod(messageId, StringUtils::ToNative(method), val->GetDictionary()); |
| 233 | + } |
| 234 | + |
| 235 | + throw gcnew Exception("Unable to convert paramaters to CefDictionaryValue."); |
| 236 | +} |
| 237 | + |
| 238 | + |
| 239 | + |
| 240 | +int CefBrowserHostWrapper::ExecuteDevToolsMethod(int messageId, String^ method, String^ paramsAsJson) |
| 241 | +{ |
| 242 | + ThrowIfDisposed(); |
| 243 | + |
| 244 | + ThrowIfExecutedOnNonCefUiThread(); |
| 245 | + |
| 246 | + if (String::IsNullOrEmpty(paramsAsJson)) |
| 247 | + { |
| 248 | + return _browserHost->ExecuteDevToolsMethod(messageId, StringUtils::ToNative(method), NULL); |
| 249 | + } |
| 250 | + |
| 251 | + auto val = CefParseJSON(StringUtils::ToNative(paramsAsJson), cef_json_parser_options_t::JSON_PARSER_RFC); |
| 252 | + |
| 253 | + if (val && val->GetType() == VTYPE_DICTIONARY) |
| 254 | + { |
| 255 | + return _browserHost->ExecuteDevToolsMethod(messageId, StringUtils::ToNative(method), val->GetDictionary()); |
| 256 | + } |
| 257 | + |
| 258 | + throw gcnew Exception("Unable to parse paramsAsJson with CefParseJSON method"); |
| 259 | +} |
| 260 | + |
| 261 | +IRegistration^ CefBrowserHostWrapper::AddDevToolsMessageObserver(IDevToolsMessageObserver^ observer) |
| 262 | +{ |
| 263 | + ThrowIfDisposed(); |
| 264 | + |
| 265 | + ThrowIfExecutedOnNonCefUiThread(); |
| 266 | + |
| 267 | + auto registration = _browserHost->AddDevToolsMessageObserver(new CefDevToolsMessageObserverAdapter(observer)); |
| 268 | + |
| 269 | + return gcnew CefRegistrationWrapper(registration); |
| 270 | +} |
| 271 | + |
196 | 272 | void CefBrowserHostWrapper::AddWordToDictionary(String^ word)
|
197 | 273 | {
|
198 | 274 | ThrowIfDisposed();
|
@@ -321,7 +397,7 @@ void CefBrowserHostWrapper::SendKeyEvent(int message, int wParam, int lParam)
|
321 | 397 | }
|
322 | 398 | }
|
323 | 399 | }
|
324 |
| - |
| 400 | + |
325 | 401 | _browserHost->SendKeyEvent(keyEvent);
|
326 | 402 | }
|
327 | 403 |
|
|
0 commit comments