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

Class BrowserWindow

BrowserWindow.h:10–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "Tab.h"
9
10class BrowserWindow
11{
12public:
13 static const int c_uiBarHeight = 70;
14 static const int c_optionsDropdownHeight = 108;
15 static const int c_optionsDropdownWidth = 200;
16
17 static ATOM RegisterClass(_In_ HINSTANCE hInstance);
18 static LRESULT CALLBACK WndProcStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
19 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
20
21 static BOOL LaunchWindow(_In_ HINSTANCE hInstance, _In_ int nCmdShow);
22 static std::wstring GetAppDataDirectory();
23 std::wstring GetFullPathFor(LPCWSTR relativePath);
24 HRESULT HandleTabURIUpdate(size_t tabId, ICoreWebView2* webview);
25 HRESULT HandleTabHistoryUpdate(size_t tabId, ICoreWebView2* webview);
26 HRESULT HandleTabNavStarting(size_t tabId, ICoreWebView2* webview);
27 HRESULT HandleTabNavCompleted(size_t tabId, ICoreWebView2* webview, ICoreWebView2NavigationCompletedEventArgs* args);
28 HRESULT HandleTabSecurityUpdate(size_t tabId, ICoreWebView2* webview, ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args);
29 void HandleTabCreated(size_t tabId, bool shouldBeActive);
30 HRESULT HandleTabMessageReceived(size_t tabId, ICoreWebView2* webview, ICoreWebView2WebMessageReceivedEventArgs* eventArgs);
31 int GetDPIAwareBound(int bound);
32 static void CheckFailure(HRESULT hr, LPCWSTR errorMessage);
33protected:
34 HINSTANCE m_hInst = nullptr; // Current app instance
35 HWND m_hWnd = nullptr;
36
37 static WCHAR s_windowClass[MAX_LOADSTRING]; // The window class name
38 static WCHAR s_title[MAX_LOADSTRING]; // The title bar text
39
40 int m_minWindowWidth = 0;
41 int m_minWindowHeight = 0;
42
43 Microsoft::WRL::ComPtr<ICoreWebView2Environment> m_uiEnv;
44 Microsoft::WRL::ComPtr<ICoreWebView2Environment> m_contentEnv;
45 Microsoft::WRL::ComPtr<ICoreWebView2Controller> m_controlsController;
46 Microsoft::WRL::ComPtr<ICoreWebView2Controller> m_optionsController;
47 Microsoft::WRL::ComPtr<ICoreWebView2> m_controlsWebView;
48 Microsoft::WRL::ComPtr<ICoreWebView2> m_optionsWebView;
49 std::map<size_t,std::unique_ptr<Tab>> m_tabs;
50 size_t m_activeTabId = 0;
51
52 EventRegistrationToken m_controlsUIMessageBrokerToken = {}; // Token for the UI message handler in controls WebView
53 EventRegistrationToken m_controlsZoomToken = {};
54 EventRegistrationToken m_optionsUIMessageBrokerToken = {}; // Token for the UI message handler in options WebView
55 EventRegistrationToken m_optionsZoomToken = {};
56 EventRegistrationToken m_lostOptionsFocus = {}; // Token for the lost focus handler in options WebView
57 Microsoft::WRL::ComPtr<ICoreWebView2WebMessageReceivedEventHandler> m_uiMessageBroker;
58
59 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
60 HRESULT InitUIWebViews();
61 HRESULT CreateBrowserControlsWebView();
62 HRESULT CreateBrowserOptionsWebView();
63 HRESULT ClearContentCache();
64 HRESULT ClearControlsCache();
65 HRESULT ClearContentCookies();
66 HRESULT ClearControlsCookies();
67

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected