forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScenarioWebViewEventMonitor.h
62 lines (51 loc) · 2.56 KB
/
ScenarioWebViewEventMonitor.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
// 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 <string>
#include "ComponentBase.h"
std::wstring WebErrorStatusToString(COREWEBVIEW2_WEB_ERROR_STATUS status);
// The event monitor examines events from the m_appWindowEventSource and
// m_webviewEventSource and displays the details of those events in
// m_appWindowEventView and m_webviewEventView.
class ScenarioWebViewEventMonitor : public ComponentBase
{
public:
ScenarioWebViewEventMonitor(AppWindow* appWindowEventSource);
~ScenarioWebViewEventMonitor() override;
void InitializeEventView(ICoreWebView2* webviewEventView);
private:
// Because WebResourceRequested fires so much more often than
// all other events, we default to it off and it is configurable.
void EnableWebResourceRequestedEvent(bool enable);
void EnableWebResourceResponseReceivedEvent(bool enable);
// Send information about an event to the event view.
void PostEventMessage(std::wstring messageAsJson);
// The event view displays the events and their details.
AppWindow* m_appWindowEventView;
wil::com_ptr<ICoreWebView2> m_webviewEventView;
// The URI of the HTML document that displays the events.
std::wstring m_sampleUri;
// The event source objects fire the events.
AppWindow* m_appWindowEventSource;
wil::com_ptr<ICoreWebView2> m_webviewEventSource;
wil::com_ptr<ICoreWebView2_2> m_webviewEventSource2;
// The events we register on the event source
EventRegistrationToken m_frameNavigationStartingToken = {};
EventRegistrationToken m_navigationStartingToken = {};
EventRegistrationToken m_sourceChangedToken = {};
EventRegistrationToken m_contentLoadingToken = {};
EventRegistrationToken m_historyChangedToken = {};
EventRegistrationToken m_navigationCompletedToken = {};
EventRegistrationToken m_DOMContentLoadedToken = {};
EventRegistrationToken m_documentTitleChangedToken = {};
EventRegistrationToken m_webMessageReceivedToken = {};
EventRegistrationToken m_webResourceRequestedToken = {};
EventRegistrationToken m_newWindowRequestedToken = {};
EventRegistrationToken m_webResourceResponseReceivedToken = {};
// This event is registered with the event viewer so they
// can communicate back to us for toggling the WebResourceRequested
// event.
EventRegistrationToken m_eventViewWebMessageReceivedToken = {};
};