| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_text_input_proxy.h" | 5 #include "ppapi/proxy/ppb_text_input_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/proxy/plugin_dispatcher.h" | 7 #include "ppapi/proxy/plugin_dispatcher.h" |
| 8 #include "ppapi/proxy/ppapi_messages.h" | 8 #include "ppapi/proxy/ppapi_messages.h" |
| 9 #include "ppapi/shared_impl/ppb_instance_shared.h" |
| 9 #include "ppapi/thunk/enter.h" | 10 #include "ppapi/thunk/enter.h" |
| 10 #include "ppapi/thunk/thunk.h" | 11 #include "ppapi/thunk/thunk.h" |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 namespace proxy { | 14 namespace proxy { |
| 14 | 15 |
| 16 namespace { |
| 17 |
| 18 void RequestSurroundingText(PP_Instance instance) { |
| 19 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 20 if (!dispatcher) |
| 21 return; // Instance has gone away while message was pending. |
| 22 |
| 23 // Just fake out a RequestSurroundingText message to the proxy for the PPP |
| 24 // interface. |
| 25 InterfaceProxy* proxy = dispatcher->GetInterfaceProxy(API_ID_PPB_TEXT_INPUT); |
| 26 if (!proxy) |
| 27 return; |
| 28 proxy->OnMessageReceived(PpapiMsg_PPPTextInput_RequestSurroundingText( |
| 29 API_ID_PPP_TEXT_INPUT, instance, |
| 30 PPB_Instance_Shared::kExtraCharsForTextInput)); |
| 31 } |
| 32 |
| 33 } // namespace |
| 34 |
| 15 PPB_TextInput_Proxy::PPB_TextInput_Proxy(Dispatcher* dispatcher) | 35 PPB_TextInput_Proxy::PPB_TextInput_Proxy(Dispatcher* dispatcher) |
| 16 : InterfaceProxy(dispatcher) { | 36 : InterfaceProxy(dispatcher) { |
| 17 } | 37 } |
| 18 | 38 |
| 19 PPB_TextInput_Proxy::~PPB_TextInput_Proxy() { | 39 PPB_TextInput_Proxy::~PPB_TextInput_Proxy() { |
| 20 } | 40 } |
| 21 | 41 |
| 22 ppapi::thunk::PPB_TextInput_FunctionAPI* | 42 ppapi::thunk::PPB_TextInput_FunctionAPI* |
| 23 PPB_TextInput_Proxy::AsPPB_TextInput_FunctionAPI() { | 43 PPB_TextInput_Proxy::AsPPB_TextInput_FunctionAPI() { |
| 24 return this; | 44 return this; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateCaretPosition( | 56 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateCaretPosition( |
| 37 API_ID_PPB_TEXT_INPUT, instance, caret, bounding_box)); | 57 API_ID_PPB_TEXT_INPUT, instance, caret, bounding_box)); |
| 38 } | 58 } |
| 39 | 59 |
| 40 void PPB_TextInput_Proxy::CancelCompositionText(PP_Instance instance) { | 60 void PPB_TextInput_Proxy::CancelCompositionText(PP_Instance instance) { |
| 41 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_CancelCompositionText( | 61 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_CancelCompositionText( |
| 42 API_ID_PPB_TEXT_INPUT, instance)); | 62 API_ID_PPB_TEXT_INPUT, instance)); |
| 43 } | 63 } |
| 44 | 64 |
| 45 void PPB_TextInput_Proxy::SelectionChanged(PP_Instance instance) { | 65 void PPB_TextInput_Proxy::SelectionChanged(PP_Instance instance) { |
| 46 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_SelectionChanged( | 66 // The "right" way to do this is to send the message to the host. However, |
| 47 API_ID_PPB_TEXT_INPUT, instance)); | 67 // all it will do it call RequestSurroundingText with a hardcoded number of |
| 68 // characters in response, which is an entire IPC round-trip. |
| 69 // |
| 70 // We can avoid this round-trip by just implementing the |
| 71 // RequestSurroundingText logic in the plugin process. If the logic in the |
| 72 // host becomes more complex (like a more adaptive number of characters), |
| 73 // we'll need to reevanuate whether we want to do the round trip instead. |
| 74 // |
| 75 // Be careful to post a task to avoid reentering the plugin. |
| 76 MessageLoop::current()->PostTask( |
| 77 FROM_HERE, |
| 78 base::Bind(&RequestSurroundingText, instance)); |
| 48 } | 79 } |
| 49 | 80 |
| 50 void PPB_TextInput_Proxy::UpdateSurroundingText(PP_Instance instance, | 81 void PPB_TextInput_Proxy::UpdateSurroundingText(PP_Instance instance, |
| 51 const char* text, | 82 const char* text, |
| 52 uint32_t caret, | 83 uint32_t caret, |
| 53 uint32_t anchor) { | 84 uint32_t anchor) { |
| 54 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateSurroundingText( | 85 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateSurroundingText( |
| 55 API_ID_PPB_TEXT_INPUT, instance, text, caret, anchor)); | 86 API_ID_PPB_TEXT_INPUT, instance, text, caret, anchor)); |
| 56 } | 87 } |
| 57 | 88 |
| 58 bool PPB_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) { | 89 bool PPB_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 59 bool handled = true; | 90 bool handled = true; |
| 60 IPC_BEGIN_MESSAGE_MAP(PPB_TextInput_Proxy, msg) | 91 IPC_BEGIN_MESSAGE_MAP(PPB_TextInput_Proxy, msg) |
| 61 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_SetTextInputType, | 92 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_SetTextInputType, |
| 62 OnMsgSetTextInputType) | 93 OnMsgSetTextInputType) |
| 63 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateCaretPosition, | 94 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateCaretPosition, |
| 64 OnMsgUpdateCaretPosition) | 95 OnMsgUpdateCaretPosition) |
| 65 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_CancelCompositionText, | 96 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_CancelCompositionText, |
| 66 OnMsgCancelCompositionText) | 97 OnMsgCancelCompositionText) |
| 67 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_SelectionChanged, | |
| 68 OnMsgSelectionChanged) | |
| 69 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateSurroundingText, | 98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateSurroundingText, |
| 70 OnMsgUpdateSurroundingText) | 99 OnMsgUpdateSurroundingText) |
| 71 IPC_MESSAGE_UNHANDLED(handled = false) | 100 IPC_MESSAGE_UNHANDLED(handled = false) |
| 72 IPC_END_MESSAGE_MAP() | 101 IPC_END_MESSAGE_MAP() |
| 73 return handled; | 102 return handled; |
| 74 } | 103 } |
| 75 | 104 |
| 76 void PPB_TextInput_Proxy::OnMsgSetTextInputType(PP_Instance instance, | 105 void PPB_TextInput_Proxy::OnMsgSetTextInputType(PP_Instance instance, |
| 77 PP_TextInput_Type type) { | 106 PP_TextInput_Type type) { |
| 78 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | 107 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 90 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box); | 119 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box); |
| 91 } | 120 } |
| 92 | 121 |
| 93 void PPB_TextInput_Proxy::OnMsgCancelCompositionText(PP_Instance instance) { | 122 void PPB_TextInput_Proxy::OnMsgCancelCompositionText(PP_Instance instance) { |
| 94 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | 123 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, |
| 95 true); | 124 true); |
| 96 if (enter.succeeded()) | 125 if (enter.succeeded()) |
| 97 enter.functions()->CancelCompositionText(instance); | 126 enter.functions()->CancelCompositionText(instance); |
| 98 } | 127 } |
| 99 | 128 |
| 100 void PPB_TextInput_Proxy::OnMsgSelectionChanged(PP_Instance instance) { | |
| 101 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | |
| 102 true); | |
| 103 if (enter.succeeded()) | |
| 104 enter.functions()->SelectionChanged(instance); | |
| 105 } | |
| 106 | |
| 107 void PPB_TextInput_Proxy::OnMsgUpdateSurroundingText(PP_Instance instance, | 129 void PPB_TextInput_Proxy::OnMsgUpdateSurroundingText(PP_Instance instance, |
| 108 const std::string& text, | 130 const std::string& text, |
| 109 uint32_t caret, | 131 uint32_t caret, |
| 110 uint32_t anchor) { | 132 uint32_t anchor) { |
| 111 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | 133 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, |
| 112 true); | 134 true); |
| 113 if (enter.succeeded()) | 135 if (enter.succeeded()) |
| 114 enter.functions()->UpdateSurroundingText(instance, | 136 enter.functions()->UpdateSurroundingText(instance, |
| 115 text.c_str(), caret, anchor); | 137 text.c_str(), caret, anchor); |
| 116 } | 138 } |
| 117 | 139 |
| 118 } // namespace proxy | 140 } // namespace proxy |
| 119 } // namespace ppapi | 141 } // namespace ppapi |
| OLD | NEW |