diff options
128 files changed, 684 insertions, 535 deletions
diff --git a/ppapi/cpp/audio.cc b/ppapi/cpp/audio.cc index 00478c5..fc7c55a 100644 --- a/ppapi/cpp/audio.cc +++ b/ppapi/cpp/audio.cc @@ -4,6 +4,7 @@ #include "ppapi/cpp/audio.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" namespace pp { @@ -16,14 +17,14 @@ template <> const char* interface_name<PPB_Audio>() { } // namespace -Audio::Audio(Instance* instance, +Audio::Audio(const InstanceHandle& instance, const AudioConfig& config, PPB_Audio_Callback callback, void* user_data) : config_(config) { if (has_interface<PPB_Audio>()) { PassRefFromConstructor(get_interface<PPB_Audio>()->Create( - instance->pp_instance(), config.pp_resource(), callback, user_data)); + instance.pp_instance(), config.pp_resource(), callback, user_data)); } } diff --git a/ppapi/cpp/audio.h b/ppapi/cpp/audio.h index 8df9f37d..a07fcf5 100644 --- a/ppapi/cpp/audio.h +++ b/ppapi/cpp/audio.h @@ -8,7 +8,6 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/ppb_audio.h" #include "ppapi/cpp/audio_config.h" -#include "ppapi/cpp/instance.h" #include "ppapi/cpp/resource.h" /// @file @@ -17,6 +16,8 @@ namespace pp { +class InstanceHandle; + /// An audio resource. Refer to the /// <a href="/native-client/devguide/coding/audio">Audio</a> /// chapter in the Developer's Guide for information on using this interface. @@ -38,14 +39,17 @@ class Audio : public Resource { /// the device configuration and is specified in the <code>AudioConfig</code> /// documentation. /// - /// @param[in] instance A pointer to an <code>Instance</code> identifying one - /// instance of a module. + /// @param[in] instance The instance with which this resource will be + /// associated. + // /// @param[in] config An <code>AudioConfig</code> containing the audio config /// resource. + // /// @param[in] callback A <code>PPB_Audio_Callback</code> callback function /// that the browser calls when it needs more samples to play. + // /// @param[in] user_data A pointer to user data used in the callback function. - Audio(Instance* instance, + Audio(const InstanceHandle& instance, const AudioConfig& config, PPB_Audio_Callback callback, void* user_data); diff --git a/ppapi/cpp/audio_config.cc b/ppapi/cpp/audio_config.cc index a49515e..ef03922 100644 --- a/ppapi/cpp/audio_config.cc +++ b/ppapi/cpp/audio_config.cc @@ -4,7 +4,7 @@ #include "ppapi/cpp/audio_config.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -23,7 +23,7 @@ AudioConfig::AudioConfig() sample_frame_count_(0) { } -AudioConfig::AudioConfig(Instance* instance, +AudioConfig::AudioConfig(const InstanceHandle& instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) : sample_rate_(sample_rate), @@ -31,27 +31,28 @@ AudioConfig::AudioConfig(Instance* instance, if (has_interface<PPB_AudioConfig>()) { PassRefFromConstructor( get_interface<PPB_AudioConfig>()->CreateStereo16Bit( - instance->pp_instance(), sample_rate, sample_frame_count)); + instance.pp_instance(), sample_rate, sample_frame_count)); } } // static -PP_AudioSampleRate AudioConfig::RecommendSampleRate(Instance* instance) { +PP_AudioSampleRate AudioConfig::RecommendSampleRate( + const InstanceHandle& instance) { if (!has_interface<PPB_AudioConfig>()) return PP_AUDIOSAMPLERATE_NONE; return get_interface<PPB_AudioConfig>()-> - RecommendSampleRate(instance->pp_instance()); + RecommendSampleRate(instance.pp_instance()); } // static uint32_t AudioConfig::RecommendSampleFrameCount( - Instance* instance, + const InstanceHandle& instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count) { if (!has_interface<PPB_AudioConfig>()) return 0; return get_interface<PPB_AudioConfig>()-> - RecommendSampleFrameCount(instance->pp_instance(), + RecommendSampleFrameCount(instance.pp_instance(), sample_rate, requested_sample_frame_count); } diff --git a/ppapi/cpp/audio_config.h b/ppapi/cpp/audio_config.h index ff1d256..e8c47ab 100644 --- a/ppapi/cpp/audio_config.h +++ b/ppapi/cpp/audio_config.h @@ -16,7 +16,7 @@ namespace pp { -class Instance; +class InstanceHandle; /// A 16 bit stereo AudioConfig resource. Refer to the /// <a href="/chrome/nativeclient/docs/audio.html">Pepper @@ -64,21 +64,24 @@ class AudioConfig : public Resource { /// resulting resource will be is_null(). You can pass the result of /// RecommendSampleFrameCount() as the sample frame count. /// - /// @param[in] instance A pointer to an <code>Instance</code> identifying - /// one instance of a module. + /// @param[in] instance The instance with which this resource will be + /// associated. + /// /// @param[in] sample_rate A <code>PP_AudioSampleRate</code> which is either /// <code>PP_AUDIOSAMPLERATE_44100</code> or /// <code>PP_AUDIOSAMPLERATE_48000</code>. + /// /// @param[in] sample_frame_count A uint32_t frame count returned from the /// <code>RecommendSampleFrameCount</code> function. - AudioConfig(Instance* instance, + AudioConfig(const InstanceHandle& instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); /// RecommendSampleRate() returns the native sample rate used by the /// audio system. Applications that use the recommended sample rate might /// obtain lower latency and higher fidelity output. - static PP_AudioSampleRate RecommendSampleRate(Instance* instance); + static PP_AudioSampleRate RecommendSampleRate( + const InstanceHandle& instance); /// RecommendSampleFrameCount() returns a supported frame count closest to /// the requested count. The sample frame count determines the overall @@ -92,8 +95,6 @@ class AudioConfig : public Resource { /// will return a supported count closest to the requested value for use in /// the constructor. /// - /// @param[in] instance A pointer to an <code>Instance</code> identifying - /// one instance of a module. /// @param[in] sample_rate A <code>PP_AudioSampleRate</code> which is either /// <code>PP_AUDIOSAMPLERATE_44100</code> or /// <code>PP_AUDIOSAMPLERATE_48000</code>. @@ -103,7 +104,7 @@ class AudioConfig : public Resource { /// successful. If the sample frame count or bit rate is not supported, /// this function will fail and return 0. static uint32_t RecommendSampleFrameCount( - Instance* instance, + const InstanceHandle& instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count); diff --git a/ppapi/cpp/dev/audio_input_dev.cc b/ppapi/cpp/dev/audio_input_dev.cc index 856a41b..386345b 100644 --- a/ppapi/cpp/dev/audio_input_dev.cc +++ b/ppapi/cpp/dev/audio_input_dev.cc @@ -6,7 +6,7 @@ #include "ppapi/c/dev/ppb_audio_input_dev.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -20,14 +20,14 @@ template <> const char* interface_name<PPB_AudioInput_Dev>() { } // namespace -AudioInput_Dev::AudioInput_Dev(Instance* instance, +AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance, const AudioConfig& config, PPB_AudioInput_Callback callback, void* user_data) : config_(config) { if (has_interface<PPB_AudioInput_Dev>()) { PassRefFromConstructor(get_interface<PPB_AudioInput_Dev>()->Create( - instance->pp_instance(), config.pp_resource(), callback, user_data)); + instance.pp_instance(), config.pp_resource(), callback, user_data)); } } diff --git a/ppapi/cpp/dev/audio_input_dev.h b/ppapi/cpp/dev/audio_input_dev.h index 2fc79c6..2761437 100644 --- a/ppapi/cpp/dev/audio_input_dev.h +++ b/ppapi/cpp/dev/audio_input_dev.h @@ -11,14 +11,14 @@ namespace pp { -class Instance; +class InstanceHandle; class AudioInput_Dev : public Resource { public: /// An empty constructor for an AudioInput resource. AudioInput_Dev() {} - AudioInput_Dev(Instance* instance, + AudioInput_Dev(const InstanceHandle& instance, const AudioConfig& config, PPB_AudioInput_Callback callback, void* user_data); diff --git a/ppapi/cpp/dev/buffer_dev.cc b/ppapi/cpp/dev/buffer_dev.cc index aa616de..7994be2 100644 --- a/ppapi/cpp/dev/buffer_dev.cc +++ b/ppapi/cpp/dev/buffer_dev.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/dev/buffer_dev.h" #include "ppapi/c/dev/ppb_buffer_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -32,14 +32,14 @@ Buffer_Dev::Buffer_Dev(PP_Resource resource) Init(); } -Buffer_Dev::Buffer_Dev(Instance* instance, uint32_t size) +Buffer_Dev::Buffer_Dev(const InstanceHandle& instance, uint32_t size) : data_(NULL), size_(0) { if (!has_interface<PPB_Buffer_Dev>()) return; PassRefFromConstructor(get_interface<PPB_Buffer_Dev>()->Create( - instance->pp_instance(), size)); + instance.pp_instance(), size)); Init(); } diff --git a/ppapi/cpp/dev/buffer_dev.h b/ppapi/cpp/dev/buffer_dev.h index 9e9ac813..da89cba 100644 --- a/ppapi/cpp/dev/buffer_dev.h +++ b/ppapi/cpp/dev/buffer_dev.h @@ -9,7 +9,7 @@ namespace pp { -class Instance; +class InstanceHandle; class Buffer_Dev : public Resource { public: @@ -20,7 +20,7 @@ class Buffer_Dev : public Resource { // Creates & Maps a new Buffer in the browser with the given size. The // resulting object will be is_null() if either Create() or Map() fails. - Buffer_Dev(Instance* instance, uint32_t size); + Buffer_Dev(const InstanceHandle& instance, uint32_t size); // Unmap the underlying shared memory. virtual ~Buffer_Dev(); diff --git a/ppapi/cpp/dev/device_ref_dev.cc b/ppapi/cpp/dev/device_ref_dev.cc index 4fc2bc5..525739e 100644 --- a/ppapi/cpp/dev/device_ref_dev.cc +++ b/ppapi/cpp/dev/device_ref_dev.cc @@ -22,8 +22,8 @@ DeviceRef_Dev::DeviceRef_Dev() { DeviceRef_Dev::DeviceRef_Dev(PP_Resource resource) : Resource(resource) { } -DeviceRef_Dev::DeviceRef_Dev(PassRef, PP_Resource resource) { - PassRefFromConstructor(resource); +DeviceRef_Dev::DeviceRef_Dev(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { } DeviceRef_Dev::DeviceRef_Dev(const DeviceRef_Dev& other) : Resource(other) { @@ -41,7 +41,7 @@ PP_DeviceType_Dev DeviceRef_Dev::GetType() const { Var DeviceRef_Dev::GetName() const { if (!has_interface<PPB_DeviceRef_Dev>()) return Var(); - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_DeviceRef_Dev>()->GetName(pp_resource())); } diff --git a/ppapi/cpp/dev/device_ref_dev.h b/ppapi/cpp/dev/device_ref_dev.h index 515c388..048b956 100644 --- a/ppapi/cpp/dev/device_ref_dev.h +++ b/ppapi/cpp/dev/device_ref_dev.h @@ -17,8 +17,6 @@ class DeviceRef_Dev : public Resource { explicit DeviceRef_Dev(PP_Resource resource); - struct PassRef {}; - DeviceRef_Dev(PassRef, PP_Resource resource); DeviceRef_Dev(const DeviceRef_Dev& other); diff --git a/ppapi/cpp/dev/file_chooser_dev.cc b/ppapi/cpp/dev/file_chooser_dev.cc index ef52b5b0..7987f48 100644 --- a/ppapi/cpp/dev/file_chooser_dev.cc +++ b/ppapi/cpp/dev/file_chooser_dev.cc @@ -8,7 +8,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/file_ref.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -22,13 +22,13 @@ template <> const char* interface_name<PPB_FileChooser_Dev>() { } // namespace -FileChooser_Dev::FileChooser_Dev(const Instance* instance, +FileChooser_Dev::FileChooser_Dev(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, const Var& accept_mime_types) { if (!has_interface<PPB_FileChooser_Dev>()) return; PassRefFromConstructor(get_interface<PPB_FileChooser_Dev>()->Create( - instance->pp_instance(), mode, accept_mime_types.pp_var())); + instance.pp_instance(), mode, accept_mime_types.pp_var())); } FileChooser_Dev::FileChooser_Dev(const FileChooser_Dev& other) @@ -45,7 +45,7 @@ int32_t FileChooser_Dev::Show(const CompletionCallback& cc) { FileRef FileChooser_Dev::GetNextChosenFile() const { if (!has_interface<PPB_FileChooser_Dev>()) return FileRef(); - return FileRef(FileRef::PassRef(), + return FileRef(PASS_REF, get_interface<PPB_FileChooser_Dev>()->GetNextChosenFile(pp_resource())); } diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h index ec0a6d5..c2abc70 100644 --- a/ppapi/cpp/dev/file_chooser_dev.h +++ b/ppapi/cpp/dev/file_chooser_dev.h @@ -12,7 +12,7 @@ namespace pp { class CompletionCallback; class FileRef; -class Instance; +class InstanceHandle; class Var; class FileChooser_Dev : public Resource { @@ -42,7 +42,7 @@ class FileChooser_Dev : public Resource { /// TODO(darin): What if the mime type is unknown to the system? The plugin /// may wish to describe the mime type and provide a matching file extension. /// It is more webby to use mime types here instead of file extensions. - FileChooser_Dev(const Instance* instance, + FileChooser_Dev(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, const Var& accept_mime_types); diff --git a/ppapi/cpp/dev/find_dev.cc b/ppapi/cpp/dev/find_dev.cc index 9a29a5d..331ee43 100644 --- a/ppapi/cpp/dev/find_dev.cc +++ b/ppapi/cpp/dev/find_dev.cc @@ -22,8 +22,7 @@ static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE; PP_Bool StartFind(PP_Instance instance, const char* text, PP_Bool case_sensitive) { - void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface); if (!object) return PP_FALSE; bool return_value = static_cast<Find_Dev*>(object)->StartFind( @@ -32,15 +31,13 @@ PP_Bool StartFind(PP_Instance instance, } void SelectFindResult(PP_Instance instance, PP_Bool forward) { - void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface); if (object) static_cast<Find_Dev*>(object)->SelectFindResult(PP_ToBool(forward)); } void StopFind(PP_Instance instance) { - void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPFindInterface); + void* object = Instance::GetPerInstanceObject(instance, kPPPFindInterface); if (object) static_cast<Find_Dev*>(object)->StopFind(); } @@ -53,26 +50,28 @@ const PPP_Find_Dev ppp_find = { } // 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(const InstanceHandle& instance) + : associated_instance_(instance) { + Module::Get()->AddPluginInterface(kPPPFindInterface, &ppp_find); + Instance::AddPerInstanceObject(instance, kPPPFindInterface, this); } Find_Dev::~Find_Dev() { - associated_instance_->RemovePerInstanceObject(kPPPFindInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPFindInterface, this); } void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) { if (has_interface<PPB_Find_Dev>()) { get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged( - associated_instance_->pp_instance(), total, PP_FromBool(final_result)); + associated_instance_.pp_instance(), total, PP_FromBool(final_result)); } } void Find_Dev::SelectedFindResultChanged(int32_t index) { if (has_interface<PPB_Find_Dev>()) { get_interface<PPB_Find_Dev>()->SelectedFindResultChanged( - associated_instance_->pp_instance(), index); + associated_instance_.pp_instance(), index); } } diff --git a/ppapi/cpp/dev/find_dev.h b/ppapi/cpp/dev/find_dev.h index b89160f..4e96f68 100644 --- a/ppapi/cpp/dev/find_dev.h +++ b/ppapi/cpp/dev/find_dev.h @@ -8,11 +8,10 @@ #include <string> #include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/cpp/instance_handle.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 @@ -39,7 +38,7 @@ class Instance; class Find_Dev { public: // The instance parameter must outlive this class. - Find_Dev(Instance* instance); + Find_Dev(const InstanceHandle& instance); virtual ~Find_Dev(); // PPP_Find_Dev functions exposed as virtual functions for you to @@ -53,7 +52,7 @@ class Find_Dev { void SelectedFindResultChanged(int32_t index); private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/font_dev.cc b/ppapi/cpp/dev/font_dev.cc index 568e816..4c74d47 100644 --- a/ppapi/cpp/dev/font_dev.cc +++ b/ppapi/cpp/dev/font_dev.cc @@ -7,7 +7,7 @@ #include <algorithm> #include "ppapi/cpp/image_data.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/point.h" #include "ppapi/cpp/rect.h" #include "ppapi/cpp/module_impl.h" @@ -102,11 +102,12 @@ Font_Dev::Font_Dev() : Resource() { Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { } -Font_Dev::Font_Dev(Instance* instance, const FontDescription_Dev& description) { +Font_Dev::Font_Dev(const InstanceHandle& instance, + const FontDescription_Dev& description) { if (!has_interface<PPB_Font_Dev>()) return; PassRefFromConstructor(get_interface<PPB_Font_Dev>()->Create( - instance->pp_instance(), &description.pp_font_description())); + instance.pp_instance(), &description.pp_font_description())); } Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { @@ -118,12 +119,11 @@ Font_Dev& Font_Dev::operator=(const Font_Dev& other) { } // static -Var Font_Dev::GetFontFamilies(Instance* instance) { +Var Font_Dev::GetFontFamilies(const InstanceHandle& instance) { if (!has_interface<PPB_Font_Dev>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_Font_Dev>()->GetFontFamilies( - instance->pp_instance())); + return Var(PASS_REF, get_interface<PPB_Font_Dev>()->GetFontFamilies( + instance.pp_instance())); } bool Font_Dev::Describe(FontDescription_Dev* description, @@ -136,7 +136,7 @@ bool Font_Dev::Describe(FontDescription_Dev* description, if (!get_interface<PPB_Font_Dev>()->Describe( pp_resource(), &description->pp_font_description_, metrics)) return false; - description->face_ = Var(Var::PassRef(), + description->face_ = Var(PASS_REF, description->pp_font_description_.face); return true; diff --git a/ppapi/cpp/dev/font_dev.h b/ppapi/cpp/dev/font_dev.h index a9604e9..d0875a5 100644 --- a/ppapi/cpp/dev/font_dev.h +++ b/ppapi/cpp/dev/font_dev.h @@ -16,7 +16,7 @@ struct PP_FontDescription_Dev; namespace pp { class ImageData; -class Instance; +class InstanceHandle; class Point; class Rect; @@ -103,13 +103,14 @@ class Font_Dev : public Resource { Font_Dev(); explicit Font_Dev(PP_Resource resource); - Font_Dev(Instance* instance, const FontDescription_Dev& description); + Font_Dev(const InstanceHandle& instance, + const FontDescription_Dev& description); Font_Dev(const Font_Dev& other); Font_Dev& operator=(const Font_Dev& other); // PPB_Font methods: - static Var GetFontFamilies(Instance* instance); + static Var GetFontFamilies(const InstanceHandle& instance); bool Describe(FontDescription_Dev* description, PP_FontMetrics_Dev* metrics) const; bool DrawTextAt(ImageData* dest, diff --git a/ppapi/cpp/dev/fullscreen_dev.cc b/ppapi/cpp/dev/fullscreen_dev.cc index 46af7ea..9e6a542 100644 --- a/ppapi/cpp/dev/fullscreen_dev.cc +++ b/ppapi/cpp/dev/fullscreen_dev.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/dev/fullscreen_dev.h" #include "ppapi/c/dev/ppb_fullscreen_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/size.h" @@ -20,7 +20,7 @@ template <> const char* interface_name<PPB_Fullscreen_Dev>() { } // namespace -Fullscreen_Dev::Fullscreen_Dev(Instance* instance) +Fullscreen_Dev::Fullscreen_Dev(const InstanceHandle& instance) : instance_(instance) { } @@ -30,21 +30,21 @@ Fullscreen_Dev::~Fullscreen_Dev() { bool Fullscreen_Dev::IsFullscreen() { return has_interface<PPB_Fullscreen_Dev>() && get_interface<PPB_Fullscreen_Dev>()->IsFullscreen( - instance_->pp_instance()); + instance_.pp_instance()); } bool Fullscreen_Dev::SetFullscreen(bool fullscreen) { if (!has_interface<PPB_Fullscreen_Dev>()) return false; return PP_ToBool(get_interface<PPB_Fullscreen_Dev>()->SetFullscreen( - instance_->pp_instance(), PP_FromBool(fullscreen))); + instance_.pp_instance(), PP_FromBool(fullscreen))); } bool Fullscreen_Dev::GetScreenSize(Size* size) { if (!has_interface<PPB_Fullscreen_Dev>()) return false; return PP_ToBool(get_interface<PPB_Fullscreen_Dev>()->GetScreenSize( - instance_->pp_instance(), &size->pp_size())); + instance_.pp_instance(), &size->pp_size())); } } // namespace pp diff --git a/ppapi/cpp/dev/fullscreen_dev.h b/ppapi/cpp/dev/fullscreen_dev.h index 9a11031..96c1ba2 100644 --- a/ppapi/cpp/dev/fullscreen_dev.h +++ b/ppapi/cpp/dev/fullscreen_dev.h @@ -5,14 +5,15 @@ #ifndef PPAPI_CPP_DEV_FULLSCREEN_DEV_H_ #define PPAPI_CPP_DEV_FULLSCREEN_DEV_H_ +#include "ppapi/cpp/instance_handle.h" + namespace pp { -class Instance; class Size; class Fullscreen_Dev { public: - Fullscreen_Dev(Instance* instance); + Fullscreen_Dev(const InstanceHandle& instance); virtual ~Fullscreen_Dev(); // PPB_Fullscreen_Dev methods. @@ -21,7 +22,7 @@ class Fullscreen_Dev { bool GetScreenSize(Size* size); private: - Instance* instance_; + InstanceHandle instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/ime_input_event_dev.cc b/ppapi/cpp/dev/ime_input_event_dev.cc index bc1f387..6f920e9 100644 --- a/ppapi/cpp/dev/ime_input_event_dev.cc +++ b/ppapi/cpp/dev/ime_input_event_dev.cc @@ -38,7 +38,7 @@ IMEInputEvent_Dev::IMEInputEvent_Dev(const InputEvent& event) : InputEvent() { Var IMEInputEvent_Dev::GetText() const { if (!has_interface<PPB_IMEInputEvent_Dev>()) return Var(); - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_IMEInputEvent_Dev>()->GetText(pp_resource())); } diff --git a/ppapi/cpp/dev/message_loop_dev.cc b/ppapi/cpp/dev/message_loop_dev.cc index f212c06..cbe589f 100644 --- a/ppapi/cpp/dev/message_loop_dev.cc +++ b/ppapi/cpp/dev/message_loop_dev.cc @@ -7,7 +7,7 @@ #include "ppapi/c/dev/ppb_message_loop_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" namespace pp { @@ -23,10 +23,10 @@ template <> const char* interface_name<PPB_MessageLoop_Dev>() { MessageLoop_Dev::MessageLoop_Dev() : Resource() { } -MessageLoop_Dev::MessageLoop_Dev(Instance* instance) : Resource() { +MessageLoop_Dev::MessageLoop_Dev(const InstanceHandle& instance) : Resource() { if (has_interface<PPB_MessageLoop_Dev>()) { PassRefFromConstructor(get_interface<PPB_MessageLoop_Dev>()->Create( - instance->pp_instance())); + instance.pp_instance())); } } diff --git a/ppapi/cpp/dev/message_loop_dev.h b/ppapi/cpp/dev/message_loop_dev.h index b558ea4..11f1dfa 100644 --- a/ppapi/cpp/dev/message_loop_dev.h +++ b/ppapi/cpp/dev/message_loop_dev.h @@ -10,7 +10,7 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; /// A message loop allows PPAPI calls to be issued on a thread. You may not /// issue any API calls on a thread without creating a message loop. It also @@ -135,7 +135,7 @@ class MessageLoop_Dev : public Resource { /// This may be called from any thread. After your thread starts but before /// issuing any other PPAPI calls on it, you must associate it with a message /// loop by calling AttachToCurrentThread. - explicit MessageLoop_Dev(Instance* instance); + explicit MessageLoop_Dev(const InstanceHandle& instance); MessageLoop_Dev(const MessageLoop_Dev& other); diff --git a/ppapi/cpp/dev/printing_dev.cc b/ppapi/cpp/dev/printing_dev.cc index 6c07be9..26fff41 100644 --- a/ppapi/cpp/dev/printing_dev.cc +++ b/ppapi/cpp/dev/printing_dev.cc @@ -5,6 +5,7 @@ #include "ppapi/cpp/dev/printing_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -16,7 +17,7 @@ static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE; uint32_t QuerySupportedFormats(PP_Instance instance) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); if (!object) return 0; return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats(); @@ -25,7 +26,7 @@ uint32_t QuerySupportedFormats(PP_Instance instance) { int32_t Begin(PP_Instance instance, const struct PP_PrintSettings_Dev* print_settings) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); + Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); if (!object) return 0; return static_cast<Printing_Dev*>(object)->PrintBegin(*print_settings); @@ -69,14 +70,15 @@ const PPP_Printing_Dev ppp_printing = { } // namespace -Printing_Dev::Printing_Dev(Instance* instance) +Printing_Dev::Printing_Dev(const InstanceHandle& instance) : associated_instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing); - associated_instance_->AddPerInstanceObject(kPPPPrintingInterface, this); + Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing); + Instance::AddPerInstanceObject(instance, kPPPPrintingInterface, this); } Printing_Dev::~Printing_Dev() { - associated_instance_->RemovePerInstanceObject(kPPPPrintingInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPPrintingInterface, this); } } // namespace pp diff --git a/ppapi/cpp/dev/printing_dev.h b/ppapi/cpp/dev/printing_dev.h index 6b8d7d0..c2b6b05 100644 --- a/ppapi/cpp/dev/printing_dev.h +++ b/ppapi/cpp/dev/printing_dev.h @@ -6,18 +6,17 @@ #define PPAPI_CPP_DEV_PRINTING_DEV_H_ #include "ppapi/c/dev/ppp_printing_dev.h" +#include "ppapi/cpp/instance_handle.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); + explicit Printing_Dev(const InstanceHandle& instance); virtual ~Printing_Dev(); // PPP_Printing_Dev functions exposed as virtual functions for you to @@ -30,7 +29,7 @@ class Printing_Dev { virtual bool IsPrintScalingDisabled() = 0; private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/resource_array_dev.cc b/ppapi/cpp/dev/resource_array_dev.cc index 4193e0f..6a8493f 100644 --- a/ppapi/cpp/dev/resource_array_dev.cc +++ b/ppapi/cpp/dev/resource_array_dev.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/dev/resource_array_dev.h" #include "ppapi/c/dev/ppb_resource_array_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" namespace pp { @@ -21,20 +21,20 @@ template <> const char* interface_name<PPB_ResourceArray_Dev>() { ResourceArray_Dev::ResourceArray_Dev() { } -ResourceArray_Dev::ResourceArray_Dev(PassRef, PP_Resource resource) { - PassRefFromConstructor(resource); +ResourceArray_Dev::ResourceArray_Dev(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { } ResourceArray_Dev::ResourceArray_Dev(const ResourceArray_Dev& other) : Resource(other) { } -ResourceArray_Dev::ResourceArray_Dev(Instance* instance, +ResourceArray_Dev::ResourceArray_Dev(const InstanceHandle& instance, const PP_Resource elements[], uint32_t size) { - if (has_interface<PPB_ResourceArray_Dev>() && instance) { + if (has_interface<PPB_ResourceArray_Dev>()) { PassRefFromConstructor(get_interface<PPB_ResourceArray_Dev>()->Create( - instance->pp_instance(), elements, size)); + instance.pp_instance(), elements, size)); } } diff --git a/ppapi/cpp/dev/resource_array_dev.h b/ppapi/cpp/dev/resource_array_dev.h index 1d5a25f..9d9635c 100644 --- a/ppapi/cpp/dev/resource_array_dev.h +++ b/ppapi/cpp/dev/resource_array_dev.h @@ -10,19 +10,17 @@ namespace pp { -class Instance; +class InstanceHandle; class ResourceArray_Dev : public Resource { public: ResourceArray_Dev(); - struct PassRef {}; - ResourceArray_Dev(PassRef, PP_Resource resource); ResourceArray_Dev(const ResourceArray_Dev& other); - ResourceArray_Dev(Instance* instance, + ResourceArray_Dev(const InstanceHandle& instance, const PP_Resource elements[], uint32_t size); diff --git a/ppapi/cpp/dev/scrollbar_dev.cc b/ppapi/cpp/dev/scrollbar_dev.cc index dc133a9..26eb9ef 100644 --- a/ppapi/cpp/dev/scrollbar_dev.cc +++ b/ppapi/cpp/dev/scrollbar_dev.cc @@ -6,7 +6,7 @@ #include "ppapi/cpp/dev/scrollbar_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/rect.h" @@ -24,7 +24,7 @@ template <> const char* interface_name<PPB_Scrollbar_Dev>() { Scrollbar_Dev::Scrollbar_Dev(PP_Resource resource) : Widget_Dev(resource) { } -Scrollbar_Dev::Scrollbar_Dev(const Instance& instance, bool vertical) { +Scrollbar_Dev::Scrollbar_Dev(const InstanceHandle& instance, bool vertical) { if (!has_interface<PPB_Scrollbar_Dev>()) return; PassRefFromConstructor(get_interface<PPB_Scrollbar_Dev>()->Create( diff --git a/ppapi/cpp/dev/scrollbar_dev.h b/ppapi/cpp/dev/scrollbar_dev.h index f7944e9..fabbbd7 100644 --- a/ppapi/cpp/dev/scrollbar_dev.h +++ b/ppapi/cpp/dev/scrollbar_dev.h @@ -10,7 +10,7 @@ namespace pp { -class Instance; +class InstanceHandle; // This class allows a plugin to use the browser's scrollbar widget. class Scrollbar_Dev : public Widget_Dev { @@ -19,7 +19,7 @@ class Scrollbar_Dev : public Widget_Dev { Scrollbar_Dev() {} explicit Scrollbar_Dev(PP_Resource resource); - Scrollbar_Dev(const Instance& instance, bool vertical); + Scrollbar_Dev(const InstanceHandle& instance, bool vertical); Scrollbar_Dev(const Scrollbar_Dev& other); Scrollbar_Dev& operator=(const Scrollbar_Dev& other); diff --git a/ppapi/cpp/dev/selection_dev.cc b/ppapi/cpp/dev/selection_dev.cc index b086ac1..37bbbeb 100644 --- a/ppapi/cpp/dev/selection_dev.cc +++ b/ppapi/cpp/dev/selection_dev.cc @@ -5,6 +5,7 @@ #include "ppapi/cpp/dev/selection_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/var.h" @@ -29,14 +30,15 @@ const PPP_Selection_Dev ppp_selection = { } // namespace -Selection_Dev::Selection_Dev(Instance* instance) +Selection_Dev::Selection_Dev(const InstanceHandle& instance) : associated_instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPSelectionInterface, &ppp_selection); - associated_instance_->AddPerInstanceObject(kPPPSelectionInterface, this); + Module::Get()->AddPluginInterface(kPPPSelectionInterface, &ppp_selection); + Instance::AddPerInstanceObject(instance, kPPPSelectionInterface, this); } Selection_Dev::~Selection_Dev() { - associated_instance_->RemovePerInstanceObject(kPPPSelectionInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPSelectionInterface, this); } } // namespace pp diff --git a/ppapi/cpp/dev/selection_dev.h b/ppapi/cpp/dev/selection_dev.h index 282bdb4..7e9fa2b 100644 --- a/ppapi/cpp/dev/selection_dev.h +++ b/ppapi/cpp/dev/selection_dev.h @@ -6,10 +6,10 @@ #define PPAPI_CPP_DEV_SELECTION_DEV_H_ #include "ppapi/c/dev/ppp_selection_dev.h" +#include "ppapi/cpp/instance_handle.h" namespace pp { -class Instance; class Var; // This class allows you to associate the PPP_Selection_Dev C-based interface @@ -36,7 +36,7 @@ class Var; // }; class Selection_Dev { public: - Selection_Dev(Instance* instance); + explicit Selection_Dev(const InstanceHandle& instance); virtual ~Selection_Dev(); // PPP_Selection_Dev functions exposed as virtual functions for you to @@ -44,7 +44,7 @@ class Selection_Dev { virtual Var GetSelectedText(bool html) = 0; private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/text_input_dev.cc b/ppapi/cpp/dev/text_input_dev.cc index 6388836..6783892 100644 --- a/ppapi/cpp/dev/text_input_dev.cc +++ b/ppapi/cpp/dev/text_input_dev.cc @@ -4,7 +4,7 @@ #include "ppapi/cpp/dev/text_input_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/rect.h" @@ -19,7 +19,8 @@ template <> const char* interface_name<PPB_TextInput_Dev>() { } // namespace -TextInput_Dev::TextInput_Dev(Instance* instance) : instance_(instance) { +TextInput_Dev::TextInput_Dev(const InstanceHandle& instance) + : instance_(instance) { } TextInput_Dev::~TextInput_Dev() { @@ -29,7 +30,7 @@ void TextInput_Dev::SetTextInputType(PP_TextInput_Type type) { if (!has_interface<PPB_TextInput_Dev>()) return; get_interface<PPB_TextInput_Dev>()->SetTextInputType( - instance_->pp_instance(), type); + instance_.pp_instance(), type); } void TextInput_Dev::UpdateCaretPosition(const Rect& caret, @@ -37,14 +38,14 @@ void TextInput_Dev::UpdateCaretPosition(const Rect& caret, if (!has_interface<PPB_TextInput_Dev>()) return; get_interface<PPB_TextInput_Dev>()->UpdateCaretPosition( - instance_->pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect()); + instance_.pp_instance(), &caret.pp_rect(), &bounding_box.pp_rect()); } void TextInput_Dev::CancelCompositionText() { if (!has_interface<PPB_TextInput_Dev>()) return; get_interface<PPB_TextInput_Dev>()->CancelCompositionText( - instance_->pp_instance()); + instance_.pp_instance()); } } // namespace pp diff --git a/ppapi/cpp/dev/text_input_dev.h b/ppapi/cpp/dev/text_input_dev.h index 79fadd6..af21a90 100644 --- a/ppapi/cpp/dev/text_input_dev.h +++ b/ppapi/cpp/dev/text_input_dev.h @@ -6,17 +6,17 @@ #define PPAPI_CPP_DEV_TEXT_INPUT_DEV_H_ #include "ppapi/c/dev/ppb_text_input_dev.h" +#include "ppapi/cpp/instance_handle.h" /// @file /// This file defines the API for controlling text input methods. namespace pp { -class Instance; class Rect; class TextInput_Dev { public: - explicit TextInput_Dev(Instance* instance); + explicit TextInput_Dev(const InstanceHandle& instance); virtual ~TextInput_Dev(); void SetTextInputType(PP_TextInput_Type type); @@ -24,7 +24,7 @@ class TextInput_Dev { void CancelCompositionText(); private: - Instance* instance_; + InstanceHandle instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc index 6c163fd..c1153b8 100644 --- a/ppapi/cpp/dev/transport_dev.cc +++ b/ppapi/cpp/dev/transport_dev.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/dev/transport_dev.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/resource.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -21,12 +21,12 @@ template <> const char* interface_name<PPB_Transport_Dev>() { } // namespace -Transport_Dev::Transport_Dev(Instance* instance, +Transport_Dev::Transport_Dev(const InstanceHandle& instance, const char* name, PP_TransportType type) { if (has_interface<PPB_Transport_Dev>()) PassRefFromConstructor(get_interface<PPB_Transport_Dev>()->CreateTransport( - instance->pp_instance(), name, type)); + instance.pp_instance(), name, type)); } bool Transport_Dev::IsWritable() { @@ -58,7 +58,7 @@ int32_t Transport_Dev::GetNextAddress(Var* address, PP_Var temp_address = PP_MakeUndefined(); int32_t ret_val = get_interface<PPB_Transport_Dev>()->GetNextAddress( pp_resource(), &temp_address, cc.pp_completion_callback()); - *address = Var(Var::PassRef(), temp_address); + *address = Var(PASS_REF, temp_address); return ret_val; } diff --git a/ppapi/cpp/dev/transport_dev.h b/ppapi/cpp/dev/transport_dev.h index cf0721e..8545583 100644 --- a/ppapi/cpp/dev/transport_dev.h +++ b/ppapi/cpp/dev/transport_dev.h @@ -11,12 +11,14 @@ namespace pp { -class Instance; +class InstanceHandle; class Var; class Transport_Dev : public Resource { public: - Transport_Dev(Instance* instance, const char* name, PP_TransportType type); + Transport_Dev(const InstanceHandle& instance, + const char* name, + PP_TransportType type); bool IsWritable(); int32_t SetProperty(PP_TransportProperty property, const Var& value); diff --git a/ppapi/cpp/dev/url_util_dev.cc b/ppapi/cpp/dev/url_util_dev.cc index 3d07cb4..0353883 100644 --- a/ppapi/cpp/dev/url_util_dev.cc +++ b/ppapi/cpp/dev/url_util_dev.cc @@ -4,7 +4,7 @@ #include "ppapi/cpp/dev/url_util_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" namespace pp { @@ -27,24 +27,23 @@ const URLUtil_Dev* URLUtil_Dev::Get() { Var URLUtil_Dev::Canonicalize(const Var& url, PP_URLComponents_Dev* components) const { - return Var(Var::PassRef(), - interface_->Canonicalize(url.pp_var(), components)); + return Var(PASS_REF, 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(), + return Var(PASS_REF, interface_->ResolveRelativeToURL(base_url.pp_var(), relative_string.pp_var(), components)); } Var URLUtil_Dev::ResolveRelativeToDocument( - const Instance& instance, + const InstanceHandle& instance, const Var& relative_string, PP_URLComponents_Dev* components) const { - return Var(Var::PassRef(), + return Var(PASS_REF, interface_->ResolveRelativeToDocument(instance.pp_instance(), relative_string.pp_var(), components)); @@ -56,28 +55,29 @@ bool URLUtil_Dev::IsSameSecurityOrigin(const Var& url_a, url_b.pp_var())); } -bool URLUtil_Dev::DocumentCanRequest(const Instance& instance, +bool URLUtil_Dev::DocumentCanRequest(const InstanceHandle& instance, const Var& url) const { return PP_ToBool(interface_->DocumentCanRequest(instance.pp_instance(), url.pp_var())); } -bool URLUtil_Dev::DocumentCanAccessDocument(const Instance& active, - const Instance& target) const { +bool URLUtil_Dev::DocumentCanAccessDocument( + const InstanceHandle& active, + const InstanceHandle& target) const { return PP_ToBool( interface_->DocumentCanAccessDocument(active.pp_instance(), target.pp_instance())); } -Var URLUtil_Dev::GetDocumentURL(const Instance& instance, +Var URLUtil_Dev::GetDocumentURL(const InstanceHandle& instance, PP_URLComponents_Dev* components) const { - return Var(Var::PassRef(), + return Var(PASS_REF, interface_->GetDocumentURL(instance.pp_instance(), components)); } -Var URLUtil_Dev::GetPluginInstanceURL(const Instance& instance, +Var URLUtil_Dev::GetPluginInstanceURL(const InstanceHandle& instance, PP_URLComponents_Dev* components) const { - return Var(Var::PassRef(), + return Var(PASS_REF, interface_->GetPluginInstanceURL(instance.pp_instance(), components)); } diff --git a/ppapi/cpp/dev/url_util_dev.h b/ppapi/cpp/dev/url_util_dev.h index 168e796..056c79b 100644 --- a/ppapi/cpp/dev/url_util_dev.h +++ b/ppapi/cpp/dev/url_util_dev.h @@ -10,7 +10,7 @@ namespace pp { -class Instance; +class InstanceHandle; // Simple wrapper around the PPB_URLUtil interface. class URLUtil_Dev { @@ -28,18 +28,18 @@ class URLUtil_Dev { Var ResolveRelativeToURL(const Var& base_url, const Var& relative_string, PP_URLComponents_Dev* components = NULL) const; - Var ResolveRelativeToDocument(const Instance& instance, + Var ResolveRelativeToDocument(const InstanceHandle& 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; - Var GetDocumentURL(const Instance& instance, + bool DocumentCanRequest(const InstanceHandle& instance, const Var& url) const; + bool DocumentCanAccessDocument(const InstanceHandle& active, + const InstanceHandle& target) const; + Var GetDocumentURL(const InstanceHandle& instance, PP_URLComponents_Dev* components = NULL) const; - Var GetPluginInstanceURL(const Instance& instance, + Var GetPluginInstanceURL(const InstanceHandle& instance, PP_URLComponents_Dev* components = NULL) const; private: diff --git a/ppapi/cpp/dev/video_capture_client_dev.cc b/ppapi/cpp/dev/video_capture_client_dev.cc index 1bebeec..22a6b9b 100644 --- a/ppapi/cpp/dev/video_capture_client_dev.cc +++ b/ppapi/cpp/dev/video_capture_client_dev.cc @@ -6,6 +6,7 @@ #include "ppapi/c/dev/ppp_video_capture_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" namespace pp { @@ -64,15 +65,16 @@ PPP_VideoCapture_Dev ppp_video_capture = { } // namespace -VideoCaptureClient_Dev::VideoCaptureClient_Dev(Instance* instance) +VideoCaptureClient_Dev::VideoCaptureClient_Dev(const InstanceHandle& instance) : instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPVideoCaptureInterface, - &ppp_video_capture); - instance_->AddPerInstanceObject(kPPPVideoCaptureInterface, this); + Module::Get()->AddPluginInterface(kPPPVideoCaptureInterface, + &ppp_video_capture); + Instance::AddPerInstanceObject(instance, kPPPVideoCaptureInterface, this); } VideoCaptureClient_Dev::~VideoCaptureClient_Dev() { - instance_->RemovePerInstanceObject(kPPPVideoCaptureInterface, this); + Instance::RemovePerInstanceObject(instance_, + kPPPVideoCaptureInterface, this); } } // namespace pp diff --git a/ppapi/cpp/dev/video_capture_client_dev.h b/ppapi/cpp/dev/video_capture_client_dev.h index 77d0ed9..31fbcf5 100644 --- a/ppapi/cpp/dev/video_capture_client_dev.h +++ b/ppapi/cpp/dev/video_capture_client_dev.h @@ -9,15 +9,14 @@ #include "ppapi/c/dev/pp_video_capture_dev.h" #include "ppapi/cpp/dev/buffer_dev.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/resource.h" namespace pp { -class Instance; - class VideoCaptureClient_Dev { public: - explicit VideoCaptureClient_Dev(Instance* instance); + explicit VideoCaptureClient_Dev(const InstanceHandle& instance); virtual ~VideoCaptureClient_Dev(); virtual void OnDeviceInfo(PP_Resource video_capture, @@ -28,7 +27,7 @@ class VideoCaptureClient_Dev { virtual void OnBufferReady(PP_Resource video_capture, uint32_t buffer) = 0; private: - Instance* instance_; + InstanceHandle instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/video_capture_dev.cc b/ppapi/cpp/dev/video_capture_dev.cc index 7e590b6..c1c60ec 100644 --- a/ppapi/cpp/dev/video_capture_dev.cc +++ b/ppapi/cpp/dev/video_capture_dev.cc @@ -9,7 +9,7 @@ #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/dev/device_ref_dev.h" #include "ppapi/cpp/dev/resource_array_dev.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -39,7 +39,7 @@ struct VideoCapture_Dev::EnumerateDevicesState { VideoCapture_Dev* video_capture; }; -VideoCapture_Dev::VideoCapture_Dev(const Instance& instance) +VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) : enum_state_(NULL) { if (!has_interface<PPB_VideoCapture_Dev>()) return; @@ -149,8 +149,7 @@ void VideoCapture_Dev::OnEnumerateDevicesComplete(void* user_data, if (result == PP_OK) { // It will take care of releasing the reference. - ResourceArray_Dev resources(ResourceArray_Dev::PassRef(), - enum_state->devices_resource); + ResourceArray_Dev resources(pp::PASS_REF, enum_state->devices_resource); if (need_to_callback) { enum_state->devices->clear(); diff --git a/ppapi/cpp/dev/video_capture_dev.h b/ppapi/cpp/dev/video_capture_dev.h index 1760cf7..712f9e8 100644 --- a/ppapi/cpp/dev/video_capture_dev.h +++ b/ppapi/cpp/dev/video_capture_dev.h @@ -14,11 +14,11 @@ namespace pp { class CompletionCallback; class DeviceRef_Dev; -class Instance; +class InstanceHandle; class VideoCapture_Dev : public Resource { public: - explicit VideoCapture_Dev(const Instance& instance); + explicit VideoCapture_Dev(const InstanceHandle& instance); VideoCapture_Dev(PP_Resource resource); VideoCapture_Dev(const VideoCapture_Dev& other); diff --git a/ppapi/cpp/dev/video_decoder_client_dev.cc b/ppapi/cpp/dev/video_decoder_client_dev.cc index 20cd329..4c34530 100644 --- a/ppapi/cpp/dev/video_decoder_client_dev.cc +++ b/ppapi/cpp/dev/video_decoder_client_dev.cc @@ -7,6 +7,7 @@ #include "ppapi/c/dev/ppp_video_decoder_dev.h" #include "ppapi/cpp/dev/video_decoder_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -21,8 +22,8 @@ void ProvidePictureBuffers(PP_Instance instance, PP_Resource decoder, uint32_t req_num_of_bufs, const PP_Size* dimensions) { - void* object = pp::Instance::GetPerInstanceObject( - instance, kPPPVideoDecoderInterface); + void* object = Instance::GetPerInstanceObject(instance, + kPPPVideoDecoderInterface); if (!object) return; static_cast<VideoDecoderClient_Dev*>(object)->ProvidePictureBuffers( @@ -32,8 +33,8 @@ void ProvidePictureBuffers(PP_Instance instance, void DismissPictureBuffer(PP_Instance instance, PP_Resource decoder, int32_t picture_buffer_id) { - void* object = pp::Instance::GetPerInstanceObject( - instance, kPPPVideoDecoderInterface); + void* object = Instance::GetPerInstanceObject(instance, + kPPPVideoDecoderInterface); if (!object) return; static_cast<VideoDecoderClient_Dev*>(object)->DismissPictureBuffer( @@ -43,8 +44,8 @@ void DismissPictureBuffer(PP_Instance instance, void PictureReady(PP_Instance instance, PP_Resource decoder, const PP_Picture_Dev* picture) { - void* object = pp::Instance::GetPerInstanceObject( - instance, kPPPVideoDecoderInterface); + void* object = Instance::GetPerInstanceObject(instance, + kPPPVideoDecoderInterface); if (!object) return; static_cast<VideoDecoderClient_Dev*>(object)->PictureReady(decoder, *picture); @@ -53,8 +54,8 @@ void PictureReady(PP_Instance instance, void NotifyError(PP_Instance instance, PP_Resource decoder, PP_VideoDecodeError_Dev error) { - void* object = pp::Instance::GetPerInstanceObject( - instance, kPPPVideoDecoderInterface); + void* object = Instance::GetPerInstanceObject(instance, + kPPPVideoDecoderInterface); if (!object) return; static_cast<VideoDecoderClient_Dev*>(object)->NotifyError(decoder, error); @@ -69,17 +70,16 @@ static PPP_VideoDecoder_Dev videodecoder_interface = { } // namespace -VideoDecoderClient_Dev::VideoDecoderClient_Dev(Instance* instance) +VideoDecoderClient_Dev::VideoDecoderClient_Dev(const InstanceHandle& instance) : associated_instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPVideoDecoderInterface, - &videodecoder_interface); - associated_instance_->AddPerInstanceObject( - kPPPVideoDecoderInterface, this); + Module::Get()->AddPluginInterface(kPPPVideoDecoderInterface, + &videodecoder_interface); + Instance::AddPerInstanceObject(instance, kPPPVideoDecoderInterface, this); } VideoDecoderClient_Dev::~VideoDecoderClient_Dev() { - associated_instance_->RemovePerInstanceObject( - kPPPVideoDecoderInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPVideoDecoderInterface, this); } } // namespace pp diff --git a/ppapi/cpp/dev/video_decoder_client_dev.h b/ppapi/cpp/dev/video_decoder_client_dev.h index 7280736..77aa135 100644 --- a/ppapi/cpp/dev/video_decoder_client_dev.h +++ b/ppapi/cpp/dev/video_decoder_client_dev.h @@ -7,10 +7,10 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/cpp/instance_handle.h" namespace pp { -class Instance; class VideoDecoder_Dev; // This class provides a C++ interface for callbacks related to video decoding. @@ -19,7 +19,7 @@ class VideoDecoder_Dev; // instance. class VideoDecoderClient_Dev { public: - VideoDecoderClient_Dev(Instance* instance); + VideoDecoderClient_Dev(const InstanceHandle& instance); virtual ~VideoDecoderClient_Dev(); // Callback to provide buffers for the decoded output pictures. @@ -41,7 +41,7 @@ class VideoDecoderClient_Dev { PP_VideoDecodeError_Dev error) = 0; private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/video_decoder_dev.cc b/ppapi/cpp/dev/video_decoder_dev.cc index dcc7312..92bbe1c 100644 --- a/ppapi/cpp/dev/video_decoder_dev.cc +++ b/ppapi/cpp/dev/video_decoder_dev.cc @@ -8,7 +8,7 @@ #include "ppapi/c/dev/ppp_video_decoder_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/graphics_3d.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -22,13 +22,13 @@ template <> const char* interface_name<PPB_VideoDecoder_Dev>() { } // namespace -VideoDecoder_Dev::VideoDecoder_Dev(const Instance* instance, +VideoDecoder_Dev::VideoDecoder_Dev(const InstanceHandle& instance, const Graphics3D& context, PP_VideoDecoder_Profile profile) { if (!has_interface<PPB_VideoDecoder_Dev>()) return; PassRefFromConstructor(get_interface<PPB_VideoDecoder_Dev>()->Create( - instance->pp_instance(), context.pp_resource(), profile)); + instance.pp_instance(), context.pp_resource(), profile)); } VideoDecoder_Dev::VideoDecoder_Dev(PP_Resource resource) : Resource(resource) { diff --git a/ppapi/cpp/dev/video_decoder_dev.h b/ppapi/cpp/dev/video_decoder_dev.h index 9eb8f2e..c33ce2d 100644 --- a/ppapi/cpp/dev/video_decoder_dev.h +++ b/ppapi/cpp/dev/video_decoder_dev.h @@ -15,7 +15,7 @@ namespace pp { class Graphics3D; -class Instance; +class InstanceHandle; // C++ wrapper for the Pepper Video Decoder interface. For more detailed // documentation refer to the C interfaces. @@ -24,7 +24,7 @@ class Instance; class VideoDecoder_Dev : public Resource { public: // See PPB_VideoDecoder_Dev::Create. - VideoDecoder_Dev(const Instance* instance, + VideoDecoder_Dev(const InstanceHandle& instance, const Graphics3D& context, PP_VideoDecoder_Profile profile); diff --git a/ppapi/cpp/dev/websocket_dev.cc b/ppapi/cpp/dev/websocket_dev.cc index 65578fd..d8cc702 100644 --- a/ppapi/cpp/dev/websocket_dev.cc +++ b/ppapi/cpp/dev/websocket_dev.cc @@ -7,7 +7,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_macros.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/var.h" @@ -22,11 +22,11 @@ template <> const char* interface_name<PPB_WebSocket_Dev>() { } // namespace -WebSocket_Dev::WebSocket_Dev(Instance* instance) { +WebSocket_Dev::WebSocket_Dev(const InstanceHandle& instance) { if (!has_interface<PPB_WebSocket_Dev>()) return; PassRefFromConstructor(get_interface<PPB_WebSocket_Dev>()->Create( - instance->pp_instance())); + instance.pp_instance())); } WebSocket_Dev::~WebSocket_Dev() { @@ -101,8 +101,8 @@ Var WebSocket_Dev::GetCloseReason() { if (!has_interface<PPB_WebSocket_Dev>()) return 0; - return Var(Var::PassRef(), - get_interface<PPB_WebSocket_Dev>()->GetCloseReason(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket_Dev>()->GetCloseReason(pp_resource())); } bool WebSocket_Dev::GetCloseWasClean() { @@ -118,16 +118,16 @@ Var WebSocket_Dev::GetExtensions() { if (!has_interface<PPB_WebSocket_Dev>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket_Dev>()->GetExtensions(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket_Dev>()->GetExtensions(pp_resource())); } Var WebSocket_Dev::GetProtocol() { if (!has_interface<PPB_WebSocket_Dev>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket_Dev>()->GetProtocol(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket_Dev>()->GetProtocol(pp_resource())); } PP_WebSocketReadyState_Dev WebSocket_Dev::GetReadyState() { @@ -141,8 +141,8 @@ Var WebSocket_Dev::GetURL() { if (!has_interface<PPB_WebSocket_Dev>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket_Dev>()->GetURL(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket_Dev>()->GetURL(pp_resource())); } } // namespace pp diff --git a/ppapi/cpp/dev/widget_client_dev.cc b/ppapi/cpp/dev/widget_client_dev.cc index 9f53983..f170e15 100644 --- a/ppapi/cpp/dev/widget_client_dev.cc +++ b/ppapi/cpp/dev/widget_client_dev.cc @@ -9,6 +9,7 @@ #include "ppapi/cpp/dev/scrollbar_dev.h" #include "ppapi/cpp/dev/widget_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/rect.h" @@ -24,8 +25,7 @@ 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); + void* object = Instance::GetPerInstanceObject(instance, kPPPWidgetInterface); if (!object) return; return static_cast<WidgetClient_Dev*>(object)->InvalidateWidget( @@ -44,7 +44,7 @@ void Scrollbar_ValueChanged(PP_Instance instance, PP_Resource scrollbar_id, uint32_t value) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPScrollbarInterface); + Instance::GetPerInstanceObject(instance, kPPPScrollbarInterface); if (!object) return; return static_cast<WidgetClient_Dev*>(object)->ScrollbarValueChanged( @@ -55,7 +55,7 @@ void Scrollbar_OverlayChanged(PP_Instance instance, PP_Resource scrollbar_id, PP_Bool overlay) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPScrollbarInterface); + Instance::GetPerInstanceObject(instance, kPPPScrollbarInterface); if (!object) return; return static_cast<WidgetClient_Dev*>(object)->ScrollbarOverlayChanged( @@ -69,18 +69,20 @@ static PPP_Scrollbar_Dev scrollbar_interface = { } // namespace -WidgetClient_Dev::WidgetClient_Dev(Instance* instance) +WidgetClient_Dev::WidgetClient_Dev(const InstanceHandle& 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); + Module::Get()->AddPluginInterface(kPPPWidgetInterface, &widget_interface); + Instance::AddPerInstanceObject(instance, kPPPWidgetInterface, this); + Module::Get()->AddPluginInterface(kPPPScrollbarInterface, + &scrollbar_interface); + Instance::AddPerInstanceObject(instance, kPPPScrollbarInterface, this); } WidgetClient_Dev::~WidgetClient_Dev() { - associated_instance_->RemovePerInstanceObject(kPPPScrollbarInterface, this); - associated_instance_->RemovePerInstanceObject(kPPPWidgetInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPScrollbarInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPWidgetInterface, this); } } // namespace pp diff --git a/ppapi/cpp/dev/widget_client_dev.h b/ppapi/cpp/dev/widget_client_dev.h index c865621..808a72e 100644 --- a/ppapi/cpp/dev/widget_client_dev.h +++ b/ppapi/cpp/dev/widget_client_dev.h @@ -6,10 +6,10 @@ #define PPAPI_CPP_DEV_WIDGET_CLIENT_DEV_H_ #include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/instance_handle.h" namespace pp { -class Instance; class Rect; class Scrollbar_Dev; class Widget_Dev; @@ -19,7 +19,7 @@ class Widget_Dev; // instance. class WidgetClient_Dev { public: - WidgetClient_Dev(Instance* instance); + explicit WidgetClient_Dev(const InstanceHandle& instance); virtual ~WidgetClient_Dev(); /** @@ -43,7 +43,7 @@ class WidgetClient_Dev { bool type) = 0; private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/dev/zoom_dev.cc b/ppapi/cpp/dev/zoom_dev.cc index 49a8cec..4e9f78f 100644 --- a/ppapi/cpp/dev/zoom_dev.cc +++ b/ppapi/cpp/dev/zoom_dev.cc @@ -6,6 +6,7 @@ #include "ppapi/c/dev/ppb_zoom_dev.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -18,8 +19,7 @@ static const char kPPPZoomInterface[] = PPP_ZOOM_DEV_INTERFACE; void Zoom(PP_Instance instance, double factor, PP_Bool text_only) { - void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPZoomInterface); + void* object = Instance::GetPerInstanceObject(instance, kPPPZoomInterface); if (!object) return; static_cast<Zoom_Dev*>(object)->Zoom(factor, PP_ToBool(text_only)); @@ -35,19 +35,21 @@ template <> const char* interface_name<PPB_Zoom_Dev>() { } // 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(const InstanceHandle& instance) + : associated_instance_(instance) { + Module::Get()->AddPluginInterface(kPPPZoomInterface, &ppp_zoom); + Instance::AddPerInstanceObject(instance, kPPPZoomInterface, this); } Zoom_Dev::~Zoom_Dev() { - associated_instance_->RemovePerInstanceObject(kPPPZoomInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPZoomInterface, this); } void Zoom_Dev::ZoomChanged(double factor) { if (has_interface<PPB_Zoom_Dev>()) get_interface<PPB_Zoom_Dev>()->ZoomChanged( - associated_instance_->pp_instance(), factor); + associated_instance_.pp_instance(), factor); } void Zoom_Dev::ZoomLimitsChanged(double minimum_factor, @@ -55,7 +57,7 @@ void Zoom_Dev::ZoomLimitsChanged(double minimum_factor, if (!has_interface<PPB_Zoom_Dev>()) return; get_interface<PPB_Zoom_Dev>()->ZoomLimitsChanged( - associated_instance_->pp_instance(), minimum_factor, maximium_factor); + 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 index 0a079f0..9e17ff5 100644 --- a/ppapi/cpp/dev/zoom_dev.h +++ b/ppapi/cpp/dev/zoom_dev.h @@ -8,11 +8,10 @@ #include <string> #include "ppapi/c/dev/ppp_zoom_dev.h" +#include "ppapi/cpp/instance_handle.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 @@ -38,7 +37,7 @@ class Instance; // }; class Zoom_Dev { public: - Zoom_Dev(Instance* instance); + explicit Zoom_Dev(const InstanceHandle& instance); virtual ~Zoom_Dev(); // PPP_Zoom_Dev functions exposed as virtual functions for you to @@ -50,7 +49,7 @@ class Zoom_Dev { void ZoomLimitsChanged(double minimum_factor, double maximium_factor); private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/file_io.cc b/ppapi/cpp/file_io.cc index 09354d5..399c430 100644 --- a/ppapi/cpp/file_io.cc +++ b/ppapi/cpp/file_io.cc @@ -8,7 +8,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/file_ref.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -25,11 +25,11 @@ template <> const char* interface_name<PPB_FileIO>() { FileIO::FileIO() { } -FileIO::FileIO(Instance* instance) { +FileIO::FileIO(const InstanceHandle& instance) { if (!has_interface<PPB_FileIO>()) return; PassRefFromConstructor(get_interface<PPB_FileIO>()->Create( - instance->pp_instance())); + instance.pp_instance())); } FileIO::FileIO(const FileIO& other) diff --git a/ppapi/cpp/file_io.h b/ppapi/cpp/file_io.h index 29a45f6..0d8dcc9 100644 --- a/ppapi/cpp/file_io.h +++ b/ppapi/cpp/file_io.h @@ -17,7 +17,7 @@ namespace pp { class CompletionCallback; class FileRef; -class Instance; +class InstanceHandle; /// The <code>FileIO</code> class represents a regular file. class FileIO : public Resource { @@ -29,8 +29,9 @@ class FileIO : public Resource { /// A constructor used to create a <code>FileIO</code> and associate it with /// the provided <code>Instance</code>. /// - /// @param[in] instance An <code>Instance</code>. - FileIO(Instance* instance); + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit FileIO(const InstanceHandle& instance); /// The copy constructor for <code>FileIO</code>. /// diff --git a/ppapi/cpp/file_ref.cc b/ppapi/cpp/file_ref.cc index ed98974..864e646 100644 --- a/ppapi/cpp/file_ref.cc +++ b/ppapi/cpp/file_ref.cc @@ -23,8 +23,7 @@ template <> const char* interface_name<PPB_FileRef>() { FileRef::FileRef(PP_Resource resource) : Resource(resource) { } -FileRef::FileRef(PassRef, PP_Resource resource) { - PassRefFromConstructor(resource); +FileRef::FileRef(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { } FileRef::FileRef(const FileSystem& file_system, @@ -48,23 +47,20 @@ PP_FileSystemType FileRef::GetFileSystemType() const { Var FileRef::GetName() const { if (!has_interface<PPB_FileRef>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_FileRef>()->GetName(pp_resource())); + return Var(PASS_REF, get_interface<PPB_FileRef>()->GetName(pp_resource())); } Var FileRef::GetPath() const { if (!has_interface<PPB_FileRef>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_FileRef>()->GetPath(pp_resource())); + return Var(PASS_REF, get_interface<PPB_FileRef>()->GetPath(pp_resource())); } FileRef FileRef::GetParent() const { if (!has_interface<PPB_FileRef>()) return FileRef(); - return FileRef(PassRef(), - get_interface<PPB_FileRef>()->GetParent( - pp_resource())); + return FileRef(PASS_REF, + get_interface<PPB_FileRef>()->GetParent(pp_resource())); } int32_t FileRef::MakeDirectory(const CompletionCallback& cc) { diff --git a/ppapi/cpp/file_ref.h b/ppapi/cpp/file_ref.h index 04e7745..05cdc36 100644 --- a/ppapi/cpp/file_ref.h +++ b/ppapi/cpp/file_ref.h @@ -27,16 +27,13 @@ class FileRef : public Resource { /// object. FileRef() {} - /// A constructor used to create a <code>FileRef</code> and associate it with - /// the provided <code>Instance</code>. + /// A constructor used when you have an existing PP_Resource for a FileRef + /// and which to create a C++ object that takes an additional reference to + /// the resource. /// - /// @param[in] resource An <code>Instance</code>. + /// @param[in] resource A PP_Resource corresponding to file reference. explicit FileRef(PP_Resource resource); - /// A special structure used by the constructor that does not increment the - /// reference count of the underlying file reference. - struct PassRef {}; - /// A constructor used when you have received a PP_Resource as a return /// value that has already been reference counted. /// diff --git a/ppapi/cpp/file_system.cc b/ppapi/cpp/file_system.cc index 8499dfd..1f2aaa6 100644 --- a/ppapi/cpp/file_system.cc +++ b/ppapi/cpp/file_system.cc @@ -8,6 +8,7 @@ #include "ppapi/c/ppb_file_system.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/file_ref.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -24,12 +25,12 @@ template <> const char* interface_name<PPB_FileSystem>() { FileSystem::FileSystem() { } -FileSystem::FileSystem(Instance* instance, +FileSystem::FileSystem(const InstanceHandle& instance, PP_FileSystemType type) { if (!has_interface<PPB_FileSystem>()) return; PassRefFromConstructor(get_interface<PPB_FileSystem>()->Create( - instance->pp_instance(), type)); + instance.pp_instance(), type)); } int32_t FileSystem::Open(int64_t expected_size, diff --git a/ppapi/cpp/file_system.h b/ppapi/cpp/file_system.h index 73b4813..8aea7a5 100644 --- a/ppapi/cpp/file_system.h +++ b/ppapi/cpp/file_system.h @@ -30,11 +30,12 @@ class FileSystem : public Resource { /// This constructor creates a file system object of the given type. /// - /// @param[in] instance A <code>Instance</code> identifying the instance - /// with the file. + /// @param[in] instance The instance with which this resource will be + /// associated. + /// /// @param[in] type A file system type as defined by /// <code>PP_FileSystemType</code> enum. - FileSystem(Instance* instance, PP_FileSystemType type); + FileSystem(const InstanceHandle& instance, PP_FileSystemType type); /// Open() opens the file system. A file system must be opened before running /// any other operation on it. diff --git a/ppapi/cpp/fullscreen.cc b/ppapi/cpp/fullscreen.cc index 1c751cc6..26b6e77a 100644 --- a/ppapi/cpp/fullscreen.cc +++ b/ppapi/cpp/fullscreen.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/fullscreen.h" #include "ppapi/c/ppb_fullscreen.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/size.h" @@ -20,7 +20,7 @@ template <> const char* interface_name<PPB_Fullscreen>() { } // namespace -Fullscreen::Fullscreen(Instance* instance) +Fullscreen::Fullscreen(const InstanceHandle& instance) : instance_(instance) { } @@ -30,21 +30,21 @@ Fullscreen::~Fullscreen() { bool Fullscreen::IsFullscreen() { return has_interface<PPB_Fullscreen>() && get_interface<PPB_Fullscreen>()->IsFullscreen( - instance_->pp_instance()); + instance_.pp_instance()); } bool Fullscreen::SetFullscreen(bool fullscreen) { if (!has_interface<PPB_Fullscreen>()) return false; return PP_ToBool(get_interface<PPB_Fullscreen>()->SetFullscreen( - instance_->pp_instance(), PP_FromBool(fullscreen))); + instance_.pp_instance(), PP_FromBool(fullscreen))); } bool Fullscreen::GetScreenSize(Size* size) { if (!has_interface<PPB_Fullscreen>()) return false; return PP_ToBool(get_interface<PPB_Fullscreen>()->GetScreenSize( - instance_->pp_instance(), &size->pp_size())); + instance_.pp_instance(), &size->pp_size())); } } // namespace pp diff --git a/ppapi/cpp/fullscreen.h b/ppapi/cpp/fullscreen.h index 55922dd..3504424 100644 --- a/ppapi/cpp/fullscreen.h +++ b/ppapi/cpp/fullscreen.h @@ -5,13 +5,14 @@ #ifndef PPAPI_CPP_FULLSCREEN_H_ #define PPAPI_CPP_FULLSCREEN_H_ +#include "ppapi/cpp/instance_handle.h" + /// @file /// This file defines the API for handling transitions of a module instance to /// and from fullscreen mode. namespace pp { -class Instance; class Size; /// The Fullscreen class allowing you to check and toggle fullscreen mode. @@ -19,9 +20,9 @@ class Fullscreen { public: /// A constructor for creating a <code>Fullscreen</code>. /// - /// @param[in] instance The instance that will own the new - /// <code>Fullscreen</code>. - Fullscreen(Instance* instance); + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit Fullscreen(const InstanceHandle& instance); /// Destructor. virtual ~Fullscreen(); @@ -63,7 +64,7 @@ class Fullscreen { bool GetScreenSize(Size* size); private: - Instance* instance_; + InstanceHandle instance_; }; } // namespace pp diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc index c0ea84e..1ae976b 100644 --- a/ppapi/cpp/graphics_2d.cc +++ b/ppapi/cpp/graphics_2d.cc @@ -8,7 +8,7 @@ #include "ppapi/c/ppb_graphics_2d.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/image_data.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/point.h" @@ -32,14 +32,14 @@ Graphics2D::Graphics2D(const Graphics2D& other) size_(other.size_) { } -Graphics2D::Graphics2D(Instance* instance, +Graphics2D::Graphics2D(const InstanceHandle& instance, const Size& size, bool is_always_opaque) : Resource() { if (!has_interface<PPB_Graphics2D>()) return; PassRefFromConstructor(get_interface<PPB_Graphics2D>()->Create( - instance->pp_instance(), + instance.pp_instance(), &size.pp_size(), PP_FromBool(is_always_opaque))); if (!is_null()) { diff --git a/ppapi/cpp/graphics_2d.h b/ppapi/cpp/graphics_2d.h index c30a43c..0ce6641 100644 --- a/ppapi/cpp/graphics_2d.h +++ b/ppapi/cpp/graphics_2d.h @@ -16,7 +16,7 @@ namespace pp { class CompletionCallback; class ImageData; -class Instance; +class InstanceHandle; class Point; class Rect; @@ -37,9 +37,12 @@ class Graphics2D : public Resource { /// in the browser, resulting object will be is_null() if the allocation /// failed. /// - /// @param[in] instance The module instance. + /// @param[in] instance The instance with which this resource will be + /// associated. + /// /// @param[in] size The size of the 2D graphics context in the browser, /// measured in device pixels. + /// /// @param[in] is_always_opaque Set the <code>is_always_opaque</code> flag /// to true if you know that you will be painting only opaque data to this /// context. This option will disable blending when compositing the module @@ -49,7 +52,9 @@ class Graphics2D : public Resource { /// always be set to 0xFF or there may be painting artifacts. The alpha values /// overwrite the destination alpha values without blending when /// <code>is_always_opaque</code> is true. - Graphics2D(Instance* instance, const Size& size, bool is_always_opaque); + Graphics2D(const InstanceHandle& instance, + const Size& size, + bool is_always_opaque); /// A destructor that decrements the reference count of a /// <code>Graphics2D</code> object made using the previous copy constructor. diff --git a/ppapi/cpp/graphics_3d.cc b/ppapi/cpp/graphics_3d.cc index cce5547..32578de 100644 --- a/ppapi/cpp/graphics_3d.cc +++ b/ppapi/cpp/graphics_3d.cc @@ -6,7 +6,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/var.h" @@ -23,20 +23,20 @@ template <> const char* interface_name<PPB_Graphics3D>() { Graphics3D::Graphics3D() { } -Graphics3D::Graphics3D(const Instance* instance, +Graphics3D::Graphics3D(const InstanceHandle& instance, const int32_t attrib_list[]) { if (has_interface<PPB_Graphics3D>()) { PassRefFromConstructor(get_interface<PPB_Graphics3D>()->Create( - instance->pp_instance(), 0, attrib_list)); + instance.pp_instance(), 0, attrib_list)); } } -Graphics3D::Graphics3D(const Instance* instance, +Graphics3D::Graphics3D(const InstanceHandle& instance, const Graphics3D& share_context, const int32_t attrib_list[]) { if (has_interface<PPB_Graphics3D>()) { PassRefFromConstructor(get_interface<PPB_Graphics3D>()->Create( - instance->pp_instance(), + instance.pp_instance(), share_context.pp_resource(), attrib_list)); } diff --git a/ppapi/cpp/graphics_3d.h b/ppapi/cpp/graphics_3d.h index 9d89e28..56383da 100644 --- a/ppapi/cpp/graphics_3d.h +++ b/ppapi/cpp/graphics_3d.h @@ -13,7 +13,7 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; /// This class represents a 3D rendering context in the browser. class Graphics3D : public Resource { @@ -26,7 +26,8 @@ class Graphics3D : public Resource { /// to a module instance using <code>Instance::BindGraphics</code> to draw on /// the web page. /// - /// @param[in] instance The instance that will own the new Graphics3D. + /// @param[in] instance The instance with which this resource will be + /// associated. /// /// @param[in] attrib_list The list of attributes (name=value pairs) for the /// context. The list is terminated with @@ -61,7 +62,7 @@ class Graphics3D : public Resource { /// Default: Implementation defined. /// /// On failure, the object will be is_null(). - Graphics3D(const Instance* instance, + Graphics3D(const InstanceHandle& instance, const int32_t attrib_list[]); /// A constructor for creating and initializing a 3D rendering context. The @@ -84,7 +85,7 @@ class Graphics3D : public Resource { /// 2-argument version of this constructor for more information. /// /// On failure, the object will be is_null(). - Graphics3D(const Instance* instance, + Graphics3D(const InstanceHandle& instance, const Graphics3D& share_context, const int32_t attrib_list[]); diff --git a/ppapi/cpp/graphics_3d_client.cc b/ppapi/cpp/graphics_3d_client.cc index d827f9d..6702c05 100644 --- a/ppapi/cpp/graphics_3d_client.cc +++ b/ppapi/cpp/graphics_3d_client.cc @@ -6,6 +6,7 @@ #include "ppapi/c/ppp_graphics_3d.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -17,7 +18,7 @@ const char kPPPGraphics3DInterface[] = PPP_GRAPHICS_3D_INTERFACE; void Graphics3D_ContextLost(PP_Instance instance) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPGraphics3DInterface); + Instance::GetPerInstanceObject(instance, kPPPGraphics3DInterface); if (!object) return; return static_cast<Graphics3DClient*>(object)->Graphics3DContextLost(); @@ -29,15 +30,16 @@ static PPP_Graphics3D graphics3d_interface = { } // namespace -Graphics3DClient::Graphics3DClient(Instance* instance) +Graphics3DClient::Graphics3DClient(const InstanceHandle& instance) : associated_instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPGraphics3DInterface, - &graphics3d_interface); - associated_instance_->AddPerInstanceObject(kPPPGraphics3DInterface, this); + Module::Get()->AddPluginInterface(kPPPGraphics3DInterface, + &graphics3d_interface); + Instance::AddPerInstanceObject(instance, kPPPGraphics3DInterface, this); } Graphics3DClient::~Graphics3DClient() { - associated_instance_->RemovePerInstanceObject(kPPPGraphics3DInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPGraphics3DInterface, this); } } // namespace pp diff --git a/ppapi/cpp/graphics_3d_client.h b/ppapi/cpp/graphics_3d_client.h index 60299ca..5886b84 100644 --- a/ppapi/cpp/graphics_3d_client.h +++ b/ppapi/cpp/graphics_3d_client.h @@ -6,14 +6,13 @@ #define PPAPI_CPP_GRAPHICS_3D_CLIENT_H_ #include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/instance_handle.h" /// @file /// This file defines the API for callbacks related to 3D. namespace pp { -class Instance; - // 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. @@ -24,7 +23,7 @@ class Graphics3DClient { /// /// @param[in] instance The instance that will own the new /// <code>Graphics3DClient</code>. - explicit Graphics3DClient(Instance* instance); + explicit Graphics3DClient(const InstanceHandle& instance); /// Destructor. virtual ~Graphics3DClient(); @@ -34,7 +33,7 @@ class Graphics3DClient { virtual void Graphics3DContextLost() = 0; private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/image_data.cc b/ppapi/cpp/image_data.cc index 5fcc4c3..4ccbaba 100644 --- a/ppapi/cpp/image_data.cc +++ b/ppapi/cpp/image_data.cc @@ -8,7 +8,7 @@ #include <algorithm> -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -33,16 +33,13 @@ ImageData::ImageData(const ImageData& other) } ImageData::ImageData(PassRef, PP_Resource resource) - : data_(NULL) { + : Resource(PASS_REF, resource), + data_(NULL) { memset(&desc_, 0, sizeof(PP_ImageDataDesc)); - - if (!has_interface<PPB_ImageData>()) - return; - - PassRefAndInitData(resource); + InitData(); } -ImageData::ImageData(Instance* instance, +ImageData::ImageData(const InstanceHandle& instance, PP_ImageDataFormat format, const Size& size, bool init_to_zero) @@ -52,9 +49,10 @@ ImageData::ImageData(Instance* instance, if (!has_interface<PPB_ImageData>()) return; - PassRefAndInitData(get_interface<PPB_ImageData>()->Create( - instance->pp_instance(), format, &size.pp_size(), + PassRefFromConstructor(get_interface<PPB_ImageData>()->Create( + instance.pp_instance(), format, &size.pp_size(), PP_FromBool(init_to_zero))); + InitData(); } ImageData& ImageData::operator=(const ImageData& other) { @@ -83,8 +81,9 @@ PP_ImageDataFormat ImageData::GetNativeImageDataFormat() { return get_interface<PPB_ImageData>()->GetNativeImageDataFormat(); } -void ImageData::PassRefAndInitData(PP_Resource resource) { - PassRefFromConstructor(resource); +void ImageData::InitData() { + if (!has_interface<PPB_ImageData>()) + return; 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 1e6def8..7822188 100644 --- a/ppapi/cpp/image_data.h +++ b/ppapi/cpp/image_data.h @@ -10,13 +10,12 @@ #include "ppapi/cpp/size.h" #include "ppapi/cpp/resource.h" - /// @file /// This file defines the APIs for determining how a browser /// handles image data. namespace pp { -class Instance; +class InstanceHandle; class ImageData : public Resource { public: @@ -24,10 +23,6 @@ class ImageData : public Resource { /// object. ImageData(); - /// A special structure used by the constructor that does not increment the - /// reference count of the underlying Image resource. - struct PassRef {}; - /// A constructor used when you have received a <code>PP_Resource</code> as a /// return value that has already been reference counted. /// @@ -45,8 +40,8 @@ class ImageData : public Resource { /// with the provided parameters. The resulting object will be is_null() if /// the allocation failed. /// - /// @param[in] instance A <code>PP_Instance</code> identifying one instance - /// of a module. + /// @param[in] instance The instance with which this resource will be + /// associated. /// /// @param[in] format A PP_ImageDataFormat containing desired image format. /// PP_ImageDataFormat is an enumeration of the different types of @@ -62,7 +57,7 @@ class ImageData : public Resource { /// initialized to transparent during the creation process. If this flag is /// not set, the current contents of the bitmap will be undefined, and the /// module should be sure to set all the pixels. - ImageData(Instance* instance, + ImageData(const InstanceHandle& instance, PP_ImageDataFormat format, const Size& size, bool init_to_zero); @@ -123,7 +118,7 @@ class ImageData : public Resource { uint32_t* GetAddr32(const Point& coord); private: - void PassRefAndInitData(PP_Resource resource); + void InitData(); PP_ImageDataDesc desc_; void* data_; diff --git a/ppapi/cpp/input_event.cc b/ppapi/cpp/input_event.cc index 632b1ec..94da006 100644 --- a/ppapi/cpp/input_event.cc +++ b/ppapi/cpp/input_event.cc @@ -4,7 +4,7 @@ #include "ppapi/cpp/input_event.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/point.h" @@ -84,7 +84,7 @@ MouseInputEvent::MouseInputEvent(const InputEvent& event) : InputEvent() { } } -MouseInputEvent::MouseInputEvent(Instance* instance, +MouseInputEvent::MouseInputEvent(const InstanceHandle& instance, PP_InputEvent_Type type, PP_TimeTicks time_stamp, uint32_t modifiers, @@ -96,7 +96,7 @@ MouseInputEvent::MouseInputEvent(Instance* instance, if (!has_interface<PPB_MouseInputEvent>()) return; PassRefFromConstructor(get_interface<PPB_MouseInputEvent>()->Create( - instance->pp_instance(), type, time_stamp, modifiers, mouse_button, + instance.pp_instance(), type, time_stamp, modifiers, mouse_button, &mouse_position.pp_point(), click_count, &mouse_movement.pp_point())); } @@ -140,7 +140,7 @@ WheelInputEvent::WheelInputEvent(const InputEvent& event) : InputEvent() { } } -WheelInputEvent::WheelInputEvent(Instance* instance, +WheelInputEvent::WheelInputEvent(const InstanceHandle& instance, PP_TimeTicks time_stamp, uint32_t modifiers, const FloatPoint& wheel_delta, @@ -150,7 +150,7 @@ WheelInputEvent::WheelInputEvent(Instance* instance, if (!has_interface<PPB_WheelInputEvent>()) return; PassRefFromConstructor(get_interface<PPB_WheelInputEvent>()->Create( - instance->pp_instance(), time_stamp, modifiers, + instance.pp_instance(), time_stamp, modifiers, &wheel_delta.pp_float_point(), &wheel_ticks.pp_float_point(), PP_FromBool(scroll_by_page))); } @@ -190,7 +190,7 @@ KeyboardInputEvent::KeyboardInputEvent(const InputEvent& event) : InputEvent() { } } -KeyboardInputEvent::KeyboardInputEvent(Instance* instance, +KeyboardInputEvent::KeyboardInputEvent(const InstanceHandle& instance, PP_InputEvent_Type type, PP_TimeTicks time_stamp, uint32_t modifiers, @@ -200,7 +200,7 @@ KeyboardInputEvent::KeyboardInputEvent(Instance* instance, if (!has_interface<PPB_KeyboardInputEvent>()) return; PassRefFromConstructor(get_interface<PPB_KeyboardInputEvent>()->Create( - instance->pp_instance(), type, time_stamp, modifiers, key_code, + instance.pp_instance(), type, time_stamp, modifiers, key_code, character_text.pp_var())); } @@ -213,7 +213,7 @@ uint32_t KeyboardInputEvent::GetKeyCode() const { Var KeyboardInputEvent::GetCharacterText() const { if (!has_interface<PPB_KeyboardInputEvent>()) return Var(); - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_KeyboardInputEvent>()->GetCharacterText( pp_resource())); } diff --git a/ppapi/cpp/input_event.h b/ppapi/cpp/input_event.h index 39e8cf3..653aae5 100644 --- a/ppapi/cpp/input_event.h +++ b/ppapi/cpp/input_event.h @@ -16,7 +16,7 @@ namespace pp { class FloatPoint; -class Instance; +class InstanceHandle; class Point; class Var; @@ -124,7 +124,7 @@ class MouseInputEvent : public InputEvent { // TODO(brettw) figure out exactly what this means. /// /// @param[in] mouse_movement The change in position of the mouse. - MouseInputEvent(Instance* instance, + MouseInputEvent(const InstanceHandle& instance, PP_InputEvent_Type type, PP_TimeTicks time_stamp, uint32_t modifiers, @@ -193,7 +193,7 @@ class WheelInputEvent : public InputEvent { /// /// @param[in] scroll_by_page When true, the user is requesting to scroll /// by pages. When false, the user is requesting to scroll by lines. - WheelInputEvent(Instance* instance, + WheelInputEvent(const InstanceHandle& instance, PP_TimeTicks time_stamp, uint32_t modifiers, const FloatPoint& wheel_delta, @@ -279,7 +279,7 @@ class KeyboardInputEvent : public InputEvent { /// /// @param[in] character_text This value represents the typed character as a /// UTF-8 string. - KeyboardInputEvent(Instance* instance, + KeyboardInputEvent(const InstanceHandle& instance, PP_InputEvent_Type type, PP_TimeTicks time_stamp, uint32_t modifiers, diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc index e42adf6..56d88ab 100644 --- a/ppapi/cpp/instance.cc +++ b/ppapi/cpp/instance.cc @@ -11,6 +11,7 @@ #include "ppapi/cpp/graphics_2d.h" #include "ppapi/cpp/graphics_3d.h" #include "ppapi/cpp/image_data.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -137,6 +138,18 @@ void Instance::AddPerInstanceObject(const std::string& interface_name, interface_name_to_objects_[interface_name] = object; } +// static +void Instance::AddPerInstanceObject(const InstanceHandle& instance, + const std::string& interface_name, + void* object) { + // TODO(brettw) assert we're on the main thread (instance is not threadsafe + // and may be deleted from the main thread). + Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); + if (!that) + return; + that->AddPerInstanceObject(interface_name, object); +} + void Instance::RemovePerInstanceObject(const std::string& interface_name, void* object) { InterfaceNameToObjectMap::iterator found = interface_name_to_objects_.find( @@ -156,6 +169,17 @@ void Instance::RemovePerInstanceObject(const std::string& interface_name, } // static +void Instance::RemovePerInstanceObject(const InstanceHandle& instance, + const std::string& interface_name, + void* object) { + // TODO(brettw) assert we're on the main thread. + Instance* that = Module::Get()->InstanceForPPInstance(instance.pp_instance()); + if (!that) + return; + that->RemovePerInstanceObject(interface_name, object); +} + +// static void* Instance::GetPerInstanceObject(PP_Instance instance, const std::string& interface_name) { Instance* that = Module::Get()->InstanceForPPInstance(instance); diff --git a/ppapi/cpp/instance.h b/ppapi/cpp/instance.h index 025f398..f891bed 100644 --- a/ppapi/cpp/instance.h +++ b/ppapi/cpp/instance.h @@ -14,6 +14,7 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/view.h" struct PP_InputEvent; @@ -24,6 +25,7 @@ namespace pp { class Graphics2D; class Graphics3D; class InputEvent; +class InstanceHandle; class Rect; class URLLoader; class Var; @@ -60,8 +62,7 @@ class Instance { virtual ~Instance(); /// This function returns the <code>PP_Instance</code> identifying this - /// object. When using the PPAPI C++ wrappers this is not normally necessary, - /// but is required when using the lower-level C APIs. + /// object. /// /// @return A <code>PP_Instance</code> identifying this object. PP_Instance pp_instance() const { return pp_instance_; } @@ -486,6 +487,13 @@ class Instance { /// @param[in] object void AddPerInstanceObject(const std::string& interface_name, void* object); + /// Static version of AddPerInstanceObject that takes an InstanceHandle. As + /// with all other instance functions, this must only be called on the main + /// thread. + static void AddPerInstanceObject(const InstanceHandle& instance, + const std::string& interface_name, + void* object); + // {PENDING: summarize Remove method here} /// /// Refer to AddPerInstanceObject() for further information. @@ -495,6 +503,13 @@ class Instance { /// @param[in] object void RemovePerInstanceObject(const std::string& interface_name, void* object); + /// Static version of AddPerInstanceObject that takes an InstanceHandle. As + /// with all other instance functions, this must only be called on the main + /// thread. + static void RemovePerInstanceObject(const InstanceHandle& instance, + const std::string& interface_name, + void* object); + /// Look up an object previously associated with an instance. Returns NULL /// if the instance is invalid or there is no object for the given interface /// name on the instance. diff --git a/ppapi/cpp/instance_handle.cc b/ppapi/cpp/instance_handle.cc new file mode 100644 index 0000000..8c3195a --- /dev/null +++ b/ppapi/cpp/instance_handle.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/instance_handle.h" + +#include "ppapi/cpp/instance.h" + +namespace pp { + +InstanceHandle::InstanceHandle(Instance* instance) + : pp_instance_(instance->pp_instance()) { +} + +} // namespace pp diff --git a/ppapi/cpp/instance_handle.h b/ppapi/cpp/instance_handle.h new file mode 100644 index 0000000..941db6e --- /dev/null +++ b/ppapi/cpp/instance_handle.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_INSTANCE_HANDLE_H_ +#define PPAPI_CPP_INSTANCE_HANDLE_H_ + +#include "ppapi/c/pp_instance.h" + +namespace pp { + +class Instance; + +/// An instance handle identifies an instance in a constructor for a resource. +/// Its existence solves two different problems: +/// +/// A pp::Instance objects' lifetime is managed by the system on the main thread +/// of the plugin. This means that it may get destroyed at any time based on +/// something that happens on the web page. This means that it's never OK to +/// refer to a pp::Instance object on a background thread. So we need to pass +/// some kind of identifier instead to resource constructors so that they may +/// safely be used on background threads. If the instance becomes invalid, the +/// resource creation will fail on the background thread, but it won't crash. +/// +/// Background: PP_Instance would be a good identifier to use for this case. +/// However, using it in the constructor to resources is problematic. +/// PP_Instance is just a typedef for an integer, as is a PP_Resource. Many +/// resources have alternate constructors that just take an existing +/// PP_Resource, so the constructors would be ambiguous. Having this wrapper +/// around a PP_Instance prevents this ambiguity, and also gives us a nice +/// place to consolidate an implicit conversion from pp::Instance* for prettier +/// code on the main thread (you can just pass "this" to resource constructors +/// in your instance objects). +/// +/// So you should always pass InstanceHandles to background threads instead of +/// a pp::Instance, and use them in resource constructors and code that may be +/// used from background threads. +class InstanceHandle { + public: + /// Implicit constructor for converting a pp::Instance to an instance handle. + InstanceHandle(Instance* instance); + + /// Explicitly convert a PP_Instance to an instance handle. This should not + /// be implicit because it can make some resource constructors ambiguous. + /// PP_Instance is just a typedef for an integer, as is PP_Resource, so the + /// compiler can get confused between the two. + explicit InstanceHandle(PP_Instance pp_instance) + : pp_instance_(pp_instance) {} + + PP_Instance pp_instance() const { return pp_instance_; } + + private: + PP_Instance pp_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_INSTANCE_HANDLE_H_ diff --git a/ppapi/cpp/module.cc b/ppapi/cpp/module.cc index fd130ad..de92afb 100644 --- a/ppapi/cpp/module.cc +++ b/ppapi/cpp/module.cc @@ -138,7 +138,7 @@ void Messaging_HandleMessage(PP_Instance pp_instance, PP_Var var) { Instance* instance = module_singleton->InstanceForPPInstance(pp_instance); if (!instance) return; - instance->HandleMessage(Var(Var::PassRef(), var)); + instance->HandleMessage(Var(PASS_REF, var)); } static PPP_Messaging instance_messaging_interface = { diff --git a/ppapi/cpp/module.h b/ppapi/cpp/module.h index a9af8e0..871128c 100644 --- a/ppapi/cpp/module.h +++ b/ppapi/cpp/module.h @@ -86,7 +86,10 @@ class Module { const void* GetBrowserInterface(const char* interface_name); /// InstanceForPPInstance() returns the object associated with this - /// <code>PP_Instance</code>, or NULL if one is not found. + /// <code>PP_Instance</code>, or NULL if one is not found. This should only + /// be called from the main thread! This instance object may be destroyed at + /// any time on the main thread, so using it on other threads may cause a + /// crash. /// /// @param[in] instance This <code>PP_Instance</code>. /// diff --git a/ppapi/cpp/mouse_lock.cc b/ppapi/cpp/mouse_lock.cc index 4d3b9bf..828ee89 100644 --- a/ppapi/cpp/mouse_lock.cc +++ b/ppapi/cpp/mouse_lock.cc @@ -8,6 +8,7 @@ #include "ppapi/c/ppp_mouse_lock.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -19,7 +20,7 @@ static const char kPPPMouseLockInterface[] = PPP_MOUSELOCK_INTERFACE; void MouseLockLost(PP_Instance instance) { void* object = - pp::Instance::GetPerInstanceObject(instance, kPPPMouseLockInterface); + Instance::GetPerInstanceObject(instance, kPPPMouseLockInterface); if (!object) return; static_cast<MouseLock*>(object)->MouseLockLost(); @@ -35,28 +36,28 @@ template <> const char* interface_name<PPB_MouseLock>() { } // namespace -MouseLock::MouseLock(Instance* instance) +MouseLock::MouseLock(const InstanceHandle& instance) : associated_instance_(instance) { - pp::Module::Get()->AddPluginInterface(kPPPMouseLockInterface, - &ppp_mouse_lock); - associated_instance_->AddPerInstanceObject(kPPPMouseLockInterface, this); + Module::Get()->AddPluginInterface(kPPPMouseLockInterface, &ppp_mouse_lock); + Instance::AddPerInstanceObject(instance, kPPPMouseLockInterface, this); } MouseLock::~MouseLock() { - associated_instance_->RemovePerInstanceObject(kPPPMouseLockInterface, this); + Instance::RemovePerInstanceObject(associated_instance_, + kPPPMouseLockInterface, this); } int32_t MouseLock::LockMouse(const CompletionCallback& cc) { if (!has_interface<PPB_MouseLock>()) return cc.MayForce(PP_ERROR_NOINTERFACE); return get_interface<PPB_MouseLock>()->LockMouse( - associated_instance_->pp_instance(), cc.pp_completion_callback()); + associated_instance_.pp_instance(), cc.pp_completion_callback()); } void MouseLock::UnlockMouse() { if (has_interface<PPB_MouseLock>()) { get_interface<PPB_MouseLock>()->UnlockMouse( - associated_instance_->pp_instance()); + associated_instance_.pp_instance()); } } diff --git a/ppapi/cpp/mouse_lock.h b/ppapi/cpp/mouse_lock.h index a943074..8c70baa 100644 --- a/ppapi/cpp/mouse_lock.h +++ b/ppapi/cpp/mouse_lock.h @@ -6,6 +6,7 @@ #define PPAPI_CPP_MOUSE_LOCK_H_ #include "ppapi/c/pp_stdint.h" +#include "ppapi/cpp/instance_handle.h" /// @file /// This file defines the API for locking the target of mouse events to a @@ -14,7 +15,6 @@ namespace pp { class CompletionCallback; -class Instance; /// This class allows you to associate the <code>PPP_MouseLock</code> and /// <code>PPB_MouseLock</code> C-based interfaces with an object. It associates @@ -50,9 +50,9 @@ class MouseLock { public: /// A constructor for creating a <code>MouseLock</code>. /// - /// @param[in] instance The instance that will own the new - /// <code>MouseLock</code>. - explicit MouseLock(Instance* instance); + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit MouseLock(const InstanceHandle& instance); /// Destructor. virtual ~MouseLock(); @@ -90,7 +90,7 @@ class MouseLock { void UnlockMouse(); private: - Instance* associated_instance_; + InstanceHandle associated_instance_; }; } // namespace pp diff --git a/ppapi/cpp/pass_ref.h b/ppapi/cpp/pass_ref.h new file mode 100644 index 0000000..ebe1ddd --- /dev/null +++ b/ppapi/cpp/pass_ref.h @@ -0,0 +1,18 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_PASS_REF_H_ +#define PPAPI_CPP_PASS_REF_H_ + +namespace pp { + +/// An annotation for constructors and other functions that take ownership of +/// a pointer. For example, a resource constructor that takes ownership of a +/// passed in PP_Resource ref count would take this to differentiate from +/// the more typical use case of taking its own ref. +enum PassRef { PASS_REF }; + +} // namespace pp + +#endif // PPAPI_CPP_PASS_REF_H_ diff --git a/ppapi/cpp/private/flash.cc b/ppapi/cpp/private/flash.cc index 9cc7870..501da37 100644 --- a/ppapi/cpp/private/flash.cc +++ b/ppapi/cpp/private/flash.cc @@ -8,7 +8,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/dev/font_dev.h" #include "ppapi/cpp/image_data.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/point.h" @@ -45,21 +45,22 @@ bool Flash::IsAvailable() { } // static -void Flash::SetInstanceAlwaysOnTop(Instance* instance, bool on_top) { +void Flash::SetInstanceAlwaysOnTop(const InstanceHandle& instance, + bool on_top) { if (has_interface<PPB_Flash>()) { - get_interface<PPB_Flash>()->SetInstanceAlwaysOnTop(instance->pp_instance(), + get_interface<PPB_Flash>()->SetInstanceAlwaysOnTop(instance.pp_instance(), PP_FromBool(on_top)); } else if (has_interface<PPB_Flash_12_0>()) { get_interface<PPB_Flash_12_0>()->SetInstanceAlwaysOnTop( - instance->pp_instance(), PP_FromBool(on_top)); + instance.pp_instance(), PP_FromBool(on_top)); } else if (has_interface<PPB_Flash_11>()) { get_interface<PPB_Flash_11>()->SetInstanceAlwaysOnTop( - instance->pp_instance(), PP_FromBool(on_top)); + instance.pp_instance(), PP_FromBool(on_top)); } } // static -bool Flash::DrawGlyphs(Instance* instance, +bool Flash::DrawGlyphs(const InstanceHandle& instance, ImageData* image, const FontDescription_Dev& font_desc, uint32_t color, @@ -73,7 +74,7 @@ bool Flash::DrawGlyphs(Instance* instance, bool rv = false; if (has_interface<PPB_Flash>()) { rv = PP_ToBool(get_interface<PPB_Flash>()->DrawGlyphs( - instance->pp_instance(), + instance.pp_instance(), image->pp_resource(), &font_desc.pp_font_description(), color, @@ -86,7 +87,7 @@ bool Flash::DrawGlyphs(Instance* instance, glyph_advances)); } else if (has_interface<PPB_Flash_12_0>()) { rv = PP_ToBool(get_interface<PPB_Flash_12_0>()->DrawGlyphs( - instance->pp_instance(), + instance.pp_instance(), image->pp_resource(), &font_desc.pp_font_description(), color, @@ -99,7 +100,7 @@ bool Flash::DrawGlyphs(Instance* instance, glyph_advances)); } else if (has_interface<PPB_Flash_11>()) { rv = PP_ToBool(get_interface<PPB_Flash_11>()->DrawGlyphs( - instance->pp_instance(), + instance.pp_instance(), image->pp_resource(), &font_desc.pp_font_description(), color, @@ -114,20 +115,21 @@ bool Flash::DrawGlyphs(Instance* instance, } // static -Var Flash::GetProxyForURL(Instance* instance, const std::string& url) { +Var Flash::GetProxyForURL(const InstanceHandle& instance, + const std::string& url) { Var rv; if (has_interface<PPB_Flash>()) { - rv = Var(Var::PassRef(), - get_interface<PPB_Flash>()->GetProxyForURL(instance->pp_instance(), + rv = Var(PASS_REF, + get_interface<PPB_Flash>()->GetProxyForURL(instance.pp_instance(), url.c_str())); } else if (has_interface<PPB_Flash_12_0>()) { - rv = Var(Var::PassRef(), + rv = Var(PASS_REF, get_interface<PPB_Flash_12_0>()->GetProxyForURL( - instance->pp_instance(), url.c_str())); + instance.pp_instance(), url.c_str())); } else if (has_interface<PPB_Flash_11>()) { - rv = Var(Var::PassRef(), + rv = Var(PASS_REF, get_interface<PPB_Flash_11>()->GetProxyForURL( - instance->pp_instance(), url.c_str())); + instance.pp_instance(), url.c_str())); } return rv; } @@ -155,37 +157,38 @@ int32_t Flash::Navigate(const URLRequestInfo& request_info, } // static -void Flash::RunMessageLoop(Instance* instance) { +void Flash::RunMessageLoop(const InstanceHandle& instance) { if (has_interface<PPB_Flash>()) - get_interface<PPB_Flash>()->RunMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash>()->RunMessageLoop(instance.pp_instance()); else if (has_interface<PPB_Flash_12_0>()) - get_interface<PPB_Flash_12_0>()->RunMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash_12_0>()->RunMessageLoop(instance.pp_instance()); else if (has_interface<PPB_Flash_11>()) - get_interface<PPB_Flash_11>()->RunMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash_11>()->RunMessageLoop(instance.pp_instance()); } // static -void Flash::QuitMessageLoop(Instance* instance) { +void Flash::QuitMessageLoop(const InstanceHandle& instance) { if (has_interface<PPB_Flash>()) - get_interface<PPB_Flash>()->QuitMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash>()->QuitMessageLoop(instance.pp_instance()); else if (has_interface<PPB_Flash_12_0>()) - get_interface<PPB_Flash_12_0>()->QuitMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash_12_0>()->QuitMessageLoop(instance.pp_instance()); else if (has_interface<PPB_Flash_11>()) - get_interface<PPB_Flash_11>()->QuitMessageLoop(instance->pp_instance()); + get_interface<PPB_Flash_11>()->QuitMessageLoop(instance.pp_instance()); } // static -double Flash::GetLocalTimeZoneOffset(Instance* instance, PP_Time t) { +double Flash::GetLocalTimeZoneOffset(const InstanceHandle& instance, + PP_Time t) { double rv = 0; if (has_interface<PPB_Flash>()) { rv = get_interface<PPB_Flash>()->GetLocalTimeZoneOffset( - instance->pp_instance(), t); + instance.pp_instance(), t); } else if (has_interface<PPB_Flash_12_0>()) { rv = get_interface<PPB_Flash_12_0>()->GetLocalTimeZoneOffset( - instance->pp_instance(), t); + instance.pp_instance(), t); } else if (has_interface<PPB_Flash_11>()) { rv = get_interface<PPB_Flash_11>()->GetLocalTimeZoneOffset( - instance->pp_instance(), t); + instance.pp_instance(), t); } return rv; } @@ -194,15 +197,15 @@ double Flash::GetLocalTimeZoneOffset(Instance* instance, PP_Time t) { Var Flash::GetCommandLineArgs(Module* module) { Var rv; if (has_interface<PPB_Flash>()) { - rv = Var(Var::PassRef(), + rv = Var(PASS_REF, get_interface<PPB_Flash>()->GetCommandLineArgs( module->pp_module())); } else if (has_interface<PPB_Flash_12_0>()) { - rv = Var(Var::PassRef(), + rv = Var(PASS_REF, get_interface<PPB_Flash_12_0>()->GetCommandLineArgs( module->pp_module())); } else if (has_interface<PPB_Flash_11>()) { - rv = Var(Var::PassRef(), + rv = Var(PASS_REF, get_interface<PPB_Flash_11>()->GetCommandLineArgs( module->pp_module())); } @@ -218,27 +221,27 @@ void Flash::PreloadFontWin(const void* logfontw) { } // static -bool Flash::IsRectTopmost(Instance* instance, const Rect& rect) { +bool Flash::IsRectTopmost(const InstanceHandle& instance, const Rect& rect) { bool rv = false; if (has_interface<PPB_Flash>()) { rv = PP_ToBool(get_interface<PPB_Flash>()->IsRectTopmost( - instance->pp_instance(), &rect.pp_rect())); + instance.pp_instance(), &rect.pp_rect())); } return rv; } // static -int32_t Flash::InvokePrinting(Instance* instance) { +int32_t Flash::InvokePrinting(const InstanceHandle& instance) { int32_t rv = PP_ERROR_NOTSUPPORTED; if (has_interface<PPB_Flash>()) - rv = get_interface<PPB_Flash>()->InvokePrinting(instance->pp_instance()); + rv = get_interface<PPB_Flash>()->InvokePrinting(instance.pp_instance()); return rv; } // static -void Flash::UpdateActivity(Instance* instance) { +void Flash::UpdateActivity(const InstanceHandle& instance) { if (has_interface<PPB_Flash>()) - get_interface<PPB_Flash>()->UpdateActivity(instance->pp_instance()); + get_interface<PPB_Flash>()->UpdateActivity(instance.pp_instance()); } } // namespace flash diff --git a/ppapi/cpp/private/flash.h b/ppapi/cpp/private/flash.h index e60cc01..9eafac3 100644 --- a/ppapi/cpp/private/flash.h +++ b/ppapi/cpp/private/flash.h @@ -16,7 +16,7 @@ namespace pp { class FontDescription_Dev; class ImageData; -class Instance; +class InstanceHandle; class Module; class Point; class Rect; @@ -30,8 +30,9 @@ class Flash { // Returns true if the required interface is available. static bool IsAvailable(); - static void SetInstanceAlwaysOnTop(Instance* instance, bool on_top); - static bool DrawGlyphs(Instance* instance, + static void SetInstanceAlwaysOnTop(const InstanceHandle& instance, + bool on_top); + static bool DrawGlyphs(const InstanceHandle& instance, ImageData* image, const FontDescription_Dev& font_desc, uint32_t color, @@ -42,18 +43,20 @@ class Flash { uint32_t glyph_count, const uint16_t glyph_indices[], const PP_Point glyph_advances[]); - static Var GetProxyForURL(Instance* instance, const std::string& url); + static Var GetProxyForURL(const InstanceHandle& instance, + const std::string& url); static int32_t Navigate(const URLRequestInfo& request_info, const std::string& target, bool from_user_action); - static void RunMessageLoop(Instance* instance); - static void QuitMessageLoop(Instance* instance); - static double GetLocalTimeZoneOffset(Instance* instance, PP_Time t); + static void RunMessageLoop(const InstanceHandle& instance); + static void QuitMessageLoop(const InstanceHandle& instance); + static double GetLocalTimeZoneOffset(const InstanceHandle& instance, + PP_Time t); static Var GetCommandLineArgs(Module* module); static void PreloadFontWin(const void* logfontw); - static bool IsRectTopmost(Instance* instance, const Rect& rect); - static int32_t InvokePrinting(Instance* instance); - static void UpdateActivity(Instance* instance); + static bool IsRectTopmost(const InstanceHandle& instance, const Rect& rect); + static int32_t InvokePrinting(const InstanceHandle& instance); + static void UpdateActivity(const InstanceHandle& instance); }; diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc index 006da19..6f554e4 100644 --- a/ppapi/cpp/private/flash_clipboard.cc +++ b/ppapi/cpp/private/flash_clipboard.cc @@ -8,7 +8,7 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_errors.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/var.h" @@ -35,37 +35,37 @@ bool Clipboard::IsAvailable() { } // static -bool Clipboard::IsFormatAvailable(Instance* instance, +bool Clipboard::IsFormatAvailable(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { bool rv = false; if (has_interface<PPB_Flash_Clipboard>()) { rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( - instance->pp_instance(), clipboard_type, format)); + instance.pp_instance(), clipboard_type, format)); } return rv; } // static bool Clipboard::ReadData( - Instance* instance, + const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format clipboard_format, Var* out) { bool rv = false; if (has_interface<PPB_Flash_Clipboard>()) { PP_Var result = get_interface<PPB_Flash_Clipboard>()->ReadData( - instance->pp_instance(), + instance.pp_instance(), clipboard_type, clipboard_format); - *out = Var(Var::PassRef(), result); + *out = Var(PASS_REF, result); rv = true; } else if (has_interface<PPB_Flash_Clipboard_3_0>() && clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { PP_Var result = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText( - instance->pp_instance(), + instance.pp_instance(), clipboard_type); - *out = Var(Var::PassRef(), result); + *out = Var(PASS_REF, result); rv = true; } return rv; @@ -73,7 +73,7 @@ bool Clipboard::ReadData( // static bool Clipboard::WriteData( - Instance* instance, + const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, const std::vector<PP_Flash_Clipboard_Format>& formats, const std::vector<Var>& data_items) { @@ -98,7 +98,7 @@ bool Clipboard::WriteData( } rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( - instance->pp_instance(), + instance.pp_instance(), clipboard_type, data_items.size(), formats_ptr, @@ -110,7 +110,7 @@ bool Clipboard::WriteData( for (int32_t i = formats.size() - 1; i >= 0; --i) { if (formats[i] == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText( - instance->pp_instance(), + instance.pp_instance(), clipboard_type, data_items[i].pp_var()) == PP_OK); break; diff --git a/ppapi/cpp/private/flash_clipboard.h b/ppapi/cpp/private/flash_clipboard.h index 65446e3..2894c8f 100644 --- a/ppapi/cpp/private/flash_clipboard.h +++ b/ppapi/cpp/private/flash_clipboard.h @@ -13,7 +13,7 @@ namespace pp { -class Instance; +class InstanceHandle; namespace flash { @@ -23,20 +23,20 @@ class Clipboard { static bool IsAvailable(); // Returns true if the given format is available from the given clipboard. - static bool IsFormatAvailable(Instance* instance, + static bool IsFormatAvailable(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format); // Returns true on success, in which case |out| will be filled with // data read from the given clipboard in the given format. - static bool ReadData(Instance* instance, + static bool ReadData(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format clipboard_format, Var* out); // Returns true on success in which case all of |data| will be written to // the clipboard. Otherwise nothing will be written. - static bool WriteData(Instance* instance, + static bool WriteData(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, const std::vector<PP_Flash_Clipboard_Format>& formats, const std::vector<Var>& data_items); diff --git a/ppapi/cpp/private/flash_fullscreen.cc b/ppapi/cpp/private/flash_fullscreen.cc index 7a37a54..8a5be26 100644 --- a/ppapi/cpp/private/flash_fullscreen.cc +++ b/ppapi/cpp/private/flash_fullscreen.cc @@ -20,7 +20,7 @@ template <> const char* interface_name<PPB_FlashFullscreen>() { } // namespace -FlashFullscreen::FlashFullscreen(Instance* instance) +FlashFullscreen::FlashFullscreen(const InstanceHandle& instance) : instance_(instance) { } @@ -30,21 +30,21 @@ FlashFullscreen::~FlashFullscreen() { bool FlashFullscreen::IsFullscreen() { return has_interface<PPB_FlashFullscreen>() && get_interface<PPB_FlashFullscreen>()->IsFullscreen( - instance_->pp_instance()); + instance_.pp_instance()); } bool FlashFullscreen::SetFullscreen(bool fullscreen) { if (!has_interface<PPB_FlashFullscreen>()) return false; return PP_ToBool(get_interface<PPB_FlashFullscreen>()->SetFullscreen( - instance_->pp_instance(), PP_FromBool(fullscreen))); + instance_.pp_instance(), PP_FromBool(fullscreen))); } bool FlashFullscreen::GetScreenSize(Size* size) { if (!has_interface<PPB_FlashFullscreen>()) return false; return PP_ToBool(get_interface<PPB_FlashFullscreen>()->GetScreenSize( - instance_->pp_instance(), &size->pp_size())); + instance_.pp_instance(), &size->pp_size())); } } // namespace pp diff --git a/ppapi/cpp/private/flash_fullscreen.h b/ppapi/cpp/private/flash_fullscreen.h index 539f249..224824d 100644 --- a/ppapi/cpp/private/flash_fullscreen.h +++ b/ppapi/cpp/private/flash_fullscreen.h @@ -5,14 +5,15 @@ #ifndef PPAPI_CPP_PRIVATE_FLASH_FULLSCREEN_H_ #define PPAPI_CPP_PRIVATE_FLASH_FULLSCREEN_H_ +#include "ppapi/cpp/instance_handle.h" + namespace pp { -class Instance; class Size; class FlashFullscreen { public: - FlashFullscreen(Instance* instance); + FlashFullscreen(const InstanceHandle& instance); virtual ~FlashFullscreen(); // PPB_FlashFullscreen methods. @@ -21,7 +22,7 @@ class FlashFullscreen { bool GetScreenSize(Size* size); private: - Instance* instance_; + InstanceHandle instance_; }; } // namespace pp diff --git a/ppapi/cpp/private/flash_menu.cc b/ppapi/cpp/private/flash_menu.cc index ce13f7a..e77021b 100644 --- a/ppapi/cpp/private/flash_menu.cc +++ b/ppapi/cpp/private/flash_menu.cc @@ -6,7 +6,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/point.h" @@ -23,7 +23,8 @@ template <> const char* interface_name<PPB_Flash_Menu>() { namespace flash { -Menu::Menu(const Instance& instance, const struct PP_Flash_Menu* menu_data) { +Menu::Menu(const InstanceHandle& instance, + const struct PP_Flash_Menu* menu_data) { if (has_interface<PPB_Flash_Menu>()) { PassRefFromConstructor(get_interface<PPB_Flash_Menu>()->Create( instance.pp_instance(), menu_data)); diff --git a/ppapi/cpp/private/flash_menu.h b/ppapi/cpp/private/flash_menu.h index 88f1e50..a0a7499 100644 --- a/ppapi/cpp/private/flash_menu.h +++ b/ppapi/cpp/private/flash_menu.h @@ -11,7 +11,7 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; class Point; namespace flash { @@ -19,7 +19,7 @@ namespace flash { class Menu : public Resource { public: // TODO(viettrungluu): Write a proper C++ wrapper of |PP_Flash_Menu|. - Menu(const Instance& instance, const struct PP_Flash_Menu* menu_data); + Menu(const InstanceHandle& instance, const struct PP_Flash_Menu* menu_data); int32_t Show(const Point& location, int32_t* selected_id, diff --git a/ppapi/cpp/private/flash_message_loop.cc b/ppapi/cpp/private/flash_message_loop.cc index ea25891..7f25438 100644 --- a/ppapi/cpp/private/flash_message_loop.cc +++ b/ppapi/cpp/private/flash_message_loop.cc @@ -6,7 +6,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash_message_loop.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module_impl.h" namespace pp { @@ -21,10 +21,10 @@ template <> const char* interface_name<PPB_Flash_MessageLoop>() { namespace flash { -MessageLoop::MessageLoop(Instance* instance) { +MessageLoop::MessageLoop(const InstanceHandle& instance) { if (has_interface<PPB_Flash_MessageLoop>()) { PassRefFromConstructor(get_interface<PPB_Flash_MessageLoop>()->Create( - instance->pp_instance())); + instance.pp_instance())); } } diff --git a/ppapi/cpp/private/flash_message_loop.h b/ppapi/cpp/private/flash_message_loop.h index de2af45..fecb2d6 100644 --- a/ppapi/cpp/private/flash_message_loop.h +++ b/ppapi/cpp/private/flash_message_loop.h @@ -10,13 +10,13 @@ namespace pp { -class Instance; +class InstanceHandle; namespace flash { class MessageLoop : public Resource { public: - explicit MessageLoop(Instance* instance); + explicit MessageLoop(const InstanceHandle& instance); virtual ~MessageLoop(); static bool IsAvailable(); diff --git a/ppapi/cpp/private/flash_net_connector.cc b/ppapi/cpp/private/flash_net_connector.cc index 970740d..b448e7e 100644 --- a/ppapi/cpp/private/flash_net_connector.cc +++ b/ppapi/cpp/private/flash_net_connector.cc @@ -6,7 +6,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -22,7 +22,7 @@ template <> const char* interface_name<PPB_Flash_NetConnector>() { namespace flash { -NetConnector::NetConnector(const Instance& instance) { +NetConnector::NetConnector(const InstanceHandle& instance) { if (has_interface<PPB_Flash_NetConnector>()) { PassRefFromConstructor(get_interface<PPB_Flash_NetConnector>()->Create( instance.pp_instance())); diff --git a/ppapi/cpp/private/flash_net_connector.h b/ppapi/cpp/private/flash_net_connector.h index 2ab14aa..eb064ba 100644 --- a/ppapi/cpp/private/flash_net_connector.h +++ b/ppapi/cpp/private/flash_net_connector.h @@ -11,13 +11,13 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; namespace flash { class NetConnector : public Resource { public: - explicit NetConnector(const Instance& instance); + explicit NetConnector(const InstanceHandle& instance); int32_t ConnectTcp(const char* host, uint16_t port, diff --git a/ppapi/cpp/private/instance_private.cc b/ppapi/cpp/private/instance_private.cc index ad6e1a2..4e38114 100644 --- a/ppapi/cpp/private/instance_private.cc +++ b/ppapi/cpp/private/instance_private.cc @@ -50,14 +50,14 @@ Var InstancePrivate::GetInstanceObject() { VarPrivate InstancePrivate::GetWindowObject() { if (!has_interface<PPB_Instance_Private>()) return VarPrivate(); - return VarPrivate(Var::PassRef(), + return VarPrivate(PASS_REF, get_interface<PPB_Instance_Private>()->GetWindowObject(pp_instance())); } VarPrivate InstancePrivate::GetOwnerElementObject() { if (!has_interface<PPB_Instance_Private>()) return VarPrivate(); - return VarPrivate(Var::PassRef(), + return VarPrivate(PASS_REF, get_interface<PPB_Instance_Private>()->GetOwnerElementObject( pp_instance())); } @@ -65,7 +65,7 @@ VarPrivate InstancePrivate::GetOwnerElementObject() { VarPrivate InstancePrivate::ExecuteScript(const Var& script, Var* exception) { if (!has_interface<PPB_Instance_Private>()) return VarPrivate(); - return VarPrivate(Var::PassRef(), + return VarPrivate(PASS_REF, get_interface<PPB_Instance_Private>()->ExecuteScript( pp_instance(), script.pp_var(), diff --git a/ppapi/cpp/private/net_address_private.cc b/ppapi/cpp/private/net_address_private.cc index 01352dd..19bf2d3732 100644 --- a/ppapi/cpp/private/net_address_private.cc +++ b/ppapi/cpp/private/net_address_private.cc @@ -51,7 +51,7 @@ std::string NetAddressPrivate::Describe(const PP_NetAddress_Private& addr, if (!module) return std::string(); - Var result(Var::PassRef(), + Var result(PASS_REF, get_interface<PPB_NetAddress_Private>()->Describe( module->pp_module(), &addr, diff --git a/ppapi/cpp/private/tcp_socket_private.cc b/ppapi/cpp/private/tcp_socket_private.cc index 17938b4..9e2c1f6 100644 --- a/ppapi/cpp/private/tcp_socket_private.cc +++ b/ppapi/cpp/private/tcp_socket_private.cc @@ -7,7 +7,7 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -21,10 +21,10 @@ template <> const char* interface_name<PPB_TCPSocket_Private>() { } // namespace -TCPSocketPrivate::TCPSocketPrivate(Instance* instance) { - if (has_interface<PPB_TCPSocket_Private>() && instance) { +TCPSocketPrivate::TCPSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_TCPSocket_Private>()) { PassRefFromConstructor(get_interface<PPB_TCPSocket_Private>()->Create( - instance->pp_instance())); + instance.pp_instance())); } } diff --git a/ppapi/cpp/private/tcp_socket_private.h b/ppapi/cpp/private/tcp_socket_private.h index b8728b4..415a1ed 100644 --- a/ppapi/cpp/private/tcp_socket_private.h +++ b/ppapi/cpp/private/tcp_socket_private.h @@ -12,11 +12,11 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; class TCPSocketPrivate : public Resource { public: - explicit TCPSocketPrivate(Instance* instance); + explicit TCPSocketPrivate(const InstanceHandle& instance); // Returns true if the required interface is available. static bool IsAvailable(); diff --git a/ppapi/cpp/private/udp_socket_private.cc b/ppapi/cpp/private/udp_socket_private.cc index 68d372f..34c3e54 100644 --- a/ppapi/cpp/private/udp_socket_private.cc +++ b/ppapi/cpp/private/udp_socket_private.cc @@ -7,7 +7,7 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -21,10 +21,10 @@ template <> const char* interface_name<PPB_UDPSocket_Private>() { } // namespace -UDPSocketPrivate::UDPSocketPrivate(Instance* instance) { - if (has_interface<PPB_UDPSocket_Private>() && instance) { +UDPSocketPrivate::UDPSocketPrivate(const InstanceHandle& instance) { + if (has_interface<PPB_UDPSocket_Private>()) { PassRefFromConstructor(get_interface<PPB_UDPSocket_Private>()->Create( - instance->pp_instance())); + instance.pp_instance())); } } diff --git a/ppapi/cpp/private/udp_socket_private.h b/ppapi/cpp/private/udp_socket_private.h index abe434b..e80091c 100644 --- a/ppapi/cpp/private/udp_socket_private.h +++ b/ppapi/cpp/private/udp_socket_private.h @@ -12,11 +12,11 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; class UDPSocketPrivate : public Resource { public: - explicit UDPSocketPrivate(Instance* instance); + explicit UDPSocketPrivate(const InstanceHandle& instance); int32_t Bind(const PP_NetAddress_Private* addr, const CompletionCallback& callback); diff --git a/ppapi/cpp/private/var_private.cc b/ppapi/cpp/private/var_private.cc index 8b3228b..27e418a 100644 --- a/ppapi/cpp/private/var_private.cc +++ b/ppapi/cpp/private/var_private.cc @@ -6,6 +6,7 @@ #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/private/instance_private.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/module_impl.h" @@ -23,10 +24,11 @@ template <> const char* interface_name<PPB_Var_Deprecated>() { using namespace deprecated; -VarPrivate::VarPrivate(InstancePrivate* instance, ScriptableObject* object) { +VarPrivate::VarPrivate(const InstanceHandle& instance, + ScriptableObject* object) { if (has_interface<PPB_Var_Deprecated>()) { var_ = get_interface<PPB_Var_Deprecated>()->CreateObject( - instance->pp_instance(), object->GetClass(), object); + instance.pp_instance(), object->GetClass(), object); needs_release_ = true; } else { var_.type = PP_VARTYPE_NULL; diff --git a/ppapi/cpp/private/var_private.h b/ppapi/cpp/private/var_private.h index 860f643..1c4cc8a 100644 --- a/ppapi/cpp/private/var_private.h +++ b/ppapi/cpp/private/var_private.h @@ -9,7 +9,7 @@ namespace pp { -class InstancePrivate; +class InstanceHandle; namespace deprecated { class ScriptableObject; @@ -29,7 +29,8 @@ class VarPrivate : public Var { VarPrivate(const std::string& utf8_str) : Var(utf8_str) {} VarPrivate(PassRef, PP_Var var) : Var(PassRef(), var) {} VarPrivate(DontManage, PP_Var var) : Var(DontManage(), var) {} - VarPrivate(InstancePrivate* instance, deprecated::ScriptableObject* object); + VarPrivate(const InstanceHandle& instance, + deprecated::ScriptableObject* object); VarPrivate(const Var& other) : Var(other) {} virtual ~VarPrivate() {} diff --git a/ppapi/cpp/resource.cc b/ppapi/cpp/resource.cc index 5a327d6..3ccc198 100644 --- a/ppapi/cpp/resource.cc +++ b/ppapi/cpp/resource.cc @@ -44,6 +44,9 @@ Resource::Resource(PP_Resource resource) : pp_resource_(resource) { Module::Get()->core()->AddRefResource(pp_resource_); } +Resource::Resource(PassRef, PP_Resource resource) : pp_resource_(resource) { +} + void Resource::PassRefFromConstructor(PP_Resource resource) { PP_DCHECK(!pp_resource_); pp_resource_ = resource; diff --git a/ppapi/cpp/resource.h b/ppapi/cpp/resource.h index e6bd074..f214672 100644 --- a/ppapi/cpp/resource.h +++ b/ppapi/cpp/resource.h @@ -6,6 +6,8 @@ #define PPAPI_CPP_RESOURCE_H_ #include "ppapi/c/pp_resource.h" +#include "ppapi/cpp/instance_handle.h" +#include "ppapi/cpp/pass_ref.h" /// @file /// This file defines a <code>Resource</code> type representing data associated @@ -15,7 +17,6 @@ namespace pp { /// A reference counted module resource. class Resource { public: - /// The default constructor. Resource(); @@ -60,6 +61,10 @@ class Resource { /// resource. explicit Resource(PP_Resource resource); + /// Constructor used when a <code>PP_Resource</code> already has a ref count + /// assigned. Add additional refcount is not taken. + Resource(PassRef, PP_Resource resource); + /// PassRefFromConstructor is called by derived class' constructors to /// initialize this <code>Resource</code> with a <code>PP_Resource</code> /// that has already had its reference count incremented by diff --git a/ppapi/cpp/trusted/browser_font_trusted.cc b/ppapi/cpp/trusted/browser_font_trusted.cc index 8bea86a..b9f2b0d 100644 --- a/ppapi/cpp/trusted/browser_font_trusted.cc +++ b/ppapi/cpp/trusted/browser_font_trusted.cc @@ -158,7 +158,7 @@ BrowserFont_Trusted& BrowserFont_Trusted::operator=( Var BrowserFont_Trusted::GetFontFamilies(Instance* instance) { if (!has_interface<PPB_Font_Dev>()) return Var(); - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_Font_Dev>()->GetFontFamilies( instance->pp_instance())); } @@ -179,7 +179,7 @@ bool BrowserFont_Trusted::Describe( BrowserFontMetricsToFontMetrics(metrics))) return false; } - description->face_ = Var(Var::PassRef(), + description->face_ = Var(PASS_REF, description->pp_font_description_.face); return true; } diff --git a/ppapi/cpp/trusted/file_chooser_trusted.cc b/ppapi/cpp/trusted/file_chooser_trusted.cc index aa05798..a5f6879 100644 --- a/ppapi/cpp/trusted/file_chooser_trusted.cc +++ b/ppapi/cpp/trusted/file_chooser_trusted.cc @@ -24,7 +24,7 @@ template <> const char* interface_name<PPB_FileChooserTrusted>() { FileChooser_Trusted::FileChooser_Trusted() : save_as_(false) { } -FileChooser_Trusted::FileChooser_Trusted(const Instance* instance, +FileChooser_Trusted::FileChooser_Trusted(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, const Var& accept_mime_types, bool save_as, diff --git a/ppapi/cpp/trusted/file_chooser_trusted.h b/ppapi/cpp/trusted/file_chooser_trusted.h index d6a2491..d730dbf 100644 --- a/ppapi/cpp/trusted/file_chooser_trusted.h +++ b/ppapi/cpp/trusted/file_chooser_trusted.h @@ -16,7 +16,7 @@ class FileChooser_Trusted : public FileChooser_Dev { /// Creates an is_null() FileChooser_Trusted object. FileChooser_Trusted(); - FileChooser_Trusted(const Instance* instance, + FileChooser_Trusted(const InstanceHandle& instance, PP_FileChooserMode_Dev mode, const Var& accept_mime_types, bool save_as, diff --git a/ppapi/cpp/url_loader.cc b/ppapi/cpp/url_loader.cc index a2cef70..73855e9 100644 --- a/ppapi/cpp/url_loader.cc +++ b/ppapi/cpp/url_loader.cc @@ -8,7 +8,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/file_ref.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/url_request_info.h" @@ -27,21 +27,13 @@ template <> const char* interface_name<PPB_URLLoader>() { URLLoader::URLLoader(PP_Resource resource) : Resource(resource) { } -// TODO(brettw) remove this when NaCl is updated. -URLLoader::URLLoader(const Instance& instance) { +URLLoader::URLLoader(const InstanceHandle& instance) { if (!has_interface<PPB_URLLoader>()) return; PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( instance.pp_instance())); } -URLLoader::URLLoader(Instance* instance) { - if (!has_interface<PPB_URLLoader>()) - return; - PassRefFromConstructor(get_interface<PPB_URLLoader>()->Create( - instance->pp_instance())); -} - URLLoader::URLLoader(const URLLoader& other) : Resource(other) { } @@ -81,7 +73,7 @@ bool URLLoader::GetDownloadProgress( URLResponseInfo URLLoader::GetResponseInfo() const { if (!has_interface<PPB_URLLoader>()) return URLResponseInfo(); - return URLResponseInfo(URLResponseInfo::PassRef(), + return URLResponseInfo(PASS_REF, get_interface<PPB_URLLoader>()->GetResponseInfo( pp_resource())); } diff --git a/ppapi/cpp/url_loader.h b/ppapi/cpp/url_loader.h index 6074cb9..3ed5fe6 100644 --- a/ppapi/cpp/url_loader.h +++ b/ppapi/cpp/url_loader.h @@ -13,7 +13,7 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; class URLRequestInfo; class URLResponseInfo; @@ -26,10 +26,6 @@ class URLLoader : public Resource { /// <code>URLLoader</code> object. URLLoader() {} - // TODO(brettw) remove this when NaCl is updated to use the new version - // that takes a pointer. - explicit URLLoader(const Instance& instance); - /// A constructor used when a <code>PP_Resource</code> is provided as a /// return value whose reference count we need to increment. /// @@ -40,8 +36,9 @@ class URLLoader : public Resource { /// A constructor used to allocate a new URLLoader in the browser. The /// resulting object will be <code>is_null</code> if the allocation failed. /// - /// @param[in] instance An <code>Instance</code>. - explicit URLLoader(Instance* instance); + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit URLLoader(const InstanceHandle& instance); /// The copy constructor for <code>URLLoader</code>. /// diff --git a/ppapi/cpp/url_request_info.cc b/ppapi/cpp/url_request_info.cc index 1b31240..c7cd22e 100644 --- a/ppapi/cpp/url_request_info.cc +++ b/ppapi/cpp/url_request_info.cc @@ -5,7 +5,7 @@ #include "ppapi/cpp/url_request_info.h" #include "ppapi/cpp/file_ref.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" @@ -19,11 +19,11 @@ template <> const char* interface_name<PPB_URLRequestInfo>() { } // namespace -URLRequestInfo::URLRequestInfo(Instance* instance) { +URLRequestInfo::URLRequestInfo(const InstanceHandle& instance) { if (!has_interface<PPB_URLRequestInfo>()) return; PassRefFromConstructor( - get_interface<PPB_URLRequestInfo>()->Create(instance->pp_instance())); + get_interface<PPB_URLRequestInfo>()->Create(instance.pp_instance())); } URLRequestInfo::URLRequestInfo(const URLRequestInfo& other) diff --git a/ppapi/cpp/url_request_info.h b/ppapi/cpp/url_request_info.h index 955ff21..49e47ae 100644 --- a/ppapi/cpp/url_request_info.h +++ b/ppapi/cpp/url_request_info.h @@ -14,7 +14,7 @@ namespace pp { class FileRef; -class Instance; +class InstanceHandle; /// URLRequestInfo provides an API for creating and manipulating URL requests. class URLRequestInfo : public Resource { @@ -27,8 +27,9 @@ class URLRequestInfo : public Resource { /// browser. The resulting object will be <code>is_null</code> if the /// allocation failed. /// - /// @param[in] instance An <code>Instance</code>. - explicit URLRequestInfo(Instance* instance); + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit URLRequestInfo(const InstanceHandle& instance); /// The copy constructor for <code>URLRequestInfo</code>. /// diff --git a/ppapi/cpp/url_response_info.cc b/ppapi/cpp/url_response_info.cc index 64b7686..a1e2d3a 100644 --- a/ppapi/cpp/url_response_info.cc +++ b/ppapi/cpp/url_response_info.cc @@ -22,14 +22,14 @@ URLResponseInfo::URLResponseInfo(const URLResponseInfo& other) : Resource(other) { } -URLResponseInfo::URLResponseInfo(PassRef, PP_Resource resource) { - PassRefFromConstructor(resource); +URLResponseInfo::URLResponseInfo(PassRef, PP_Resource resource) + : Resource(PASS_REF, resource) { } Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) const { if (!has_interface<PPB_URLResponseInfo>()) return Var(); - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_URLResponseInfo>()->GetProperty(pp_resource(), property)); } @@ -37,7 +37,7 @@ Var URLResponseInfo::GetProperty(PP_URLResponseProperty property) const { FileRef URLResponseInfo::GetBodyAsFileRef() const { if (!has_interface<PPB_URLResponseInfo>()) return FileRef(); - return FileRef(FileRef::PassRef(), + return FileRef(PASS_REF, get_interface<PPB_URLResponseInfo>()->GetBodyAsFileRef( pp_resource())); } diff --git a/ppapi/cpp/url_response_info.h b/ppapi/cpp/url_response_info.h index aee4ca1..682fbf7 100644 --- a/ppapi/cpp/url_response_info.h +++ b/ppapi/cpp/url_response_info.h @@ -22,10 +22,6 @@ class URLResponseInfo : public Resource { /// resource. URLResponseInfo() {} - /// A special structure used by the constructor that does not increment the - /// reference count of the underlying resource. - struct PassRef {}; - /// A constructor used when you have received a <code>PP_Resource</code> as a /// return value that has already been reference counted. /// diff --git a/ppapi/cpp/var.h b/ppapi/cpp/var.h index a0c5c19..b0914be 100644 --- a/ppapi/cpp/var.h +++ b/ppapi/cpp/var.h @@ -9,7 +9,7 @@ #include <vector> #include "ppapi/c/pp_var.h" - +#include "ppapi/cpp/pass_ref.h" /// @file /// This file defines the API for handling the passing of data types between @@ -50,12 +50,6 @@ class Var { /// A constructor used to create a UTF-8 character <code>Var</code>. Var(const std::string& utf8_str); // Must be encoded in UTF-8. - /// PassRef can be used to construct a <code>Var</code> with a - /// <code>PP_Var</code> when the <code>PP_Var</code> - /// already has had its reference count incremented. For example: - /// <code>pp::Var my_var(PassRef(), my_pp_var);</code> - struct PassRef {}; - /// A constructor used when you have received a <code>Var</code> as a return /// value that has had its reference count incremented for you. /// @@ -269,7 +263,7 @@ class Var { /// Destructor. ~OutException() { if (output_ && !originally_had_exception_) - *output_ = Var(PassRef(), temp_); + *output_ = Var(PASS_REF, temp_); } PP_Var* get() { diff --git a/ppapi/cpp/websocket.cc b/ppapi/cpp/websocket.cc index 2a65370..11c2aac 100644 --- a/ppapi/cpp/websocket.cc +++ b/ppapi/cpp/websocket.cc @@ -7,7 +7,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_macros.h" #include "ppapi/cpp/completion_callback.h" -#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/instance_handle.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/var.h" @@ -22,11 +22,11 @@ template <> const char* interface_name<PPB_WebSocket>() { } // namespace -WebSocket::WebSocket(Instance* instance) { +WebSocket::WebSocket(const InstanceHandle& instance) { if (!has_interface<PPB_WebSocket>()) return; PassRefFromConstructor(get_interface<PPB_WebSocket>()->Create( - instance->pp_instance())); + instance.pp_instance())); } WebSocket::~WebSocket() { @@ -101,7 +101,7 @@ Var WebSocket::GetCloseReason() { if (!has_interface<PPB_WebSocket>()) return 0; - return Var(Var::PassRef(), + return Var(PASS_REF, get_interface<PPB_WebSocket>()->GetCloseReason(pp_resource())); } @@ -118,16 +118,16 @@ Var WebSocket::GetExtensions() { if (!has_interface<PPB_WebSocket>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket>()->GetExtensions(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket>()->GetExtensions(pp_resource())); } Var WebSocket::GetProtocol() { if (!has_interface<PPB_WebSocket>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket>()->GetProtocol(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket>()->GetProtocol(pp_resource())); } PP_WebSocketReadyState WebSocket::GetReadyState() { @@ -141,8 +141,8 @@ Var WebSocket::GetURL() { if (!has_interface<PPB_WebSocket>()) return Var(); - return Var(Var::PassRef(), - get_interface<PPB_WebSocket>()->GetURL(pp_resource())); + return Var(PASS_REF, + get_interface<PPB_WebSocket>()->GetURL(pp_resource())); } } // namespace pp diff --git a/ppapi/cpp/websocket.h b/ppapi/cpp/websocket.h index 61e61df..dce2330 100644 --- a/ppapi/cpp/websocket.h +++ b/ppapi/cpp/websocket.h @@ -14,14 +14,17 @@ namespace pp { class CompletionCallback; -class Instance; +class InstanceHandle; class Var; /// The <code>WebSocket</code> class class WebSocket : public Resource { public: /// Constructs a WebSocket object. - WebSocket(Instance* instance); + /// + /// @param[in] instance The instance with which this resource will be + /// associated. + explicit WebSocket(const InstanceHandle& instance); /// Destructs a WebSocket object. virtual ~WebSocket(); diff --git a/ppapi/example/example.cc b/ppapi/example/example.cc index 8319d49..17ac037 100644 --- a/ppapi/example/example.cc +++ b/ppapi/example/example.cc @@ -98,14 +98,14 @@ class MyFetcher { callback_factory_.Initialize(this); } - void Start(const pp::InstancePrivate& instance, + void Start(pp::Instance* instance, const pp::Var& url, MyFetcherClient* client) { pp::URLRequestInfo request; request.SetURL(url); request.SetMethod("GET"); - loader_ = pp::URLLoader(instance); + loader_ = pp::URLLoader(pp::InstanceHandle(instance)); client_ = client; pp::CompletionCallback callback = @@ -415,7 +415,7 @@ int gettimeofday(struct timeval *tv, struct timezone*) { if (!fetcher_) { fetcher_ = new MyFetcher(); - fetcher_->Start(*this, href, this); + fetcher_->Start(this, href, this); } } diff --git a/ppapi/examples/video_capture/video_capture.cc b/ppapi/examples/video_capture/video_capture.cc index 512cca4..20c0c75 100644 --- a/ppapi/examples/video_capture/video_capture.cc +++ b/ppapi/examples/video_capture/video_capture.cc @@ -150,7 +150,7 @@ VCDemoInstance::VCDemoInstance(PP_Instance instance, pp::Module* module) texture_y_(0), texture_u_(0), texture_v_(0), - video_capture_(*this), + video_capture_(this), callback_factory_(this), context_(NULL) { gles2_if_ = static_cast<const struct PPB_OpenGLES2*>( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_net_address_private_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_net_address_private_rpc_server.cc index 3343049..f8ca72b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_net_address_private_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_net_address_private_rpc_server.cc @@ -107,7 +107,7 @@ void PpbNetAddressPrivateRpcServer::PPB_NetAddress_Private_Describe( module, reinterpret_cast<PP_NetAddress_Private*>(addr), static_cast<PP_Bool>(include_port)); - pp::Var address(pp::Var::PassRef(), pp_address); + pp::Var address(pp::PASS_REF, pp_address); if (!SerializeTo(&address.pp_var(), description, description_bytes)) return; diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc index 8fb9d6f..8f3ab6e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_testing_rpc_server.cc @@ -132,6 +132,6 @@ void PpbTestingRpcServer::PPB_Testing_GetDocumentURL( return; DebugPrintf("PPB_Testing_Dev::GetDocumentURL: url=%s\n", - pp::Var(pp::Var::PassRef(), pp_url).AsString().c_str()); + pp::Var(pp::PASS_REF, pp_url).AsString().c_str()); rpc->result = NACL_SRPC_RESULT_OK; } diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 0034f26..c89daa0 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -340,7 +340,7 @@ class PrintingAdapter : public pp::Printing_Dev { PP_Resource image_data = ppp_printing_->PrintPages(plugin_->pp_instance(), page_ranges, page_range_count); - return pp::ImageData(pp::ImageData::PassRef(), image_data); + return pp::ImageData(pp::PASS_REF, image_data); } return pp::Resource(); } @@ -383,7 +383,7 @@ class SelectionAdapter : public pp::Selection_Dev { if (ppp_selection_ != NULL) { PP_Var var = ppp_selection_->GetSelectedText(plugin_->pp_instance(), PP_FromBool(html)); - return pp::Var(pp::Var::PassRef(), var); + return pp::Var(pp::PASS_REF, var); } return pp::Var(); } @@ -825,7 +825,7 @@ bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { // manifest. This takes into account the setting of <base> tags that // precede the embed/object. CHECK(url_util_ != NULL); - pp::Var base_var = url_util_->GetDocumentURL(*this); + pp::Var base_var = url_util_->GetDocumentURL(this); if (!base_var.is_string()) { PLUGIN_PRINTF(("Plugin::Init (unable to find document url)\n")); return false; diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi index e212681..cce3a54 100644 --- a/ppapi/ppapi_sources.gypi +++ b/ppapi/ppapi_sources.gypi @@ -151,6 +151,8 @@ 'cpp/input_event.h', 'cpp/instance.cc', 'cpp/instance.h', + 'cpp/instance_handle.cc', + 'cpp/instance_handle.h', 'cpp/logging.h', 'cpp/module.cc', 'cpp/module.h', diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc index 6ffe53e..90e7d72 100644 --- a/ppapi/tests/test_case.cc +++ b/ppapi/tests/test_case.cc @@ -126,7 +126,7 @@ std::string TestCase::CheckResourcesAndVars() { << kVarsToPrint <<"):<p>"; errors += output.str(); for (uint32_t i = 0; i < std::min(tracked_vars, kVarsToPrint); ++i) { - pp::Var leaked_var(pp::Var::PassRef(), vars[i]); + pp::Var leaked_var(pp::PASS_REF, vars[i]); #if (defined __native_client__) errors += leaked_var.DebugString() + "<p>"; #else diff --git a/ppapi/tests/test_char_set.cc b/ppapi/tests/test_char_set.cc index dfff9ed..5056c2c 100644 --- a/ppapi/tests/test_char_set.cc +++ b/ppapi/tests/test_char_set.cc @@ -352,11 +352,11 @@ std::string TestCharSet::TestCharSetToUTF16() { std::string TestCharSet::TestGetDefaultCharSet() { // Test invalid instance. - pp::Var result(pp::Var::PassRef(), char_set_interface_->GetDefaultCharSet(0)); + pp::Var result(pp::PASS_REF, char_set_interface_->GetDefaultCharSet(0)); ASSERT_TRUE(result.is_undefined()); // Just make sure the default char set is a nonempty string. - result = pp::Var(pp::Var::PassRef(), + result = pp::Var(pp::PASS_REF, char_set_interface_->GetDefaultCharSet(instance_->pp_instance())); ASSERT_TRUE(result.is_string()); ASSERT_FALSE(result.AsString().empty()); diff --git a/ppapi/tests/test_flash.cc b/ppapi/tests/test_flash.cc index 9f666a8..debbc49 100644 --- a/ppapi/tests/test_flash.cc +++ b/ppapi/tests/test_flash.cc @@ -41,27 +41,27 @@ std::string TestFlash::TestSetInstanceAlwaysOnTop() { } std::string TestFlash::TestGetProxyForURL() { - Var result(Var::PassRef(), + Var result(pp::PASS_REF, flash_interface_->GetProxyForURL(instance_->pp_instance(), "http://127.0.0.1/foobar/")); ASSERT_TRUE(result.is_string()); // Assume no one configures a proxy for localhost. ASSERT_EQ("DIRECT", result.AsString()); - result = Var(Var::PassRef(), + result = Var(pp::PASS_REF, flash_interface_->GetProxyForURL(instance_->pp_instance(), "http://www.google.com")); // Don't know what the proxy might be, but it should be a valid result. ASSERT_TRUE(result.is_string()); - result = Var(Var::PassRef(), + result = Var(pp::PASS_REF, flash_interface_->GetProxyForURL(instance_->pp_instance(), "file:///tmp")); ASSERT_TRUE(result.is_string()); // Should get "DIRECT" for file:// URLs. ASSERT_EQ("DIRECT", result.AsString()); - result = Var(Var::PassRef(), + result = Var(pp::PASS_REF, flash_interface_->GetProxyForURL(instance_->pp_instance(), "this_isnt_an_url")); // Should be an error. @@ -91,7 +91,7 @@ std::string TestFlash::TestGetLocalTimeZoneOffset() { } std::string TestFlash::TestGetCommandLineArgs() { - Var result(Var::PassRef(), + Var result(pp::PASS_REF, flash_interface_->GetCommandLineArgs( pp::Module::Get()->pp_module())); ASSERT_TRUE(result.is_string()); diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc index 09e4000..0f44247 100644 --- a/ppapi/tests/test_flash_clipboard.cc +++ b/ppapi/tests/test_flash_clipboard.cc @@ -54,7 +54,7 @@ std::string TestFlashClipboard::ReadStringVar( PP_Flash_Clipboard_Format format) { std::string result_str; pp::Var result_var( - pp::Var::PassRef(), + pp::PASS_REF, clipboard_interface_->ReadData(instance_->pp_instance(), PP_FLASH_CLIPBOARD_TYPE_STANDARD, format)); diff --git a/ppapi/tests/test_input_event.cc b/ppapi/tests/test_input_event.cc index c9f1736..73b7635 100644 --- a/ppapi/tests/test_input_event.cc +++ b/ppapi/tests/test_input_event.cc @@ -212,9 +212,9 @@ bool TestInputEvent::AreEquivalentEvents(PP_Resource received, return keyboard_input_event_interface_->GetKeyCode(received) == keyboard_input_event_interface_->GetKeyCode(expected) && - pp::Var(pp::Var::PassRef(), + pp::Var(pp::PASS_REF, keyboard_input_event_interface_->GetCharacterText(received)) == - pp::Var(pp::Var::PassRef(), + pp::Var(pp::PASS_REF, keyboard_input_event_interface_->GetCharacterText(expected)); default: diff --git a/ppapi/tests/test_scrollbar.cc b/ppapi/tests/test_scrollbar.cc index b005db7..83c8365 100644 --- a/ppapi/tests/test_scrollbar.cc +++ b/ppapi/tests/test_scrollbar.cc @@ -18,7 +18,7 @@ REGISTER_TEST_CASE(Scrollbar); TestScrollbar::TestScrollbar(TestingInstance* instance) : TestCase(instance), WidgetClient_Dev(instance), - scrollbar_(*instance, true), + scrollbar_(instance, true), scrollbar_value_changed_(false) { } diff --git a/ppapi/tests/test_tcp_socket_private.cc b/ppapi/tests/test_tcp_socket_private.cc index 1de1fa8..bcd749d 100644 --- a/ppapi/tests/test_tcp_socket_private.cc +++ b/ppapi/tests/test_tcp_socket_private.cc @@ -49,7 +49,7 @@ bool TestTCPSocketPrivate::Init() { return false; PP_URLComponents_Dev components; - pp::Var pp_url = pp::URLUtil_Dev::Get()->GetDocumentURL(*instance_, + pp::Var pp_url = pp::URLUtil_Dev::Get()->GetDocumentURL(instance_, &components); if (!pp_url.is_string()) return false; diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc index 2b0a66b..984fee0 100644 --- a/ppapi/tests/test_url_loader.cc +++ b/ppapi/tests/test_url_loader.cc @@ -169,7 +169,7 @@ std::string TestURLLoader::LoadAndCompareBody( const std::string& expected_body) { TestCompletionCallback callback(instance_->pp_instance(), force_async_); - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); int32_t rv = loader.Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); @@ -251,7 +251,7 @@ std::string TestURLLoader::GetReachableAbsoluteURL( // Get the absolute page URL and replace the test case file name // with the given one. pp::Var document_url( - pp::Var::PassRef(), + pp::PASS_REF, testing_interface_->GetDocumentURL(instance_->pp_instance(), NULL)); std::string url(document_url.AsString()); @@ -306,7 +306,7 @@ int32_t TestURLLoader::OpenTrusted(const pp::URLRequestInfo& request) { int32_t TestURLLoader::Open(const pp::URLRequestInfo& request, bool trusted) { - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); if (trusted) url_loader_trusted_interface_->GrantUniversalAccess(loader.pp_resource()); TestCompletionCallback callback(instance_->pp_instance(), force_async_); @@ -439,7 +439,7 @@ std::string TestURLLoader::TestStreamToFile() { TestCompletionCallback callback(instance_->pp_instance(), force_async_); - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); int32_t rv = loader.Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); @@ -728,7 +728,7 @@ std::string TestURLLoader::TestAuditURLRedirect() { TestCompletionCallback callback(instance_->pp_instance(), force_async_); - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); int32_t rv = loader.Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); @@ -777,7 +777,7 @@ std::string TestURLLoader::TestAbortCalls() { // Abort |Open()|. { callback.reset_run_count(); - rv = pp::URLLoader(*instance_).Open(request, callback); + rv = pp::URLLoader(instance_).Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); if (callback.run_count() > 0) @@ -795,7 +795,7 @@ std::string TestURLLoader::TestAbortCalls() { { char buf[2] = { 0 }; { - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); rv = loader.Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); @@ -836,7 +836,7 @@ std::string TestURLLoader::TestUntendedLoad() { request.SetRecordDownloadProgress(true); TestCompletionCallback callback(instance_->pp_instance(), force_async_); - pp::URLLoader loader(*instance_); + pp::URLLoader loader(instance_); int32_t rv = loader.Open(request, callback); if (force_async_ && rv != PP_OK_COMPLETIONPENDING) return ReportError("URLLoader::Open force_async", rv); diff --git a/ppapi/tests/test_url_util.cc b/ppapi/tests/test_url_util.cc index 179aeeb..5de683f 100644 --- a/ppapi/tests/test_url_util.cc +++ b/ppapi/tests/test_url_util.cc @@ -108,18 +108,18 @@ std::string TestURLUtil::TestIsSameSecurityOrigin() { std::string TestURLUtil::TestDocumentCanRequest() { // This is hard to test, but we can at least verify we can't request // some random domain. - ASSERT_FALSE(util_->DocumentCanRequest(*instance_, "http://evil.com/")); + ASSERT_FALSE(util_->DocumentCanRequest(instance_, "http://evil.com/")); PASS(); } std::string TestURLUtil::TestDocumentCanAccessDocument() { // This is hard to test, but we can at least verify we can access ourselves. - ASSERT_TRUE(util_->DocumentCanAccessDocument(*instance_, *instance_)); + ASSERT_TRUE(util_->DocumentCanAccessDocument(instance_, instance_)); PASS(); } std::string TestURLUtil::TestGetDocumentURL() { - pp::Var url = util_->GetDocumentURL(*instance_); + pp::Var url = util_->GetDocumentURL(instance_); ASSERT_TRUE(url.is_string()); pp::VarPrivate window = instance_->GetWindowObject(); pp::Var href = window.GetProperty("location").GetProperty("href"); @@ -130,7 +130,7 @@ std::string TestURLUtil::TestGetDocumentURL() { } std::string TestURLUtil::TestGetPluginInstanceURL() { - pp::Var url = util_->GetPluginInstanceURL(*instance_); + pp::Var url = util_->GetPluginInstanceURL(instance_); ASSERT_TRUE(url.is_string()); // see test_case.html ASSERT_EQ(url.AsString(), "http://a.b.c/test"); diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc index a98c693..449b64c 100644 --- a/ppapi/tests/test_utils.cc +++ b/ppapi/tests/test_utils.cc @@ -50,7 +50,7 @@ bool GetLocalHostPort(PP_Instance instance, std::string* host, uint16_t* port) { return false; PP_URLComponents_Dev components; - pp::Var pp_url(pp::Var::PassRef(), + pp::Var pp_url(pp::PASS_REF, testing->GetDocumentURL(instance, &components)); if (!pp_url.is_string()) return false; diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc index 8eeeac2..b705ad5 100644 --- a/ppapi/tests/test_websocket.cc +++ b/ppapi/tests/test_websocket.cc @@ -584,7 +584,7 @@ std::string TestWebSocket::TestCcInterfaces() { for (uint32_t i = 0; i < binary_length; ++i) binary_message[i] = i; result = ws.SendMessage(pp::Var( - pp::Var::PassRef(), CreateVarBinary(binary_message, binary_length))); + pp::PASS_REF, CreateVarBinary(binary_message, binary_length))); ASSERT_EQ(PP_OK, result); pp::Var text_receive_var; diff --git a/ppapi/utility/threading/simple_thread.cc b/ppapi/utility/threading/simple_thread.cc index d0876e9..f17c237 100644 --- a/ppapi/utility/threading/simple_thread.cc +++ b/ppapi/utility/threading/simple_thread.cc @@ -38,7 +38,7 @@ void* RunThread(void* void_data) { } // namespace -SimpleThread::SimpleThread(Instance* instance) +SimpleThread::SimpleThread(const InstanceHandle& instance) : instance_(instance), message_loop_(instance), thread_(0) { diff --git a/ppapi/utility/threading/simple_thread.h b/ppapi/utility/threading/simple_thread.h index a093961..d60a43d 100644 --- a/ppapi/utility/threading/simple_thread.h +++ b/ppapi/utility/threading/simple_thread.h @@ -12,6 +12,7 @@ #endif #include "ppapi/cpp/dev/message_loop_dev.h" +#include "ppapi/cpp/instance_handle.h" namespace pp { @@ -27,7 +28,7 @@ class SimpleThread { typedef void (*ThreadFunc)(MessageLoop_Dev&, void* user_data); - SimpleThread(Instance* instance); + explicit SimpleThread(const InstanceHandle& instance); ~SimpleThread(); // Starts a thread and runs a message loop in it. If you need control over @@ -49,7 +50,7 @@ class SimpleThread { ThreadHandle thread() const { return thread_; } private: - Instance* instance_; + InstanceHandle instance_; MessageLoop_Dev message_loop_; ThreadHandle thread_; |