1 // Copyright 2014 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 "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" 6 7 #include "base/logging.h" 8 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/time/time.h" 10 #include "mojo/examples/pepper_container_app/plugin_instance.h" 11 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/shared_impl/ppb_message_loop_shared.h" 13 14 namespace mojo { 15 namespace examples { 16 17 namespace { 18 19 const PP_Instance kInstanceId = 1; 20 21 } // namespace 22 23 // A non-abstract subclass of ppapi::MessageLoopShared that represents the 24 // message loop of the main thread. 25 // TODO(yzshen): Build a more general ppapi::MessageLoopShared subclass to fully 26 // support PPB_MessageLoop. 27 class MojoPpapiGlobals::MainThreadMessageLoopResource 28 : public ppapi::MessageLoopShared { 29 public: 30 explicit MainThreadMessageLoopResource( 31 base::MessageLoopProxy* main_thread_message_loop) 32 : MessageLoopShared(ForMainThread()), 33 main_thread_message_loop_(main_thread_message_loop) {} 34 35 // ppapi::MessageLoopShared implementation. 36 virtual void PostClosure(const tracked_objects::Location& from_here, 37 const base::Closure& closure, 38 int64 delay_ms) OVERRIDE { 39 main_thread_message_loop_->PostDelayedTask( 40 from_here, closure, base::TimeDelta::FromMilliseconds(delay_ms)); 41 } 42 43 virtual base::MessageLoopProxy* GetMessageLoopProxy() OVERRIDE { 44 return main_thread_message_loop_.get(); 45 } 46 47 virtual bool CurrentlyHandlingBlockingMessage() OVERRIDE { 48 return false; 49 } 50 51 // ppapi::thunk::PPB_MessageLoop_API implementation. 52 virtual int32_t AttachToCurrentThread() OVERRIDE { 53 NOTIMPLEMENTED(); 54 return PP_ERROR_FAILED; 55 } 56 57 virtual int32_t Run() OVERRIDE { 58 NOTIMPLEMENTED(); 59 return PP_ERROR_FAILED; 60 } 61 62 virtual int32_t PostWork(PP_CompletionCallback callback, 63 int64_t delay_ms) OVERRIDE { 64 NOTIMPLEMENTED(); 65 return PP_ERROR_FAILED; 66 } 67 68 virtual int32_t PostQuit(PP_Bool should_destroy) OVERRIDE { 69 NOTIMPLEMENTED(); 70 return PP_ERROR_FAILED; 71 } 72 73 private: 74 virtual ~MainThreadMessageLoopResource() {} 75 76 scoped_refptr<base::MessageLoopProxy> main_thread_message_loop_; 77 DISALLOW_COPY_AND_ASSIGN(MainThreadMessageLoopResource); 78 }; 79 80 MojoPpapiGlobals::MojoPpapiGlobals(Delegate* delegate) 81 : delegate_(delegate), 82 plugin_instance_(NULL), 83 resource_tracker_(ppapi::ResourceTracker::THREAD_SAFE) {} 84 85 MojoPpapiGlobals::~MojoPpapiGlobals() {} 86 87 PP_Instance MojoPpapiGlobals::AddInstance(PluginInstance* instance) { 88 DCHECK(!plugin_instance_); 89 plugin_instance_ = instance; 90 resource_tracker_.DidCreateInstance(kInstanceId); 91 return kInstanceId; 92 } 93 94 void MojoPpapiGlobals::InstanceDeleted(PP_Instance instance) { 95 DCHECK_EQ(instance, kInstanceId); 96 DCHECK(plugin_instance_); 97 resource_tracker_.DidDeleteInstance(instance); 98 plugin_instance_ = NULL; 99 } 100 101 PluginInstance* MojoPpapiGlobals::GetInstance(PP_Instance instance) { 102 if (instance == kInstanceId) 103 return plugin_instance_; 104 return NULL; 105 } 106 107 ScopedMessagePipeHandle MojoPpapiGlobals::CreateGLES2Context() { 108 return delegate_->CreateGLES2Context(); 109 } 110 111 ppapi::ResourceTracker* MojoPpapiGlobals::GetResourceTracker() { 112 return &resource_tracker_; 113 } 114 115 ppapi::VarTracker* MojoPpapiGlobals::GetVarTracker() { 116 NOTIMPLEMENTED(); 117 return NULL; 118 } 119 120 ppapi::CallbackTracker* MojoPpapiGlobals::GetCallbackTrackerForInstance( 121 PP_Instance instance) { 122 if (instance == kInstanceId && plugin_instance_) 123 return plugin_instance_->plugin_module()->callback_tracker(); 124 return NULL; 125 } 126 127 void MojoPpapiGlobals::LogWithSource(PP_Instance instance, 128 PP_LogLevel level, 129 const std::string& source, 130 const std::string& value) { 131 NOTIMPLEMENTED(); 132 } 133 134 void MojoPpapiGlobals::BroadcastLogWithSource(PP_Module module, 135 PP_LogLevel level, 136 const std::string& source, 137 const std::string& value) { 138 NOTIMPLEMENTED(); 139 } 140 141 ppapi::thunk::PPB_Instance_API* MojoPpapiGlobals::GetInstanceAPI( 142 PP_Instance instance) { 143 if (instance == kInstanceId && plugin_instance_) 144 return plugin_instance_; 145 return NULL; 146 } 147 148 ppapi::thunk::ResourceCreationAPI* MojoPpapiGlobals::GetResourceCreationAPI( 149 PP_Instance instance) { 150 if (instance == kInstanceId && plugin_instance_) 151 return plugin_instance_->resource_creation(); 152 return NULL; 153 } 154 155 PP_Module MojoPpapiGlobals::GetModuleForInstance(PP_Instance instance) { 156 NOTIMPLEMENTED(); 157 return 0; 158 } 159 160 ppapi::MessageLoopShared* MojoPpapiGlobals::GetCurrentMessageLoop() { 161 if (base::MessageLoopProxy::current().get() == GetMainThreadMessageLoop()) { 162 if (!main_thread_message_loop_resource_.get()) { 163 main_thread_message_loop_resource_ = new MainThreadMessageLoopResource( 164 GetMainThreadMessageLoop()); 165 } 166 return main_thread_message_loop_resource_.get(); 167 } 168 169 NOTIMPLEMENTED(); 170 return NULL; 171 } 172 173 base::TaskRunner* MojoPpapiGlobals::GetFileTaskRunner() { 174 NOTIMPLEMENTED(); 175 return NULL; 176 } 177 178 std::string MojoPpapiGlobals::GetCmdLine() { 179 NOTIMPLEMENTED(); 180 return std::string(); 181 } 182 183 void MojoPpapiGlobals::PreCacheFontForFlash(const void* logfontw) { 184 NOTIMPLEMENTED(); 185 } 186 187 } // namespace examples 188 } // namespace mojo 189