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 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( |
| 51 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 52 instance_id, |
| 53 static_cast<int>(clipboard_type), |
| 54 SerializedVarSendInput(dispatcher, text))); |
| 55 // Assume success, since it allows us to avoid a sync IPC. |
| 56 return PP_OK; |
| 57 } |
| 58 |
| 59 const PPB_Flash_Clipboard flash_clipboard_interface = { |
| 60 &ReadPlainText, |
| 61 &WritePlainText |
| 62 }; |
| 63 |
| 64 InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher, |
| 65 const void* target_interface) { |
| 66 return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface); |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
| 71 PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy( |
| 72 Dispatcher* dispatcher, const void* target_interface) |
| 73 : InterfaceProxy(dispatcher, target_interface) { |
| 74 } |
| 75 |
| 76 PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() { |
| 77 } |
| 78 |
| 79 // static |
| 80 const InterfaceProxy::Info* PPB_Flash_Clipboard_Proxy::GetInfo() { |
| 81 static const Info info = { |
| 82 &flash_clipboard_interface, |
| 83 PPB_FLASH_CLIPBOARD_INTERFACE, |
| 84 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 85 false, |
| 86 &CreateFlashClipboardProxy |
| 87 }; |
| 88 return &info; |
| 89 } |
| 90 |
| 91 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 92 bool handled = true; |
| 93 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
| 94 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, |
| 95 OnMsgReadPlainText) |
| 96 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, |
| 97 OnMsgWritePlainText) |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) |
| 99 IPC_END_MESSAGE_MAP() |
| 100 return handled; |
| 101 } |
| 102 |
| 103 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( |
| 104 PP_Instance instance_id, |
| 105 int clipboard_type, |
| 106 SerializedVarReturnValue result) { |
| 107 result.Return(dispatcher(), |
| 108 ppb_flash_clipboard_target()->ReadPlainText( |
| 109 instance_id, |
| 110 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); |
| 111 } |
| 112 |
| 113 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( |
| 114 PP_Instance instance_id, |
| 115 int clipboard_type, |
| 116 SerializedVarReceiveInput text) { |
| 117 int32_t result = ppb_flash_clipboard_target()->WritePlainText( |
| 118 instance_id, |
| 119 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 120 text.Get(dispatcher())); |
| 121 LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly."; |
| 122 } |
| 123 |
| 124 } // namespace proxy |
| 125 } // namespace pp |
OLD | NEW |