OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 #include "nacl_mounts/real_pepper_interface.h" | 6 #include "nacl_mounts/real_pepper_interface.h" |
7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <stdio.h> |
| 9 |
8 #include <ppapi/c/pp_errors.h> | 10 #include <ppapi/c/pp_errors.h> |
| 11 #include <ppapi/c/ppb_console.h> |
9 #include <ppapi/c/ppb_file_io.h> | 12 #include <ppapi/c/ppb_file_io.h> |
10 #include <ppapi/c/ppb_file_ref.h> | 13 #include <ppapi/c/ppb_file_ref.h> |
11 #include <ppapi/c/ppb_file_system.h> | 14 #include <ppapi/c/ppb_file_system.h> |
| 15 #include <ppapi/c/ppb_messaging.h> |
12 #include <ppapi/c/ppb_var.h> | 16 #include <ppapi/c/ppb_var.h> |
13 #include <stdio.h> | |
14 | 17 |
15 #define DEFINE_CONSTRUCTOR(Class, Interface) \ | 18 #define DEFINE_CONSTRUCTOR(Class, Interface) \ |
16 Class::Class(const Interface* interface) : interface_(interface) {} | 19 Class::Class(const Interface* interface) : interface_(interface) {} |
17 | 20 |
18 #define DEFINE_METHOD1(Class, ReturnType, MethodName, Type0) \ | 21 #define DEFINE_METHOD1(Class, ReturnType, MethodName, Type0) \ |
19 ReturnType Class::MethodName(Type0 arg0) { \ | 22 ReturnType Class::MethodName(Type0 arg0) { \ |
20 return interface_->MethodName(arg0); \ | 23 return interface_->MethodName(arg0); \ |
21 } | 24 } |
22 | 25 |
23 #define DEFINE_METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ | 26 #define DEFINE_METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ |
(...skipping 14 matching lines...) Expand all Loading... |
38 } | 41 } |
39 | 42 |
40 #define DEFINE_METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, \ | 43 #define DEFINE_METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, \ |
41 Type3, Type4) \ | 44 Type3, Type4) \ |
42 ReturnType Class::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ | 45 ReturnType Class::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ |
43 Type3 arg3, Type4 arg4) { \ | 46 Type3 arg3, Type4 arg4) { \ |
44 return interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \ | 47 return interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \ |
45 } | 48 } |
46 | 49 |
47 | 50 |
| 51 #define DEFINE_VMETHOD1(Class, MethodName, Type0) \ |
| 52 void Class::MethodName(Type0 arg0) { \ |
| 53 interface_->MethodName(arg0); \ |
| 54 } |
| 55 |
| 56 #define DEFINE_VMETHOD2(Class, MethodName, Type0, Type1) \ |
| 57 void Class::MethodName(Type0 arg0, Type1 arg1) { \ |
| 58 interface_->MethodName(arg0, arg1); \ |
| 59 } |
| 60 |
| 61 #define DEFINE_VMETHOD3(Class, MethodName, Type0, Type1, Type2) \ |
| 62 void Class::MethodName(Type0 arg0, Type1 arg1, Type2 arg2) { \ |
| 63 interface_->MethodName(arg0, arg1, arg2); \ |
| 64 } |
| 65 |
| 66 #define DEFINE_VMETHOD4(Class, MethodName, Type0, Type1, Type2, Type3) \ |
| 67 void Class::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ |
| 68 Type3 arg3) { \ |
| 69 interface_->MethodName(arg0, arg1, arg2, arg3); \ |
| 70 } |
| 71 |
| 72 #define DEFINE_VMETHOD5(Class, MethodName, Type0, Type1, Type2, Type3, Type4) \ |
| 73 void Class::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ |
| 74 Type3 arg3, Type4 arg4) { \ |
| 75 interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \ |
| 76 } |
| 77 |
| 78 |
| 79 |
48 class RealFileSystemInterface : public FileSystemInterface { | 80 class RealFileSystemInterface : public FileSystemInterface { |
49 public: | 81 public: |
50 explicit RealFileSystemInterface(const PPB_FileSystem* filesystem_interface); | 82 explicit RealFileSystemInterface(const PPB_FileSystem* filesystem_interface); |
51 virtual PP_Resource Create(PP_Instance, PP_FileSystemType); | 83 virtual PP_Resource Create(PP_Instance, PP_FileSystemType); |
52 virtual int32_t Open(PP_Resource, int64_t, PP_CompletionCallback); | 84 virtual int32_t Open(PP_Resource, int64_t, PP_CompletionCallback); |
53 | 85 |
54 private: | 86 private: |
55 const PPB_FileSystem* interface_; | 87 const PPB_FileSystem* interface_; |
56 }; | 88 }; |
57 DEFINE_CONSTRUCTOR(RealFileSystemInterface, PPB_FileSystem) | 89 DEFINE_CONSTRUCTOR(RealFileSystemInterface, PPB_FileSystem) |
58 DEFINE_METHOD2(RealFileSystemInterface, PP_Resource, Create, PP_Instance, | 90 DEFINE_METHOD2(RealFileSystemInterface, PP_Resource, Create, PP_Instance, |
59 PP_FileSystemType) | 91 PP_FileSystemType) |
60 DEFINE_METHOD3(RealFileSystemInterface, int32_t, Open, PP_Resource, int64_t, | 92 DEFINE_METHOD3(RealFileSystemInterface, int32_t, Open, PP_Resource, int64_t, |
61 PP_CompletionCallback) | 93 PP_CompletionCallback) |
62 | 94 |
63 | 95 |
| 96 class RealConsoleInterface : public ConsoleInterface { |
| 97 public: |
| 98 explicit RealConsoleInterface(const PPB_Console* console_interface); |
| 99 virtual void Log(PP_Instance, PP_LogLevel, struct PP_Var); |
| 100 private: |
| 101 const PPB_Console* interface_; |
| 102 }; |
| 103 DEFINE_CONSTRUCTOR(RealConsoleInterface, PPB_Console) |
| 104 DEFINE_VMETHOD3(RealConsoleInterface, Log, PP_Instance, PP_LogLevel, |
| 105 struct PP_Var); |
| 106 |
| 107 |
64 class RealFileRefInterface : public FileRefInterface { | 108 class RealFileRefInterface : public FileRefInterface { |
65 public: | 109 public: |
66 explicit RealFileRefInterface(const PPB_FileRef* fileref_interface); | 110 explicit RealFileRefInterface(const PPB_FileRef* fileref_interface); |
67 | 111 |
68 virtual PP_Resource Create(PP_Resource, const char*); | 112 virtual PP_Resource Create(PP_Resource, const char*); |
69 virtual int32_t Delete(PP_Resource, PP_CompletionCallback); | 113 virtual int32_t Delete(PP_Resource, PP_CompletionCallback); |
70 virtual PP_Var GetName(PP_Resource); | 114 virtual PP_Var GetName(PP_Resource); |
71 virtual int32_t MakeDirectory(PP_Resource, PP_Bool, | 115 virtual int32_t MakeDirectory(PP_Resource, PP_Bool, |
72 PP_CompletionCallback); | 116 PP_CompletionCallback); |
73 | 117 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 }; | 178 }; |
135 DEFINE_CONSTRUCTOR(RealDirectoryReaderInterface, PPB_DirectoryReader_Dev) | 179 DEFINE_CONSTRUCTOR(RealDirectoryReaderInterface, PPB_DirectoryReader_Dev) |
136 DEFINE_METHOD1(RealDirectoryReaderInterface, PP_Resource, Create, PP_Resource) | 180 DEFINE_METHOD1(RealDirectoryReaderInterface, PP_Resource, Create, PP_Resource) |
137 DEFINE_METHOD3(RealDirectoryReaderInterface, int32_t, GetNextEntry, PP_Resource, | 181 DEFINE_METHOD3(RealDirectoryReaderInterface, int32_t, GetNextEntry, PP_Resource, |
138 PP_DirectoryEntry_Dev*, PP_CompletionCallback) | 182 PP_DirectoryEntry_Dev*, PP_CompletionCallback) |
139 | 183 |
140 class RealVarInterface : public VarInterface { | 184 class RealVarInterface : public VarInterface { |
141 public: | 185 public: |
142 explicit RealVarInterface(const PPB_Var* var_interface); | 186 explicit RealVarInterface(const PPB_Var* var_interface); |
143 | 187 |
| 188 virtual struct PP_Var VarFromUtf8(const char *, uint32_t); |
144 virtual const char* VarToUtf8(PP_Var, uint32_t*); | 189 virtual const char* VarToUtf8(PP_Var, uint32_t*); |
145 | 190 |
146 private: | 191 private: |
147 const PPB_Var* interface_; | 192 const PPB_Var* interface_; |
148 }; | 193 }; |
149 DEFINE_CONSTRUCTOR(RealVarInterface, PPB_Var) | 194 DEFINE_CONSTRUCTOR(RealVarInterface, PPB_Var) |
| 195 DEFINE_METHOD2(RealVarInterface, struct PP_Var, VarFromUtf8, const char *, |
| 196 uint32_t) |
150 DEFINE_METHOD2(RealVarInterface, const char*, VarToUtf8, PP_Var, uint32_t*) | 197 DEFINE_METHOD2(RealVarInterface, const char*, VarToUtf8, PP_Var, uint32_t*) |
151 | 198 |
| 199 class RealMessagingInterface : public MessagingInterface { |
| 200 public: |
| 201 explicit RealMessagingInterface(const PPB_Messaging* messaging_interface); |
| 202 |
| 203 virtual void PostMessage(PP_Instance, struct PP_Var); |
| 204 |
| 205 private: |
| 206 const PPB_Messaging* interface_; |
| 207 }; |
| 208 DEFINE_CONSTRUCTOR(RealMessagingInterface, PPB_Messaging); |
| 209 DEFINE_VMETHOD2(RealMessagingInterface, PostMessage, PP_Instance, struct |
| 210 PP_Var); |
| 211 |
152 | 212 |
153 RealPepperInterface::RealPepperInterface(PP_Instance instance, | 213 RealPepperInterface::RealPepperInterface(PP_Instance instance, |
154 PPB_GetInterface get_browser_interface) | 214 PPB_GetInterface get_browser_interface) |
155 : instance_(instance), | 215 : instance_(instance), |
156 core_interface_(NULL), | 216 core_interface_(NULL), |
157 message_loop_interface_(NULL) { | 217 message_loop_interface_(NULL) { |
158 core_interface_ = static_cast<const PPB_Core*>( | 218 core_interface_ = static_cast<const PPB_Core*>( |
159 get_browser_interface(PPB_CORE_INTERFACE)); | 219 get_browser_interface(PPB_CORE_INTERFACE)); |
160 message_loop_interface_ = static_cast<const PPB_MessageLoop*>( | 220 message_loop_interface_ = static_cast<const PPB_MessageLoop*>( |
161 get_browser_interface(PPB_MESSAGELOOP_INTERFACE)); | 221 get_browser_interface(PPB_MESSAGELOOP_INTERFACE)); |
162 assert(core_interface_); | 222 assert(core_interface_); |
163 assert(message_loop_interface_); | 223 assert(message_loop_interface_); |
164 | 224 |
| 225 console_interface_ = new RealConsoleInterface( |
| 226 static_cast<const PPB_Console*>(get_browser_interface( |
| 227 PPB_CONSOLE_INTERFACE))); |
165 directory_reader_interface_ = new RealDirectoryReaderInterface( | 228 directory_reader_interface_ = new RealDirectoryReaderInterface( |
166 static_cast<const PPB_DirectoryReader_Dev*>(get_browser_interface( | 229 static_cast<const PPB_DirectoryReader_Dev*>(get_browser_interface( |
167 PPB_DIRECTORYREADER_DEV_INTERFACE))); | 230 PPB_DIRECTORYREADER_DEV_INTERFACE))); |
168 fileio_interface_ = new RealFileIoInterface(static_cast<const PPB_FileIO*>( | 231 fileio_interface_ = new RealFileIoInterface(static_cast<const PPB_FileIO*>( |
169 get_browser_interface(PPB_FILEIO_INTERFACE))); | 232 get_browser_interface(PPB_FILEIO_INTERFACE))); |
170 fileref_interface_ = new RealFileRefInterface(static_cast<const PPB_FileRef*>( | 233 fileref_interface_ = new RealFileRefInterface(static_cast<const PPB_FileRef*>( |
171 get_browser_interface(PPB_FILEREF_INTERFACE))); | 234 get_browser_interface(PPB_FILEREF_INTERFACE))); |
172 filesystem_interface_ = new RealFileSystemInterface( | 235 filesystem_interface_ = new RealFileSystemInterface( |
173 static_cast<const PPB_FileSystem*>(get_browser_interface( | 236 static_cast<const PPB_FileSystem*>(get_browser_interface( |
174 PPB_FILESYSTEM_INTERFACE))); | 237 PPB_FILESYSTEM_INTERFACE))); |
| 238 messaging_interface_ = new RealMessagingInterface( |
| 239 static_cast<const PPB_Messaging*>(get_browser_interface( |
| 240 PPB_MESSAGING_INTERFACE))); |
175 var_interface_= new RealVarInterface( | 241 var_interface_= new RealVarInterface( |
176 static_cast<const PPB_Var*>(get_browser_interface( | 242 static_cast<const PPB_Var*>(get_browser_interface( |
177 PPB_VAR_INTERFACE))); | 243 PPB_VAR_INTERFACE))); |
178 } | 244 } |
179 | 245 |
180 PP_Instance RealPepperInterface::GetInstance() { | 246 PP_Instance RealPepperInterface::GetInstance() { |
181 return instance_; | 247 return instance_; |
182 } | 248 } |
183 | 249 |
184 void RealPepperInterface::AddRefResource(PP_Resource resource) { | 250 void RealPepperInterface::AddRefResource(PP_Resource resource) { |
185 if (resource) | 251 if (resource) |
186 core_interface_->AddRefResource(resource); | 252 core_interface_->AddRefResource(resource); |
187 } | 253 } |
188 | 254 |
189 void RealPepperInterface::ReleaseResource(PP_Resource resource) { | 255 void RealPepperInterface::ReleaseResource(PP_Resource resource) { |
190 if (resource) | 256 if (resource) |
191 core_interface_->ReleaseResource(resource); | 257 core_interface_->ReleaseResource(resource); |
192 } | 258 } |
193 | 259 |
| 260 ConsoleInterface* RealPepperInterface::GetConsoleInterface() { |
| 261 return console_interface_; |
| 262 } |
| 263 |
194 FileSystemInterface* RealPepperInterface::GetFileSystemInterface() { | 264 FileSystemInterface* RealPepperInterface::GetFileSystemInterface() { |
195 return filesystem_interface_; | 265 return filesystem_interface_; |
196 } | 266 } |
197 | 267 |
198 FileRefInterface* RealPepperInterface::GetFileRefInterface() { | 268 FileRefInterface* RealPepperInterface::GetFileRefInterface() { |
199 return fileref_interface_; | 269 return fileref_interface_; |
200 } | 270 } |
201 | 271 |
202 FileIoInterface* RealPepperInterface::GetFileIoInterface() { | 272 FileIoInterface* RealPepperInterface::GetFileIoInterface() { |
203 return fileio_interface_; | 273 return fileio_interface_; |
204 } | 274 } |
205 | 275 |
206 DirectoryReaderInterface* RealPepperInterface::GetDirectoryReaderInterface() { | 276 DirectoryReaderInterface* RealPepperInterface::GetDirectoryReaderInterface() { |
207 return directory_reader_interface_; | 277 return directory_reader_interface_; |
208 } | 278 } |
209 | 279 |
| 280 MessagingInterface* RealPepperInterface::GetMessagingInterface() { |
| 281 return messaging_interface_; |
| 282 } |
| 283 |
210 VarInterface* RealPepperInterface::GetVarInterface() { | 284 VarInterface* RealPepperInterface::GetVarInterface() { |
211 return var_interface_; | 285 return var_interface_; |
212 } | 286 } |
213 | 287 |
214 int32_t RealPepperInterface::InitializeMessageLoop() { | 288 int32_t RealPepperInterface::InitializeMessageLoop() { |
215 int32_t result; | 289 int32_t result; |
216 PP_Resource message_loop = 0; | 290 PP_Resource message_loop = 0; |
217 if (core_interface_->IsMainThread()) { | 291 if (core_interface_->IsMainThread()) { |
218 // TODO(binji): Spin up the main thread's ppapi work thread. | 292 // TODO(binji): Spin up the main thread's ppapi work thread. |
219 assert(0); | 293 assert(0); |
220 } else { | 294 } else { |
221 message_loop = message_loop_interface_->GetCurrent(); | 295 message_loop = message_loop_interface_->GetCurrent(); |
222 if (!message_loop) { | 296 if (!message_loop) { |
223 message_loop = message_loop_interface_->Create(instance_); | 297 message_loop = message_loop_interface_->Create(instance_); |
224 result = message_loop_interface_->AttachToCurrentThread(message_loop); | 298 result = message_loop_interface_->AttachToCurrentThread(message_loop); |
225 assert(result == PP_OK); | 299 assert(result == PP_OK); |
226 } | 300 } |
227 } | 301 } |
228 | 302 |
229 return PP_OK; | 303 return PP_OK; |
230 } | 304 } |
OLD | NEW |