Skip to content

Commit

Permalink
Move the last-focused and last-mouse-event pepper plugin instance var…
Browse files Browse the repository at this point in the history
…iable 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
  • Loading branch information
jam@chromium.org committed Dec 5, 2013
1 parent 2c20618 commit e16c7a1
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 68 deletions.
63 changes: 28 additions & 35 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -178,29 +173,29 @@ 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();
}

void RenderFrameImpl::PepperTextInputTypeChanged(
PepperPluginInstanceImpl* instance) {
if (instance != focused_pepper_plugin_)
if (instance != render_view_->focused_pepper_plugin())
return;

GetRenderWidget()->UpdateTextInputType();
Expand All @@ -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)
Expand All @@ -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();
}
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down
16 changes: 0 additions & 16 deletions content/renderer/render_frame_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -329,18 +322,9 @@ class CONTENT_EXPORT RenderFrameImpl
typedef std::set<PepperPluginInstanceImpl*> 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.
Expand Down
34 changes: 18 additions & 16 deletions content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions content/renderer/render_view_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion content/renderer/text_input_client_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e16c7a1

Please sign in to comment.