diff options
Diffstat (limited to 'webkit/plugins')
80 files changed, 801 insertions, 628 deletions
diff --git a/webkit/plugins/ppapi/callbacks_unittest.cc b/webkit/plugins/ppapi/callbacks_unittest.cc index 4cd8084..30e534b 100644 --- a/webkit/plugins/ppapi/callbacks_unittest.cc +++ b/webkit/plugins/ppapi/callbacks_unittest.cc @@ -12,6 +12,7 @@ #include "webkit/plugins/ppapi/mock_resource.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" namespace webkit { @@ -110,27 +111,29 @@ namespace { class CallbackMockResource : public MockResource { public: - CallbackMockResource(PluginInstance* instance) : MockResource(instance) {} + CallbackMockResource(PP_Instance instance) : MockResource(instance) {} ~CallbackMockResource() {} PP_Resource SetupForTest() { PP_Resource resource_id = GetReference(); EXPECT_NE(0, resource_id); + PluginModule* module = ResourceHelper::GetPluginModule(this); + callback_did_run_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), + module->GetCallbackTracker(), resource_id, PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); EXPECT_EQ(0U, info_did_run_.run_count); callback_did_abort_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), + module->GetCallbackTracker(), resource_id, PP_MakeCompletionCallback(&TestCallback, &info_did_abort_)); EXPECT_EQ(0U, info_did_abort_.run_count); callback_didnt_run_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), + module->GetCallbackTracker(), resource_id, PP_MakeCompletionCallback(&TestCallback, &info_didnt_run_)); EXPECT_EQ(0U, info_didnt_run_.run_count); @@ -188,13 +191,13 @@ TEST_F(CallbackResourceTest, AbortOnNoRef) { // Check that the uncompleted one gets aborted, and that the others don't get // called again. scoped_refptr<CallbackMockResource> resource_1( - new CallbackMockResource(instance())); + new CallbackMockResource(instance()->pp_instance())); PP_Resource resource_1_id = resource_1->SetupForTest(); // Also do the same for a second resource, and make sure that unref-ing the // first resource doesn't much up the second resource. scoped_refptr<CallbackMockResource> resource_2( - new CallbackMockResource(instance())); + new CallbackMockResource(instance()->pp_instance())); PP_Resource resource_2_id = resource_2->SetupForTest(); // Double-check that resource #1 is still okay. @@ -223,7 +226,7 @@ TEST_F(CallbackResourceTest, Resurrection) { ResourceTracker* resource_tracker = ResourceTracker::Get(); scoped_refptr<CallbackMockResource> resource( - new CallbackMockResource(instance())); + new CallbackMockResource(instance()->pp_instance())); PP_Resource resource_id = resource->SetupForTest(); // Unref it, spin the message loop to run posted calls, and check that things diff --git a/webkit/plugins/ppapi/message_channel.h b/webkit/plugins/ppapi/message_channel.h index a6091f13..c6470c4 100644 --- a/webkit/plugins/ppapi/message_channel.h +++ b/webkit/plugins/ppapi/message_channel.h @@ -6,8 +6,8 @@ #define WEBKIT_PLUGINS_PPAPI_MESSAGE_CHANNEL_H_ #include "base/task.h" +#include "ppapi/shared_impl/resource.h" #include "third_party/npapi/bindings/npruntime.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_Var; diff --git a/webkit/plugins/ppapi/mock_resource.h b/webkit/plugins/ppapi/mock_resource.h index 1368c4a..3db87f6 100644 --- a/webkit/plugins/ppapi/mock_resource.h +++ b/webkit/plugins/ppapi/mock_resource.h @@ -1,11 +1,11 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef WEBKIT_PLUGINS_PPAPI_MOCK_RESOURCE_H_ #define WEBKIT_PLUGINS_PPAPI_MOCK_RESOURCE_H_ -#include "webkit/plugins/ppapi/resource.h" +#include "ppapi/shared_impl/resource.h" namespace webkit { namespace ppapi { @@ -13,9 +13,9 @@ namespace ppapi { // Tests can derive from this to implement special test-specific resources. // It's assumed that a test will only need one mock resource, so it can // static_cast to get its own implementation. -class MockResource : public Resource { +class MockResource : public ::ppapi::Resource { public: - MockResource(PluginInstance* instance) : Resource(instance) {} + MockResource(PP_Instance instance) : Resource(instance) {} virtual ~MockResource() {} }; diff --git a/webkit/plugins/ppapi/plugin_object.cc b/webkit/plugins/ppapi/plugin_object.cc index 5362fa4..153ce87 100644 --- a/webkit/plugins/ppapi/plugin_object.cc +++ b/webkit/plugins/ppapi/plugin_object.cc @@ -20,7 +20,6 @@ #include "webkit/plugins/ppapi/npapi_glue.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/string.h" diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index dc8d055..1517f34 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -29,6 +29,7 @@ #include "ppapi/c/ppp_messaging.h" #include "ppapi/c/private/ppb_instance_private.h" #include "ppapi/c/private/ppp_instance_private.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/var.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_buffer_api.h" @@ -65,6 +66,7 @@ #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" #include "webkit/plugins/ppapi/ppp_pdf.h" +#include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/string.h" #include "webkit/plugins/sad_plugin.h" @@ -431,9 +433,8 @@ bool PluginInstance::Initialize(WebPluginContainer* container, } bool PluginInstance::HandleDocumentLoad(PPB_URLLoader_Impl* loader) { - Resource::ScopedResourceId resource(loader); - return PP_ToBool(instance_interface_->HandleDocumentLoad(pp_instance(), - resource.id)); + return PP_ToBool(instance_interface_->HandleDocumentLoad( + pp_instance(), loader->pp_resource())); } bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, @@ -460,11 +461,10 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, else rv = true; // Unfiltered events are assumed to be handled. scoped_refptr<PPB_InputEvent_Impl> event_resource( - new PPB_InputEvent_Impl(this, events[i])); - Resource::ScopedResourceId resource(event_resource); + new PPB_InputEvent_Impl(pp_instance(), events[i])); rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( - pp_instance(), resource.id)); + pp_instance(), event_resource->pp_resource())); } } } @@ -1371,7 +1371,7 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, static_cast<PPB_Surface3D_Impl*>(enter_surface_3d.object()) : NULL; if (graphics_2d) { - if (graphics_2d->instance() != this) + if (graphics_2d->pp_instance() != pp_instance()) return PP_FALSE; // Can't bind other instance's contexts. if (!graphics_2d->BindToInstance(this)) return PP_FALSE; // Can't bind to more than one instance. @@ -1382,7 +1382,7 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, } else if (graphics_3d) { // Make sure graphics can only be bound to the instance it is // associated with. - if (graphics_3d->instance() != this) + if (graphics_3d->pp_instance() != pp_instance()) return PP_FALSE; if (!graphics_3d->BindToInstance(true)) return PP_FALSE; @@ -1392,7 +1392,7 @@ PP_Bool PluginInstance::BindGraphics(PP_Instance instance, } else if (surface_3d) { // Make sure graphics can only be bound to the instance it is // associated with. - if (surface_3d->instance() != this) + if (surface_3d->pp_instance() != pp_instance()) return PP_FALSE; if (!surface_3d->BindToInstance(true)) return PP_FALSE; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 9949c17..16c7fff 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -58,6 +58,7 @@ class WebPluginContainer; namespace ppapi { struct PPP_Instance_Combined; +class Resource; } namespace webkit { @@ -75,7 +76,6 @@ class PPB_ImageData_Impl; class PPB_Surface3D_Impl; class PPB_URLLoader_Impl; class PPB_URLRequestInfo_Impl; -class Resource; // Represents one time a plugin appears on one web page. // @@ -372,7 +372,7 @@ class PluginInstance : public base::RefCounted<PluginInstance>, gfx::Rect clip_; // The current device context for painting in 2D or 3D. - scoped_refptr<Resource> bound_graphics_; + scoped_refptr< ::ppapi::Resource> bound_graphics_; // We track two types of focus, one from WebKit, which is the focus among // all elements of the page, one one from the browser, which is whether the diff --git a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc index e302fc6..cc6e66d 100644 --- a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc +++ b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc @@ -154,7 +154,7 @@ void WebPluginImpl::didReceiveResponse( const WebKit::WebURLResponse& response) { DCHECK(!document_loader_); - document_loader_ = new PPB_URLLoader_Impl(instance_, true); + document_loader_ = new PPB_URLLoader_Impl(instance_->pp_instance(), true); document_loader_->didReceiveResponse(NULL, response); if (!instance_->HandleDocumentLoad(document_loader_)) diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc index f13dda9..1f84d45 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.cc +++ b/webkit/plugins/ppapi/ppb_audio_impl.cc @@ -9,10 +9,13 @@ #include "ppapi/c/ppb_audio.h" #include "ppapi/c/ppb_audio_config.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/tracker_base.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_audio_config_api.h" #include "ppapi/thunk/thunk.h" #include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Audio_API; @@ -23,7 +26,7 @@ namespace ppapi { // PPB_AudioConfig ------------------------------------------------------------- -PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PluginInstance* instance) +PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(PP_Instance instance) : Resource(instance) { } @@ -31,7 +34,7 @@ PPB_AudioConfig_Impl::~PPB_AudioConfig_Impl() { } // static -PP_Resource PPB_AudioConfig_Impl::Create(PluginInstance* instance, +PP_Resource PPB_AudioConfig_Impl::Create(PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { scoped_refptr<PPB_AudioConfig_Impl> config( @@ -47,9 +50,8 @@ PPB_AudioConfig_API* PPB_AudioConfig_Impl::AsPPB_AudioConfig_API() { // PPB_Audio_Impl -------------------------------------------------------------- -PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) +PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance) : Resource(instance), - config_id_(0), audio_(NULL), create_callback_pending_(false), shared_memory_size_for_create_callback_(0) { @@ -57,9 +59,6 @@ PPB_Audio_Impl::PPB_Audio_Impl(PluginInstance* instance) } PPB_Audio_Impl::~PPB_Audio_Impl() { - if (config_id_) - ResourceTracker::Get()->ReleaseResource(config_id_); - // Calling ShutDown() makes sure StreamCreated cannot be called anymore and // releases the audio data associated with the pointer. Note however, that // until ShutDown returns, StreamCreated may still be called. This will be @@ -79,12 +78,12 @@ PPB_Audio_Impl::~PPB_Audio_Impl() { } // static -PP_Resource PPB_Audio_Impl::Create(PluginInstance* instance, - PP_Resource config_id, +PP_Resource PPB_Audio_Impl::Create(PP_Instance instance, + PP_Resource config, PPB_Audio_Callback audio_callback, void* user_data) { scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance)); - if (!audio->Init(config_id, audio_callback, user_data)) + if (!audio->Init(config, audio_callback, user_data)) return 0; return audio->GetReference(); } @@ -93,32 +92,34 @@ PPB_Audio_API* PPB_Audio_Impl::AsPPB_Audio_API() { return this; } -bool PPB_Audio_Impl::Init(PP_Resource config_id, +bool PPB_Audio_Impl::Init(PP_Resource config, PPB_Audio_Callback callback, void* user_data) { // Validate the config and keep a reference to it. - EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true); + EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); if (enter.failed()) return false; - config_id_ = config_id; - ResourceTracker::Get()->AddRefResource(config_id); + config_ = config; if (!callback) return false; SetCallback(callback, user_data); + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return false; + // When the stream is created, we'll get called back on StreamCreated(). CHECK(!audio_); - audio_ = instance()->delegate()->CreateAudio( - enter.object()->GetSampleRate(), - enter.object()->GetSampleFrameCount(), - this); + audio_ = plugin_delegate->CreateAudio(enter.object()->GetSampleRate(), + enter.object()->GetSampleFrameCount(), + this); return audio_ != NULL; } PP_Resource PPB_Audio_Impl::GetCurrentConfig() { - // AddRef on behalf of caller. - ResourceTracker::Get()->AddRefResource(config_id_); - return config_id_; + // AddRef on behalf of caller, while keeping a ref for ourselves. + ::ppapi::TrackerBase::Get()->GetResourceTracker()->AddRefResource(config_); + return config_; } PP_Bool PPB_Audio_Impl::StartPlayback() { @@ -141,22 +142,23 @@ PP_Bool PPB_Audio_Impl::StopPlayback() { return PP_TRUE; } -int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config_id, +int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config, PP_CompletionCallback create_callback) { - // Validate the config and keep a reference to it. - EnterResourceNoLock<PPB_AudioConfig_API> enter(config_id, true); + EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); if (enter.failed()) - return false; - config_id_ = config_id; - ResourceTracker::Get()->AddRefResource(config_id); + return PP_ERROR_FAILED; + config_ = config; + + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; // When the stream is created, we'll get called back on StreamCreated(). DCHECK(!audio_); - audio_ = instance()->delegate()->CreateAudio( - enter.object()->GetSampleRate(), - enter.object()->GetSampleFrameCount(), - this); + audio_ = plugin_delegate->CreateAudio(enter.object()->GetSampleRate(), + enter.object()->GetSampleFrameCount(), + this); if (!audio_) return PP_ERROR_FAILED; diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h index 4570a87..86ab386 100644 --- a/webkit/plugins/ppapi/ppb_audio_impl.h +++ b/webkit/plugins/ppapi/ppb_audio_impl.h @@ -15,23 +15,22 @@ #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/shared_impl/audio_config_impl.h" #include "ppapi/shared_impl/audio_impl.h" +#include "ppapi/shared_impl/scoped_pp_resource.h" +#include "ppapi/shared_impl/resource.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { -class PluginInstance; - // The implementation is actually in AudioConfigImpl. -class PPB_AudioConfig_Impl : public Resource, +class PPB_AudioConfig_Impl : public ::ppapi::Resource, public ::ppapi::AudioConfigImpl { public: virtual ~PPB_AudioConfig_Impl(); // Non-trusted creation. - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); @@ -39,14 +38,14 @@ class PPB_AudioConfig_Impl : public Resource, virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; private: - explicit PPB_AudioConfig_Impl(PluginInstance* instance); + explicit PPB_AudioConfig_Impl(PP_Instance instance); DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Impl); }; // Some of the backend functionality of this class is implemented by the // AudioImpl so it can be shared with the proxy. -class PPB_Audio_Impl : public Resource, +class PPB_Audio_Impl : public ::ppapi::Resource, public ::ppapi::AudioImpl, public PluginDelegate::PlatformAudio::Client { public: @@ -54,13 +53,13 @@ class PPB_Audio_Impl : public Resource, // // Untrusted initialization should just call the static Create() function // to properly create & initialize this class. - explicit PPB_Audio_Impl(PluginInstance* instance); + explicit PPB_Audio_Impl(PP_Instance instance); virtual ~PPB_Audio_Impl(); // Creation function for untrusted plugins. This handles all initialization // and will return 0 on failure. - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_Resource config_id, PPB_Audio_Callback audio_callback, void* user_data); @@ -88,7 +87,7 @@ class PPB_Audio_Impl : public Resource, base::SyncSocket::Handle socket); // AudioConfig used for creating this Audio object. We own a ref. - PP_Resource config_id_; + ::ppapi::ScopedPPResource config_; // PluginDelegate audio object that we delegate audio IPC through. We don't // own this pointer but are responsible for calling Shutdown on it. diff --git a/webkit/plugins/ppapi/ppb_broker_impl.cc b/webkit/plugins/ppapi/ppb_broker_impl.cc index 46ff79f..8bf2e79 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.cc +++ b/webkit/plugins/ppapi/ppb_broker_impl.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ::ppapi::thunk::PPB_Broker_API; @@ -31,7 +32,7 @@ int32_t PlatformFileToInt(base::PlatformFile handle) { // PPB_Broker_Impl ------------------------------------------------------ -PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) +PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) : Resource(instance), broker_(NULL), connect_callback_(), @@ -65,15 +66,19 @@ int32_t PPB_Broker_Impl::Connect(PP_CompletionCallback connect_callback) { return PP_ERROR_FAILED; } + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + // The callback must be populated now in case we are connected to the broker // and BrokerConnected is called before ConnectToPpapiBroker returns. // Because it must be created now, it must be aborted and cleared if // ConnectToPpapiBroker fails. connect_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), + plugin_instance->module()->GetCallbackTracker(), pp_resource(), connect_callback); - broker_ = instance()->delegate()->ConnectToPpapiBroker(this); + broker_ = plugin_instance->delegate()->ConnectToPpapiBroker(this); if (!broker_) { scoped_refptr<TrackedCompletionCallback> callback; callback.swap(connect_callback_); diff --git a/webkit/plugins/ppapi/ppb_broker_impl.h b/webkit/plugins/ppapi/ppb_broker_impl.h index c3a7434..3974657 100644 --- a/webkit/plugins/ppapi/ppb_broker_impl.h +++ b/webkit/plugins/ppapi/ppb_broker_impl.h @@ -9,22 +9,20 @@ #include "base/memory/weak_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_broker_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_Broker_Impl : public Resource, +class PPB_Broker_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Broker_API, public base::SupportsWeakPtr<PPB_Broker_Impl> { public: - explicit PPB_Broker_Impl(PluginInstance* instance); + explicit PPB_Broker_Impl(PP_Instance instance); virtual ~PPB_Broker_Impl(); // Resource override. diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.cc b/webkit/plugins/ppapi/ppb_buffer_impl.cc index 2782b84..dc3e70f 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.cc +++ b/webkit/plugins/ppapi/ppb_buffer_impl.cc @@ -13,6 +13,7 @@ #include "ppapi/c/pp_resource.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ::ppapi::thunk::PPB_Buffer_API; using ::ppapi::thunk::PPB_BufferTrusted_API; @@ -20,15 +21,17 @@ using ::ppapi::thunk::PPB_BufferTrusted_API; namespace webkit { namespace ppapi { -PPB_Buffer_Impl::PPB_Buffer_Impl(PluginInstance* instance) - : Resource(instance), size_(0), map_count_(0) { +PPB_Buffer_Impl::PPB_Buffer_Impl(PP_Instance instance) + : Resource(instance), + size_(0), + map_count_(0) { } PPB_Buffer_Impl::~PPB_Buffer_Impl() { } // static -PP_Resource PPB_Buffer_Impl::Create(PluginInstance* instance, uint32_t size) { +PP_Resource PPB_Buffer_Impl::Create(PP_Instance instance, uint32_t size) { scoped_refptr<PPB_Buffer_Impl> buffer(new PPB_Buffer_Impl(instance)); if (!buffer->Init(size)) return 0; @@ -48,11 +51,11 @@ PPB_BufferTrusted_API* PPB_Buffer_Impl::AsPPB_BufferTrusted_API() { } bool PPB_Buffer_Impl::Init(uint32_t size) { - if (size == 0 || !instance()) + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (size == 0 || !plugin_delegate) return false; size_ = size; - shared_memory_.reset( - instance()->delegate()->CreateAnonymousSharedMemory(size)); + shared_memory_.reset(plugin_delegate->CreateAnonymousSharedMemory(size)); return shared_memory_.get() != NULL; } diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h index 47a7095..2a94bbd 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.h +++ b/webkit/plugins/ppapi/ppb_buffer_impl.h @@ -10,22 +10,20 @@ #include "base/shared_memory.h" #include "ppapi/thunk/ppb_buffer_api.h" #include "ppapi/thunk/ppb_buffer_trusted_api.h" -#include "webkit/plugins/ppapi/resource.h" +#include "ppapi/shared_impl/resource.h" struct PPB_Buffer_Dev; namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_Buffer_Impl : public Resource, +class PPB_Buffer_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Buffer_API, public ::ppapi::thunk::PPB_BufferTrusted_API { public: virtual ~PPB_Buffer_Impl(); - static PP_Resource Create(PluginInstance* instance, uint32_t size); + static PP_Resource Create(PP_Instance instance, uint32_t size); virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); @@ -46,7 +44,7 @@ class PPB_Buffer_Impl : public Resource, virtual int32_t GetSharedMemory(int* handle) OVERRIDE; private: - explicit PPB_Buffer_Impl(PluginInstance* instance); + explicit PPB_Buffer_Impl(PP_Instance instance); bool Init(uint32_t size); scoped_ptr<base::SharedMemory> shared_memory_; diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.cc b/webkit/plugins/ppapi/ppb_context_3d_impl.cc index 3aa2037..544adbb 100644 --- a/webkit/plugins/ppapi/ppb_context_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_context_3d_impl.cc @@ -14,6 +14,7 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_Context3D_API; @@ -66,9 +67,8 @@ PP_Context3DTrustedState PPStateFromGPUState( } // namespace -PPB_Context3D_Impl::PPB_Context3D_Impl(PluginInstance* instance) +PPB_Context3D_Impl::PPB_Context3D_Impl(PP_Instance instance) : Resource(instance), - instance_(instance), transfer_buffer_id_(0), draw_surface_(NULL), read_surface_(NULL), @@ -80,7 +80,7 @@ PPB_Context3D_Impl::~PPB_Context3D_Impl() { } // static -PP_Resource PPB_Context3D_Impl::Create(PP_Instance pp_instance, +PP_Resource PPB_Context3D_Impl::Create(PP_Instance instance, PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { @@ -89,12 +89,7 @@ PP_Resource PPB_Context3D_Impl::Create(PP_Instance pp_instance, if (share_context != 0) return 0; - PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); - if (!instance) - return 0; - - scoped_refptr<PPB_Context3D_Impl> context( - new PPB_Context3D_Impl(instance)); + scoped_refptr<PPB_Context3D_Impl> context(new PPB_Context3D_Impl(instance)); if (!context->Init(config, share_context, attrib_list)) return 0; @@ -102,7 +97,7 @@ PP_Resource PPB_Context3D_Impl::Create(PP_Instance pp_instance, } // static -PP_Resource PPB_Context3D_Impl::CreateRaw(PP_Instance pp_instance, +PP_Resource PPB_Context3D_Impl::CreateRaw(PP_Instance instance, PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { @@ -111,12 +106,7 @@ PP_Resource PPB_Context3D_Impl::CreateRaw(PP_Instance pp_instance, if (share_context != 0) return 0; - PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); - if (!instance) - return 0; - - scoped_refptr<PPB_Context3D_Impl> context( - new PPB_Context3D_Impl(instance)); + scoped_refptr<PPB_Context3D_Impl> context(new PPB_Context3D_Impl(instance)); if (!context->InitRaw(config, share_context, attrib_list)) return 0; @@ -287,8 +277,12 @@ bool PPB_Context3D_Impl::Init(PP_Config3D_Dev config, bool PPB_Context3D_Impl::InitRaw(PP_Config3D_Dev config, PP_Resource share_context, const int32_t* attrib_list) { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + // Create and initialize the objects required to issue GLES2 calls. - platform_context_.reset(instance()->CreateContext3D()); + platform_context_.reset(plugin_instance->CreateContext3D()); if (!platform_context_.get()) { Destroy(); return false; diff --git a/webkit/plugins/ppapi/ppb_context_3d_impl.h b/webkit/plugins/ppapi/ppb_context_3d_impl.h index f1340e2..5b56482 100644 --- a/webkit/plugins/ppapi/ppb_context_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_context_3d_impl.h @@ -7,9 +7,9 @@ #include "base/memory/scoped_callback_factory.h" #include "base/memory/scoped_ptr.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_context_3d_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" struct PPB_Context3DTrusted_Dev; @@ -26,7 +26,7 @@ namespace ppapi { class PPB_Surface3D_Impl; -class PPB_Context3D_Impl : public Resource, +class PPB_Context3D_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Context3D_API { public: virtual ~PPB_Context3D_Impl(); @@ -86,7 +86,7 @@ class PPB_Context3D_Impl : public Resource, } private: - explicit PPB_Context3D_Impl(PluginInstance* instance); + explicit PPB_Context3D_Impl(PP_Instance instance); bool Init(PP_Config3D_Dev config, PP_Resource share_context, @@ -99,9 +99,6 @@ class PPB_Context3D_Impl : public Resource, void Destroy(); void OnContextLost(); - // Plugin instance this context is associated with. - PluginInstance* instance_; - // PluginDelegate's 3D Context. Responsible for providing the command buffer. // Possibly NULL. scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_; diff --git a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc index 3968dd4..6525563 100644 --- a/webkit/plugins/ppapi/ppb_cursor_control_impl.cc +++ b/webkit/plugins/ppapi/ppb_cursor_control_impl.cc @@ -13,7 +13,6 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource.h" using ::ppapi::thunk::PPB_CursorControl_FunctionAPI; diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc index f758873..38e2179 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.cc +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.cc @@ -18,6 +18,7 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/ppb_file_system_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" using ::ppapi::thunk::EnterResourceNoLock; @@ -53,7 +54,7 @@ FilePath::StringType UTF8StringToFilePathString(const std::string& str) { PPB_DirectoryReader_Impl::PPB_DirectoryReader_Impl( PPB_FileRef_Impl* directory_ref) - : Resource(directory_ref->instance()), + : Resource(directory_ref->pp_instance()), directory_ref_(directory_ref), has_more_(true), entry_(NULL) { @@ -86,11 +87,13 @@ int32_t PPB_DirectoryReader_Impl::GetNextEntry( entry_ = NULL; return PP_OK; } + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; - PluginInstance* instance = directory_ref_->instance(); - if (!instance->delegate()->ReadDirectory( + if (!plugin_instance->delegate()->ReadDirectory( directory_ref_->GetFileSystemURL(), - new FileCallbacks(instance->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, NULL, this))) return PP_ERROR_FAILED; @@ -125,7 +128,7 @@ bool PPB_DirectoryReader_Impl::FillUpEntry() { if (entry_->file_ref) ResourceTracker::Get()->ReleaseResource(entry_->file_ref); PPB_FileRef_Impl* file_ref = - new PPB_FileRef_Impl(instance(), directory_ref_->file_system(), + new PPB_FileRef_Impl(pp_instance(), directory_ref_->file_system(), FilePathStringToUTF8String(dir_entry.name)); entry_->file_ref = file_ref->GetReference(); entry_->file_type = diff --git a/webkit/plugins/ppapi/ppb_directory_reader_impl.h b/webkit/plugins/ppapi/ppb_directory_reader_impl.h index cda9800..9adfa1f 100644 --- a/webkit/plugins/ppapi/ppb_directory_reader_impl.h +++ b/webkit/plugins/ppapi/ppb_directory_reader_impl.h @@ -8,8 +8,8 @@ #include <queue> #include "base/file_util_proxy.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_directory_reader_api.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_CompletionCallback; struct PP_DirectoryEntry_Dev; @@ -21,7 +21,7 @@ namespace ppapi { class PPB_FileRef_Impl; class PPB_DirectoryReader_Impl - : public Resource, + : public ::ppapi::Resource, public ::ppapi::thunk::PPB_DirectoryReader_API { public: explicit PPB_DirectoryReader_Impl(PPB_FileRef_Impl* directory_ref); diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc index 14f4784..c9c3e08 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.cc @@ -17,14 +17,14 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" +#include "webkit/glue/webkit_glue.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource_tracker.h" -#include "webkit/glue/webkit_glue.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::StringVar; using ppapi::thunk::PPB_FileChooser_API; @@ -63,7 +63,7 @@ class FileChooserCompletionImpl : public WebFileChooserCompletion { } // namespace PPB_FileChooser_Impl::PPB_FileChooser_Impl( - PluginInstance* instance, + PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types) : Resource(instance), @@ -79,7 +79,7 @@ PPB_FileChooser_Impl::~PPB_FileChooser_Impl() { // static PP_Resource PPB_FileChooser_Impl::Create( - PluginInstance* instance, + PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types) { if (mode != PP_FILECHOOSERMODE_OPEN && @@ -110,7 +110,7 @@ void PPB_FileChooser_Impl::StoreChosenFiles( #endif chosen_files_.push_back(make_scoped_refptr( - new PPB_FileRef_Impl(instance(), file_path))); + new PPB_FileRef_Impl(pp_instance(), file_path))); } RunCallback((chosen_files_.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); @@ -133,8 +133,12 @@ void PPB_FileChooser_Impl::RegisterCallback( DCHECK(callback.func); DCHECK(!callback_.get() || callback_->completed()); - callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return; + + callback_ = new TrackedCompletionCallback(plugin_module->GetCallbackTracker(), + pp_resource(), callback); } void PPB_FileChooser_Impl::RunCallback(int32_t result) { @@ -156,8 +160,12 @@ int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { params.acceptTypes = WebString::fromUTF8(accept_mime_types_); params.directory = false; - if (!instance()->delegate()->RunFileChooser(params, - new FileChooserCompletionImpl(this))) + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + + if (!plugin_delegate->RunFileChooser(params, + new FileChooserCompletionImpl(this))) return PP_ERROR_FAILED; RegisterCallback(callback); diff --git a/webkit/plugins/ppapi/ppb_file_chooser_impl.h b/webkit/plugins/ppapi/ppb_file_chooser_impl.h index 88813d8..b8205b8 100644 --- a/webkit/plugins/ppapi/ppb_file_chooser_impl.h +++ b/webkit/plugins/ppapi/ppb_file_chooser_impl.h @@ -8,28 +8,29 @@ #include <string> #include <vector> +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" +#include "ppapi/c/dev/ppb_file_chooser_dev.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_chooser_api.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_CompletionCallback; namespace webkit { namespace ppapi { -class PluginInstance; class PPB_FileRef_Impl; class TrackedCompletionCallback; -class PPB_FileChooser_Impl : public Resource, +class PPB_FileChooser_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_FileChooser_API { public: - PPB_FileChooser_Impl(PluginInstance* instance, + PPB_FileChooser_Impl(PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types); virtual ~PPB_FileChooser_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types); diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.cc b/webkit/plugins/ppapi/ppb_file_io_impl.cc index 63021fa..faa0870 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_io_impl.cc @@ -24,6 +24,7 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/quota_file_io.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" using ppapi::PPTimeToTime; @@ -47,7 +48,7 @@ PPB_FileIO_Impl::CallbackEntry::CallbackEntry(const CallbackEntry& entry) PPB_FileIO_Impl::CallbackEntry::~CallbackEntry() { } -PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance) +PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance) : Resource(instance), ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), file_(base::kInvalidPlatformFileValue), @@ -80,10 +81,14 @@ int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref, if (!PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) return PP_ERROR_BADARGUMENT; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return false; + file_system_type_ = file_ref->GetFileSystemType(); switch (file_system_type_) { case PP_FILESYSTEMTYPE_EXTERNAL: - if (!instance()->delegate()->AsyncOpenFile( + if (!plugin_delegate->AsyncOpenFile( file_ref->GetSystemPath(), flags, callback_factory_.NewCallback( &PPB_FileIO_Impl::AsyncOpenFileCallback))) @@ -92,7 +97,7 @@ int32_t PPB_FileIO_Impl::Open(PP_Resource pp_file_ref, case PP_FILESYSTEMTYPE_LOCALPERSISTENT: case PP_FILESYSTEMTYPE_LOCALTEMPORARY: file_system_url_ = file_ref->GetFileSystemURL(); - if (!instance()->delegate()->AsyncOpenFileSystemURL( + if (!plugin_delegate->AsyncOpenFileSystemURL( file_system_url_, flags, callback_factory_.NewCallback( &PPB_FileIO_Impl::AsyncOpenFileCallback))) @@ -118,8 +123,12 @@ int32_t PPB_FileIO_Impl::Query(PP_FileInfo* info, DCHECK(!info_); // If |info_|, a callback should be pending (caught above). info_ = info; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( - instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) return PP_ERROR_FAILED; @@ -134,8 +143,12 @@ int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, if (rv != PP_OK) return rv; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (!base::FileUtilProxy::Touch( - instance()->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) @@ -153,8 +166,12 @@ int32_t PPB_FileIO_Impl::Read(int64_t offset, if (rv != PP_OK) return rv; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (!base::FileUtilProxy::Read( - instance()->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, bytes_to_read, callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadCallback))) return PP_ERROR_FAILED; @@ -171,6 +188,10 @@ int32_t PPB_FileIO_Impl::Write(int64_t offset, if (rv != PP_OK) return rv; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (quota_file_io_.get()) { if (!quota_file_io_->Write( offset, buffer, bytes_to_write, @@ -178,7 +199,7 @@ int32_t PPB_FileIO_Impl::Write(int64_t offset, return PP_ERROR_FAILED; } else { if (!base::FileUtilProxy::Write( - instance()->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, buffer, bytes_to_write, callback_factory_.NewCallback(&PPB_FileIO_Impl::WriteCallback))) return PP_ERROR_FAILED; @@ -194,6 +215,10 @@ int32_t PPB_FileIO_Impl::SetLength(int64_t length, if (rv != PP_OK) return rv; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (quota_file_io_.get()) { if (!quota_file_io_->SetLength( length, @@ -201,7 +226,7 @@ int32_t PPB_FileIO_Impl::SetLength(int64_t length, return PP_ERROR_FAILED; } else { if (!base::FileUtilProxy::Truncate( - instance()->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, length, callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) return PP_ERROR_FAILED; @@ -216,8 +241,12 @@ int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { if (rv != PP_OK) return rv; + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return PP_ERROR_FAILED; + if (!base::FileUtilProxy::Flush( - instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) return PP_ERROR_FAILED; @@ -226,9 +255,10 @@ int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { } void PPB_FileIO_Impl::Close() { - if (file_ != base::kInvalidPlatformFileValue) { + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (file_ != base::kInvalidPlatformFileValue && plugin_delegate) { base::FileUtilProxy::Close( - instance()->delegate()->GetFileThreadMessageLoopProxy(), file_, NULL); + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, NULL); file_ = base::kInvalidPlatformFileValue; quota_file_io_.reset(); } @@ -313,9 +343,13 @@ void PPB_FileIO_Impl::RegisterCallback(OperationType op, DCHECK(pending_op_ == OPERATION_NONE || (pending_op_ != OPERATION_EXCLUSIVE && pending_op_ == op)); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return; + CallbackEntry entry; entry.callback = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); entry.read_buffer = read_buffer; callbacks_.push(entry); @@ -358,7 +392,7 @@ void PPB_FileIO_Impl::AsyncOpenFileCallback( (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY || file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) { quota_file_io_.reset(new QuotaFileIO( - instance(), file_, file_system_url_, file_system_type_)); + pp_instance(), file_, file_system_url_, file_system_type_)); } RunAndRemoveFirstPendingCallback(PlatformFileErrorToPepperError(error_code)); diff --git a/webkit/plugins/ppapi/ppb_file_io_impl.h b/webkit/plugins/ppapi/ppb_file_io_impl.h index 2426387..5da3aeb 100644 --- a/webkit/plugins/ppapi/ppb_file_io_impl.h +++ b/webkit/plugins/ppapi/ppb_file_io_impl.h @@ -15,10 +15,10 @@ #include "base/platform_file.h" #include "ppapi/c/pp_file_info.h" #include "ppapi/c/pp_time.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_io_api.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_CompletionCallback; struct PPB_FileIO; @@ -31,10 +31,10 @@ class PluginModule; class PPB_FileRef_Impl; class QuotaFileIO; -class PPB_FileIO_Impl : public Resource, +class PPB_FileIO_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_FileIO_API { public: - explicit PPB_FileIO_Impl(PluginInstance* instance); + explicit PPB_FileIO_Impl(PP_Instance instance); virtual ~PPB_FileIO_Impl(); // Resource overrides. diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc index 1a1e397..b4c108f 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc @@ -19,6 +19,7 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" #include "webkit/plugins/ppapi/ppb_file_system_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::PPTimeToTime; using ppapi::StringVar; @@ -58,7 +59,7 @@ PPB_FileRef_Impl::PPB_FileRef_Impl() } PPB_FileRef_Impl::PPB_FileRef_Impl( - PluginInstance* instance, + PP_Instance instance, scoped_refptr<PPB_FileSystem_Impl> file_system, const std::string& validated_path) : Resource(instance), @@ -66,7 +67,7 @@ PPB_FileRef_Impl::PPB_FileRef_Impl( virtual_path_(validated_path) { } -PPB_FileRef_Impl::PPB_FileRef_Impl(PluginInstance* instance, +PPB_FileRef_Impl::PPB_FileRef_Impl(PP_Instance instance, const FilePath& external_file_path) : Resource(instance), file_system_(NULL), @@ -85,7 +86,7 @@ PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, PPB_FileSystem_Impl* file_system = static_cast<PPB_FileSystem_Impl*>(enter.object()); - if (!file_system->instance()) + if (!file_system->pp_instance()) return 0; if (file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && @@ -97,7 +98,7 @@ PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, return 0; TrimTrailingSlash(&validated_path); - return (new PPB_FileRef_Impl(file_system->instance(), + return (new PPB_FileRef_Impl(file_system->pp_instance(), file_system, validated_path))->GetReference(); } @@ -139,14 +140,19 @@ PP_Var PPB_FileRef_Impl::GetName() const { result = virtual_path_.substr(pos + 1); } - return StringVar::StringToPPVar(instance()->module()->pp_module(), result); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(plugin_module->pp_module(), result); } PP_Var PPB_FileRef_Impl::GetPath() const { if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) return PP_MakeUndefined(); - return StringVar::StringToPPVar(instance()->module()->pp_module(), - virtual_path_); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(plugin_module->pp_module(), virtual_path_); } PP_Resource PPB_FileRef_Impl::GetParent() { @@ -163,7 +169,7 @@ PP_Resource PPB_FileRef_Impl::GetParent() { std::string parent_path = virtual_path_.substr(0, pos); scoped_refptr<PPB_FileRef_Impl> parent_ref( - new PPB_FileRef_Impl(instance(), file_system_, parent_path)); + new PPB_FileRef_Impl(pp_instance(), file_system_, parent_path)); return parent_ref->GetReference(); } @@ -171,9 +177,13 @@ int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, PP_CompletionCallback callback) { if (!IsValidNonExternalFileSystem()) return PP_ERROR_NOACCESS; - if (!instance()->delegate()->MakeDirectory( + + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + if (!plugin_instance->delegate()->MakeDirectory( GetFileSystemURL(), PP_ToBool(make_ancestors), - new FileCallbacks(instance()->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; @@ -184,11 +194,14 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, PP_CompletionCallback callback) { if (!IsValidNonExternalFileSystem()) return PP_ERROR_NOACCESS; - if (!instance()->delegate()->Touch( + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + if (!plugin_instance->delegate()->Touch( GetFileSystemURL(), PPTimeToTime(last_access_time), PPTimeToTime(last_modified_time), - new FileCallbacks(instance()->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; @@ -197,9 +210,12 @@ int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { if (!IsValidNonExternalFileSystem()) return PP_ERROR_NOACCESS; - if (!instance()->delegate()->Delete( + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + if (!plugin_instance->delegate()->Delete( GetFileSystemURL(), - new FileCallbacks(instance()->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; @@ -219,9 +235,12 @@ int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, // TODO(viettrungluu): Also cancel when the new file ref is destroyed? // http://crbug.com/67624 - if (!instance()->delegate()->Rename( + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + if (!plugin_instance->delegate()->Rename( GetFileSystemURL(), new_file_ref->GetFileSystemURL(), - new FileCallbacks(instance()->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, NULL, NULL))) return PP_ERROR_FAILED; return PP_OK_COMPLETIONPENDING; diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.h b/webkit/plugins/ppapi/ppb_file_ref_impl.h index 7823c50..1bd264c 100644 --- a/webkit/plugins/ppapi/ppb_file_ref_impl.h +++ b/webkit/plugins/ppapi/ppb_file_ref_impl.h @@ -10,24 +10,24 @@ #include "base/file_path.h" #include "googleurl/src/gurl.h" #include "ppapi/c/ppb_file_ref.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_ref_api.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { class PPB_FileSystem_Impl; -class PluginInstance; +class PluginDelegate; class PluginModule; -class PPB_FileRef_Impl : public Resource, +class PPB_FileRef_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_FileRef_API { public: PPB_FileRef_Impl(); - PPB_FileRef_Impl(PluginInstance* instance, + PPB_FileRef_Impl(PP_Instance instance, scoped_refptr<PPB_FileSystem_Impl> file_system, const std::string& validated_path); - PPB_FileRef_Impl(PluginInstance* instance, + PPB_FileRef_Impl(PP_Instance instance, const FilePath& external_file_path); virtual ~PPB_FileRef_Impl(); diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.cc b/webkit/plugins/ppapi/ppb_file_system_impl.cc index 2a4bb05..ac9f900 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.cc +++ b/webkit/plugins/ppapi/ppb_file_system_impl.cc @@ -18,18 +18,16 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" -#include "webkit/plugins/ppapi/resource.h" -#include "webkit/plugins/ppapi/resource_tracker.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::PPB_FileSystem_API; namespace webkit { namespace ppapi { -PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, +PPB_FileSystem_Impl::PPB_FileSystem_Impl(PP_Instance instance, PP_FileSystemType type) : Resource(instance), - instance_(instance), type_(type), opened_(false), called_open_(false) { @@ -40,7 +38,7 @@ PPB_FileSystem_Impl::~PPB_FileSystem_Impl() { } // static -PP_Resource PPB_FileSystem_Impl::Create(PluginInstance* instance, +PP_Resource PPB_FileSystem_Impl::Create(PP_Instance instance, PP_FileSystemType type) { if (type != PP_FILESYSTEMTYPE_EXTERNAL && type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && @@ -64,14 +62,18 @@ int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, type_ != PP_FILESYSTEMTYPE_LOCALTEMPORARY) return PP_ERROR_FAILED; + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return PP_ERROR_FAILED; + fileapi::FileSystemType file_system_type = (type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ? fileapi::kFileSystemTypeTemporary : fileapi::kFileSystemTypePersistent); - if (!instance()->delegate()->OpenFileSystem( - instance()->container()->element().document().url(), + if (!plugin_instance->delegate()->OpenFileSystem( + plugin_instance->container()->element().document().url(), file_system_type, expected_size, - new FileCallbacks(instance()->module()->AsWeakPtr(), + new FileCallbacks(plugin_instance->module()->AsWeakPtr(), pp_resource(), callback, NULL, scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) return PP_ERROR_FAILED; diff --git a/webkit/plugins/ppapi/ppb_file_system_impl.h b/webkit/plugins/ppapi/ppb_file_system_impl.h index 66b5ff2..0f41561 100644 --- a/webkit/plugins/ppapi/ppb_file_system_impl.h +++ b/webkit/plugins/ppapi/ppb_file_system_impl.h @@ -9,29 +9,24 @@ #include "base/compiler_specific.h" #include "googleurl/src/gurl.h" #include "ppapi/c/pp_file_info.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_file_system_api.h" -#include "webkit/plugins/ppapi/resource.h" struct PPB_FileSystem; namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_FileSystem_Impl : public Resource, +class PPB_FileSystem_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_FileSystem_API { public: - PPB_FileSystem_Impl(PluginInstance* instance, PP_FileSystemType type); virtual ~PPB_FileSystem_Impl(); - static PP_Resource Create(PluginInstance* instance, - PP_FileSystemType type); + static PP_Resource Create(PP_Instance instance, PP_FileSystemType type); // Resource overrides. virtual ::ppapi::thunk::PPB_FileSystem_API* AsPPB_FileSystem_API() OVERRIDE; - PluginInstance* instance() { return instance_; } PP_FileSystemType type() const { return type_; } const GURL& root_url() const { return root_url_; } void set_root_url(const GURL& root_url) { root_url_ = root_url; } @@ -44,7 +39,8 @@ class PPB_FileSystem_Impl : public Resource, virtual PP_FileSystemType GetType() OVERRIDE; private: - PluginInstance* instance_; + PPB_FileSystem_Impl(PP_Instance instance, PP_FileSystemType type); + PP_FileSystemType type_; GURL root_url_; bool opened_; diff --git a/webkit/plugins/ppapi/ppb_flash_file_impl.cc b/webkit/plugins/ppapi/ppb_flash_file_impl.cc index 9a1ac5a..de8b939 100644 --- a/webkit/plugins/ppapi/ppb_flash_file_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_file_impl.cc @@ -20,6 +20,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" #if defined(OS_WIN) @@ -225,7 +226,7 @@ int32_t OpenFileRefFile(PP_Resource file_ref_id, return PP_ERROR_BADRESOURCE; PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); - PluginInstance* instance = file_ref->instance(); + PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); if (!instance) return PP_ERROR_FAILED; @@ -245,7 +246,7 @@ int32_t QueryFileRefFile(PP_Resource file_ref_id, return PP_ERROR_BADRESOURCE; PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); - PluginInstance* instance = file_ref->instance(); + PluginInstance* instance = ResourceHelper::GetPluginInstance(file_ref); if (!instance) return PP_ERROR_FAILED; diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index b38932d..58354db 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -18,6 +18,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" using ppapi::PPTimeToTime; @@ -64,11 +65,10 @@ int32_t Navigate(PP_Resource request_id, if (!target) return PP_ERROR_BADARGUMENT; - PluginInstance* instance = request->instance(); - if (!instance) + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(request); + if (!plugin_instance) return PP_ERROR_FAILED; - - return instance->Navigate(request, target, from_user_action); + return plugin_instance->Navigate(request, target, from_user_action); } void RunMessageLoop(PP_Instance instance) { diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc index 80faa25..2d64e8b 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc @@ -12,6 +12,7 @@ #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ::ppapi::thunk::PPB_Flash_Menu_API; @@ -94,7 +95,7 @@ bool ConvertMenuData(const PP_Flash_Menu* in_menu, } // namespace -PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PluginInstance* instance) +PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PP_Instance instance) : Resource(instance) { } @@ -102,7 +103,7 @@ PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { } // static -PP_Resource PPB_Flash_Menu_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Flash_Menu_Impl::Create(PP_Instance instance, const PP_Flash_Menu* menu_data) { scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); if (!menu->Init(menu_data)) @@ -141,12 +142,17 @@ int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - int32_t rv = instance()->delegate()->ShowContextMenu( - instance(), this, gfx::Point(location->x, location->y)); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + + int32_t rv = plugin_instance->delegate()->ShowContextMenu( + plugin_instance, this, gfx::Point(location->x, location->y)); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_instance->module()->GetCallbackTracker(), + pp_resource(), callback); selected_id_out_ = selected_id_out; } else { // This should never be completed synchronously successfully. diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.h b/webkit/plugins/ppapi/ppb_flash_menu_impl.h index 9c6c6fb..fc0b99d 100644 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_menu_impl.h @@ -12,21 +12,21 @@ #include "base/memory/ref_counted.h" #include "ppapi/c/pp_point.h" #include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_flash_menu_api.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/resource.h" struct WebMenuItem; namespace webkit { namespace ppapi { -class PPB_Flash_Menu_Impl : public Resource, +class PPB_Flash_Menu_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Flash_Menu_API { public: virtual ~PPB_Flash_Menu_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, const PP_Flash_Menu* menu_data); // Resource. @@ -44,7 +44,7 @@ class PPB_Flash_Menu_Impl : public Resource, const MenuData& menu_data() const { return menu_data_; } private: - explicit PPB_Flash_Menu_Impl(PluginInstance* instance); + explicit PPB_Flash_Menu_Impl(PP_Instance instance); bool Init(const PP_Flash_Menu* menu_data); diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc index 820c3db..e22cccf 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.cc @@ -10,14 +10,14 @@ #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ::ppapi::thunk::PPB_Flash_NetConnector_API; namespace webkit { namespace ppapi { -PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl( - PluginInstance* instance) +PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl(PP_Instance instance) : Resource(instance) { } @@ -48,11 +48,15 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - int32_t rv = instance()->delegate()->ConnectTcp(this, host, port); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + int32_t rv = plugin_instance->delegate()->ConnectTcp(this, host, port); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_instance->module()->GetCallbackTracker(), + pp_resource(), callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; @@ -81,11 +85,15 @@ int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress( if (callback_.get() && !callback_->completed()) return PP_ERROR_INPROGRESS; - int32_t rv = instance()->delegate()->ConnectTcpAddress(this, addr); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + int32_t rv = plugin_instance->delegate()->ConnectTcpAddress(this, addr); if (rv == PP_OK_COMPLETIONPENDING) { // Record callback and output buffers. callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_instance->module()->GetCallbackTracker(), + pp_resource(), callback); socket_out_ = socket_out; local_addr_out_ = local_addr_out; remote_addr_out_ = remote_addr_out; diff --git a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h index 3e90347..b1e04df 100644 --- a/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_net_connector_impl.h @@ -6,20 +6,21 @@ #define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_NET_CONNECTOR_IMPL_H_ #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "ppapi/c/private/ppb_flash_net_connector.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_flash_net_connector_api.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { class PPB_Flash_NetConnector_Impl - : public Resource, + : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Flash_NetConnector_API { public: - explicit PPB_Flash_NetConnector_Impl(PluginInstance* instance); + explicit PPB_Flash_NetConnector_Impl(PP_Instance instance); virtual ~PPB_Flash_NetConnector_Impl(); // Resource override. diff --git a/webkit/plugins/ppapi/ppb_font_impl.cc b/webkit/plugins/ppapi/ppb_font_impl.cc index 8db4ed6..a714e03 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.cc +++ b/webkit/plugins/ppapi/ppb_font_impl.cc @@ -14,6 +14,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/string.h" using ppapi::StringVar; @@ -42,15 +43,18 @@ bool PPTextRunToTextRun(const PP_TextRun_Dev* run, } // namespace -PPB_Font_Impl::PPB_Font_Impl(PluginInstance* instance, +PPB_Font_Impl::PPB_Font_Impl(PP_Instance pp_instance, const PP_FontDescription_Dev& desc) - : Resource(instance) { + : Resource(pp_instance) { StringVar* face_name = StringVar::FromPPVar(desc.face); WebKitForwarding::Font* result = NULL; - instance->module()->GetWebKitForwarding()->CreateFontForwarding( - NULL, desc, face_name ? face_name->value() : std::string(), - instance->delegate()->GetPreferences(), &result); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (plugin_instance) { + plugin_instance->module()->GetWebKitForwarding()->CreateFontForwarding( + NULL, desc, face_name ? face_name->value() : std::string(), + plugin_instance->delegate()->GetPreferences(), &result); + } font_forwarding_.reset(result); } @@ -58,7 +62,7 @@ PPB_Font_Impl::~PPB_Font_Impl() { } // static -PP_Resource PPB_Font_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Font_Impl::Create(PP_Instance instance, const PP_FontDescription_Dev& description) { if (!::ppapi::FontImpl::IsPPFontDescriptionValid(description)) return 0; @@ -77,9 +81,13 @@ PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, if (!result) return PP_FALSE; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_FALSE; + // Convert the string. - description->face = StringVar::StringToPPVar( - instance()->module()->pp_module(), face); + description->face = StringVar::StringToPPVar(plugin_module->pp_module(), + face); return PP_TRUE; } diff --git a/webkit/plugins/ppapi/ppb_font_impl.h b/webkit/plugins/ppapi/ppb_font_impl.h index fce96be..9e89c9e 100644 --- a/webkit/plugins/ppapi/ppb_font_impl.h +++ b/webkit/plugins/ppapi/ppb_font_impl.h @@ -8,9 +8,10 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/shared_impl/function_group_base.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/webkit_forwarding.h" #include "ppapi/thunk/ppb_font_api.h" -#include "webkit/plugins/ppapi/resource.h" namespace WebKit { class WebFont; @@ -21,12 +22,12 @@ namespace ppapi { class PluginInstance; -class PPB_Font_Impl : public Resource, +class PPB_Font_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Font_API { public: virtual ~PPB_Font_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, const PP_FontDescription_Dev& description); // Resource. @@ -48,7 +49,7 @@ class PPB_Font_Impl : public Resource, uint32_t char_offset) OVERRIDE; private: - PPB_Font_Impl(PluginInstance* instance, const PP_FontDescription_Dev& desc); + PPB_Font_Impl(PP_Instance instance, const PP_FontDescription_Dev& desc); scoped_ptr< ::ppapi::WebKitForwarding::Font> font_forwarding_; diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc index d32dc46..3a75e99 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc @@ -23,6 +23,7 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -150,7 +151,7 @@ struct PPB_Graphics2D_Impl::QueuedOperation { scoped_refptr<PPB_ImageData_Impl> replace_image; }; -PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PluginInstance* instance) +PPB_Graphics2D_Impl::PPB_Graphics2D_Impl(PP_Instance instance) : Resource(instance), bound_instance_(NULL), offscreen_flush_pending_(false), @@ -161,7 +162,7 @@ PPB_Graphics2D_Impl::~PPB_Graphics2D_Impl() { } // static -PP_Resource PPB_Graphics2D_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Graphics2D_Impl::Create(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque) { scoped_refptr<PPB_Graphics2D_Impl> graphics_2d( @@ -175,7 +176,7 @@ PP_Resource PPB_Graphics2D_Impl::Create(PluginInstance* instance, bool PPB_Graphics2D_Impl::Init(int width, int height, bool is_always_opaque) { // The underlying PPB_ImageData_Impl will validate the dimensions. - image_data_ = new PPB_ImageData_Impl(instance()); + image_data_ = new PPB_ImageData_Impl(pp_instance()); if (!image_data_->Init(PPB_ImageData_Impl::GetNativeImageDataFormat(), width, height, true) || !image_data_->Map()) { @@ -488,7 +489,10 @@ void PPB_Graphics2D_Impl::Paint(WebKit::WebCanvas* canvas, canvas->save(); canvas->clipRect(sk_plugin_rect); - if (instance()->IsFullPagePlugin()) { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return; + if (plugin_instance->IsFullPagePlugin()) { // When we're resizing a window with a full-frame plugin, the plugin may // not yet have bound a new device, which will leave parts of the // background exposed if the window is getting larger. We want this to diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h index 2c96584..fc36f18 100644 --- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.h +++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.h @@ -10,9 +10,9 @@ #include "base/basictypes.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/ppb_graphics_2d.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_graphics_2d_api.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCanvas.h" -#include "webkit/plugins/ppapi/resource.h" struct PPB_Graphics2D; @@ -27,13 +27,12 @@ class PPB_ImageData_Impl; class PluginInstance; class PluginModule; -class PPB_Graphics2D_Impl - : public Resource, - public ::ppapi::thunk::PPB_Graphics2D_API { +class PPB_Graphics2D_Impl : public ::ppapi::Resource, + public ::ppapi::thunk::PPB_Graphics2D_API { public: virtual ~PPB_Graphics2D_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque); @@ -75,7 +74,7 @@ class PPB_Graphics2D_Impl PPB_ImageData_Impl* image_data() { return image_data_.get(); } private: - explicit PPB_Graphics2D_Impl(PluginInstance* instance); + explicit PPB_Graphics2D_Impl(PP_Instance instance); bool Init(int width, int height, bool is_always_opaque); diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc index 470fbf5..8283e32 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.cc @@ -8,6 +8,7 @@ #include "gpu/command_buffer/client/gles2_implementation.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::PPB_Graphics3D_API; @@ -49,7 +50,7 @@ PP_Graphics3DTrustedState PPStateFromGPUState( } } // namespace. -PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginInstance* instance) +PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PP_Instance instance) : Resource(instance), bound_to_instance_(false), commit_pending_(false), @@ -61,7 +62,7 @@ PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { } // static -PP_Resource PPB_Graphics3D_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list) { scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( @@ -71,7 +72,7 @@ PP_Resource PPB_Graphics3D_Impl::Create(PluginInstance* instance, return graphics_3d->GetReference(); } -PP_Resource PPB_Graphics3D_Impl::CreateRaw(PluginInstance* instance, +PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list) { scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( @@ -180,12 +181,16 @@ bool PPB_Graphics3D_Impl::Init(PP_Resource share_context, bool PPB_Graphics3D_Impl::InitRaw(PP_Resource share_context, const int32_t* attrib_list) { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + // TODO(alokp): Support shared context. DCHECK_EQ(0, share_context); if (share_context != 0) - return 0; + return false; - platform_context_.reset(instance()->CreateContext3D()); + platform_context_.reset(plugin_instance->CreateContext3D()); if (!platform_context_.get()) return false; @@ -205,7 +210,10 @@ void PPB_Graphics3D_Impl::OnSwapBuffers() { // to commit our backing texture so that the graphics appears on the page. // When the backing texture will be committed we get notified via // ViewFlushedPaint(). - instance()->CommitBackingTexture(); + // + // Don't need to check for NULL from GetPluginInstance since when we're + // bound, we know our instance is valid. + ResourceHelper::GetPluginInstance(this)->CommitBackingTexture(); commit_pending_ = true; } else if (HasPendingSwap()) { // If we're off-screen, no need to trigger and wait for compositing. @@ -216,8 +224,10 @@ void PPB_Graphics3D_Impl::OnSwapBuffers() { } void PPB_Graphics3D_Impl::OnContextLost() { + // Don't need to check for NULL from GetPluginInstance since when we're + // bound, we know our instance is valid. if (bound_to_instance_) - instance()->BindGraphics(instance()->pp_instance(), 0); + ResourceHelper::GetPluginInstance(this)->BindGraphics(pp_instance(), 0); // Send context lost to plugin. This may have been caused by a PPAPI call, so // avoid re-entering. @@ -229,15 +239,16 @@ void PPB_Graphics3D_Impl::SendContextLost() { // By the time we run this, the instance may have been deleted, or in the // process of being deleted. Even in the latter case, we don't want to send a // callback after DidDestroy. - if (!instance() || !instance()->container()) + PluginInstance* instance = ResourceHelper::GetPluginInstance(this); + if (!instance || !instance->container()) return; const PPP_Graphics3D_Dev* ppp_graphics_3d = static_cast<const PPP_Graphics3D_Dev*>( - instance()->module()->GetPluginInterface( + instance->module()->GetPluginInterface( PPP_GRAPHICS_3D_DEV_INTERFACE)); if (ppp_graphics_3d) - ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); + ppp_graphics_3d->Graphics3DContextLost(pp_instance()); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h index 9bcc1c7..52b72c5 100644 --- a/webkit/plugins/ppapi/ppb_graphics_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_graphics_3d_impl.h @@ -7,21 +7,21 @@ #include "base/memory/scoped_callback_factory.h" #include "ppapi/shared_impl/graphics_3d_impl.h" +#include "ppapi/shared_impl/resource.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { -class PPB_Graphics3D_Impl : public Resource, +class PPB_Graphics3D_Impl : public ::ppapi::Resource, public ::ppapi::Graphics3DImpl { public: virtual ~PPB_Graphics3D_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list); - static PP_Resource CreateRaw(PluginInstance* instance, + static PP_Resource CreateRaw(PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list); @@ -63,7 +63,7 @@ class PPB_Graphics3D_Impl : public Resource, virtual int32 DoSwapBuffers() OVERRIDE; private: - explicit PPB_Graphics3D_Impl(PluginInstance* instance); + explicit PPB_Graphics3D_Impl(PP_Instance instance); bool Init(PP_Resource share_context, const int32_t* attrib_list); diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.cc b/webkit/plugins/ppapi/ppb_image_data_impl.cc index d565add..6563713 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.cc +++ b/webkit/plugins/ppapi/ppb_image_data_impl.cc @@ -18,13 +18,14 @@ #include "third_party/skia/include/core/SkColorPriv.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ::ppapi::thunk::PPB_ImageData_API; namespace webkit { namespace ppapi { -PPB_ImageData_Impl::PPB_ImageData_Impl(PluginInstance* instance) +PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance) : Resource(instance), format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), width_(0), @@ -35,7 +36,7 @@ PPB_ImageData_Impl::~PPB_ImageData_Impl() { } // static -PP_Resource PPB_ImageData_Impl::Create(PluginInstance* instance, +PP_Resource PPB_ImageData_Impl::Create(PP_Instance instance, PP_ImageDataFormat format, const PP_Size& size, PP_Bool init_to_zero) { @@ -62,8 +63,11 @@ bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, std::numeric_limits<int32>::max()) return false; // Prevent overflow of signed 32-bit ints. - platform_image_.reset( - instance()->delegate()->CreateImage2D(width, height)); + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return false; + + platform_image_.reset(plugin_delegate->CreateImage2D(width, height)); format_ = format; width_ = width; height_ = height; diff --git a/webkit/plugins/ppapi/ppb_image_data_impl.h b/webkit/plugins/ppapi/ppb_image_data_impl.h index d96de31..bc7770a 100644 --- a/webkit/plugins/ppapi/ppb_image_data_impl.h +++ b/webkit/plugins/ppapi/ppb_image_data_impl.h @@ -9,9 +9,9 @@ #include "base/memory/scoped_ptr.h" #include "ppapi/c/ppb_image_data.h" #include "ppapi/shared_impl/image_data_impl.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_image_data_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" namespace skia { class PlatformCanvas; @@ -23,17 +23,17 @@ class SkBitmap; namespace webkit { namespace ppapi { -class PPB_ImageData_Impl : public Resource, +class PPB_ImageData_Impl : public ::ppapi::Resource, public ::ppapi::ImageDataImpl, public ::ppapi::thunk::PPB_ImageData_API { public: // If you call this constructor, you must also call Init before use. Normally // you should use the static Create function, but this constructor is needed // for some internal uses of ImageData (like Graphics2D). - explicit PPB_ImageData_Impl(PluginInstance* instance); + explicit PPB_ImageData_Impl(PP_Instance instance); virtual ~PPB_ImageData_Impl(); - static PP_Resource Create(PluginInstance* pp_instance, + static PP_Resource Create(PP_Instance pp_instance, PP_ImageDataFormat format, const PP_Size& size, PP_Bool init_to_zero); diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.cc b/webkit/plugins/ppapi/ppb_input_event_impl.cc index f2383b0..b0e6100 100644 --- a/webkit/plugins/ppapi/ppb_input_event_impl.cc +++ b/webkit/plugins/ppapi/ppb_input_event_impl.cc @@ -7,6 +7,7 @@ #include "ppapi/shared_impl/var.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::InputEventData; using ppapi::InputEventImpl; @@ -16,24 +17,21 @@ using ppapi::thunk::PPB_InputEvent_API; namespace webkit { namespace ppapi { -PPB_InputEvent_Impl::PPB_InputEvent_Impl(PluginInstance* instance, +PPB_InputEvent_Impl::PPB_InputEvent_Impl(PP_Instance instance, const InputEventData& data) : Resource(instance), InputEventImpl(data) { } -// static -PP_Resource PPB_InputEvent_Impl::Create(PluginInstance* instance, - const InputEventData& data) { - return (new PPB_InputEvent_Impl(instance, data))->GetReference(); -} - PPB_InputEvent_API* PPB_InputEvent_Impl::AsPPB_InputEvent_API() { return this; } PP_Var PPB_InputEvent_Impl::StringToPPVar(const std::string& str) { - return StringVar::StringToPPVar(instance()->module()->pp_module(), str); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_MakeUndefined(); + return StringVar::StringToPPVar(plugin_module->pp_module(), str); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_input_event_impl.h b/webkit/plugins/ppapi/ppb_input_event_impl.h index 48bc3fb..e678758 100644 --- a/webkit/plugins/ppapi/ppb_input_event_impl.h +++ b/webkit/plugins/ppapi/ppb_input_event_impl.h @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "ppapi/shared_impl/input_event_impl.h" -#include "webkit/plugins/ppapi/resource.h" +#include "ppapi/shared_impl/resource.h" namespace ppapi { struct InputEventData; @@ -12,15 +12,12 @@ struct InputEventData; namespace webkit { namespace ppapi { -class PPB_InputEvent_Impl : public Resource, +class PPB_InputEvent_Impl : public ::ppapi::Resource, public ::ppapi::InputEventImpl { public: - PPB_InputEvent_Impl(PluginInstance* instance, + PPB_InputEvent_Impl(PP_Instance instance, const ::ppapi::InputEventData& data); - static PP_Resource Create(PluginInstance* instance, - const ::ppapi::InputEventData& data); - // Resource overrides. virtual ::ppapi::thunk::PPB_InputEvent_API* AsPPB_InputEvent_API() OVERRIDE; diff --git a/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc b/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc index c8188ce..43b5dc0 100644 --- a/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc +++ b/webkit/plugins/ppapi/ppb_layer_compositor_impl.cc @@ -12,7 +12,7 @@ using ppapi::thunk::PPB_LayerCompositor_API; namespace webkit { namespace ppapi { -PPB_LayerCompositor_Impl::PPB_LayerCompositor_Impl(PluginInstance* instance) +PPB_LayerCompositor_Impl::PPB_LayerCompositor_Impl(PP_Instance instance) : Resource(instance) { } diff --git a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h b/webkit/plugins/ppapi/ppb_layer_compositor_impl.h index b35264f..d4f1838 100644 --- a/webkit/plugins/ppapi/ppb_layer_compositor_impl.h +++ b/webkit/plugins/ppapi/ppb_layer_compositor_impl.h @@ -5,8 +5,9 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_LAYER_COMPOSITOR_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_LAYER_COMPOSITOR_IMPL_H_ +#include "base/compiler_specific.h" #include "ppapi/thunk/ppb_layer_compositor_api.h" -#include "webkit/plugins/ppapi/resource.h" +#include "ppapi/shared_impl/resource.h" struct PP_Rect; struct PP_Size; @@ -14,13 +15,11 @@ struct PP_Size; namespace webkit { namespace ppapi { -class PluginInstance; - class PPB_LayerCompositor_Impl - : public Resource, + : public ::ppapi::Resource, public ::ppapi::thunk::PPB_LayerCompositor_API { public: - explicit PPB_LayerCompositor_Impl(PluginInstance* instance); + explicit PPB_LayerCompositor_Impl(PP_Instance instance); virtual ~PPB_LayerCompositor_Impl(); static const PPB_LayerCompositor_Dev* GetInterface(); diff --git a/webkit/plugins/ppapi/ppb_proxy_impl.cc b/webkit/plugins/ppapi/ppb_proxy_impl.cc index 630e1e0..b36a994 100644 --- a/webkit/plugins/ppapi/ppb_proxy_impl.cc +++ b/webkit/plugins/ppapi/ppb_proxy_impl.cc @@ -10,7 +10,6 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" -#include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_tracker.h" using ppapi::thunk::EnterResource; diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc index 3407ba7..8d33358 100644 --- a/webkit/plugins/ppapi/ppb_scrollbar_impl.cc +++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.cc @@ -18,6 +18,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/glue/webkit_glue.h" #if defined(OS_WIN) @@ -108,7 +109,7 @@ const PPB_Scrollbar_0_4_Dev ppb_scrollbar_0_4 = { } // namespace // static -PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Scrollbar_Impl::Create(PP_Instance instance, bool vertical) { scoped_refptr<PPB_Scrollbar_Impl> scrollbar( new PPB_Scrollbar_Impl(instance)); @@ -116,7 +117,7 @@ PP_Resource PPB_Scrollbar_Impl::Create(PluginInstance* instance, return scrollbar->GetReference(); } -PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PluginInstance* instance) +PPB_Scrollbar_Impl::PPB_Scrollbar_Impl(PP_Instance instance) : PPB_Widget_Impl(instance), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { } @@ -125,9 +126,12 @@ PPB_Scrollbar_Impl::~PPB_Scrollbar_Impl() { } void PPB_Scrollbar_Impl::Init(bool vertical) { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return; scrollbar_.reset(WebScrollbar::createForPlugin( vertical ? WebScrollbar::Vertical : WebScrollbar::Horizontal, - instance()->container(), + ResourceHelper::GetPluginInstance(this)->container(), static_cast<WebKit::WebScrollbarClient*>(this))); } @@ -135,6 +139,11 @@ PPB_Scrollbar_API* PPB_Scrollbar_Impl::AsPPB_Scrollbar_API() { return this; } +void PPB_Scrollbar_Impl::InstanceWasDeleted() { + Resource::LastPluginRefWasDeleted(); + scrollbar_.reset(); +} + // static const PPB_Scrollbar_0_3_Dev* PPB_Scrollbar_Impl::Get0_3Interface() { return &ppb_scrollbar_0_3; @@ -158,15 +167,19 @@ uint32_t PPB_Scrollbar_Impl::GetValue() { } void PPB_Scrollbar_Impl::SetValue(uint32_t value) { - scrollbar_->setValue(value); + if (scrollbar_.get()) + scrollbar_->setValue(value); } void PPB_Scrollbar_Impl::SetDocumentSize(uint32_t size) { - scrollbar_->setDocumentSize(size); + if (scrollbar_.get()) + scrollbar_->setDocumentSize(size); } void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, uint32_t count) { + if (!scrollbar_.get()) + return; tickmarks_.resize(count); for (uint32 i = 0; i < count; ++i) { tickmarks_[i] = WebRect(tick_marks[i].point.x, @@ -179,6 +192,9 @@ void PPB_Scrollbar_Impl::SetTickMarks(const PP_Rect* tick_marks, } void PPB_Scrollbar_Impl::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { + if (!scrollbar_.get()) + return; + WebScrollbar::ScrollDirection direction = multiplier >= 0 ? WebScrollbar::ScrollForward : WebScrollbar::ScrollBackward; float fmultiplier = 1.0; @@ -203,7 +219,7 @@ PP_Bool PPB_Scrollbar_Impl::PaintInternal(const gfx::Rect& rect, PPB_ImageData_Impl* image) { ImageDataAutoMapper mapper(image); skia::PlatformCanvas* canvas = image->mapped_canvas(); - if (!canvas) + if (!canvas || !scrollbar_.get()) return PP_FALSE; scrollbar_->paint(webkit_glue::ToWebCanvas(canvas), rect); @@ -218,13 +234,15 @@ PP_Bool PPB_Scrollbar_Impl::PaintInternal(const gfx::Rect& rect, PP_Bool PPB_Scrollbar_Impl::HandleEventInternal( const ::ppapi::InputEventData& data) { scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(data)); - if (!web_input_event.get()) + if (!web_input_event.get() || !scrollbar_.get()) return PP_FALSE; return PP_FromBool(scrollbar_->handleInputEvent(*web_input_event.get())); } void PPB_Scrollbar_Impl::SetLocationInternal(const PP_Rect* location) { + if (!scrollbar_.get()) + return; scrollbar_->setLocation(WebRect(location->point.x, location->point.y, location->size.width, @@ -232,33 +250,38 @@ void PPB_Scrollbar_Impl::SetLocationInternal(const PP_Rect* location) { } void PPB_Scrollbar_Impl::valueChanged(WebKit::WebScrollbar* scrollbar) { + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return; + const PPP_Scrollbar_Dev* ppp_scrollbar = - static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> - GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); + static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( + PPP_SCROLLBAR_DEV_INTERFACE)); if (!ppp_scrollbar) { // Try the old version. This is ok because the old interface is a subset of // the new one, and ValueChanged didn't change. ppp_scrollbar = - static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> - GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE_0_2)); + static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( + PPP_SCROLLBAR_DEV_INTERFACE_0_2)); if (!ppp_scrollbar) return; } - ScopedResourceId resource(this); - ppp_scrollbar->ValueChanged( - instance()->pp_instance(), resource.id, scrollbar_->value()); + ppp_scrollbar->ValueChanged(pp_instance(), pp_resource(), + scrollbar_->value()); } void PPB_Scrollbar_Impl::overlayChanged(WebScrollbar* scrollbar) { + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return; + const PPP_Scrollbar_Dev* ppp_scrollbar = - static_cast<const PPP_Scrollbar_Dev*>(instance()->module()-> - GetPluginInterface(PPP_SCROLLBAR_DEV_INTERFACE)); + static_cast<const PPP_Scrollbar_Dev*>(plugin_module->GetPluginInterface( + PPP_SCROLLBAR_DEV_INTERFACE)); if (!ppp_scrollbar) return; - ScopedResourceId resource(this); - ppp_scrollbar->OverlayChanged( - instance()->pp_instance(), resource.id, - PP_FromBool(IsOverlay())); + ppp_scrollbar->OverlayChanged(pp_instance(), pp_resource(), + PP_FromBool(IsOverlay())); } void PPB_Scrollbar_Impl::invalidateScrollbarRect( diff --git a/webkit/plugins/ppapi/ppb_scrollbar_impl.h b/webkit/plugins/ppapi/ppb_scrollbar_impl.h index a10e694..3544d10 100644 --- a/webkit/plugins/ppapi/ppb_scrollbar_impl.h +++ b/webkit/plugins/ppapi/ppb_scrollbar_impl.h @@ -17,19 +17,17 @@ namespace webkit { namespace ppapi { -class PluginInstance; - class PPB_Scrollbar_Impl : public PPB_Widget_Impl, public ::ppapi::thunk::PPB_Scrollbar_API, public WebKit::WebScrollbarClient { public: - static PP_Resource Create(PluginInstance* instance, - bool vertical); + static PP_Resource Create(PP_Instance instance, bool vertical); virtual ~PPB_Scrollbar_Impl(); - // Resource override. + // Resource overrides. virtual PPB_Scrollbar_API* AsPPB_Scrollbar_API() OVERRIDE; + virtual void InstanceWasDeleted(); // Returns a pointer to the interface implementing PPB_Scrollbar_0_3 that is // exposed to the plugin. New code should use the thunk system for the new @@ -51,7 +49,7 @@ class PPB_Scrollbar_Impl : public PPB_Widget_Impl, virtual void ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) OVERRIDE; private: - PPB_Scrollbar_Impl(PluginInstance* instance); + explicit PPB_Scrollbar_Impl(PP_Instance instance); void Init(bool vertical); // PPB_Widget private implementation. diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc index fe26514..1193252 100644 --- a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc @@ -13,13 +13,14 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::PPB_Surface3D_API; namespace webkit { namespace ppapi { -PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) +PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance) : Resource(instance), bound_to_instance_(false), swap_initiated_(false), @@ -32,7 +33,7 @@ PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { } // static -PP_Resource PPB_Surface3D_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Surface3D_Impl::Create(PP_Instance instance, PP_Config3D_Dev config, const int32_t* attrib_list) { scoped_refptr<PPB_Surface3D_Impl> surface( @@ -71,8 +72,12 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { if (!context_) return PP_ERROR_FAILED; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_ERROR_FAILED; + swap_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); if (impl) context_->gles2_impl()->SwapBuffers(); @@ -95,8 +100,12 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { if (context == context_) return true; + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return false; + if (!context && bound_to_instance_) - instance()->BindGraphics(instance()->pp_instance(), 0); + plugin_instance->BindGraphics(pp_instance(), 0); // Unbind from the current context. if (context_ && context_->platform_context()) @@ -106,7 +115,7 @@ bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { // TODO(alokp): This should be the responsibility of plugins. gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); if (impl) { - const gfx::Size& size = instance()->position().size(); + const gfx::Size& size = plugin_instance->position().size(); impl->ResizeCHROMIUM(size.width(), size.height()); } @@ -137,8 +146,12 @@ unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { } void PPB_Surface3D_Impl::OnSwapBuffers() { - if (bound_to_instance_) { - instance()->CommitBackingTexture(); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) + return; + + if (bound_to_instance_ && plugin_instance) { + plugin_instance->CommitBackingTexture(); swap_initiated_ = true; } else if (swap_callback_.get() && !swap_callback_->completed()) { // If we're off-screen, no need to trigger compositing so run the callback @@ -151,8 +164,9 @@ void PPB_Surface3D_Impl::OnSwapBuffers() { } void PPB_Surface3D_Impl::OnContextLost() { - if (bound_to_instance_) - instance()->BindGraphics(instance()->pp_instance(), 0); + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (bound_to_instance_ && plugin_instance) + plugin_instance->BindGraphics(pp_instance(), 0); // Send context lost to plugin. This may have been caused by a PPAPI call, so // avoid re-entering. @@ -161,17 +175,19 @@ void PPB_Surface3D_Impl::OnContextLost() { } void PPB_Surface3D_Impl::SendContextLost() { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + // By the time we run this, the instance may have been deleted, or in the // process of being deleted. Even in the latter case, we don't want to send a // callback after DidDestroy. - if (!instance() || !instance()->container()) + if (!plugin_instance || !plugin_instance->container()) return; const PPP_Graphics3D_Dev* ppp_graphics_3d = static_cast<const PPP_Graphics3D_Dev*>( - instance()->module()->GetPluginInterface( + plugin_instance->module()->GetPluginInterface( PPP_GRAPHICS_3D_DEV_INTERFACE)); if (ppp_graphics_3d) - ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); + ppp_graphics_3d->Graphics3DContextLost(pp_instance()); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.h b/webkit/plugins/ppapi/ppb_surface_3d_impl.h index 11703af..deea404 100644 --- a/webkit/plugins/ppapi/ppb_surface_3d_impl.h +++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.h @@ -6,10 +6,10 @@ #define WEBKIT_PLUGINS_PPAPI_PPB_SURFACE_3D_IMPL_H_ #include "base/memory/ref_counted.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_surface_3d_api.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" namespace gfx { class Size; @@ -20,12 +20,12 @@ namespace ppapi { class PPB_Context3D_Impl; -class PPB_Surface3D_Impl : public Resource, +class PPB_Surface3D_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Surface3D_API { public: virtual ~PPB_Surface3D_Impl(); - static PP_Resource Create(PluginInstance* instance_id, + static PP_Resource Create(PP_Instance instance, PP_Config3D_Dev config, const int32_t* attrib_list); @@ -58,7 +58,7 @@ class PPB_Surface3D_Impl : public Resource, void OnContextLost(); private: - explicit PPB_Surface3D_Impl(PluginInstance* instance); + explicit PPB_Surface3D_Impl(PP_Instance instance); bool Init(PP_Config3D_Dev config, const int32_t* attrib_list); diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc index 3048c60..d4ba8df 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.cc +++ b/webkit/plugins/ppapi/ppb_transport_impl.cc @@ -16,6 +16,7 @@ #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::StringVar; using ppapi::thunk::PPB_Transport_API; @@ -47,7 +48,7 @@ int MapNetError(int result) { } // namespace -PPB_Transport_Impl::PPB_Transport_Impl(PluginInstance* instance) +PPB_Transport_Impl::PPB_Transport_Impl(PP_Instance instance) : Resource(instance), started_(false), writable_(false), @@ -61,7 +62,7 @@ PPB_Transport_Impl::~PPB_Transport_Impl() { } // static -PP_Resource PPB_Transport_Impl::Create(PluginInstance* instance, +PP_Resource PPB_Transport_Impl::Create(PP_Instance instance, const char* name, const char* proto) { scoped_refptr<PPB_Transport_Impl> t(new PPB_Transport_Impl(instance)); @@ -86,7 +87,10 @@ bool PPB_Transport_Impl::Init(const char* name, const char* proto) { return false; } - p2p_transport_.reset(instance()->delegate()->CreateP2PTransport()); + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return false; + p2p_transport_.reset(plugin_delegate->CreateP2PTransport()); return p2p_transport_.get() != NULL; } @@ -113,8 +117,12 @@ int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { started_ = true; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_ERROR_FAILED; + connect_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); return PP_OK_COMPLETIONPENDING; } @@ -126,15 +134,19 @@ int32_t PPB_Transport_Impl::GetNextAddress(PP_Var* address, if (next_address_callback_.get() && !next_address_callback_->completed()) return PP_ERROR_INPROGRESS; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_ERROR_FAILED; + if (!local_candidates_.empty()) { - *address = StringVar::StringToPPVar(instance()->module()->pp_module(), + *address = StringVar::StringToPPVar(plugin_module->pp_module(), local_candidates_.front()); local_candidates_.pop_front(); return PP_OK; } next_address_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); return PP_OK_COMPLETIONPENDING; } @@ -162,12 +174,16 @@ int32_t PPB_Transport_Impl::Recv(void* data, uint32_t len, if (!channel) return PP_ERROR_FAILED; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_ERROR_FAILED; + scoped_refptr<net::IOBuffer> buffer = new net::WrappedIOBuffer(static_cast<const char*>(data)); int result = MapNetError(channel->Read(buffer, len, &channel_read_callback_)); if (result == PP_OK_COMPLETIONPENDING) { recv_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); } return result; @@ -185,13 +201,17 @@ int32_t PPB_Transport_Impl::Send(const void* data, uint32_t len, if (!channel) return PP_ERROR_FAILED; + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_ERROR_FAILED; + scoped_refptr<net::IOBuffer> buffer = new net::WrappedIOBuffer(static_cast<const char*>(data)); int result = MapNetError(channel->Write(buffer, len, &channel_write_callback_)); if (result == PP_OK_COMPLETIONPENDING) { send_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); } return result; @@ -202,7 +222,11 @@ int32_t PPB_Transport_Impl::Close() { return PP_ERROR_FAILED; p2p_transport_.reset(); - instance()->module()->GetCallbackTracker()->AbortAll(); + + + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (plugin_module) + plugin_module->GetCallbackTracker()->AbortAll(); return PP_OK; } diff --git a/webkit/plugins/ppapi/ppb_transport_impl.h b/webkit/plugins/ppapi/ppb_transport_impl.h index f1219cb..e49153b 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.h +++ b/webkit/plugins/ppapi/ppb_transport_impl.h @@ -11,21 +11,21 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "net/base/completion_callback.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_transport_api.h" #include "webkit/glue/p2p_transport.h" #include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { -class PPB_Transport_Impl : public Resource, +class PPB_Transport_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Transport_API, public webkit_glue::P2PTransport::EventHandler { public: virtual ~PPB_Transport_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, const char* name, const char* proto); @@ -50,7 +50,7 @@ class PPB_Transport_Impl : public Resource, virtual void OnError(int error) OVERRIDE; private: - explicit PPB_Transport_Impl(PluginInstance* instance); + explicit PPB_Transport_Impl(PP_Instance instance); bool Init(const char* name, const char* proto); diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.cc b/webkit/plugins/ppapi/ppb_url_loader_impl.cc index 95349b7..ce58de4 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.cc @@ -29,8 +29,10 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" using appcache::WebApplicationCacheHostImpl; +using ppapi::Resource; using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_URLLoader_API; using ppapi::thunk::PPB_URLRequestInfo_API; @@ -51,7 +53,18 @@ using WebKit::WebURLResponse; namespace webkit { namespace ppapi { -PPB_URLLoader_Impl::PPB_URLLoader_Impl(PluginInstance* instance, +namespace { + +WebFrame* GetFrameForResource(const Resource* resource) { + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(resource); + if (!plugin_instance) + return NULL; + return plugin_instance->container()->element().document().frame(); +} + +} // namespace + +PPB_URLLoader_Impl::PPB_URLLoader_Impl(PP_Instance instance, bool main_document_loader) : Resource(instance), main_document_loader_(main_document_loader), @@ -99,7 +112,7 @@ int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, if (loader_.get()) return PP_ERROR_INPROGRESS; - WebFrame* frame = instance()->container()->element().document().frame(); + WebFrame* frame = GetFrameForResource(this); if (!frame) return PP_ERROR_FAILED; WebURLRequest web_request(request->ToWebURLRequest(frame)); @@ -226,12 +239,10 @@ int32_t PPB_URLLoader_Impl::FinishStreamingToFile( } void PPB_URLLoader_Impl::Close() { - if (loader_.get()) { + if (loader_.get()) loader_->cancel(); - } else if (main_document_loader_) { - WebFrame* frame = instance()->container()->element().document().frame(); - frame->stopLoading(); - } + else if (main_document_loader_) + GetFrameForResource(this)->stopLoading(); // TODO(viettrungluu): Check what happens to the callback (probably the // wrong thing). May need to post abort here. crbug.com/69457 } @@ -362,8 +373,12 @@ void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { DCHECK(callback.func); DCHECK(!pending_callback_.get() || pending_callback_->completed()); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return; + pending_callback_ = new TrackedCompletionCallback( - instance()->module()->GetCallbackTracker(), pp_resource(), callback); + plugin_module->GetCallbackTracker(), pp_resource(), callback); } void PPB_URLLoader_Impl::RunCallback(int32_t result) { @@ -404,7 +419,7 @@ size_t PPB_URLLoader_Impl::FillUserBuffer() { void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { scoped_refptr<PPB_URLResponseInfo_Impl> response_info( - new PPB_URLResponseInfo_Impl(instance())); + new PPB_URLResponseInfo_Impl(pp_instance())); if (response_info->Initialize(response)) response_info_ = response_info; } @@ -418,7 +433,7 @@ void PPB_URLLoader_Impl::UpdateStatus() { // getting download progress when they happen to set the upload progress // flag. status_callback_( - instance()->pp_instance(), pp_resource(), + pp_instance(), pp_resource(), RecordUploadProgress() ? bytes_sent_ : -1, RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, RecordDownloadProgress() ? bytes_received_ : -1, diff --git a/webkit/plugins/ppapi/ppb_url_loader_impl.h b/webkit/plugins/ppapi/ppb_url_loader_impl.h index d067ebf..429a042 100644 --- a/webkit/plugins/ppapi/ppb_url_loader_impl.h +++ b/webkit/plugins/ppapi/ppb_url_loader_impl.h @@ -11,11 +11,11 @@ #include "base/memory/scoped_ptr.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/trusted/ppb_url_loader_trusted.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_url_loader_api.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" #include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource.h" namespace WebKit { class WebFrame; @@ -25,15 +25,14 @@ class WebURL; namespace webkit { namespace ppapi { -class PluginInstance; class PPB_URLRequestInfo_Impl; class PPB_URLResponseInfo_Impl; -class PPB_URLLoader_Impl : public Resource, +class PPB_URLLoader_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_URLLoader_API, public WebKit::WebURLLoaderClient { public: - PPB_URLLoader_Impl(PluginInstance* instance, bool main_document_loader); + PPB_URLLoader_Impl(PP_Instance instance, bool main_document_loader); virtual ~PPB_URLLoader_Impl(); // Resource overrides. diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc index 1b72319..985a795 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.cc @@ -25,6 +25,7 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/ppb_file_system_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/string.h" using ppapi::StringVar; @@ -183,7 +184,7 @@ struct PPB_URLRequestInfo_Impl::BodyItem { PP_Time expected_last_modified_time; }; -PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PluginInstance* instance) +PPB_URLRequestInfo_Impl::PPB_URLRequestInfo_Impl(PP_Instance instance) : Resource(instance), stream_to_file_(false), follow_redirects_(true), @@ -292,13 +293,17 @@ WebURLRequest PPB_URLRequestInfo_Impl::ToWebURLRequest(WebFrame* frame) const { FilePath platform_path; switch (body_[i].file_ref->file_system()->type()) { case PP_FILESYSTEMTYPE_LOCALTEMPORARY: - case PP_FILESYSTEMTYPE_LOCALPERSISTENT: + case PP_FILESYSTEMTYPE_LOCALPERSISTENT: { // TODO(kinuko): remove this sync IPC when we add more generic // AppendURLRange solution that works for both Blob/FileSystem URL. - instance()->delegate()->SyncGetFileSystemPlatformPath( - body_[i].file_ref->GetFileSystemURL(), - &platform_path); + PluginDelegate* plugin_delegate = + ResourceHelper::GetPluginDelegate(this); + if (plugin_delegate) { + plugin_delegate->SyncGetFileSystemPlatformPath( + body_[i].file_ref->GetFileSystemURL(), &platform_path); + } break; + } case PP_FILESYSTEMTYPE_EXTERNAL: platform_path = body_[i].file_ref->GetSystemPath(); break; diff --git a/webkit/plugins/ppapi/ppb_url_request_info_impl.h b/webkit/plugins/ppapi/ppb_url_request_info_impl.h index c0ec99b..277edfb 100644 --- a/webkit/plugins/ppapi/ppb_url_request_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_request_info_impl.h @@ -8,10 +8,11 @@ #include <string> #include <vector> +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "ppapi/c/ppb_url_request_info.h" #include "ppapi/thunk/ppb_url_request_info_api.h" -#include "webkit/plugins/ppapi/resource.h" +#include "ppapi/shared_impl/resource.h" namespace WebKit { class WebFrame; @@ -23,10 +24,10 @@ namespace ppapi { class PPB_FileRef_Impl; -class PPB_URLRequestInfo_Impl : public Resource, +class PPB_URLRequestInfo_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_URLRequestInfo_API { public: - explicit PPB_URLRequestInfo_Impl(PluginInstance* instance); + explicit PPB_URLRequestInfo_Impl(PP_Instance instance); virtual ~PPB_URLRequestInfo_Impl(); // Resource overrides. diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc index b1ec1fd..fa35c0d 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.cc +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.cc @@ -15,6 +15,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/glue/webkit_glue.h" using ppapi::StringVar; @@ -50,7 +51,7 @@ bool IsRedirect(int32_t status) { } // namespace -PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PluginInstance* instance) +PPB_URLResponseInfo_Impl::PPB_URLResponseInfo_Impl(PP_Instance instance) : Resource(instance), status_code_(-1) { } @@ -73,7 +74,7 @@ bool PPB_URLResponseInfo_Impl::Initialize(const WebURLResponse& response) { WebString file_path = response.downloadFilePath(); if (!file_path.isEmpty()) { - body_ = new PPB_FileRef_Impl(instance(), + body_ = new PPB_FileRef_Impl(pp_instance(), webkit_glue::WebStringToFilePath(file_path)); } return true; @@ -84,7 +85,10 @@ PPB_URLResponseInfo_API* PPB_URLResponseInfo_Impl::AsPPB_URLResponseInfo_API() { } PP_Var PPB_URLResponseInfo_Impl::GetProperty(PP_URLResponseProperty property) { - PP_Module pp_module = instance()->module()->pp_module(); + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (!plugin_module) + return PP_MakeUndefined(); + PP_Module pp_module = plugin_module->pp_module(); switch (property) { case PP_URLRESPONSEPROPERTY_URL: return StringVar::StringToPPVar(pp_module, url_); diff --git a/webkit/plugins/ppapi/ppb_url_response_info_impl.h b/webkit/plugins/ppapi/ppb_url_response_info_impl.h index 5c50746..96399923 100644 --- a/webkit/plugins/ppapi/ppb_url_response_info_impl.h +++ b/webkit/plugins/ppapi/ppb_url_response_info_impl.h @@ -8,9 +8,10 @@ #include <string> #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "ppapi/c/ppb_url_response_info.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_url_response_info_api.h" -#include "webkit/plugins/ppapi/resource.h" namespace WebKit { class WebURLResponse; @@ -22,10 +23,10 @@ namespace ppapi { class PPB_FileRef_Impl; class PPB_URLResponseInfo_Impl - : public Resource, + : public ::ppapi::Resource, public ::ppapi::thunk::PPB_URLResponseInfo_API { public: - explicit PPB_URLResponseInfo_Impl(PluginInstance* instance); + explicit PPB_URLResponseInfo_Impl(PP_Instance instance); virtual ~PPB_URLResponseInfo_Impl(); bool Initialize(const WebKit::WebURLResponse& response); diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.cc b/webkit/plugins/ppapi/ppb_video_capture_impl.cc index 3663853..05646d6 100644 --- a/webkit/plugins/ppapi/ppb_video_capture_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_capture_impl.cc @@ -17,6 +17,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_buffer_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "webkit/plugins/ppapi/resource_tracker.h" using ppapi::thunk::EnterResourceNoLock; @@ -26,7 +27,7 @@ using ppapi::thunk::PPB_VideoCapture_API; namespace webkit { namespace ppapi { -PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PluginInstance* instance) +PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance) : Resource(instance), buffer_count_hint_(0), ppp_videocapture_(NULL), @@ -39,14 +40,16 @@ PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() { } bool PPB_VideoCapture_Impl::Init() { - ppp_videocapture_ = - static_cast<const PPP_VideoCapture_Dev*>(instance()->module()-> - GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); + PluginInstance* instance = ResourceHelper::GetPluginInstance(this); + if (!instance) + return false; + ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>( + instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); if (!ppp_videocapture_) return false; platform_video_capture_.reset( - instance()->delegate()->CreateVideoCapture(this)); + instance->delegate()->CreateVideoCapture(this)); return !!platform_video_capture_.get(); } @@ -161,9 +164,7 @@ void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, // conflicting "master" resolution), or because the browser failed to start // the capture. status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; - ppp_videocapture_->OnError(instance()->pp_instance(), - ScopedResourceId(this).id, - PP_ERROR_FAILED); + ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); } void PPB_VideoCapture_Impl::OnBufferReady( @@ -178,9 +179,7 @@ void PPB_VideoCapture_Impl::OnBufferReady( buffer->buffer_size); memcpy(buffers_[i].data, buffer->memory_pointer, size); platform_video_capture_->FeedBuffer(buffer); - ppp_videocapture_->OnBufferReady(instance()->pp_instance(), - ScopedResourceId(this).id, - i); + ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); return; } } @@ -208,7 +207,7 @@ void PPB_VideoCapture_Impl::OnDeviceInfoReceived( buffers_.reserve(buffer_count_hint_); for (size_t i = 0; i < buffer_count_hint_; ++i) { - resources[i] = PPB_Buffer_Impl::Create(instance(), size); + resources[i] = PPB_Buffer_Impl::Create(pp_instance(), size); if (!resources[i]) break; @@ -228,19 +227,14 @@ void PPB_VideoCapture_Impl::OnDeviceInfoReceived( if (buffers_.empty()) { // We couldn't allocate/map buffers at all. Send an error and stop the // capture. - ppp_videocapture_->OnError(instance()->pp_instance(), - ScopedResourceId(this).id, - PP_ERROR_NOMEMORY); + ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY); status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; platform_video_capture_->StopCapture(this); return; } - ppp_videocapture_->OnDeviceInfo(instance()->pp_instance(), - ScopedResourceId(this).id, - &info, - buffers_.size(), - resources.get()); + ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info, + buffers_.size(), resources.get()); } void PPB_VideoCapture_Impl::ReleaseBuffers() { @@ -253,9 +247,7 @@ void PPB_VideoCapture_Impl::ReleaseBuffers() { } void PPB_VideoCapture_Impl::SendStatus() { - ppp_videocapture_->OnStatus(instance()->pp_instance(), - ScopedResourceId(this).id, - status_); + ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_); } PPB_VideoCapture_Impl::BufferInfo::BufferInfo() diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.h b/webkit/plugins/ppapi/ppb_video_capture_impl.h index d05747d..f99c989 100644 --- a/webkit/plugins/ppapi/ppb_video_capture_impl.h +++ b/webkit/plugins/ppapi/ppb_video_capture_impl.h @@ -13,10 +13,10 @@ #include "base/memory/scoped_ptr.h" #include "media/video/capture/video_capture.h" #include "ppapi/c/dev/ppp_video_capture_dev.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_video_capture_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/ppb_buffer_impl.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_VideoCaptureDeviceInfo_Dev; struct PPB_VideoCapture_Dev; @@ -24,13 +24,11 @@ struct PPB_VideoCapture_Dev; namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_VideoCapture_Impl : public Resource, +class PPB_VideoCapture_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_VideoCapture_API, public media::VideoCapture::EventHandler { public: - explicit PPB_VideoCapture_Impl(PluginInstance* instance); + explicit PPB_VideoCapture_Impl(PP_Instance instance); virtual ~PPB_VideoCapture_Impl(); bool Init(); diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index 919a1c8..1585dd7 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -15,6 +15,7 @@ #include "ppapi/c/dev/ppp_video_decoder_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" +#include "webkit/plugins/ppapi/resource_helper.h" #include "ppapi/thunk/enter.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" @@ -31,11 +32,14 @@ using ppapi::thunk::PPB_VideoDecoder_API; namespace webkit { namespace ppapi { -PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) - : Resource(instance) { - ppp_videodecoder_ = - static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> - GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); +PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) + : Resource(instance), + ppp_videodecoder_(NULL) { + PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); + if (plugin_module) { + ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( + plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); + } } PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { @@ -46,7 +50,7 @@ PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { } // static -PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, +PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance, PP_Resource context3d_id, const PP_VideoConfigElement* config) { if (!context3d_id) @@ -80,7 +84,13 @@ bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, context3d_impl->platform_context()->GetCommandBufferRouteId(); if (command_buffer_route_id == 0) return false; - platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( + + + PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); + if (!plugin_delegate) + return false; + + platform_video_decoder_ = plugin_delegate->CreateVideoDecoder( this, command_buffer_route_id); if (!platform_video_decoder_) return false; @@ -181,10 +191,8 @@ void PPB_VideoDecoder_Impl::ProvidePictureBuffers( return; PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); - ScopedResourceId resource(this); - ppp_videodecoder_->ProvidePictureBuffers( - instance()->pp_instance(), resource.id, requested_num_of_buffers, - out_dim); + ppp_videodecoder_->ProvidePictureBuffers(pp_instance(), pp_resource(), + requested_num_of_buffers, out_dim); } void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { @@ -194,26 +202,20 @@ void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { PP_Picture_Dev output; output.picture_buffer_id = picture.picture_buffer_id(); output.bitstream_buffer_id = picture.bitstream_buffer_id(); - ScopedResourceId resource(this); - ppp_videodecoder_->PictureReady( - instance()->pp_instance(), resource.id, output); + ppp_videodecoder_->PictureReady(pp_instance(), pp_resource(), output); } void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { if (!ppp_videodecoder_) return; - - ScopedResourceId resource(this); - ppp_videodecoder_->DismissPictureBuffer( - instance()->pp_instance(), resource.id, picture_buffer_id); + ppp_videodecoder_->DismissPictureBuffer(pp_instance(), pp_resource(), + picture_buffer_id); } void PPB_VideoDecoder_Impl::NotifyEndOfStream() { if (!ppp_videodecoder_) return; - - ScopedResourceId resource(this); - ppp_videodecoder_->EndOfStream(instance()->pp_instance(), resource.id); + ppp_videodecoder_->EndOfStream(pp_instance(), pp_resource()); } void PPB_VideoDecoder_Impl::NotifyError( @@ -221,12 +223,11 @@ void PPB_VideoDecoder_Impl::NotifyError( if (!ppp_videodecoder_) return; - ScopedResourceId resource(this); // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and // PP_VideoDecodeError_Dev have identical enum values. There is no compiler // assert to guarantee this. We either need to add such asserts or // merge these two enums. - ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, + ppp_videodecoder_->NotifyError(pp_instance(), pp_resource(), static_cast<PP_VideoDecodeError_Dev>(error)); } diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h index 7f0848d..c7593ce 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h @@ -13,10 +13,10 @@ #include "base/memory/scoped_ptr.h" #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/pp_var.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/video_decoder_impl.h" #include "ppapi/thunk/ppb_video_decoder_api.h" #include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_PictureBuffer_Dev; struct PP_VideoDecoderConfig_Dev; @@ -40,16 +40,14 @@ class PPB_Context3D_API; namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_VideoDecoder_Impl : public Resource, +class PPB_VideoDecoder_Impl : public ::ppapi::Resource, public ::ppapi::VideoDecoderImpl, public media::VideoDecodeAccelerator::Client { public: virtual ~PPB_VideoDecoder_Impl(); // See PPB_VideoDecoder_Dev::Create. Returns 0 on failure to create & // initialize. - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_Resource context3d_id, const PP_VideoConfigElement* config); @@ -86,7 +84,7 @@ class PPB_VideoDecoder_Impl : public Resource, const PP_VideoConfigElement* dec_config) OVERRIDE; private: - explicit PPB_VideoDecoder_Impl(PluginInstance* instance); + explicit PPB_VideoDecoder_Impl(PP_Instance instance); // This is NULL before initialization, and if this PPB_VideoDecoder_Impl is // swapped with another. diff --git a/webkit/plugins/ppapi/ppb_video_layer_impl.cc b/webkit/plugins/ppapi/ppb_video_layer_impl.cc index e7cad6f..aa90f13 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_layer_impl.cc @@ -13,7 +13,7 @@ using ppapi::thunk::PPB_VideoLayer_API; namespace webkit { namespace ppapi { -PPB_VideoLayer_Impl::PPB_VideoLayer_Impl(PluginInstance* instance) +PPB_VideoLayer_Impl::PPB_VideoLayer_Impl(PP_Instance instance) : Resource(instance) { } @@ -21,7 +21,7 @@ PPB_VideoLayer_Impl::~PPB_VideoLayer_Impl() { } // static -PP_Resource PPB_VideoLayer_Impl::Create(PluginInstance* instance, +PP_Resource PPB_VideoLayer_Impl::Create(PP_Instance instance, PP_VideoLayerMode_Dev mode) { if (mode != PP_VIDEOLAYERMODE_SOFTWARE) return 0; diff --git a/webkit/plugins/ppapi/ppb_video_layer_impl.h b/webkit/plugins/ppapi/ppb_video_layer_impl.h index 7449b57..c082957 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_impl.h +++ b/webkit/plugins/ppapi/ppb_video_layer_impl.h @@ -5,8 +5,9 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_LAYER_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_LAYER_IMPL_H_ +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_video_layer_api.h" -#include "webkit/plugins/ppapi/resource.h" struct PP_Rect; struct PP_Size; @@ -14,14 +15,12 @@ struct PP_Size; namespace webkit { namespace ppapi { -class PluginInstance; - -class PPB_VideoLayer_Impl : public Resource, +class PPB_VideoLayer_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_VideoLayer_API { public: virtual ~PPB_VideoLayer_Impl(); - static PP_Resource Create(PluginInstance* instance, + static PP_Resource Create(PP_Instance instance, PP_VideoLayerMode_Dev mode); // Resource override. @@ -30,7 +29,7 @@ class PPB_VideoLayer_Impl : public Resource, // Derived classes must implement PPB_VideoLayer_API. protected: - explicit PPB_VideoLayer_Impl(PluginInstance* instance); + explicit PPB_VideoLayer_Impl(PP_Instance instance); private: DISALLOW_COPY_AND_ASSIGN(PPB_VideoLayer_Impl); diff --git a/webkit/plugins/ppapi/ppb_video_layer_software.cc b/webkit/plugins/ppapi/ppb_video_layer_software.cc index dbc1364..b569420 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_software.cc +++ b/webkit/plugins/ppapi/ppb_video_layer_software.cc @@ -7,7 +7,7 @@ namespace webkit { namespace ppapi { -PPB_VideoLayer_Software::PPB_VideoLayer_Software(PluginInstance* instance) +PPB_VideoLayer_Software::PPB_VideoLayer_Software(PP_Instance instance) : PPB_VideoLayer_Impl(instance) { } diff --git a/webkit/plugins/ppapi/ppb_video_layer_software.h b/webkit/plugins/ppapi/ppb_video_layer_software.h index a1b901b..6367cd1 100644 --- a/webkit/plugins/ppapi/ppb_video_layer_software.h +++ b/webkit/plugins/ppapi/ppb_video_layer_software.h @@ -6,16 +6,13 @@ #define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_LAYER_SOFTWARE_H_ #include "webkit/plugins/ppapi/ppb_video_layer_impl.h" -#include "webkit/plugins/ppapi/resource.h" namespace webkit { namespace ppapi { -class PluginInstance; - class PPB_VideoLayer_Software : public PPB_VideoLayer_Impl { public: - explicit PPB_VideoLayer_Software(PluginInstance* instance); + explicit PPB_VideoLayer_Software(PP_Instance instance); virtual ~PPB_VideoLayer_Software(); // PPB_VideoLayer_Impl implementations. diff --git a/webkit/plugins/ppapi/ppb_widget_impl.cc b/webkit/plugins/ppapi/ppb_widget_impl.cc index 241b2c2..c071067 100644 --- a/webkit/plugins/ppapi/ppb_widget_impl.cc +++ b/webkit/plugins/ppapi/ppb_widget_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "webkit/plugins/ppapi/ppb_image_data_impl.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/plugin_module.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::thunk::EnterResourceNoLock; using ppapi::thunk::PPB_ImageData_API; @@ -20,7 +21,7 @@ using ppapi::thunk::PPB_Widget_API; namespace webkit { namespace ppapi { -PPB_Widget_Impl::PPB_Widget_Impl(PluginInstance* instance) +PPB_Widget_Impl::PPB_Widget_Impl(PP_Instance instance) : Resource(instance) { memset(&location_, 0, sizeof(location_)); } @@ -59,14 +60,14 @@ void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { } void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { - if (!instance()) + PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); + if (!plugin_instance) return; const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( - instance()->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); + plugin_instance->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); if (!widget) return; - ScopedResourceId resource(this); - widget->Invalidate(instance()->pp_instance(), resource.id, dirty); + widget->Invalidate(pp_instance(), pp_resource(), dirty); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/ppb_widget_impl.h b/webkit/plugins/ppapi/ppb_widget_impl.h index b8ebc71..eeed6dd 100644 --- a/webkit/plugins/ppapi/ppb_widget_impl.h +++ b/webkit/plugins/ppapi/ppb_widget_impl.h @@ -8,8 +8,8 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "ppapi/c/pp_rect.h" +#include "ppapi/shared_impl/resource.h" #include "ppapi/thunk/ppb_widget_api.h" -#include "webkit/plugins/ppapi/resource.h" struct PPB_Widget_Dev; @@ -24,12 +24,11 @@ namespace webkit { namespace ppapi { class PPB_ImageData_Impl; -class PluginInstance; -class PPB_Widget_Impl : public Resource, +class PPB_Widget_Impl : public ::ppapi::Resource, public ::ppapi::thunk::PPB_Widget_API { public: - explicit PPB_Widget_Impl(PluginInstance* instance); + explicit PPB_Widget_Impl(PP_Instance instance); virtual ~PPB_Widget_Impl(); // Resource overrides. diff --git a/webkit/plugins/ppapi/quota_file_io.cc b/webkit/plugins/ppapi/quota_file_io.cc index 82fdf9f..63db38e 100644 --- a/webkit/plugins/ppapi/quota_file_io.cc +++ b/webkit/plugins/ppapi/quota_file_io.cc @@ -10,6 +10,8 @@ #include "base/message_loop_proxy.h" #include "base/task.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_helper.h" +#include "webkit/plugins/ppapi/resource_tracker.h" using base::PlatformFile; using base::PlatformFileError; @@ -90,8 +92,15 @@ class QuotaFileIO::WriteOperation : public PendingOperationBase { return; } DCHECK(buffer_.get()); + + PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate(); + if (!plugin_delegate) { + DidFail(base::PLATFORM_FILE_ERROR_FAILED); + return; + } + if (!base::FileUtilProxy::Write( - quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), quota_io_->file_, offset_, buffer_.get(), bytes_to_write_, callback_factory_.NewCallback(&WriteOperation::DidFinish))) { DidFail(base::PLATFORM_FILE_ERROR_FAILED); @@ -163,8 +172,15 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { DidFinish(base::PLATFORM_FILE_OK); return; } + + PluginDelegate* plugin_delegate = quota_io_->GetPluginDelegate(); + if (!plugin_delegate) { + DidFail(base::PLATFORM_FILE_ERROR_FAILED); + return; + } + if (!base::FileUtilProxy::Truncate( - quota_io_->instance_->delegate()->GetFileThreadMessageLoopProxy(), + plugin_delegate->GetFileThreadMessageLoopProxy(), quota_io_->file_, length_, callback_factory_.NewCallback(&SetLengthOperation::DidFinish))) { DidFail(base::PLATFORM_FILE_ERROR_FAILED); @@ -193,11 +209,11 @@ class QuotaFileIO::SetLengthOperation : public PendingOperationBase { // QuotaFileIO -------------------------------------------------------------- QuotaFileIO::QuotaFileIO( - PluginInstance* instance, + PP_Instance instance, PlatformFile file, const GURL& file_url, PP_FileSystemType type) - : instance_(instance), + : pp_instance_(instance), file_(file), file_url_(file_url), storage_type_(PPFileSystemTypeToQuotaStorageType(type)), @@ -208,7 +224,6 @@ QuotaFileIO::QuotaFileIO( max_written_offset_(0), inflight_operations_(0), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { - DCHECK(instance_); DCHECK_NE(base::kInvalidPlatformFileValue, file_); DCHECK_NE(quota::kStorageTypeUnknown, storage_type_); } @@ -253,6 +268,13 @@ bool QuotaFileIO::WillSetLength(int64_t length, StatusCallback* callback) { return RegisterOperationForQuotaChecks(op); } +PluginDelegate* QuotaFileIO::GetPluginDelegate() const { + PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance_); + if (instance) + return instance->delegate(); + return NULL; +} + bool QuotaFileIO::RegisterOperationForQuotaChecks( PendingOperationBase* op_ptr) { scoped_ptr<PendingOperationBase> op(op_ptr); @@ -262,10 +284,14 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks( outstanding_quota_queries_ = 0; outstanding_errors_ = 0; + PluginDelegate* plugin_delegate = GetPluginDelegate(); + if (!plugin_delegate) + return false; + // Query the file size. ++outstanding_quota_queries_; if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( - instance_->delegate()->GetFileThreadMessageLoopProxy(), file_, + plugin_delegate->GetFileThreadMessageLoopProxy(), file_, callback_factory_.NewCallback( &QuotaFileIO::DidQueryInfoForQuota))) { // This makes the call fail synchronously; we do not fire the callback @@ -275,7 +301,7 @@ bool QuotaFileIO::RegisterOperationForQuotaChecks( // Query the current available space. ++outstanding_quota_queries_; - instance_->delegate()->QueryAvailableSpace( + plugin_delegate->QueryAvailableSpace( GURL(file_url_.path()).GetOrigin(), storage_type_, callback_factory_.NewCallback(&QuotaFileIO::DidQueryAvailableSpace)); } @@ -324,7 +350,9 @@ bool QuotaFileIO::CheckIfExceedsQuota(int64_t new_file_size) const { void QuotaFileIO::WillUpdate() { if (inflight_operations_++ == 0) { - instance_->delegate()->WillUpdateFile(file_url_); + PluginDelegate* plugin_delegate = GetPluginDelegate(); + if (plugin_delegate) + plugin_delegate->WillUpdateFile(file_url_); DCHECK_EQ(0, max_written_offset_); } } @@ -349,7 +377,10 @@ void QuotaFileIO::DidWrite(WriteOperation* op, DCHECK(pending_operations_.empty()); int64_t growth = max_written_offset_ - cached_file_size_; growth = growth < 0 ? 0 : growth; - instance_->delegate()->DidUpdateFile(file_url_, growth); + + PluginDelegate* plugin_delegate = GetPluginDelegate(); + if (plugin_delegate) + plugin_delegate->DidUpdateFile(file_url_, growth); max_written_offset_ = 0; } } @@ -360,7 +391,11 @@ void QuotaFileIO::DidSetLength(PlatformFileError error, int64_t new_file_size) { DCHECK(pending_callbacks_.empty()); int64_t delta = (error != base::PLATFORM_FILE_OK) ? 0 : new_file_size - cached_file_size_; - instance_->delegate()->DidUpdateFile(file_url_, delta); + + + PluginDelegate* plugin_delegate = GetPluginDelegate(); + if (plugin_delegate) + plugin_delegate->DidUpdateFile(file_url_, delta); inflight_operations_ = 0; } diff --git a/webkit/plugins/ppapi/quota_file_io.h b/webkit/plugins/ppapi/quota_file_io.h index 1ee3188..a57b0dd 100644 --- a/webkit/plugins/ppapi/quota_file_io.h +++ b/webkit/plugins/ppapi/quota_file_io.h @@ -12,12 +12,13 @@ #include "base/platform_file.h" #include "googleurl/src/gurl.h" #include "ppapi/c/pp_file_info.h" +#include "ppapi/c/pp_instance.h" #include "webkit/quota/quota_types.h" namespace webkit { namespace ppapi { -class PluginInstance; +class PluginDelegate; // This class is created per PPB_FileIO_Impl instance and provides // write operations for quota-managed files (i.e. files of @@ -27,7 +28,7 @@ class QuotaFileIO { typedef base::FileUtilProxy::WriteCallback WriteCallback; typedef base::FileUtilProxy::StatusCallback StatusCallback; - QuotaFileIO(PluginInstance* instance, + QuotaFileIO(PP_Instance instance, base::PlatformFile file, const GURL& path_url, PP_FileSystemType type); @@ -54,6 +55,10 @@ class QuotaFileIO { bool SetLength(int64_t length, StatusCallback* callback); bool WillSetLength(int64_t length, StatusCallback* callback); + // Returns the plugin delegate or NULL if the resource has outlived the + // instance. + PluginDelegate* GetPluginDelegate() const; + private: class PendingOperationBase; class WriteOperation; @@ -71,7 +76,7 @@ class QuotaFileIO { void DidQueryForQuotaCheck(); // The plugin instance that owns this (via PPB_FileIO_Impl). - PluginInstance* instance_; + PP_Instance pp_instance_; // The file information associated to this instance. base::PlatformFile file_; diff --git a/webkit/plugins/ppapi/quota_file_io_unittest.cc b/webkit/plugins/ppapi/quota_file_io_unittest.cc index 79a4637..a2356fa 100644 --- a/webkit/plugins/ppapi/quota_file_io_unittest.cc +++ b/webkit/plugins/ppapi/quota_file_io_unittest.cc @@ -13,6 +13,7 @@ #include "base/scoped_temp_dir.h" #include "base/task.h" #include "webkit/plugins/ppapi/mock_plugin_delegate.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppapi_unittest.h" #include "webkit/plugins/ppapi/quota_file_io.h" @@ -101,7 +102,8 @@ class QuotaFileIOTest : public PpapiUnittest { ASSERT_NE(base::kInvalidPlatformFileValue, file_); ASSERT_FALSE(created); quota_file_io_.reset(new QuotaFileIO( - instance(), file_, GURL(), PP_FILESYSTEMTYPE_LOCALTEMPORARY)); + instance()->pp_instance(), file_, GURL(), + PP_FILESYSTEMTYPE_LOCALTEMPORARY)); } virtual void TearDown() OVERRIDE { diff --git a/webkit/plugins/ppapi/resource.cc b/webkit/plugins/ppapi/resource.cc deleted file mode 100644 index a84e1d3..0000000 --- a/webkit/plugins/ppapi/resource.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/resource.h" - -#include "base/logging.h" -#include "webkit/plugins/ppapi/callbacks.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/resource_tracker.h" - -namespace webkit { -namespace ppapi { - -Resource::Resource(PluginInstance* instance) - : ::ppapi::Resource(instance->pp_instance()), - instance_(instance) { -} - -Resource::~Resource() { -} - -PP_Resource Resource::GetReference() { - ResourceTracker* tracker = ResourceTracker::Get(); - tracker->AddRefResource(pp_resource()); - return pp_resource(); -} - -void Resource::LastPluginRefWasDeleted() { - instance()->module()->GetCallbackTracker()->PostAbortForResource( - pp_resource()); -} - -void Resource::InstanceWasDeleted() { - ::ppapi::Resource::InstanceWasDeleted(); - instance_ = NULL; -} - -} // namespace ppapi -} // namespace webkit - diff --git a/webkit/plugins/ppapi/resource.h b/webkit/plugins/ppapi/resource.h deleted file mode 100644 index 2514177..0000000 --- a/webkit/plugins/ppapi/resource.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ -#define WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/shared_impl/resource.h" -#include "webkit/plugins/ppapi/resource_tracker.h" - -namespace webkit { -namespace ppapi { - -class Resource : public ::ppapi::Resource { - public: - explicit Resource(PluginInstance* instance); - virtual ~Resource(); - - // Returns the instance owning this resource. This is generally to be - // non-NULL except if the instance is destroyed and some code internal to the - // PPAPI implementation is keeping a reference for some reason. - PluginInstance* instance() const { return instance_; } - - // Returns an resource id of this object. If the object doesn't have a - // resource id, new one is created with plugin refcount of 1. If it does, - // the refcount is incremented. Use this when you need to return a new - // reference to the plugin. - PP_Resource GetReference(); - - // When you need to ensure that a resource has a reference, but you do not - // want to increase the refcount (for example, if you need to call a plugin - // callback function with a reference), you can use this class. For example: - // - // plugin_callback(.., ScopedResourceId(resource).id, ...); - class ScopedResourceId { - public: - explicit ScopedResourceId(Resource* resource) - : id(resource->GetReference()) {} - ~ScopedResourceId() { - ResourceTracker::Get()->ReleaseResource(id); - } - const PP_Resource id; - }; - - // Resource implementation. - virtual void LastPluginRefWasDeleted() OVERRIDE; - virtual void InstanceWasDeleted() OVERRIDE; - - private: - // Non-owning pointer to our instance. See getter above. - PluginInstance* instance_; - - DISALLOW_COPY_AND_ASSIGN(Resource); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_H_ diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 6ecde57..7009f0c 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -39,8 +39,7 @@ using ppapi::StringVar; namespace webkit { namespace ppapi { -ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) - : instance_(instance) { +ResourceCreationImpl::ResourceCreationImpl(PluginInstance* instance) { } ResourceCreationImpl::~ResourceCreationImpl() { @@ -52,34 +51,34 @@ ResourceCreationImpl::AsResourceCreationAPI() { } PP_Resource ResourceCreationImpl::CreateAudio( - PP_Instance instance_id, + PP_Instance instance, PP_Resource config_id, PPB_Audio_Callback audio_callback, void* user_data) { - return PPB_Audio_Impl::Create(instance_, config_id, audio_callback, + return PPB_Audio_Impl::Create(instance, config_id, audio_callback, user_data); } PP_Resource ResourceCreationImpl::CreateAudioConfig( - PP_Instance instance_id, + PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { - return PPB_AudioConfig_Impl::Create(instance_, sample_rate, + return PPB_AudioConfig_Impl::Create(instance, sample_rate, sample_frame_count); } PP_Resource ResourceCreationImpl::CreateAudioTrusted( - PP_Instance instance_id) { - return (new PPB_Audio_Impl(instance_))->GetReference(); + PP_Instance instance) { + return (new PPB_Audio_Impl(instance))->GetReference(); } PP_Resource ResourceCreationImpl::CreateBroker(PP_Instance instance) { - return (new PPB_Broker_Impl(instance_))->GetReference(); + return (new PPB_Broker_Impl(instance))->GetReference(); } PP_Resource ResourceCreationImpl::CreateBuffer(PP_Instance instance, uint32_t size) { - return PPB_Buffer_Impl::Create(instance_, size); + return PPB_Buffer_Impl::Create(instance, size); } PP_Resource ResourceCreationImpl::CreateContext3D( @@ -109,11 +108,11 @@ PP_Resource ResourceCreationImpl::CreateFileChooser( PP_Instance instance, PP_FileChooserMode_Dev mode, const PP_Var& accept_mime_types) { - return PPB_FileChooser_Impl::Create(instance_, mode, accept_mime_types); + return PPB_FileChooser_Impl::Create(instance, mode, accept_mime_types); } PP_Resource ResourceCreationImpl::CreateFileIO(PP_Instance instance) { - return (new PPB_FileIO_Impl(instance_))->GetReference(); + return (new PPB_FileIO_Impl(instance))->GetReference(); } PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, @@ -124,18 +123,18 @@ PP_Resource ResourceCreationImpl::CreateFileRef(PP_Resource file_system, PP_Resource ResourceCreationImpl::CreateFileSystem( PP_Instance instance, PP_FileSystemType type) { - return PPB_FileSystem_Impl::Create(instance_, type); + return PPB_FileSystem_Impl::Create(instance, type); } PP_Resource ResourceCreationImpl::CreateFlashMenu( PP_Instance instance, const PP_Flash_Menu* menu_data) { - return PPB_Flash_Menu_Impl::Create(instance_, menu_data); + return PPB_Flash_Menu_Impl::Create(instance, menu_data); } PP_Resource ResourceCreationImpl::CreateFlashNetConnector( PP_Instance instance) { - return (new PPB_Flash_NetConnector_Impl(instance_))->GetReference(); + return (new PPB_Flash_NetConnector_Impl(instance))->GetReference(); } PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( @@ -145,37 +144,37 @@ PP_Resource ResourceCreationImpl::CreateFlashTCPSocket( } PP_Resource ResourceCreationImpl::CreateFontObject( - PP_Instance pp_instance, + PP_Instance instance, const PP_FontDescription_Dev* description) { - return PPB_Font_Impl::Create(instance_, *description); + return PPB_Font_Impl::Create(instance, *description); } PP_Resource ResourceCreationImpl::CreateGraphics2D( - PP_Instance pp_instance, + PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque) { - return PPB_Graphics2D_Impl::Create(instance_, size, is_always_opaque); + return PPB_Graphics2D_Impl::Create(instance, size, is_always_opaque); } PP_Resource ResourceCreationImpl::CreateGraphics3D( PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list) { - return PPB_Graphics3D_Impl::Create(instance_, share_context, attrib_list); + return PPB_Graphics3D_Impl::Create(instance, share_context, attrib_list); } PP_Resource ResourceCreationImpl::CreateGraphics3DRaw( PP_Instance instance, PP_Resource share_context, const int32_t* attrib_list) { - return PPB_Graphics3D_Impl::CreateRaw(instance_, share_context, attrib_list); + return PPB_Graphics3D_Impl::CreateRaw(instance, share_context, attrib_list); } -PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance pp_instance, +PP_Resource ResourceCreationImpl::CreateImageData(PP_Instance instance, PP_ImageDataFormat format, const PP_Size& size, PP_Bool init_to_zero) { - return PPB_ImageData_Impl::Create(instance_, format, size, init_to_zero); + return PPB_ImageData_Impl::Create(instance, format, size, init_to_zero); } PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( @@ -203,7 +202,7 @@ PP_Resource ResourceCreationImpl::CreateKeyboardInputEvent( data.character_text = string_var->value(); } - return PPB_InputEvent_Impl::Create(instance_, data); + return (new PPB_InputEvent_Impl(instance, data))->GetReference(); } PP_Resource ResourceCreationImpl::CreateMouseInputEvent( @@ -229,38 +228,38 @@ PP_Resource ResourceCreationImpl::CreateMouseInputEvent( data.mouse_position = *mouse_position; data.mouse_click_count = click_count; - return PPB_InputEvent_Impl::Create(instance_, data); + return (new PPB_InputEvent_Impl(instance, data))->GetReference(); } PP_Resource ResourceCreationImpl::CreateScrollbar(PP_Instance instance, PP_Bool vertical) { - return PPB_Scrollbar_Impl::Create(instance_, PP_ToBool(vertical)); + return PPB_Scrollbar_Impl::Create(instance, PP_ToBool(vertical)); } PP_Resource ResourceCreationImpl::CreateSurface3D( PP_Instance instance, PP_Config3D_Dev config, const int32_t* attrib_list) { - return PPB_Surface3D_Impl::Create(instance_, config, attrib_list); + return PPB_Surface3D_Impl::Create(instance, config, attrib_list); } PP_Resource ResourceCreationImpl::CreateTransport(PP_Instance instance, const char* name, const char* proto) { - return PPB_Transport_Impl::Create(instance_, name, proto); + return PPB_Transport_Impl::Create(instance, name, proto); } PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) { - return (new PPB_URLLoader_Impl(instance_, false))->GetReference(); + return (new PPB_URLLoader_Impl(instance, false))->GetReference(); } PP_Resource ResourceCreationImpl::CreateURLRequestInfo(PP_Instance instance) { - return (new PPB_URLRequestInfo_Impl(instance_))->GetReference(); + return (new PPB_URLRequestInfo_Impl(instance))->GetReference(); } PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) { scoped_refptr<PPB_VideoCapture_Impl> video_capture = - new PPB_VideoCapture_Impl(instance_); + new PPB_VideoCapture_Impl(instance); if (!video_capture->Init()) return 0; return video_capture->GetReference(); @@ -270,12 +269,12 @@ PP_Resource ResourceCreationImpl::CreateVideoDecoder( PP_Instance instance, PP_Resource context3d_id, const PP_VideoConfigElement* config) { - return PPB_VideoDecoder_Impl::Create(instance_, context3d_id, config); + return PPB_VideoDecoder_Impl::Create(instance, context3d_id, config); } PP_Resource ResourceCreationImpl::CreateVideoLayer(PP_Instance instance, PP_VideoLayerMode_Dev mode) { - return PPB_VideoLayer_Impl::Create(instance_, mode); + return PPB_VideoLayer_Impl::Create(instance, mode); } PP_Resource ResourceCreationImpl::CreateWheelInputEvent( @@ -293,7 +292,7 @@ PP_Resource ResourceCreationImpl::CreateWheelInputEvent( data.wheel_ticks = *wheel_ticks; data.wheel_scroll_by_page = PP_ToBool(scroll_by_page); - return PPB_InputEvent_Impl::Create(instance_, data); + return (new PPB_InputEvent_Impl(instance, data))->GetReference(); } } // namespace ppapi diff --git a/webkit/plugins/ppapi/resource_creation_impl.h b/webkit/plugins/ppapi/resource_creation_impl.h index 1b29cb5..64d0ff9 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.h +++ b/webkit/plugins/ppapi/resource_creation_impl.h @@ -115,8 +115,6 @@ class ResourceCreationImpl : public ::ppapi::FunctionGroupBase, PP_Bool scroll_by_page) OVERRIDE; private: - PluginInstance* instance_; - DISALLOW_COPY_AND_ASSIGN(ResourceCreationImpl); }; diff --git a/webkit/plugins/ppapi/resource_helper.cc b/webkit/plugins/ppapi/resource_helper.cc new file mode 100644 index 0000000..27f303d --- /dev/null +++ b/webkit/plugins/ppapi/resource_helper.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/plugins/ppapi/resource_helper.h" + +#include "base/logging.h" +#include "ppapi/shared_impl/resource.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/plugin_module.h" +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_tracker.h" + +namespace webkit { +namespace ppapi { + +// static +PluginInstance* ResourceHelper::GetPluginInstance( + const ::ppapi::Resource* resource) { + ResourceTracker* tracker = ResourceTracker::Get(); + return tracker->GetInstance(resource->pp_instance()); +} + +PluginModule* ResourceHelper::GetPluginModule( + const ::ppapi::Resource* resource) { + PluginInstance* instance = GetPluginInstance(resource); + return instance ? instance->module() : NULL; +} + +PluginDelegate* ResourceHelper::GetPluginDelegate( + const ::ppapi::Resource* resource) { + PluginInstance* instance = GetPluginInstance(resource); + return instance ? instance->delegate() : NULL; +} + +} // namespace ppapi +} // namespace webkit + diff --git a/webkit/plugins/ppapi/resource_helper.h b/webkit/plugins/ppapi/resource_helper.h new file mode 100644 index 0000000..d958889 --- /dev/null +++ b/webkit/plugins/ppapi/resource_helper.h @@ -0,0 +1,48 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_PLUGINS_PPAPI_RESOURCE_HELPER_H_ +#define WEBKIT_PLUGINS_PPAPI_RESOURCE_HELPER_H_ + +#include "base/basictypes.h" +#include "ppapi/c/pp_resource.h" + +namespace ppapi { +class Resource; +} + +namespace webkit { +namespace ppapi { + +class PluginInstance; +class PluginModule; +class PluginDelegate; + +// Helper functions for Resoruce implementations. +// +// This is specifically not designed to be a base class that derives from +// ppapi::Resource to avoid diamond inheritance if most of a resource class +// is implemented in the shared_impl (to share code with the proxy). +class ResourceHelper { + public: + // Returns the instance implementation object for the given resource, or NULL + // if the resource has outlived its instance. + static PluginInstance* GetPluginInstance(const ::ppapi::Resource* resource); + + // Returns the module for the given resource, or NULL if the resource has + // outlived its instance. + static PluginModule* GetPluginModule(const ::ppapi::Resource* resource); + + // Returns the plugin delegate for the given resource, or NULL if the + // resource has outlived its instance. + static PluginDelegate* GetPluginDelegate(const ::ppapi::Resource* resource); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(ResourceHelper); +}; + +} // namespace ppapi +} // namespace webkit + +#endif // WEBKIT_PLUGINS_PPAPI_RESOURCE_IMPL_HELPER_H_ diff --git a/webkit/plugins/ppapi/resource_tracker.cc b/webkit/plugins/ppapi/resource_tracker.cc index 18211e7..ee29686 100644 --- a/webkit/plugins/ppapi/resource_tracker.cc +++ b/webkit/plugins/ppapi/resource_tracker.cc @@ -14,6 +14,7 @@ #include "ppapi/shared_impl/function_group_base.h" #include "ppapi/shared_impl/id_assignment.h" #include "ppapi/shared_impl/tracker_base.h" +#include "webkit/plugins/ppapi/callbacks.h" #include "webkit/plugins/ppapi/npobject_var.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -21,8 +22,8 @@ #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" #include "webkit/plugins/ppapi/ppb_find_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" -#include "webkit/plugins/ppapi/resource.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" +#include "webkit/plugins/ppapi/resource_helper.h" using ppapi::CheckIdType; using ppapi::MakeTypedId; @@ -65,8 +66,7 @@ struct ResourceTracker::InstanceData { ResourceTracker* ResourceTracker::global_tracker_ = NULL; ResourceTracker* ResourceTracker::singleton_override_ = NULL; -ResourceTracker::ResourceTracker() - : last_resource_id_(0) { +ResourceTracker::ResourceTracker() { // Wire up the new shared resource tracker base to use our implementation. ::ppapi::TrackerBase::Init(&GetTrackerBase); } @@ -166,6 +166,20 @@ void ResourceTracker::CleanupInstanceData(PP_Instance instance, return this; } +void ResourceTracker::LastPluginRefWasDeleted(::ppapi::Resource* object) { + ::ppapi::ResourceTracker::LastPluginRefWasDeleted(object); + + // TODO(brettw) this should be removed when we have the callback tracker + // moved to the shared_impl. This will allow the logic to post aborts for + // any callbacks directly in the Resource::LastPluginRefWasDeleted function + // and we can remove this function altogether. + PluginModule* plugin_module = ResourceHelper::GetPluginModule(object); + if (plugin_module) { + plugin_module->GetCallbackTracker()->PostAbortForResource( + object->pp_resource()); + } +} + void ResourceTracker::AddNPObjectVar(NPObjectVar* object_var) { DCHECK(instance_map_.find(object_var->pp_instance()) != instance_map_.end()); InstanceData& data = *instance_map_[object_var->pp_instance()].get(); diff --git a/webkit/plugins/ppapi/resource_tracker.h b/webkit/plugins/ppapi/resource_tracker.h index 4802fab..52ddf10 100644 --- a/webkit/plugins/ppapi/resource_tracker.h +++ b/webkit/plugins/ppapi/resource_tracker.h @@ -36,7 +36,6 @@ namespace ppapi { class PluginInstance; class PluginModule; -class Resource; class ResourceTrackerTest; // This class maintains a global list of all live pepper resources. It allows @@ -58,6 +57,9 @@ class ResourceTracker : public ::ppapi::TrackerBase, virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE; virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; + // ppapi::ResourceTracker overrides. + virtual void LastPluginRefWasDeleted(::ppapi::Resource* object) OVERRIDE; + // PP_Vars ------------------------------------------------------------------- // Tracks all live NPObjectVar. This is so we can map between instance + @@ -109,7 +111,6 @@ class ResourceTracker : public ::ppapi::TrackerBase, PluginInstance* GetInstance(PP_Instance instance); private: - friend class Resource; friend class ResourceTrackerTest; typedef std::set<PP_Resource> ResourceSet; @@ -155,22 +156,8 @@ class ResourceTracker : public ::ppapi::TrackerBase, // See SetSingletonOverride above. static ResourceTracker* singleton_override_; - // Last assigned resource ID. - PP_Resource last_resource_id_; - ::ppapi::VarTracker var_tracker_; - // For each PP_Resource, keep the Resource* (as refptr) and plugin use count. - // This use count is different then Resource's RefCount, and is manipulated - // using this AddRefResource/UnrefResource. When it drops to zero, we just - // remove the resource from this resource tracker, but the resource object - // will be alive so long as some scoped_refptr still holds it's - // reference. This prevents plugins from forcing destruction of Resource - // objects. - typedef std::pair<scoped_refptr<Resource>, size_t> ResourceAndRefCount; - typedef base::hash_map<PP_Resource, ResourceAndRefCount> ResourceMap; - ResourceMap live_resources_; - // Like ResourceAndRefCount but for vars, which are associated with modules. typedef std::pair<scoped_refptr< ::ppapi::Var>, size_t> VarAndRefCount; typedef base::hash_map<int32, VarAndRefCount> VarMap; diff --git a/webkit/plugins/ppapi/resource_tracker_unittest.cc b/webkit/plugins/ppapi/resource_tracker_unittest.cc index c43b1d2..0b418bb 100644 --- a/webkit/plugins/ppapi/resource_tracker_unittest.cc +++ b/webkit/plugins/ppapi/resource_tracker_unittest.cc @@ -23,22 +23,6 @@ namespace ppapi { namespace { -// Tracked Resources ----------------------------------------------------------- - -class TrackedMockResource : public MockResource { - public: - static int tracked_objects_alive; - - TrackedMockResource(PluginInstance* instance) : MockResource(instance) { - tracked_objects_alive++; - } - ~TrackedMockResource() { - tracked_objects_alive--; - } -}; - -int TrackedMockResource::tracked_objects_alive = 0; - // Tracked NPObjects ----------------------------------------------------------- int g_npobjects_alive = 0; diff --git a/webkit/plugins/ppapi/url_request_info_unittest.cc b/webkit/plugins/ppapi/url_request_info_unittest.cc index ef86615..adeffca 100644 --- a/webkit/plugins/ppapi/url_request_info_unittest.cc +++ b/webkit/plugins/ppapi/url_request_info_unittest.cc @@ -52,7 +52,7 @@ class URLRequestInfoTest : public PpapiUnittest { PpapiUnittest::SetUp(); // Must be after our base class's SetUp for the instance to be valid. - info_ = new PPB_URLRequestInfo_Impl(instance()); + info_ = new PPB_URLRequestInfo_Impl(instance()->pp_instance()); } static void SetUpTestCase() { |