From e16c7a1cd385933d7e5f306bf858db9d0cd8f7e8 Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Thu, 5 Dec 2013 16:30:08 +0000 Subject: [PATCH] Move the last-focused and last-mouse-event pepper plugin instance variable from RenderFrame back to RenderView. I moved this in r238191, but as Nasko pointed out this will break once there are multiple RenderFrames per RenderView. So instead I'm moving them back for now. Once RenderView is gone, the browser will know which frame is in focus, and the IPCs which use thse variables now will go to the right RenderFrame. At that point these variables can move back again. BUG=304341 R=nasko@chromium.org Review URL: https://codereview.chromium.org/105713002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238979 0039d316-1c4b-4281-b951-d872f2087c98 --- content/renderer/render_frame_impl.cc | 63 +++++++++---------- content/renderer/render_frame_impl.h | 16 ----- content/renderer/render_view_impl.cc | 34 +++++----- content/renderer/render_view_impl.h | 29 +++++++++ .../renderer/text_input_client_observer.cc | 5 +- 5 files changed, 79 insertions(+), 68 deletions(-) diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index 2278e9239f08ed..9aa4963437bbf1 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -125,12 +125,7 @@ RenderFrameImpl::RenderFrameImpl(RenderViewImpl* render_view, int routing_id) : render_view_(render_view), routing_id_(routing_id), is_swapped_out_(false), - is_detaching_(false) -#if defined(ENABLE_PLUGINS) - , focused_pepper_plugin_(NULL), - pepper_last_mouse_event_target_(NULL) -#endif -{ + is_detaching_(false) { RenderThread::Get()->AddRoute(routing_id_, this); #if defined(ENABLE_PLUGINS) new PepperBrowserConnection(this); @@ -164,9 +159,9 @@ void RenderFrameImpl::PepperInstanceDeleted( PepperPluginInstanceImpl* instance) { active_pepper_instances_.erase(instance); - if (pepper_last_mouse_event_target_ == instance) - pepper_last_mouse_event_target_ = NULL; - if (focused_pepper_plugin_ == instance) + if (render_view_->pepper_last_mouse_event_target() == instance) + render_view_->set_pepper_last_mouse_event_target(NULL); + if (render_view_->focused_pepper_plugin() == instance) PepperFocusChanged(instance, false); } @@ -178,21 +173,21 @@ void RenderFrameImpl::PepperDidChangeCursor( // picked up until the plugin gets the next input event. That is bad if, e.g., // the plugin would like to set an invisible cursor when there isn't any user // input for a while. - if (instance == pepper_last_mouse_event_target_) + if (instance == render_view_->pepper_last_mouse_event_target()) GetRenderWidget()->didChangeCursor(cursor); } void RenderFrameImpl::PepperDidReceiveMouseEvent( PepperPluginInstanceImpl* instance) { - pepper_last_mouse_event_target_ = instance; + render_view_->set_pepper_last_mouse_event_target(instance); } void RenderFrameImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, bool focused) { if (focused) - focused_pepper_plugin_ = instance; - else if (focused_pepper_plugin_ == instance) - focused_pepper_plugin_ = NULL; + render_view_->set_focused_pepper_plugin(instance); + else if (render_view_->focused_pepper_plugin() == instance) + render_view_->set_focused_pepper_plugin(NULL); GetRenderWidget()->UpdateTextInputType(); GetRenderWidget()->UpdateSelectionBounds(); @@ -200,7 +195,7 @@ void RenderFrameImpl::PepperFocusChanged(PepperPluginInstanceImpl* instance, void RenderFrameImpl::PepperTextInputTypeChanged( PepperPluginInstanceImpl* instance) { - if (instance != focused_pepper_plugin_) + if (instance != render_view_->focused_pepper_plugin()) return; GetRenderWidget()->UpdateTextInputType(); @@ -212,14 +207,14 @@ void RenderFrameImpl::PepperTextInputTypeChanged( void RenderFrameImpl::PepperCaretPositionChanged( PepperPluginInstanceImpl* instance) { - if (instance != focused_pepper_plugin_) + if (instance != render_view_->focused_pepper_plugin()) return; GetRenderWidget()->UpdateSelectionBounds(); } void RenderFrameImpl::PepperCancelComposition( PepperPluginInstanceImpl* instance) { - if (instance != focused_pepper_plugin_) + if (instance != render_view_->focused_pepper_plugin()) return; Send(new ViewHostMsg_ImeCancelComposition(render_view_->GetRoutingID()));; #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA) @@ -229,7 +224,7 @@ void RenderFrameImpl::PepperCancelComposition( void RenderFrameImpl::PepperSelectionChanged( PepperPluginInstanceImpl* instance) { - if (instance != focused_pepper_plugin_) + if (instance != render_view_->focused_pepper_plugin()) return; render_view_->SyncSelectionIfRequired(); } @@ -246,17 +241,11 @@ RenderWidgetFullscreenPepper* RenderFrameImpl::CreatePepperFullscreenContainer( return widget; } -bool RenderFrameImpl::GetPepperCaretBounds(gfx::Rect* rect) { - if (!focused_pepper_plugin_) - return false; - *rect = focused_pepper_plugin_->GetCaretBounds(); - return true; -} - bool RenderFrameImpl::IsPepperAcceptingCompositionEvents() const { - if (!focused_pepper_plugin_) + if (!render_view_->focused_pepper_plugin()) return false; - return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); + return render_view_->focused_pepper_plugin()-> + IsPluginAcceptingCompositionEvents(); } void RenderFrameImpl::PluginCrashed(const base::FilePath& plugin_path, @@ -347,7 +336,7 @@ void RenderFrameImpl::WillHandleMouseEvent(const blink::WebMouseEvent& event) { // is, we set |pepper_last_mouse_event_target_| to NULL here. If a plugin gets // the event, it will notify us via DidReceiveMouseEvent() and set itself as // |pepper_last_mouse_event_target_|. - pepper_last_mouse_event_target_ = NULL; + render_view_->set_pepper_last_mouse_event_target(NULL); } void RenderFrameImpl::SimulateImeSetComposition( @@ -381,15 +370,19 @@ void RenderFrameImpl::OnImeSetComposition( // The code below mimics the behavior of WebCore::Editor::setComposition. // Empty -> nonempty: composition started. - if (pepper_composition_text_.empty() && !text.empty()) - focused_pepper_plugin_->HandleCompositionStart(base::string16()); + if (pepper_composition_text_.empty() && !text.empty()) { + render_view_->focused_pepper_plugin()->HandleCompositionStart( + base::string16()); + } // Nonempty -> empty: composition canceled. - if (!pepper_composition_text_.empty() && text.empty()) - focused_pepper_plugin_->HandleCompositionEnd(base::string16()); + if (!pepper_composition_text_.empty() && text.empty()) { + render_view_->focused_pepper_plugin()->HandleCompositionEnd( + base::string16()); + } pepper_composition_text_ = text; // Nonempty: composition is ongoing. if (!pepper_composition_text_.empty()) { - focused_pepper_plugin_->HandleCompositionUpdate( + render_view_->focused_pepper_plugin()->HandleCompositionUpdate( pepper_composition_text_, underlines, selection_start, selection_end); } @@ -435,8 +428,8 @@ void RenderFrameImpl::OnImeConfirmComposition( } else { // Mimics the order of events sent by WebKit. // See WebCore::Editor::setComposition() for the corresponding code. - focused_pepper_plugin_->HandleCompositionEnd(last_text); - focused_pepper_plugin_->HandleTextInput(last_text); + render_view_->focused_pepper_plugin()->HandleCompositionEnd(last_text); + render_view_->focused_pepper_plugin()->HandleTextInput(last_text); } pepper_composition_text_.clear(); } diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h index 4671fb5389d01c..b851c88eb80db5 100644 --- a/content/renderer/render_frame_impl.h +++ b/content/renderer/render_frame_impl.h @@ -102,9 +102,6 @@ class CONTENT_EXPORT RenderFrameImpl RenderWidgetFullscreenPepper* CreatePepperFullscreenContainer( PepperPluginInstanceImpl* plugin); - // Retrieves the current caret position if a PPAPI plugin has focus. - bool GetPepperCaretBounds(gfx::Rect* rect); - bool IsPepperAcceptingCompositionEvents() const; // Notification that the given plugin has crashed. @@ -147,10 +144,6 @@ class CONTENT_EXPORT RenderFrameImpl const base::string16& text, const gfx::Range& replacement_range, bool keep_selection); - - PepperPluginInstanceImpl* focused_pepper_plugin() { - return focused_pepper_plugin_; - } #endif // ENABLE_PLUGINS // IPC::Sender @@ -329,18 +322,9 @@ class CONTENT_EXPORT RenderFrameImpl typedef std::set PepperPluginSet; PepperPluginSet active_pepper_instances_; - // Whether or not the focus is on a PPAPI plugin - PepperPluginInstanceImpl* focused_pepper_plugin_; - // Current text input composition text. Empty if no composition is in // progress. base::string16 pepper_composition_text_; - - // The plugin instance that received the last mouse event. It is set to NULL - // if the last mouse event went to elements other than Pepper plugins. - // |pepper_last_mouse_event_target_| is not owned by this class. We can know - // about when it is destroyed via InstanceDeleted(). - PepperPluginInstanceImpl* pepper_last_mouse_event_target_; #endif // All the registered observers. diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index a45d94b6e56f63..b687069b743912 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -862,6 +862,10 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) #endif #if defined(OS_WIN) focused_plugin_id_(-1), +#endif +#if defined(ENABLE_PLUGINS) + focused_pepper_plugin_(NULL), + pepper_last_mouse_event_target_(NULL), #endif enumeration_completion_id_(0), load_progress_tracker_(new LoadProgressTracker(this)), @@ -4413,9 +4417,8 @@ void RenderViewImpl::SyncSelectionIfRequired() { size_t offset; gfx::Range range; #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { - main_render_frame_->focused_pepper_plugin()->GetSurroundingText( - &text, &range); + if (focused_pepper_plugin_) { + focused_pepper_plugin_->GetSurroundingText(&text, &range); offset = 0; // Pepper API does not support offset reporting. // TODO(kinaba): cut as needed. } else @@ -5679,8 +5682,8 @@ void RenderViewImpl::OnImeSetComposition( int selection_start, int selection_end) { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { - main_render_frame_->OnImeSetComposition( + if (focused_pepper_plugin_) { + focused_pepper_plugin_->render_frame()->OnImeSetComposition( text, underlines, selection_start, selection_end); return; } @@ -5722,8 +5725,8 @@ void RenderViewImpl::OnImeConfirmComposition( const gfx::Range& replacement_range, bool keep_selection) { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { - main_render_frame_->OnImeConfirmComposition( + if (focused_pepper_plugin_) { + focused_pepper_plugin_->render_frame()->OnImeConfirmComposition( text, replacement_range, keep_selection); return; } @@ -5785,21 +5788,20 @@ void RenderViewImpl::SetDeviceScaleFactor(float device_scale_factor) { ui::TextInputType RenderViewImpl::GetTextInputType() { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) - return main_render_frame_->focused_pepper_plugin()->text_input_type(); + if (focused_pepper_plugin_) + return focused_pepper_plugin_->text_input_type(); #endif return RenderWidget::GetTextInputType(); } void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { + if (focused_pepper_plugin_) { // TODO(kinaba) http://crbug.com/101101 // Current Pepper IME API does not handle selection bounds. So we simply // use the caret position as an empty range for now. It will be updated // after Pepper API equips features related to surrounding text retrieval. - gfx::Rect caret = - main_render_frame_->focused_pepper_plugin()->GetCaretBounds(); + gfx::Rect caret = focused_pepper_plugin_->GetCaretBounds(); *start = caret; *end = caret; return; @@ -5815,7 +5817,7 @@ void RenderViewImpl::GetCompositionCharacterBounds( bounds->clear(); #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { + if (focused_pepper_plugin_) { return; } #endif @@ -5847,7 +5849,7 @@ void RenderViewImpl::GetCompositionCharacterBounds( void RenderViewImpl::GetCompositionRange(gfx::Range* range) { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) { + if (focused_pepper_plugin_) { return; } #endif @@ -5857,8 +5859,8 @@ void RenderViewImpl::GetCompositionRange(gfx::Range* range) { bool RenderViewImpl::CanComposeInline() { #if defined(ENABLE_PLUGINS) - if (main_render_frame_->focused_pepper_plugin()) - return main_render_frame_->IsPepperAcceptingCompositionEvents(); + if (focused_pepper_plugin_) + return focused_pepper_plugin_->IsPluginAcceptingCompositionEvents(); #endif return true; } diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h index f2de2cdd77b84f..1a18fb6c7fb470 100644 --- a/content/renderer/render_view_impl.h +++ b/content/renderer/render_view_impl.h @@ -280,6 +280,19 @@ class CONTENT_EXPORT RenderViewImpl // Plugin-related functions -------------------------------------------------- #if defined(ENABLE_PLUGINS) + PepperPluginInstanceImpl* focused_pepper_plugin() { + return focused_pepper_plugin_; + } + void set_focused_pepper_plugin(PepperPluginInstanceImpl* plugin) { + focused_pepper_plugin_ = plugin; + } + PepperPluginInstanceImpl* pepper_last_mouse_event_target() { + return pepper_last_mouse_event_target_; + } + void set_pepper_last_mouse_event_target(PepperPluginInstanceImpl* plugin) { + pepper_last_mouse_event_target_ = plugin; + } + #if defined(OS_MACOSX) || defined(OS_WIN) // Informs the render view that the given plugin has gained or lost focus. void PluginFocusChanged(bool focused, int plugin_id); @@ -1422,6 +1435,22 @@ class CONTENT_EXPORT RenderViewImpl int focused_plugin_id_; #endif +#if defined(ENABLE_PLUGINS) + // TODO(jam): these belong on RenderFrame, once the browser knows which frame + // is focused and sends the IPCs which use these to the correct frame. Until + // then, we must store these on RenderView as that's the one place that knows + // about all the RenderFrames for a page. + + // Whether or not the focus is on a PPAPI plugin + PepperPluginInstanceImpl* focused_pepper_plugin_; + + // The plugin instance that received the last mouse event. It is set to NULL + // if the last mouse event went to elements other than Pepper plugins. + // |pepper_last_mouse_event_target_| is not owned by this class. We depend on + // the RenderFrameImpl to NULL it out when it destructs. + PepperPluginInstanceImpl* pepper_last_mouse_event_target_; +#endif + // Misc ---------------------------------------------------------------------- // The current and pending file chooser completion objects. If the queue is diff --git a/content/renderer/text_input_client_observer.cc b/content/renderer/text_input_client_observer.cc index d15d1d421ac769..5ce95ff6093742 100644 --- a/content/renderer/text_input_client_observer.cc +++ b/content/renderer/text_input_client_observer.cc @@ -6,6 +6,7 @@ #include "base/memory/scoped_ptr.h" #include "content/common/text_input_client_messages.h" +#include "content/renderer/pepper/pepper_plugin_instance_impl.h" #include "content/renderer/render_view_impl.h" #include "third_party/WebKit/public/platform/WebPoint.h" #include "third_party/WebKit/public/platform/WebRect.h" @@ -52,7 +53,9 @@ void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { gfx::Rect rect; #if defined(ENABLE_PLUGINS) - if (!render_view_impl_->main_render_frame()->GetPepperCaretBounds(&rect)) + if (render_view_impl_->focused_pepper_plugin()) { + rect = render_view_impl_->focused_pepper_plugin()->GetCaretBounds(); + } else #endif { blink::WebFrame* frame = webview()->focusedFrame();