diff options
Diffstat (limited to 'ppapi/cpp/dev')
54 files changed, 3519 insertions, 0 deletions
diff --git a/ppapi/cpp/dev/audio_config_dev.cc b/ppapi/cpp/dev/audio_config_dev.cc new file mode 100644 index 0000000..c68dd84 --- /dev/null +++ b/ppapi/cpp/dev/audio_config_dev.cc @@ -0,0 +1,39 @@ +// 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. + +#include "ppapi/cpp/dev/audio_config_dev.h" + +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +DeviceFuncs<PPB_AudioConfig_Dev> audio_cfg_f(PPB_AUDIO_CONFIG_DEV_INTERFACE); + +namespace pp { + +AudioConfig_Dev::AudioConfig_Dev() + : sample_rate_(PP_AUDIOSAMPLERATE_NONE), + sample_frame_count_(0) { +} + +AudioConfig_Dev::AudioConfig_Dev(PP_AudioSampleRate_Dev sample_rate, + uint32_t sample_frame_count) + : sample_rate_(sample_rate), + sample_frame_count_(sample_frame_count) { + if (audio_cfg_f) { + PassRefFromConstructor(audio_cfg_f->CreateStereo16Bit( + Module::Get()->pp_module(), sample_rate, + sample_frame_count)); + } +} + +// static +uint32_t AudioConfig_Dev::RecommendSampleFrameCount( + uint32_t requested_sample_frame_count) { + if (!audio_cfg_f) + return 0; + return audio_cfg_f->RecommendSampleFrameCount(requested_sample_frame_count); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/audio_config_dev.h b/ppapi/cpp/dev/audio_config_dev.h new file mode 100644 index 0000000..1229156 --- /dev/null +++ b/ppapi/cpp/dev/audio_config_dev.h @@ -0,0 +1,57 @@ +// 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_DEV_AUDIO_CONFIG_DEV_H_ +#define PPAPI_CPP_DEV_AUDIO_CONFIG_DEV_H_ + +#include "ppapi/c/dev/ppb_audio_config_dev.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +// Typical usage: +// +// // Create an audio config with a supported frame count. +// uint32_t sample_frame_count = +// AudioConfig_Dev::RecommendSampleFrameCount(4096); +// AudioConfig_Dev config(PP_AUDIOSAMPLERATE_44100, sample_frame_count); +// if (config.is_null()) +// return false; // Couldn't configure audio. +// +// // Then use the config to create your audio resource. +// Audio_dev audio(..., config, ...); +// if (audio.is_null()) +// return false; // Couldn't create audio. +class AudioConfig_Dev : public Resource { + public: + AudioConfig_Dev(); + + // Creates an audio config based on the given sample rate and frame count. + // If the rate and frame count aren't supported, the resulting resource + // will be is_null(). Pass the result of RecommendSampleFrameCount as the + // semple frame count. + // + // See PPB_AudioConfigDev.CreateStereo16Bit for more. + AudioConfig_Dev(PP_AudioSampleRate_Dev sample_rate, + uint32_t sample_frame_count); + + // Returns a supported frame count for use in the constructor. + // + // See PPB_AudioConfigDev.RecommendSampleFrameCount. + static uint32_t RecommendSampleFrameCount( + uint32_t requested_sample_frame_count); + + PP_AudioSampleRate_Dev sample_rate() const { return sample_rate_; } + uint32_t sample_frame_count() { return sample_frame_count_; } + + private: + PP_AudioSampleRate_Dev sample_rate_; + uint32_t sample_frame_count_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_AUDIO_CONFIG_DEV_H_ + diff --git a/ppapi/cpp/dev/audio_dev.cc b/ppapi/cpp/dev/audio_dev.cc new file mode 100644 index 0000000..c747c78 --- /dev/null +++ b/ppapi/cpp/dev/audio_dev.cc @@ -0,0 +1,38 @@ +// 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. + +#include "ppapi/cpp/dev/audio_dev.h" + +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_Audio_Dev> audio_f(PPB_AUDIO_DEV_INTERFACE); + +} // namespace + +namespace pp { + +Audio_Dev::Audio_Dev(const Instance& instance, + const AudioConfig_Dev& config, + PPB_Audio_Callback callback, + void* user_data) + : config_(config) { + if (audio_f) { + PassRefFromConstructor(audio_f->Create(instance.pp_instance(), + config.pp_resource(), + callback, user_data)); + } +} + +bool Audio_Dev::StartPlayback() { + return audio_f && audio_f->StartPlayback(pp_resource()); +} + +bool Audio_Dev::StopPlayback() { + return audio_f && audio_f->StopPlayback(pp_resource()); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/audio_dev.h b/ppapi/cpp/dev/audio_dev.h new file mode 100644 index 0000000..983e53c --- /dev/null +++ b/ppapi/cpp/dev/audio_dev.h @@ -0,0 +1,38 @@ +// 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_DEV_AUDIO_DEV_H_ +#define PPAPI_CPP_DEV_AUDIO_DEV_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/dev/ppb_audio_dev.h" +#include "ppapi/cpp/dev/audio_config_dev.h" +#include "ppapi/cpp/dev/buffer_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Audio_Dev : public Resource { + public: + Audio_Dev() {} + Audio_Dev(const Instance& instance, + const AudioConfig_Dev& config, + PPB_Audio_Callback callback, + void* user_data); + + AudioConfig_Dev& config() { return config_; } + const AudioConfig_Dev& config() const { return config_; } + + bool StartPlayback(); + bool StopPlayback(); + + private: + AudioConfig_Dev config_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_AUDIO_DEV_H_ + diff --git a/ppapi/cpp/dev/buffer_dev.cc b/ppapi/cpp/dev/buffer_dev.cc new file mode 100644 index 0000000..57ebed7 --- /dev/null +++ b/ppapi/cpp/dev/buffer_dev.cc @@ -0,0 +1,55 @@ +// 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. + +#include "ppapi/cpp/dev/buffer_dev.h" + +#include "ppapi/c/dev/ppb_buffer_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_Buffer_Dev> buffer_f(PPB_BUFFER_DEV_INTERFACE); + +} // namespace + +namespace pp { + +Buffer_Dev::Buffer_Dev() : data_(NULL), size_(0) { +} + +Buffer_Dev::Buffer_Dev(const Buffer_Dev& other) + : Resource(other), + data_(other.data_), + size_(other.size_) { +} + +Buffer_Dev::Buffer_Dev(int32_t size) : data_(NULL), size_(0) { + if (!buffer_f) + return; + + PassRefFromConstructor(buffer_f->Create(Module::Get()->pp_module(), size)); + if (!buffer_f->Describe(pp_resource(), &size_) || + !(data_ = buffer_f->Map(pp_resource()))) + *this = Buffer_Dev(); +} + +Buffer_Dev::~Buffer_Dev() { +} + +Buffer_Dev& Buffer_Dev::operator=(const Buffer_Dev& other) { + Buffer_Dev copy(other); + swap(copy); + return *this; +} + +void Buffer_Dev::swap(Buffer_Dev& other) { + Resource::swap(other); + std::swap(size_, other.size_); + std::swap(data_, other.data_); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/buffer_dev.h b/ppapi/cpp/dev/buffer_dev.h new file mode 100644 index 0000000..7497a6f --- /dev/null +++ b/ppapi/cpp/dev/buffer_dev.h @@ -0,0 +1,39 @@ +// 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_DEV_BUFFER_DEV_H_ +#define PPAPI_CPP_DEV_BUFFER_DEV_H_ + +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Buffer_Dev : public Resource { + public: + // Creates an is_null() Buffer object. + Buffer_Dev(); + + Buffer_Dev(const Buffer_Dev& other); + + // Allocates a new Buffer in the browser with the given size. The + // resulting object will be is_null() if the allocation failed. + explicit Buffer_Dev(int32_t size); + + ~Buffer_Dev(); + + Buffer_Dev& operator=(const Buffer_Dev& other); + void swap(Buffer_Dev& other); + + int32_t size() const { return size_; } + void* data() const { return data_; } + + private: + void* data_; + int32_t size_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_BUFFER_DEV_H_ + diff --git a/ppapi/cpp/dev/directory_entry_dev.cc b/ppapi/cpp/dev/directory_entry_dev.cc new file mode 100644 index 0000000..a5f8179 --- /dev/null +++ b/ppapi/cpp/dev/directory_entry_dev.cc @@ -0,0 +1,41 @@ +// 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. + +#include "ppapi/cpp/dev/directory_entry_dev.h" + +#include <string.h> + +#include "ppapi/cpp/module.h" + +namespace pp { + +DirectoryEntry_Dev::DirectoryEntry_Dev() { + memset(&data_, 0, sizeof(data_)); +} + +DirectoryEntry_Dev::DirectoryEntry_Dev(const DirectoryEntry_Dev& other) { + data_.file_ref = other.data_.file_ref; + data_.file_type = other.data_.file_type; + if (data_.file_ref) + Module::Get()->core()->AddRefResource(data_.file_ref); +} + +DirectoryEntry_Dev::~DirectoryEntry_Dev() { + if (data_.file_ref) + Module::Get()->core()->ReleaseResource(data_.file_ref); +} + +DirectoryEntry_Dev& DirectoryEntry_Dev::operator=( + const DirectoryEntry_Dev& other) { + DirectoryEntry_Dev copy(other); + swap(copy); + return *this; +} + +void DirectoryEntry_Dev::swap(DirectoryEntry_Dev& other) { + std::swap(data_.file_ref, other.data_.file_ref); + std::swap(data_.file_type, other.data_.file_type); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/directory_entry_dev.h b/ppapi/cpp/dev/directory_entry_dev.h new file mode 100644 index 0000000..84ef623 --- /dev/null +++ b/ppapi/cpp/dev/directory_entry_dev.h @@ -0,0 +1,38 @@ +// 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_DEV_DIRECTORY_ENTRY_DEV_H_ +#define PPAPI_CPP_DEV_DIRECTORY_ENTRY_DEV_H_ + +#include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "ppapi/cpp/dev/file_ref_dev.h" + +namespace pp { + +class DirectoryEntry_Dev { + public: + DirectoryEntry_Dev(); + DirectoryEntry_Dev(const DirectoryEntry_Dev& other); + ~DirectoryEntry_Dev(); + + DirectoryEntry_Dev& operator=(const DirectoryEntry_Dev& other); + void swap(DirectoryEntry_Dev& other); + + // Returns true if the DirectoryEntry is invalid or uninitialized. + bool is_null() const { return !data_.file_ref; } + + // Returns the FileRef held by this DirectoryEntry. + FileRef_Dev file_ref() const { return FileRef_Dev(data_.file_ref); } + + // Returns the type of the file referenced by this DirectoryEntry. + PP_FileType_Dev file_type() const { return data_.file_type; } + + private: + friend class DirectoryReader_Dev; + PP_DirectoryEntry_Dev data_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_DIRECTORY_ENTRY_DEV_H_ diff --git a/ppapi/cpp/dev/directory_reader_dev.cc b/ppapi/cpp/dev/directory_reader_dev.cc new file mode 100644 index 0000000..bcf5e11 --- /dev/null +++ b/ppapi/cpp/dev/directory_reader_dev.cc @@ -0,0 +1,53 @@ +// 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. + +#include "ppapi/cpp/dev/directory_reader_dev.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/directory_entry_dev.h" +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_DirectoryReader_Dev> directory_reader_f( + PPB_DIRECTORYREADER_DEV_INTERFACE); + +} // namespace + +namespace pp { + +DirectoryReader_Dev::DirectoryReader_Dev(const FileRef_Dev& directory_ref) { + if (!directory_reader_f) + return; + PassRefFromConstructor( + directory_reader_f->Create(directory_ref.pp_resource())); +} + +DirectoryReader_Dev::DirectoryReader_Dev(const DirectoryReader_Dev& other) + : Resource(other) { +} + +DirectoryReader_Dev& DirectoryReader_Dev::operator=( + const DirectoryReader_Dev& other) { + DirectoryReader_Dev copy(other); + swap(copy); + return *this; +} + +void DirectoryReader_Dev::swap(DirectoryReader_Dev& other) { + Resource::swap(other); +} + +int32_t DirectoryReader_Dev::GetNextEntry(DirectoryEntry_Dev* entry, + const CompletionCallback& cc) { + if (!directory_reader_f) + return PP_ERROR_NOINTERFACE; + return directory_reader_f->GetNextEntry(pp_resource(), &entry->data_, + cc.pp_completion_callback()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/directory_reader_dev.h b/ppapi/cpp/dev/directory_reader_dev.h new file mode 100644 index 0000000..e90fbc0 --- /dev/null +++ b/ppapi/cpp/dev/directory_reader_dev.h @@ -0,0 +1,36 @@ +// 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_DEV_DIRECTORY_READER_DEV_H_ +#define PPAPI_CPP_DEV_DIRECTORY_READER_DEV_H_ + +#include <stdlib.h> + +#include "ppapi/c/dev/ppb_directory_reader_dev.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class DirectoryEntry_Dev; +class FileRef_Dev; + +class DirectoryReader_Dev : public Resource { + public: + // Creates a DirectoryReader for the given directory. + DirectoryReader_Dev(const FileRef_Dev& directory_ref); + + DirectoryReader_Dev(const DirectoryReader_Dev& other); + + DirectoryReader_Dev& operator=(const DirectoryReader_Dev& other); + void swap(DirectoryReader_Dev& other); + + // See PPB_DirectoryReader::GetNextEntry. + int32_t GetNextEntry(DirectoryEntry_Dev* entry, + const CompletionCallback& cc); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DIRECTORY_READER_H_ diff --git a/ppapi/cpp/dev/file_chooser_dev.cc b/ppapi/cpp/dev/file_chooser_dev.cc new file mode 100644 index 0000000..051ab38 --- /dev/null +++ b/ppapi/cpp/dev/file_chooser_dev.cc @@ -0,0 +1,58 @@ +// 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. + +#include "ppapi/cpp/dev/file_chooser_dev.h" + +#include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_FileChooser_Dev> file_chooser_f(PPB_FILECHOOSER_DEV_INTERFACE); + +} // namespace + +namespace pp { + +FileChooser_Dev::FileChooser_Dev(const Instance& instance, + const PP_FileChooserOptions_Dev& options) { + if (!file_chooser_f) + return; + PassRefFromConstructor(file_chooser_f->Create(instance.pp_instance(), + &options)); +} + +FileChooser_Dev::FileChooser_Dev(const FileChooser_Dev& other) + : Resource(other) { +} + +FileChooser_Dev& FileChooser_Dev::operator=(const FileChooser_Dev& other) { + FileChooser_Dev copy(other); + swap(copy); + return *this; +} + +void FileChooser_Dev::swap(FileChooser_Dev& other) { + Resource::swap(other); +} + +int32_t FileChooser_Dev::Show(const CompletionCallback& cc) { + if (!file_chooser_f) + return PP_ERROR_NOINTERFACE; + return file_chooser_f->Show(pp_resource(), cc.pp_completion_callback()); +} + +FileRef_Dev FileChooser_Dev::GetNextChosenFile() const { + if (!file_chooser_f) + return FileRef_Dev(); + return FileRef_Dev(FileRef_Dev::PassRef(), + file_chooser_f->GetNextChosenFile(pp_resource())); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h new file mode 100644 index 0000000..f611b1e --- /dev/null +++ b/ppapi/cpp/dev/file_chooser_dev.h @@ -0,0 +1,38 @@ +// 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_DEV_FILE_CHOOSER_DEV_H_ +#define PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_ + +#include "ppapi/cpp/resource.h" + +struct PP_FileChooserOptions_Dev; + +namespace pp { + +class CompletionCallback; +class FileRef_Dev; +class Instance; + +class FileChooser_Dev : public Resource { + public: + // Creates an is_null() FileChooser object. + FileChooser_Dev() {} + + FileChooser_Dev(const Instance& instance, + const PP_FileChooserOptions_Dev& options); + + FileChooser_Dev(const FileChooser_Dev& other); + + FileChooser_Dev& operator=(const FileChooser_Dev& other); + void swap(FileChooser_Dev& other); + + // PPB_FileChooser methods: + int32_t Show(const CompletionCallback& cc); + FileRef_Dev GetNextChosenFile() const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_ diff --git a/ppapi/cpp/dev/file_io_dev.cc b/ppapi/cpp/dev/file_io_dev.cc new file mode 100644 index 0000000..54731ed --- /dev/null +++ b/ppapi/cpp/dev/file_io_dev.cc @@ -0,0 +1,135 @@ +// 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. + +#include "ppapi/cpp/dev/file_io_dev.h" + +#include "ppapi/c/dev/ppb_file_io_dev.h" +#include "ppapi/c/dev/ppb_file_io_trusted_dev.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_FileIO_Dev> file_io_f( + PPB_FILEIO_DEV_INTERFACE); +DeviceFuncs<PPB_FileIOTrusted_Dev> file_io_trusted_f( + PPB_FILEIOTRUSTED_DEV_INTERFACE); + +} // namespace + +namespace pp { + +FileIO_Dev::FileIO_Dev() { + if (!file_io_f) + return; + PassRefFromConstructor(file_io_f->Create(Module::Get()->pp_module())); +} + +FileIO_Dev::FileIO_Dev(const FileIO_Dev& other) + : Resource(other) { +} + +FileIO_Dev& FileIO_Dev::operator=(const FileIO_Dev& other) { + FileIO_Dev copy(other); + swap(copy); + return *this; +} + +void FileIO_Dev::swap(FileIO_Dev& other) { + Resource::swap(other); +} + +int32_t FileIO_Dev::Open(const FileRef_Dev& file_ref, + int32_t open_flags, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Open(pp_resource(), file_ref.pp_resource(), open_flags, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::Query(PP_FileInfo_Dev* result_buf, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Query(pp_resource(), result_buf, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::Touch(PP_Time last_access_time, + PP_Time last_modified_time, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Touch(pp_resource(), last_access_time, last_modified_time, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::Read(int64_t offset, + char* buffer, + int32_t bytes_to_read, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Read(pp_resource(), offset, buffer, bytes_to_read, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::Write(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Write(pp_resource(), offset, buffer, bytes_to_write, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::SetLength(int64_t length, + const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->SetLength(pp_resource(), length, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::Flush(const CompletionCallback& cc) { + if (!file_io_f) + return PP_ERROR_NOINTERFACE; + return file_io_f->Flush(pp_resource(), cc.pp_completion_callback()); +} + +void FileIO_Dev::Close() { + if (!file_io_f) + return; + file_io_f->Close(pp_resource()); +} + +int32_t FileIO_Dev::GetOSFileDescriptor() { + if (!file_io_trusted_f) + return PP_ERROR_NOINTERFACE; + return file_io_trusted_f->GetOSFileDescriptor(pp_resource()); +} + +int32_t FileIO_Dev::WillWrite(int64_t offset, + int32_t bytes_to_write, + const CompletionCallback& cc) { + if (!file_io_trusted_f) + return PP_ERROR_NOINTERFACE; + return file_io_trusted_f->WillWrite(pp_resource(), offset, bytes_to_write, + cc.pp_completion_callback()); +} + +int32_t FileIO_Dev::WillSetLength(int64_t length, + const CompletionCallback& cc) { + if (!file_io_trusted_f) + return PP_ERROR_NOINTERFACE; + return file_io_trusted_f->WillSetLength(pp_resource(), length, + cc.pp_completion_callback()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/file_io_dev.h b/ppapi/cpp/dev/file_io_dev.h new file mode 100644 index 0000000..e38c2e1 --- /dev/null +++ b/ppapi/cpp/dev/file_io_dev.h @@ -0,0 +1,61 @@ +// 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_DEV_FILE_IO_DEV_H_ +#define PPAPI_CPP_DEV_FILE_IO_DEV_H_ + +#include "ppapi/c/pp_time.h" +#include "ppapi/cpp/resource.h" + +struct PP_FileInfo_Dev; + +namespace pp { + +class CompletionCallback; +class FileRef_Dev; + +class FileIO_Dev : public Resource { + public: + FileIO_Dev(); + FileIO_Dev(const FileIO_Dev& other); + + FileIO_Dev& operator=(const FileIO_Dev& other); + void swap(FileIO_Dev& other); + + // PPB_FileIO methods: + int32_t Open(const FileRef_Dev& file_ref, + int32_t open_flags, + const CompletionCallback& cc); + int32_t Query(PP_FileInfo_Dev* result_buf, + const CompletionCallback& cc); + int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + const CompletionCallback& cc); + int32_t Read(int64_t offset, + char* buffer, + int32_t bytes_to_read, + const CompletionCallback& cc); + int32_t Write(int64_t offset, + const char* buffer, + int32_t bytes_to_write, + const CompletionCallback& cc); + int32_t SetLength(int64_t length, + const CompletionCallback& cc); + int32_t Flush(const CompletionCallback& cc); + void Close(); + + // PPB_FileIOTrusted methods: + // NOTE: These are only available to trusted plugins and will return + // PP_ERROR_NOINTERFACE if called from an untrusted plugin. + int32_t GetOSFileDescriptor(); + int32_t WillWrite(int64_t offset, + int32_t bytes_to_write, + const CompletionCallback& cc); + int32_t WillSetLength(int64_t length, + const CompletionCallback& cc); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FILE_IO_DEV_H_ diff --git a/ppapi/cpp/dev/file_ref_dev.cc b/ppapi/cpp/dev/file_ref_dev.cc new file mode 100644 index 0000000..c65c07f --- /dev/null +++ b/ppapi/cpp/dev/file_ref_dev.cc @@ -0,0 +1,124 @@ +// 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. + +#include "ppapi/cpp/dev/file_ref_dev.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/file_system_dev.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_FileRef_Dev> file_ref_f(PPB_FILEREF_DEV_INTERFACE); + +} // namespace + +namespace pp { + +FileRef_Dev::FileRef_Dev(PP_Resource resource) : Resource(resource) { +} + +FileRef_Dev::FileRef_Dev(PassRef, PP_Resource resource) { + PassRefFromConstructor(resource); +} + +FileRef_Dev::FileRef_Dev(const FileSystem_Dev& file_system, + const char* path) { + if (!file_ref_f) + return; + PassRefFromConstructor(file_ref_f->Create(file_system.pp_resource(), path)); +} + +FileRef_Dev::FileRef_Dev(const FileRef_Dev& other) + : Resource(other) { +} + +FileRef_Dev& FileRef_Dev::operator=(const FileRef_Dev& other) { + FileRef_Dev copy(other); + swap(copy); + return *this; +} + +void FileRef_Dev::swap(FileRef_Dev& other) { + Resource::swap(other); +} + +PP_FileSystemType_Dev FileRef_Dev::GetFileSystemType() const { + if (!file_ref_f) + return PP_FILESYSTEMTYPE_EXTERNAL; + return file_ref_f->GetFileSystemType(pp_resource()); +} + +Var FileRef_Dev::GetName() const { + if (!file_ref_f) + return Var(); + return Var(Var::PassRef(), file_ref_f->GetName(pp_resource())); +} + +Var FileRef_Dev::GetPath() const { + if (!file_ref_f) + return Var(); + return Var(Var::PassRef(), file_ref_f->GetPath(pp_resource())); +} + +FileRef_Dev FileRef_Dev::GetParent() const { + if (!file_ref_f) + return FileRef_Dev(); + return FileRef_Dev(PassRef(), file_ref_f->GetParent(pp_resource())); +} + +int32_t FileRef_Dev::MakeDirectory(const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->MakeDirectory(pp_resource(), + false, // make_ancestors + cc.pp_completion_callback()); +} + +int32_t FileRef_Dev::MakeDirectoryIncludingAncestors( + const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->MakeDirectory(pp_resource(), + true, // make_ancestors + cc.pp_completion_callback()); +} + +int32_t FileRef_Dev::Query(PP_FileInfo_Dev* result_buf, + const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->Query(pp_resource(), + result_buf, + cc.pp_completion_callback()); +} + +int32_t FileRef_Dev::Touch(PP_Time last_access_time, + PP_Time last_modified_time, + const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->Touch(pp_resource(), + last_access_time, + last_modified_time, + cc.pp_completion_callback()); +} + +int32_t FileRef_Dev::Delete(const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->Delete(pp_resource(), cc.pp_completion_callback()); +} + +int32_t FileRef_Dev::Rename(const FileRef_Dev& new_file_ref, + const CompletionCallback& cc) { + if (!file_ref_f) + return PP_ERROR_NOINTERFACE; + return file_ref_f->Rename(pp_resource(), + new_file_ref.pp_resource(), + cc.pp_completion_callback()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/file_ref_dev.h b/ppapi/cpp/dev/file_ref_dev.h new file mode 100644 index 0000000..b2d10a6 --- /dev/null +++ b/ppapi/cpp/dev/file_ref_dev.h @@ -0,0 +1,71 @@ +// 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_DEV_FILE_REF_DEV_H_ +#define PPAPI_CPP_DEV_FILE_REF_DEV_H_ + +#include "ppapi/c/dev/ppb_file_ref_dev.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class CompletionCallback; +class FileSystem_Dev; + +class FileRef_Dev : public Resource { + public: + // Creates an is_null() FileRef object. + FileRef_Dev() {} + + // This constructor is used when we've gotten a PP_Resource as a return value + // that we need to addref. + explicit FileRef_Dev(PP_Resource resource); + + // This constructor is used when we've gotten a PP_Resource as a return value + // that has already been addref'ed for us. + struct PassRef {}; + FileRef_Dev(PassRef, PP_Resource resource); + + // Creates a FileRef pointing to a path in the given filesystem. + FileRef_Dev(const FileSystem_Dev& file_system, const char* path); + + FileRef_Dev(const FileRef_Dev& other); + + FileRef_Dev& operator=(const FileRef_Dev& other); + void swap(FileRef_Dev& other); + + // Returns the file system type. + PP_FileSystemType_Dev GetFileSystemType() const; + + // Returns the name of the file. + Var GetName() const; + + // Returns the absolute path of the file. See PPB_FileRef::GetPath for more + // details. + Var GetPath() const; + + // Returns the parent directory of this file. See PPB_FileRef::GetParent for + // more details. + FileRef_Dev GetParent() const; + + int32_t MakeDirectory(const CompletionCallback& cc); + + int32_t MakeDirectoryIncludingAncestors(const CompletionCallback& cc); + + int32_t Query(PP_FileInfo_Dev* result_buf, const CompletionCallback& cc); + + int32_t Touch(PP_Time last_access_time, + PP_Time last_modified_time, + const CompletionCallback& cc); + + int32_t Delete(const CompletionCallback& cc); + + int32_t Rename(const FileRef_Dev& new_file_ref, const CompletionCallback& cc); +}; + +} // namespace pp + +#endif // PPAPI_CPP_FILE_REF_H_ diff --git a/ppapi/cpp/dev/file_system_dev.cc b/ppapi/cpp/dev/file_system_dev.cc new file mode 100644 index 0000000..e6dfaff --- /dev/null +++ b/ppapi/cpp/dev/file_system_dev.cc @@ -0,0 +1,37 @@ +// 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. + +#include "ppapi/cpp/dev/file_system_dev.h" + +#include "ppapi/c/dev/ppb_file_system_dev.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_FileSystem_Dev> file_sys_f(PPB_FILESYSTEM_DEV_INTERFACE); + +} // namespace + +namespace pp { + +FileSystem_Dev::FileSystem_Dev(Instance* instance, + PP_FileSystemType_Dev type) { + if (!file_sys_f) + return; + PassRefFromConstructor(file_sys_f->Create(instance->pp_instance(), type)); +} + +int32_t FileSystem_Dev::Open(int64_t expected_size, + const CompletionCallback& cc) { + if (!file_sys_f) + return PP_ERROR_NOINTERFACE; + return file_sys_f->Open(pp_resource(), expected_size, + cc.pp_completion_callback()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/file_system_dev.h b/ppapi/cpp/dev/file_system_dev.h new file mode 100644 index 0000000..497740a --- /dev/null +++ b/ppapi/cpp/dev/file_system_dev.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_DEV_FILE_SYSTEM_DEV_H_ +#define PPAPI_CPP_DEV_FILE_SYSTEM_DEV_H_ + +#include "ppapi/c/dev/pp_file_info_dev.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_stdint.h" +#include "ppapi/c/pp_time.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" + +struct PP_FileInfo_Dev; + +namespace pp { + +class CompletionCallback; +class FileRef_Dev; + +// Wraps methods from ppb_file_system.h +class FileSystem_Dev : public Resource { + public: + FileSystem_Dev(Instance* instance, PP_FileSystemType_Dev type); + + int32_t Open(int64_t expected_size, const CompletionCallback& cc); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FILE_SYSTEM_DEV_H_ diff --git a/ppapi/cpp/dev/find_dev.cc b/ppapi/cpp/dev/find_dev.cc new file mode 100644 index 0000000..8cbde54 --- /dev/null +++ b/ppapi/cpp/dev/find_dev.cc @@ -0,0 +1,75 @@ +// 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. + +#include "ppapi/cpp/dev/find_dev.h" + +#include "ppapi/c/dev/ppb_find_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE; + +bool StartFind(PP_Instance instance, + const char* text, + bool case_sensitive) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + if (!object) + return false; + return static_cast<Find_Dev*>(object)->StartFind(text, case_sensitive); +} + +void SelectFindResult(PP_Instance instance, bool forward) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + if (object) + static_cast<Find_Dev*>(object)->SelectFindResult(forward); +} + +void StopFind(PP_Instance instance) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + if (object) + static_cast<Find_Dev*>(object)->StopFind(); +} + +const PPP_Find_Dev ppp_find = { + &StartFind, + &SelectFindResult, + &StopFind +}; + +DeviceFuncs<PPB_Find_Dev> ppb_find_f(PPB_FIND_DEV_INTERFACE); + +} // namespace + +Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find); + associated_instance_->AddPerInstanceObject(kPPPFindInterface, this); +} + +Find_Dev::~Find_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPFindInterface, this); +} + +void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) { + if (ppb_find_f) { + ppb_find_f->NumberOfFindResultsChanged(associated_instance_->pp_instance(), + total, final_result); + } +} + +void Find_Dev::SelectedFindResultChanged(int32_t index) { + if (ppb_find_f) { + ppb_find_f->SelectedFindResultChanged(associated_instance_->pp_instance(), + index); + } +} + +} // namespace pp diff --git a/ppapi/cpp/dev/find_dev.h b/ppapi/cpp/dev/find_dev.h new file mode 100644 index 0000000..b89160f --- /dev/null +++ b/ppapi/cpp/dev/find_dev.h @@ -0,0 +1,61 @@ +// 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_DEV_FIND_DEV_H_ +#define PPAPI_CPP_DEV_FIND_DEV_H_ + +#include <string> + +#include "ppapi/c/dev/ppp_find_dev.h" + +namespace pp { + +class Instance; + +// This class allows you to associate the PPP_Find and PPB_Find C-based +// interfaces with an object. It associates itself with the given instance, and +// registers as the global handler for handling the PPP_Find interface that the +// browser calls. +// +// You would typically use this either via inheritance on your instance: +// class MyInstance : public pp::Instance, public pp::Find_Dev { +// class MyInstance() : pp::Find_Dev(this) { +// } +// ... +// }; +// +// or by composition: +// class MyFinder : public pp::Find { +// ... +// }; +// +// class MyInstance : public pp::Instance { +// MyInstance() : finder_(this) { +// } +// +// MyFinder finder_; +// }; +class Find_Dev { + public: + // The instance parameter must outlive this class. + Find_Dev(Instance* instance); + virtual ~Find_Dev(); + + // PPP_Find_Dev functions exposed as virtual functions for you to + // override. + virtual bool StartFind(const std::string& text, bool case_sensitive) = 0; + virtual void SelectFindResult(bool forward) = 0; + virtual void StopFind() = 0; + + // PPB_Find_Def functions for you to call to report find results. + void NumberOfFindResultsChanged(int32_t total, bool final_result); + void SelectedFindResultChanged(int32_t index); + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FIND_DEV_H_ diff --git a/ppapi/cpp/dev/font_dev.cc b/ppapi/cpp/dev/font_dev.cc new file mode 100644 index 0000000..9e294fb --- /dev/null +++ b/ppapi/cpp/dev/font_dev.cc @@ -0,0 +1,210 @@ +// 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. + +#include "ppapi/cpp/dev/font_dev.h" + +#include <algorithm> + +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/point.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_Font_Dev> font_f(PPB_FONT_DEV_INTERFACE); + +} // namespace + +namespace pp { + +// FontDescription_Dev --------------------------------------------------------- + +FontDescription_Dev::FontDescription_Dev() { + pp_font_description_.face = face_.pp_var(); + set_family(PP_FONTFAMILY_DEFAULT); + set_size(0); + set_weight(PP_FONTWEIGHT_NORMAL); + set_italic(false); + set_small_caps(false); + set_letter_spacing(0); + set_word_spacing(0); +} + +FontDescription_Dev::FontDescription_Dev(const FontDescription_Dev& other) { + set_face(other.face()); + set_family(other.family()); + set_size(other.size()); + set_weight(other.weight()); + set_italic(other.italic()); + set_small_caps(other.small_caps()); + set_letter_spacing(other.letter_spacing()); + set_word_spacing(other.word_spacing()); +} + +FontDescription_Dev::~FontDescription_Dev() { +} + +FontDescription_Dev& FontDescription_Dev::operator=( + const FontDescription_Dev& other) { + FontDescription_Dev copy(other); + swap(copy); + return *this; +} + +void FontDescription_Dev::swap(FontDescription_Dev& other) { + // Need to fix up both the face and the pp_font_description_.face which the + // setter does for us. + Var temp = face(); + set_face(other.face()); + other.set_face(temp); + + std::swap(pp_font_description_.family, other.pp_font_description_.family); + std::swap(pp_font_description_.size, other.pp_font_description_.size); + std::swap(pp_font_description_.weight, other.pp_font_description_.weight); + std::swap(pp_font_description_.italic, other.pp_font_description_.italic); + std::swap(pp_font_description_.small_caps, + other.pp_font_description_.small_caps); + std::swap(pp_font_description_.letter_spacing, + other.pp_font_description_.letter_spacing); + std::swap(pp_font_description_.word_spacing, + other.pp_font_description_.word_spacing); +} + +// TextRun_Dev ----------------------------------------------------------------- + +TextRun_Dev::TextRun_Dev() { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = false; + pp_text_run_.override_direction = false; +} + +TextRun_Dev::TextRun_Dev(const std::string& text, + bool rtl, + bool override_direction) + : text_(text) { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = rtl; + pp_text_run_.override_direction = override_direction; +} + +TextRun_Dev::TextRun_Dev(const TextRun_Dev& other) : text_(other.text_) { + pp_text_run_.text = text_.pp_var(); + pp_text_run_.rtl = other.pp_text_run_.rtl; + pp_text_run_.override_direction = other.pp_text_run_.override_direction; +} + +TextRun_Dev::~TextRun_Dev() { +} + +TextRun_Dev& TextRun_Dev::operator=(const TextRun_Dev& other) { + TextRun_Dev copy(other); + swap(copy); + return *this; +} + +void TextRun_Dev::swap(TextRun_Dev& other) { + std::swap(text_, other.text_); + + // Fix up both object's pp_text_run.text to point to their text_ member. + pp_text_run_.text = text_.pp_var(); + other.pp_text_run_.text = other.text_.pp_var(); + + std::swap(pp_text_run_.rtl, other.pp_text_run_.rtl); + std::swap(pp_text_run_.override_direction, + other.pp_text_run_.override_direction); +} + +// Font ------------------------------------------------------------------------ + +Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { +} + +Font_Dev::Font_Dev(const FontDescription_Dev& description) { + if (!font_f) + return; + PassRefFromConstructor(font_f->Create( + Module::Get()->pp_module(), &description.pp_font_description())); +} + +Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { +} + +Font_Dev& Font_Dev::operator=(const Font_Dev& other) { + Font_Dev copy(other); + swap(copy); + return *this; +} + +void Font_Dev::swap(Font_Dev& other) { + Resource::swap(other); +} + +bool Font_Dev::Describe(FontDescription_Dev* description, + PP_FontMetrics_Dev* metrics) const { + if (!font_f) + return false; + + // Be careful with ownership of the |face| string. It will come back with + // a ref of 1, which we want to assign to the |face_| member of the C++ class. + if (!font_f->Describe(pp_resource(), &description->pp_font_description_, + metrics)) + return false; + description->face_ = Var(Var::PassRef(), + description->pp_font_description_.face); + + return true; +} + +bool Font_Dev::DrawTextAt(ImageData* dest, + const TextRun_Dev& text, + const Point& position, + uint32_t color, + const Rect& clip, + bool image_data_is_opaque) const { + if (!font_f) + return false; + return font_f->DrawTextAt(pp_resource(), dest->pp_resource(), + &text.pp_text_run(), &position.pp_point(), + color, &clip.pp_rect(), image_data_is_opaque); +} + +int32_t Font_Dev::MeasureText(const TextRun_Dev& text) const { + if (!font_f) + return -1; + return font_f->MeasureText(pp_resource(), &text.pp_text_run()); +} + +uint32_t Font_Dev::CharacterOffsetForPixel(const TextRun_Dev& text, + int32_t pixel_position) const { + if (!font_f) + return 0; + return font_f->CharacterOffsetForPixel(pp_resource(), &text.pp_text_run(), + pixel_position); + +} + +int32_t Font_Dev::PixelOffsetForCharacter(const TextRun_Dev& text, + uint32_t char_offset) const { + if (!font_f) + return 0; + return font_f->PixelOffsetForCharacter(pp_resource(), &text.pp_text_run(), + char_offset); +} + +bool Font_Dev::DrawSimpleText(ImageData* dest, + const std::string& text, + const Point& position, + uint32_t color, + bool image_data_is_opaque) const { + return DrawTextAt(dest, TextRun_Dev(text), position, color, + Rect(dest->size()), image_data_is_opaque); +} + +int32_t Font_Dev::MeasureSimpleText(const std::string& text) const { + return MeasureText(TextRun_Dev(text)); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/font_dev.h b/ppapi/cpp/dev/font_dev.h new file mode 100644 index 0000000..bac8bb9 --- /dev/null +++ b/ppapi/cpp/dev/font_dev.h @@ -0,0 +1,139 @@ +// 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_DEV_FONT_DEV_H_ +#define PPAPI_CPP_DEV_FONT_DEV_H_ + +#include <string> + +#include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +struct PP_FontDescription_Dev; + +namespace pp { + +class Font_dev; +class ImageData; +class Instance; +class Point; +class Rect; + +// FontDescription_Dev --------------------------------------------------------- + +class FontDescription_Dev { + public: + FontDescription_Dev(); + FontDescription_Dev(const FontDescription_Dev& other); + ~FontDescription_Dev(); + + const PP_FontDescription_Dev& pp_font_description() const { + return pp_font_description_; + } + + FontDescription_Dev& operator=(const FontDescription_Dev& other); + void swap(FontDescription_Dev& other); + + Var face() const { return face_; } + void set_face(const Var& face) { + face_ = face; + pp_font_description_.face = face_.pp_var(); + } + + PP_FontFamily_Dev family() const { return pp_font_description_.family; } + void set_family(PP_FontFamily_Dev f) { pp_font_description_.family = f; } + + uint32_t size() const { return pp_font_description_.size; } + void set_size(uint32_t s) { pp_font_description_.size = s; } + + PP_FontWeight_Dev weight() const { return pp_font_description_.weight; } + void set_weight(PP_FontWeight_Dev w) { pp_font_description_.weight = w; } + + bool italic() const { return pp_font_description_.italic; } + void set_italic(bool i) { pp_font_description_.italic = i; } + + bool small_caps() const { return pp_font_description_.small_caps; } + void set_small_caps(bool s) { pp_font_description_.small_caps = s; } + + int letter_spacing() const { return pp_font_description_.letter_spacing; } + void set_letter_spacing(int s) { pp_font_description_.letter_spacing = s; } + + int word_spacing() const { return pp_font_description_.word_spacing; } + void set_word_spacing(int w) { pp_font_description_.word_spacing = w; } + + private: + friend class Font_Dev; + + Var face_; // Manages memory for pp_font_description_.face + PP_FontDescription_Dev pp_font_description_; +}; + +// TextRun_Dev --------------------------------------------------------------------- + +class TextRun_Dev { + public: + TextRun_Dev(); + TextRun_Dev(const std::string& text, + bool rtl = false, + bool override_direction = false); + TextRun_Dev(const TextRun_Dev& other); + ~TextRun_Dev(); + + TextRun_Dev& operator=(const TextRun_Dev& other); + void swap(TextRun_Dev& other); + + const PP_TextRun_Dev& pp_text_run() const { + return pp_text_run_; + } + + private: + Var text_; // Manages memory for the reference in pp_text_run_. + PP_TextRun_Dev pp_text_run_; +}; + +// Font ------------------------------------------------------------------------ + +// Provides access to system fonts. +class Font_Dev : public Resource { + public: + // Creates an is_null() Font object. + Font_Dev() {} + + explicit Font_Dev(PP_Resource resource); + explicit Font_Dev(const FontDescription_Dev& description); + Font_Dev(const Font_Dev& other); + + Font_Dev& operator=(const Font_Dev& other); + void swap(Font_Dev& other); + + // PPB_Font methods: + bool Describe(FontDescription_Dev* description, + PP_FontMetrics_Dev* metrics) const; + bool DrawTextAt(ImageData* dest, + const TextRun_Dev& text, + const Point& position, + uint32_t color, + const Rect& clip, + bool image_data_is_opaque) const; + int32_t MeasureText(const TextRun_Dev& text) const; + uint32_t CharacterOffsetForPixel(const TextRun_Dev& text, + int32_t pixel_position) const; + int32_t PixelOffsetForCharacter(const TextRun_Dev& text, + uint32_t char_offset) const; + + // Convenience function that assumes a left-to-right string with no clipping. + bool DrawSimpleText(ImageData* dest, + const std::string& text, + const Point& position, + uint32_t color, + bool image_data_is_opaque = false) const; + + // Convenience function that assumes a left-to-right string. + int32_t MeasureSimpleText(const std::string& text) const; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FONT_DEV_H_ diff --git a/ppapi/cpp/dev/fullscreen_dev.cc b/ppapi/cpp/dev/fullscreen_dev.cc new file mode 100644 index 0000000..fd04ec9 --- /dev/null +++ b/ppapi/cpp/dev/fullscreen_dev.cc @@ -0,0 +1,39 @@ +// 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. + +#include "ppapi/cpp/dev/fullscreen_dev.h" + +#include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +DeviceFuncs<PPB_Fullscreen_Dev> ppb_fullscreen_f(PPB_FULLSCREEN_DEV_INTERFACE); + +} // anonymous namespace + +Fullscreen_Dev::Fullscreen_Dev(Instance* instance) + : associated_instance_(instance) { +} + +Fullscreen_Dev::~Fullscreen_Dev() { +} + +bool Fullscreen_Dev::IsFullscreen() { + return ppb_fullscreen_f && ppb_fullscreen_f->IsFullscreen( + associated_instance_->pp_instance()); +} + +bool Fullscreen_Dev::SetFullscreen(bool fullscreen) { + if (!ppb_fullscreen_f) + return false; + return ppb_fullscreen_f->SetFullscreen(associated_instance_->pp_instance(), + fullscreen); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/fullscreen_dev.h b/ppapi/cpp/dev/fullscreen_dev.h new file mode 100644 index 0000000..1050faf --- /dev/null +++ b/ppapi/cpp/dev/fullscreen_dev.h @@ -0,0 +1,31 @@ +// 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_DEV_FULLSCREEN_DEV_H_ +#define PPAPI_CPP_DEV_FULLSCREEN_DEV_H_ + +#include <string> + +#include "ppapi/c/dev/ppb_fullscreen_dev.h" + +namespace pp { + +class Instance; + +class Fullscreen_Dev { + public: + Fullscreen_Dev(Instance* instance); + virtual ~Fullscreen_Dev(); + + // PPB_Fullscreen_Dev methods. + bool IsFullscreen(); + bool SetFullscreen(bool fullscreen); + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_FULLSCREEN_DEV_H_ diff --git a/ppapi/cpp/dev/graphics_3d_client_dev.cc b/ppapi/cpp/dev/graphics_3d_client_dev.cc new file mode 100644 index 0000000..bdd2e7e --- /dev/null +++ b/ppapi/cpp/dev/graphics_3d_client_dev.cc @@ -0,0 +1,43 @@ +// 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. + +#include "ppapi/cpp/dev/graphics_3d_client_dev.h" + +#include "ppapi/c/dev/ppp_graphics_3d_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +const char kPPPGraphics3DInterface[] = PPP_GRAPHICS_3D_DEV_INTERFACE; + +void Graphics3D_ContextLost(PP_Instance instance) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPGraphics3DInterface); + if (!object) + return; + return static_cast<Graphics3DClient_Dev*>(object)->Graphics3DContextLost(); +} + +static PPP_Graphics3D_Dev graphics3d_interface = { + &Graphics3D_ContextLost, +}; + +} // namespace + +Graphics3DClient_Dev::Graphics3DClient_Dev(Instance* instance) + : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPGraphics3DInterface, + &graphics3d_interface); + associated_instance_->AddPerInstanceObject(kPPPGraphics3DInterface, this); +} + +Graphics3DClient_Dev::~Graphics3DClient_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPGraphics3DInterface, this); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/graphics_3d_client_dev.h b/ppapi/cpp/dev/graphics_3d_client_dev.h new file mode 100644 index 0000000..5f68fb2 --- /dev/null +++ b/ppapi/cpp/dev/graphics_3d_client_dev.h @@ -0,0 +1,36 @@ +// 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_DEV_GRAPHICS_3D_CLIENT_DEV_H_ +#define PPAPI_CPP_DEV_GRAPHICS_3D_CLIENT_DEV_H_ + +#include "ppapi/c/pp_stdint.h" + +namespace pp { + +class Instance; +class Rect; +class Scrollbar_Dev; +class Widget_Dev; + +// This class provides a C++ interface for callbacks related to 3D. You +// would normally use multiple inheritance to derive from this class in your +// instance. +class Graphics3DClient_Dev { + public: + Graphics3DClient_Dev(Instance* instance); + virtual ~Graphics3DClient_Dev(); + + /** + * Notification that the context was lost for the 3D devices. + */ + virtual void Graphics3DContextLost() = 0; + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_GRAPHICS_3D_CLIENT_DEV_H_ diff --git a/ppapi/cpp/dev/graphics_3d_dev.cc b/ppapi/cpp/dev/graphics_3d_dev.cc new file mode 100644 index 0000000..766b70c --- /dev/null +++ b/ppapi/cpp/dev/graphics_3d_dev.cc @@ -0,0 +1,117 @@ +// 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. + +#include "ppapi/cpp/dev/graphics_3d_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +extern "C" { +const PPB_OpenGLES_Dev* pepper_opengl_interface = NULL; +} + +namespace { + +DeviceFuncs<PPB_Graphics3D_Dev> graphics_3d_f(PPB_GRAPHICS_3D_DEV_INTERFACE); +DeviceFuncs<PPB_OpenGLES_Dev> opengles_f(PPB_OPENGLES_DEV_INTERFACE); + +inline void InitializeOpenGLCInterface() { + if (!pepper_opengl_interface) + pepper_opengl_interface = &(*opengles_f); +} + +} // namespace + +namespace pp { + +// static +bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, + int32_t *num_config) { + if (graphics_3d_f) + return graphics_3d_f->GetConfigs(configs, config_size, num_config); + return false; +} + +// static +bool Graphics3D_Dev::ChooseConfig(const int32_t *attrib_list, int32_t *configs, + int32_t config_size, int32_t *num_config) { + if (graphics_3d_f) + return graphics_3d_f->ChooseConfig(attrib_list, configs, config_size, + num_config); + return false; +} + +// static +bool Graphics3D_Dev::GetConfigAttrib(int32_t config, int32_t attribute, + int32_t *value) { + if (graphics_3d_f) + return graphics_3d_f->GetConfigAttrib(config, attribute, value); + return false; +} + +// static +const char* Graphics3D_Dev::QueryString(int32_t name) { + if (graphics_3d_f) + return graphics_3d_f->QueryString(name); + return NULL; +} + +// static +void* Graphics3D_Dev::GetProcAddress(const char* name) { + if (graphics_3d_f) + return graphics_3d_f->GetProcAddress(name); + return NULL; +} + +Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) { + if (graphics_3d_f && graphics_3d_f->IsGraphics3D(resource_id)) + return Graphics3D_Dev(resource_id); + return Graphics3D_Dev(); +} + +bool Graphics3D_Dev::ResetCurrent() { + return graphics_3d_f && graphics_3d_f->MakeCurent(0); +} + +Graphics3D_Dev Graphics3D_Dev::GetCurrentContext() { + if (graphics_3d_f) + return FromResource(graphics_3d_f->GetCurrentContext()); + return Graphics3D_Dev(); +} + +uint32_t Graphics3D_Dev::GetError() { + if (graphics_3d_f) + return graphics_3d_f->GetError(); + return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED; +} + +const PPB_OpenGLES_Dev* Graphics3D_Dev::GetImplementation() { + return &(*opengles_f); +} + +Graphics3D_Dev::Graphics3D_Dev(const Instance& instance, + int32_t config, + int32_t share_context, + const int32_t* attrib_list) { + if (graphics_3d_f && opengles_f) { + InitializeOpenGLCInterface(); + PassRefFromConstructor(graphics_3d_f->CreateContext(instance.pp_instance(), + config, share_context, + attrib_list)); + } +} + +bool Graphics3D_Dev::MakeCurrent() const { + InitializeOpenGLCInterface(); + return graphics_3d_f && graphics_3d_f->MakeCurent(pp_resource()); +} + +bool Graphics3D_Dev::SwapBuffers() const { + return graphics_3d_f && graphics_3d_f->SwapBuffers(pp_resource()); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/graphics_3d_dev.h b/ppapi/cpp/dev/graphics_3d_dev.h new file mode 100644 index 0000000..88fe47d --- /dev/null +++ b/ppapi/cpp/dev/graphics_3d_dev.h @@ -0,0 +1,54 @@ +// 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_DEV_GRAPHICS_3D_DEV_H_ +#define PPAPI_CPP_DEV_GRAPHICS_3D_DEV_H_ + +#include "ppapi/c/dev/ppb_graphics_3d_dev.h" +#include "ppapi/c/dev/ppb_opengles_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Graphics3D_Dev : public Resource { + public: + static bool GetConfigs(int32_t* configs, int32_t config_size, + int32_t* num_config); + + static bool ChooseConfig(const int32_t* attrib_list, int32_t* configs, + int32_t config_size, int32_t* num_config); + + static bool GetConfigAttrib(int32_t config, int32_t attribute, + int32_t* value); + + static const char* QueryString(int32_t name); + + static void* GetProcAddress(const char* name); + + static bool ResetCurrent(); + static Graphics3D_Dev GetCurrentContext(); + static uint32_t GetError(); + static const PPB_OpenGLES_Dev* GetImplementation(); + + // Creates an is_null() Graphics3D object. + Graphics3D_Dev() {} + + Graphics3D_Dev(const Instance& instance, + int32_t config, + int32_t share_context, + const int32_t* attrib_list); + + bool MakeCurrent() const; + bool SwapBuffers() const; + + protected: + explicit Graphics3D_Dev(PP_Resource resource_id) : Resource(resource_id) {} + static Graphics3D_Dev FromResource(PP_Resource resource_id); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_GRAPHICS_3D_DEV_H_ + diff --git a/ppapi/cpp/dev/printing_dev.cc b/ppapi/cpp/dev/printing_dev.cc new file mode 100644 index 0000000..a5aa361 --- /dev/null +++ b/ppapi/cpp/dev/printing_dev.cc @@ -0,0 +1,74 @@ +// 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. + +#include "ppapi/cpp/dev/printing_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE; + +PP_PrintOutputFormat_Dev* QuerySupportedFormats(PP_Instance instance, + uint32_t* format_count) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + if (!object) + return NULL; + return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats( + format_count); +} + +int32_t Begin(PP_Instance instance, + const struct PP_PrintSettings_Dev* print_settings) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + if (!object) + return 0; + return static_cast<Printing_Dev*>(object)->PrintBegin(*print_settings); +} + +PP_Resource PrintPages(PP_Instance instance, + const struct PP_PrintPageNumberRange_Dev* page_ranges, + uint32_t page_range_count) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + if (!object) + return 0; + return static_cast<Printing_Dev*>(object)->PrintPages( + page_ranges, page_range_count).detach(); +} + +void End(PP_Instance instance) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + if (object) + static_cast<Printing_Dev*>(object)->PrintEnd(); +} + +const PPP_Printing_Dev ppp_printing = { + &QuerySupportedFormats, + &Begin, + &PrintPages, + &End +}; + +} // namespace + +Printing_Dev::Printing_Dev(Instance* instance) + : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing); + associated_instance_->AddPerInstanceObject(kPPPPrintingInterface, this); +} + +Printing_Dev::~Printing_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPPrintingInterface, this); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/printing_dev.h b/ppapi/cpp/dev/printing_dev.h new file mode 100644 index 0000000..ca34ba3 --- /dev/null +++ b/ppapi/cpp/dev/printing_dev.h @@ -0,0 +1,38 @@ +// 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_DEV_PRINTING_DEV_H_ +#define PPAPI_CPP_DEV_PRINTING_DEV_H_ + +#include "ppapi/c/dev/ppp_printing_dev.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Instance; + +// You would typically use this either via inheritance on your instance or +// by composition: see find_dev.h for an example. +class Printing_Dev { + public: + // The instance parameter must outlive this class. + explicit Printing_Dev(Instance* instance); + virtual ~Printing_Dev(); + + // PPP_Printing_Dev functions exposed as virtual functions for you to + // override. + virtual PP_PrintOutputFormat_Dev* QuerySupportedPrintOutputFormats( + uint32_t* format_count) = 0; + virtual int32_t PrintBegin(const PP_PrintSettings_Dev& print_settings) = 0; + virtual Resource PrintPages(const PP_PrintPageNumberRange_Dev* page_ranges, + uint32_t page_range_count) = 0; + virtual void PrintEnd() = 0; + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_PRINTING_DEV_H_ diff --git a/ppapi/cpp/dev/scriptable_object_deprecated.cc b/ppapi/cpp/dev/scriptable_object_deprecated.cc new file mode 100644 index 0000000..59f44d1 --- /dev/null +++ b/ppapi/cpp/dev/scriptable_object_deprecated.cc @@ -0,0 +1,188 @@ +// 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. + +#include "ppapi/cpp/dev/scriptable_object_deprecated.h" + +#include "ppapi/c/dev/ppp_class_deprecated.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace deprecated { + +namespace { + +// Allows converting an output param of a Var to an output param of a PP_Var +// for exceptions. The object is only copied if it is not void, which we +// take to mean an exception occurred. +class ExceptionConverter { + public: + ExceptionConverter(PP_Var* out) : out_(out) { + } + ~ExceptionConverter() { + if (!exception_.is_undefined()) + *out_ = exception_.Detach(); + } + + Var* Get() { return &exception_; } + + private: + PP_Var* out_; + Var exception_; +}; + +// Used internally to convert a C-style array of PP_Var to a vector of Var. +void ArgListToVector(uint32_t argc, PP_Var* argv, std::vector<Var>* output) { + output->reserve(argc); + for (size_t i = 0; i < argc; i++) + output->push_back(Var(Var::DontManage(), argv[i])); +} + +bool HasProperty(void* object, PP_Var name, PP_Var* exception) { + ExceptionConverter e(exception); + return static_cast<ScriptableObject*>(object)->HasProperty( + Var(Var::DontManage(), name), e.Get()); +} + +bool HasMethod(void* object, PP_Var name, PP_Var* exception) { + ExceptionConverter e(exception); + return static_cast<ScriptableObject*>(object)->HasMethod( + Var(Var::DontManage(), name), e.Get()); +} + +PP_Var GetProperty(void* object, + PP_Var name, + PP_Var* exception) { + ExceptionConverter e(exception); + return static_cast<ScriptableObject*>(object)->GetProperty( + Var(Var::DontManage(), name), e.Get()).Detach(); +} + +void GetAllPropertyNames(void* object, + uint32_t* property_count, + PP_Var** properties, + PP_Var* exception) { + ExceptionConverter e(exception); + std::vector<Var> props; + static_cast<ScriptableObject*>(object)->GetAllPropertyNames(&props, e.Get()); + if (props.empty()) + return; + *property_count = static_cast<uint32_t>(props.size()); + *properties = static_cast<PP_Var*>( + Module::Get()->core()->MemAlloc(sizeof(PP_Var) * props.size())); + for (size_t i = 0; i < props.size(); ++i) + (*properties)[i] = props[i].Detach(); +} + +void SetProperty(void* object, + PP_Var name, + PP_Var value, + PP_Var* exception) { + ExceptionConverter e(exception); + static_cast<ScriptableObject*>(object)->SetProperty( + Var(Var::DontManage(), name), Var(Var::DontManage(), value), e.Get()); +} + +void RemoveProperty(void* object, + PP_Var name, + PP_Var* exception) { + ExceptionConverter e(exception); + static_cast<ScriptableObject*>(object)->RemoveProperty( + Var(Var::DontManage(), name), e.Get()); +} + +PP_Var Call(void* object, + PP_Var method_name, + uint32_t argc, + PP_Var* argv, + PP_Var* exception) { + ExceptionConverter e(exception); + + std::vector<Var> args; + ArgListToVector(argc, argv, &args); + return static_cast<ScriptableObject*>(object)->Call( + Var(Var::DontManage(), method_name), args, e.Get()).Detach(); +} + +PP_Var Construct(void* object, + uint32_t argc, + PP_Var* argv, + PP_Var* exception) { + ExceptionConverter e(exception); + + std::vector<Var> args; + ArgListToVector(argc, argv, &args); + return static_cast<ScriptableObject*>(object)->Construct( + args, e.Get()).Detach(); +} + +void Deallocate(void* object) { + delete static_cast<ScriptableObject*>(object); +} + +PPP_Class_Deprecated plugin_class = { + &HasProperty, + &HasMethod, + &GetProperty, + &GetAllPropertyNames, + &SetProperty, + &RemoveProperty, + &Call, + &Construct, + &Deallocate +}; + +} // namespace + +bool ScriptableObject::HasProperty(const Var& /*name*/, Var* /*exception*/) { + return false; +} + +bool ScriptableObject::HasMethod(const Var& /*name*/, Var* /*exception*/) { + return false; +} + +Var ScriptableObject::GetProperty(const Var& /*name*/, Var* exception) { + *exception = Var("Property does not exist on ScriptableObject"); + return Var(); +} + +void ScriptableObject::GetAllPropertyNames(std::vector<Var>* /*properties*/, + Var* /*exception*/) { +} + +void ScriptableObject::SetProperty(const Var& /*name*/, + const Var& /*value*/, + Var* exception) { + *exception = Var("Property can not be set on ScriptableObject"); +} + +void ScriptableObject::RemoveProperty(const Var& /*name*/, + Var* exception) { + *exception = Var( + "Property does does not exist to be removed in ScriptableObject"); +} + +Var ScriptableObject::Call(const Var& /*method_name*/, + const std::vector<Var>& /*args*/, + Var* exception) { + *exception = Var("Method does not exist to call in ScriptableObject"); + return Var(); +} + +Var ScriptableObject::Construct(const std::vector<Var>& /*args*/, + Var* exception) { + *exception = Var("Constuct method does not exist in ScriptableObject"); + return Var(); +} + +// static +const PPP_Class_Deprecated* ScriptableObject::GetClass() { + return &plugin_class; +} + +} // namespace deprecated + +} // namespace pp diff --git a/ppapi/cpp/dev/scriptable_object_deprecated.h b/ppapi/cpp/dev/scriptable_object_deprecated.h new file mode 100644 index 0000000..42ab466 --- /dev/null +++ b/ppapi/cpp/dev/scriptable_object_deprecated.h @@ -0,0 +1,92 @@ +// 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_SCRIPTABLE_OBJECT_DEPRECATED_H_ +#define PPAPI_CPP_SCRIPTABLE_OBJECT_DEPRECATED_H_ + +#include <vector> + +struct PPP_Class_Deprecated; + +namespace pp { +class Var; +} +using pp::Var; + +namespace pp { + +namespace deprecated { + +// This class allows you to implement objects accessible by JavaScript. Derive +// from this class and override the virtual functions you support. pp::Var has +// a constructor that takes a pointer to a ScriptableObject for when you want +// to convert your custom object to a var. +// +// Please see the PPB_Core C interface for more information on how to implement +// these functions. These functions are the backend implementation for the +// functions in PPB_Var, which contains further information. +// +// Please see: +// http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript +// for a general overview of interfacing with JavaScript. +class ScriptableObject { + public: + ScriptableObject() {} + virtual ~ScriptableObject() {} + + // The default implementation returns false. + virtual bool HasProperty(const Var& name, Var* exception); + + // The default implementation returns false. + virtual bool HasMethod(const Var& name, Var* exception); + + // The default implementation sets an exception that the property doesn't + // exist. + virtual Var GetProperty(const Var& name, Var* exception); + + // The default implementation returns no properties. + virtual void GetAllPropertyNames(std::vector<Var>* properties, + Var* exception); + + // The default implementation sets an exception that the property can not be + // set. + virtual void SetProperty(const Var& name, + const Var& value, + Var* exception); + + // The default implementation sets an exception that the method does not + // exist. + virtual void RemoveProperty(const Var& name, + Var* exception); + + // TODO(brettw) need native array access here. + + // method_name is guaranteed to be either a string or an integer. + // + // The default implementation sets an exception that the method does not + // exist. + virtual Var Call(const Var& method_name, + const std::vector<Var>& args, + Var* exception); + + // The default implementation sets an exception that the method does not + // exist. + virtual Var Construct(const std::vector<Var>& args, + Var* exception); + + private: + friend class ::pp::Var; + static const PPP_Class_Deprecated* GetClass(); + + // Unimplemented, copy and assigmnent is not allowed. + ScriptableObject(const ScriptableObject& other); + ScriptableObject& operator=(const ScriptableObject& other); +}; + +} // namespace deprecated + +} // namespace pp + +#endif // PPAPI_CPP_SCRIPTABLE_OBJECT_DEPRECATED_H_ + diff --git a/ppapi/cpp/dev/scrollbar_dev.cc b/ppapi/cpp/dev/scrollbar_dev.cc new file mode 100644 index 0000000..23395ef --- /dev/null +++ b/ppapi/cpp/dev/scrollbar_dev.cc @@ -0,0 +1,84 @@ +// 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. + +#include <vector> + +#include "ppapi/cpp/dev/scrollbar_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/rect.h" + +namespace { + +DeviceFuncs<PPB_Scrollbar_Dev> scrollbar_f(PPB_SCROLLBAR_DEV_INTERFACE); + +} // namespace + +namespace pp { + +Scrollbar_Dev::Scrollbar_Dev(PP_Resource resource) : Widget_Dev(resource) { +} + +Scrollbar_Dev::Scrollbar_Dev(const Instance& instance, bool vertical) { + if (!scrollbar_f) + return; + PassRefFromConstructor(scrollbar_f->Create(instance.pp_instance(), vertical)); +} + +Scrollbar_Dev::Scrollbar_Dev(const Scrollbar_Dev& other) + : Widget_Dev(other) { +} + +Scrollbar_Dev& Scrollbar_Dev::operator=(const Scrollbar_Dev& other) { + Scrollbar_Dev copy(other); + swap(copy); + return *this; +} + +void Scrollbar_Dev::swap(Scrollbar_Dev& other) { + Resource::swap(other); +} + +uint32_t Scrollbar_Dev::GetThickness() { + if (!scrollbar_f) + return 0; + return scrollbar_f->GetThickness(); +} + +uint32_t Scrollbar_Dev::GetValue() { + if (!scrollbar_f) + return 0; + return scrollbar_f->GetValue(pp_resource()); +} + +void Scrollbar_Dev::SetValue(uint32_t value) { + if (scrollbar_f) + scrollbar_f->SetValue(pp_resource(), value); +} + +void Scrollbar_Dev::SetDocumentSize(uint32_t size) { + if (scrollbar_f) + scrollbar_f->SetDocumentSize(pp_resource(), size); +} + +void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) { + if (!scrollbar_f) + return; + + std::vector<PP_Rect> temp; + temp.resize(count); + for (uint32_t i = 0; i < count; ++i) + temp[i] = tick_marks[i]; + + scrollbar_f->SetTickMarks(pp_resource(), count ? &temp[0] : NULL, count); +} + +void Scrollbar_Dev::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { + if (scrollbar_f) + scrollbar_f->ScrollBy(pp_resource(), unit, multiplier); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/scrollbar_dev.h b/ppapi/cpp/dev/scrollbar_dev.h new file mode 100644 index 0000000..0605641 --- /dev/null +++ b/ppapi/cpp/dev/scrollbar_dev.h @@ -0,0 +1,39 @@ +// 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_DEV_SCROLLBAR_DEV_H_ +#define PPAPI_CPP_DEV_SCROLLBAR_DEV_H_ + +#include "ppapi/c/dev/ppb_scrollbar_dev.h" +#include "ppapi/cpp/dev/widget_dev.h" + +namespace pp { + +class Instance; + +// This class allows a plugin to use the browser's scrollbar widget. +class Scrollbar_Dev : public Widget_Dev { + public: + // Creates an is_null() Scrollbar object. + Scrollbar_Dev() {} + + explicit Scrollbar_Dev(PP_Resource resource); + Scrollbar_Dev(const Instance& instance, bool vertical); + Scrollbar_Dev(const Scrollbar_Dev& other); + + Scrollbar_Dev& operator=(const Scrollbar_Dev& other); + void swap(Scrollbar_Dev& other); + + // PPB_Scrollbar methods: + static uint32_t GetThickness(); + uint32_t GetValue(); + void SetValue(uint32_t value); + void SetDocumentSize(uint32_t size); + void SetTickMarks(const Rect* tick_marks, uint32_t count); + void ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_SCROLLBAR_DEV_H_ diff --git a/ppapi/cpp/dev/selection_dev.cc b/ppapi/cpp/dev/selection_dev.cc new file mode 100644 index 0000000..6f1fcb7 --- /dev/null +++ b/ppapi/cpp/dev/selection_dev.cc @@ -0,0 +1,41 @@ +// 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. + +#include "ppapi/cpp/dev/selection_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +namespace { + +static const char kPPPSelectionInterface[] = PPP_SELECTION_DEV_INTERFACE; + +PP_Var GetSelectedText(PP_Instance instance, bool html) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPSelectionInterface); + if (!object) + return Var().Detach(); + return static_cast<Selection_Dev*>(object)->GetSelectedText(html).Detach(); +} + +const PPP_Selection_Dev ppp_selection = { + &GetSelectedText +}; + +} // namespace + +Selection_Dev::Selection_Dev(Instance* instance) + : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPSelectionInterface, &ppp_selection); + associated_instance_->AddPerInstanceObject(kPPPSelectionInterface, this); +} + +Selection_Dev::~Selection_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPSelectionInterface, this); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/selection_dev.h b/ppapi/cpp/dev/selection_dev.h new file mode 100644 index 0000000..282bdb4 --- /dev/null +++ b/ppapi/cpp/dev/selection_dev.h @@ -0,0 +1,52 @@ +// 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_DEV_SELECTION_DEV_H_ +#define PPAPI_CPP_DEV_SELECTION_DEV_H_ + +#include "ppapi/c/dev/ppp_selection_dev.h" + +namespace pp { + +class Instance; +class Var; + +// This class allows you to associate the PPP_Selection_Dev C-based interface +// with an object. It registers as the global handler for handling the +// PPP_Selection_Dev interface that the browser calls. +// +// You would typically use this either via inheritance on your instance: +// class MyInstance : public pp::Instance, public pp::Selection_Dev { +// class MyInstance() : pp::Selection_Dev(this) { +// } +// ... +// }; +// +// or by composition: +// class MySelection : public pp::Selection_Dev { +// ... +// }; +// +// class MyInstance : public pp::Instance { +// MyInstance() : selection_(this) { +// } +// +// MySelection selection_; +// }; +class Selection_Dev { + public: + Selection_Dev(Instance* instance); + virtual ~Selection_Dev(); + + // PPP_Selection_Dev functions exposed as virtual functions for you to + // override. + virtual Var GetSelectedText(bool html) = 0; + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_SELECTION_DEV_H_ diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc new file mode 100644 index 0000000..f7eae6b --- /dev/null +++ b/ppapi/cpp/dev/transport_dev.cc @@ -0,0 +1,28 @@ +// 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. + +#include "ppapi/cpp/dev/transport_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_Transport_Dev> transport_f(PPB_TRANSPORT_DEV_INTERFACE); + +} // namespace + +namespace pp { + +Transport_Dev::Transport_Dev(const char* name, + const char* proto) { + if (transport_f) + PassRefFromConstructor( + transport_f->CreateTransport(Module::Get()->pp_module(), name, proto)); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/transport_dev.h b/ppapi/cpp/dev/transport_dev.h new file mode 100644 index 0000000..a9b73c2 --- /dev/null +++ b/ppapi/cpp/dev/transport_dev.h @@ -0,0 +1,23 @@ +// 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_DEV_TRANSPORT_DEV_H_ +#define PPAPI_CPP_DEV_TRANSPORT_DEV_H_ + +#include "ppapi/c/dev/ppb_transport_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Transport_Dev : public Resource { + public: + Transport_Dev() {} + Transport_Dev(const char* name, const char* proto); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_TRANSPORT_DEV_H_ + diff --git a/ppapi/cpp/dev/url_loader_dev.cc b/ppapi/cpp/dev/url_loader_dev.cc new file mode 100644 index 0000000..5c63f3d --- /dev/null +++ b/ppapi/cpp/dev/url_loader_dev.cc @@ -0,0 +1,115 @@ +// 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. + +#include "ppapi/cpp/dev/url_loader_dev.h" + +#include "ppapi/c/dev/ppb_url_loader_dev.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/dev/url_request_info_dev.h" +#include "ppapi/cpp/dev/url_response_info_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_URLLoader_Dev> url_loader_f(PPB_URLLOADER_DEV_INTERFACE); + +} // namespace + +namespace pp { + +URLLoader_Dev::URLLoader_Dev(PP_Resource resource) : Resource(resource) { +} + +URLLoader_Dev::URLLoader_Dev(const Instance& instance) { + if (!url_loader_f) + return; + PassRefFromConstructor(url_loader_f->Create(instance.pp_instance())); +} + +URLLoader_Dev::URLLoader_Dev(const URLLoader_Dev& other) + : Resource(other) { +} + +URLLoader_Dev& URLLoader_Dev::operator=(const URLLoader_Dev& other) { + URLLoader_Dev copy(other); + swap(copy); + return *this; +} + +void URLLoader_Dev::swap(URLLoader_Dev& other) { + Resource::swap(other); +} + +int32_t URLLoader_Dev::Open(const URLRequestInfo_Dev& request_info, + const CompletionCallback& cc) { + if (!url_loader_f) + return PP_ERROR_NOINTERFACE; + return url_loader_f->Open(pp_resource(), request_info.pp_resource(), + cc.pp_completion_callback()); +} + +int32_t URLLoader_Dev::FollowRedirect(const CompletionCallback& cc) { + if (!url_loader_f) + return PP_ERROR_NOINTERFACE; + return url_loader_f->FollowRedirect(pp_resource(), + cc.pp_completion_callback()); +} + +bool URLLoader_Dev::GetUploadProgress(int64_t* bytes_sent, + int64_t* total_bytes_to_be_sent) const { + if (!url_loader_f) + return false; + return url_loader_f->GetUploadProgress( + pp_resource(), + bytes_sent, + total_bytes_to_be_sent); +} + +bool URLLoader_Dev::GetDownloadProgress( + int64_t* bytes_received, + int64_t* total_bytes_to_be_received) const { + if (!url_loader_f) + return false; + return url_loader_f->GetDownloadProgress( + pp_resource(), + bytes_received, + total_bytes_to_be_received); +} + +URLResponseInfo_Dev URLLoader_Dev::GetResponseInfo() const { + if (!url_loader_f) + return URLResponseInfo_Dev(); + return URLResponseInfo_Dev(URLResponseInfo_Dev::PassRef(), + url_loader_f->GetResponseInfo(pp_resource())); +} + +int32_t URLLoader_Dev::ReadResponseBody(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& cc) { + if (!url_loader_f) + return PP_ERROR_NOINTERFACE; + return url_loader_f->ReadResponseBody(pp_resource(), + buffer, + bytes_to_read, + cc.pp_completion_callback()); +} + +int32_t URLLoader_Dev::FinishStreamingToFile(const CompletionCallback& cc) { + if (!url_loader_f) + return PP_ERROR_NOINTERFACE; + return url_loader_f->FinishStreamingToFile(pp_resource(), + cc.pp_completion_callback()); +} + +void URLLoader_Dev::Close() { + if (!url_loader_f) + return; + url_loader_f->Close(pp_resource()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/url_loader_dev.h b/ppapi/cpp/dev/url_loader_dev.h new file mode 100644 index 0000000..4256c32 --- /dev/null +++ b/ppapi/cpp/dev/url_loader_dev.h @@ -0,0 +1,108 @@ +// 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_DEV_URL_LOADER_DEV_H_ +#define PPAPI_CPP_DEV_URL_LOADER_DEV_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class CompletionCallback; +class Instance; +class URLRequestInfo_Dev; +class URLResponseInfo_Dev; + +// URLLoader provides an API to download URLs. +// +// EXAMPLE USAGE: +// +// class MyHandler { +// public: +// MyHandler(const Instance& instance) +// : factory_(this), +// loader_(instance), +// did_open_(false) { +// } +// void ProcessURL(const char* url) { +// CompletionCallback* cc = NewCallback(); +// int32_t rv = loader_.Open(MakeRequest(url), cc); +// if (rv != PP_Error_WouldBlock) +// cc->Run(rv); +// } +// private: +// CompletionCallback* NewCallback() { +// return factory_.NewCallback(&MyHandler::DidCompleteIO); +// } +// URLRequestInfo MakeRequest(const char* url) { +// URLRequestInfo request; +// request.SetURL(url); +// request.SetMethod("GET"); +// request.SetFollowRedirects(true); +// return request; +// } +// void DidCompleteIO(int32_t result) { +// if (result > 0) { +// // buf_ now contains 'result' number of bytes from the URL. +// ProcessBytes(buf_, result); +// ReadMore(); +// } else if (result == PP_OK && !did_open_) { +// // Headers are available, and we can start reading the body. +// did_open_ = true; +// ProcessResponseInfo(loader_.GetResponseInfo()); +// ReadMore(); +// } else { +// // Done reading (possibly with an error given by 'result'). +// } +// } +// void ReadMore() { +// CompletionCallback* cc = NewCallback(); +// int32_t rv = fio_.Read(offset_, buf_, sizeof(buf_), cc); +// if (rv != PP_Error_WouldBlock) +// cc->Run(rv); +// } +// void ProcessResponseInfo(const URLResponseInfo& response_info) { +// // Read response headers, etc. +// } +// void ProcessBytes(const char* bytes, int32_t length) { +// // Do work ... +// } +// pp::CompletionCallbackFactory<MyHandler> factory_; +// pp::URLLoader loader_; +// char buf_[4096]; +// bool did_open_; +// }; +// +class URLLoader_Dev : public Resource { + public: + // Creates an is_null() URLLoader object. + URLLoader_Dev() {} + + explicit URLLoader_Dev(PP_Resource resource); + explicit URLLoader_Dev(const Instance& instance); + URLLoader_Dev(const URLLoader_Dev& other); + + URLLoader_Dev& operator=(const URLLoader_Dev& other); + void swap(URLLoader_Dev& other); + + // PPB_URLLoader methods: + int32_t Open(const URLRequestInfo_Dev& request_info, + const CompletionCallback& cc); + int32_t FollowRedirect(const CompletionCallback& cc); + bool GetUploadProgress(int64_t* bytes_sent, + int64_t* total_bytes_to_be_sent) const; + bool GetDownloadProgress(int64_t* bytes_received, + int64_t* total_bytes_to_be_received) const; + URLResponseInfo_Dev GetResponseInfo() const; + int32_t ReadResponseBody(char* buffer, + int32_t bytes_to_read, + const CompletionCallback& cc); + int32_t FinishStreamingToFile(const CompletionCallback& cc); + void Close(); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_URL_LOADER_DEV_H_ diff --git a/ppapi/cpp/dev/url_request_info_dev.cc b/ppapi/cpp/dev/url_request_info_dev.cc new file mode 100644 index 0000000..faf975c5 --- /dev/null +++ b/ppapi/cpp/dev/url_request_info_dev.cc @@ -0,0 +1,81 @@ +// 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. + +#include "ppapi/cpp/dev/url_request_info_dev.h" + +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_URLRequestInfo_Dev> url_request_info_f( + PPB_URLREQUESTINFO_DEV_INTERFACE); + +} // namespace + +namespace pp { + +URLRequestInfo_Dev::URLRequestInfo_Dev() { + if (!url_request_info_f) + return; + PassRefFromConstructor( + url_request_info_f->Create(Module::Get()->pp_module())); +} + +URLRequestInfo_Dev::URLRequestInfo_Dev(const URLRequestInfo_Dev& other) + : Resource(other) { +} + +URLRequestInfo_Dev& URLRequestInfo_Dev::operator=( + const URLRequestInfo_Dev& other) { + URLRequestInfo_Dev copy(other); + swap(copy); + return *this; +} + +void URLRequestInfo_Dev::swap(URLRequestInfo_Dev& other) { + Resource::swap(other); +} + +bool URLRequestInfo_Dev::SetProperty(PP_URLRequestProperty_Dev property, + const Var& value) { + if (!url_request_info_f) + return false; + return url_request_info_f->SetProperty(pp_resource(), + property, + value.pp_var()); +} + +bool URLRequestInfo_Dev::AppendDataToBody(const char* data, uint32_t len) { + if (!url_request_info_f) + return false; + return url_request_info_f->AppendDataToBody(pp_resource(), data, len); +} + +bool URLRequestInfo_Dev::AppendFileToBody( + const FileRef_Dev& file_ref, + PP_Time expected_last_modified_time) { + if (!url_request_info_f) + return false; + return url_request_info_f->AppendFileToBody(pp_resource(), + file_ref.pp_resource(), + 0, + -1, + expected_last_modified_time); +} + +bool URLRequestInfo_Dev::AppendFileRangeToBody( + const FileRef_Dev& file_ref, + int64_t start_offset, + int64_t length, + PP_Time expected_last_modified_time) { + return url_request_info_f->AppendFileToBody(pp_resource(), + file_ref.pp_resource(), + start_offset, + length, + expected_last_modified_time); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/url_request_info_dev.h b/ppapi/cpp/dev/url_request_info_dev.h new file mode 100644 index 0000000..1d56543 --- /dev/null +++ b/ppapi/cpp/dev/url_request_info_dev.h @@ -0,0 +1,57 @@ +// 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_DEV_URL_REQUEST_INFO_DEV_H_ +#define PPAPI_CPP_DEV_URL_REQUEST_INFO_DEV_H_ + +#include "ppapi/c/dev/ppb_url_request_info_dev.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class FileRef_Dev; + +class URLRequestInfo_Dev : public Resource { + public: + URLRequestInfo_Dev(); + URLRequestInfo_Dev(const URLRequestInfo_Dev& other); + + URLRequestInfo_Dev& operator=(const URLRequestInfo_Dev& other); + void swap(URLRequestInfo_Dev& other); + + // PPB_URLRequestInfo_Dev methods: + bool SetProperty(PP_URLRequestProperty_Dev property, const Var& value); + bool AppendDataToBody(const char* data, uint32_t len); + bool AppendFileToBody(const FileRef_Dev& file_ref, + PP_Time expected_last_modified_time = 0); + bool AppendFileRangeToBody(const FileRef_Dev& file_ref, + int64_t start_offset, + int64_t length, + PP_Time expected_last_modified_time = 0); + + // Convenient helpers for setting properties: + bool SetURL(const Var& url_string) { + return SetProperty(PP_URLREQUESTPROPERTY_URL, url_string); + } + bool SetMethod(const Var& method_string) { + return SetProperty(PP_URLREQUESTPROPERTY_METHOD, method_string); + } + bool SetHeaders(const Var& headers_string) { + return SetProperty(PP_URLREQUESTPROPERTY_HEADERS, headers_string); + } + bool SetStreamToFile(bool enable) { + return SetProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, enable); + } + bool SetFollowRedirects(bool enable) { + return SetProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, enable); + } + bool SetRecordUploadProgress(bool enable) { + return SetProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, enable); + } +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_URL_REQUEST_INFO_DEV_H_ diff --git a/ppapi/cpp/dev/url_response_info_dev.cc b/ppapi/cpp/dev/url_response_info_dev.cc new file mode 100644 index 0000000..abeca7f --- /dev/null +++ b/ppapi/cpp/dev/url_response_info_dev.cc @@ -0,0 +1,54 @@ +// 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. + +#include "ppapi/cpp/dev/url_response_info_dev.h" + +#include "ppapi/cpp/dev/file_ref_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_URLResponseInfo_Dev> url_response_info_f( + PPB_URLRESPONSEINFO_DEV_INTERFACE); + +} // namespace + +namespace pp { + +URLResponseInfo_Dev::URLResponseInfo_Dev(const URLResponseInfo_Dev& other) + : Resource(other) { +} + +URLResponseInfo_Dev::URLResponseInfo_Dev(PassRef, PP_Resource resource) { + PassRefFromConstructor(resource); +} + +URLResponseInfo_Dev& URLResponseInfo_Dev::operator=( + const URLResponseInfo_Dev& other) { + URLResponseInfo_Dev copy(other); + swap(copy); + return *this; +} + +void URLResponseInfo_Dev::swap(URLResponseInfo_Dev& other) { + Resource::swap(other); +} + +Var URLResponseInfo_Dev::GetProperty( + PP_URLResponseProperty_Dev property) const { + if (!url_response_info_f) + return Var(); + return Var(Var::PassRef(), + url_response_info_f->GetProperty(pp_resource(), property)); +} + +FileRef_Dev URLResponseInfo_Dev::GetBody() const { + if (!url_response_info_f) + return FileRef_Dev(); + return FileRef_Dev(FileRef_Dev::PassRef(), + url_response_info_f->GetBody(pp_resource())); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/url_response_info_dev.h b/ppapi/cpp/dev/url_response_info_dev.h new file mode 100644 index 0000000..6596c8b --- /dev/null +++ b/ppapi/cpp/dev/url_response_info_dev.h @@ -0,0 +1,58 @@ +// 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_DEV_URL_RESPONSE_INFO_DEV_H_ +#define PPAPI_CPP_DEV_URL_RESPONSE_INFO_DEV_H_ + +#include "ppapi/c/dev/ppb_url_response_info_dev.h" +#include "ppapi/cpp/resource.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class FileRef_Dev; + +class URLResponseInfo_Dev : public Resource { + public: + // Creates an is_null() URLResponseInfo object. + URLResponseInfo_Dev() {} + + // This constructor is used when we've gotten a PP_Resource as a return value + // that has already been addref'ed for us. + struct PassRef {}; + URLResponseInfo_Dev(PassRef, PP_Resource resource); + + URLResponseInfo_Dev(const URLResponseInfo_Dev& other); + + URLResponseInfo_Dev& operator=(const URLResponseInfo_Dev& other); + void swap(URLResponseInfo_Dev& other); + + // PPB_URLResponseInfo methods: + Var GetProperty(PP_URLResponseProperty_Dev property) const; + FileRef_Dev GetBody() const; + + // Convenient helpers for getting properties: + Var GetURL() const { + return GetProperty(PP_URLRESPONSEPROPERTY_URL); + } + Var GetRedirectURL() const { + return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTURL); + } + Var GetRedirectMethod() const { + return GetProperty(PP_URLRESPONSEPROPERTY_REDIRECTMETHOD); + } + int32_t GetStatusCode() const { + return GetProperty(PP_URLRESPONSEPROPERTY_STATUSCODE).AsInt(); + } + Var GetStatusLine() const { + return GetProperty(PP_URLRESPONSEPROPERTY_STATUSLINE); + } + Var GetHeaders() const { + return GetProperty(PP_URLRESPONSEPROPERTY_HEADERS); + } +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_URL_RESPONSE_INFO_DEV_H_ diff --git a/ppapi/cpp/dev/url_util_dev.cc b/ppapi/cpp/dev/url_util_dev.cc new file mode 100644 index 0000000..82e1974 --- /dev/null +++ b/ppapi/cpp/dev/url_util_dev.cc @@ -0,0 +1,70 @@ +// 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. + +#include "ppapi/cpp/dev/url_util_dev.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" + +namespace pp { + +// static +const UrlUtil_Dev* UrlUtil_Dev::Get() { + static bool tried_to_init = false; + static UrlUtil_Dev util; + + if (!tried_to_init) { + tried_to_init = true; + util.interface_ = static_cast<const PPB_UrlUtil_Dev*>( + Module::Get()->GetBrowserInterface(PPB_URLUTIL_DEV_INTERFACE)); + } + + if (!util.interface_) + return NULL; + return &util; +} + +Var UrlUtil_Dev::Canonicalize(const Var& url, + PP_UrlComponents_Dev* components) const { + return Var(Var::PassRef(), + interface_->Canonicalize(url.pp_var(), components)); +} + +Var UrlUtil_Dev::ResolveRelativeToUrl(const Var& base_url, + const Var& relative_string, + PP_UrlComponents_Dev* components) const { + return Var(Var::PassRef(), + interface_->ResolveRelativeToUrl(base_url.pp_var(), + relative_string.pp_var(), + components)); +} + +Var UrlUtil_Dev::ResoveRelativeToDocument( + const Instance& instance, + const Var& relative_string, + PP_UrlComponents_Dev* components) const { + return Var(Var::PassRef(), + interface_->ResolveRelativeToDocument(instance.pp_instance(), + relative_string.pp_var(), + components)); +} + +bool UrlUtil_Dev::IsSameSecurityOrigin(const Var& url_a, + const Var& url_b) const { + return interface_->IsSameSecurityOrigin(url_a.pp_var(), url_b.pp_var()); +} + +bool UrlUtil_Dev::DocumentCanRequest(const Instance& instance, + const Var& url) const { + return interface_->DocumentCanRequest(instance.pp_instance(), url.pp_var()); +} + +bool UrlUtil_Dev::DocumentCanAccessDocument(const Instance& active, + const Instance& target) const { + return interface_->DocumentCanAccessDocument(active.pp_instance(), + target.pp_instance()); +} + +} // namespace pp + diff --git a/ppapi/cpp/dev/url_util_dev.h b/ppapi/cpp/dev/url_util_dev.h new file mode 100644 index 0000000..3be217e --- /dev/null +++ b/ppapi/cpp/dev/url_util_dev.h @@ -0,0 +1,54 @@ +// 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_DEV_URL_UTIL_DEV_H_ +#define PPAPI_CPP_DEV_URL_UTIL_DEV_H_ + +#include "ppapi/c/dev/ppb_url_util_dev.h" +#include "ppapi/cpp/var.h" + +namespace pp { + +class Instance; +class Module; + +// Simple wrapper around the PPB_UrlUtil interface. +class UrlUtil_Dev { + public: + // This class is just a collection of random functions that aren't + // particularly attached to anything. So this getter returns a cached + // instance of this interface. This may return NULL if the browser doesn't + // support the UrlUtil inteface. Since this is a singleton, don't delete the + // pointer. + static const UrlUtil_Dev* Get(); + + Var Canonicalize(const Var& url, + PP_UrlComponents_Dev* components = NULL) const; + + Var ResolveRelativeToUrl(const Var& base_url, + const Var& relative_string, + PP_UrlComponents_Dev* components = NULL) const; + Var ResoveRelativeToDocument(const Instance& instance, + const Var& relative_string, + PP_UrlComponents_Dev* components = NULL) const; + + bool IsSameSecurityOrigin(const Var& url_a, const Var& url_b) const; + bool DocumentCanRequest(const Instance& instance, const Var& url) const; + bool DocumentCanAccessDocument(const Instance& active, + const Instance& target) const; + + private: + UrlUtil_Dev() : interface_(NULL) {} + + // Copy and assignment are disallowed. + UrlUtil_Dev(const UrlUtil_Dev& other); + UrlUtil_Dev& operator=(const UrlUtil_Dev& other); + + const PPB_UrlUtil_Dev* interface_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_URL_UTIL_DEV_H_ + diff --git a/ppapi/cpp/dev/video_decoder_dev.cc b/ppapi/cpp/dev/video_decoder_dev.cc new file mode 100644 index 0000000..298bad4 --- /dev/null +++ b/ppapi/cpp/dev/video_decoder_dev.cc @@ -0,0 +1,84 @@ +// 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. + +#include "ppapi/cpp/dev/video_decoder_dev.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_VideoDecoder_Dev> video_decoder_f( + PPB_VIDEODECODER_DEV_INTERFACE); + +} // namespace + + +namespace pp { + +VideoDecoder_Dev::VideoDecoder_Dev(PP_Resource resource) : Resource(resource) { +} + +VideoDecoder_Dev::VideoDecoder_Dev( + const Instance& instance, + const PP_VideoDecoderConfig_Dev& decoder_config) { + if (!video_decoder_f) + return; + PassRefFromConstructor(video_decoder_f->Create(instance.pp_instance(), + &decoder_config)); +} + +VideoDecoder_Dev::VideoDecoder_Dev(const VideoDecoder_Dev& other) + : Resource(other) { +} + +VideoDecoder_Dev& VideoDecoder_Dev::operator=(const VideoDecoder_Dev& other) { + VideoDecoder_Dev copy(other); + swap(copy); + return *this; +} + +void VideoDecoder_Dev::swap(VideoDecoder_Dev& other) { + Resource::swap(other); +} + +// static +bool VideoDecoder_Dev::GetConfig(const Instance& instance, + PP_VideoCodecId_Dev codec, + PP_VideoConfig_Dev* configs, + int32_t config_size, + int32_t* num_config) { + if (!video_decoder_f) + return false; + return video_decoder_f->GetConfig(instance.pp_instance(), + codec, + configs, + config_size, + num_config); +} + +bool VideoDecoder_Dev::Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer) { + if (!video_decoder_f || !pp_resource()) + return false; + return video_decoder_f->Decode(pp_resource(), + &input_buffer); +} + +int32_t VideoDecoder_Dev::Flush(PP_CompletionCallback callback) { + if (!video_decoder_f) + return PP_ERROR_NOINTERFACE; + return video_decoder_f->Flush(pp_resource(), callback); +} + +bool VideoDecoder_Dev::ReturnUncompressedDataBuffer( + PP_VideoUncompressedDataBuffer_Dev& buffer) { + if (!video_decoder_f || !pp_resource()) + return false; + return video_decoder_f->ReturnUncompressedDataBuffer(pp_resource(), + &buffer); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/video_decoder_dev.h b/ppapi/cpp/dev/video_decoder_dev.h new file mode 100644 index 0000000..0ee6fc96 --- /dev/null +++ b/ppapi/cpp/dev/video_decoder_dev.h @@ -0,0 +1,47 @@ +// 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_DEV_VIDEO_DECODER_DEV_H_ +#define PPAPI_CPP_DEV_VIDEO_DECODER_DEV_H_ + +#include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/c/dev/ppb_video_decoder_dev.h" +#include "ppapi/cpp/resource.h" + +namespace pp { + +class Instance; + +// Provides access to video decoders. +class VideoDecoder_Dev : public Resource { + public: + // Creates an is_null() VideoDecoder object. + VideoDecoder_Dev() {} + + explicit VideoDecoder_Dev(PP_Resource resource); + + VideoDecoder_Dev(const Instance& instance, + const PP_VideoDecoderConfig_Dev& decoder_config); + VideoDecoder_Dev(const VideoDecoder_Dev& other); + + VideoDecoder_Dev& operator=(const VideoDecoder_Dev& other); + void swap(VideoDecoder_Dev& other); + + // PPB_VideoDecoder methods: + static bool GetConfig(const Instance& instance, + PP_VideoCodecId_Dev codec, + PP_VideoConfig_Dev* configs, + int32_t config_size, + int32_t* num_config); + + bool Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer); + + int32_t Flush(PP_CompletionCallback callback); + + bool ReturnUncompressedDataBuffer(PP_VideoUncompressedDataBuffer_Dev& buffer); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_VIDEO_DECODER_DEV_H_ diff --git a/ppapi/cpp/dev/widget_client_dev.cc b/ppapi/cpp/dev/widget_client_dev.cc new file mode 100644 index 0000000..8407810 --- /dev/null +++ b/ppapi/cpp/dev/widget_client_dev.cc @@ -0,0 +1,74 @@ +// 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. + +#include "ppapi/cpp/dev/widget_client_dev.h" + +#include "ppapi/c/dev/ppp_scrollbar_dev.h" +#include "ppapi/c/dev/ppp_widget_dev.h" +#include "ppapi/cpp/dev/scrollbar_dev.h" +#include "ppapi/cpp/dev/widget_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" +#include "ppapi/cpp/rect.h" + +namespace pp { + +namespace { + +// PPP_Widget_Dev -------------------------------------------------------------- + +const char kPPPWidgetInterface[] = PPP_WIDGET_DEV_INTERFACE; + +void Widget_Invalidate(PP_Instance instance, + PP_Resource widget_id, + const PP_Rect* dirty_rect) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPWidgetInterface); + if (!object) + return; + return static_cast<WidgetClient_Dev*>(object)->InvalidateWidget( + Widget_Dev(widget_id), *dirty_rect); +} + +static PPP_Widget_Dev widget_interface = { + &Widget_Invalidate, +}; + +// PPP_Scrollbar_Dev ----------------------------------------------------------- + +const char kPPPScrollbarInterface[] = PPP_SCROLLBAR_DEV_INTERFACE; + +void Scrollbar_ValueChanged(PP_Instance instance, + PP_Resource scrollbar_id, + uint32_t value) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPScrollbarInterface); + if (!object) + return; + return static_cast<WidgetClient_Dev*>(object)->ScrollbarValueChanged( + Scrollbar_Dev(scrollbar_id), value); +} + +static PPP_Scrollbar_Dev scrollbar_interface = { + &Scrollbar_ValueChanged, +}; + +} // namespace + +WidgetClient_Dev::WidgetClient_Dev(Instance* instance) + : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPWidgetInterface, &widget_interface); + associated_instance_->AddPerInstanceObject(kPPPWidgetInterface, this); + pp::Module::Get()->AddPluginInterface(kPPPScrollbarInterface, + &scrollbar_interface); + associated_instance_->AddPerInstanceObject(kPPPScrollbarInterface, this); +} + +WidgetClient_Dev::~WidgetClient_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPScrollbarInterface, this); + associated_instance_->RemovePerInstanceObject(kPPPWidgetInterface, this); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/widget_client_dev.h b/ppapi/cpp/dev/widget_client_dev.h new file mode 100644 index 0000000..a8910e8 --- /dev/null +++ b/ppapi/cpp/dev/widget_client_dev.h @@ -0,0 +1,44 @@ +// 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_DEV_WIDGET_CLIENT_DEV_H_ +#define PPAPI_CPP_DEV_WIDGET_CLIENT_DEV_H_ + +#include "ppapi/c/pp_stdint.h" + +namespace pp { + +class Instance; +class Rect; +class Scrollbar_Dev; +class Widget_Dev; + +// This class provides a C++ interface for callbacks related to widgets. You +// would normally use multiple inheritance to derive from this class in your +// instance. +class WidgetClient_Dev { + public: + WidgetClient_Dev(Instance* instance); + virtual ~WidgetClient_Dev(); + + /** + * Notification that the given widget should be repainted. This is the + * implementation for PPP_Widget_Dev. + */ + virtual void InvalidateWidget(Widget_Dev widget, const Rect& dirty_rect) = 0; + + /** + * Notification that the given scrollbar should change value. This is the + * implementation for PPP_Scrollbar_Dev. + */ + virtual void ScrollbarValueChanged(Scrollbar_Dev scrollbar, + uint32_t value) = 0; + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_WIDGET_CLIENT_DEV_H_ diff --git a/ppapi/cpp/dev/widget_dev.cc b/ppapi/cpp/dev/widget_dev.cc new file mode 100644 index 0000000..e3c94ee --- /dev/null +++ b/ppapi/cpp/dev/widget_dev.cc @@ -0,0 +1,62 @@ +// 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. + +#include "ppapi/cpp/dev/widget_dev.h" + +#include "ppapi/c/dev/ppb_widget_dev.h" +#include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/rect.h" +#include "ppapi/cpp/module_impl.h" + +namespace { + +DeviceFuncs<PPB_Widget_Dev> widget_f(PPB_WIDGET_DEV_INTERFACE); + +} // namespace + +namespace pp { + +Widget_Dev::Widget_Dev(PP_Resource resource) : Resource(resource) { +} + +Widget_Dev::Widget_Dev(const Widget_Dev& other) : Resource(other) { +} + +Widget_Dev& Widget_Dev::operator=(const Widget_Dev& other) { + Widget_Dev copy(other); + swap(copy); + return *this; +} + +void Widget_Dev::swap(Widget_Dev& other) { + Resource::swap(other); +} + +bool Widget_Dev::Paint(const Rect& rect, ImageData* image) { + if (!widget_f) + return false; + return widget_f->Paint( + pp_resource(), &rect.pp_rect(), image->pp_resource()); +} + +bool Widget_Dev::HandleEvent(const PP_InputEvent& event) { + if (!widget_f) + return false; + return widget_f->HandleEvent(pp_resource(), &event); +} + +bool Widget_Dev::GetLocation(Rect* location) { + if (!widget_f) + return false; + return widget_f->GetLocation(pp_resource(), &location->pp_rect()); +} + +void Widget_Dev::SetLocation(const Rect& location) { + if (widget_f) + widget_f->SetLocation(pp_resource(), &location.pp_rect()); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/widget_dev.h b/ppapi/cpp/dev/widget_dev.h new file mode 100644 index 0000000..59ca60d --- /dev/null +++ b/ppapi/cpp/dev/widget_dev.h @@ -0,0 +1,41 @@ +// 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_DEV_WIDGET_DEV_H_ +#define PPAPI_CPP_DEV_WIDGET_DEV_H_ + +#include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/resource.h" + +struct PP_InputEvent; + +namespace pp { + +class ImageData; +class Instance; +class Rect; + +// This is the base class for widget elements. As such, it can't be created +// directly. +class Widget_Dev : public Resource { + public: + // Creates an is_null() Widget object. + Widget_Dev() {} + + explicit Widget_Dev(PP_Resource resource); + Widget_Dev(const Widget_Dev& other); + + Widget_Dev& operator=(const Widget_Dev& other); + void swap(Widget_Dev& other); + + // PPB_Widget methods: + bool Paint(const Rect& rect, ImageData* image); + bool HandleEvent(const PP_InputEvent& event); + bool GetLocation(Rect* location); + void SetLocation(const Rect& location); +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_WIDGET_DEV_H_ diff --git a/ppapi/cpp/dev/zoom_dev.cc b/ppapi/cpp/dev/zoom_dev.cc new file mode 100644 index 0000000..43966b3 --- /dev/null +++ b/ppapi/cpp/dev/zoom_dev.cc @@ -0,0 +1,58 @@ +// 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. + +#include "ppapi/cpp/dev/zoom_dev.h" + +#include "ppapi/c/dev/ppb_zoom_dev.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +static const char kPPPZoomInterface[] = PPP_ZOOM_DEV_INTERFACE; + +void Zoom(PP_Instance instance, + double factor, + bool text_only) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPZoomInterface); + if (!object) + return; + static_cast<Zoom_Dev*>(object)->Zoom(factor, text_only); +} + +const PPP_Zoom_Dev ppp_zoom = { + &Zoom +}; + +DeviceFuncs<PPB_Zoom_Dev> ppb_zoom_f(PPB_ZOOM_DEV_INTERFACE); + +} // namespace + +Zoom_Dev::Zoom_Dev(Instance* instance) : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPZoomInterface, &ppp_zoom); + associated_instance_->AddPerInstanceObject(kPPPZoomInterface, this); +} + +Zoom_Dev::~Zoom_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPZoomInterface, this); +} + +void Zoom_Dev::ZoomChanged(double factor) { + if (ppb_zoom_f) + ppb_zoom_f->ZoomChanged(associated_instance_->pp_instance(), factor); +} + +void Zoom_Dev::ZoomLimitsChanged(double minimum_factor, + double maximium_factor) { + if (!ppb_zoom_f) + return; + ppb_zoom_f->ZoomLimitsChanged( + associated_instance_->pp_instance(), minimum_factor, maximium_factor); +} + +} // namespace pp diff --git a/ppapi/cpp/dev/zoom_dev.h b/ppapi/cpp/dev/zoom_dev.h new file mode 100644 index 0000000..0a079f0 --- /dev/null +++ b/ppapi/cpp/dev/zoom_dev.h @@ -0,0 +1,58 @@ +// 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_DEV_ZOOM_DEV_H_ +#define PPAPI_CPP_DEV_ZOOM_DEV_H_ + +#include <string> + +#include "ppapi/c/dev/ppp_zoom_dev.h" + +namespace pp { + +class Instance; + +// This class allows you to associate the PPP_Zoom_Dev and PPB_Zoom_Dev C-based +// interfaces with an object. It associates itself with the given instance, and +// registers as the global handler for handling the PPP_Zoom_Dev interface that +// the browser calls. +// +// You would typically use this either via inheritance on your instance: +// class MyInstance : public pp::Instance, public pp::Zoom_Dev { +// class MyInstance() : pp::Zoom_Dev(this) { +// } +// ... +// }; +// +// or by composition: +// class MyZoom : public pp::Zoom_Dev { +// ... +// }; +// +// class MyInstance : public pp::Instance { +// MyInstance() : zoom_(this) { +// } +// +// MyZoom zoom_; +// }; +class Zoom_Dev { + public: + Zoom_Dev(Instance* instance); + virtual ~Zoom_Dev(); + + // PPP_Zoom_Dev functions exposed as virtual functions for you to + // override. + virtual void Zoom(double factor, bool text_only) = 0; + + // PPB_Zoom_Def functions for you to call to report new zoom factor. + void ZoomChanged(double factor); + void ZoomLimitsChanged(double minimum_factor, double maximium_factor); + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_ZOOM_DEV_H_ |