Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: ppapi/proxy/plugin_main_nacl.cc

Issue 10546140: Add untrusted NaCl build for PPAPI proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/DEPS ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <map>
6 #include <set>
7
8 #include "build/build_config.h"
9 // Need to include this before most other files because it defines
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
12 // ViewMsgLog et al. functions.
13
14 #include "base/message_loop.h"
15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h"
17 #include "ipc/ipc_channel_handle.h"
18 #include "ipc/ipc_logging.h"
19 #include "ipc/ipc_message.h"
20 #include "native_client/src/shared/ppapi_proxy/ppruntime.h"
21 #include "native_client/src/untrusted/irt/irt_ppapi.h"
22 #include "ppapi/c/ppp.h"
23 #include "ppapi/c/ppp_instance.h"
24 #include "ppapi/proxy/plugin_dispatcher.h"
25 #include "ppapi/proxy/plugin_globals.h"
26
27 #if defined(IPC_MESSAGE_LOG_ENABLED)
28 #define IPC_MESSAGE_MACROS_LOG_ENABLED
29 #include "ppapi/proxy/ppapi_messages.h"
30 #endif
31
32 // This must match up with NACL_CHROME_INITIAL_IPC_DESC,
33 // defined in sel_main_chrome.h
34 #define NACL_IPC_FD 6
35
36 using ppapi::proxy::PluginDispatcher;
37 using ppapi::proxy::PluginGlobals;
38
39 namespace {
40
41 struct PP_ThreadFunctions thread_funcs;
42
43 // Copied from src/content/ppapi_plugin/ppapi_thread. This is a minimal
44 // implementation to get us started.
45 class PluginDispatcherDelegate : public PluginDispatcher::PluginDelegate {
46 public:
47 explicit PluginDispatcherDelegate(
48 scoped_refptr<base::MessageLoopProxy> io_loop)
49 : message_loop_(io_loop),
50 shutdown_event_(true, false) {
51 }
52
53 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE {
54 return message_loop_.get();
55 }
56
57 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE {
58 return &shutdown_event_;
59 }
60
61 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
62 base::PlatformFile handle,
63 const IPC::SyncChannel& channel,
64 bool should_close_source) OVERRIDE {
65 return IPC::InvalidPlatformFileForTransit();
66 }
67
68 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE {
69 return &instances_;
70 }
71
72 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE {
73 if (!plugin_dispatcher ||
74 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) {
75 return 0;
76 }
77
78 uint32 id = 0;
79 do {
80 // Although it is unlikely, make sure that we won't cause any trouble when
81 // the counter overflows.
82 id = next_plugin_dispatcher_id_++;
83 } while (id == 0 ||
84 plugin_dispatchers_.find(id) != plugin_dispatchers_.end());
85 plugin_dispatchers_[id] = plugin_dispatcher;
86 return id;
87 }
88
89 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE {
90 plugin_dispatchers_.erase(plugin_dispatcher_id);
91 }
92
93 private:
94 std::set<PP_Instance> instances_;
95 std::map<uint32, PluginDispatcher*> plugin_dispatchers_;
96 uint32 next_plugin_dispatcher_id_;
97 scoped_refptr<base::MessageLoopProxy> message_loop_;
98 base::WaitableEvent shutdown_event_;
99 };
100
101 } // namespace
102
103 void PpapiPluginRegisterThreadCreator(
104 const struct PP_ThreadFunctions* new_funcs) {
105 thread_funcs = *new_funcs;
106 }
107
108 int IrtInit() {
109 return 0;
110 }
111
112 int PpapiPluginMain() {
113 base::AtExitManager exit_manager;
114 MessageLoop loop;
115 IPC::Logging::set_log_function_map(&g_log_function_mapping);
116 ppapi::proxy::PluginGlobals plugin_globals;
117 base::Thread io_thread("Chrome_NaClIOThread");
118 base::Thread::Options options;
119 options.message_loop_type = MessageLoop::TYPE_IO;
120 io_thread.StartWithOptions(options);
121
122 int32_t error = ::PPP_InitializeModule(
123 0 /* module */,
124 &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
125 // TODO(dmichael): Handle other error conditions, like failure to connect?
126 if (error)
127 return error;
128
129 PluginDispatcherDelegate delegate(io_thread.message_loop_proxy());
130
131 // TODO(dmichael) Figure out how to determine if we're in incognito
132 PluginDispatcher dispatcher(::PPP_GetInterface, false /* incognito */);
133 IPC::ChannelHandle channel_handle("NaCl IPC",
134 base::FileDescriptor(NACL_IPC_FD, false));
135 dispatcher.InitPluginWithChannel(&delegate, channel_handle, false);
136
137 loop.Run();
138 return 0;
139 }
140
OLDNEW
« no previous file with comments | « ppapi/proxy/DEPS ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698