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

Side by Side Diff: ppapi/proxy/plugin_globals_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
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/include/portability.h"
Mark Seaborn 2012/06/13 20:27:37 Are you just #including this for EXTERN_C_BEGIN?
bbudge 2012/06/14 02:45:10 Done.
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 #define NACL_IPC_FD 6 // TODO(use API constant)
Mark Seaborn 2012/06/13 20:27:37 Please add a comment that this must match up with
bbudge 2012/06/14 02:45:10 Done.
Mark Seaborn 2012/06/14 21:49:20 I don't see a different comment in the new version
bbudge 2012/06/15 01:07:32 Oops. Good catch. Done. On 2012/06/14 21:49:20, Ma
33
34 using ppapi::proxy::PluginDispatcher;
35 using ppapi::proxy::PluginGlobals;
36
37 namespace {
38
39 struct PP_ThreadFunctions thread_funcs;
40
41 // Copied from src/content/ppapi_plugin/ppapi_thread. This is a minimal
42 // implementation to get us started.
43 class PluginDispatcherDelegate : public PluginDispatcher::PluginDelegate {
44 public:
45 explicit PluginDispatcherDelegate(
46 scoped_refptr<base::MessageLoopProxy> io_loop)
47 : message_loop_(io_loop),
48 shutdown_event_(true, false) {
49 }
50
51 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE {
52 return message_loop_.get();
53 }
54
55 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE {
56 return &shutdown_event_;
57 }
58
59 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
60 base::PlatformFile handle,
61 const IPC::SyncChannel& channel,
62 bool should_close_source) OVERRIDE {
63 return IPC::InvalidPlatformFileForTransit();
64 }
65
66 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE {
67 return &instances_;
68 }
69
70 virtual uint32 Register(PluginDispatcher* plugin_dispatcher) OVERRIDE {
71 if (!plugin_dispatcher ||
72 plugin_dispatchers_.size() >= std::numeric_limits<uint32>::max()) {
73 return 0;
74 }
75
76 uint32 id = 0;
77 do {
78 // Although it is unlikely, make sure that we won't cause any trouble when
79 // the counter overflows.
80 id = next_plugin_dispatcher_id_++;
81 } while (id == 0 ||
82 plugin_dispatchers_.find(id) != plugin_dispatchers_.end());
83 plugin_dispatchers_[id] = plugin_dispatcher;
84 return id;
85 }
86
87 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE {
88 plugin_dispatchers_.erase(plugin_dispatcher_id);
89 }
90
91 private:
92 std::set<PP_Instance> instances_;
93 std::map<uint32, PluginDispatcher*> plugin_dispatchers_;
94 uint32 next_plugin_dispatcher_id_;
95 scoped_refptr<base::MessageLoopProxy> message_loop_;
96 base::WaitableEvent shutdown_event_;
97 };
98
99 } // namespace
100
101 EXTERN_C_BEGIN
102
103 void PpapiPluginRegisterThreadCreator(
104 const struct PP_ThreadFunctions* new_funcs) {
105 thread_funcs = *new_funcs;
106 }
107
108 int IrtInit() {
109 static int initialized = 0;
Mark Seaborn 2012/06/13 20:27:37 This function body doesn't do anything, so this ca
bbudge 2012/06/14 02:45:10 Done.
110 if (initialized) {
111 return 0;
112 }
113
114 initialized = 1;
115 return 0;
116 }
117
118 int PpapiPluginMain() {
119 base::AtExitManager exit_manager;
120 MessageLoop loop;
121 IPC::Logging::set_log_function_map(&g_log_function_mapping);
122 ppapi::proxy::PluginGlobals plugin_globals;
123 base::Thread io_thread("Chrome_NaClIOThread");
124 base::Thread::Options options;
125 options.message_loop_type = MessageLoop::TYPE_IO;
126 io_thread.StartWithOptions(options);
127
128 int32_t ok = ::PPP_InitializeModule(
129 0 /* module */,
130 &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
131 // TODO(dmichael): Handle other error canditions, like failure to connect?
Mark Seaborn 2012/06/13 20:27:37 'conditions'
bbudge 2012/06/14 02:45:10 Done.
132 // if (!ok)
133 // return ok;
134
135 PluginDispatcherDelegate delegate(io_thread.message_loop_proxy());
136
137 // TODO(dmichael) Figure out how to determine if we're in incognito
Mark Seaborn 2012/06/13 20:27:37 This does not seem appropriate to the untrusted pr
138 PluginDispatcher dispatcher(::PPP_GetInterface, false /* incognito */);
139 IPC::ChannelHandle channel_handle("NaCl IPC",
140 base::FileDescriptor(NACL_IPC_FD, false));
141 dispatcher.InitPluginWithChannel(&delegate, channel_handle, false);
142
143 loop.Run();
144 return 0;
145 }
146
147 EXTERN_C_END
148
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698