diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
commit | 679147eead574d186ebf3069647b4c23e8ccace6 (patch) | |
tree | fc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/ppapi/cpp/private | |
download | qtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz |
Initial import.
Diffstat (limited to 'chromium/ppapi/cpp/private')
55 files changed, 4606 insertions, 0 deletions
diff --git a/chromium/ppapi/cpp/private/DEPS b/chromium/ppapi/cpp/private/DEPS new file mode 100644 index 00000000000..89916e4d70b --- /dev/null +++ b/chromium/ppapi/cpp/private/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+ppapi/c/private", + "+ppapi/c/trusted", + "+ppapi/cpp/trusted", +] diff --git a/chromium/ppapi/cpp/private/content_decryptor_private.cc b/chromium/ppapi/cpp/private/content_decryptor_private.cc new file mode 100644 index 00000000000..48690946128 --- /dev/null +++ b/chromium/ppapi/cpp/private/content_decryptor_private.cc @@ -0,0 +1,346 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/content_decryptor_private.h" + +#include <cstring> // memcpy + +#include "ppapi/c/ppb_var.h" +#include "ppapi/c/private/ppb_content_decryptor_private.h" +#include "ppapi/c/private/ppp_content_decryptor_private.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/logging.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +static const char kPPPContentDecryptorInterface[] = + PPP_CONTENTDECRYPTOR_PRIVATE_INTERFACE; + +void GenerateKeyRequest(PP_Instance instance, + PP_Var key_system_arg, + PP_Var type_arg, + PP_Var init_data_arg) { + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + pp::Var key_system_var(pp::PASS_REF, key_system_arg); + if (!key_system_var.is_string()) + return; + + pp::Var type_var(pp::PASS_REF, type_arg); + if (!type_var.is_string()) + return; + + pp::Var init_data_var(pp::PASS_REF, init_data_arg); + if (!init_data_var.is_array_buffer()) + return; + pp::VarArrayBuffer init_data_array_buffer(init_data_var); + + static_cast<ContentDecryptor_Private*>(object)->GenerateKeyRequest( + key_system_var.AsString(), + type_var.AsString(), + init_data_array_buffer); +} + +void AddKey(PP_Instance instance, + PP_Var session_id_arg, + PP_Var key_arg, + PP_Var init_data_arg) { + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + pp::Var session_id_var(pp::PASS_REF, session_id_arg); + if (!session_id_var.is_string()) + return; + + pp::Var key_var(pp::PASS_REF, key_arg); + if (!key_var.is_array_buffer()) + return; + pp::VarArrayBuffer key(key_var); + + pp::Var init_data_var(pp::PASS_REF, init_data_arg); + if (!init_data_var.is_array_buffer()) + return; + pp::VarArrayBuffer init_data(init_data_var); + + + static_cast<ContentDecryptor_Private*>(object)->AddKey( + session_id_var.AsString(), + key, + init_data); +} + +void CancelKeyRequest(PP_Instance instance, PP_Var session_id_arg) { + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + pp::Var session_id_var(pp::PASS_REF, session_id_arg); + if (!session_id_var.is_string()) + return; + + static_cast<ContentDecryptor_Private*>(object)->CancelKeyRequest( + session_id_var.AsString()); +} + + +void Decrypt(PP_Instance instance, + PP_Resource encrypted_resource, + const PP_EncryptedBlockInfo* encrypted_block_info) { + pp::Buffer_Dev encrypted_block(encrypted_resource); + + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + static_cast<ContentDecryptor_Private*>(object)->Decrypt( + encrypted_block, + *encrypted_block_info); +} + +void InitializeAudioDecoder( + PP_Instance instance, + const PP_AudioDecoderConfig* decoder_config, + PP_Resource extra_data_resource) { + pp::Buffer_Dev extra_data_buffer(extra_data_resource); + + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + static_cast<ContentDecryptor_Private*>(object)->InitializeAudioDecoder( + *decoder_config, + extra_data_buffer); +} + +void InitializeVideoDecoder( + PP_Instance instance, + const PP_VideoDecoderConfig* decoder_config, + PP_Resource extra_data_resource) { + pp::Buffer_Dev extra_data_buffer(extra_data_resource); + + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + static_cast<ContentDecryptor_Private*>(object)->InitializeVideoDecoder( + *decoder_config, + extra_data_buffer); +} + +void DeinitializeDecoder(PP_Instance instance, + PP_DecryptorStreamType decoder_type, + uint32_t request_id) { + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + static_cast<ContentDecryptor_Private*>(object)->DeinitializeDecoder( + decoder_type, + request_id); +} + +void ResetDecoder(PP_Instance instance, + PP_DecryptorStreamType decoder_type, + uint32_t request_id) { + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + static_cast<ContentDecryptor_Private*>(object)->ResetDecoder(decoder_type, + request_id); +} + +void DecryptAndDecode(PP_Instance instance, + PP_DecryptorStreamType decoder_type, + PP_Resource encrypted_resource, + const PP_EncryptedBlockInfo* encrypted_block_info) { + pp::Buffer_Dev encrypted_buffer(encrypted_resource); + + void* object = + Instance::GetPerInstanceObject(instance, kPPPContentDecryptorInterface); + if (!object) + return; + + static_cast<ContentDecryptor_Private*>(object)->DecryptAndDecode( + decoder_type, + encrypted_buffer, + *encrypted_block_info); +} + +const PPP_ContentDecryptor_Private ppp_content_decryptor = { + &GenerateKeyRequest, + &AddKey, + &CancelKeyRequest, + &Decrypt, + &InitializeAudioDecoder, + &InitializeVideoDecoder, + &DeinitializeDecoder, + &ResetDecoder, + &DecryptAndDecode +}; + +template <> const char* interface_name<PPB_ContentDecryptor_Private>() { + return PPB_CONTENTDECRYPTOR_PRIVATE_INTERFACE; +} + +} // namespace + +ContentDecryptor_Private::ContentDecryptor_Private(Instance* instance) + : associated_instance_(instance) { + Module::Get()->AddPluginInterface(kPPPContentDecryptorInterface, + &ppp_content_decryptor); + instance->AddPerInstanceObject(kPPPContentDecryptorInterface, this); +} + +ContentDecryptor_Private::~ContentDecryptor_Private() { + Instance::RemovePerInstanceObject(associated_instance_, + kPPPContentDecryptorInterface, + this); +} + +void ContentDecryptor_Private::NeedKey(const std::string& key_system, + const std::string& session_id, + pp::VarArrayBuffer init_data) { + // session_id can be empty here. + if (has_interface<PPB_ContentDecryptor_Private>()) { + pp::Var key_system_var(key_system); + pp::Var session_id_var(session_id); + + get_interface<PPB_ContentDecryptor_Private>()->NeedKey( + associated_instance_.pp_instance(), + key_system_var.pp_var(), + session_id_var.pp_var(), + init_data.pp_var()); + } +} + +void ContentDecryptor_Private::KeyAdded(const std::string& key_system, + const std::string& session_id) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + pp::Var key_system_var(key_system); + pp::Var session_id_var(session_id); + get_interface<PPB_ContentDecryptor_Private>()->KeyAdded( + associated_instance_.pp_instance(), + key_system_var.pp_var(), + session_id_var.pp_var()); + } +} + +void ContentDecryptor_Private::KeyMessage(const std::string& key_system, + const std::string& session_id, + pp::VarArrayBuffer message, + const std::string& default_url) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + pp::Var key_system_var(key_system); + pp::Var session_id_var(session_id); + pp::Var default_url_var(default_url); + get_interface<PPB_ContentDecryptor_Private>()->KeyMessage( + associated_instance_.pp_instance(), + key_system_var.pp_var(), + session_id_var.pp_var(), + message.pp_var(), + default_url_var.pp_var()); + } +} + +void ContentDecryptor_Private::KeyError(const std::string& key_system, + const std::string& session_id, + int32_t media_error, + int32_t system_code) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + pp::Var key_system_var(key_system); + pp::Var session_id_var(session_id); + get_interface<PPB_ContentDecryptor_Private>()->KeyError( + associated_instance_.pp_instance(), + key_system_var.pp_var(), + session_id_var.pp_var(), + media_error, + system_code); + } +} + +void ContentDecryptor_Private::DeliverBlock( + pp::Buffer_Dev decrypted_block, + const PP_DecryptedBlockInfo& decrypted_block_info) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DeliverBlock( + associated_instance_.pp_instance(), + decrypted_block.pp_resource(), + &decrypted_block_info); + } +} + +void ContentDecryptor_Private::DecoderInitializeDone( + PP_DecryptorStreamType decoder_type, + uint32_t request_id, + bool success) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DecoderInitializeDone( + associated_instance_.pp_instance(), + decoder_type, + request_id, + PP_FromBool(success)); + } +} + +void ContentDecryptor_Private::DecoderDeinitializeDone( + PP_DecryptorStreamType decoder_type, + uint32_t request_id) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DecoderDeinitializeDone( + associated_instance_.pp_instance(), + decoder_type, + request_id); + } +} + +void ContentDecryptor_Private::DecoderResetDone( + PP_DecryptorStreamType decoder_type, + uint32_t request_id) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DecoderResetDone( + associated_instance_.pp_instance(), + decoder_type, + request_id); + } +} + +void ContentDecryptor_Private::DeliverFrame( + pp::Buffer_Dev decrypted_frame, + const PP_DecryptedFrameInfo& decrypted_frame_info) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DeliverFrame( + associated_instance_.pp_instance(), + decrypted_frame.pp_resource(), + &decrypted_frame_info); + } +} + +void ContentDecryptor_Private::DeliverSamples( + pp::Buffer_Dev audio_frames, + const PP_DecryptedBlockInfo& decrypted_block_info) { + if (has_interface<PPB_ContentDecryptor_Private>()) { + get_interface<PPB_ContentDecryptor_Private>()->DeliverSamples( + associated_instance_.pp_instance(), + audio_frames.pp_resource(), + &decrypted_block_info); + } +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/content_decryptor_private.h b/chromium/ppapi/cpp/private/content_decryptor_private.h new file mode 100644 index 00000000000..477c6de5c25 --- /dev/null +++ b/chromium/ppapi/cpp/private/content_decryptor_private.h @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_CONTENT_DECRYPTOR_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_CONTENT_DECRYPTOR_PRIVATE_H_ + +#include "ppapi/c/private/pp_content_decryptor.h" +#include "ppapi/c/private/ppb_content_decryptor_private.h" +#include "ppapi/c/private/ppp_content_decryptor_private.h" + +#include "ppapi/cpp/dev/buffer_dev.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/var.h" +#include "ppapi/cpp/var_array_buffer.h" + +namespace pp { + +class Instance; + +// TODO(tomfinegan): Remove redundant pp:: usage, and pass VarArrayBuffers as +// const references. + +class ContentDecryptor_Private { + public: + explicit ContentDecryptor_Private(Instance* instance); + virtual ~ContentDecryptor_Private(); + + // PPP_ContentDecryptor_Private functions exposed as virtual functions + // for you to override. + // TODO(tomfinegan): This could be optimized to pass pp::Var instead of + // strings. The change would allow the CDM wrapper to reuse vars when + // replying to the browser. + virtual void GenerateKeyRequest(const std::string& key_system, + const std::string& type, + pp::VarArrayBuffer init_data) = 0; + virtual void AddKey(const std::string& session_id, + pp::VarArrayBuffer key, + pp::VarArrayBuffer init_data) = 0; + virtual void CancelKeyRequest(const std::string& session_id) = 0; + virtual void Decrypt(pp::Buffer_Dev encrypted_buffer, + const PP_EncryptedBlockInfo& encrypted_block_info) = 0; + virtual void InitializeAudioDecoder( + const PP_AudioDecoderConfig& decoder_config, + pp::Buffer_Dev extra_data_resource) = 0; + virtual void InitializeVideoDecoder( + const PP_VideoDecoderConfig& decoder_config, + pp::Buffer_Dev extra_data_resource) = 0; + virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, + uint32_t request_id) = 0; + virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, + uint32_t request_id) = 0; + // Null |encrypted_frame| means end-of-stream buffer. + virtual void DecryptAndDecode( + PP_DecryptorStreamType decoder_type, + pp::Buffer_Dev encrypted_buffer, + const PP_EncryptedBlockInfo& encrypted_block_info) = 0; + + // PPB_ContentDecryptor_Private methods for passing data from the decryptor + // to the browser. + void NeedKey(const std::string& key_system, + const std::string& session_id, + pp::VarArrayBuffer init_data); + void KeyAdded(const std::string& key_system, + const std::string& session_id); + void KeyMessage(const std::string& key_system, + const std::string& session_id, + pp::VarArrayBuffer message, + const std::string& default_url); + void KeyError(const std::string& key_system, + const std::string& session_id, + int32_t media_error, + int32_t system_code); + + // The plugin must not hold a reference to the encrypted buffer resource + // provided to Decrypt() when it calls this method. The browser will reuse + // the buffer in a subsequent Decrypt() call. + void DeliverBlock(pp::Buffer_Dev decrypted_block, + const PP_DecryptedBlockInfo& decrypted_block_info); + + void DecoderInitializeDone(PP_DecryptorStreamType decoder_type, + uint32_t request_id, + bool status); + void DecoderDeinitializeDone(PP_DecryptorStreamType decoder_type, + uint32_t request_id); + void DecoderResetDone(PP_DecryptorStreamType decoder_type, + uint32_t request_id); + + // The plugin must not hold a reference to the encrypted buffer resource + // provided to DecryptAndDecode() when it calls this method. The browser will + // reuse the buffer in a subsequent DecryptAndDecode() call. + void DeliverFrame(pp::Buffer_Dev decrypted_frame, + const PP_DecryptedFrameInfo& decrypted_frame_info); + + // The plugin must not hold a reference to the encrypted buffer resource + // provided to DecryptAndDecode() when it calls this method. The browser will + // reuse the buffer in a subsequent DecryptAndDecode() call. + void DeliverSamples(pp::Buffer_Dev audio_frames, + const PP_DecryptedBlockInfo& decrypted_block_info); + + private: + InstanceHandle associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_CONTENT_DECRYPTOR_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/ext_crx_file_system_private.cc b/chromium/ppapi/cpp/private/ext_crx_file_system_private.cc new file mode 100644 index 00000000000..87752b94d0b --- /dev/null +++ b/chromium/ppapi/cpp/private/ext_crx_file_system_private.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/ext_crx_file_system_private.h" + +#include "ppapi/c/private/ppb_ext_crx_file_system_private.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Ext_CrxFileSystem_Private_0_1>() { + return PPB_EXT_CRXFILESYSTEM_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +ExtCrxFileSystemPrivate::ExtCrxFileSystemPrivate() { +} + +ExtCrxFileSystemPrivate::ExtCrxFileSystemPrivate( + const InstanceHandle& instance) : instance_(instance.pp_instance()) { +} + +ExtCrxFileSystemPrivate::~ExtCrxFileSystemPrivate() { +} + +int32_t ExtCrxFileSystemPrivate::Open( + const CompletionCallbackWithOutput<pp::FileSystem>& cc) { + if (!has_interface<PPB_Ext_CrxFileSystem_Private_0_1>()) + return cc.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_Ext_CrxFileSystem_Private_0_1>()-> + Open(instance_, cc.output(), cc.pp_completion_callback()); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/ext_crx_file_system_private.h b/chromium/ppapi/cpp/private/ext_crx_file_system_private.h new file mode 100644 index 00000000000..e307f91f0e8 --- /dev/null +++ b/chromium/ppapi/cpp/private/ext_crx_file_system_private.h @@ -0,0 +1,31 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_EXTENSION_CRX_FILE_SYSTEM_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_EXTENSION_CRX_FILE_SYSTEM_PRIVATE_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/file_system.h" +#include "ppapi/cpp/instance_handle.h" + +namespace pp { + +class CompletionCallback; + +class ExtCrxFileSystemPrivate { + public: + ExtCrxFileSystemPrivate(); + explicit ExtCrxFileSystemPrivate(const InstanceHandle& instance); + virtual ~ExtCrxFileSystemPrivate(); + + int32_t Open(const CompletionCallbackWithOutput<pp::FileSystem>& cc); + + private: + PP_Instance instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_EXTENSION_CRX_FILE_SYSTEM_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/file_io_private.cc b/chromium/ppapi/cpp/private/file_io_private.cc new file mode 100644 index 00000000000..b0f5a00f075 --- /dev/null +++ b/chromium/ppapi/cpp/private/file_io_private.cc @@ -0,0 +1,40 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/file_io_private.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_file_io_private.h" +#include "ppapi/cpp/file_io.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_FileIO_Private>() { + return PPB_FILEIO_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +FileIO_Private::FileIO_Private() + : FileIO() { +} + +FileIO_Private::FileIO_Private(const InstanceHandle& instance) + : FileIO(instance) { +} + +int32_t FileIO_Private::RequestOSFileHandle( + const CompletionCallbackWithOutput<PassFileHandle>& cc) { + if (has_interface<PPB_FileIO_Private>()) + return get_interface<PPB_FileIO_Private>()->RequestOSFileHandle( + pp_resource(), + cc.output(), + cc.pp_completion_callback()); + return cc.MayForce(PP_ERROR_NOINTERFACE); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/file_io_private.h b/chromium/ppapi/cpp/private/file_io_private.h new file mode 100644 index 00000000000..6f0d06d454a --- /dev/null +++ b/chromium/ppapi/cpp/private/file_io_private.h @@ -0,0 +1,29 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FILE_IO_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_FILE_IO_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/pp_file_handle.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/file_io.h" +#include "ppapi/cpp/private/pass_file_handle.h" + +namespace pp { + +class FileIO; + +class FileIO_Private : public FileIO { + public: + FileIO_Private(); + explicit FileIO_Private(const InstanceHandle& instance); + + int32_t RequestOSFileHandle( + const CompletionCallbackWithOutput<PassFileHandle>& cc); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FILE_IO_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/flash.cc b/chromium/ppapi/cpp/private/flash.cc new file mode 100644 index 00000000000..757dbecbdbd --- /dev/null +++ b/chromium/ppapi/cpp/private/flash.cc @@ -0,0 +1,308 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash.h" + +#include <string.h> + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/dev/device_ref_dev.h" +#include "ppapi/cpp/dev/video_capture_dev.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/point.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/trusted/browser_font_trusted.h" +#include "ppapi/cpp/url_request_info.h" +#include "ppapi/cpp/var.h" +#include "ppapi/c/private/ppb_flash.h" +#include "ppapi/c/private/ppb_flash_print.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_13_0>() { + return PPB_FLASH_INTERFACE_13_0; +} + +template <> const char* interface_name<PPB_Flash_12_6>() { + return PPB_FLASH_INTERFACE_12_6; +} + +template <> const char* interface_name<PPB_Flash_12_5>() { + return PPB_FLASH_INTERFACE_12_5; +} + +template <> const char* interface_name<PPB_Flash_12_4>() { + return PPB_FLASH_INTERFACE_12_4; +} + +template <> const char* interface_name<PPB_Flash_Print_1_0>() { + return PPB_FLASH_PRINT_INTERFACE_1_0; +} + +// The combined Flash interface is all Flash v12.* interfaces. All v12 +// interfaces just append one or more functions to the previous one, so we can +// have this meta one at the most recent version. Function pointers will be +// null if they're not supported on the current Chrome version. +bool initialized_combined_interface = false; +PPB_Flash_12_6 flash_12_combined_interface; + +// Makes sure that the most recent version is loaded into the combined +// interface struct above. Any unsupported functions will be NULL. If there +// is no Flash interface supported, all functions will be NULL. +void InitializeCombinedInterface() { + if (initialized_combined_interface) + return; + if (has_interface<PPB_Flash_12_6>()) { + memcpy(&flash_12_combined_interface, get_interface<PPB_Flash_12_6>(), + sizeof(PPB_Flash_12_6)); + } else if (has_interface<PPB_Flash_12_5>()) { + memcpy(&flash_12_combined_interface, get_interface<PPB_Flash_12_5>(), + sizeof(PPB_Flash_12_5)); + } else if (has_interface<PPB_Flash_12_4>()) { + memcpy(&flash_12_combined_interface, get_interface<PPB_Flash_12_4>(), + sizeof(PPB_Flash_12_4)); + } + initialized_combined_interface = true; +} + +} // namespace + +namespace flash { + +// static +bool Flash::IsAvailable() { + return has_interface<PPB_Flash_13_0>() || + has_interface<PPB_Flash_12_6>() || + has_interface<PPB_Flash_12_5>() || + has_interface<PPB_Flash_12_4>(); +} + +// static +void Flash::SetInstanceAlwaysOnTop(const InstanceHandle& instance, + bool on_top) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + get_interface<PPB_Flash_13_0>()->SetInstanceAlwaysOnTop( + instance.pp_instance(), PP_FromBool(on_top)); + } else if (flash_12_combined_interface.SetInstanceAlwaysOnTop) { + flash_12_combined_interface.SetInstanceAlwaysOnTop( + instance.pp_instance(), PP_FromBool(on_top)); + } +} + +// static +bool Flash::DrawGlyphs(const InstanceHandle& instance, + ImageData* image, + const BrowserFontDescription& font_desc, + uint32_t color, + const Point& position, + const Rect& clip, + const float transformation[3][3], + bool allow_subpixel_aa, + uint32_t glyph_count, + const uint16_t glyph_indices[], + const PP_Point glyph_advances[]) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return PP_ToBool(get_interface<PPB_Flash_13_0>()->DrawGlyphs( + instance.pp_instance(), + image->pp_resource(), + &font_desc.pp_font_description(), + color, + &position.pp_point(), + &clip.pp_rect(), + transformation, + PP_FromBool(allow_subpixel_aa), + glyph_count, + glyph_indices, + glyph_advances)); + } + if (flash_12_combined_interface.DrawGlyphs) { + return PP_ToBool(flash_12_combined_interface.DrawGlyphs( + instance.pp_instance(), + image->pp_resource(), + &font_desc.pp_font_description(), + color, + &position.pp_point(), + &clip.pp_rect(), + transformation, + PP_FromBool(allow_subpixel_aa), + glyph_count, + glyph_indices, + glyph_advances)); + } + return false; +} + +// static +Var Flash::GetProxyForURL(const InstanceHandle& instance, + const std::string& url) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return Var(PASS_REF, get_interface<PPB_Flash_13_0>()->GetProxyForURL( + instance.pp_instance(), url.c_str())); + } + if (flash_12_combined_interface.GetProxyForURL) { + return Var(PASS_REF, flash_12_combined_interface.GetProxyForURL( + instance.pp_instance(), url.c_str())); + } + return Var(); +} + +// static +int32_t Flash::Navigate(const URLRequestInfo& request_info, + const std::string& target, + bool from_user_action) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return get_interface<PPB_Flash_13_0>()->Navigate( + request_info.pp_resource(), + target.c_str(), + PP_FromBool(from_user_action)); + } + if (flash_12_combined_interface.Navigate) { + return flash_12_combined_interface.Navigate( + request_info.pp_resource(), + target.c_str(), + PP_FromBool(from_user_action)); + } + return PP_ERROR_FAILED; +} + +// static +double Flash::GetLocalTimeZoneOffset(const InstanceHandle& instance, + PP_Time t) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return get_interface<PPB_Flash_13_0>()->GetLocalTimeZoneOffset( + instance.pp_instance(), t); + } + if (flash_12_combined_interface.GetLocalTimeZoneOffset) { + return flash_12_combined_interface.GetLocalTimeZoneOffset( + instance.pp_instance(), t); + } + return 0.0; +} + +// static +Var Flash::GetCommandLineArgs(Module* module) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return Var(PASS_REF, get_interface<PPB_Flash_13_0>()->GetCommandLineArgs( + module->pp_module())); + } + if (flash_12_combined_interface.GetCommandLineArgs) { + return Var( + PASS_REF, + flash_12_combined_interface.GetCommandLineArgs(module->pp_module())); + } + return Var(); +} + +// static +void Flash::PreloadFontWin(const void* logfontw) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) + return get_interface<PPB_Flash_13_0>()->PreloadFontWin(logfontw); + if (flash_12_combined_interface.PreloadFontWin) + return flash_12_combined_interface.PreloadFontWin(logfontw); +} + +// static +bool Flash::IsRectTopmost(const InstanceHandle& instance, const Rect& rect) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return PP_ToBool(get_interface<PPB_Flash_13_0>()->IsRectTopmost( + instance.pp_instance(), &rect.pp_rect())); + } + if (flash_12_combined_interface.IsRectTopmost) { + return PP_ToBool(flash_12_combined_interface.IsRectTopmost( + instance.pp_instance(), &rect.pp_rect())); + } + return false; +} + +// static +void Flash::UpdateActivity(const InstanceHandle& instance) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) + get_interface<PPB_Flash_13_0>()->UpdateActivity(instance.pp_instance()); + else if (flash_12_combined_interface.UpdateActivity) + flash_12_combined_interface.UpdateActivity(instance.pp_instance()); +} + +// static +Var Flash::GetSetting(const InstanceHandle& instance, PP_FlashSetting setting) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return Var(PASS_REF, get_interface<PPB_Flash_13_0>()->GetSetting( + instance.pp_instance(), setting)); + } + if (flash_12_combined_interface.GetSetting) { + return Var(PASS_REF, + flash_12_combined_interface.GetSetting(instance.pp_instance(), + setting)); + } + + return Var(); +} + +// static +bool Flash::SetCrashData(const InstanceHandle& instance, + PP_FlashCrashKey key, + const pp::Var& value) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + return PP_ToBool(get_interface<PPB_Flash_13_0>()->SetCrashData( + instance.pp_instance(), key, value.pp_var())); + } + if (flash_12_combined_interface.SetCrashData) { + return PP_ToBool( + flash_12_combined_interface.SetCrashData(instance.pp_instance(), + key, value.pp_var())); + } + return false; +} + +// static +int32_t Flash::EnumerateVideoCaptureDevices( + const InstanceHandle& instance, + const VideoCapture_Dev& video_capture, + std::vector<DeviceRef_Dev>* devices_out) { + InitializeCombinedInterface(); + if (has_interface<PPB_Flash_13_0>()) { + ResourceArrayOutputAdapter<DeviceRef_Dev> adapter(devices_out); + return get_interface<PPB_Flash_13_0>()->EnumerateVideoCaptureDevices( + instance.pp_instance(), + video_capture.pp_resource(), + adapter.pp_array_output()); + } + if (flash_12_combined_interface.EnumerateVideoCaptureDevices) { + ResourceArrayOutputAdapter<DeviceRef_Dev> adapter(devices_out); + return flash_12_combined_interface.EnumerateVideoCaptureDevices( + instance.pp_instance(), + video_capture.pp_resource(), + adapter.pp_array_output()); + } + return PP_ERROR_FAILED; +} + +// static +bool Flash::InvokePrinting(const InstanceHandle& instance) { + if (has_interface<PPB_Flash_Print_1_0>()) { + get_interface<PPB_Flash_Print_1_0>()->InvokePrinting( + instance.pp_instance()); + return true; + } + return false; +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash.h b/chromium/ppapi/cpp/private/flash.h new file mode 100644 index 00000000000..6a6b7c311aa --- /dev/null +++ b/chromium/ppapi/cpp/private/flash.h @@ -0,0 +1,80 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_H_ +#define PPAPI_CPP_PRIVATE_FLASH_H_ + +#include <string> +#include <vector> + +#include "ppapi/c/private/ppb_flash.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_time.h" + +struct PP_Point; + +namespace pp { + +class BrowserFontDescription; +class DeviceRef_Dev; +class ImageData; +class InstanceHandle; +class Module; +class Point; +class Rect; +class URLRequestInfo; +class Var; +class VideoCapture_Dev; + +namespace flash { + +class Flash { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + static void SetInstanceAlwaysOnTop(const InstanceHandle& instance, + bool on_top); + static bool DrawGlyphs(const InstanceHandle& instance, + ImageData* image, + const BrowserFontDescription& font_desc, + uint32_t color, + const Point& position, + const Rect& clip, + const float transformation[3][3], + bool allow_subpixel_aa, + uint32_t glyph_count, + const uint16_t glyph_indices[], + const PP_Point glyph_advances[]); + static Var GetProxyForURL(const InstanceHandle& instance, + const std::string& url); + static int32_t Navigate(const URLRequestInfo& request_info, + const std::string& target, + bool from_user_action); + static void RunMessageLoop(const InstanceHandle& instance); + static void QuitMessageLoop(const InstanceHandle& instance); + static double GetLocalTimeZoneOffset(const InstanceHandle& instance, + PP_Time t); + static Var GetCommandLineArgs(Module* module); + static void PreloadFontWin(const void* logfontw); + static bool IsRectTopmost(const InstanceHandle& instance, const Rect& rect); + static void UpdateActivity(const InstanceHandle& instance); + static Var GetDeviceID(const InstanceHandle& instance); + static Var GetSetting(const InstanceHandle& instance, + PP_FlashSetting setting); + static bool SetCrashData(const InstanceHandle& instance, + PP_FlashCrashKey key, + const pp::Var& value); + static int32_t EnumerateVideoCaptureDevices(const InstanceHandle& instance, + const VideoCapture_Dev& video_capture, + std::vector<DeviceRef_Dev>* devices_out); + + // PPB_Flash_Print. + static bool InvokePrinting(const InstanceHandle& instance); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_H_ diff --git a/chromium/ppapi/cpp/private/flash_clipboard.cc b/chromium/ppapi/cpp/private/flash_clipboard.cc new file mode 100644 index 00000000000..c63f747bcc0 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_clipboard.cc @@ -0,0 +1,152 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_clipboard.h" + +#include <vector> + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_Clipboard_4_0>() { + return PPB_FLASH_CLIPBOARD_INTERFACE_4_0; +} + +template <> const char* interface_name<PPB_Flash_Clipboard_5_0>() { + return PPB_FLASH_CLIPBOARD_INTERFACE_5_0; +} + +} // namespace + +namespace flash { + +// static +bool Clipboard::IsAvailable() { + return has_interface<PPB_Flash_Clipboard_5_0>() || + has_interface<PPB_Flash_Clipboard_4_0>() ; +} + +// static +uint32_t Clipboard::RegisterCustomFormat(const InstanceHandle& instance, + const std::string& format_name) { + uint32_t rv = PP_FLASH_CLIPBOARD_FORMAT_INVALID; + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + rv = get_interface<PPB_Flash_Clipboard_5_0>()->RegisterCustomFormat( + instance.pp_instance(), format_name.c_str()); + } + return rv; +} + +// static +bool Clipboard::IsFormatAvailable(const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) { + bool rv = false; + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_5_0>()->IsFormatAvailable( + instance.pp_instance(), clipboard_type, format)); + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { + rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_4_0>()->IsFormatAvailable( + instance.pp_instance(), clipboard_type, + static_cast<PP_Flash_Clipboard_Format>(format))); + } + return rv; +} + +// static +bool Clipboard::ReadData( + const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format, + Var* out) { + bool rv = false; + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + PP_Var result = get_interface<PPB_Flash_Clipboard_5_0>()->ReadData( + instance.pp_instance(), + clipboard_type, + format); + *out = Var(PASS_REF, result); + rv = true; + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { + PP_Var result = get_interface<PPB_Flash_Clipboard_4_0>()->ReadData( + instance.pp_instance(), + clipboard_type, + static_cast<PP_Flash_Clipboard_Format>(format)); + *out = Var(PASS_REF, result); + rv = true; + } + return rv; +} + +// static +bool Clipboard::WriteData( + const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + const std::vector<uint32_t>& formats, + const std::vector<Var>& data_items) { + if (formats.size() != data_items.size()) + return false; + + bool rv = false; + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + // Convert vector of pp::Var into a vector of PP_Var. + std::vector<PP_Var> data_items_vector; + for (uint32_t i = 0; i < data_items.size(); ++i) + data_items_vector.push_back(data_items[i].pp_var()); + + // Ensure that we don't dereference the memory in empty vectors. We still + // want to call WriteData because it has the effect of clearing the + // clipboard. + const uint32_t* formats_ptr(NULL); + const PP_Var* data_items_ptr(NULL); + if (data_items.size() > 0) { + formats_ptr = &formats[0]; + data_items_ptr = &data_items_vector[0]; + } + + rv = (get_interface<PPB_Flash_Clipboard_5_0>()->WriteData( + instance.pp_instance(), + clipboard_type, + data_items.size(), + formats_ptr, + data_items_ptr) == PP_OK); + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { + // Convert vector of pp::Var into a vector of PP_Var. + std::vector<PP_Var> data_items_vector; + std::vector<PP_Flash_Clipboard_Format> old_formats; + for (uint32_t i = 0; i < data_items.size(); ++i) { + data_items_vector.push_back(data_items[i].pp_var()); + old_formats.push_back(static_cast<PP_Flash_Clipboard_Format>(formats[i])); + } + + // Ensure that we don't dereference the memory in empty vectors. We still + // want to call WriteData because it has the effect of clearing the + // clipboard. + const PP_Flash_Clipboard_Format* formats_ptr(NULL); + const PP_Var* data_items_ptr(NULL); + if (data_items.size() > 0) { + formats_ptr = &old_formats[0]; + data_items_ptr = &data_items_vector[0]; + } + + rv = (get_interface<PPB_Flash_Clipboard_4_0>()->WriteData( + instance.pp_instance(), + clipboard_type, + data_items.size(), + formats_ptr, + data_items_ptr) == PP_OK); + } + + return rv; +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_clipboard.h b/chromium/ppapi/cpp/private/flash_clipboard.h new file mode 100644 index 00000000000..aab06efb1e9 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_clipboard.h @@ -0,0 +1,53 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_ +#define PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_ + +#include <string> +#include <vector> + +#include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class InstanceHandle; + +namespace flash { + +class Clipboard { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + // Returns a format ID on success or PP_FLASH_CLIPBOARD_FORMAT_INVALID on + // failure. + static uint32_t RegisterCustomFormat(const InstanceHandle& instance, + const std::string& format_name); + + // Returns true if the given format is available from the given clipboard. + static bool IsFormatAvailable(const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format); + + // Returns true on success, in which case |out| will be filled with + // data read from the given clipboard in the given format. + static bool ReadData(const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t clipboard_format, + Var* out); + + // Returns true on success in which case all of |data| will be written to + // the clipboard. Otherwise nothing will be written. + static bool WriteData(const InstanceHandle& instance, + PP_Flash_Clipboard_Type clipboard_type, + const std::vector<uint32_t>& formats, + const std::vector<Var>& data_items); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_ diff --git a/chromium/ppapi/cpp/private/flash_device_id.cc b/chromium/ppapi/cpp/private/flash_device_id.cc new file mode 100644 index 00000000000..6ed893573ec --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_device_id.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_device_id.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_flash_device_id.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_DeviceID_1_0>() { + return PPB_FLASH_DEVICEID_INTERFACE_1_0; +} + +} // namespace + +namespace flash { + +DeviceID::DeviceID() { +} + +DeviceID::DeviceID(const InstanceHandle& instance) : Resource() { + if (has_interface<PPB_Flash_DeviceID_1_0>()) { + PassRefFromConstructor(get_interface<PPB_Flash_DeviceID_1_0>()->Create( + instance.pp_instance())); + } +} + +int32_t DeviceID::GetDeviceID( + const CompletionCallbackWithOutput<Var>& callback) { + if (has_interface<PPB_Flash_DeviceID_1_0>()) { + return get_interface<PPB_Flash_DeviceID_1_0>()->GetDeviceID( + pp_resource(), + callback.output(), + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_device_id.h b/chromium/ppapi/cpp/private/flash_device_id.h new file mode 100644 index 00000000000..33c5e55652f --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_device_id.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_DEVICE_ID_H_ +#define PPAPI_CPP_PRIVATE_FLASH_DEVICE_ID_H_ + +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/resource.h" + +namespace pp { +namespace flash { + +class DeviceID : public Resource { + public: + DeviceID(); + DeviceID(const InstanceHandle& instance); + + // On success, returns a string var. + int32_t GetDeviceID(const CompletionCallbackWithOutput<Var>& callback); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_DEVICE_ID_H_ diff --git a/chromium/ppapi/cpp/private/flash_drm.cc b/chromium/ppapi/cpp/private/flash_drm.cc new file mode 100644 index 00000000000..44887abc207 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_drm.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_drm.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_flash_device_id.h" +#include "ppapi/c/private/ppb_flash_drm.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_DRM_1_0>() { + return PPB_FLASH_DRM_INTERFACE_1_0; +} + +template <> const char* interface_name<PPB_Flash_DeviceID_1_0>() { + return PPB_FLASH_DEVICEID_INTERFACE_1_0; +} + +} // namespace + +namespace flash { + +DRM::DRM() { +} + +DRM::DRM(const InstanceHandle& instance) : Resource() { + if (has_interface<PPB_Flash_DRM_1_0>()) { + PassRefFromConstructor(get_interface<PPB_Flash_DRM_1_0>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_Flash_DeviceID_1_0>()) { + PassRefFromConstructor(get_interface<PPB_Flash_DeviceID_1_0>()->Create( + instance.pp_instance())); + } +} + +int32_t DRM::GetDeviceID(const CompletionCallbackWithOutput<Var>& callback) { + if (has_interface<PPB_Flash_DRM_1_0>()) { + return get_interface<PPB_Flash_DRM_1_0>()->GetDeviceID( + pp_resource(), + callback.output(), + callback.pp_completion_callback()); + } + if (has_interface<PPB_Flash_DeviceID_1_0>()) { + return get_interface<PPB_Flash_DeviceID_1_0>()->GetDeviceID( + pp_resource(), + callback.output(), + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +bool DRM::GetHmonitor(int64_t* hmonitor) { + if (has_interface<PPB_Flash_DRM_1_0>()) { + return PP_ToBool(get_interface<PPB_Flash_DRM_1_0>()->GetHmonitor( + pp_resource(), + hmonitor)); + } + return 0; +} + +int32_t DRM::GetVoucherFile( + const CompletionCallbackWithOutput<FileRef>& callback) { + if (has_interface<PPB_Flash_DRM_1_0>()) { + return get_interface<PPB_Flash_DRM_1_0>()->GetVoucherFile( + pp_resource(), + callback.output(), + callback.pp_completion_callback()); + } + return PP_ERROR_FAILED; +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_drm.h b/chromium/ppapi/cpp/private/flash_drm.h new file mode 100644 index 00000000000..45ecde8b9a4 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_drm.h @@ -0,0 +1,35 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_DRM_H_ +#define PPAPI_CPP_PRIVATE_FLASH_DRM_H_ + +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/file_ref.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class FileRef; + +namespace flash { + +class DRM : public Resource { + public: + DRM(); + explicit DRM(const InstanceHandle& instance); + + // On success, returns a string var. + int32_t GetDeviceID(const CompletionCallbackWithOutput<Var>& callback); + // Outputs the HMONITOR associated with the current plugin instance in + // |hmonitor|. True is returned upon success. + bool GetHmonitor(int64_t* hmonitor); + // Returns the voucher file as a FileRef or an invalid resource on failure. + int32_t GetVoucherFile(const CompletionCallbackWithOutput<FileRef>& callback); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_DRM_H_ diff --git a/chromium/ppapi/cpp/private/flash_file.cc b/chromium/ppapi/cpp/private/flash_file.cc new file mode 100644 index 00000000000..7004b985b1a --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_file.cc @@ -0,0 +1,178 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_file.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/file_ref.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +// FileModuleLocal ------------------------------------------------------------- + +namespace { + +template <> const char* interface_name<PPB_Flash_File_ModuleLocal_3_0>() { + return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_3_0; +} + +} // namespace + +namespace flash { + +static FileModuleLocal::DirEntry ConvertDirEntry(const PP_DirEntry_Dev& entry) { + FileModuleLocal::DirEntry rv = { entry.name, PP_ToBool(entry.is_dir) }; + return rv; +} + +// static +bool FileModuleLocal::IsAvailable() { + return has_interface<PPB_Flash_File_ModuleLocal_3_0>(); +} + +// static +PP_FileHandle FileModuleLocal::OpenFile(const InstanceHandle& instance, + const std::string& path, + int32_t mode) { + PP_FileHandle file_handle = PP_kInvalidFileHandle; + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle); + } + return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle; +} + +// static +bool FileModuleLocal::RenameFile(const InstanceHandle& instance, + const std::string& path_from, + const std::string& path_to) { + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str()); + } + return result == PP_OK; +} + +// static +bool FileModuleLocal::DeleteFileOrDir(const InstanceHandle& instance, + const std::string& path, + bool recursive) { + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + DeleteFileOrDir(instance.pp_instance(), path.c_str(), + PP_FromBool(recursive)); + } + return result == PP_OK; +} + +// static +bool FileModuleLocal::CreateDir(const InstanceHandle& instance, + const std::string& path) { + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + CreateDir(instance.pp_instance(), path.c_str()); + } + return result == PP_OK; +} + +// static +bool FileModuleLocal::QueryFile(const InstanceHandle& instance, + const std::string& path, + PP_FileInfo* info) { + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + QueryFile(instance.pp_instance(), path.c_str(), info); + } + return result == PP_OK; +} + +// static +bool FileModuleLocal::GetDirContents( + const InstanceHandle& instance, + const std::string& path, + std::vector<DirEntry>* dir_contents) { + dir_contents->clear(); + + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + PP_DirContents_Dev* contents = NULL; + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + GetDirContents(instance.pp_instance(), path.c_str(), &contents); + if (result == PP_OK && contents) { + for (int32_t i = 0; i < contents->count; i++) + dir_contents->push_back(ConvertDirEntry(contents->entries[i])); + } + if (contents) { + get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + FreeDirContents(instance.pp_instance(), contents); + } + } + return result == PP_OK; +} + +// static +PP_FileHandle FileModuleLocal::CreateTemporaryFile( + const InstanceHandle& instance) { + PP_FileHandle file_handle = PP_kInvalidFileHandle; + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { + result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> + CreateTemporaryFile(instance.pp_instance(), &file_handle); + } + return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle; +} + +} // namespace flash + +// FileFileRef ----------------------------------------------------------------- + +namespace { + +template <> const char* interface_name<PPB_Flash_File_FileRef>() { + return PPB_FLASH_FILE_FILEREF_INTERFACE; +} + +} // namespace + +namespace flash { + +// static +bool FileFileRef::IsAvailable() { + return has_interface<PPB_Flash_File_FileRef>(); +} + +// static +PP_FileHandle FileFileRef::OpenFile(const pp::FileRef& resource, + int32_t mode) { + PP_FileHandle file_handle = PP_kInvalidFileHandle; + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_FileRef>()) { + result = get_interface<PPB_Flash_File_FileRef>()-> + OpenFile(resource.pp_resource(), mode, &file_handle); + } + return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle; +} + +// static +bool FileFileRef::QueryFile(const pp::FileRef& resource, + PP_FileInfo* info) { + int32_t result = PP_ERROR_FAILED; + if (has_interface<PPB_Flash_File_FileRef>()) { + result = get_interface<PPB_Flash_File_FileRef>()-> + QueryFile(resource.pp_resource(), info); + } + return result == PP_OK; +} + +} // namespace flash + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_file.h b/chromium/ppapi/cpp/private/flash_file.h new file mode 100644 index 00000000000..04ab195eeb3 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_file.h @@ -0,0 +1,72 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_FILE_H_ +#define PPAPI_CPP_PRIVATE_FLASH_FILE_H_ + +#include <string> +#include <vector> + +#include "ppapi/c/private/ppb_flash_file.h" + +namespace pp { + +class FileRef; +class InstanceHandle; + +namespace flash { + +// FileModuleLocal ------------------------------------------------------------- + +class FileModuleLocal { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + // Returns |PP_kInvalidFileHandle| on error. + static PP_FileHandle OpenFile(const InstanceHandle& instance, + const std::string& path, + int32_t mode); + static bool RenameFile(const InstanceHandle& instance, + const std::string& path_from, + const std::string& path_to); + static bool DeleteFileOrDir(const InstanceHandle& instance, + const std::string& path, + bool recursive); + static bool CreateDir(const InstanceHandle& instance, + const std::string& path); + static bool QueryFile(const InstanceHandle& instance, + const std::string& path, + PP_FileInfo* info); + // Note that, unlike the C interface, no |FreeDirContents()| is needed. + struct DirEntry { + std::string name; + bool is_dir; + }; + static bool GetDirContents(const InstanceHandle& instance, + const std::string& path, + std::vector<DirEntry>* dir_contents); + + // Returns |PP_kInvalidFileHandle| on error. + static PP_FileHandle CreateTemporaryFile(const InstanceHandle& instance); +}; + +// FileFileRef ----------------------------------------------------------------- + +class FileFileRef { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + // Returns |PP_kInvalidFileHandle| on error. + static PP_FileHandle OpenFile(const pp::FileRef& resource, + int32_t mode); + static bool QueryFile(const pp::FileRef& resource, + PP_FileInfo* info); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_FILE_H_ diff --git a/chromium/ppapi/cpp/private/flash_font_file.cc b/chromium/ppapi/cpp/private/flash_font_file.cc new file mode 100644 index 00000000000..df11f57d741 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_font_file.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_font_file.h" + +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/c/private/ppb_flash_font_file.h" +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_FontFile_0_1>() { + return PPB_FLASH_FONTFILE_INTERFACE_0_1; +} + +} // namespace + +namespace flash { + +FontFile::FontFile() { +} + +FontFile::FontFile(const InstanceHandle& instance, + const PP_BrowserFont_Trusted_Description* description, + PP_PrivateFontCharset charset) { + if (has_interface<PPB_Flash_FontFile_0_1>()) { + PassRefFromConstructor(get_interface<PPB_Flash_FontFile_0_1>()->Create( + instance.pp_instance(), description, charset)); + } +} + +FontFile::~FontFile() { +} + +// static +bool FontFile::IsAvailable() { + return has_interface<PPB_Flash_FontFile_0_1>(); +} + +bool FontFile::GetFontTable(uint32_t table, + void* output, + uint32_t* output_length) { + if (has_interface<PPB_Flash_FontFile_0_1>()) { + return !!get_interface<PPB_Flash_FontFile_0_1>()-> + GetFontTable(pp_resource(), table, output, output_length); + } + return false; +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_font_file.h b/chromium/ppapi/cpp/private/flash_font_file.h new file mode 100644 index 00000000000..053fca25789 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_font_file.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_FONT_FILE_H_ +#define PPAPI_CPP_PRIVATE_FLASH_FONT_FILE_H_ + +#include "ppapi/c/private/pp_private_font_charset.h" +#include "ppapi/cpp/resource.h" + +struct PP_BrowserFont_Trusted_Description; + +namespace pp { + +class InstanceHandle; + +namespace flash { + +class FontFile : public Resource { + public: + // Default constructor for making an is_null() FontFile resource. + FontFile(); + FontFile(const InstanceHandle& instance, + const PP_BrowserFont_Trusted_Description* description, + PP_PrivateFontCharset charset); + virtual ~FontFile(); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + bool GetFontTable(uint32_t table, void* output, uint32_t* output_length); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_FONT_FILE_H_ diff --git a/chromium/ppapi/cpp/private/flash_fullscreen.cc b/chromium/ppapi/cpp/private/flash_fullscreen.cc new file mode 100644 index 00000000000..8d33b5f0f7f --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_fullscreen.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_fullscreen.h" + +#include "ppapi/c/private/ppb_flash_fullscreen.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/size.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_FlashFullscreen_0_1>() { + return PPB_FLASHFULLSCREEN_INTERFACE_0_1; +} + +template <> const char* interface_name<PPB_FlashFullscreen_1_0>() { + return PPB_FLASHFULLSCREEN_INTERFACE_1_0; +} + +} // namespace + +FlashFullscreen::FlashFullscreen(const InstanceHandle& instance) + : instance_(instance) { +} + +FlashFullscreen::~FlashFullscreen() { +} + +bool FlashFullscreen::IsFullscreen() { + if (has_interface<PPB_FlashFullscreen_1_0>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_1_0>()->IsFullscreen( + instance_.pp_instance())); + } + if (has_interface<PPB_FlashFullscreen_0_1>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_0_1>()->IsFullscreen( + instance_.pp_instance())); + } + return false; +} + +bool FlashFullscreen::SetFullscreen(bool fullscreen) { + if (has_interface<PPB_FlashFullscreen_1_0>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_1_0>()->SetFullscreen( + instance_.pp_instance(), PP_FromBool(fullscreen))); + } + if (has_interface<PPB_FlashFullscreen_0_1>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_0_1>()->SetFullscreen( + instance_.pp_instance(), PP_FromBool(fullscreen))); + } + return false; +} + +bool FlashFullscreen::GetScreenSize(Size* size) { + if (has_interface<PPB_FlashFullscreen_1_0>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_1_0>()->GetScreenSize( + instance_.pp_instance(), &size->pp_size())); + } + if (has_interface<PPB_FlashFullscreen_0_1>()) { + return PP_ToBool(get_interface<PPB_FlashFullscreen_0_1>()->GetScreenSize( + instance_.pp_instance(), &size->pp_size())); + } + return false; +} + +bool FlashFullscreen::MustRecreateContexts() { + return !get_interface<PPB_FlashFullscreen_1_0>(); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_fullscreen.h b/chromium/ppapi/cpp/private/flash_fullscreen.h new file mode 100644 index 00000000000..48e4ffd9091 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_fullscreen.h @@ -0,0 +1,32 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_FULLSCREEN_H_ +#define PPAPI_CPP_PRIVATE_FLASH_FULLSCREEN_H_ + +#include "ppapi/cpp/instance_handle.h" + +namespace pp { + +class Size; + +class FlashFullscreen { + public: + FlashFullscreen(const InstanceHandle& instance); + virtual ~FlashFullscreen(); + + // PPB_FlashFullscreen methods. + bool IsFullscreen(); + bool SetFullscreen(bool fullscreen); + bool GetScreenSize(Size* size); + + bool MustRecreateContexts(); + + private: + InstanceHandle instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_FULLSCREEN_H_ diff --git a/chromium/ppapi/cpp/private/flash_menu.cc b/chromium/ppapi/cpp/private/flash_menu.cc new file mode 100644 index 00000000000..e77021b1a5b --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_menu.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_menu.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/point.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_Menu>() { + return PPB_FLASH_MENU_INTERFACE; +} + +} // namespace + +namespace flash { + +Menu::Menu(const InstanceHandle& instance, + const struct PP_Flash_Menu* menu_data) { + if (has_interface<PPB_Flash_Menu>()) { + PassRefFromConstructor(get_interface<PPB_Flash_Menu>()->Create( + instance.pp_instance(), menu_data)); + } +} + +int32_t Menu::Show(const Point& location, + int32_t* selected_id, + const CompletionCallback& cc) { + if (!has_interface<PPB_Flash_Menu>()) + return cc.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_Flash_Menu>()->Show( + pp_resource(), + &location.pp_point(), + selected_id, + cc.pp_completion_callback()); +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_menu.h b/chromium/ppapi/cpp/private/flash_menu.h new file mode 100644 index 00000000000..a0a7499a636 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_menu.h @@ -0,0 +1,32 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_MENU_H_ +#define PPAPI_CPP_PRIVATE_FLASH_MENU_H_ + +#include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; +class Point; + +namespace flash { + +class Menu : public Resource { + public: + // TODO(viettrungluu): Write a proper C++ wrapper of |PP_Flash_Menu|. + Menu(const InstanceHandle& instance, const struct PP_Flash_Menu* menu_data); + + int32_t Show(const Point& location, + int32_t* selected_id, + const CompletionCallback& cc); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_H_ diff --git a/chromium/ppapi/cpp/private/flash_message_loop.cc b/chromium/ppapi/cpp/private/flash_message_loop.cc new file mode 100644 index 00000000000..7f254382177 --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_message_loop.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/flash_message_loop.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_flash_message_loop.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Flash_MessageLoop>() { + return PPB_FLASH_MESSAGELOOP_INTERFACE; +} + +} // namespace + +namespace flash { + +MessageLoop::MessageLoop(const InstanceHandle& instance) { + if (has_interface<PPB_Flash_MessageLoop>()) { + PassRefFromConstructor(get_interface<PPB_Flash_MessageLoop>()->Create( + instance.pp_instance())); + } +} + +MessageLoop::~MessageLoop() { +} + +// static +bool MessageLoop::IsAvailable() { + return has_interface<PPB_Flash_MessageLoop>(); +} + +int32_t MessageLoop::Run() { + if (!has_interface<PPB_Flash_MessageLoop>()) + return PP_ERROR_NOINTERFACE; + return get_interface<PPB_Flash_MessageLoop>()->Run(pp_resource()); +} + +void MessageLoop::Quit() { + if (has_interface<PPB_Flash_MessageLoop>()) + get_interface<PPB_Flash_MessageLoop>()->Quit(pp_resource()); +} + +} // namespace flash +} // namespace pp diff --git a/chromium/ppapi/cpp/private/flash_message_loop.h b/chromium/ppapi/cpp/private/flash_message_loop.h new file mode 100644 index 00000000000..fecb2d6b42d --- /dev/null +++ b/chromium/ppapi/cpp/private/flash_message_loop.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_FLASH_MESSAGE_LOOP_H_ +#define PPAPI_CPP_PRIVATE_FLASH_MESSAGE_LOOP_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class InstanceHandle; + +namespace flash { + +class MessageLoop : public Resource { + public: + explicit MessageLoop(const InstanceHandle& instance); + virtual ~MessageLoop(); + + static bool IsAvailable(); + + int32_t Run(); + void Quit(); +}; + +} // namespace flash +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_FLASH_MESSAGE_LOOP_H_ diff --git a/chromium/ppapi/cpp/private/host_resolver_private.cc b/chromium/ppapi/cpp/private/host_resolver_private.cc new file mode 100644 index 00000000000..92a344eda7e --- /dev/null +++ b/chromium/ppapi/cpp/private/host_resolver_private.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/host_resolver_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/pass_ref.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_HostResolver_Private_0_1>() { + return PPB_HOSTRESOLVER_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +HostResolverPrivate::HostResolverPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_HostResolver_Private_0_1>()) { + PassRefFromConstructor( + get_interface<PPB_HostResolver_Private_0_1>()->Create( + instance.pp_instance())); + } +} + +// static +bool HostResolverPrivate::IsAvailable() { + return has_interface<PPB_HostResolver_Private_0_1>(); +} + +int32_t HostResolverPrivate::Resolve(const std::string& host, + uint16_t port, + const PP_HostResolver_Private_Hint& hint, + const CompletionCallback& callback) { + if (!has_interface<PPB_HostResolver_Private_0_1>()) + return callback.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_HostResolver_Private_0_1>()->Resolve( + pp_resource(), + host.c_str(), + port, + &hint, + callback.pp_completion_callback()); +} + +Var HostResolverPrivate::GetCanonicalName() { + if (!has_interface<PPB_HostResolver_Private_0_1>()) + return Var(Var::Null()); + + PP_Var pp_canonical_name = + get_interface<PPB_HostResolver_Private_0_1>()->GetCanonicalName( + pp_resource()); + return Var(PASS_REF, pp_canonical_name); +} + +uint32_t HostResolverPrivate::GetSize() { + if (!has_interface<PPB_HostResolver_Private_0_1>()) + return 0; + return get_interface<PPB_HostResolver_Private_0_1>()->GetSize(pp_resource()); +} + +bool HostResolverPrivate::GetNetAddress(uint32_t index, + PP_NetAddress_Private* address) { + if (!has_interface<PPB_HostResolver_Private_0_1>()) + return false; + PP_Bool result = get_interface<PPB_HostResolver_Private_0_1>()->GetNetAddress( + pp_resource(), index, address); + return PP_ToBool(result); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/host_resolver_private.h b/chromium/ppapi/cpp/private/host_resolver_private.h new file mode 100644 index 00000000000..2e4b08e6b4f --- /dev/null +++ b/chromium/ppapi/cpp/private/host_resolver_private.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_HOST_RESOLVER_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_HOST_RESOLVER_PRIVATE_H_ + +#include <string> + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_host_resolver_private.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +struct PP_NetAddress_Private; + +namespace pp { + +class CompletionCallback; +class InstanceHandle; + +class HostResolverPrivate : public Resource { + public: + explicit HostResolverPrivate(const InstanceHandle& instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Resolve(const std::string& host, + uint16_t port, + const PP_HostResolver_Private_Hint& hint, + const CompletionCallback& callback); + Var GetCanonicalName(); + uint32_t GetSize(); + bool GetNetAddress(uint32_t index, PP_NetAddress_Private* address); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_HOST_RESOLVER_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/instance_private.cc b/chromium/ppapi/cpp/private/instance_private.cc new file mode 100644 index 00000000000..c55408a28cb --- /dev/null +++ b/chromium/ppapi/cpp/private/instance_private.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/instance_private.h" + +#include "ppapi/c/private/ppb_instance_private.h" +#include "ppapi/c/private/ppp_instance_private.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/private/var_private.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Instance_Private>() { + return PPB_INSTANCE_PRIVATE_INTERFACE; +} + +PP_Var GetInstanceObject(PP_Instance pp_instance) { + Module* module_singleton = Module::Get(); + if (!module_singleton) + return Var().Detach(); + InstancePrivate* instance_private = static_cast<InstancePrivate*>( + module_singleton->InstanceForPPInstance(pp_instance)); + if (!instance_private) + return Var().Detach(); + return instance_private->GetInstanceObject().Detach(); +} + +const PPP_Instance_Private ppp_instance_private = { + &GetInstanceObject +}; + +} // namespace + +InstancePrivate::InstancePrivate(PP_Instance instance) : Instance(instance) { + // If at least 1 InstancePrivate is created, register the PPP_INSTANCE_PRIVATE + // interface. + Module::Get()->AddPluginInterface(PPP_INSTANCE_PRIVATE_INTERFACE, + &ppp_instance_private); +} + +InstancePrivate::~InstancePrivate() {} + +Var InstancePrivate::GetInstanceObject() { + return Var(); +} + +VarPrivate InstancePrivate::GetWindowObject() { + if (!has_interface<PPB_Instance_Private>()) + return VarPrivate(); + return VarPrivate(PASS_REF, + get_interface<PPB_Instance_Private>()->GetWindowObject(pp_instance())); +} + +VarPrivate InstancePrivate::GetOwnerElementObject() { + if (!has_interface<PPB_Instance_Private>()) + return VarPrivate(); + return VarPrivate(PASS_REF, + get_interface<PPB_Instance_Private>()->GetOwnerElementObject( + pp_instance())); +} + +VarPrivate InstancePrivate::ExecuteScript(const Var& script, Var* exception) { + if (!has_interface<PPB_Instance_Private>()) + return VarPrivate(); + return VarPrivate(PASS_REF, + get_interface<PPB_Instance_Private>()->ExecuteScript( + pp_instance(), + script.pp_var(), + VarPrivate::OutException(exception).get())); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/instance_private.h b/chromium/ppapi/cpp/private/instance_private.h new file mode 100644 index 00000000000..58254698995 --- /dev/null +++ b/chromium/ppapi/cpp/private/instance_private.h @@ -0,0 +1,59 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ + +/** + * @file + * Defines the API ... + * + * @addtogroup CPP + * @{ + */ + +#include "ppapi/c/ppb_console.h" +#include "ppapi/cpp/instance.h" + +/** The C++ interface to the Pepper API. */ +namespace pp { + +class Var; +class VarPrivate; + +class InstancePrivate : public Instance { + public: + explicit InstancePrivate(PP_Instance instance); + virtual ~InstancePrivate(); + + // @{ + /// @name PPP_Instance_Private methods for the plugin to override: + + /// See PPP_Instance_Private.GetInstanceObject. + virtual Var GetInstanceObject(); + + // @} + + // @{ + /// @name PPB_Instance_Private methods for querying the browser: + + /// See PPB_Instance_Private.GetWindowObject. + VarPrivate GetWindowObject(); + + /// See PPB_Instance_Private.GetOwnerElementObject. + VarPrivate GetOwnerElementObject(); + + /// See PPB_Instance.ExecuteScript. + VarPrivate ExecuteScript(const Var& script, Var* exception = NULL); + + // @} +}; + +} // namespace pp + +/** + * @} + * End addtogroup CPP + */ +#endif // PPAPI_CPP_PRIVATE_INSTANCE_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/net_address_private.cc b/chromium/ppapi/cpp/private/net_address_private.cc new file mode 100644 index 00000000000..3a32827639a --- /dev/null +++ b/chromium/ppapi/cpp/private/net_address_private.cc @@ -0,0 +1,218 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/net_address_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_NetAddress_Private_1_1>() { + return PPB_NETADDRESS_PRIVATE_INTERFACE_1_1; +} + +template <> const char* interface_name<PPB_NetAddress_Private_1_0>() { + return PPB_NETADDRESS_PRIVATE_INTERFACE_1_0; +} + +template <> const char* interface_name<PPB_NetAddress_Private_0_1>() { + return PPB_NETADDRESS_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +// static +bool NetAddressPrivate::IsAvailable() { + return has_interface<PPB_NetAddress_Private_1_1>() || + has_interface<PPB_NetAddress_Private_1_0>() || + has_interface<PPB_NetAddress_Private_0_1>(); +} + +// static +bool NetAddressPrivate::AreEqual(const PP_NetAddress_Private& addr1, + const PP_NetAddress_Private& addr2) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + return !!get_interface<PPB_NetAddress_Private_1_1>()->AreEqual(&addr1, + &addr2); + } + if (has_interface<PPB_NetAddress_Private_1_0>()) { + return !!get_interface<PPB_NetAddress_Private_1_0>()->AreEqual(&addr1, + &addr2); + } + if (has_interface<PPB_NetAddress_Private_0_1>()) { + return !!get_interface<PPB_NetAddress_Private_0_1>()->AreEqual(&addr1, + &addr2); + } + return false; +} + +// static +bool NetAddressPrivate::AreHostsEqual(const PP_NetAddress_Private& addr1, + const PP_NetAddress_Private& addr2) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + return !!get_interface<PPB_NetAddress_Private_1_1>()->AreHostsEqual(&addr1, + &addr2); + } + if (has_interface<PPB_NetAddress_Private_1_0>()) { + return !!get_interface<PPB_NetAddress_Private_1_0>()->AreHostsEqual(&addr1, + &addr2); + } + if (has_interface<PPB_NetAddress_Private_0_1>()) { + return !!get_interface<PPB_NetAddress_Private_0_1>()->AreHostsEqual(&addr1, + &addr2); + } + return false; +} + +// static +std::string NetAddressPrivate::Describe(const PP_NetAddress_Private& addr, + bool include_port) { + Module* module = Module::Get(); + if (!module) + return std::string(); + + PP_Var result_pp_var = PP_MakeUndefined(); + if (has_interface<PPB_NetAddress_Private_1_1>()) { + result_pp_var = get_interface<PPB_NetAddress_Private_1_1>()->Describe( + module->pp_module(), + &addr, + PP_FromBool(include_port)); + } else if (has_interface<PPB_NetAddress_Private_1_0>()) { + result_pp_var = get_interface<PPB_NetAddress_Private_1_0>()->Describe( + module->pp_module(), + &addr, + PP_FromBool(include_port)); + } else if (has_interface<PPB_NetAddress_Private_0_1>()) { + result_pp_var = get_interface<PPB_NetAddress_Private_0_1>()->Describe( + module->pp_module(), + &addr, + PP_FromBool(include_port)); + } + + Var result(PASS_REF, result_pp_var); + return result.is_string() ? result.AsString() : std::string(); +} + +// static +bool NetAddressPrivate::ReplacePort(const PP_NetAddress_Private& addr_in, + uint16_t port, + PP_NetAddress_Private* addr_out) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + return !!get_interface<PPB_NetAddress_Private_1_1>()->ReplacePort(&addr_in, + port, + addr_out); + } + if (has_interface<PPB_NetAddress_Private_1_0>()) { + return !!get_interface<PPB_NetAddress_Private_1_0>()->ReplacePort(&addr_in, + port, + addr_out); + } + if (has_interface<PPB_NetAddress_Private_0_1>()) { + return !!get_interface<PPB_NetAddress_Private_0_1>()->ReplacePort(&addr_in, + port, + addr_out); + } + return false; +} + +// static +bool NetAddressPrivate::GetAnyAddress(bool is_ipv6, + PP_NetAddress_Private* addr) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + get_interface<PPB_NetAddress_Private_1_1>()->GetAnyAddress( + PP_FromBool(is_ipv6), + addr); + return true; + } else if (has_interface<PPB_NetAddress_Private_1_0>()) { + get_interface<PPB_NetAddress_Private_1_0>()->GetAnyAddress( + PP_FromBool(is_ipv6), + addr); + return true; + } else if (has_interface<PPB_NetAddress_Private_0_1>()) { + get_interface<PPB_NetAddress_Private_0_1>()->GetAnyAddress( + PP_FromBool(is_ipv6), + addr); + return true; + } + return false; +} + +// static +PP_NetAddressFamily_Private NetAddressPrivate::GetFamily( + const PP_NetAddress_Private& addr) { + if (has_interface<PPB_NetAddress_Private_1_1>()) + return get_interface<PPB_NetAddress_Private_1_1>()->GetFamily(&addr); + if (has_interface<PPB_NetAddress_Private_1_0>()) + return get_interface<PPB_NetAddress_Private_1_0>()->GetFamily(&addr); + return PP_NETADDRESSFAMILY_PRIVATE_UNSPECIFIED; +} + +// static +uint16_t NetAddressPrivate::GetPort(const PP_NetAddress_Private& addr) { + if (has_interface<PPB_NetAddress_Private_1_1>()) + return get_interface<PPB_NetAddress_Private_1_1>()->GetPort(&addr); + if (has_interface<PPB_NetAddress_Private_1_0>()) + return get_interface<PPB_NetAddress_Private_1_0>()->GetPort(&addr); + return 0; +} + +// static +bool NetAddressPrivate::GetAddress(const PP_NetAddress_Private& addr, + void* address, + uint16_t address_size) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + return PP_ToBool(get_interface<PPB_NetAddress_Private_1_1>()->GetAddress( + &addr, + address, + address_size)); + } + if (has_interface<PPB_NetAddress_Private_1_0>()) { + return PP_ToBool(get_interface<PPB_NetAddress_Private_1_0>()->GetAddress( + &addr, + address, + address_size)); + } + return false; +} + +// static +uint32_t NetAddressPrivate::GetScopeID(const PP_NetAddress_Private& addr) { + if (has_interface<PPB_NetAddress_Private_1_1>()) + return get_interface<PPB_NetAddress_Private_1_1>()->GetScopeID(&addr); + return 0; +} + +// static +bool NetAddressPrivate::CreateFromIPv4Address( + const uint8_t ip[4], + uint16_t port, + struct PP_NetAddress_Private* addr_out) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + get_interface<PPB_NetAddress_Private_1_1>()->CreateFromIPv4Address( + ip, port, addr_out); + return true; + } + return false; +} + +// static +bool NetAddressPrivate::CreateFromIPv6Address( + const uint8_t ip[16], + uint32_t scope_id, + uint16_t port, + struct PP_NetAddress_Private* addr_out) { + if (has_interface<PPB_NetAddress_Private_1_1>()) { + get_interface<PPB_NetAddress_Private_1_1>()->CreateFromIPv6Address( + ip, scope_id, port, addr_out); + return true; + } + return false; +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/net_address_private.h b/chromium/ppapi/cpp/private/net_address_private.h new file mode 100644 index 00000000000..5ad50d736e8 --- /dev/null +++ b/chromium/ppapi/cpp/private/net_address_private.h @@ -0,0 +1,48 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_NET_ADDRESS_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_NET_ADDRESS_PRIVATE_H_ + +#include <string> + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_net_address_private.h" + +namespace pp { + +class NetAddressPrivate { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + static bool AreEqual(const PP_NetAddress_Private& addr1, + const PP_NetAddress_Private& addr2); + static bool AreHostsEqual(const PP_NetAddress_Private& addr1, + const PP_NetAddress_Private& addr2); + static std::string Describe(const PP_NetAddress_Private& addr, + bool include_port); + static bool ReplacePort(const PP_NetAddress_Private& addr_in, + uint16_t port, + PP_NetAddress_Private* addr_out); + static bool GetAnyAddress(bool is_ipv6, PP_NetAddress_Private* addr); + static PP_NetAddressFamily_Private GetFamily( + const PP_NetAddress_Private& addr); + static uint16_t GetPort(const PP_NetAddress_Private& addr); + static bool GetAddress(const PP_NetAddress_Private& addr, + void* address, + uint16_t address_size); + static uint32_t GetScopeID(const PP_NetAddress_Private& addr); + static bool CreateFromIPv4Address(const uint8_t ip[4], + uint16_t port, + struct PP_NetAddress_Private* addr_out); + static bool CreateFromIPv6Address(const uint8_t ip[16], + uint32_t scope_id, + uint16_t port, + struct PP_NetAddress_Private* addr_out); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_NET_ADDRESS_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/network_list_private.cc b/chromium/ppapi/cpp/private/network_list_private.cc new file mode 100644 index 00000000000..1297aa3a09c --- /dev/null +++ b/chromium/ppapi/cpp/private/network_list_private.cc @@ -0,0 +1,110 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/network_list_private.h" + +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_NetworkList_Private>() { + return PPB_NETWORKLIST_PRIVATE_INTERFACE; +} + +} // namespace + +NetworkListPrivate::NetworkListPrivate() { +} + +NetworkListPrivate::NetworkListPrivate(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +// static +bool NetworkListPrivate::IsAvailable() { + return has_interface<PPB_NetworkList_Private>(); +} + +uint32_t NetworkListPrivate::GetCount() const { + if (!has_interface<PPB_NetworkList_Private>()) + return 0; + return get_interface<PPB_NetworkList_Private>()->GetCount(pp_resource()); +} + +std::string NetworkListPrivate::GetName(uint32_t index) const { + if (!has_interface<PPB_NetworkList_Private>()) + return std::string(); + Var result(PASS_REF, + get_interface<PPB_NetworkList_Private>()->GetName( + pp_resource(), index)); + return result.is_string() ? result.AsString() : std::string(); +} + +PP_NetworkListType_Private NetworkListPrivate::GetType(uint32_t index) const { + if (!has_interface<PPB_NetworkList_Private>()) + return PP_NETWORKLIST_ETHERNET; + return get_interface<PPB_NetworkList_Private>()->GetType( + pp_resource(), index); +} + +PP_NetworkListState_Private NetworkListPrivate::GetState(uint32_t index) const { + if (!has_interface<PPB_NetworkList_Private>()) + return PP_NETWORKLIST_DOWN; + return get_interface<PPB_NetworkList_Private>()->GetState( + pp_resource(), index); +} + +void NetworkListPrivate::GetIpAddresses( + uint32_t index, + std::vector<PP_NetAddress_Private>* addresses) const { + if (!has_interface<PPB_NetworkList_Private>()) + return; + + // Most network interfaces don't have more than 3 network + // interfaces. + addresses->resize(3); + + int32_t result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( + pp_resource(), index, &addresses->front(), addresses->size()); + + if (result < 0) { + addresses->resize(0); + return; + } + + if (result <= static_cast<int32_t>(addresses->size())) { + addresses->resize(result); + return; + } + + addresses->resize(result); + result = get_interface<PPB_NetworkList_Private>()->GetIpAddresses( + pp_resource(), index, &addresses->front(), addresses->size()); + if (result < 0) { + addresses->resize(0); + } else if (result < static_cast<int32_t>(addresses->size())) { + addresses->resize(result); + } +} + +std::string NetworkListPrivate::GetDisplayName(uint32_t index) const { + if (!has_interface<PPB_NetworkList_Private>()) + return std::string(); + Var result(PASS_REF, + get_interface<PPB_NetworkList_Private>()->GetDisplayName( + pp_resource(), index)); + return result.is_string() ? result.AsString() : std::string(); +} + +uint32_t NetworkListPrivate::GetMTU(uint32_t index) const { + if (!has_interface<PPB_NetworkList_Private>()) + return 0; + return get_interface<PPB_NetworkList_Private>()->GetMTU( + pp_resource(), index); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/network_list_private.h b/chromium/ppapi/cpp/private/network_list_private.h new file mode 100644 index 00000000000..31cd9b598b8 --- /dev/null +++ b/chromium/ppapi/cpp/private/network_list_private.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_NETWORK_LIST_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_NETWORK_LIST_PRIVATE_H_ + +#include <string> +#include <vector> + +#include "ppapi/c/private/ppb_network_list_private.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class NetworkListPrivate : public Resource { + public: + NetworkListPrivate(); + NetworkListPrivate(PassRef, PP_Resource resource); + + /// Returns true if the required interface is available. + static bool IsAvailable(); + + /// @return Returns the number of available network interfaces or 0 + /// if the list has never been updated. + uint32_t GetCount() const; + + /// @return Returns the name for the network interface with the + /// specified <code>index</code>. + std::string GetName(uint32_t index) const; + + /// @return Returns the type of the network interface with the + /// specified <code>index</code>. + PP_NetworkListType_Private GetType(uint32_t index) const; + + /// @return Returns the current state of the network interface with + /// the specified <code>index</code>. + PP_NetworkListState_Private GetState(uint32_t index) const; + + /// Gets the list of IP addresses for the network interface with the + /// specified <code>index</code> and stores them in + /// <code>addresses</code>. + void GetIpAddresses(uint32_t index, + std::vector<PP_NetAddress_Private>* addresses) const; + + /// @return Returns the display name for the network interface with + /// the specified <code>index</code>. + std::string GetDisplayName(uint32_t index) const; + + /// @return Returns the MTU for the network interface with the + /// specified <code>index</code>. + uint32_t GetMTU(uint32_t index) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_NETWORK_LIST_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/network_monitor_private.cc b/chromium/ppapi/cpp/private/network_monitor_private.cc new file mode 100644 index 00000000000..2f931ea4288 --- /dev/null +++ b/chromium/ppapi/cpp/private/network_monitor_private.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/network_monitor_private.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_NetworkMonitor_Private>() { + return PPB_NETWORKMONITOR_PRIVATE_INTERFACE; +} + +} // namespace + +NetworkMonitorPrivate::NetworkMonitorPrivate( + const InstanceHandle& instance, + PPB_NetworkMonitor_Callback callback, + void* user_data) { + if (has_interface<PPB_NetworkMonitor_Private>()) { + PassRefFromConstructor(get_interface<PPB_NetworkMonitor_Private>()->Create( + instance.pp_instance(), callback, user_data)); + } +} + +// static +bool NetworkMonitorPrivate::IsAvailable() { + return has_interface<PPB_NetworkMonitor_Private>(); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/network_monitor_private.h b/chromium/ppapi/cpp/private/network_monitor_private.h new file mode 100644 index 00000000000..693bbcdc7fb --- /dev/null +++ b/chromium/ppapi/cpp/private/network_monitor_private.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_NETWORK_MONITOR_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_NETWORK_MONITOR_PRIVATE_H_ + +#include "ppapi/c/private/ppb_network_monitor_private.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/instance_handle.h" + +namespace pp { + +class Instance; + +class NetworkMonitorPrivate : public Resource { + public: + NetworkMonitorPrivate(const InstanceHandle& instance, + PPB_NetworkMonitor_Callback callback, + void* user_data); + + // Returns true if the required interface is available. + static bool IsAvailable(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_NETWORK_MONITOR_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/pass_file_handle.cc b/chromium/ppapi/cpp/private/pass_file_handle.cc new file mode 100644 index 00000000000..5735d33a71f --- /dev/null +++ b/chromium/ppapi/cpp/private/pass_file_handle.cc @@ -0,0 +1,48 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/pass_file_handle.h" + +#ifdef _WIN32 +# include <windows.h> +#else +# include <unistd.h> +#endif + +namespace pp { + +PassFileHandle::PassFileHandle() + : handle_(PP_kInvalidFileHandle) { +} + +PassFileHandle::PassFileHandle(PP_FileHandle handle) + : handle_(handle) { +} + +PassFileHandle::PassFileHandle(PassFileHandle& handle) + : handle_(handle.Release()) { +} + +PassFileHandle::~PassFileHandle() { + Close(); +} + +PP_FileHandle PassFileHandle::Release() { + PP_FileHandle released = handle_; + handle_ = PP_kInvalidFileHandle; + return released; +} + +void PassFileHandle::Close() { + if (handle_ != PP_kInvalidFileHandle) { +#ifdef _WIN32 + CloseHandle(handle_); +#else + close(handle_); +#endif + handle_ = PP_kInvalidFileHandle; + } +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/pass_file_handle.h b/chromium/ppapi/cpp/private/pass_file_handle.h new file mode 100644 index 00000000000..c25353b4838 --- /dev/null +++ b/chromium/ppapi/cpp/private/pass_file_handle.h @@ -0,0 +1,81 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_PASS_FILE_HANDLE_H_ +#define PPAPI_CPP_PRIVATE_PASS_FILE_HANDLE_H_ + +#include <string.h> + +#include "ppapi/c/private/pp_file_handle.h" +#include "ppapi/cpp/output_traits.h" + +namespace pp { + +// A wrapper class for PP_FileHandle to make sure a file handle is +// closed. This object takes the ownership of the file handle when it +// is constructed. This loses the ownership when this object is +// assigned to another object, just like auto_ptr. +class PassFileHandle { + public: + PassFileHandle(); + // This constructor takes the ownership of |handle|. + explicit PassFileHandle(PP_FileHandle handle); + // Moves the ownership of |handle| to this object. + PassFileHandle(PassFileHandle& handle); + ~PassFileHandle(); + + // Releases |handle_|. The caller must close the file handle returned. + PP_FileHandle Release(); + + private: + // PassFileHandleRef allows users to return PassFileHandle as a + // value. This technique is also used by auto_ptr_ref. + struct PassFileHandleRef { + PP_FileHandle handle; + explicit PassFileHandleRef(PP_FileHandle h) + : handle(h) { + } + }; + + public: + PassFileHandle(PassFileHandleRef ref) + : handle_(ref.handle) { + } + + operator PassFileHandleRef() { + return PassFileHandleRef(Release()); + } + + private: + void operator=(const PassFileHandle&); + + void Close(); + + PP_FileHandle handle_; +}; + +namespace internal { + +template<> +struct CallbackOutputTraits<PassFileHandle> { + typedef PP_FileHandle* APIArgType; + typedef PP_FileHandle StorageType; + + static inline APIArgType StorageToAPIArg(StorageType& t) { + return &t; + } + + static inline PassFileHandle StorageToPluginArg(StorageType& t) { + return PassFileHandle(t); + } + + static inline void Initialize(StorageType* t) { + memset(t, 0, sizeof(*t)); + } +}; + +} // namespace internal +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_PASS_FILE_HANDLE_H_ diff --git a/chromium/ppapi/cpp/private/pdf.cc b/chromium/ppapi/cpp/private/pdf.cc new file mode 100644 index 00000000000..753613c18a3 --- /dev/null +++ b/chromium/ppapi/cpp/private/pdf.cc @@ -0,0 +1,187 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/pdf.h" + +#include "ppapi/c/trusted/ppb_browser_font_trusted.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_PDF>() { + return PPB_PDF_INTERFACE; +} + +} // namespace + +// static +bool PDF::IsAvailable() { + return has_interface<PPB_PDF>(); +} + +// static +Var PDF::GetLocalizedString(const InstanceHandle& instance, + PP_ResourceString string_id) { + if (has_interface<PPB_PDF>()) { + return Var(PASS_REF, + get_interface<PPB_PDF>()->GetLocalizedString( + instance.pp_instance(), string_id)); + } + return Var(); +} + +// static +ImageData PDF::GetResourceImage(const InstanceHandle& instance, + PP_ResourceImage image_id) { + if (has_interface<PPB_PDF>()) { + return ImageData(PASS_REF, + get_interface<PPB_PDF>()->GetResourceImage( + instance.pp_instance(), image_id)); + } + return ImageData(); +} + +// static +PP_Resource PDF::GetFontFileWithFallback( + const InstanceHandle& instance, + const PP_FontDescription_Dev* description, + PP_PrivateFontCharset charset) { + if (has_interface<PPB_PDF>()) { + PP_BrowserFont_Trusted_Description converted_desc; + converted_desc.face = description->face; + converted_desc.family = static_cast<PP_BrowserFont_Trusted_Family>( + description->family); + converted_desc.size = description->size; + converted_desc.weight = static_cast<PP_BrowserFont_Trusted_Weight>( + description->weight); + converted_desc.italic = description->italic; + converted_desc.small_caps = description->small_caps; + converted_desc.letter_spacing = description->letter_spacing; + converted_desc.word_spacing = description->word_spacing; + return get_interface<PPB_PDF>()->GetFontFileWithFallback( + instance.pp_instance(), &converted_desc, charset); + } + return 0; +} + +// static +PP_Resource PDF::GetFontFileWithFallback( + const InstanceHandle& instance, + const PP_BrowserFont_Trusted_Description* description, + PP_PrivateFontCharset charset) { + if (has_interface<PPB_PDF>()) { + return get_interface<PPB_PDF>()->GetFontFileWithFallback( + instance.pp_instance(), description, charset); + } + return 0; +} + +// static +bool PDF::GetFontTableForPrivateFontFile(PP_Resource font_file, + uint32_t table, + void* output, + uint32_t* output_length) { + if (has_interface<PPB_PDF>()) { + return get_interface<PPB_PDF>()->GetFontTableForPrivateFontFile(font_file, + table, output, output_length); + } + return false; +} + +// static +void PDF::SearchString(const InstanceHandle& instance, + const unsigned short* string, + const unsigned short* term, + bool case_sensitive, + PP_PrivateFindResult** results, + int* count) { + if (has_interface<PPB_PDF>()) { + get_interface<PPB_PDF>()->SearchString(instance.pp_instance(), string, + term, case_sensitive, results, count); + } +} + +// static +void PDF::DidStartLoading(const InstanceHandle& instance) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->DidStartLoading(instance.pp_instance()); +} + +// static +void PDF::DidStopLoading(const InstanceHandle& instance) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->DidStopLoading(instance.pp_instance()); +} + +// static +void PDF::SetContentRestriction(const InstanceHandle& instance, + int restrictions) { + if (has_interface<PPB_PDF>()) { + get_interface<PPB_PDF>()->SetContentRestriction(instance.pp_instance(), + restrictions); + } +} + +// static +void PDF::HistogramPDFPageCount(const InstanceHandle& instance, + int count) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->HistogramPDFPageCount(instance.pp_instance(), + count); +} + +// static +void PDF::UserMetricsRecordAction(const InstanceHandle& instance, + const Var& action) { + if (has_interface<PPB_PDF>()) { + get_interface<PPB_PDF>()->UserMetricsRecordAction(instance.pp_instance(), + action.pp_var()); + } +} + +// static +void PDF::HasUnsupportedFeature(const InstanceHandle& instance) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->HasUnsupportedFeature(instance.pp_instance()); +} + +// static +void PDF::SaveAs(const InstanceHandle& instance) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->SaveAs(instance.pp_instance()); +} + +// static +void PDF::Print(const InstanceHandle& instance) { + if (has_interface<PPB_PDF>()) + get_interface<PPB_PDF>()->Print(instance.pp_instance()); +} + +// static +bool PDF::IsFeatureEnabled(const InstanceHandle& instance, + PP_PDFFeature feature) { + if (has_interface<PPB_PDF>()) + return PP_ToBool(get_interface<PPB_PDF>()->IsFeatureEnabled( + instance.pp_instance(), feature)); + return false; +} + +// static +ImageData PDF::GetResourceImageForScale(const InstanceHandle& instance, + PP_ResourceImage image_id, + float scale) { + if (has_interface<PPB_PDF>()) { + return ImageData(PASS_REF, + get_interface<PPB_PDF>()->GetResourceImageForScale( + instance.pp_instance(), image_id, scale)); + } + return ImageData(); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/pdf.h b/chromium/ppapi/cpp/private/pdf.h new file mode 100644 index 00000000000..893f9e3f279 --- /dev/null +++ b/chromium/ppapi/cpp/private/pdf.h @@ -0,0 +1,69 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_PDF_H_ +#define PPAPI_CPP_PRIVATE_PDF_H_ + +#include <string> + +#include "ppapi/c/private/ppb_pdf.h" + +struct PP_BrowserFont_Trusted_Description; + +namespace pp { + +class ImageData; +class InstanceHandle; +class Var; + +class PDF { + public: + // Returns true if the required interface is available. + static bool IsAvailable(); + + static Var GetLocalizedString(const InstanceHandle& instance, + PP_ResourceString string_id); + static ImageData GetResourceImage(const InstanceHandle& instance, + PP_ResourceImage image_id); + // TODO(raymes): Remove this version when the PDF code is changed to use + // PP_BrowserFont_Trusted_Description. + static PP_Resource GetFontFileWithFallback( + const InstanceHandle& instance, + const PP_FontDescription_Dev* description, + PP_PrivateFontCharset charset); + static PP_Resource GetFontFileWithFallback( + const InstanceHandle& instance, + const PP_BrowserFont_Trusted_Description* description, + PP_PrivateFontCharset charset); + static bool GetFontTableForPrivateFontFile(PP_Resource font_file, + uint32_t table, + void* output, + uint32_t* output_length); + static void SearchString(const InstanceHandle& instance, + const unsigned short* string, + const unsigned short* term, + bool case_sensitive, + PP_PrivateFindResult** results, + int* count); + static void DidStartLoading(const InstanceHandle& instance); + static void DidStopLoading(const InstanceHandle& instance); + static void SetContentRestriction(const InstanceHandle& instance, + int restrictions); + static void HistogramPDFPageCount(const InstanceHandle& instance, + int count); + static void UserMetricsRecordAction(const InstanceHandle& instance, + const Var& action); + static void HasUnsupportedFeature(const InstanceHandle& instance); + static void SaveAs(const InstanceHandle& instance); + static void Print(const InstanceHandle& instance); + static bool IsFeatureEnabled(const InstanceHandle& instance, + PP_PDFFeature feature); + static ImageData GetResourceImageForScale(const InstanceHandle& instance, + PP_ResourceImage image_id, + float scale); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_PDF_H_ diff --git a/chromium/ppapi/cpp/private/tcp_server_socket_private.cc b/chromium/ppapi/cpp/private/tcp_server_socket_private.cc new file mode 100644 index 00000000000..50adcc126a6 --- /dev/null +++ b/chromium/ppapi/cpp/private/tcp_server_socket_private.cc @@ -0,0 +1,91 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/tcp_server_socket_private.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_TCPServerSocket_Private_0_2>() { + return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_2; +} + +template <> const char* interface_name<PPB_TCPServerSocket_Private_0_1>() { + return PPB_TCPSERVERSOCKET_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +TCPServerSocketPrivate::TCPServerSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_TCPServerSocket_Private_0_2>()) { + PassRefFromConstructor( + get_interface<PPB_TCPServerSocket_Private_0_2>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_TCPServerSocket_Private_0_1>()) { + PassRefFromConstructor( + get_interface<PPB_TCPServerSocket_Private_0_1>()->Create( + instance.pp_instance())); + } +} + +// static +bool TCPServerSocketPrivate::IsAvailable() { + return has_interface<PPB_TCPServerSocket_Private_0_2>() || + has_interface<PPB_TCPServerSocket_Private_0_1>(); +} + +int32_t TCPServerSocketPrivate::Listen(const PP_NetAddress_Private* addr, + int32_t backlog, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPServerSocket_Private_0_2>()) { + return get_interface<PPB_TCPServerSocket_Private_0_2>()->Listen( + pp_resource(), addr, backlog, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPServerSocket_Private_0_1>()) { + return get_interface<PPB_TCPServerSocket_Private_0_1>()->Listen( + pp_resource(), addr, backlog, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t TCPServerSocketPrivate::Accept(PP_Resource* tcp_socket, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPServerSocket_Private_0_2>()) { + return get_interface<PPB_TCPServerSocket_Private_0_2>()->Accept( + pp_resource(), tcp_socket, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPServerSocket_Private_0_1>()) { + return get_interface<PPB_TCPServerSocket_Private_0_1>()->Accept( + pp_resource(), tcp_socket, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t TCPServerSocketPrivate::GetLocalAddress(PP_NetAddress_Private* addr) { + if (has_interface<PPB_TCPServerSocket_Private_0_2>()) { + return get_interface<PPB_TCPServerSocket_Private_0_2>()->GetLocalAddress( + pp_resource(), addr); + } + return PP_ERROR_NOINTERFACE; +} + +void TCPServerSocketPrivate::StopListening() { + if (has_interface<PPB_TCPServerSocket_Private_0_2>()) { + return get_interface<PPB_TCPServerSocket_Private_0_2>()->StopListening( + pp_resource()); + } + if (has_interface<PPB_TCPServerSocket_Private_0_1>()) { + return get_interface<PPB_TCPServerSocket_Private_0_1>()->StopListening( + pp_resource()); + } +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/tcp_server_socket_private.h b/chromium/ppapi/cpp/private/tcp_server_socket_private.h new file mode 100644 index 00000000000..d6a1942fc2e --- /dev/null +++ b/chromium/ppapi/cpp/private/tcp_server_socket_private.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_tcp_server_socket_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; + +class TCPServerSocketPrivate : public Resource { + public: + explicit TCPServerSocketPrivate(const InstanceHandle& instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Listen(const PP_NetAddress_Private* addr, + int32_t backlog, + const CompletionCallback& callback); + // Accepts incoming connection and stores resource of accepted + // socket into |socket|. If Accept returns PP_OK_COMPLETIONPENDING, + // the memory pointed by |socket| should stay valid until the + // |callback| is called or StopListening method is called. + int32_t Accept(PP_Resource* socket, + const CompletionCallback& callback); + int32_t GetLocalAddress(PP_NetAddress_Private* addr); + void StopListening(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_TCP_SERVER_SOCKET_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/tcp_socket_private.cc b/chromium/ppapi/cpp/private/tcp_socket_private.cc new file mode 100644 index 00000000000..996e0a0f513 --- /dev/null +++ b/chromium/ppapi/cpp/private/tcp_socket_private.cc @@ -0,0 +1,248 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/tcp_socket_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_TCPSocket_Private_0_5>() { + return PPB_TCPSOCKET_PRIVATE_INTERFACE_0_5; +} + +template <> const char* interface_name<PPB_TCPSocket_Private_0_4>() { + return PPB_TCPSOCKET_PRIVATE_INTERFACE_0_4; +} + +template <> const char* interface_name<PPB_TCPSocket_Private_0_3>() { + return PPB_TCPSOCKET_PRIVATE_INTERFACE_0_3; +} + +} // namespace + +TCPSocketPrivate::TCPSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + PassRefFromConstructor(get_interface<PPB_TCPSocket_Private_0_5>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_TCPSocket_Private_0_4>()) { + PassRefFromConstructor(get_interface<PPB_TCPSocket_Private_0_4>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_TCPSocket_Private_0_3>()) { + PassRefFromConstructor(get_interface<PPB_TCPSocket_Private_0_3>()->Create( + instance.pp_instance())); + } +} + +TCPSocketPrivate::TCPSocketPrivate(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +// static +bool TCPSocketPrivate::IsAvailable() { + return has_interface<PPB_TCPSocket_Private_0_5>() || + has_interface<PPB_TCPSocket_Private_0_4>() || + has_interface<PPB_TCPSocket_Private_0_3>(); +} + +int32_t TCPSocketPrivate::Connect(const char* host, + uint16_t port, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->Connect( + pp_resource(), host, port, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->Connect( + pp_resource(), host, port, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->Connect( + pp_resource(), host, port, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t TCPSocketPrivate::ConnectWithNetAddress( + const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->ConnectWithNetAddress( + pp_resource(), addr, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->ConnectWithNetAddress( + pp_resource(), addr, callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->ConnectWithNetAddress( + pp_resource(), addr, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +bool TCPSocketPrivate::GetLocalAddress(PP_NetAddress_Private* local_addr) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_5>()-> + GetLocalAddress(pp_resource(), local_addr); + return PP_ToBool(result); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_4>()-> + GetLocalAddress(pp_resource(), local_addr); + return PP_ToBool(result); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_3>()-> + GetLocalAddress(pp_resource(), local_addr); + return PP_ToBool(result); + } + return false; +} + +bool TCPSocketPrivate::GetRemoteAddress(PP_NetAddress_Private* remote_addr) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_5>()-> + GetRemoteAddress(pp_resource(), remote_addr); + return PP_ToBool(result); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_4>()-> + GetRemoteAddress(pp_resource(), remote_addr); + return PP_ToBool(result); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + PP_Bool result = get_interface<PPB_TCPSocket_Private_0_3>()-> + GetRemoteAddress(pp_resource(), remote_addr); + return PP_ToBool(result); + } + return false; +} + +int32_t TCPSocketPrivate::SSLHandshake(const char* server_name, + uint16_t server_port, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->SSLHandshake( + pp_resource(), server_name, server_port, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->SSLHandshake( + pp_resource(), server_name, server_port, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->SSLHandshake( + pp_resource(), server_name, server_port, + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +X509CertificatePrivate TCPSocketPrivate::GetServerCertificate() { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return X509CertificatePrivate(PASS_REF, + get_interface<PPB_TCPSocket_Private_0_5>()->GetServerCertificate( + pp_resource())); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return X509CertificatePrivate(PASS_REF, + get_interface<PPB_TCPSocket_Private_0_4>()->GetServerCertificate( + pp_resource())); + } + return X509CertificatePrivate(); +} + +bool TCPSocketPrivate::AddChainBuildingCertificate( + const X509CertificatePrivate& cert, + bool trusted) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return PP_ToBool(get_interface<PPB_TCPSocket_Private_0_5>()-> + AddChainBuildingCertificate(pp_resource(), cert.pp_resource(), + PP_FromBool(trusted))); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return PP_ToBool(get_interface<PPB_TCPSocket_Private_0_4>()-> + AddChainBuildingCertificate(pp_resource(), cert.pp_resource(), + PP_FromBool(trusted))); + } + return false; +} + +int32_t TCPSocketPrivate::Read(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->Read( + pp_resource(), buffer, bytes_to_read, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->Read( + pp_resource(), buffer, bytes_to_read, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->Read( + pp_resource(), buffer, bytes_to_read, + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t TCPSocketPrivate::Write(const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->Write( + pp_resource(), buffer, bytes_to_write, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->Write( + pp_resource(), buffer, bytes_to_write, + callback.pp_completion_callback()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->Write( + pp_resource(), buffer, bytes_to_write, + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +void TCPSocketPrivate::Disconnect() { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->Disconnect( + pp_resource()); + } + if (has_interface<PPB_TCPSocket_Private_0_4>()) { + return get_interface<PPB_TCPSocket_Private_0_4>()->Disconnect( + pp_resource()); + } + if (has_interface<PPB_TCPSocket_Private_0_3>()) { + return get_interface<PPB_TCPSocket_Private_0_3>()->Disconnect( + pp_resource()); + } +} + +int32_t TCPSocketPrivate::SetOption(PP_TCPSocketOption_Private name, + const Var& value, + const CompletionCallback& callback) { + if (has_interface<PPB_TCPSocket_Private_0_5>()) { + return get_interface<PPB_TCPSocket_Private_0_5>()->SetOption( + pp_resource(), name, value.pp_var(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/tcp_socket_private.h b/chromium/ppapi/cpp/private/tcp_socket_private.h new file mode 100644 index 00000000000..12e435e5895 --- /dev/null +++ b/chromium/ppapi/cpp/private/tcp_socket_private.h @@ -0,0 +1,56 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_TCP_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_TCP_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_tcp_socket_private.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/private/x509_certificate_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; + +class TCPSocketPrivate : public Resource { + public: + explicit TCPSocketPrivate(const InstanceHandle& instance); + + TCPSocketPrivate(PassRef, PP_Resource resource); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t Connect(const char* host, + uint16_t port, + const CompletionCallback& callback); + int32_t ConnectWithNetAddress(const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + bool GetLocalAddress(PP_NetAddress_Private* local_addr); + bool GetRemoteAddress(PP_NetAddress_Private* remote_addr); + int32_t SSLHandshake(const char* server_name, + uint16_t server_port, + const CompletionCallback& callback); + X509CertificatePrivate GetServerCertificate(); + bool AddChainBuildingCertificate(const X509CertificatePrivate& cert, + bool trusted); + + int32_t Read(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& callback); + int32_t Write(const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& callback); + void Disconnect(); + int32_t SetOption(PP_TCPSocketOption_Private name, + const Var& value, + const CompletionCallback& callback); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_TCP_SOCKET_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/udp_socket_private.cc b/chromium/ppapi/cpp/private/udp_socket_private.cc new file mode 100644 index 00000000000..c100924fc23 --- /dev/null +++ b/chromium/ppapi/cpp/private/udp_socket_private.cc @@ -0,0 +1,137 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/udp_socket_private.h" + +#include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_UDPSocket_Private_0_4>() { + return PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4; +} + +template <> const char* interface_name<PPB_UDPSocket_Private_0_3>() { + return PPB_UDPSOCKET_PRIVATE_INTERFACE_0_3; +} + +} // namespace + +UDPSocketPrivate::UDPSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + PassRefFromConstructor(get_interface<PPB_UDPSocket_Private_0_4>()->Create( + instance.pp_instance())); + } else if (has_interface<PPB_UDPSocket_Private_0_3>()) { + PassRefFromConstructor(get_interface<PPB_UDPSocket_Private_0_3>()->Create( + instance.pp_instance())); + } +} + +// static +bool UDPSocketPrivate::IsAvailable() { + return has_interface<PPB_UDPSocket_Private_0_4>() || + has_interface<PPB_UDPSocket_Private_0_3>(); +} + +int32_t UDPSocketPrivate::SetSocketFeature(PP_UDPSocketFeature_Private name, + const Var& value) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + return get_interface<PPB_UDPSocket_Private_0_4>()->SetSocketFeature( + pp_resource(), name, value.pp_var()); + } + return PP_ERROR_NOINTERFACE; +} + +int32_t UDPSocketPrivate::Bind(const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + return get_interface<PPB_UDPSocket_Private_0_4>()->Bind( + pp_resource(), addr, callback.pp_completion_callback()); + } + if (has_interface<PPB_UDPSocket_Private_0_3>()) { + return get_interface<PPB_UDPSocket_Private_0_3>()->Bind( + pp_resource(), addr, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +bool UDPSocketPrivate::GetBoundAddress(PP_NetAddress_Private* addr) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + PP_Bool result = + get_interface<PPB_UDPSocket_Private_0_4>()->GetBoundAddress( + pp_resource(), addr); + return PP_ToBool(result); + } + if (has_interface<PPB_UDPSocket_Private_0_3>()) { + PP_Bool result = + get_interface<PPB_UDPSocket_Private_0_3>()->GetBoundAddress( + pp_resource(), addr); + return PP_ToBool(result); + } + return false; +} + +int32_t UDPSocketPrivate::RecvFrom(char* buffer, + int32_t num_bytes, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + return get_interface<PPB_UDPSocket_Private_0_4>()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.pp_completion_callback()); + } + if (has_interface<PPB_UDPSocket_Private_0_3>()) { + return get_interface<PPB_UDPSocket_Private_0_3>()->RecvFrom( + pp_resource(), buffer, num_bytes, callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +bool UDPSocketPrivate::GetRecvFromAddress(PP_NetAddress_Private* addr) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + PP_Bool result = + get_interface<PPB_UDPSocket_Private_0_4>()->GetRecvFromAddress( + pp_resource(), addr); + return PP_ToBool(result); + } + if (has_interface<PPB_UDPSocket_Private_0_3>()) { + PP_Bool result = + get_interface<PPB_UDPSocket_Private_0_3>()->GetRecvFromAddress( + pp_resource(), addr); + return PP_ToBool(result); + } + return false; +} + +int32_t UDPSocketPrivate::SendTo(const char* buffer, + int32_t num_bytes, + const PP_NetAddress_Private* addr, + const CompletionCallback& callback) { + if (has_interface<PPB_UDPSocket_Private_0_4>()) { + return get_interface<PPB_UDPSocket_Private_0_4>()->SendTo( + pp_resource(), buffer, num_bytes, addr, + callback.pp_completion_callback()); + } + if (has_interface<PPB_UDPSocket_Private_0_3>()) { + return get_interface<PPB_UDPSocket_Private_0_3>()->SendTo( + pp_resource(), buffer, num_bytes, addr, + callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +void UDPSocketPrivate::Close() { + if (has_interface<PPB_UDPSocket_Private_0_4>()) + return get_interface<PPB_UDPSocket_Private_0_4>()->Close(pp_resource()); + if (has_interface<PPB_UDPSocket_Private_0_3>()) + return get_interface<PPB_UDPSocket_Private_0_3>()->Close(pp_resource()); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/udp_socket_private.h b/chromium/ppapi/cpp/private/udp_socket_private.h new file mode 100644 index 00000000000..34e06a906a0 --- /dev/null +++ b/chromium/ppapi/cpp/private/udp_socket_private.h @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_UDP_SOCKET_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_UDP_SOCKET_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_udp_socket_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class InstanceHandle; +class Var; + +class UDPSocketPrivate : public Resource { + public: + explicit UDPSocketPrivate(const InstanceHandle& instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + int32_t SetSocketFeature(PP_UDPSocketFeature_Private name, const Var& value); + int32_t Bind(const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + bool GetBoundAddress(PP_NetAddress_Private* addr); + int32_t RecvFrom(char* buffer, + int32_t num_bytes, + const CompletionCallback& callback); + bool GetRecvFromAddress(PP_NetAddress_Private* addr); + int32_t SendTo(const char* buffer, + int32_t num_bytes, + const PP_NetAddress_Private* addr, + const CompletionCallback& callback); + void Close(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_UDP_SOCKET_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/var_private.cc b/chromium/ppapi/cpp/private/var_private.cc new file mode 100644 index 00000000000..ff61226d582 --- /dev/null +++ b/chromium/ppapi/cpp/private/var_private.cc @@ -0,0 +1,190 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/var_private.h" + +#include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/private/instance_private.h" +#include "ppapi/cpp/logging.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/dev/scriptable_object_deprecated.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_Var_Deprecated>() { + return PPB_VAR_DEPRECATED_INTERFACE; +} + +} // namespace + +using namespace deprecated; + +VarPrivate::VarPrivate(const InstanceHandle& instance, + ScriptableObject* object) { + if (has_interface<PPB_Var_Deprecated>()) { + var_ = get_interface<PPB_Var_Deprecated>()->CreateObject( + instance.pp_instance(), object->GetClass(), object); + } else { + var_.type = PP_VARTYPE_NULL; + var_.padding = 0; + } + is_managed_ = true; +} + +ScriptableObject* VarPrivate::AsScriptableObject() const { + if (!is_object()) { + PP_NOTREACHED(); + } else if (has_interface<PPB_Var_Deprecated>()) { + void* object = NULL; + if (get_interface<PPB_Var_Deprecated>()->IsInstanceOf( + var_, ScriptableObject::GetClass(), &object)) { + return reinterpret_cast<ScriptableObject*>(object); + } + } + return NULL; +} + +bool VarPrivate::HasProperty(const Var& name, Var* exception) const { + if (!has_interface<PPB_Var_Deprecated>()) + return false; + return get_interface<PPB_Var_Deprecated>()->HasProperty( + var_, name.pp_var(), OutException(exception).get()); +} + +bool VarPrivate::HasMethod(const Var& name, Var* exception) const { + if (!has_interface<PPB_Var_Deprecated>()) + return false; + return get_interface<PPB_Var_Deprecated>()->HasMethod( + var_, name.pp_var(), OutException(exception).get()); +} + +VarPrivate VarPrivate::GetProperty(const Var& name, Var* exception) const { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->GetProperty( + var_, name.pp_var(), OutException(exception).get())); +} + +void VarPrivate::GetAllPropertyNames(std::vector<Var>* properties, + Var* exception) const { + if (!has_interface<PPB_Var_Deprecated>()) + return; + PP_Var* props = NULL; + uint32_t prop_count = 0; + get_interface<PPB_Var_Deprecated>()->GetAllPropertyNames( + var_, &prop_count, &props, OutException(exception).get()); + if (!prop_count) + return; + properties->resize(prop_count); + for (uint32_t i = 0; i < prop_count; ++i) { + Var temp(PassRef(), props[i]); + (*properties)[i] = temp; + } + const PPB_Memory_Dev* memory_if = static_cast<const PPB_Memory_Dev*>( + pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); + memory_if->MemFree(props); +} + +void VarPrivate::SetProperty(const Var& name, const Var& value, + Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return; + get_interface<PPB_Var_Deprecated>()->SetProperty( + var_, name.pp_var(), value.pp_var(), OutException(exception).get()); +} + +void VarPrivate::RemoveProperty(const Var& name, Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return; + get_interface<PPB_Var_Deprecated>()->RemoveProperty( + var_, name.pp_var(), OutException(exception).get()); +} + +VarPrivate VarPrivate::Call(const Var& method_name, uint32_t argc, Var* argv, + Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + if (argc > 0) { + std::vector<PP_Var> args; + args.reserve(argc); + for (size_t i = 0; i < argc; i++) + args.push_back(argv[i].pp_var()); + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), argc, &args[0], + OutException(exception).get())); + } else { + // Don't try to get the address of a vector if it's empty. + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 0, NULL, + OutException(exception).get())); + } +} + +VarPrivate VarPrivate::Construct(uint32_t argc, Var* argv, + Var* exception) const { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + if (argc > 0) { + std::vector<PP_Var> args; + args.reserve(argc); + for (size_t i = 0; i < argc; i++) + args.push_back(argv[i].pp_var()); + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( + var_, argc, &args[0], OutException(exception).get())); + } else { + // Don't try to get the address of a vector if it's empty. + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct( + var_, 0, NULL, OutException(exception).get())); + } +} + +VarPrivate VarPrivate::Call(const Var& method_name, Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 0, NULL, OutException(exception).get())); +} + +VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, + Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + PP_Var args[1] = {arg1.pp_var()}; + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 1, args, OutException(exception).get())); +} + +VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, + const Var& arg2, Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + PP_Var args[2] = {arg1.pp_var(), arg2.pp_var()}; + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 2, args, OutException(exception).get())); +} + +VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, + const Var& arg2, const Var& arg3, Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + PP_Var args[3] = {arg1.pp_var(), arg2.pp_var(), arg3.pp_var()}; + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 3, args, OutException(exception).get())); +} + +VarPrivate VarPrivate::Call(const Var& method_name, const Var& arg1, + const Var& arg2, const Var& arg3, const Var& arg4, + Var* exception) { + if (!has_interface<PPB_Var_Deprecated>()) + return Var(); + PP_Var args[4] = {arg1.pp_var(), arg2.pp_var(), arg3.pp_var(), arg4.pp_var()}; + return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call( + var_, method_name.pp_var(), 4, args, OutException(exception).get())); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/var_private.h b/chromium/ppapi/cpp/private/var_private.h new file mode 100644 index 00000000000..7cc0e31dccf --- /dev/null +++ b/chromium/ppapi/cpp/private/var_private.h @@ -0,0 +1,124 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_VAR_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_VAR_PRIVATE_H_ + +#include "ppapi/cpp/var.h" + +namespace pp { + +class InstanceHandle; + +namespace deprecated { +class ScriptableObject; +} + +// VarPrivate is a version of Var that exposes the private scripting API. +// It's designed to be mostly interchangeable with Var since most callers will +// be dealing with Vars from various places. +class VarPrivate : public Var { + public: + VarPrivate() : Var() {} + VarPrivate(Null) : Var(Null()) {} + VarPrivate(bool b) : Var(b) {} + VarPrivate(int32_t i) : Var(i) {} + VarPrivate(double d) : Var(d) {} + VarPrivate(const char* utf8_str) : Var(utf8_str) {} + VarPrivate(const std::string& utf8_str) : Var(utf8_str) {} + VarPrivate(PassRef, PP_Var var) : Var(PassRef(), var) {} + VarPrivate(DontManage, PP_Var var) : Var(DontManage(), var) {} + VarPrivate(const InstanceHandle& instance, + deprecated::ScriptableObject* object); + VarPrivate(const Var& other) : Var(other) {} + + virtual ~VarPrivate() {} + + // This assumes the object is of type object. If it's not, it will assert in + // debug mode. If it is not an object or not a ScriptableObject type, returns + // NULL. + deprecated::ScriptableObject* AsScriptableObject() const; + + bool HasProperty(const Var& name, Var* exception = NULL) const; + bool HasMethod(const Var& name, Var* exception = NULL) const; + VarPrivate GetProperty(const Var& name, Var* exception = NULL) const; + void GetAllPropertyNames(std::vector<Var>* properties, + Var* exception = NULL) const; + void SetProperty(const Var& name, const Var& value, Var* exception = NULL); + void RemoveProperty(const Var& name, Var* exception = NULL); + VarPrivate Call(const Var& method_name, uint32_t argc, Var* argv, + Var* exception = NULL); + VarPrivate Construct(uint32_t argc, Var* argv, Var* exception = NULL) const; + + // Convenience functions for calling functions with small # of args. + VarPrivate Call(const Var& method_name, Var* exception = NULL); + VarPrivate Call(const Var& method_name, const Var& arg1, + Var* exception = NULL); + VarPrivate Call(const Var& method_name, const Var& arg1, const Var& arg2, + Var* exception = NULL); + VarPrivate Call(const Var& method_name, const Var& arg1, const Var& arg2, + const Var& arg3, Var* exception = NULL); + VarPrivate Call(const Var& method_name, const Var& arg1, const Var& arg2, + const Var& arg3, const Var& arg4, Var* exception = NULL); + + // For use when calling the raw C PPAPI when using the C++ Var as a possibly + // NULL exception. This will handle getting the address of the internal value + // out if it's non-NULL and fixing up the reference count. + // + // Danger: this will only work for things with exception semantics, i.e. that + // the value will not be changed if it's a non-undefined exception. Otherwise, + // this class will mess up the refcounting. + // + // This is a bit subtle: + // - If NULL is passed, we return NULL from get() and do nothing. + // + // - If a undefined value is passed, we return the address of a undefined var + // from get and have the output value take ownership of that var. + // + // - If a non-undefined value is passed, we return the address of that var + // from get, and nothing else should change. + // + // Example: + // void FooBar(a, b, Var* exception = NULL) { + // foo_interface->Bar(a, b, VarPrivate::OutException(exception).get()); + // } + class OutException { + public: + OutException(Var* v) + : output_(v), + originally_had_exception_(v && !v->is_undefined()) { + if (output_) { + temp_ = output_->pp_var(); + } else { + temp_.padding = 0; + temp_.type = PP_VARTYPE_UNDEFINED; + } + } + ~OutException() { + if (output_ && !originally_had_exception_) + *output_ = Var(PassRef(), temp_); + } + + PP_Var* get() { + if (output_) + return &temp_; + return NULL; + } + + private: + Var* output_; + bool originally_had_exception_; + PP_Var temp_; + }; + + private: + // Prevent an arbitrary pointer argument from being implicitly converted to + // a bool at Var construction. If somebody makes such a mistake, (s)he will + // get a compilation error. + VarPrivate(void* non_scriptable_object_pointer); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_VAR_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/video_destination_private.cc b/chromium/ppapi/cpp/private/video_destination_private.cc new file mode 100644 index 00000000000..5233b5f09ee --- /dev/null +++ b/chromium/ppapi/cpp/private/video_destination_private.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/video_destination_private.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_video_destination_private.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/private/video_frame_private.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_VideoDestination_Private_0_1>() { + return PPB_VIDEODESTINATION_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +VideoDestination_Private::VideoDestination_Private() { +} + +VideoDestination_Private::VideoDestination_Private( + const InstanceHandle& instance) { + if (!has_interface<PPB_VideoDestination_Private_0_1>()) + return; + PassRefFromConstructor( + get_interface<PPB_VideoDestination_Private_0_1>()->Create( + instance.pp_instance())); +} + +VideoDestination_Private::VideoDestination_Private( + const VideoDestination_Private& other) + : Resource(other) { +} + +VideoDestination_Private::VideoDestination_Private(PassRef, + PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +int32_t VideoDestination_Private::Open(const Var& stream_url, + const CompletionCallback& cc) { + if (has_interface<PPB_VideoDestination_Private_0_1>()) { + int32_t result = + get_interface<PPB_VideoDestination_Private_0_1>()->Open( + pp_resource(), + stream_url.pp_var(), + cc.pp_completion_callback()); + return result; + } + return cc.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t VideoDestination_Private::PutFrame( + const VideoFrame_Private& frame) { + if (has_interface<PPB_VideoDestination_Private_0_1>()) { + return get_interface<PPB_VideoDestination_Private_0_1>()->PutFrame( + pp_resource(), + &frame.pp_video_frame()); + } + return PP_ERROR_NOINTERFACE; +} + +void VideoDestination_Private::Close() { + if (has_interface<PPB_VideoDestination_Private_0_1>()) { + get_interface<PPB_VideoDestination_Private_0_1>()->Close(pp_resource()); + } +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/video_destination_private.h b/chromium/ppapi/cpp/private/video_destination_private.h new file mode 100644 index 00000000000..a9364850901 --- /dev/null +++ b/chromium/ppapi/cpp/private/video_destination_private.h @@ -0,0 +1,87 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_VIDEO_DESTINATION_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_VIDEO_DESTINATION_PRIVATE_H_ + +#include <string> + +#include "ppapi/c/pp_time.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/resource.h" + +/// @file +/// This file defines the <code>PPB_VideoDestination_Private</code> interface +/// for a video destination resource, which sends video frames to a MediaStream +/// video track in the browser. + +namespace pp { + +class InstanceHandle; +class VideoFrame_Private; + +/// The <code>VideoDestination_Private</code> class contains methods for +/// creating video destination resources and using them to send video frames to +/// a MediaStream video track in the browser. +class VideoDestination_Private : public Resource { + public: + /// Default constructor for creating a <code>VideoDestination_Private</code> + /// object. + VideoDestination_Private(); + + /// Constructor for creating a <code>VideoDestination_Private</code> for an + /// instance. + explicit VideoDestination_Private(const InstanceHandle& instance); + + /// The copy constructor for <code>VideoDestination_Private</code>. + /// + /// @param[in] other A reference to a <code>VideoDestination_Private</code>. + VideoDestination_Private(const VideoDestination_Private& other); + + /// A constructor used when you have received a PP_Resource as a return + /// value that has had its reference count incremented for you. + /// + /// @param[in] resource A PP_Resource corresponding to a video destination. + VideoDestination_Private(PassRef, PP_Resource resource); + + /// Opens a video destination for putting frames. + /// + /// @param[in] stream_url A <code>Var</code> string holding a URL identifying + /// a MediaStream. + /// @param[in] callback A <code>CompletionCallback</code> to be + /// called upon completion of Open(). + /// + /// @return An int32_t containing a result code from <code>pp_errors.h</code>. + /// Returns PP_ERROR_BADRESOURCE if destination isn't a valid video + /// destination. + /// Returns PP_ERROR_INPROGRESS if destination is already open. + /// Returns PP_ERROR_FAILED if the MediaStream doesn't exist or if there is + /// some other browser error. + int32_t Open(const Var& stream_url, const CompletionCallback& cc); + + /// Puts a frame to the video destination. + /// + /// After this call, you should take care to release your references to the + /// image embedded in the video frame. If you paint to the image after + /// PutFrame(), there is the possibility of artifacts because the browser may + /// still be copying the frame to the stream. + /// + /// @param[in] frame A <code>VideoFrame_Private</code> holding the video + /// frame to send to the destination. + /// + /// @return An int32_t containing a result code from <code>pp_errors.h</code>. + /// Returns PP_ERROR_BADRESOURCE if destination isn't a valid video + /// destination. + /// Returns PP_ERROR_FAILED if destination is not open, if the video frame has + /// an invalid image data resource, or if some other browser error occurs. + int32_t PutFrame(const VideoFrame_Private& frame); + + /// Closes the video destination. + void Close(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_VIDEO_DESTINATION_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/video_frame_private.cc b/chromium/ppapi/cpp/private/video_frame_private.cc new file mode 100644 index 00000000000..9976647d5b3 --- /dev/null +++ b/chromium/ppapi/cpp/private/video_frame_private.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/video_frame_private.h" + +namespace pp { + +VideoFrame_Private::VideoFrame_Private() + : video_frame_() { + video_frame_.image_data = image_data_.pp_resource(); +} + +VideoFrame_Private::VideoFrame_Private(const ImageData& image_data, + PP_TimeTicks timestamp) + : image_data_(image_data), video_frame_() { + video_frame_.timestamp = timestamp; + video_frame_.image_data = image_data_.pp_resource(); +} + +VideoFrame_Private::VideoFrame_Private( + PassRef, + const PP_VideoFrame_Private& pp_video_frame) + : video_frame_(pp_video_frame) { + // Take over the image_data resource in the frame. + image_data_ = ImageData(PASS_REF, video_frame_.image_data); +} + +VideoFrame_Private::VideoFrame_Private(const VideoFrame_Private& other) + : video_frame_() { + set_image_data(other.image_data()); + set_timestamp(other.timestamp()); +} + +VideoFrame_Private::~VideoFrame_Private() { +} + +VideoFrame_Private& VideoFrame_Private::operator=( + const VideoFrame_Private& other) { + if (this == &other) + return *this; + + set_image_data(other.image_data()); + set_timestamp(other.timestamp()); + + return *this; +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/video_frame_private.h b/chromium/ppapi/cpp/private/video_frame_private.h new file mode 100644 index 00000000000..7413876e7d6 --- /dev/null +++ b/chromium/ppapi/cpp/private/video_frame_private.h @@ -0,0 +1,103 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_ + +#include <string.h> + +#include "ppapi/c/pp_time.h" +#include "ppapi/c/private/pp_video_frame_private.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/pass_ref.h" + +/// @file +/// This file defines the struct used to hold a video frame. + +namespace pp { + +/// The <code>PP_VideoFrame_Private</code> struct represents a video frame. +/// Video sources and destinations use frames to transfer video to and from +/// the browser. +class VideoFrame_Private { + public: + /// Default constructor for creating a <code>VideoFrame_Private</code> object. + VideoFrame_Private(); + + /// Constructor that takes an existing <code>PP_VideoFrame_Private</code> + /// structure. The 'image_data' PP_Resource field in the structure will be + /// managed by this instance. + VideoFrame_Private(PassRef, const PP_VideoFrame_Private& pp_video_frame); + + /// Constructor that takes an existing <code>ImageData</code> instance and + /// a timestamp. + VideoFrame_Private(const ImageData& image_data, PP_TimeTicks timestamp); + + /// The copy constructor for <code>VideoFrame_Private</code>. + /// + /// @param[in] other A reference to a <code>VideoFrame_Private</code>. + VideoFrame_Private(const VideoFrame_Private& other); + + ~VideoFrame_Private(); + + /// The assignment operator for <code>VideoFrame_Private</code>. + /// + /// @param[in] other A reference to a <code>VideoFrame_Private</code>. + VideoFrame_Private& operator=(const VideoFrame_Private& other); + + const PP_VideoFrame_Private& pp_video_frame() const { + return video_frame_; + } + + ImageData image_data() const { + return image_data_; + } + void set_image_data(const ImageData& image_data) { + image_data_ = image_data; + // The assignment above manages the underlying PP_Resources. Copy the new + // one into our internal video frame struct. + video_frame_.image_data = image_data_.pp_resource(); + } + + PP_TimeTicks timestamp() const { return video_frame_.timestamp; } + void set_timestamp(PP_TimeTicks timestamp) { + video_frame_.timestamp = timestamp; + } + + private: + ImageData image_data_; // This manages the PP_Resource in video_frame_. + PP_VideoFrame_Private video_frame_; +}; + +namespace internal { + +// A specialization of CallbackOutputTraits to provide the callback system the +// information on how to handle pp::VideoFrame_Private. This converts +// PP_VideoFrame_Private to pp::VideoFrame_Private when passing to the plugin, +// and specifically manages the PP_Resource embedded in the video_frame_ field. +template<> +struct CallbackOutputTraits<pp::VideoFrame_Private> { + typedef PP_VideoFrame_Private* APIArgType; + typedef PP_VideoFrame_Private StorageType; + + static inline APIArgType StorageToAPIArg(StorageType& t) { + return &t; + } + + static inline pp::VideoFrame_Private StorageToPluginArg(StorageType& t) { + return pp::VideoFrame_Private(PASS_REF, t); + } + + static inline void Initialize(StorageType* t) { + VideoFrame_Private dummy; + *t = dummy.pp_video_frame(); + } +}; + +} // namespace internal + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/video_source_private.cc b/chromium/ppapi/cpp/private/video_source_private.cc new file mode 100644 index 00000000000..264c001103c --- /dev/null +++ b/chromium/ppapi/cpp/private/video_source_private.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/video_source_private.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_video_source_private.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/private/video_frame_private.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_VideoSource_Private_0_1>() { + return PPB_VIDEOSOURCE_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +VideoSource_Private::VideoSource_Private() { +} + +VideoSource_Private::VideoSource_Private(const InstanceHandle& instance) { + if (!has_interface<PPB_VideoSource_Private_0_1>()) + return; + PassRefFromConstructor(get_interface<PPB_VideoSource_Private_0_1>()->Create( + instance.pp_instance())); +} + +VideoSource_Private::VideoSource_Private(const VideoSource_Private& other) + : Resource(other) { +} + +VideoSource_Private::VideoSource_Private(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +int32_t VideoSource_Private::Open(const Var& stream_url, + const CompletionCallback& cc) { + if (has_interface<PPB_VideoSource_Private_0_1>()) { + int32_t result = + get_interface<PPB_VideoSource_Private_0_1>()->Open( + pp_resource(), + stream_url.pp_var(), cc.pp_completion_callback()); + return result; + } + return cc.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t VideoSource_Private::GetFrame( + const CompletionCallbackWithOutput<VideoFrame_Private>& cc) { + if (has_interface<PPB_VideoSource_Private_0_1>()) { + return get_interface<PPB_VideoSource_Private_0_1>()->GetFrame( + pp_resource(), + cc.output(), cc.pp_completion_callback()); + } + return cc.MayForce(PP_ERROR_NOINTERFACE); +} + +void VideoSource_Private::Close() { + if (has_interface<PPB_VideoSource_Private_0_1>()) { + get_interface<PPB_VideoSource_Private_0_1>()->Close(pp_resource()); + } +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/video_source_private.h b/chromium/ppapi/cpp/private/video_source_private.h new file mode 100644 index 00000000000..3d919bfd9ed --- /dev/null +++ b/chromium/ppapi/cpp/private/video_source_private.h @@ -0,0 +1,84 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_VIDEO_SOURCE_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_VIDEO_SOURCE_PRIVATE_H_ + +#include <string> + +#include "ppapi/c/pp_time.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/resource.h" + +/// @file +/// This file defines the <code>PPB_VideoSource_Private</code> interface for a +/// video source resource, which receives video frames from a MediaStream video +/// track in the browser. + +namespace pp { + +class InstanceHandle; +class VideoFrame_Private; + +/// The <code>VideoSource_Private</code> class contains methods for creating +/// video source resources and using them to receive video frames from a +/// MediaStream video track in the browser. +class VideoSource_Private : public Resource { + public: + /// Default constructor for creating a <code>VideoSource_Private</code> + /// object. + VideoSource_Private(); + + /// Constructor for creating a <code>VideoSource_Private</code> for an + /// instance. + explicit VideoSource_Private(const InstanceHandle& instance); + + /// The copy constructor for <code>VideoSource_Private</code>. + /// + /// @param[in] other A reference to a <code>VideoSource_Private</code>. + VideoSource_Private(const VideoSource_Private& other); + + /// A constructor used when you have received a PP_Resource as a return + /// value that has had its reference count incremented for you. + /// + /// @param[in] resource A PP_Resource corresponding to a video source. + VideoSource_Private(PassRef, PP_Resource resource); + + /// Opens a video source for getting frames. + /// + /// @param[in] stream_url A <code>Var</code> string holding a URL identifying + /// a MediaStream. + /// @param[in] callback A <code>CompletionCallback</code> to be called upon + /// completion of Open(). + /// + /// @return An int32_t containing a result code from <code>pp_errors.h</code>. + /// Returns PP_ERROR_BADRESOURCE if source isn't a valid video source. + /// Returns PP_ERROR_INPROGRESS if source is already open. + /// Returns PP_ERROR_FAILED if the MediaStream doesn't exist or if there is + /// some other browser error. + int32_t Open(const Var& stream_url, + const CompletionCallback& cc); + + /// Gets a frame from the video source. + /// + /// @param[out] frame A <code>VideoFrame_Private</code> to hold a video + /// frame from the source. + /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be + /// called upon completion of ReceiveFrame(). + /// + /// @return An int32_t containing a result code from <code>pp_errors.h</code>. + /// Returns PP_ERROR_BADRESOURCE if source isn't a valid video source. + /// Returns PP_ERROR_FAILED if the source is not open, or if some other + /// browser error occurs. + int32_t GetFrame( + const CompletionCallbackWithOutput<VideoFrame_Private>& cc); + + /// Closes the video source. + void Close(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_VIDEO_SOURCE_PRIVATE_H_ diff --git a/chromium/ppapi/cpp/private/x509_certificate_private.cc b/chromium/ppapi/cpp/private/x509_certificate_private.cc new file mode 100644 index 00000000000..ec242b79533 --- /dev/null +++ b/chromium/ppapi/cpp/private/x509_certificate_private.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/private/x509_certificate_private.h" + +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/pass_ref.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +template <> const char* interface_name<PPB_X509Certificate_Private_0_1>() { + return PPB_X509CERTIFICATE_PRIVATE_INTERFACE_0_1; +} + +} // namespace + +X509CertificatePrivate::X509CertificatePrivate() : Resource() {} + +X509CertificatePrivate::X509CertificatePrivate(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { +} + +X509CertificatePrivate::X509CertificatePrivate(const InstanceHandle& instance) { + if (has_interface<PPB_X509Certificate_Private_0_1>()) { + PassRefFromConstructor(get_interface<PPB_X509Certificate_Private_0_1>()-> + Create(instance.pp_instance())); + } +} + +// static +bool X509CertificatePrivate::IsAvailable() { + return has_interface<PPB_X509Certificate_Private_0_1>(); +} + +bool X509CertificatePrivate::Initialize(const char* bytes, uint32_t length) { + if (!has_interface<PPB_X509Certificate_Private_0_1>()) + return false; + PP_Bool result = get_interface<PPB_X509Certificate_Private_0_1>()->Initialize( + pp_resource(), + bytes, + length); + return PP_ToBool(result); +} + +Var X509CertificatePrivate::GetField( + PP_X509Certificate_Private_Field field) const { + if (!has_interface<PPB_X509Certificate_Private_0_1>()) + return Var(); + return Var(PassRef(), + get_interface<PPB_X509Certificate_Private_0_1>()->GetField(pp_resource(), + field)); +} + +} // namespace pp diff --git a/chromium/ppapi/cpp/private/x509_certificate_private.h b/chromium/ppapi/cpp/private/x509_certificate_private.h new file mode 100644 index 00000000000..981f581439c --- /dev/null +++ b/chromium/ppapi/cpp/private/x509_certificate_private.h @@ -0,0 +1,35 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PRIVATE_X509_CERTIFICATE_PRIVATE_H_ +#define PPAPI_CPP_PRIVATE_X509_CERTIFICATE_PRIVATE_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/private/ppb_x509_certificate_private.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Var; + +class X509CertificatePrivate : public Resource { + public: + // Creates an is_null() object. + X509CertificatePrivate(); + X509CertificatePrivate(PassRef, PP_Resource resource); + explicit X509CertificatePrivate(const InstanceHandle& instance); + + // Returns true if the required interface is available. + static bool IsAvailable(); + + // Creates a new certificate from a DER-encoded representation. Returns true + // if the certificate was successfully created. + bool Initialize(const char* bytes, uint32_t length); + // Returns the specified field as a |Var|. + Var GetField(PP_X509Certificate_Private_Field field) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_PRIVATE_X509_CERTIFICATE_PRIVATE_H_ |