diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 07:34:52 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 07:34:52 +0000 |
commit | 3c8c74c98b54130795812527b5b3eb6c569123c2 (patch) | |
tree | 880d846d4d98dfd57c7f5a0fc7f30879fde2a993 /ppapi/proxy | |
parent | 8cdb650a50c6d00099d030e4dbbba7eca82379cd (diff) | |
download | chromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.zip chromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.tar.gz chromium_src-3c8c74c98b54130795812527b5b3eb6c569123c2.tar.bz2 |
Pepper IME API for surrounding text retrieval.
IME benefits from knowing what portion of text is selected inside a text editing plugin.
This change is to implement a Pepper API for doing it. It consists of three API functions:
1. Browser asks plugins by PPP_TextInput_Dev::RequestSurroundingText() to send such info.
2. Plugin must reply the query by PPB_TextInput_Dev::UpdateSurroundingText().
3. Additionally, plugin notifies the browser by PPB_TextInput_Dev::SelectionChanged() that the selection is changed. Typically triggers the steps 1->2.
Intention of the API design is (1) to avoid synchronous IPC, and (2) to keep the room to implement it in an optimal and right way, that is, expensive send of selection text happens only when needed (= "IME requiring the info is on" + "selection indeed changed in the plugin"), though the current impl in the patch is not necessary like that (for sake of simplicity).
The changes in the API is in:
* ppapi/c/dev/ppb_text_input_dev.h
* ppapi/c/dev/ppp_text_input_dev.h
The browser side implementation mostly resides in:
* content/renderer/render_view_impl.cc
* content/renderer/pepper/pepper_plugin_delegate_impl.{h,cc}
* webkit/plugins/ppapi/ppapi_plugin_instance.{h,cc}
The other files are for wiring necessary cables.
BUG=101101
TEST=Manual: make ppapi_example_ime and run ./your/chrome --register-pepper-plugins=\
"/path/to/ppapi_example_ime.plugin;application/x-ppapi-example-ime" \
--ppapi-out-of-process \
file:///path/to/ppapi/examples/ime/ime.html
Try some IME that supports reconversion (e.g., Google Japanese Input on Windows).
Review URL: http://codereview.chromium.org/8769003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/interface_list.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 12 | ||||
-rw-r--r-- | ppapi/proxy/ppb_text_input_proxy.cc | 37 | ||||
-rw-r--r-- | ppapi/proxy/ppb_text_input_proxy.h | 14 | ||||
-rw-r--r-- | ppapi/proxy/ppp_text_input_proxy.cc | 73 | ||||
-rw-r--r-- | ppapi/proxy/ppp_text_input_proxy.h | 41 |
6 files changed, 179 insertions, 2 deletions
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 374bbf2..e746ffd 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -109,6 +109,7 @@ #include "ppapi/proxy/ppp_messaging_proxy.h" #include "ppapi/proxy/ppp_mouse_lock_proxy.h" #include "ppapi/proxy/ppp_printing_proxy.h" +#include "ppapi/proxy/ppp_text_input_proxy.h" #include "ppapi/proxy/ppp_video_decoder_proxy.h" #include "ppapi/proxy/resource_creation_proxy.h" #include "ppapi/shared_impl/ppb_opengles2_shared.h" @@ -222,6 +223,9 @@ InterfaceList::InterfaceList() { AddProxy(API_ID_PPP_PRINTING, &ProxyFactory<PPP_Printing_Proxy>); AddPPP(PPP_PRINTING_DEV_INTERFACE, API_ID_PPP_PRINTING, PPP_Printing_Proxy::GetProxyInterface()); + AddProxy(API_ID_PPP_TEXT_INPUT, &ProxyFactory<PPP_TextInput_Proxy>); + AddPPP(PPP_TEXTINPUT_DEV_INTERFACE, API_ID_PPP_TEXT_INPUT, + PPP_TextInput_Proxy::GetProxyInterface()); // Old-style GetInfo PPP interfaces. // Do not add more stuff here, they should be added to interface_list*.h diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index f1cd174..7a5c2f4 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -513,6 +513,11 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPPrinting_IsScalingDisabled, PP_Instance /* instance */, bool /* result */) +// PPP_TextInput. +IPC_MESSAGE_ROUTED2(PpapiMsg_PPPTextInput_RequestSurroundingText, + PP_Instance /* instance */, + uint32_t /* desired_number_of_characters */) + // PPB_URLLoader // (Messages from browser to plugin to notify it of changes in state.) IPC_MESSAGE_ROUTED1( @@ -943,6 +948,13 @@ 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 */, + uint32_t /* caret */, + uint32_t /* anchor */) // PPB_URLLoader. IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBURLLoader_Create, diff --git a/ppapi/proxy/ppb_text_input_proxy.cc b/ppapi/proxy/ppb_text_input_proxy.cc index 7a48912..e7434e0 100644 --- a/ppapi/proxy/ppb_text_input_proxy.cc +++ b/ppapi/proxy/ppb_text_input_proxy.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -42,6 +42,19 @@ void PPB_TextInput_Proxy::CancelCompositionText(PP_Instance instance) { API_ID_PPB_TEXT_INPUT, instance)); } +void PPB_TextInput_Proxy::SelectionChanged(PP_Instance instance) { + dispatcher()->Send(new PpapiHostMsg_PPBTextInput_SelectionChanged( + API_ID_PPB_TEXT_INPUT, instance)); +} + +void PPB_TextInput_Proxy::UpdateSurroundingText(PP_Instance instance, + const char* text, + uint32_t caret, + uint32_t anchor) { + dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateSurroundingText( + API_ID_PPB_TEXT_INPUT, instance, text, caret, anchor)); +} + bool PPB_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_TextInput_Proxy, msg) @@ -51,6 +64,10 @@ 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) IPC_END_MESSAGE_MAP() return handled; @@ -80,5 +97,23 @@ 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, + uint32_t anchor) { + ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, + true); + if (enter.succeeded()) + enter.functions()->UpdateSurroundingText(instance, + text.c_str(), caret, anchor); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppb_text_input_proxy.h b/ppapi/proxy/ppb_text_input_proxy.h index 92a8b12..e5226a4 100644 --- a/ppapi/proxy/ppb_text_input_proxy.h +++ b/ppapi/proxy/ppb_text_input_proxy.h @@ -1,10 +1,12 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef PPAPI_PROXY_PPB_TEXT_INPUT_PROXY_H_ #define PPAPI_PROXY_PPB_TEXT_INPUT_PROXY_H_ +#include <string> + #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_rect.h" #include "ppapi/proxy/interface_proxy.h" @@ -31,6 +33,11 @@ class PPB_TextInput_Proxy const PP_Rect& caret, const PP_Rect& bounding_box) OVERRIDE; virtual void CancelCompositionText(PP_Instance instance) OVERRIDE; + virtual void SelectionChanged(PP_Instance instance) OVERRIDE; + virtual void UpdateSurroundingText(PP_Instance instance, + const char* text, + uint32_t caret, + uint32_t anchor) OVERRIDE; // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; @@ -44,6 +51,11 @@ 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, + uint32_t anchor); DISALLOW_COPY_AND_ASSIGN(PPB_TextInput_Proxy); }; diff --git a/ppapi/proxy/ppp_text_input_proxy.cc b/ppapi/proxy/ppp_text_input_proxy.cc new file mode 100644 index 0000000..8a8254a --- /dev/null +++ b/ppapi/proxy/ppp_text_input_proxy.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppp_text_input_proxy.h" + +#include "ppapi/c/dev/ppp_text_input_dev.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/proxy_lock.h" + +namespace ppapi { +namespace proxy { + +namespace { + +void RequestSurroundingText(PP_Instance instance, + uint32_t desired_number_of_characters) { + proxy::HostDispatcher* dispatcher = + proxy::HostDispatcher::GetForInstance(instance); + if (!dispatcher) { + // The dispatcher should always be valid. + NOTREACHED(); + return; + } + + dispatcher->Send(new PpapiMsg_PPPTextInput_RequestSurroundingText( + API_ID_PPP_TEXT_INPUT, instance, desired_number_of_characters)); +} + +const PPP_TextInput_Dev g_ppp_text_input_thunk = { + &RequestSurroundingText +}; + +} // namespace + +// static +const PPP_TextInput_Dev* PPP_TextInput_Proxy::GetProxyInterface() { + return &g_ppp_text_input_thunk; +} + +PPP_TextInput_Proxy::PPP_TextInput_Proxy(Dispatcher* dispatcher) + : InterfaceProxy(dispatcher), + ppp_text_input_impl_(NULL) { + if (dispatcher->IsPlugin()) { + ppp_text_input_impl_ = static_cast<const PPP_TextInput_Dev*>( + dispatcher->local_get_interface()(PPP_TEXTINPUT_DEV_INTERFACE)); + } +} + +PPP_TextInput_Proxy::~PPP_TextInput_Proxy() { +} + +bool PPP_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPP_TextInput_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPTextInput_RequestSurroundingText, + OnMsgRequestSurroundingText) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPP_TextInput_Proxy::OnMsgRequestSurroundingText( + PP_Instance instance, uint32_t desired_number_of_characters) { + if (ppp_text_input_impl_) { + CallWhileUnlocked(ppp_text_input_impl_->RequestSurroundingText, + instance, desired_number_of_characters); + } +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppp_text_input_proxy.h b/ppapi/proxy/ppp_text_input_proxy.h new file mode 100644 index 0000000..c4f09db --- /dev/null +++ b/ppapi/proxy/ppp_text_input_proxy.h @@ -0,0 +1,41 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPP_TEXT_INPUT_PROXY_H_ +#define PPAPI_PROXY_PPP_TEXT_INPUT_PROXY_H_ + +#include "ppapi/c/dev/ppp_text_input_dev.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" + +namespace ppapi { +namespace proxy { + +class PPP_TextInput_Proxy : public InterfaceProxy { + public: + PPP_TextInput_Proxy(Dispatcher* dispatcher); + virtual ~PPP_TextInput_Proxy(); + + static const PPP_TextInput_Dev* GetProxyInterface(); + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + + private: + // Message handlers. + void OnMsgRequestSurroundingText(PP_Instance instance, + uint32_t desired_number_of_characters); + + // When this proxy is in the plugin side, this value caches the interface + // pointer so we don't have to retrieve it from the dispatcher each time. + // In the host, this value is always NULL. + const PPP_TextInput_Dev* ppp_text_input_impl_; + + DISALLOW_COPY_AND_ASSIGN(PPP_TextInput_Proxy); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPP_TEXT_INPUT_PROXY_H_ |