-
Notifications
You must be signed in to change notification settings - Fork 171
/
web_view.h
96 lines (56 loc) 路 2.16 KB
/
web_view.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by yangbin on 2021/11/12.
//
#ifndef WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_
#define WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_
#include <windows.h>
#include <string>
#include <flutter/method_channel.h>
#include <flutter/encodable_value.h>
#include "wil/resource.h"
#include "wil/com.h"
#include "WebView2.h"
namespace webview_window {
class WebView {
public:
WebView(std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> method_channel,
int64_t web_view_id,
std::wstring userDataFolder,
std::function<void(HRESULT)> on_web_view_created_callback
);
virtual ~WebView();
[[nodiscard]] const wil::unique_hwnd &NativeWindow() const { return view_window_; }
void UpdateBounds();
void Navigate(const std::wstring &url);
void AddScriptToExecuteOnDocumentCreated(const std::wstring &javaScript);
void SetApplicationNameForUserAgent(const std::wstring &application_name);
void GoBack();
void GoForward();
void Reload();
void Stop();
void openDevToolsWindow();
void ExecuteJavaScript(const std::wstring &javaScript,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
void PostWebMessageAsString(const std::wstring &webmessage,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
void PostWebMessageAsJson(const std::wstring &webmessage,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
void setTriggerOnUrlRequestedEvent(const bool value);
private:
wil::unique_hwnd view_window_;
// Pointer to WebViewController
wil::com_ptr<ICoreWebView2Controller> webview_controller_;
// Pointer to WebView
wil::com_ptr<ICoreWebView2> webview_;
std::wstring default_user_agent_;
std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> method_channel_;
int64_t web_view_id_;
std::function<void(HRESULT)> on_web_view_created_callback_;
std::wstring user_data_folder_;
bool triggerOnUrlRequestedEvent{true};
void OnWebviewControllerCreated();
[[nodiscard]] bool CanGoBack() const;
[[nodiscard]] bool CanGoForward() const;
};
}
#endif //WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_