summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/proxy/ppapi_messages.h2
-rw-r--r--ppapi/proxy/ppb_text_input_proxy.cc44
-rw-r--r--ppapi/proxy/ppb_text_input_proxy.h1
-rw-r--r--ppapi/shared_impl/ppb_instance_shared.cc3
-rw-r--r--ppapi/shared_impl/ppb_instance_shared.h5
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc20
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h4
7 files changed, 55 insertions, 24 deletions
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index 8d7d0fc..a6390f4 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -973,8 +973,6 @@ IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBTextInput_UpdateCaretPosition,
PP_Rect /* bounding_box */)
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBTextInput_CancelCompositionText,
PP_Instance /* instance */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBTextInput_SelectionChanged,
- PP_Instance /* instance */)
IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBTextInput_UpdateSurroundingText,
PP_Instance /* instance */,
std::string /* text */,
diff --git a/ppapi/proxy/ppb_text_input_proxy.cc b/ppapi/proxy/ppb_text_input_proxy.cc
index e7434e0..3d2f873 100644
--- a/ppapi/proxy/ppb_text_input_proxy.cc
+++ b/ppapi/proxy/ppb_text_input_proxy.cc
@@ -6,12 +6,32 @@
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/ppb_instance_shared.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h"
namespace ppapi {
namespace proxy {
+namespace {
+
+void RequestSurroundingText(PP_Instance instance) {
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return; // Instance has gone away while message was pending.
+
+ // Just fake out a RequestSurroundingText message to the proxy for the PPP
+ // interface.
+ InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPB_TEXT_INPUT);
+ if (!proxy)
+ return;
+ proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText(
+ API_ID_PPP_TEXT_INPUT, instance,
+ PPB_Instance_Shared::kExtraCharsForTextInput));
+}
+
+} // namespace
+
PPB_TextInput_Proxy::PPB_TextInput_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher) {
}
@@ -43,8 +63,19 @@ void PPB_TextInput_Proxy::CancelCompositionText(PP_Instance instance) {
}
void PPB_TextInput_Proxy::SelectionChanged(PP_Instance instance) {
- dispatcher()->Send(new PpapiHostMsg_PPBTextInput_SelectionChanged(
- API_ID_PPB_TEXT_INPUT, instance));
+ // The "right" way to do this is to send the message to the host. However,
+ // all it will do it call RequestSurroundingText with a hardcoded number of
+ // characters in response, which is an entire IPC round-trip.
+ //
+ // We can avoid this round-trip by just implementing the
+ // RequestSurroundingText logic in the plugin process. If the logic in the
+ // host becomes more complex (like a more adaptive number of characters),
+ // we'll need to reevanuate whether we want to do the round trip instead.
+ //
+ // Be careful to post a task to avoid reentering the plugin.
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&RequestSurroundingText, instance));
}
void PPB_TextInput_Proxy::UpdateSurroundingText(PP_Instance instance,
@@ -64,8 +95,6 @@ bool PPB_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) {
OnMsgUpdateCaretPosition)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_CancelCompositionText,
OnMsgCancelCompositionText)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_SelectionChanged,
- OnMsgSelectionChanged)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateSurroundingText,
OnMsgUpdateSurroundingText)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -97,13 +126,6 @@ void PPB_TextInput_Proxy::OnMsgCancelCompositionText(PP_Instance instance) {
enter.functions()->CancelCompositionText(instance);
}
-void PPB_TextInput_Proxy::OnMsgSelectionChanged(PP_Instance instance) {
- ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance,
- true);
- if (enter.succeeded())
- enter.functions()->SelectionChanged(instance);
-}
-
void PPB_TextInput_Proxy::OnMsgUpdateSurroundingText(PP_Instance instance,
const std::string& text,
uint32_t caret,
diff --git a/ppapi/proxy/ppb_text_input_proxy.h b/ppapi/proxy/ppb_text_input_proxy.h
index e5226a4..066ac5b 100644
--- a/ppapi/proxy/ppb_text_input_proxy.h
+++ b/ppapi/proxy/ppb_text_input_proxy.h
@@ -51,7 +51,6 @@ class PPB_TextInput_Proxy
PP_Rect caret,
PP_Rect bounding_box);
void OnMsgCancelCompositionText(PP_Instance instance);
- void OnMsgSelectionChanged(PP_Instance instance);
void OnMsgUpdateSurroundingText(PP_Instance instance,
const std::string& text,
uint32_t caret,
diff --git a/ppapi/shared_impl/ppb_instance_shared.cc b/ppapi/shared_impl/ppb_instance_shared.cc
index 22e263a..5a29a99 100644
--- a/ppapi/shared_impl/ppb_instance_shared.cc
+++ b/ppapi/shared_impl/ppb_instance_shared.cc
@@ -16,6 +16,9 @@
namespace ppapi {
+// static
+const int PPB_Instance_Shared::kExtraCharsForTextInput = 100;
+
PPB_Instance_Shared::~PPB_Instance_Shared() {
}
diff --git a/ppapi/shared_impl/ppb_instance_shared.h b/ppapi/shared_impl/ppb_instance_shared.h
index 385d805..eed82e1 100644
--- a/ppapi/shared_impl/ppb_instance_shared.h
+++ b/ppapi/shared_impl/ppb_instance_shared.h
@@ -33,6 +33,11 @@ class PPAPI_SHARED_EXPORT PPB_Instance_Shared
bool ValidateSetCursorParams(PP_MouseCursor_Type type,
PP_Resource image,
const PP_Point* hot_spot);
+
+ // The length of text to request as a surrounding context of selection.
+ // For now, the value is copied from the one with render_view_impl.cc.
+ // TODO(kinaba) implement a way to dynamically sync the requirement.
+ static const int kExtraCharsForTextInput;
};
} // namespace ppapi
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 037e1a9..ffb0c17 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -158,11 +158,6 @@ namespace {
// that they don't accept texts.
const ui::TextInputType kPluginDefaultTextInputType = ui::TEXT_INPUT_TYPE_TEXT;
-// The length of text to request as a surrounding context of selection.
-// For now, the value is copied from the one with render_view_impl.cc.
-// TODO(kinaba) implement a way to dynamically sync the requirement.
-static const size_t kExtraCharsBeforeAndAfterSelection = 100;
-
#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \
COMPILE_ASSERT(static_cast<int>(WebCursorInfo::webkit_name) \
== static_cast<int>(np_name), \
@@ -611,7 +606,15 @@ void PluginInstance::SelectionChanged() {
// TODO(kinaba): currently the browser always calls RequestSurroundingText.
// It can be optimized so that it won't call it back until the information
// is really needed.
- RequestSurroundingText(kExtraCharsBeforeAndAfterSelection);
+
+ // Avoid calling in nested context or else this will reenter the plugin. This
+ // uses a weak pointer rather than exploiting the fact that this class is
+ // refcounted because we don't actually want this operation to affect the
+ // lifetime of the instance.
+ MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&PluginInstance::RequestSurroundingText,
+ AsWeakPtr(),
+ static_cast<size_t>(kExtraCharsForTextInput)));
}
void PluginInstance::UpdateSurroundingText(const std::string& text,
@@ -900,15 +903,14 @@ string16 PluginInstance::GetLinkAtPosition(const gfx::Point& point) {
return link;
}
-bool PluginInstance::RequestSurroundingText(
+void PluginInstance::RequestSurroundingText(
size_t desired_number_of_characters) {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
if (!LoadTextInputInterface())
- return false;
+ return;
plugin_textinput_interface_->RequestSurroundingText(
pp_instance(), desired_number_of_characters);
- return true;
}
void PluginInstance::Zoom(double factor, bool text_only) {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 7c8e0de..dc430e71 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -13,6 +13,7 @@
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "ppapi/c/dev/pp_cursor_type_dev.h"
@@ -90,6 +91,7 @@ class PPB_URLRequestInfo_Impl;
// ResourceTracker.
class WEBKIT_PLUGINS_EXPORT PluginInstance :
public base::RefCounted<PluginInstance>,
+ public base::SupportsWeakPtr<PluginInstance>,
public ::ppapi::FunctionGroupBase,
public ::ppapi::PPB_Instance_Shared {
public:
@@ -221,7 +223,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
string16 GetSelectedText(bool html);
string16 GetLinkAtPosition(const gfx::Point& point);
- bool RequestSurroundingText(size_t desired_number_of_characters);
+ void RequestSurroundingText(size_t desired_number_of_characters);
void Zoom(double factor, bool text_only);
bool StartFind(const string16& search_text,
bool case_sensitive,