MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Browser / CreateBrowserOptionsWebView

Method CreateBrowserOptionsWebView

BrowserWindow.cpp:273–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273HRESULT BrowserWindow::CreateBrowserOptionsWebView()
274{
275 return m_uiEnv->CreateCoreWebView2Controller(m_hWnd, Callback<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>(
276 [this](HRESULT result, ICoreWebView2Controller* host) -> HRESULT
277 {
278 if (!SUCCEEDED(result))
279 {
280 OutputDebugString(L"Options WebView creation failed\n");
281 return result;
282 }
283 // WebView created
284 m_optionsController = host;
285 CheckFailure(m_optionsController->get_CoreWebView2(&m_optionsWebView), L"");
286
287 wil::com_ptr<ICoreWebView2Settings> settings;
288 RETURN_IF_FAILED(m_optionsWebView->get_Settings(&settings));
289 RETURN_IF_FAILED(settings->put_AreDevToolsEnabled(FALSE));
290
291 RETURN_IF_FAILED(m_optionsController->add_ZoomFactorChanged(Callback<ICoreWebView2ZoomFactorChangedEventHandler>(
292 [](ICoreWebView2Controller* host, IUnknown* args) -> HRESULT
293 {
294 host->put_ZoomFactor(1.0);
295 return S_OK;
296 }
297 ).Get(), &m_optionsZoomToken));
298
299 // Hide by default
300 RETURN_IF_FAILED(m_optionsController->put_IsVisible(FALSE));
301 RETURN_IF_FAILED(m_optionsWebView->add_WebMessageReceived(m_uiMessageBroker.Get(), &m_optionsUIMessageBrokerToken));
302
303 // Hide menu when focus is lost
304 RETURN_IF_FAILED(m_optionsController->add_LostFocus(Callback<ICoreWebView2FocusChangedEventHandler>(
305 [this](ICoreWebView2Controller* sender, IUnknown* args) -> HRESULT
306 {
307 web::json::value jsonObj = web::json::value::parse(L"{}");
308 jsonObj[L"message"] = web::json::value(MG_OPTIONS_LOST_FOCUS);
309 jsonObj[L"args"] = web::json::value::parse(L"{}");
310
311 PostJsonToWebView(jsonObj, m_controlsWebView.Get());
312
313 return S_OK;
314 }).Get(), &m_lostOptionsFocus));
315
316 RETURN_IF_FAILED(ResizeUIWebViews());
317
318 std::wstring optionsPath = GetFullPathFor(L"wvbrowser_ui\\controls_ui\\options.html");
319 RETURN_IF_FAILED(m_optionsWebView->Navigate(optionsPath.c_str()));
320
321 return S_OK;
322 }).Get());
323}
324
325// Set the message broker for the UI webview. This will capture messages from ui web content.
326// Lambda is used to capture the instance while satisfying Microsoft::WRL::Callback<T>()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected