| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "webkit/plugins/ppapi/plugin_module.h" | 5 #include "webkit/plugins/ppapi/plugin_module.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id); | 222 return ResourceTracker::Get()->GetLiveObjectsForInstance(instance_id); |
| 223 } | 223 } |
| 224 | 224 |
| 225 const PPB_Testing_Dev testing_interface = { | 225 const PPB_Testing_Dev testing_interface = { |
| 226 &ReadImageData, | 226 &ReadImageData, |
| 227 &RunMessageLoop, | 227 &RunMessageLoop, |
| 228 &QuitMessageLoop, | 228 &QuitMessageLoop, |
| 229 &GetLiveObjectsForInstance | 229 &GetLiveObjectsForInstance |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 // Return the part of the interface name before the ';' separator. |
| 233 // If there is no ';', just returns the whole string. |
| 234 std::string GetInterfacePrefix(const std::string& interface_string) { |
| 235 size_t separator_pos = interface_string.find_first_of(';'); |
| 236 return interface_string.substr(0, separator_pos); |
| 237 } |
| 238 |
| 232 // GetInterface ---------------------------------------------------------------- | 239 // GetInterface ---------------------------------------------------------------- |
| 233 | 240 |
| 234 const void* GetInterface(const char* name) { | 241 const void* GetInterface(const char* name) { |
| 235 // All interfaces should be used on the main thread. | 242 // All interfaces should be used on the main thread. |
| 236 DCHECK(IsMainThread()); | 243 DCHECK(IsMainThread()); |
| 237 | 244 |
| 245 std::string name_prefix(GetInterfacePrefix(name)); |
| 238 // Please keep alphabetized by interface macro name with "special" stuff at | 246 // Please keep alphabetized by interface macro name with "special" stuff at |
| 239 // the bottom. | 247 // the bottom. |
| 240 if (strcmp(name, PPB_AUDIO_CONFIG_INTERFACE) == 0) | 248 if (strcmp(name, PPB_AUDIO_CONFIG_INTERFACE) == 0) |
| 241 return ::ppapi::thunk::GetPPB_AudioConfig_Thunk(); | 249 return ::ppapi::thunk::GetPPB_AudioConfig_Thunk(); |
| 242 if (strcmp(name, PPB_AUDIO_INTERFACE) == 0) | 250 if (strcmp(name, PPB_AUDIO_INTERFACE) == 0) |
| 243 return ::ppapi::thunk::GetPPB_Audio_Thunk(); | 251 return ::ppapi::thunk::GetPPB_Audio_Thunk(); |
| 244 if (strcmp(name, PPB_AUDIO_TRUSTED_INTERFACE) == 0) | 252 if (strcmp(name, PPB_AUDIO_TRUSTED_INTERFACE) == 0) |
| 245 return ::ppapi::thunk::GetPPB_AudioTrusted_Thunk(); | 253 return ::ppapi::thunk::GetPPB_AudioTrusted_Thunk(); |
| 246 if (strcmp(name, PPB_BROKER_TRUSTED_INTERFACE) == 0) | 254 if (strcmp(name, PPB_BROKER_TRUSTED_INTERFACE) == 0) |
| 247 return PPB_Broker_Impl::GetTrustedInterface(); | 255 return PPB_Broker_Impl::GetTrustedInterface(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (strcmp(name, PPB_FONT_DEV_INTERFACE) == 0) | 294 if (strcmp(name, PPB_FONT_DEV_INTERFACE) == 0) |
| 287 return ::ppapi::thunk::GetPPB_Font_Thunk(); | 295 return ::ppapi::thunk::GetPPB_Font_Thunk(); |
| 288 if (strcmp(name, PPB_FULLSCREEN_DEV_INTERFACE) == 0) | 296 if (strcmp(name, PPB_FULLSCREEN_DEV_INTERFACE) == 0) |
| 289 return PluginInstance::GetFullscreenInterface(); | 297 return PluginInstance::GetFullscreenInterface(); |
| 290 if (strcmp(name, PPB_GRAPHICS_2D_INTERFACE) == 0) | 298 if (strcmp(name, PPB_GRAPHICS_2D_INTERFACE) == 0) |
| 291 return PPB_Graphics2D_Impl::GetInterface(); | 299 return PPB_Graphics2D_Impl::GetInterface(); |
| 292 if (strcmp(name, PPB_IMAGEDATA_INTERFACE) == 0) | 300 if (strcmp(name, PPB_IMAGEDATA_INTERFACE) == 0) |
| 293 return PPB_ImageData_Impl::GetInterface(); | 301 return PPB_ImageData_Impl::GetInterface(); |
| 294 if (strcmp(name, PPB_IMAGEDATA_TRUSTED_INTERFACE) == 0) | 302 if (strcmp(name, PPB_IMAGEDATA_TRUSTED_INTERFACE) == 0) |
| 295 return PPB_ImageData_Impl::GetTrustedInterface(); | 303 return PPB_ImageData_Impl::GetTrustedInterface(); |
| 296 if (strcmp(name, PPB_INSTANCE_INTERFACE) == 0) | 304 if (name_prefix == GetInterfacePrefix(PPB_INSTANCE_INTERFACE)) |
| 297 return PluginInstance::GetInterface(); | 305 return PluginInstance::GetInterface(name); |
| 298 if (strcmp(name, PPB_INSTANCE_PRIVATE_INTERFACE) == 0) | 306 if (strcmp(name, PPB_INSTANCE_PRIVATE_INTERFACE) == 0) |
| 299 return PluginInstance::GetPrivateInterface(); | 307 return PluginInstance::GetPrivateInterface(); |
| 300 if (strcmp(name, PPB_MESSAGING_INTERFACE) == 0) | 308 if (strcmp(name, PPB_MESSAGING_INTERFACE) == 0) |
| 301 return PluginInstance::GetMessagingInterface(); | 309 return PluginInstance::GetMessagingInterface(); |
| 302 if (strcmp(name, PPB_PDF_INTERFACE) == 0) | 310 if (strcmp(name, PPB_PDF_INTERFACE) == 0) |
| 303 return PPB_PDF_Impl::GetInterface(); | 311 return PPB_PDF_Impl::GetInterface(); |
| 304 if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) | 312 if (strcmp(name, PPB_PROXY_PRIVATE_INTERFACE) == 0) |
| 305 return PPB_Proxy_Impl::GetInterface(); | 313 return PPB_Proxy_Impl::GetInterface(); |
| 306 if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE) == 0) | 314 if (strcmp(name, PPB_SCROLLBAR_DEV_INTERFACE) == 0) |
| 307 return PPB_Scrollbar_Impl::GetInterface(); | 315 return PPB_Scrollbar_Impl::GetInterface(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 const PPB_Core* PluginModule::GetCore() { | 489 const PPB_Core* PluginModule::GetCore() { |
| 482 return &core_interface; | 490 return &core_interface; |
| 483 } | 491 } |
| 484 | 492 |
| 485 // static | 493 // static |
| 486 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { | 494 PluginModule::GetInterfaceFunc PluginModule::GetLocalGetInterfaceFunc() { |
| 487 return &GetInterface; | 495 return &GetInterface; |
| 488 } | 496 } |
| 489 | 497 |
| 490 PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) { | 498 PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) { |
| 491 const PPP_Instance* plugin_instance_interface = | 499 PluginInstance* instance(NULL); |
| 492 reinterpret_cast<const PPP_Instance*>(GetPluginInterface( | 500 const void* plugin_instance_if = GetPluginInterface(PPP_INSTANCE_INTERFACE); |
| 493 PPP_INSTANCE_INTERFACE)); | 501 if (plugin_instance_if) { |
| 494 if (!plugin_instance_interface) { | 502 instance = new PluginInstance(delegate, this, |
| 503 PluginInstance::new_instance_interface<PPP_Instance>( |
| 504 plugin_instance_if)); |
| 505 } else { |
| 506 // If the current interface is not supported, try retrieving older versions. |
| 507 const void* instance_if_0_4 = |
| 508 GetPluginInterface(PPP_INSTANCE_INTERFACE_0_4); |
| 509 if (instance_if_0_4) { |
| 510 instance = new PluginInstance(delegate, this, |
| 511 PluginInstance::new_instance_interface<PPP_Instance_0_4>( |
| 512 instance_if_0_4)); |
| 513 } |
| 514 } |
| 515 if (!instance) { |
| 495 LOG(WARNING) << "Plugin doesn't support instance interface, failing."; | 516 LOG(WARNING) << "Plugin doesn't support instance interface, failing."; |
| 496 return NULL; | 517 return NULL; |
| 497 } | 518 } |
| 498 PluginInstance* instance = new PluginInstance(delegate, this, | |
| 499 plugin_instance_interface); | |
| 500 if (out_of_process_proxy_.get()) | 519 if (out_of_process_proxy_.get()) |
| 501 out_of_process_proxy_->AddInstance(instance->pp_instance()); | 520 out_of_process_proxy_->AddInstance(instance->pp_instance()); |
| 502 return instance; | 521 return instance; |
| 503 } | 522 } |
| 504 | 523 |
| 505 PluginInstance* PluginModule::GetSomeInstance() const { | 524 PluginInstance* PluginModule::GetSomeInstance() const { |
| 506 // This will generally crash later if there is not actually any instance to | 525 // This will generally crash later if there is not actually any instance to |
| 507 // return, so we force a crash now to make bugs easier to track down. | 526 // return, so we force a crash now to make bugs easier to track down. |
| 508 CHECK(!instances_.empty()); | 527 CHECK(!instances_.empty()); |
| 509 return *instances_.begin(); | 528 return *instances_.begin(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 int retval = entry_points_.initialize_module(pp_module(), &GetInterface); | 596 int retval = entry_points_.initialize_module(pp_module(), &GetInterface); |
| 578 if (retval != 0) { | 597 if (retval != 0) { |
| 579 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; | 598 LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; |
| 580 return false; | 599 return false; |
| 581 } | 600 } |
| 582 return true; | 601 return true; |
| 583 } | 602 } |
| 584 | 603 |
| 585 } // namespace ppapi | 604 } // namespace ppapi |
| 586 } // namespace webkit | 605 } // namespace webkit |
| OLD | NEW |