-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.cpp
More file actions
132 lines (109 loc) · 5.17 KB
/
main.cpp
File metadata and controls
132 lines (109 loc) · 5.17 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <WPE/WebKit.h>
#include <WPE/WebKit/WKCookieManagerSoup.h>
#include <cstdio>
#include <glib.h>
#include <initializer_list>
WKPageNavigationClientV0 s_navigationClient = {
{ 0, nullptr },
// decidePolicyForNavigationAction
[](WKPageRef, WKNavigationActionRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*) {
WKFramePolicyListenerUse(listener);
},
// decidePolicyForNavigationResponse
[](WKPageRef, WKNavigationResponseRef, WKFramePolicyListenerRef listener, WKTypeRef, const void*) {
WKFramePolicyListenerUse(listener);
},
nullptr, // decidePolicyForPluginLoad
nullptr, // didStartProvisionalNavigation
nullptr, // didReceiveServerRedirectForProvisionalNavigation
nullptr, // didFailProvisionalNavigation
nullptr, // didCommitNavigation
nullptr, // didFinishNavigation
nullptr, // didFailNavigation
nullptr, // didFailProvisionalLoadInSubframe
// didFinishDocumentLoad
[](WKPageRef page, WKNavigationRef, WKTypeRef, const void*) {
WKStringRef messageName = WKStringCreateWithUTF8CString("Hello");
WKMutableArrayRef messageBody = WKMutableArrayCreate();
for (auto& item : { "Test1", "Test2", "Test3" }) {
WKStringRef itemString = WKStringCreateWithUTF8CString(item);
WKArrayAppendItem(messageBody, itemString);
WKRelease(itemString);
}
fprintf(stderr, "[WPELauncher] Hello InjectedBundle ...\n");
WKPagePostMessageToInjectedBundle(page, messageName, messageBody);
WKRelease(messageBody);
WKRelease(messageName);
},
nullptr, // didSameDocumentNavigation
nullptr, // renderingProgressDidChange
nullptr, // canAuthenticateAgainstProtectionSpace
nullptr, // didReceiveAuthenticationChallenge
nullptr, // webProcessDidCrash
nullptr, // copyWebCryptoMasterKey
nullptr, // didBeginNavigationGesture
nullptr, // willEndNavigationGesture
nullptr, // didEndNavigationGesture
nullptr, // didRemoveNavigationGestureSnapshot
};
int main(int argc, char* argv[])
{
GMainLoop* loop = g_main_loop_new(nullptr, FALSE);
auto contextConfiguration = WKContextConfigurationCreate();
auto injectedBundlePath = WKStringCreateWithUTF8CString("/usr/lib/libWPEInjectedBundle.so");
WKContextConfigurationSetInjectedBundlePath(contextConfiguration, injectedBundlePath);
gchar *wpeStoragePath = g_build_filename(g_get_user_cache_dir(), "wpe", "local-storage", nullptr);
g_mkdir_with_parents(wpeStoragePath, 0700);
auto storageDirectory = WKStringCreateWithUTF8CString(wpeStoragePath);
g_free(wpeStoragePath);
WKContextConfigurationSetLocalStorageDirectory(contextConfiguration, storageDirectory);
gchar *wpeDiskCachePath = g_build_filename(g_get_user_cache_dir(), "wpe", "disk-cache", nullptr);
g_mkdir_with_parents(wpeDiskCachePath, 0700);
auto diskCacheDirectory = WKStringCreateWithUTF8CString(wpeDiskCachePath);
g_free(wpeDiskCachePath);
WKContextConfigurationSetDiskCacheDirectory(contextConfiguration, diskCacheDirectory);
WKRelease(injectedBundlePath);
WKContextRef context = WKContextCreateWithConfiguration(contextConfiguration);
WKRelease(contextConfiguration);
auto pageGroupIdentifier = WKStringCreateWithUTF8CString("WPEPageGroup");
auto pageGroup = WKPageGroupCreateWithIdentifier(pageGroupIdentifier);
WKRelease(pageGroupIdentifier);
auto preferences = WKPreferencesCreate();
// Allow mixed content.
WKPreferencesSetAllowRunningOfInsecureContent(preferences, true);
WKPreferencesSetAllowDisplayOfInsecureContent(preferences, true);
// By default allow console log messages to system console reporting.
if (!g_getenv("WPE_SHELL_DISABLE_CONSOLE_LOG"))
WKPreferencesSetLogsPageMessagesToSystemConsoleEnabled(preferences, true);
WKPageGroupSetPreferences(pageGroup, preferences);
auto pageConfiguration = WKPageConfigurationCreate();
WKPageConfigurationSetContext(pageConfiguration, context);
WKPageConfigurationSetPageGroup(pageConfiguration, pageGroup);
WKPreferencesSetFullScreenEnabled(preferences, true);
if (g_getenv("WPE_SHELL_DISABLE_MEDIA_DISK_CACHE"))
WKPreferencesSetMediaDataLoadsAutomatically(preferences, false);
if (!!g_getenv("WPE_SHELL_COOKIE_STORAGE")) {
gchar *cookieDatabasePath = g_build_filename(g_get_user_cache_dir(), "cookies.db", nullptr);
auto path = WKStringCreateWithUTF8CString(cookieDatabasePath);
g_free(cookieDatabasePath);
auto cookieManager = WKContextGetCookieManager(context);
WKCookieManagerSetCookiePersistentStorage(cookieManager, path, kWKCookieStorageTypeSQLite);
}
auto view = WKViewCreate(pageConfiguration);
auto page = WKViewGetPage(view);
WKPageSetPageNavigationClient(page, &s_navigationClient.base);
const char* url = "http://youtube.com/tv";
if (argc > 1)
url = argv[1];
auto shellURL = WKURLCreateWithUTF8CString(url);
WKPageLoadURL(page, shellURL);
WKRelease(shellURL);
g_main_loop_run(loop);
WKRelease(view);
WKRelease(pageConfiguration);
WKRelease(pageGroup);
WKRelease(context);
WKRelease(preferences);
g_main_loop_unref(loop);
return 0;
}