forked from MicrosoftEdge/WebView2Browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrowserWindow.h
74 lines (63 loc) · 3.41 KB
/
BrowserWindow.h
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
// Copyright (C) Microsoft Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include "framework.h"
#include "Tab.h"
class BrowserWindow
{
public:
static const int c_uiBarHeight = 70;
static const int c_optionsDropdownHeight = 108;
static const int c_optionsDropdownWidth = 200;
static ATOM RegisterClass(_In_ HINSTANCE hInstance);
static LRESULT CALLBACK WndProcStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static BOOL LaunchWindow(_In_ HINSTANCE hInstance, _In_ int nCmdShow);
static std::wstring GetAppDataDirectory();
std::wstring GetFullPathFor(LPCWSTR relativePath);
HRESULT HandleTabURIUpdate(size_t tabId, ICoreWebView2* webview);
HRESULT HandleTabHistoryUpdate(size_t tabId, ICoreWebView2* webview);
HRESULT HandleTabNavStarting(size_t tabId, ICoreWebView2* webview);
HRESULT HandleTabNavCompleted(size_t tabId, ICoreWebView2* webview, ICoreWebView2NavigationCompletedEventArgs* args);
HRESULT HandleTabSecurityUpdate(size_t tabId, ICoreWebView2* webview, ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args);
void HandleTabCreated(size_t tabId, bool shouldBeActive);
HRESULT HandleTabMessageReceived(size_t tabId, ICoreWebView2* webview, ICoreWebView2WebMessageReceivedEventArgs* eventArgs);
int GetDPIAwareBound(int bound);
static void CheckFailure(HRESULT hr, LPCWSTR errorMessage);
protected:
HINSTANCE m_hInst = nullptr; // Current app instance
HWND m_hWnd = nullptr;
static WCHAR s_windowClass[MAX_LOADSTRING]; // The window class name
static WCHAR s_title[MAX_LOADSTRING]; // The title bar text
int m_minWindowWidth = 0;
int m_minWindowHeight = 0;
Microsoft::WRL::ComPtr<ICoreWebView2Environment> m_uiEnv;
Microsoft::WRL::ComPtr<ICoreWebView2Environment> m_contentEnv;
Microsoft::WRL::ComPtr<ICoreWebView2Controller> m_controlsController;
Microsoft::WRL::ComPtr<ICoreWebView2Controller> m_optionsController;
Microsoft::WRL::ComPtr<ICoreWebView2> m_controlsWebView;
Microsoft::WRL::ComPtr<ICoreWebView2> m_optionsWebView;
std::map<size_t,std::unique_ptr<Tab>> m_tabs;
size_t m_activeTabId = 0;
EventRegistrationToken m_controlsUIMessageBrokerToken = {}; // Token for the UI message handler in controls WebView
EventRegistrationToken m_controlsZoomToken = {};
EventRegistrationToken m_optionsUIMessageBrokerToken = {}; // Token for the UI message handler in options WebView
EventRegistrationToken m_optionsZoomToken = {};
EventRegistrationToken m_lostOptionsFocus = {}; // Token for the lost focus handler in options WebView
Microsoft::WRL::ComPtr<ICoreWebView2WebMessageReceivedEventHandler> m_uiMessageBroker;
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
HRESULT InitUIWebViews();
HRESULT CreateBrowserControlsWebView();
HRESULT CreateBrowserOptionsWebView();
HRESULT ClearContentCache();
HRESULT ClearControlsCache();
HRESULT ClearContentCookies();
HRESULT ClearControlsCookies();
void SetUIMessageBroker();
HRESULT ResizeUIWebViews();
void UpdateMinWindowSize();
HRESULT PostJsonToWebView(web::json::value jsonObj, ICoreWebView2* webview);
HRESULT SwitchToTab(size_t tabId);
std::wstring GetFilePathAsURI(std::wstring fullPath);
};