| OLD | NEW |
| (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 | |
| 6 #include "nacl_mounts/real_pepper_interface.h" | |
| 7 #include <assert.h> | |
| 8 #include <stdio.h> | |
| 9 | |
| 10 #include <ppapi/c/pp_errors.h> | |
| 11 | |
| 12 | |
| 13 #include "nacl_mounts/pepper/undef_macros.h" | |
| 14 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ | |
| 15 class Real##BaseClass : public BaseClass { \ | |
| 16 public: \ | |
| 17 explicit Real##BaseClass(const PPInterface* interface); | |
| 18 #define END_INTERFACE(BaseClass, PPInterface) \ | |
| 19 private: \ | |
| 20 const PPInterface* interface_; \ | |
| 21 }; | |
| 22 #define METHOD1(Class, ReturnType, MethodName, Type0) \ | |
| 23 virtual ReturnType MethodName(Type0); | |
| 24 #define METHOD2(Class, ReturnType, MethodName, Type0, Type1) \ | |
| 25 virtual ReturnType MethodName(Type0, Type1); | |
| 26 #define METHOD3(Class, ReturnType, MethodName, Type0, Type1, Type2) \ | |
| 27 virtual ReturnType MethodName(Type0, Type1, Type2); | |
| 28 #define METHOD4(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ | |
| 29 virtual ReturnType MethodName(Type0, Type1, Type2, Type3); | |
| 30 #define METHOD5(Class, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ | |
| 31 Type4) \ | |
| 32 virtual ReturnType MethodName(Type0, Type1, Type2, Type3, Type4); | |
| 33 #include "nacl_mounts/pepper/all_interfaces.h" | |
| 34 | |
| 35 | |
| 36 #include "nacl_mounts/pepper/undef_macros.h" | |
| 37 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ | |
| 38 Real##BaseClass::Real##BaseClass(const PPInterface* interface) \ | |
| 39 : interface_(interface) {} | |
| 40 | |
| 41 #define END_INTERFACE(BaseClass, PPInterface) | |
| 42 | |
| 43 #define METHOD1(BaseClass, ReturnType, MethodName, Type0) \ | |
| 44 ReturnType Real##BaseClass::MethodName(Type0 arg0) { \ | |
| 45 return interface_->MethodName(arg0); \ | |
| 46 } | |
| 47 #define METHOD2(BaseClass, ReturnType, MethodName, Type0, Type1) \ | |
| 48 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1) { \ | |
| 49 return interface_->MethodName(arg0, arg1); \ | |
| 50 } | |
| 51 #define METHOD3(BaseClass, ReturnType, MethodName, Type0, Type1, Type2) \ | |
| 52 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, \ | |
| 53 Type2 arg2) { \ | |
| 54 return interface_->MethodName(arg0, arg1, arg2); \ | |
| 55 } | |
| 56 #define METHOD4(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3) \ | |
| 57 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ | |
| 58 Type3 arg3) { \ | |
| 59 return interface_->MethodName(arg0, arg1, arg2, arg3); \ | |
| 60 } | |
| 61 #define METHOD5(BaseClass, ReturnType, MethodName, Type0, Type1, Type2, Type3, \ | |
| 62 Type4) \ | |
| 63 ReturnType Real##BaseClass::MethodName(Type0 arg0, Type1 arg1, Type2 arg2, \ | |
| 64 Type3 arg3, Type4 arg4) { \ | |
| 65 return interface_->MethodName(arg0, arg1, arg2, arg3, arg4); \ | |
| 66 } | |
| 67 #include "nacl_mounts/pepper/all_interfaces.h" | |
| 68 | |
| 69 | |
| 70 RealPepperInterface::RealPepperInterface(PP_Instance instance, | |
| 71 PPB_GetInterface get_browser_interface) | |
| 72 : instance_(instance), | |
| 73 core_interface_(NULL), | |
| 74 message_loop_interface_(NULL) { | |
| 75 | |
| 76 core_interface_ = static_cast<const PPB_Core*>( | |
| 77 get_browser_interface(PPB_CORE_INTERFACE)); | |
| 78 message_loop_interface_ = static_cast<const PPB_MessageLoop*>( | |
| 79 get_browser_interface(PPB_MESSAGELOOP_INTERFACE)); | |
| 80 assert(core_interface_); | |
| 81 assert(message_loop_interface_); | |
| 82 | |
| 83 #include "nacl_mounts/pepper/undef_macros.h" | |
| 84 #include "nacl_mounts/pepper/define_empty_macros.h" | |
| 85 #undef BEGIN_INTERFACE | |
| 86 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ | |
| 87 BaseClass##interface_ = new Real##BaseClass( \ | |
| 88 static_cast<const PPInterface*>( \ | |
| 89 get_browser_interface(InterfaceString))); | |
| 90 #include "nacl_mounts/pepper/all_interfaces.h" | |
| 91 } | |
| 92 | |
| 93 PP_Instance RealPepperInterface::GetInstance() { | |
| 94 return instance_; | |
| 95 } | |
| 96 | |
| 97 void RealPepperInterface::AddRefResource(PP_Resource resource) { | |
| 98 if (resource) | |
| 99 core_interface_->AddRefResource(resource); | |
| 100 } | |
| 101 | |
| 102 void RealPepperInterface::ReleaseResource(PP_Resource resource) { | |
| 103 if (resource) | |
| 104 core_interface_->ReleaseResource(resource); | |
| 105 } | |
| 106 | |
| 107 // Define getter function. | |
| 108 #include "nacl_mounts/pepper/undef_macros.h" | |
| 109 #include "nacl_mounts/pepper/define_empty_macros.h" | |
| 110 #undef BEGIN_INTERFACE | |
| 111 #define BEGIN_INTERFACE(BaseClass, PPInterface, InterfaceString) \ | |
| 112 BaseClass* RealPepperInterface::Get##BaseClass() { \ | |
| 113 return BaseClass##interface_; \ | |
| 114 } | |
| 115 #include "nacl_mounts/pepper/all_interfaces.h" | |
| 116 | |
| 117 | |
| 118 int32_t RealPepperInterface::InitializeMessageLoop() { | |
| 119 int32_t result; | |
| 120 PP_Resource message_loop = 0; | |
| 121 if (core_interface_->IsMainThread()) { | |
| 122 // TODO(binji): Spin up the main thread's ppapi work thread. | |
| 123 assert(0); | |
| 124 } else { | |
| 125 message_loop = message_loop_interface_->GetCurrent(); | |
| 126 if (!message_loop) { | |
| 127 message_loop = message_loop_interface_->Create(instance_); | |
| 128 result = message_loop_interface_->AttachToCurrentThread(message_loop); | |
| 129 assert(result == PP_OK); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 return PP_OK; | |
| 134 } | |
| OLD | NEW |