forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptComponent.h
More file actions
75 lines (63 loc) · 2.35 KB
/
ScriptComponent.h
File metadata and controls
75 lines (63 loc) · 2.35 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
69
70
71
72
73
74
75
// 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.
#ifndef THIRD_PARTY_WEBVIEW_WIN_API_SAMPLE_SCRIPT_COMPONENT_H
#define THIRD_PARTY_WEBVIEW_WIN_API_SAMPLE_SCRIPT_COMPONENT_H
#include "stdafx.h"
#include <map>
#include <set>
#include <string>
#include "AppWindow.h"
#include "ComponentBase.h"
// This component handles commands from the Script menu.
class ScriptComponent : public ComponentBase
{
public:
ScriptComponent(AppWindow* appWindow);
private:
bool HandleWindowMessage(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam,
LRESULT* result) override;
void InjectScript();
void InjectScriptInIFrame();
void AddInitializeScript();
void RemoveInitializeScript();
void SendStringWebMessage();
void SendJsonWebMessage();
void SubscribeToCdpEvent();
void CallCdpMethod();
void HandleCDPTargets();
void CallCdpMethodForSession();
HRESULT CDPMethodCallback(HRESULT error, PCWSTR resultJson);
void CollectHeapUsageViaCdp();
void HandleHeapUsageResult(std::wstring targetInfo, PCWSTR resultJson);
void AddComObject();
void OpenTaskManagerWindow();
void SendStringWebMessageIFrame();
void SendJsonWebMessageIFrame();
void AddSiteEmbeddingIFrame();
~ScriptComponent() override;
void HandleIFrames();
std::wstring IFramesToString();
std::vector<wil::com_ptr<ICoreWebView2Frame>> m_frames;
AppWindow* m_appWindow = nullptr;
wil::com_ptr<ICoreWebView2> m_webView;
int m_siteEmbeddingIFrameCount = 0;
std::wstring m_lastInitializeScriptId;
std::map<std::wstring, EventRegistrationToken> m_devToolsProtocolEventReceivedTokenMap;
EventRegistrationToken m_targetAttachedToken;
EventRegistrationToken m_targetDetachedToken;
EventRegistrationToken m_targetCreatedToken;
EventRegistrationToken m_targetInfoChangedToken;
EventRegistrationToken m_consoleAPICalledToken;
// SessionId to TargetId map
std::map<std::wstring, std::wstring> m_devToolsSessionMap;
// TargetId to description label map, where label is "<target type>,<target url>".
std::map<std::wstring, std::wstring> m_devToolsTargetLabelMap;
int m_pendingHeapUsageCollectionCount = 0;
std::wstringstream m_heapUsageResult;
};
#endif