forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsComponent.h
More file actions
69 lines (57 loc) · 2.26 KB
/
SettingsComponent.h
File metadata and controls
69 lines (57 loc) · 2.26 KB
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
// 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 "stdafx.h"
#include <functional>
#include <string>
#include <vector>
#include "AppWindow.h"
#include "ComponentBase.h"
// This component handles commands from the Settings menu. It also handles the
// NavigationStarting, FrameNavigationStarting, WebResourceRequested, ScriptDialogOpening,
// and PermissionRequested events.
class SettingsComponent : public ComponentBase
{
public:
SettingsComponent(
AppWindow* appWindow, ICoreWebView2Environment* environment,
SettingsComponent* old = nullptr);
bool HandleWindowMessage(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam,
LRESULT* result) override;
void ChangeBlockedSites();
bool ShouldBlockUri(PWSTR uri);
bool ShouldBlockScriptForUri(PWSTR uri);
void SetBlockImages(bool blockImages);
void SetReplaceImages(bool replaceImages);
void ChangeUserAgent();
void SetUserAgent(const std::wstring& userAgent);
void CompleteScriptDialogDeferral();
~SettingsComponent() override;
private:
AppWindow* m_appWindow = nullptr;
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;
wil::com_ptr<ICoreWebView2> m_webView;
wil::com_ptr<ICoreWebView2Settings> m_settings;
wil::com_ptr<ICoreWebView2Settings2> m_settings2;
bool m_blockImages = false;
bool m_replaceImages = false;
bool m_deferScriptDialogs = false;
bool m_changeUserAgent = false;
bool m_isScriptEnabled = true;
bool m_blockedSitesSet = false;
std::vector<std::wstring> m_blockedSites;
std::wstring m_overridingUserAgent;
std::function<void()> m_completeDeferredDialog;
EventRegistrationToken m_navigationStartingToken = {};
EventRegistrationToken m_frameNavigationStartingToken = {};
EventRegistrationToken m_webResourceRequestedTokenForImageBlocking = {};
EventRegistrationToken m_webResourceRequestedTokenForImageReplacing = {};
EventRegistrationToken m_webResourceRequestedTokenForUserAgent = {};
EventRegistrationToken m_scriptDialogOpeningToken = {};
EventRegistrationToken m_permissionRequestedToken = {};
};