OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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_flash_clipboard_proxy.h" |
| 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/private/ppb_flash_clipboard.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/serialized_var.h" |
| 12 |
| 13 namespace pp { |
| 14 namespace proxy { |
| 15 |
| 16 namespace { |
| 17 |
| 18 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { |
| 19 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || |
| 20 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION || |
| 21 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG; |
| 22 } |
| 23 |
| 24 PP_Var ReadPlainText(PP_Instance instance_id, |
| 25 PP_Flash_Clipboard_Type clipboard_type) { |
| 26 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 27 if (!dispatcher) |
| 28 return PP_MakeUndefined(); |
| 29 |
| 30 if (!IsValidClipboardType(clipboard_type)) |
| 31 return PP_MakeUndefined(); |
| 32 |
| 33 ReceiveSerializedVarReturnValue result; |
| 34 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( |
| 35 INTERFACE_ID_PPB_FLASH_CLIPBOARD, instance_id, |
| 36 static_cast<int>(clipboard_type), &result)); |
| 37 return result.Return(dispatcher); |
| 38 } |
| 39 |
| 40 int32_t WritePlainText(PP_Instance instance_id, |
| 41 PP_Flash_Clipboard_Type clipboard_type, |
| 42 PP_Var text) { |
| 43 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 44 if (!dispatcher) |
| 45 return PP_ERROR_BADARGUMENT; |
| 46 |
| 47 if (!IsValidClipboardType(clipboard_type)) |
| 48 return PP_ERROR_BADARGUMENT; |
| 49 |
| 50 int32_t result; |
| 51 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( |
| 52 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 53 instance_id, |
| 54 static_cast<int>(clipboard_type), |
| 55 SerializedVarSendInput(dispatcher, text), |
| 56 &result)); |
| 57 return result; |
| 58 } |
| 59 |
| 60 const PPB_Flash_Clipboard flash_clipboard_interface = { |
| 61 &ReadPlainText, |
| 62 &WritePlainText |
| 63 }; |
| 64 |
| 65 InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher, |
| 66 const void* target_interface) { |
| 67 return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface); |
| 68 } |
| 69 |
| 70 } // namespace |
| 71 |
| 72 PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy( |
| 73 Dispatcher* dispatcher, const void* target_interface) |
| 74 : InterfaceProxy(dispatcher, target_interface) { |
| 75 } |
| 76 |
| 77 PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() { |
| 78 } |
| 79 |
| 80 // static |
| 81 const InterfaceProxy::Info* PPB_Flash_Clipboard_Proxy::GetInfo() { |
| 82 static const Info info = { |
| 83 &flash_clipboard_interface, |
| 84 PPB_FLASH_CLIPBOARD_INTERFACE, |
| 85 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 86 false, |
| 87 &CreateFlashClipboardProxy |
| 88 }; |
| 89 return &info; |
| 90 } |
| 91 |
| 92 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 93 bool handled = true; |
| 94 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
| 95 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, |
| 96 OnMsgReadPlainText) |
| 97 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, |
| 98 OnMsgWritePlainText) |
| 99 IPC_MESSAGE_UNHANDLED(handled = false) |
| 100 IPC_END_MESSAGE_MAP() |
| 101 return handled; |
| 102 } |
| 103 |
| 104 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( |
| 105 PP_Instance instance_id, |
| 106 int clipboard_type, |
| 107 SerializedVarReturnValue result) { |
| 108 result.Return(dispatcher(), |
| 109 ppb_flash_clipboard_target()->ReadPlainText( |
| 110 instance_id, |
| 111 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); |
| 112 } |
| 113 |
| 114 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( |
| 115 PP_Instance instance_id, |
| 116 int clipboard_type, |
| 117 SerializedVarReceiveInput text, |
| 118 int32_t* result) { |
| 119 *result = ppb_flash_clipboard_target()->WritePlainText( |
| 120 instance_id, |
| 121 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 122 text.Get(dispatcher())); |
| 123 } |
| 124 |
| 125 } // namespace proxy |
| 126 } // namespace pp |
OLD | NEW |