Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ppapi / proxy / irt_ppapi.c
1 /*
2  * Copyright 2014 The Chromium Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #include "native_client/src/public/irt_core.h"
8 #include "native_client/src/trusted/service_runtime/include/sys/unistd.h"
9 #include "native_client/src/untrusted/irt/irt.h"
10 #include "native_client/src/untrusted/irt/irt_private.h"
11 #include "ppapi/nacl_irt/irt_ppapi.h"
12 #include "ppapi/native_client/src/untrusted/pnacl_irt_shim/irt_shim_ppapi.h"
13 #include "ppapi/proxy/plugin_main_irt.h"
14
15 static struct PP_StartFunctions g_pp_functions;
16
17 int irt_ppapi_start(const struct PP_StartFunctions* funcs) {
18   /* Disable NaCl's open_resource() interface on this thread. */
19   g_is_main_thread = 1;
20
21   g_pp_functions = *funcs;
22   return PpapiPluginMain();
23 }
24
25 int32_t PPP_InitializeModule(PP_Module module_id,
26                              PPB_GetInterface get_browser_interface) {
27   return g_pp_functions.PPP_InitializeModule(module_id, get_browser_interface);
28 }
29
30 void PPP_ShutdownModule(void) {
31   g_pp_functions.PPP_ShutdownModule();
32 }
33
34 const void* PPP_GetInterface(const char* interface_name) {
35   return g_pp_functions.PPP_GetInterface(interface_name);
36 }
37
38 static const struct nacl_irt_ppapihook nacl_irt_ppapihook = {
39   irt_ppapi_start,
40   PpapiPluginRegisterThreadCreator,
41 };
42
43 static int ppapihook_pnacl_private_filter(void) {
44   int pnacl_mode = sysconf(NACL_ABI__SC_NACL_PNACL_MODE);
45   if (pnacl_mode == -1)
46     return 0;
47   return pnacl_mode;
48 }
49
50 static const struct nacl_irt_interface irt_interfaces[] = {
51   { NACL_IRT_PPAPIHOOK_v0_1, &nacl_irt_ppapihook, sizeof(nacl_irt_ppapihook),
52     NULL },
53   { NACL_IRT_PPAPIHOOK_PNACL_PRIVATE_v0_1,
54     &nacl_irt_ppapihook_pnacl_private, sizeof(nacl_irt_ppapihook_pnacl_private),
55     ppapihook_pnacl_private_filter },
56 };
57
58 static size_t chrome_irt_query(const char* interface_ident,
59                                void* table, size_t tablesize) {
60   size_t result = nacl_irt_query_core(interface_ident, table, tablesize);
61   if (result != 0)
62     return result;
63   return nacl_irt_query_list(interface_ident, table, tablesize,
64                              irt_interfaces, sizeof(irt_interfaces));
65 }
66
67 void nacl_irt_start(uint32_t* info) {
68   nacl_irt_init(info);
69   nacl_irt_enter_user_code(info, chrome_irt_query);
70 }