| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/proxy/ppb_text_input_proxy.h" | |
| 6 | |
| 7 #include "ppapi/proxy/plugin_dispatcher.h" | |
| 8 #include "ppapi/proxy/ppapi_messages.h" | |
| 9 #include "ppapi/shared_impl/ppb_instance_shared.h" | |
| 10 #include "ppapi/thunk/enter.h" | |
| 11 #include "ppapi/thunk/thunk.h" | |
| 12 | |
| 13 namespace ppapi { | |
| 14 namespace proxy { | |
| 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 | |
| 35 PPB_TextInput_Proxy::PPB_TextInput_Proxy(Dispatcher* dispatcher) | |
| 36 : InterfaceProxy(dispatcher) { | |
| 37 } | |
| 38 | |
| 39 PPB_TextInput_Proxy::~PPB_TextInput_Proxy() { | |
| 40 } | |
| 41 | |
| 42 ppapi::thunk::PPB_TextInput_FunctionAPI* | |
| 43 PPB_TextInput_Proxy::AsPPB_TextInput_FunctionAPI() { | |
| 44 return this; | |
| 45 } | |
| 46 | |
| 47 void PPB_TextInput_Proxy::SetTextInputType(PP_Instance instance, | |
| 48 PP_TextInput_Type type) { | |
| 49 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_SetTextInputType( | |
| 50 API_ID_PPB_TEXT_INPUT, instance, type)); | |
| 51 } | |
| 52 | |
| 53 void PPB_TextInput_Proxy::UpdateCaretPosition(PP_Instance instance, | |
| 54 const PP_Rect& caret, | |
| 55 const PP_Rect& bounding_box) { | |
| 56 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateCaretPosition( | |
| 57 API_ID_PPB_TEXT_INPUT, instance, caret, bounding_box)); | |
| 58 } | |
| 59 | |
| 60 void PPB_TextInput_Proxy::CancelCompositionText(PP_Instance instance) { | |
| 61 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_CancelCompositionText( | |
| 62 API_ID_PPB_TEXT_INPUT, instance)); | |
| 63 } | |
| 64 | |
| 65 void PPB_TextInput_Proxy::SelectionChanged(PP_Instance instance) { | |
| 66 // The "right" way to do this is to send the message to the host. However, | |
| 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)); | |
| 79 } | |
| 80 | |
| 81 void PPB_TextInput_Proxy::UpdateSurroundingText(PP_Instance instance, | |
| 82 const char* text, | |
| 83 uint32_t caret, | |
| 84 uint32_t anchor) { | |
| 85 dispatcher()->Send(new PpapiHostMsg_PPBTextInput_UpdateSurroundingText( | |
| 86 API_ID_PPB_TEXT_INPUT, instance, text, caret, anchor)); | |
| 87 } | |
| 88 | |
| 89 bool PPB_TextInput_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
| 90 bool handled = true; | |
| 91 IPC_BEGIN_MESSAGE_MAP(PPB_TextInput_Proxy, msg) | |
| 92 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_SetTextInputType, | |
| 93 OnMsgSetTextInputType) | |
| 94 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateCaretPosition, | |
| 95 OnMsgUpdateCaretPosition) | |
| 96 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_CancelCompositionText, | |
| 97 OnMsgCancelCompositionText) | |
| 98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTextInput_UpdateSurroundingText, | |
| 99 OnMsgUpdateSurroundingText) | |
| 100 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 101 IPC_END_MESSAGE_MAP() | |
| 102 return handled; | |
| 103 } | |
| 104 | |
| 105 void PPB_TextInput_Proxy::OnMsgSetTextInputType(PP_Instance instance, | |
| 106 PP_TextInput_Type type) { | |
| 107 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | |
| 108 true); | |
| 109 if (enter.succeeded()) | |
| 110 enter.functions()->SetTextInputType(instance, type); | |
| 111 } | |
| 112 | |
| 113 void PPB_TextInput_Proxy::OnMsgUpdateCaretPosition(PP_Instance instance, | |
| 114 PP_Rect caret, | |
| 115 PP_Rect bounding_box) { | |
| 116 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | |
| 117 true); | |
| 118 if (enter.succeeded()) | |
| 119 enter.functions()->UpdateCaretPosition(instance, caret, bounding_box); | |
| 120 } | |
| 121 | |
| 122 void PPB_TextInput_Proxy::OnMsgCancelCompositionText(PP_Instance instance) { | |
| 123 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | |
| 124 true); | |
| 125 if (enter.succeeded()) | |
| 126 enter.functions()->CancelCompositionText(instance); | |
| 127 } | |
| 128 | |
| 129 void PPB_TextInput_Proxy::OnMsgUpdateSurroundingText(PP_Instance instance, | |
| 130 const std::string& text, | |
| 131 uint32_t caret, | |
| 132 uint32_t anchor) { | |
| 133 ppapi::thunk::EnterFunctionNoLock<PPB_TextInput_FunctionAPI> enter(instance, | |
| 134 true); | |
| 135 if (enter.succeeded()) | |
| 136 enter.functions()->UpdateSurroundingText(instance, | |
| 137 text.c_str(), caret, anchor); | |
| 138 } | |
| 139 | |
| 140 } // namespace proxy | |
| 141 } // namespace ppapi | |
| OLD | NEW |