summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
authorneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-20 19:03:07 +0000
committerneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-20 19:03:07 +0000
commit6b7550abfbaa42801809e95609efad917cd64f18 (patch)
treec748a358dab03c9b8ce5490a02eee5ef3ef64085 /ppapi/cpp
parentac873735ca81b77f9986e19b8c7f6347e9e026bc (diff)
downloadchromium_src-6b7550abfbaa42801809e95609efad917cd64f18.zip
chromium_src-6b7550abfbaa42801809e95609efad917cd64f18.tar.gz
chromium_src-6b7550abfbaa42801809e95609efad917cd64f18.tar.bz2
Remove static initializers.
BUG=52915 TEST=no new functionality, passes ppapi_tests Review URL: http://codereview.chromium.org/5797006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/dev/audio_config_dev.cc23
-rw-r--r--ppapi/cpp/dev/audio_dev.cc21
-rw-r--r--ppapi/cpp/dev/buffer_dev.cc27
-rw-r--r--ppapi/cpp/dev/buffer_dev.h4
-rw-r--r--ppapi/cpp/dev/directory_reader_dev.cc27
-rw-r--r--ppapi/cpp/dev/directory_reader_dev.h2
-rw-r--r--ppapi/cpp/dev/file_chooser_dev.cc29
-rw-r--r--ppapi/cpp/dev/file_chooser_dev.h2
-rw-r--r--ppapi/cpp/dev/file_io_dev.cc66
-rw-r--r--ppapi/cpp/dev/file_io_dev.h4
-rw-r--r--ppapi/cpp/dev/file_ref_dev.cc85
-rw-r--r--ppapi/cpp/dev/file_ref_dev.h2
-rw-r--r--ppapi/cpp/dev/file_system_dev.cc19
-rw-r--r--ppapi/cpp/dev/find_dev.cc19
-rw-r--r--ppapi/cpp/dev/font_dev.cc56
-rw-r--r--ppapi/cpp/dev/font_dev.h4
-rw-r--r--ppapi/cpp/dev/fullscreen_dev.cc18
-rw-r--r--ppapi/cpp/dev/graphics_3d_dev.cc76
-rw-r--r--ppapi/cpp/dev/scrollbar_dev.cc46
-rw-r--r--ppapi/cpp/dev/transport_dev.cc14
-rw-r--r--ppapi/cpp/dev/video_decoder_dev.cc45
-rw-r--r--ppapi/cpp/dev/video_decoder_dev.h2
-rw-r--r--ppapi/cpp/dev/widget_dev.cc36
-rw-r--r--ppapi/cpp/dev/widget_dev.h2
-rw-r--r--ppapi/cpp/dev/zoom_dev.cc13
-rw-r--r--ppapi/cpp/graphics_2d.cc49
-rw-r--r--ppapi/cpp/image_data.cc29
-rw-r--r--ppapi/cpp/image_data.h2
-rw-r--r--ppapi/cpp/instance.cc43
-rw-r--r--ppapi/cpp/module_impl.h40
-rw-r--r--ppapi/cpp/url_loader.cc63
-rw-r--r--ppapi/cpp/url_request_info.cc53
-rw-r--r--ppapi/cpp/url_response_info.cc19
-rw-r--r--ppapi/cpp/var.cc137
34 files changed, 546 insertions, 531 deletions
diff --git a/ppapi/cpp/dev/audio_config_dev.cc b/ppapi/cpp/dev/audio_config_dev.cc
index c68dd84..c8f8f3a 100644
--- a/ppapi/cpp/dev/audio_config_dev.cc
+++ b/ppapi/cpp/dev/audio_config_dev.cc
@@ -7,10 +7,16 @@
#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 {
+namespace {
+
+template <> const char* interface_name<PPB_AudioConfig_Dev>() {
+ return PPB_AUDIO_CONFIG_DEV_INTERFACE;
+}
+
+} // namespace
+
AudioConfig_Dev::AudioConfig_Dev()
: sample_rate_(PP_AUDIOSAMPLERATE_NONE),
sample_frame_count_(0) {
@@ -20,19 +26,20 @@ 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));
+ if (has_interface<PPB_AudioConfig_Dev>()) {
+ PassRefFromConstructor(
+ get_interface<PPB_AudioConfig_Dev>()->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)
+ if (!has_interface<PPB_AudioConfig_Dev>())
return 0;
- return audio_cfg_f->RecommendSampleFrameCount(requested_sample_frame_count);
+ return get_interface<PPB_AudioConfig_Dev>()->
+ RecommendSampleFrameCount(requested_sample_frame_count);
}
} // namespace pp
diff --git a/ppapi/cpp/dev/audio_dev.cc b/ppapi/cpp/dev/audio_dev.cc
index c747c78..850d4d1 100644
--- a/ppapi/cpp/dev/audio_dev.cc
+++ b/ppapi/cpp/dev/audio_dev.cc
@@ -6,32 +6,35 @@
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Audio_Dev> audio_f(PPB_AUDIO_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Audio_Dev>() {
+ return 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));
+ if (has_interface<PPB_Audio_Dev>()) {
+ PassRefFromConstructor(get_interface<PPB_Audio_Dev>()->Create(
+ instance.pp_instance(), config.pp_resource(), callback, user_data));
}
}
bool Audio_Dev::StartPlayback() {
- return audio_f && audio_f->StartPlayback(pp_resource());
+ return has_interface<PPB_Audio_Dev>() &&
+ get_interface<PPB_Audio_Dev>()->StartPlayback(pp_resource());
}
bool Audio_Dev::StopPlayback() {
- return audio_f && audio_f->StopPlayback(pp_resource());
+ return has_interface<PPB_Audio_Dev>() &&
+ get_interface<PPB_Audio_Dev>()->StopPlayback(pp_resource());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/buffer_dev.cc b/ppapi/cpp/dev/buffer_dev.cc
index 3f5c2c8..678211a 100644
--- a/ppapi/cpp/dev/buffer_dev.cc
+++ b/ppapi/cpp/dev/buffer_dev.cc
@@ -9,14 +9,16 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Buffer_Dev> buffer_f(PPB_BUFFER_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Buffer_Dev>() {
+ return PPB_BUFFER_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
Buffer_Dev::Buffer_Dev() : data_(NULL), size_(0) {
}
@@ -27,24 +29,15 @@ Buffer_Dev::Buffer_Dev(const Buffer_Dev& other)
}
Buffer_Dev::Buffer_Dev(uint32_t size) : data_(NULL), size_(0) {
- if (!buffer_f)
+ if (!has_interface<PPB_Buffer_Dev>())
return;
- PassRefFromConstructor(buffer_f->Create(Module::Get()->pp_module(), size));
- if (!buffer_f->Describe(pp_resource(), &size_) ||
- !(data_ = buffer_f->Map(pp_resource())))
+ PassRefFromConstructor(get_interface<PPB_Buffer_Dev>()->Create(
+ Module::Get()->pp_module(), size));
+ if (!get_interface<PPB_Buffer_Dev>()->Describe(pp_resource(), &size_) ||
+ !(data_ = get_interface<PPB_Buffer_Dev>()->Map(pp_resource())))
*this = Buffer_Dev();
}
-Buffer_Dev::~Buffer_Dev() {
-}
-
-Buffer_Dev& Buffer_Dev::operator=(const Buffer_Dev& other) {
- Resource::operator=(other);
- size_ = other.size_;
- data_ = other.data_;
- return *this;
-}
-
} // namespace pp
diff --git a/ppapi/cpp/dev/buffer_dev.h b/ppapi/cpp/dev/buffer_dev.h
index 19e9e68..e5f7325 100644
--- a/ppapi/cpp/dev/buffer_dev.h
+++ b/ppapi/cpp/dev/buffer_dev.h
@@ -20,10 +20,6 @@ class Buffer_Dev : public Resource {
// resulting object will be is_null() if the allocation failed.
explicit Buffer_Dev(uint32_t size);
- ~Buffer_Dev();
-
- Buffer_Dev& operator=(const Buffer_Dev& other);
-
uint32_t size() const { return size_; }
void* data() const { return data_; }
diff --git a/ppapi/cpp/dev/directory_reader_dev.cc b/ppapi/cpp/dev/directory_reader_dev.cc
index 0802944..0b461e0b 100644
--- a/ppapi/cpp/dev/directory_reader_dev.cc
+++ b/ppapi/cpp/dev/directory_reader_dev.cc
@@ -11,38 +11,33 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_DirectoryReader_Dev> directory_reader_f(
- PPB_DIRECTORYREADER_DEV_INTERFACE);
+template <> const char* interface_name<PPB_DirectoryReader_Dev>() {
+ return PPB_DIRECTORYREADER_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
DirectoryReader_Dev::DirectoryReader_Dev(const FileRef_Dev& directory_ref) {
- if (!directory_reader_f)
+ if (!has_interface<PPB_DirectoryReader_Dev>())
return;
- PassRefFromConstructor(
- directory_reader_f->Create(directory_ref.pp_resource()));
+ PassRefFromConstructor(get_interface<PPB_DirectoryReader_Dev>()->Create(
+ directory_ref.pp_resource()));
}
DirectoryReader_Dev::DirectoryReader_Dev(const DirectoryReader_Dev& other)
: Resource(other) {
}
-DirectoryReader_Dev& DirectoryReader_Dev::operator=(
- const DirectoryReader_Dev& other) {
- Resource::operator=(other);
- return *this;
-}
-
int32_t DirectoryReader_Dev::GetNextEntry(DirectoryEntry_Dev* entry,
const CompletionCallback& cc) {
- if (!directory_reader_f)
+ if (!has_interface<PPB_DirectoryReader_Dev>())
return PP_ERROR_NOINTERFACE;
- return directory_reader_f->GetNextEntry(pp_resource(), &entry->data_,
- cc.pp_completion_callback());
+ return get_interface<PPB_DirectoryReader_Dev>()->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
index 92f2a23..775d427 100644
--- a/ppapi/cpp/dev/directory_reader_dev.h
+++ b/ppapi/cpp/dev/directory_reader_dev.h
@@ -23,8 +23,6 @@ class DirectoryReader_Dev : public Resource {
DirectoryReader_Dev(const DirectoryReader_Dev& other);
- DirectoryReader_Dev& operator=(const DirectoryReader_Dev& other);
-
// See PPB_DirectoryReader::GetNextEntry.
int32_t GetNextEntry(DirectoryEntry_Dev* entry,
const CompletionCallback& cc);
diff --git a/ppapi/cpp/dev/file_chooser_dev.cc b/ppapi/cpp/dev/file_chooser_dev.cc
index 458ba12..1e63ec9 100644
--- a/ppapi/cpp/dev/file_chooser_dev.cc
+++ b/ppapi/cpp/dev/file_chooser_dev.cc
@@ -12,43 +12,40 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_FileChooser_Dev> file_chooser_f(PPB_FILECHOOSER_DEV_INTERFACE);
+template <> const char* interface_name<PPB_FileChooser_Dev>() {
+ return PPB_FILECHOOSER_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
FileChooser_Dev::FileChooser_Dev(const Instance& instance,
const PP_FileChooserOptions_Dev& options) {
- if (!file_chooser_f)
+ if (!has_interface<PPB_FileChooser_Dev>())
return;
- PassRefFromConstructor(file_chooser_f->Create(instance.pp_instance(),
- &options));
+ PassRefFromConstructor(get_interface<PPB_FileChooser_Dev>()->Create(
+ instance.pp_instance(), &options));
}
FileChooser_Dev::FileChooser_Dev(const FileChooser_Dev& other)
: Resource(other) {
}
-FileChooser_Dev& FileChooser_Dev::operator=(const FileChooser_Dev& other) {
- Resource::operator=(other);
- return *this;
-}
-
-
int32_t FileChooser_Dev::Show(const CompletionCallback& cc) {
- if (!file_chooser_f)
+ if (!has_interface<PPB_FileChooser_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_chooser_f->Show(pp_resource(), cc.pp_completion_callback());
+ return get_interface<PPB_FileChooser_Dev>()->Show(
+ pp_resource(), cc.pp_completion_callback());
}
FileRef_Dev FileChooser_Dev::GetNextChosenFile() const {
- if (!file_chooser_f)
+ if (!has_interface<PPB_FileChooser_Dev>())
return FileRef_Dev();
return FileRef_Dev(FileRef_Dev::PassRef(),
- file_chooser_f->GetNextChosenFile(pp_resource()));
+ get_interface<PPB_FileChooser_Dev>()->GetNextChosenFile(pp_resource()));
}
} // namespace pp
diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h
index 2d0ed22..1feff61 100644
--- a/ppapi/cpp/dev/file_chooser_dev.h
+++ b/ppapi/cpp/dev/file_chooser_dev.h
@@ -25,8 +25,6 @@ class FileChooser_Dev : public Resource {
FileChooser_Dev(const FileChooser_Dev& other);
- FileChooser_Dev& operator=(const FileChooser_Dev& other);
-
// PPB_FileChooser methods:
int32_t Show(const CompletionCallback& cc);
FileRef_Dev GetNextChosenFile() const;
diff --git a/ppapi/cpp/dev/file_io_dev.cc b/ppapi/cpp/dev/file_io_dev.cc
index bccfa99..5dae1d3 100644
--- a/ppapi/cpp/dev/file_io_dev.cc
+++ b/ppapi/cpp/dev/file_io_dev.cc
@@ -12,93 +12,95 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_FileIO_Dev> file_io_f(PPB_FILEIO_DEV_INTERFACE);
+template <> const char* interface_name<PPB_FileIO_Dev>() {
+ return PPB_FILEIO_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
FileIO_Dev::FileIO_Dev() {
- if (!file_io_f)
+ if (!has_interface<PPB_FileIO_Dev>())
return;
- PassRefFromConstructor(file_io_f->Create(Module::Get()->pp_module()));
+ PassRefFromConstructor(get_interface<PPB_FileIO_Dev>()->Create(
+ Module::Get()->pp_module()));
}
FileIO_Dev::FileIO_Dev(const FileIO_Dev& other)
: Resource(other) {
}
-FileIO_Dev& FileIO_Dev::operator=(const FileIO_Dev& other) {
- Resource::operator=(other);
- return *this;
-}
-
int32_t FileIO_Dev::Open(const FileRef_Dev& file_ref,
int32_t open_flags,
const CompletionCallback& cc) {
- if (!file_io_f)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Open(pp_resource(), file_ref.pp_resource(), open_flags,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->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)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Query(pp_resource(), result_buf,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->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)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Touch(pp_resource(), last_access_time, last_modified_time,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->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)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Read(pp_resource(), offset, buffer, bytes_to_read,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->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)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Write(pp_resource(), offset, buffer, bytes_to_write,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->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)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->SetLength(pp_resource(), length,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->SetLength(
+ pp_resource(), length, cc.pp_completion_callback());
}
int32_t FileIO_Dev::Flush(const CompletionCallback& cc) {
- if (!file_io_f)
+ if (!has_interface<PPB_FileIO_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_io_f->Flush(pp_resource(), cc.pp_completion_callback());
+ return get_interface<PPB_FileIO_Dev>()->Flush(
+ pp_resource(), cc.pp_completion_callback());
}
void FileIO_Dev::Close() {
- if (!file_io_f)
+ if (!has_interface<PPB_FileIO_Dev>())
return;
- file_io_f->Close(pp_resource());
+ get_interface<PPB_FileIO_Dev>()->Close(pp_resource());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/file_io_dev.h b/ppapi/cpp/dev/file_io_dev.h
index 1ec4d06..1da3652 100644
--- a/ppapi/cpp/dev/file_io_dev.h
+++ b/ppapi/cpp/dev/file_io_dev.h
@@ -20,9 +20,7 @@ class FileIO_Dev : public Resource {
FileIO_Dev();
FileIO_Dev(const FileIO_Dev& other);
- FileIO_Dev& operator=(const FileIO_Dev& other);
-
- // PPB_FileIO methods:
+ // PPB_FileIO methods:
int32_t Open(const FileRef_Dev& file_ref,
int32_t open_flags,
const CompletionCallback& cc);
diff --git a/ppapi/cpp/dev/file_ref_dev.cc b/ppapi/cpp/dev/file_ref_dev.cc
index 9a8db58..5a8caae 100644
--- a/ppapi/cpp/dev/file_ref_dev.cc
+++ b/ppapi/cpp/dev/file_ref_dev.cc
@@ -9,14 +9,17 @@
#include "ppapi/cpp/dev/file_system_dev.h"
#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_FileRef_Dev> file_ref_f(PPB_FILEREF_DEV_INTERFACE);
+template <> const char* interface_name<PPB_FileRef_Dev>() {
+ return PPB_FILEREF_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
FileRef_Dev::FileRef_Dev(PP_Resource resource) : Resource(resource) {
}
@@ -26,94 +29,94 @@ FileRef_Dev::FileRef_Dev(PassRef, PP_Resource resource) {
FileRef_Dev::FileRef_Dev(const FileSystem_Dev& file_system,
const char* path) {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return;
- PassRefFromConstructor(file_ref_f->Create(file_system.pp_resource(), path));
+ PassRefFromConstructor(get_interface<PPB_FileRef_Dev>()->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) {
- Resource::operator=(other);
- return *this;
-}
-
PP_FileSystemType_Dev FileRef_Dev::GetFileSystemType() const {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_FILESYSTEMTYPE_EXTERNAL;
- return file_ref_f->GetFileSystemType(pp_resource());
+ return get_interface<PPB_FileRef_Dev>()->GetFileSystemType(pp_resource());
}
Var FileRef_Dev::GetName() const {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return Var();
- return Var(Var::PassRef(), file_ref_f->GetName(pp_resource()));
+ return Var(Var::PassRef(),
+ get_interface<PPB_FileRef_Dev>()->GetName(pp_resource()));
}
Var FileRef_Dev::GetPath() const {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return Var();
- return Var(Var::PassRef(), file_ref_f->GetPath(pp_resource()));
+ return Var(Var::PassRef(),
+ get_interface<PPB_FileRef_Dev>()->GetPath(pp_resource()));
}
FileRef_Dev FileRef_Dev::GetParent() const {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return FileRef_Dev();
- return FileRef_Dev(PassRef(), file_ref_f->GetParent(pp_resource()));
+ return FileRef_Dev(PassRef(),
+ get_interface<PPB_FileRef_Dev>()->GetParent(
+ pp_resource()));
}
int32_t FileRef_Dev::MakeDirectory(const CompletionCallback& cc) {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->MakeDirectory(pp_resource(),
- PP_FALSE, // make_ancestors
- cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->MakeDirectory(
+ pp_resource(),
+ PP_FALSE, // make_ancestors
+ cc.pp_completion_callback());
}
int32_t FileRef_Dev::MakeDirectoryIncludingAncestors(
const CompletionCallback& cc) {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->MakeDirectory(pp_resource(),
- PP_TRUE, // make_ancestors
- cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->MakeDirectory(
+ pp_resource(),
+ PP_TRUE, // make_ancestors
+ cc.pp_completion_callback());
}
int32_t FileRef_Dev::Query(PP_FileInfo_Dev* result_buf,
const CompletionCallback& cc) {
- if (!file_ref_f)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->Query(pp_resource(),
- result_buf,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->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)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->Touch(pp_resource(),
- last_access_time,
- last_modified_time,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->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)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->Delete(pp_resource(), cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->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)
+ if (!has_interface<PPB_FileRef_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_ref_f->Rename(pp_resource(),
- new_file_ref.pp_resource(),
- cc.pp_completion_callback());
+ return get_interface<PPB_FileRef_Dev>()->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
index 99abd03..279728a 100644
--- a/ppapi/cpp/dev/file_ref_dev.h
+++ b/ppapi/cpp/dev/file_ref_dev.h
@@ -34,8 +34,6 @@ class FileRef_Dev : public Resource {
FileRef_Dev(const FileRef_Dev& other);
- FileRef_Dev& operator=(const FileRef_Dev& other);
-
// Returns the file system type.
PP_FileSystemType_Dev GetFileSystemType() const;
diff --git a/ppapi/cpp/dev/file_system_dev.cc b/ppapi/cpp/dev/file_system_dev.cc
index e6dfaff..6c25e23 100644
--- a/ppapi/cpp/dev/file_system_dev.cc
+++ b/ppapi/cpp/dev/file_system_dev.cc
@@ -11,27 +11,30 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_FileSystem_Dev> file_sys_f(PPB_FILESYSTEM_DEV_INTERFACE);
+template <> const char* interface_name<PPB_FileSystem_Dev>() {
+ return PPB_FILESYSTEM_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
FileSystem_Dev::FileSystem_Dev(Instance* instance,
PP_FileSystemType_Dev type) {
- if (!file_sys_f)
+ if (!has_interface<PPB_FileSystem_Dev>())
return;
- PassRefFromConstructor(file_sys_f->Create(instance->pp_instance(), type));
+ PassRefFromConstructor(get_interface<PPB_FileSystem_Dev>()->Create(
+ instance->pp_instance(), type));
}
int32_t FileSystem_Dev::Open(int64_t expected_size,
const CompletionCallback& cc) {
- if (!file_sys_f)
+ if (!has_interface<PPB_FileSystem_Dev>())
return PP_ERROR_NOINTERFACE;
- return file_sys_f->Open(pp_resource(), expected_size,
- cc.pp_completion_callback());
+ return get_interface<PPB_FileSystem_Dev>()->Open(
+ pp_resource(), expected_size, cc.pp_completion_callback());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/find_dev.cc b/ppapi/cpp/dev/find_dev.cc
index 74e5915..31a25bd 100644
--- a/ppapi/cpp/dev/find_dev.cc
+++ b/ppapi/cpp/dev/find_dev.cc
@@ -14,6 +14,10 @@ namespace pp {
namespace {
+template <> const char* interface_name<PPB_Find_Dev>() {
+ return PPB_FIND_DEV_INTERFACE;
+}
+
static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE;
PP_Bool StartFind(PP_Instance instance,
@@ -48,8 +52,6 @@ const PPP_Find_Dev ppp_find = {
&StopFind
};
-DeviceFuncs<PPB_Find_Dev> ppb_find_f(PPB_FIND_DEV_INTERFACE);
-
} // namespace
Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) {
@@ -62,17 +64,16 @@ Find_Dev::~Find_Dev() {
}
void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) {
- if (ppb_find_f) {
- ppb_find_f->NumberOfFindResultsChanged(associated_instance_->pp_instance(),
- total,
- BoolToPPBool(final_result));
+ if (has_interface<PPB_Find_Dev>()) {
+ get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged(
+ associated_instance_->pp_instance(), total, BoolToPPBool(final_result));
}
}
void Find_Dev::SelectedFindResultChanged(int32_t index) {
- if (ppb_find_f) {
- ppb_find_f->SelectedFindResultChanged(associated_instance_->pp_instance(),
- index);
+ if (has_interface<PPB_Find_Dev>()) {
+ get_interface<PPB_Find_Dev>()->SelectedFindResultChanged(
+ associated_instance_->pp_instance(), index);
}
}
diff --git a/ppapi/cpp/dev/font_dev.cc b/ppapi/cpp/dev/font_dev.cc
index a58aec2..0bf9cbd 100644
--- a/ppapi/cpp/dev/font_dev.cc
+++ b/ppapi/cpp/dev/font_dev.cc
@@ -13,14 +13,16 @@
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Font_Dev> font_f(PPB_FONT_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Font_Dev>() {
+ return PPB_FONT_DEV_INTERFACE;
+}
} // namespace
-namespace pp {
-
// FontDescription_Dev ---------------------------------------------------------
FontDescription_Dev::FontDescription_Dev() {
@@ -99,29 +101,25 @@ Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) {
}
Font_Dev::Font_Dev(const FontDescription_Dev& description) {
- if (!font_f)
+ if (!has_interface<PPB_Font_Dev>())
return;
- PassRefFromConstructor(font_f->Create(
+ PassRefFromConstructor(get_interface<PPB_Font_Dev>()->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) {
- Resource::operator=(other);
- return *this;
-}
bool Font_Dev::Describe(FontDescription_Dev* description,
PP_FontMetrics_Dev* metrics) const {
- if (!font_f)
+ if (!has_interface<PPB_Font_Dev>())
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))
+ if (!get_interface<PPB_Font_Dev>()->Describe(
+ pp_resource(), &description->pp_font_description_, metrics))
return false;
description->face_ = Var(Var::PassRef(),
description->pp_font_description_.face);
@@ -135,38 +133,40 @@ bool Font_Dev::DrawTextAt(ImageData* dest,
uint32_t color,
const Rect& clip,
bool image_data_is_opaque) const {
- if (!font_f)
+ if (!has_interface<PPB_Font_Dev>())
return false;
- return PPBoolToBool(font_f->DrawTextAt(pp_resource(),
- dest->pp_resource(),
- &text.pp_text_run(),
- &position.pp_point(),
- color,
- &clip.pp_rect(),
- BoolToPPBool(image_data_is_opaque)));
+ return PPBoolToBool(get_interface<PPB_Font_Dev>()->DrawTextAt(
+ pp_resource(),
+ dest->pp_resource(),
+ &text.pp_text_run(),
+ &position.pp_point(),
+ color,
+ &clip.pp_rect(),
+ BoolToPPBool(image_data_is_opaque)));
}
int32_t Font_Dev::MeasureText(const TextRun_Dev& text) const {
- if (!font_f)
+ if (!has_interface<PPB_Font_Dev>())
return -1;
- return font_f->MeasureText(pp_resource(), &text.pp_text_run());
+ return get_interface<PPB_Font_Dev>()->MeasureText(pp_resource(),
+ &text.pp_text_run());
}
uint32_t Font_Dev::CharacterOffsetForPixel(const TextRun_Dev& text,
int32_t pixel_position) const {
- if (!font_f)
+ if (!has_interface<PPB_Font_Dev>())
return 0;
- return font_f->CharacterOffsetForPixel(pp_resource(), &text.pp_text_run(),
- pixel_position);
+ return get_interface<PPB_Font_Dev>()->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)
+ if (!has_interface<PPB_Font_Dev>())
return 0;
- return font_f->PixelOffsetForCharacter(pp_resource(), &text.pp_text_run(),
- char_offset);
+ return get_interface<PPB_Font_Dev>()->PixelOffsetForCharacter(
+ pp_resource(), &text.pp_text_run(), char_offset);
}
bool Font_Dev::DrawSimpleText(ImageData* dest,
diff --git a/ppapi/cpp/dev/font_dev.h b/ppapi/cpp/dev/font_dev.h
index e356b2b..cbe4b23 100644
--- a/ppapi/cpp/dev/font_dev.h
+++ b/ppapi/cpp/dev/font_dev.h
@@ -30,12 +30,12 @@ class FontDescription_Dev {
FontDescription_Dev(const FontDescription_Dev& other);
~FontDescription_Dev();
+ FontDescription_Dev& operator=(const FontDescription_Dev& other);
+
const PP_FontDescription_Dev& pp_font_description() const {
return pp_font_description_;
}
- FontDescription_Dev& operator=(const FontDescription_Dev& other);
-
Var face() const { return face_; }
void set_face(const Var& face) {
face_ = face;
diff --git a/ppapi/cpp/dev/fullscreen_dev.cc b/ppapi/cpp/dev/fullscreen_dev.cc
index b398b49..e68b296 100644
--- a/ppapi/cpp/dev/fullscreen_dev.cc
+++ b/ppapi/cpp/dev/fullscreen_dev.cc
@@ -14,9 +14,11 @@ namespace pp {
namespace {
-DeviceFuncs<PPB_Fullscreen_Dev> ppb_fullscreen_f(PPB_FULLSCREEN_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Fullscreen_Dev>() {
+ return PPB_FULLSCREEN_DEV_INTERFACE;
+}
-} // anonymous namespace
+} // namespace
Fullscreen_Dev::Fullscreen_Dev(Instance* instance)
: associated_instance_(instance) {
@@ -26,16 +28,16 @@ Fullscreen_Dev::~Fullscreen_Dev() {
}
bool Fullscreen_Dev::IsFullscreen() {
- return ppb_fullscreen_f && ppb_fullscreen_f->IsFullscreen(
- associated_instance_->pp_instance());
+ return has_interface<PPB_Fullscreen_Dev>() &&
+ get_interface<PPB_Fullscreen_Dev>()->IsFullscreen(
+ associated_instance_->pp_instance());
}
bool Fullscreen_Dev::SetFullscreen(bool fullscreen) {
- if (!ppb_fullscreen_f)
+ if (!has_interface<PPB_Fullscreen_Dev>())
return false;
- return PPBoolToBool(
- ppb_fullscreen_f->SetFullscreen(associated_instance_->pp_instance(),
- BoolToPPBool(fullscreen)));
+ return PPBoolToBool(get_interface<PPB_Fullscreen_Dev>()->SetFullscreen(
+ associated_instance_->pp_instance(), BoolToPPBool(fullscreen)));
}
} // namespace pp
diff --git a/ppapi/cpp/dev/graphics_3d_dev.cc b/ppapi/cpp/dev/graphics_3d_dev.cc
index a15417c..8f03697 100644
--- a/ppapi/cpp/dev/graphics_3d_dev.cc
+++ b/ppapi/cpp/dev/graphics_3d_dev.cc
@@ -14,27 +14,31 @@ extern "C" {
const PPB_OpenGLES_Dev* pepper_opengl_interface = NULL;
}
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Graphics3D_Dev> graphics_3d_f(PPB_GRAPHICS_3D_DEV_INTERFACE);
-DeviceFuncs<PPB_OpenGLES_Dev> opengles_f(PPB_OPENGLES_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Graphics3D_Dev>() {
+ return PPB_GRAPHICS_3D_DEV_INTERFACE;
+}
+
+template <> const char* interface_name<PPB_OpenGLES_Dev>() {
+ return PPB_OPENGLES_DEV_INTERFACE;
+}
inline void InitializeOpenGLCInterface() {
if (!pepper_opengl_interface)
- pepper_opengl_interface = &(*opengles_f);
+ pepper_opengl_interface = get_interface<PPB_OpenGLES_Dev>();
}
} // namespace
-namespace pp {
-
// static
bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size,
int32_t *num_config) {
- if (graphics_3d_f) {
- return PPBoolToBool(graphics_3d_f->GetConfigs(configs,
- config_size,
- num_config));
+ if (has_interface<PPB_Graphics3D_Dev>()) {
+ return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigs(
+ configs, config_size, num_config));
}
return false;
}
@@ -42,11 +46,9 @@ bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size,
// 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 PPBoolToBool(graphics_3d_f->ChooseConfig(attrib_list,
- configs,
- config_size,
- num_config));
+ if (has_interface<PPB_Graphics3D_Dev>()) {
+ return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->ChooseConfig(
+ attrib_list, configs, config_size, num_config));
}
return false;
}
@@ -54,73 +56,77 @@ bool Graphics3D_Dev::ChooseConfig(const int32_t *attrib_list, int32_t *configs,
// static
bool Graphics3D_Dev::GetConfigAttrib(int32_t config, int32_t attribute,
int32_t *value) {
- if (graphics_3d_f) {
- return PPBoolToBool(graphics_3d_f->GetConfigAttrib(config,
- attribute,
- value));
+ if (has_interface<PPB_Graphics3D_Dev>()) {
+ return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->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);
+ if (has_interface<PPB_Graphics3D_Dev>())
+ return get_interface<PPB_Graphics3D_Dev>()->QueryString(name);
return NULL;
}
// static
void* Graphics3D_Dev::GetProcAddress(const char* name) {
- if (graphics_3d_f)
- return graphics_3d_f->GetProcAddress(name);
+ if (has_interface<PPB_Graphics3D_Dev>())
+ return get_interface<PPB_Graphics3D_Dev>()->GetProcAddress(name);
return NULL;
}
Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) {
- if (graphics_3d_f && graphics_3d_f->IsGraphics3D(resource_id))
+ if (has_interface<PPB_Graphics3D_Dev>() &&
+ get_interface<PPB_Graphics3D_Dev>()->IsGraphics3D(resource_id))
return Graphics3D_Dev(resource_id);
return Graphics3D_Dev();
}
bool Graphics3D_Dev::ResetCurrent() {
- return graphics_3d_f && graphics_3d_f->MakeCurent(0);
+ return has_interface<PPB_Graphics3D_Dev>() &&
+ get_interface<PPB_Graphics3D_Dev>()->MakeCurent(0);
}
Graphics3D_Dev Graphics3D_Dev::GetCurrentContext() {
- if (graphics_3d_f)
- return FromResource(graphics_3d_f->GetCurrentContext());
+ if (has_interface<PPB_Graphics3D_Dev>())
+ return FromResource(
+ get_interface<PPB_Graphics3D_Dev>()->GetCurrentContext());
return Graphics3D_Dev();
}
uint32_t Graphics3D_Dev::GetError() {
- if (graphics_3d_f)
- return graphics_3d_f->GetError();
+ if (has_interface<PPB_Graphics3D_Dev>())
+ return get_interface<PPB_Graphics3D_Dev>()->GetError();
return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED;
}
const PPB_OpenGLES_Dev* Graphics3D_Dev::GetImplementation() {
- return &(*opengles_f);
+ return get_interface<PPB_OpenGLES_Dev>();
}
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) {
+ if (has_interface<PPB_Graphics3D_Dev>() &&
+ has_interface<PPB_OpenGLES_Dev>()) {
InitializeOpenGLCInterface();
- PassRefFromConstructor(graphics_3d_f->CreateContext(instance.pp_instance(),
- config, share_context,
- attrib_list));
+ PassRefFromConstructor(get_interface<PPB_Graphics3D_Dev>()->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());
+ return has_interface<PPB_Graphics3D_Dev>() &&
+ get_interface<PPB_Graphics3D_Dev>()->MakeCurent(pp_resource());
}
bool Graphics3D_Dev::SwapBuffers() const {
- return graphics_3d_f && graphics_3d_f->SwapBuffers(pp_resource());
+ return has_interface<PPB_Graphics3D_Dev>() &&
+ get_interface<PPB_Graphics3D_Dev>()->SwapBuffers(pp_resource());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/scrollbar_dev.cc b/ppapi/cpp/dev/scrollbar_dev.cc
index f5dc570..456190f 100644
--- a/ppapi/cpp/dev/scrollbar_dev.cc
+++ b/ppapi/cpp/dev/scrollbar_dev.cc
@@ -12,57 +12,54 @@
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/rect.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Scrollbar_Dev> scrollbar_f(PPB_SCROLLBAR_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Scrollbar_Dev>() {
+ return 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)
+ if (!has_interface<PPB_Scrollbar_Dev>())
return;
- PassRefFromConstructor(scrollbar_f->Create(instance.pp_instance(),
- BoolToPPBool(vertical)));
+ PassRefFromConstructor(get_interface<PPB_Scrollbar_Dev>()->Create(
+ instance.pp_instance(), BoolToPPBool(vertical)));
}
Scrollbar_Dev::Scrollbar_Dev(const Scrollbar_Dev& other)
: Widget_Dev(other) {
}
-Scrollbar_Dev& Scrollbar_Dev::operator=(const Scrollbar_Dev& other) {
- Resource::operator=(other);
- return *this;
-}
-
uint32_t Scrollbar_Dev::GetThickness() {
- if (!scrollbar_f)
+ if (!has_interface<PPB_Scrollbar_Dev>())
return 0;
- return scrollbar_f->GetThickness();
+ return get_interface<PPB_Scrollbar_Dev>()->GetThickness();
}
uint32_t Scrollbar_Dev::GetValue() {
- if (!scrollbar_f)
+ if (!has_interface<PPB_Scrollbar_Dev>())
return 0;
- return scrollbar_f->GetValue(pp_resource());
+ return get_interface<PPB_Scrollbar_Dev>()->GetValue(pp_resource());
}
void Scrollbar_Dev::SetValue(uint32_t value) {
- if (scrollbar_f)
- scrollbar_f->SetValue(pp_resource(), value);
+ if (has_interface<PPB_Scrollbar_Dev>())
+ get_interface<PPB_Scrollbar_Dev>()->SetValue(pp_resource(), value);
}
void Scrollbar_Dev::SetDocumentSize(uint32_t size) {
- if (scrollbar_f)
- scrollbar_f->SetDocumentSize(pp_resource(), size);
+ if (has_interface<PPB_Scrollbar_Dev>())
+ get_interface<PPB_Scrollbar_Dev>()->SetDocumentSize(pp_resource(), size);
}
void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) {
- if (!scrollbar_f)
+ if (!has_interface<PPB_Scrollbar_Dev>())
return;
std::vector<PP_Rect> temp;
@@ -70,12 +67,15 @@ void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) {
for (uint32_t i = 0; i < count; ++i)
temp[i] = tick_marks[i];
- scrollbar_f->SetTickMarks(pp_resource(), count ? &temp[0] : NULL, count);
+ get_interface<PPB_Scrollbar_Dev>()->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);
+ if (has_interface<PPB_Scrollbar_Dev>())
+ get_interface<PPB_Scrollbar_Dev>()->ScrollBy(pp_resource(),
+ unit,
+ multiplier);
}
} // namespace pp
diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc
index f7eae6b..0ea4a34 100644
--- a/ppapi/cpp/dev/transport_dev.cc
+++ b/ppapi/cpp/dev/transport_dev.cc
@@ -9,19 +9,21 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Transport_Dev> transport_f(PPB_TRANSPORT_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Transport_Dev>() {
+ return 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));
+ if (has_interface<PPB_Transport_Dev>())
+ PassRefFromConstructor(get_interface<PPB_Transport_Dev>()->CreateTransport(
+ Module::Get()->pp_module(), name, proto));
}
} // namespace pp
diff --git a/ppapi/cpp/dev/video_decoder_dev.cc b/ppapi/cpp/dev/video_decoder_dev.cc
index bda3b58..503b446 100644
--- a/ppapi/cpp/dev/video_decoder_dev.cc
+++ b/ppapi/cpp/dev/video_decoder_dev.cc
@@ -10,71 +10,64 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_VideoDecoder_Dev> video_decoder_f(
- PPB_VIDEODECODER_DEV_INTERFACE);
+template <> const char* interface_name<PPB_VideoDecoder_Dev>() {
+ return 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)
+ if (!has_interface<PPB_VideoDecoder_Dev>())
return;
- PassRefFromConstructor(video_decoder_f->Create(instance.pp_instance(),
- &decoder_config));
+ PassRefFromConstructor(get_interface<PPB_VideoDecoder_Dev>()->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) {
- Resource::operator=(other);
- return *this;
-}
-
// 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)
+ if (!has_interface<PPB_VideoDecoder_Dev>())
return false;
- return PPBoolToBool(video_decoder_f->GetConfig(instance.pp_instance(),
- codec,
- configs,
- config_size,
- num_config));
+ return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->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())
+ if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource())
return false;
- return PPBoolToBool(video_decoder_f->Decode(pp_resource(), &input_buffer));
+ return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->Decode(
+ pp_resource(), &input_buffer));
}
int32_t VideoDecoder_Dev::Flush(PP_CompletionCallback callback) {
- if (!video_decoder_f)
+ if (!has_interface<PPB_VideoDecoder_Dev>())
return PP_ERROR_NOINTERFACE;
- return video_decoder_f->Flush(pp_resource(), callback);
+ return get_interface<PPB_VideoDecoder_Dev>()->Flush(pp_resource(), callback);
}
bool VideoDecoder_Dev::ReturnUncompressedDataBuffer(
PP_VideoUncompressedDataBuffer_Dev& buffer) {
- if (!video_decoder_f || !pp_resource())
+ if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource())
return false;
return PPBoolToBool(
- video_decoder_f->ReturnUncompressedDataBuffer(pp_resource(),
- &buffer));
+ get_interface<PPB_VideoDecoder_Dev>()->ReturnUncompressedDataBuffer(
+ pp_resource(), &buffer));
}
} // namespace pp
diff --git a/ppapi/cpp/dev/video_decoder_dev.h b/ppapi/cpp/dev/video_decoder_dev.h
index 15743ca..ea7d052 100644
--- a/ppapi/cpp/dev/video_decoder_dev.h
+++ b/ppapi/cpp/dev/video_decoder_dev.h
@@ -25,8 +25,6 @@ class VideoDecoder_Dev : public Resource {
const PP_VideoDecoderConfig_Dev& decoder_config);
VideoDecoder_Dev(const VideoDecoder_Dev& other);
- VideoDecoder_Dev& operator=(const VideoDecoder_Dev& other);
-
// PPB_VideoDecoder methods:
static bool GetConfig(const Instance& instance,
PP_VideoCodecId_Dev codec,
diff --git a/ppapi/cpp/dev/widget_dev.cc b/ppapi/cpp/dev/widget_dev.cc
index 46f36b5..f69a873 100644
--- a/ppapi/cpp/dev/widget_dev.cc
+++ b/ppapi/cpp/dev/widget_dev.cc
@@ -12,49 +12,47 @@
#include "ppapi/cpp/rect.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Widget_Dev> widget_f(PPB_WIDGET_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Widget_Dev>() {
+ return 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) {
- Resource::operator=(other);
- return *this;
-}
-
bool Widget_Dev::Paint(const Rect& rect, ImageData* image) {
- if (!widget_f)
+ if (!has_interface<PPB_Widget_Dev>())
return false;
- return PPBoolToBool(widget_f->Paint(pp_resource(),
- &rect.pp_rect(),
- image->pp_resource()));
+ return PPBoolToBool(get_interface<PPB_Widget_Dev>()->Paint(
+ pp_resource(), &rect.pp_rect(), image->pp_resource()));
}
bool Widget_Dev::HandleEvent(const PP_InputEvent& event) {
- if (!widget_f)
+ if (!has_interface<PPB_Widget_Dev>())
return false;
- return PPBoolToBool(widget_f->HandleEvent(pp_resource(), &event));
+ return PPBoolToBool(get_interface<PPB_Widget_Dev>()->HandleEvent(
+ pp_resource(), &event));
}
bool Widget_Dev::GetLocation(Rect* location) {
- if (!widget_f)
+ if (!has_interface<PPB_Widget_Dev>())
return false;
- return PPBoolToBool(widget_f->GetLocation(pp_resource(),
- &location->pp_rect()));
+ return PPBoolToBool(get_interface<PPB_Widget_Dev>()->GetLocation(
+ pp_resource(), &location->pp_rect()));
}
void Widget_Dev::SetLocation(const Rect& location) {
- if (widget_f)
- widget_f->SetLocation(pp_resource(), &location.pp_rect());
+ if (has_interface<PPB_Widget_Dev>())
+ get_interface<PPB_Widget_Dev>()->SetLocation(pp_resource(),
+ &location.pp_rect());
}
} // namespace pp
diff --git a/ppapi/cpp/dev/widget_dev.h b/ppapi/cpp/dev/widget_dev.h
index 8252946..bdc1399 100644
--- a/ppapi/cpp/dev/widget_dev.h
+++ b/ppapi/cpp/dev/widget_dev.h
@@ -26,8 +26,6 @@ class Widget_Dev : public Resource {
explicit Widget_Dev(PP_Resource resource);
Widget_Dev(const Widget_Dev& other);
- Widget_Dev& operator=(const Widget_Dev& other);
-
// PPB_Widget methods:
bool Paint(const Rect& rect, ImageData* image);
bool HandleEvent(const PP_InputEvent& event);
diff --git a/ppapi/cpp/dev/zoom_dev.cc b/ppapi/cpp/dev/zoom_dev.cc
index 3d20676..9451e9a 100644
--- a/ppapi/cpp/dev/zoom_dev.cc
+++ b/ppapi/cpp/dev/zoom_dev.cc
@@ -31,7 +31,9 @@ const PPP_Zoom_Dev ppp_zoom = {
&Zoom
};
-DeviceFuncs<PPB_Zoom_Dev> ppb_zoom_f(PPB_ZOOM_DEV_INTERFACE);
+template <> const char* interface_name<PPB_Zoom_Dev>() {
+ return PPB_ZOOM_DEV_INTERFACE;
+}
} // namespace
@@ -45,15 +47,16 @@ Zoom_Dev::~Zoom_Dev() {
}
void Zoom_Dev::ZoomChanged(double factor) {
- if (ppb_zoom_f)
- ppb_zoom_f->ZoomChanged(associated_instance_->pp_instance(), factor);
+ if (has_interface<PPB_Zoom_Dev>())
+ get_interface<PPB_Zoom_Dev>()->ZoomChanged(
+ associated_instance_->pp_instance(), factor);
}
void Zoom_Dev::ZoomLimitsChanged(double minimum_factor,
double maximium_factor) {
- if (!ppb_zoom_f)
+ if (!has_interface<PPB_Zoom_Dev>())
return;
- ppb_zoom_f->ZoomLimitsChanged(
+ get_interface<PPB_Zoom_Dev>()->ZoomLimitsChanged(
associated_instance_->pp_instance(), minimum_factor, maximium_factor);
}
diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc
index 37008cf..40a6312 100644
--- a/ppapi/cpp/graphics_2d.cc
+++ b/ppapi/cpp/graphics_2d.cc
@@ -14,14 +14,16 @@
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/rect.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Graphics2D> graphics_2d_f(PPB_GRAPHICS_2D_INTERFACE);
+template <> const char* interface_name<PPB_Graphics2D>() {
+ return PPB_GRAPHICS_2D_INTERFACE;
+}
} // namespace
-namespace pp {
-
Graphics2D::Graphics2D() : Resource() {
}
@@ -32,11 +34,12 @@ Graphics2D::Graphics2D(const Graphics2D& other)
Graphics2D::Graphics2D(const Size& size, bool is_always_opaque)
: Resource() {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return;
- PassRefFromConstructor(graphics_2d_f->Create(Module::Get()->pp_module(),
- &size.pp_size(),
- BoolToPPBool(is_always_opaque)));
+ PassRefFromConstructor(get_interface<PPB_Graphics2D>()->Create(
+ Module::Get()->pp_module(),
+ &size.pp_size(),
+ BoolToPPBool(is_always_opaque)));
if (!is_null()) {
// Only save the size if allocation succeeded.
size_ = size;
@@ -59,31 +62,38 @@ void Graphics2D::swap(Graphics2D& other) {
void Graphics2D::PaintImageData(const ImageData& image,
const Point& top_left) {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return;
- graphics_2d_f->PaintImageData(pp_resource(), image.pp_resource(),
- &top_left.pp_point(), NULL);
+ get_interface<PPB_Graphics2D>()->PaintImageData(pp_resource(),
+ image.pp_resource(),
+ &top_left.pp_point(),
+ NULL);
}
void Graphics2D::PaintImageData(const ImageData& image,
const Point& top_left,
const Rect& src_rect) {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return;
- graphics_2d_f->PaintImageData(pp_resource(), image.pp_resource(),
- &top_left.pp_point(), &src_rect.pp_rect());
+ get_interface<PPB_Graphics2D>()->PaintImageData(pp_resource(),
+ image.pp_resource(),
+ &top_left.pp_point(),
+ &src_rect.pp_rect());
}
void Graphics2D::Scroll(const Rect& clip, const Point& amount) {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return;
- graphics_2d_f->Scroll(pp_resource(), &clip.pp_rect(), &amount.pp_point());
+ get_interface<PPB_Graphics2D>()->Scroll(pp_resource(),
+ &clip.pp_rect(),
+ &amount.pp_point());
}
void Graphics2D::ReplaceContents(ImageData* image) {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return;
- graphics_2d_f->ReplaceContents(pp_resource(), image->pp_resource());
+ get_interface<PPB_Graphics2D>()->ReplaceContents(pp_resource(),
+ image->pp_resource());
// On success, reset the image data. This is to help prevent people
// from continuing to use the resource which will result in artifacts.
@@ -91,9 +101,10 @@ void Graphics2D::ReplaceContents(ImageData* image) {
}
int32_t Graphics2D::Flush(const CompletionCallback& cc) {
- if (!graphics_2d_f)
+ if (!has_interface<PPB_Graphics2D>())
return PP_ERROR_NOINTERFACE;
- return graphics_2d_f->Flush(pp_resource(), cc.pp_completion_callback());
+ return get_interface<PPB_Graphics2D>()->Flush(pp_resource(),
+ cc.pp_completion_callback());
}
} // namespace pp
diff --git a/ppapi/cpp/image_data.cc b/ppapi/cpp/image_data.cc
index d4b15e0..61a291d 100644
--- a/ppapi/cpp/image_data.cc
+++ b/ppapi/cpp/image_data.cc
@@ -13,14 +13,16 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_ImageData> image_data_f(PPB_IMAGEDATA_INTERFACE);
+template <> const char* interface_name<PPB_ImageData>() {
+ return PPB_IMAGEDATA_INTERFACE;
+}
} // namespace
-namespace pp {
-
ImageData::ImageData() : data_(NULL) {
memset(&desc_, 0, sizeof(PP_ImageDataDesc));
}
@@ -35,7 +37,7 @@ ImageData::ImageData(PassRef, PP_Resource resource)
: data_(NULL) {
memset(&desc_, 0, sizeof(PP_ImageDataDesc));
- if (!image_data_f)
+ if (!has_interface<PPB_ImageData>())
return;
PassRefAndInitData(resource);
@@ -47,15 +49,12 @@ ImageData::ImageData(PP_ImageDataFormat format,
: data_(NULL) {
memset(&desc_, 0, sizeof(PP_ImageDataDesc));
- if (!image_data_f)
+ if (!has_interface<PPB_ImageData>())
return;
- PassRefAndInitData(image_data_f->Create(Module::Get()->pp_module(),
- format, &size.pp_size(),
- BoolToPPBool(init_to_zero)));
-}
-
-ImageData::~ImageData() {
+ PassRefAndInitData(get_interface<PPB_ImageData>()->Create(
+ Module::Get()->pp_module(), format, &size.pp_size(),
+ BoolToPPBool(init_to_zero)));
}
ImageData& ImageData::operator=(const ImageData& other) {
@@ -84,15 +83,15 @@ uint32_t* ImageData::GetAddr32(const Point& coord) {
// static
PP_ImageDataFormat ImageData::GetNativeImageDataFormat() {
- if (!image_data_f)
+ if (!has_interface<PPB_ImageData>())
return PP_IMAGEDATAFORMAT_BGRA_PREMUL; // Default to something on failure.
- return image_data_f->GetNativeImageDataFormat();
+ return get_interface<PPB_ImageData>()->GetNativeImageDataFormat();
}
void ImageData::PassRefAndInitData(PP_Resource resource) {
PassRefFromConstructor(resource);
- if (!image_data_f->Describe(pp_resource(), &desc_) ||
- !(data_ = image_data_f->Map(pp_resource())))
+ if (!get_interface<PPB_ImageData>()->Describe(pp_resource(), &desc_) ||
+ !(data_ = get_interface<PPB_ImageData>()->Map(pp_resource())))
*this = ImageData();
}
diff --git a/ppapi/cpp/image_data.h b/ppapi/cpp/image_data.h
index 07b77e3..388bbc0 100644
--- a/ppapi/cpp/image_data.h
+++ b/ppapi/cpp/image_data.h
@@ -32,8 +32,6 @@ class ImageData : public Resource {
const Size& size,
bool init_to_zero);
- virtual ~ImageData();
-
ImageData& operator=(const ImageData& other);
void swap(ImageData& other);
diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc
index 394be04..379518d 100644
--- a/ppapi/cpp/instance.cc
+++ b/ppapi/cpp/instance.cc
@@ -17,14 +17,16 @@
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/var.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Instance> ppb_instance_f(PPB_INSTANCE_INTERFACE);
+template <> const char* interface_name<PPB_Instance>() {
+ return PPB_INSTANCE_INTERFACE;
+}
} // namespace
-namespace pp {
-
Instance::Instance(PP_Instance instance) : pp_instance_(instance) {
}
@@ -68,44 +70,49 @@ Var Instance::GetSelectedText(bool /* html */) {
}
Var Instance::GetWindowObject() {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return Var();
- return Var(Var::PassRef(), ppb_instance_f->GetWindowObject(pp_instance()));
+ return Var(Var::PassRef(),
+ get_interface<PPB_Instance>()->GetWindowObject(pp_instance()));
}
Var Instance::GetOwnerElementObject() {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return Var();
return Var(Var::PassRef(),
- ppb_instance_f->GetOwnerElementObject(pp_instance()));
+ get_interface<PPB_Instance>()->GetOwnerElementObject(
+ pp_instance()));
}
bool Instance::BindGraphics(const Graphics2D& graphics) {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return false;
- return PPBoolToBool(ppb_instance_f->BindGraphics(pp_instance(),
- graphics.pp_resource()));
+ return PPBoolToBool(get_interface<PPB_Instance>()->BindGraphics(
+ pp_instance(), graphics.pp_resource()));
}
bool Instance::BindGraphics(const Graphics3D_Dev& graphics) {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return false;
- return PPBoolToBool(ppb_instance_f->BindGraphics(pp_instance(),
- graphics.pp_resource()));
+ return PPBoolToBool(get_interface<PPB_Instance>()->BindGraphics(
+ pp_instance(), graphics.pp_resource()));
}
bool Instance::IsFullFrame() {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return false;
- return PPBoolToBool(ppb_instance_f->IsFullFrame(pp_instance()));
+ return PPBoolToBool(get_interface<PPB_Instance>()->IsFullFrame(
+ pp_instance()));
}
Var Instance::ExecuteScript(const Var& script, Var* exception) {
- if (!ppb_instance_f)
+ if (!has_interface<PPB_Instance>())
return Var();
return Var(Var::PassRef(),
- ppb_instance_f->ExecuteScript(pp_instance(), script.pp_var(),
- Var::OutException(exception).get()));
+ get_interface<PPB_Instance>()->ExecuteScript(
+ pp_instance(),
+ script.pp_var(),
+ Var::OutException(exception).get()));
}
void Instance::AddPerInstanceObject(const std::string& interface_name,
diff --git a/ppapi/cpp/module_impl.h b/ppapi/cpp/module_impl.h
index 9cde170..e8d4fe7 100644
--- a/ppapi/cpp/module_impl.h
+++ b/ppapi/cpp/module_impl.h
@@ -7,35 +7,29 @@
#include "ppapi/cpp/module.h"
-namespace {
-
-template <typename T> class DeviceFuncs {
- public:
- explicit DeviceFuncs(const char* ifname) : ifname_(ifname), funcs_(NULL) {}
+namespace pp {
- operator T const*() {
- if (!funcs_) {
- funcs_ = reinterpret_cast<T const*>(
- pp::Module::Get()->GetBrowserInterface(ifname_));
- }
- return funcs_;
- }
+namespace {
- // This version doesn't check for existence of the function object. It is
- // used so that, for DeviceFuncs f, the expression:
- // if (f) f->doSomething();
- // checks the existence only once.
- T const* operator->() const { return funcs_; }
+// Specialize this function to return the interface string corresponding to the
+// PP?_XXX structure.
+template <typename T> const char* interface_name() {
+ return NULL;
+}
- private:
- DeviceFuncs(const DeviceFuncs&other);
- DeviceFuncs &operator=(const DeviceFuncs &other);
+template <typename T> inline T const* get_interface() {
+ static T const* funcs = reinterpret_cast<T const*>(
+ pp::Module::Get()->GetBrowserInterface(interface_name<T>()));
+ return funcs;
+}
- const char* ifname_;
- T const* funcs_;
-};
+template <typename T> inline bool has_interface() {
+ return get_interface<T>() != NULL;
+}
} // namespace
+} // namespace pp
+
#endif // PPAPI_CPP_MODULE_IMPL_H_
diff --git a/ppapi/cpp/url_loader.cc b/ppapi/cpp/url_loader.cc
index 2a56a83..8ef6087 100644
--- a/ppapi/cpp/url_loader.cc
+++ b/ppapi/cpp/url_loader.cc
@@ -15,21 +15,24 @@
#include "ppapi/cpp/url_request_info.h"
#include "ppapi/cpp/url_response_info.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_URLLoader> url_loader_f(PPB_URLLOADER_INTERFACE);
+template <> const char* interface_name<PPB_URLLoader>() {
+ return PPB_URLLOADER_INTERFACE;
+}
} // namespace
-namespace pp {
-
URLLoader::URLLoader(PP_Resource resource) : Resource(resource) {
}
URLLoader::URLLoader(const Instance& instance) {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return;
- PassRefFromConstructor(url_loader_f->Create(instance.pp_instance()));
+ PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create(
+ instance.pp_instance()));
}
URLLoader::URLLoader(const URLLoader& other) : Resource(other) {
@@ -37,68 +40,66 @@ URLLoader::URLLoader(const URLLoader& other) : Resource(other) {
int32_t URLLoader::Open(const URLRequestInfo& request_info,
const CompletionCallback& cc) {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return PP_ERROR_NOINTERFACE;
- return url_loader_f->Open(pp_resource(), request_info.pp_resource(),
- cc.pp_completion_callback());
+ return get_interface<PPB_URLLoader>()->Open(pp_resource(),
+ request_info.pp_resource(),
+ cc.pp_completion_callback());
}
int32_t URLLoader::FollowRedirect(const CompletionCallback& cc) {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return PP_ERROR_NOINTERFACE;
- return url_loader_f->FollowRedirect(pp_resource(),
- cc.pp_completion_callback());
+ return get_interface<PPB_URLLoader>()->FollowRedirect(
+ pp_resource(), cc.pp_completion_callback());
}
bool URLLoader::GetUploadProgress(int64_t* bytes_sent,
int64_t* total_bytes_to_be_sent) const {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return false;
- return PPBoolToBool(url_loader_f->GetUploadProgress(pp_resource(),
- bytes_sent,
- total_bytes_to_be_sent));
+ return PPBoolToBool(get_interface<PPB_URLLoader>()->GetUploadProgress(
+ pp_resource(), bytes_sent, total_bytes_to_be_sent));
}
bool URLLoader::GetDownloadProgress(
int64_t* bytes_received,
int64_t* total_bytes_to_be_received) const {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return false;
return PPBoolToBool(
- url_loader_f->GetDownloadProgress(pp_resource(),
- bytes_received,
- total_bytes_to_be_received));
+ get_interface<PPB_URLLoader>()->GetDownloadProgress(
+ pp_resource(), bytes_received, total_bytes_to_be_received));
}
URLResponseInfo URLLoader::GetResponseInfo() const {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return URLResponseInfo();
return URLResponseInfo(URLResponseInfo::PassRef(),
- url_loader_f->GetResponseInfo(pp_resource()));
+ get_interface<PPB_URLLoader>()->GetResponseInfo(
+ pp_resource()));
}
int32_t URLLoader::ReadResponseBody(char* buffer,
int32_t bytes_to_read,
const CompletionCallback& cc) {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return PP_ERROR_NOINTERFACE;
- return url_loader_f->ReadResponseBody(pp_resource(),
- buffer,
- bytes_to_read,
- cc.pp_completion_callback());
+ return get_interface<PPB_URLLoader>()->ReadResponseBody(
+ pp_resource(), buffer, bytes_to_read, cc.pp_completion_callback());
}
int32_t URLLoader::FinishStreamingToFile(const CompletionCallback& cc) {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return PP_ERROR_NOINTERFACE;
- return url_loader_f->FinishStreamingToFile(pp_resource(),
- cc.pp_completion_callback());
+ return get_interface<PPB_URLLoader>()->FinishStreamingToFile(
+ pp_resource(), cc.pp_completion_callback());
}
void URLLoader::Close() {
- if (!url_loader_f)
+ if (!has_interface<PPB_URLLoader>())
return;
- url_loader_f->Close(pp_resource());
+ get_interface<PPB_URLLoader>()->Close(pp_resource());
}
} // namespace pp
diff --git a/ppapi/cpp/url_request_info.cc b/ppapi/cpp/url_request_info.cc
index 69a86cb..30f339b 100644
--- a/ppapi/cpp/url_request_info.cc
+++ b/ppapi/cpp/url_request_info.cc
@@ -9,20 +9,21 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_URLRequestInfo> url_request_info_f(
- PPB_URLREQUESTINFO_INTERFACE);
+template <> const char* interface_name<PPB_URLRequestInfo>() {
+ return PPB_URLREQUESTINFO_INTERFACE;
+}
} // namespace
-namespace pp {
-
URLRequestInfo::URLRequestInfo() {
- if (!url_request_info_f)
+ if (!has_interface<PPB_URLRequestInfo>())
return;
PassRefFromConstructor(
- url_request_info_f->Create(Module::Get()->pp_module()));
+ get_interface<PPB_URLRequestInfo>()->Create(Module::Get()->pp_module()));
}
URLRequestInfo::URLRequestInfo(const URLRequestInfo& other)
@@ -31,31 +32,30 @@ URLRequestInfo::URLRequestInfo(const URLRequestInfo& other)
bool URLRequestInfo::SetProperty(PP_URLRequestProperty property,
const Var& value) {
- if (!url_request_info_f)
+ if (!has_interface<PPB_URLRequestInfo>())
return false;
- return PPBoolToBool(url_request_info_f->SetProperty(pp_resource(),
- property,
- value.pp_var()));
+ return PPBoolToBool(get_interface<PPB_URLRequestInfo>()->SetProperty(
+ pp_resource(), property, value.pp_var()));
}
bool URLRequestInfo::AppendDataToBody(const char* data, uint32_t len) {
- if (!url_request_info_f)
+ if (!has_interface<PPB_URLRequestInfo>())
return false;
- return PPBoolToBool(url_request_info_f->AppendDataToBody(pp_resource(),
- data,
- len));
+ return PPBoolToBool(get_interface<PPB_URLRequestInfo>()->AppendDataToBody(
+ pp_resource(), data, len));
}
bool URLRequestInfo::AppendFileToBody(const FileRef_Dev& file_ref,
PP_Time expected_last_modified_time) {
- if (!url_request_info_f)
+ if (!has_interface<PPB_URLRequestInfo>())
return false;
return PPBoolToBool(
- url_request_info_f->AppendFileToBody(pp_resource(),
- file_ref.pp_resource(),
- 0,
- -1,
- expected_last_modified_time));
+ get_interface<PPB_URLRequestInfo>()->AppendFileToBody(
+ pp_resource(),
+ file_ref.pp_resource(),
+ 0,
+ -1,
+ expected_last_modified_time));
}
bool URLRequestInfo::AppendFileRangeToBody(
@@ -63,12 +63,15 @@ bool URLRequestInfo::AppendFileRangeToBody(
int64_t start_offset,
int64_t length,
PP_Time expected_last_modified_time) {
+ if (!has_interface<PPB_URLRequestInfo>())
+ return false;
return PPBoolToBool(
- url_request_info_f->AppendFileToBody(pp_resource(),
- file_ref.pp_resource(),
- start_offset,
- length,
- expected_last_modified_time));
+ get_interface<PPB_URLRequestInfo>()->AppendFileToBody(
+ pp_resource(),
+ file_ref.pp_resource(),
+ start_offset,
+ length,
+ expected_last_modified_time));
}
} // namespace pp
diff --git a/ppapi/cpp/url_response_info.cc b/ppapi/cpp/url_response_info.cc
index 4a023aa..caea7ef 100644
--- a/ppapi/cpp/url_response_info.cc
+++ b/ppapi/cpp/url_response_info.cc
@@ -8,15 +8,16 @@
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_URLResponseInfo> url_response_info_f(
- PPB_URLRESPONSEINFO_INTERFACE);
+template <> const char* interface_name<PPB_URLResponseInfo>() {
+ return PPB_URLRESPONSEINFO_INTERFACE;
+}
} // namespace
-namespace pp {
-
URLResponseInfo::URLResponseInfo(const URLResponseInfo& other)
: Resource(other) {
}
@@ -26,17 +27,19 @@ URLResponseInfo::URLResponseInfo(PassRef, PP_Resource resource) {
}
Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) const {
- if (!url_response_info_f)
+ if (!has_interface<PPB_URLResponseInfo>())
return Var();
return Var(Var::PassRef(),
- url_response_info_f->GetProperty(pp_resource(), property));
+ get_interface<PPB_URLResponseInfo>()->GetProperty(pp_resource(),
+ property));
}
FileRef_Dev URLResponseInfo::GetBodyAsFileRef() const {
- if (!url_response_info_f)
+ if (!has_interface<PPB_URLResponseInfo>())
return FileRef_Dev();
return FileRef_Dev(FileRef_Dev::PassRef(),
- url_response_info_f->GetBodyAsFileRef(pp_resource()));
+ get_interface<PPB_URLResponseInfo>()->GetBodyAsFileRef(
+ pp_resource()));
}
} // namespace pp
diff --git a/ppapi/cpp/var.cc b/ppapi/cpp/var.cc
index a1f6730..58ff30a 100644
--- a/ppapi/cpp/var.cc
+++ b/ppapi/cpp/var.cc
@@ -22,9 +22,13 @@
# define snprintf sprintf_s
#endif
+namespace pp {
+
namespace {
-DeviceFuncs<PPB_Var_Deprecated> ppb_var_f(PPB_VAR_DEPRECATED_INTERFACE);
+template <> const char* interface_name<PPB_Var_Deprecated>() {
+ return PPB_VAR_DEPRECATED_INTERFACE;
+}
// Technically you can call AddRef and Release on any Var, but it may involve
// cross-process calls depending on the plugin. This is an optimization so we
@@ -35,8 +39,6 @@ inline bool NeedsRefcounting(const PP_Var& var) {
} // namespace
-namespace pp {
-
using namespace deprecated;
Var::Var() {
@@ -68,9 +70,10 @@ Var::Var(double d) {
}
Var::Var(const char* utf8_str) {
- if (ppb_var_f) {
+ if (has_interface<PPB_Var_Deprecated>()) {
uint32_t len = utf8_str ? static_cast<uint32_t>(strlen(utf8_str)) : 0;
- var_ = ppb_var_f->VarFromUtf8(Module::Get()->pp_module(), utf8_str, len);
+ var_ = get_interface<PPB_Var_Deprecated>()->VarFromUtf8(
+ Module::Get()->pp_module(), utf8_str, len);
} else {
var_.type = PP_VARTYPE_NULL;
}
@@ -78,10 +81,11 @@ Var::Var(const char* utf8_str) {
}
Var::Var(const std::string& utf8_str) {
- if (ppb_var_f) {
- var_ = ppb_var_f->VarFromUtf8(Module::Get()->pp_module(),
- utf8_str.c_str(),
- static_cast<uint32_t>(utf8_str.size()));
+ if (has_interface<PPB_Var_Deprecated>()) {
+ var_ = get_interface<PPB_Var_Deprecated>()->VarFromUtf8(
+ Module::Get()->pp_module(),
+ utf8_str.c_str(),
+ static_cast<uint32_t>(utf8_str.size()));
} else {
var_.type = PP_VARTYPE_NULL;
}
@@ -89,9 +93,9 @@ Var::Var(const std::string& utf8_str) {
}
Var::Var(ScriptableObject* object) {
- if (ppb_var_f) {
- var_ = ppb_var_f->CreateObject(Module::Get()->pp_module(),
- object->GetClass(), object);
+ if (has_interface<PPB_Var_Deprecated>()) {
+ var_ = get_interface<PPB_Var_Deprecated>()->CreateObject(
+ Module::Get()->pp_module(), object->GetClass(), object);
needs_release_ = true;
} else {
var_.type = PP_VARTYPE_NULL;
@@ -102,9 +106,9 @@ Var::Var(ScriptableObject* object) {
Var::Var(const Var& other) {
var_ = other.var_;
if (NeedsRefcounting(var_)) {
- if (ppb_var_f) {
+ if (has_interface<PPB_Var_Deprecated>()) {
needs_release_ = true;
- ppb_var_f->AddRef(var_);
+ get_interface<PPB_Var_Deprecated>()->AddRef(var_);
} else {
var_.type = PP_VARTYPE_NULL;
needs_release_ = false;
@@ -115,18 +119,18 @@ Var::Var(const Var& other) {
}
Var::~Var() {
- if (needs_release_ && ppb_var_f)
- ppb_var_f->Release(var_);
+ if (needs_release_ && has_interface<PPB_Var_Deprecated>())
+ get_interface<PPB_Var_Deprecated>()->Release(var_);
}
Var& Var::operator=(const Var& other) {
- if (needs_release_ && ppb_var_f)
- ppb_var_f->Release(var_);
+ if (needs_release_ && has_interface<PPB_Var_Deprecated>())
+ get_interface<PPB_Var_Deprecated>()->Release(var_);
var_ = other.var_;
if (NeedsRefcounting(var_)) {
- if (ppb_var_f) {
+ if (has_interface<PPB_Var_Deprecated>()) {
needs_release_ = true;
- ppb_var_f->AddRef(var_);
+ get_interface<PPB_Var_Deprecated>()->AddRef(var_);
} else {
var_.type = PP_VARTYPE_NULL;
needs_release_ = false;
@@ -194,19 +198,20 @@ std::string Var::AsString() const {
return std::string();
}
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return std::string();
uint32_t len;
- const char* str = ppb_var_f->VarToUtf8(var_, &len);
+ const char* str = get_interface<PPB_Var_Deprecated>()->VarToUtf8(var_, &len);
return std::string(str, len);
}
ScriptableObject* Var::AsScriptableObject() const {
if (!is_object()) {
PP_NOTREACHED();
- } else if (ppb_var_f) {
+ } else if (has_interface<PPB_Var_Deprecated>()) {
void* object = NULL;
- if (ppb_var_f->IsInstanceOf(var_, ScriptableObject::GetClass(), &object)) {
+ if (get_interface<PPB_Var_Deprecated>()->IsInstanceOf(
+ var_, ScriptableObject::GetClass(), &object)) {
return reinterpret_cast<ScriptableObject*>(object);
}
}
@@ -214,32 +219,34 @@ ScriptableObject* Var::AsScriptableObject() const {
}
bool Var::HasProperty(const Var& name, Var* exception) const {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return false;
- return ppb_var_f->HasProperty(var_, name.var_, OutException(exception).get());
+ return get_interface<PPB_Var_Deprecated>()->HasProperty(
+ var_, name.var_, OutException(exception).get());
}
bool Var::HasMethod(const Var& name, Var* exception) const {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return false;
- return ppb_var_f->HasMethod(var_, name.var_, OutException(exception).get());
+ return get_interface<PPB_Var_Deprecated>()->HasMethod(
+ var_, name.var_, OutException(exception).get());
}
Var Var::GetProperty(const Var& name, Var* exception) const {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
- return Var(PassRef(), ppb_var_f->GetProperty(var_, name.var_,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->GetProperty(
+ var_, name.var_, OutException(exception).get()));
}
void Var::GetAllPropertyNames(std::vector<Var>* properties,
Var* exception) const {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return;
PP_Var* props = NULL;
uint32_t prop_count = 0;
- ppb_var_f->GetAllPropertyNames(var_, &prop_count, &props,
- OutException(exception).get());
+ get_interface<PPB_Var_Deprecated>()->GetAllPropertyNames(
+ var_, &prop_count, &props, OutException(exception).get());
if (!prop_count)
return;
properties->resize(prop_count);
@@ -251,94 +258,94 @@ void Var::GetAllPropertyNames(std::vector<Var>* properties,
}
void Var::SetProperty(const Var& name, const Var& value, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return;
- ppb_var_f->SetProperty(var_, name.var_, value.var_,
- OutException(exception).get());
+ get_interface<PPB_Var_Deprecated>()->SetProperty(
+ var_, name.var_, value.var_, OutException(exception).get());
}
void Var::RemoveProperty(const Var& name, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return;
- ppb_var_f->RemoveProperty(var_, name.var_, OutException(exception).get());
+ get_interface<PPB_Var_Deprecated>()->RemoveProperty(
+ var_, name.var_, OutException(exception).get());
}
Var Var::Call(const Var& method_name, uint32_t argc, Var* argv,
Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
if (argc > 0) {
std::vector<PP_Var> args;
args.reserve(argc);
for (size_t i = 0; i < argc; i++)
args.push_back(argv[i].var_);
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_,
- argc, &args[0],
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, argc, &args[0], OutException(exception).get()));
} else {
// Don't try to get the address of a vector if it's empty.
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 0, NULL,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 0, NULL, OutException(exception).get()));
}
}
Var Var::Construct(uint32_t argc, Var* argv, Var* exception) const {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
if (argc > 0) {
std::vector<PP_Var> args;
args.reserve(argc);
for (size_t i = 0; i < argc; i++)
args.push_back(argv[i].var_);
- return Var(PassRef(), ppb_var_f->Construct(var_, argc, &args[0],
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct(
+ var_, argc, &args[0], OutException(exception).get()));
} else {
// Don't try to get the address of a vector if it's empty.
- return Var(PassRef(), ppb_var_f->Construct(var_, 0, NULL,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Construct(
+ var_, 0, NULL, OutException(exception).get()));
}
}
Var Var::Call(const Var& method_name, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 0, NULL,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 0, NULL, OutException(exception).get()));
}
Var Var::Call(const Var& method_name, const Var& arg1, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
PP_Var args[1] = {arg1.var_};
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 1, args,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 1, args, OutException(exception).get()));
}
Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2,
Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
PP_Var args[2] = {arg1.var_, arg2.var_};
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 2, args,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 2, args, OutException(exception).get()));
}
Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2,
const Var& arg3, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
PP_Var args[3] = {arg1.var_, arg2.var_, arg3.var_};
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 3, args,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 3, args, OutException(exception).get()));
}
Var Var::Call(const Var& method_name, const Var& arg1, const Var& arg2,
const Var& arg3, const Var& arg4, Var* exception) {
- if (!ppb_var_f)
+ if (!has_interface<PPB_Var_Deprecated>())
return Var();
PP_Var args[4] = {arg1.var_, arg2.var_, arg3.var_, arg4.var_};
- return Var(PassRef(), ppb_var_f->Call(var_, method_name.var_, 4, args,
- OutException(exception).get()));
+ return Var(PassRef(), get_interface<PPB_Var_Deprecated>()->Call(
+ var_, method_name.var_, 4, args, OutException(exception).get()));
}
std::string Var::DebugString() const {