diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 04:25:01 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 04:25:01 +0000 |
commit | 53900d507cd50344c2e73bb988671044f1787911 (patch) | |
tree | 7cd58934003dc610f544f8e682ac8c6040715f65 /chrome/renderer | |
parent | 047e07212c7da949be3107a70e3fe9ecb160d818 (diff) | |
download | chromium_src-53900d507cd50344c2e73bb988671044f1787911.zip chromium_src-53900d507cd50344c2e73bb988671044f1787911.tar.gz chromium_src-53900d507cd50344c2e73bb988671044f1787911.tar.bz2 |
Implement more of Flush properly. This adds support for waiting on the message
loop so we can now enforce that there is only one pending Flush at a time.
Also removes the ability to have multiple flushes pending at the same time.
TEST=covered by ppapi unit test
BUG=none
Review URL: http://codereview.chromium.org/2862002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/pepper_devices_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 50 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 15 | ||||
-rwxr-xr-x | chrome/renderer/render_view.cc | 34 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 6 |
5 files changed, 91 insertions, 16 deletions
diff --git a/chrome/renderer/pepper_devices_unittest.cc b/chrome/renderer/pepper_devices_unittest.cc index c3903b3..9327ed0 100644 --- a/chrome/renderer/pepper_devices_unittest.cc +++ b/chrome/renderer/pepper_devices_unittest.cc @@ -182,7 +182,7 @@ void PepperDeviceTest::SetUp() { // Normally the RenderView creates the pepper plugin and registers it with // its internal list. Since we're creating it manually, we have to reach in // and register it to prevent tear-down from asserting. - view_->current_pepper_plugins_.insert(pepper_plugin_); + view_->current_oldstyle_pepper_plugins_.insert(pepper_plugin_); active_tests[npp()] = this; diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 535dff1..40ef961 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -6,6 +6,7 @@ #include "app/surface/transport_dib.h" #include "base/scoped_ptr.h" +#include "webkit/glue/plugins/pepper_plugin_instance.h" #if defined(OS_MACOSX) #include "chrome/common/render_messages.h" @@ -46,6 +47,55 @@ PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) : render_view_(render_view) { } +void PepperPluginDelegateImpl::ViewInitiatedPaint() { + // Notify all of our instances that we started painting. This is used for + // internal bookkeeping only, so we know that the set can not change under + // us. + for (std::set<pepper::PluginInstance*>::iterator i = + active_instances_.begin(); + i != active_instances_.end(); ++i) + (*i)->ViewInitiatedPaint(); +} + +void PepperPluginDelegateImpl::ViewFlushedPaint() { + // Notify all instances that we painted. This will call into the plugin, and + // we it may ask to close itself as a result. This will, in turn, modify our + // set, possibly invalidating the iterator. So we iterate on a copy that + // won't change out from under us. + std::set<pepper::PluginInstance*> plugins = active_instances_; + for (std::set<pepper::PluginInstance*>::iterator i = plugins.begin(); + i != plugins.end(); ++i) { + // The copy above makes sure our iterator is never invalid if some plugins + // are destroyed. But some plugin may decide to close all of its views in + // response to a paint in one of them, so we need to make sure each one is + // still "current" before using it. + // + // It's possible that a plugin was destroyed, but another one was created + // with the same address. In this case, we'll call ViewFlushedPaint on that + // new plugin. But that's OK for this particular case since we're just + // notifying all of our instances that the view flushed, and the new one is + // one of our instances. + // + // What about the case where a new one is created in a callback at a new + // address and we don't issue the callback? We're still OK since this + // callback is used for flush callbacks and we could not have possibly + // started a new paint (ViewInitiatedPaint) for the new plugin while + // processing a previous paint for an existing one. + if (active_instances_.find(*i) != active_instances_.end()) + (*i)->ViewFlushedPaint(); + } +} + +void PepperPluginDelegateImpl::InstanceCreated( + pepper::PluginInstance* instance) { + active_instances_.insert(instance); +} + +void PepperPluginDelegateImpl::InstanceDeleted( + pepper::PluginInstance* instance) { + active_instances_.erase(instance); +} + pepper::PluginDelegate::PlatformImage2D* PepperPluginDelegateImpl::CreateImage2D(int width, int height) { uint32 buffer_size = width * height * 4; diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index 870a032..8b6f0d2 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -5,25 +5,40 @@ #ifndef CHROME_RENDERER_PEPPER_PLUGIN_DELEGATE_IMPL_H_ #define CHROME_RENDERER_PEPPER_PLUGIN_DELEGATE_IMPL_H_ +#include <set> + #include "base/basictypes.h" #include "base/weak_ptr.h" #include "webkit/glue/plugins/pepper_plugin_delegate.h" class RenderView; +namespace pepper { +class PluginInstance; +} + class PepperPluginDelegateImpl : public pepper::PluginDelegate, public base::SupportsWeakPtr<PepperPluginDelegateImpl> { public: explicit PepperPluginDelegateImpl(RenderView* render_view); + // Called by RenderView to tell us about painting events, these two functions + // just correspond to the DidInitiatePaint and DidFlushPaint in R.V.. + void ViewInitiatedPaint(); + void ViewFlushedPaint(); + // pepper::PluginDelegate implementation. + virtual void InstanceCreated(pepper::PluginInstance* instance); + virtual void InstanceDeleted(pepper::PluginInstance* instance); virtual PlatformImage2D* CreateImage2D(int width, int height); private: // Pointer to the RenderView that owns us. RenderView* render_view_; + std::set<pepper::PluginInstance*> active_instances_; + DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl); }; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index b99adcd..089e0f2 100755 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -3270,7 +3270,7 @@ webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( if (use_pepper_host) { WebPluginDelegatePepper* pepper_plugin = WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); - current_pepper_plugins_.insert(pepper_plugin); + current_oldstyle_pepper_plugins_.insert(pepper_plugin); return pepper_plugin; } else { #if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. @@ -3783,12 +3783,12 @@ void RenderView::InsertCSS(const std::wstring& frame_xpath, void RenderView::OnPepperPluginDestroy( WebPluginDelegatePepper* pepper_plugin) { std::set<WebPluginDelegatePepper*>::iterator found_pepper = - current_pepper_plugins_.find(pepper_plugin); - if (found_pepper == current_pepper_plugins_.end()) { + current_oldstyle_pepper_plugins_.find(pepper_plugin); + if (found_pepper == current_oldstyle_pepper_plugins_.end()) { NOTREACHED(); return; } - current_pepper_plugins_.erase(found_pepper); + current_oldstyle_pepper_plugins_.erase(found_pepper); // The plugin could have been destroyed while it was waiting for a file // choose callback, so check all pending completion callbacks and NULL them. @@ -4284,12 +4284,15 @@ void RenderView::OnResize(const gfx::Size& new_size, } void RenderView::DidInitiatePaint() { - // Notify any pepper plugins that we started painting. The plugin "should" - // never notified that we started painting, this is used for internal - // bookkeeping only, so we know that the set can not change under us. + // Notify the pepper plugins that we started painting. + pepper_delegate_.ViewInitiatedPaint(); + + // Notify any "old-style" pepper plugins that we started painting. This is + // used for internal bookkeeping only, so we know that the set can not change + // under us. for (std::set<WebPluginDelegatePepper*>::iterator i = - current_pepper_plugins_.begin(); - i != current_pepper_plugins_.end(); ++i) + current_oldstyle_pepper_plugins_.begin(); + i != current_oldstyle_pepper_plugins_.end(); ++i) (*i)->RenderViewInitiatedPaint(); } @@ -4298,14 +4301,22 @@ void RenderView::DidFlushPaint() { // and we it may ask to close itself as a result. This will, in turn, modify // our set, possibly invalidating the iterator. So we iterate on a copy that // won't change out from under us. - std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_; + pepper_delegate_.ViewFlushedPaint(); + + // Notify any old-style pepper plugins that we painted. This will call into + // the plugin, and we it may ask to close itself as a result. This will, in + // turn, modify our set, possibly invalidating the iterator. So we iterate on + // a copy that won't change out from under us. + // This should be deleted when we don't support old Pepper anymore. + std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_; for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); i != plugins.end(); ++i) { // The copy above makes sure our iterator is never invalid if some plugins // are destroyed. But some plugin may decide to close all of its views in // response to a paint in one of them, so we need to make sure each one is // still "current" before using it. - if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end()) + if (current_oldstyle_pepper_plugins_.find(*i) != + current_oldstyle_pepper_plugins_.end()) (*i)->RenderViewFlushedPaint(); } @@ -4329,7 +4340,6 @@ void RenderView::DidFlushPaint() { } } - void RenderView::OnClearFocusedNode() { if (webview()) webview()->clearFocusedNode(); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 34457ac..3d0789e 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -1179,9 +1179,9 @@ class RenderView : public RenderWidget, std::set<WebPluginDelegateProxy*> plugin_delegates_; #endif - // A list of all pepper plugins that we've created that haven't been - // destroyed yet. - std::set<WebPluginDelegatePepper*> current_pepper_plugins_; + // A list of all Pepper v1 plugins that we've created that haven't been + // destroyed yet. Pepper v2 plugins are tracked by the pepper_delegate_. + std::set<WebPluginDelegatePepper*> current_oldstyle_pepper_plugins_; // Helper objects ------------------------------------------------------------ |