From 87b1c2fde65b570b9fd546d79375e80ce73175ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Thu, 13 Mar 2014 20:15:58 +0100 Subject: Add code to properly initialize a NPAPI plugin with aura --- .../child/npapi/webplugin_delegate_impl_aura.cc | 51 ++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/content/child/npapi/webplugin_delegate_impl_aura.cc b/content/child/npapi/webplugin_delegate_impl_aura.cc index 6abf5f9..a0fa4a0 100644 --- a/content/child/npapi/webplugin_delegate_impl_aura.cc +++ b/content/child/npapi/webplugin_delegate_impl_aura.cc @@ -11,11 +11,22 @@ using blink::WebInputEvent; namespace content { -WebPluginDelegateImpl::WebPluginDelegateImpl(WebPlugin* plugin, - PluginInstance* instance) { +WebPluginDelegateImpl::WebPluginDelegateImpl( + WebPlugin* plugin, + PluginInstance* instance) + : windowed_handle_(0), + windowed_did_set_window_(false), + windowless_(false), + plugin_(plugin), + instance_(instance), + quirks_(0), + handle_event_depth_(0), + first_set_window_call_(true) { + memset(&window_, 0, sizeof(window_)); } WebPluginDelegateImpl::~WebPluginDelegateImpl() { + DestroyInstance(); } bool WebPluginDelegateImpl::PlatformInitialize() { @@ -30,6 +41,7 @@ void WebPluginDelegateImpl::Paint(SkCanvas* canvas, const gfx::Rect& rect) { } bool WebPluginDelegateImpl::WindowedCreatePlugin() { + window_.window = 0; return true; } @@ -39,10 +51,43 @@ void WebPluginDelegateImpl::WindowedDestroyWindow() { bool WebPluginDelegateImpl::WindowedReposition( const gfx::Rect& window_rect, const gfx::Rect& clip_rect) { + if (window_rect == window_rect_ && clip_rect == clip_rect_) + return false; + + window_rect_ = window_rect; + clip_rect_ = clip_rect; + return true; } void WebPluginDelegateImpl::WindowedSetWindow() { + if (!instance_.get()) + return; + + // See https://bugzilla.mozilla.org/show_bug.cgi?id=108347 + // If we call NPP_SetWindow with a <= 0 width or height, problems arise in + // Flash (and possibly other plugins). + // TODO(piman): the Mozilla code suggests that for the Java plugin, we should + // still call NPP_SetWindow in that case. We need to verify that. + if (window_rect_.width() <= 0 || window_rect_.height() <= 0) { + return; + } + + window_.clipRect.top = clip_rect_.y(); + window_.clipRect.left = clip_rect_.x(); + window_.clipRect.bottom = clip_rect_.y() + clip_rect_.height(); + window_.clipRect.right = clip_rect_.x() + clip_rect_.width(); + window_.height = window_rect_.height(); + window_.width = window_rect_.width(); + window_.x = window_rect_.x(); + window_.y = window_rect_.y(); + window_.type = NPWindowTypeWindow; + + // Reset this flag before entering the instance in case of side-effects. + windowed_did_set_window_ = true; + + NPError err = instance()->NPP_SetWindow(&window_); + DCHECK(err == NPERR_NO_ERROR); } void WebPluginDelegateImpl::WindowlessUpdateGeometry( @@ -55,7 +100,7 @@ void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context, } bool WebPluginDelegateImpl::PlatformSetPluginHasFocus(bool focused) { - return true; + return false; } bool WebPluginDelegateImpl::PlatformHandleInputEvent( -- 1.8.3.2