forked from luakit/luakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.c
120 lines (99 loc) · 3.35 KB
/
extension.c
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
/*
* Copyright © 2016 Aidan Holm <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
#include "common/util.h"
#include "common/luah.h"
#include "common/luautil.h"
#include "common/luauniq.h"
#include "extension/ipc.h"
#include "common/luaobject.h"
#include "extension/extension.h"
#include "extension/clib/luakit.h"
#include "extension/clib/dom_document.h"
#include "extension/clib/dom_element.h"
#include "extension/clib/page.h"
#include "extension/clib/soup.h"
#include "extension/clib/msg.h"
#include "common/clib/ipc.h"
#include "common/clib/timer.h"
#include "common/clib/regex.h"
#include "common/clib/utf8.h"
#include "extension/scroll.h"
#include "extension/luajs.h"
#include "extension/script_world.h"
/* This is the global definition of common; it's also visible
everwhere common/common.h is included, which probably is about
everywhere in extensions; note that this common is separate
from the common visible on the UI side. */
common_t common;
/* Similarly, this is the global definition of extension */
extension_t extension;
static void
web_lua_init(const char *package_path, const char *package_cpath)
{
debug("Lua initializing...");
lua_State *L = common.L;
/* Set panic fuction */
lua_atpanic(L, luaH_panic);
luaL_openlibs(L);
luaH_fixups(L);
luaH_object_setup(L);
luaH_uniq_setup(L, NULL, "v");
lua_getglobal(L, "package");
lua_pushstring(L, package_path);
lua_setfield(L, -2, "path");
lua_pushstring(L, package_cpath);
lua_setfield(L, -2, "cpath");
lua_pop(L, 1);
luakit_lib_setup(L);
soup_lib_setup(L);
ipc_channel_class_setup(L);
timer_class_setup(L);
regex_class_setup(L);
utf8_lib_setup(L);
dom_document_class_setup(L);
dom_element_class_setup(L);
page_class_setup(L);
msg_lib_setup(L);
debug("Lua initialized");
}
G_MODULE_EXPORT void
webkit_web_extension_initialize_with_user_data(WebKitWebExtension *ext, GVariant *payload)
{
gchar *socket_path, *package_path, *package_cpath;
g_variant_get(payload, "(sss)", &socket_path, &package_path, &package_cpath);
common.L = luaL_newstate();
common.L = common.L;
extension.ext = ext;
extension.ipc = ipc_endpoint_new(g_strdup_printf("Web[%d]", getpid()));
if (web_extension_connect(socket_path)) {
debug("connecting to UI thread failed");
exit(EXIT_FAILURE);
}
web_lua_init(package_path, package_cpath);
web_scroll_init();
web_luajs_init();
web_script_world_init();
debug("PID %d", getpid());
debug("ready for messages");
ipc_header_t header = { .type = IPC_TYPE_extension_init, .length = 0 };
ipc_send(extension.ipc, &header, NULL);
}
// vim: ft=c:et:sw=4:ts=8:sts=4:tw=80