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

Method SwitchToTab

BrowserWindow.cpp:478–505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478HRESULT BrowserWindow::SwitchToTab(size_t tabId)
479{
480 size_t previousActiveTab = m_activeTabId;
481
482 RETURN_IF_FAILED(m_tabs.at(tabId)->ResizeWebView());
483 RETURN_IF_FAILED(m_tabs.at(tabId)->m_contentController->put_IsVisible(TRUE));
484 m_activeTabId = tabId;
485
486 if (previousActiveTab != INVALID_TAB_ID && previousActiveTab != m_activeTabId) {
487 auto previousTabIterator = m_tabs.find(previousActiveTab);
488 if (previousTabIterator != m_tabs.end() && previousTabIterator->second &&
489 previousTabIterator->second->m_contentController)
490 {
491 auto hr = m_tabs.at(previousActiveTab)->m_contentController->put_IsVisible(FALSE);
492 if (hr == HRESULT_FROM_WIN32(ERROR_INVALID_STATE)) {
493 web::json::value jsonObj = web::json::value::parse(L"{}");
494 jsonObj[L"message"] = web::json::value(MG_CLOSE_TAB);
495 jsonObj[L"args"] = web::json::value::parse(L"{}");
496 jsonObj[L"args"][L"tabId"] = web::json::value::number(previousActiveTab);
497
498 PostJsonToWebView(jsonObj, m_controlsWebView.Get());
499 }
500 RETURN_IF_FAILED(hr);
501 }
502 }
503
504 return S_OK;
505}
506
507HRESULT BrowserWindow::HandleTabURIUpdate(size_t tabId, ICoreWebView2* webview)
508{

Callers

nothing calls this directly

Calls 1

ResizeWebViewMethod · 0.80

Tested by

no test coverage detected