| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_flash_clipboard_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_clipboard_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/private/ppb_flash_clipboard.h" | 8 #include "ppapi/c/private/ppb_flash_clipboard.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" | 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/serialized_var.h" | 11 #include "ppapi/proxy/serialized_var.h" |
| 12 | 12 |
| 13 namespace pp { | 13 namespace pp { |
| 14 namespace proxy { | 14 namespace proxy { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { | 18 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { |
| 19 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || | 19 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || |
| 20 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION || | 20 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION || |
| 21 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG; | 21 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG; |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { |
| 25 // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|. |
| 26 return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || |
| 27 format == PP_FLASH_CLIPBOARD_FORMAT_HTML; |
| 28 } |
| 29 |
| 30 PP_Bool IsFormatAvailable(PP_Instance instance_id, |
| 31 PP_Flash_Clipboard_Type clipboard_type, |
| 32 PP_Flash_Clipboard_Format format) { |
| 33 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 34 if (!dispatcher) |
| 35 return PP_FALSE; |
| 36 |
| 37 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) |
| 38 return PP_FALSE; |
| 39 |
| 40 bool result = false; |
| 41 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( |
| 42 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 43 instance_id, |
| 44 static_cast<int>(clipboard_type), |
| 45 static_cast<int>(format), |
| 46 &result)); |
| 47 return BoolToPPBool(result); |
| 48 } |
| 49 |
| 24 PP_Var ReadPlainText(PP_Instance instance_id, | 50 PP_Var ReadPlainText(PP_Instance instance_id, |
| 25 PP_Flash_Clipboard_Type clipboard_type) { | 51 PP_Flash_Clipboard_Type clipboard_type) { |
| 26 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); | 52 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 27 if (!dispatcher) | 53 if (!dispatcher) |
| 28 return PP_MakeUndefined(); | 54 return PP_MakeUndefined(); |
| 29 | 55 |
| 30 if (!IsValidClipboardType(clipboard_type)) | 56 if (!IsValidClipboardType(clipboard_type)) |
| 31 return PP_MakeUndefined(); | 57 return PP_MakeUndefined(); |
| 32 | 58 |
| 33 ReceiveSerializedVarReturnValue result; | 59 ReceiveSerializedVarReturnValue result; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( | 76 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( |
| 51 INTERFACE_ID_PPB_FLASH_CLIPBOARD, | 77 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 52 instance_id, | 78 instance_id, |
| 53 static_cast<int>(clipboard_type), | 79 static_cast<int>(clipboard_type), |
| 54 SerializedVarSendInput(dispatcher, text))); | 80 SerializedVarSendInput(dispatcher, text))); |
| 55 // Assume success, since it allows us to avoid a sync IPC. | 81 // Assume success, since it allows us to avoid a sync IPC. |
| 56 return PP_OK; | 82 return PP_OK; |
| 57 } | 83 } |
| 58 | 84 |
| 59 const PPB_Flash_Clipboard flash_clipboard_interface = { | 85 const PPB_Flash_Clipboard flash_clipboard_interface = { |
| 86 &IsFormatAvailable, |
| 60 &ReadPlainText, | 87 &ReadPlainText, |
| 61 &WritePlainText | 88 &WritePlainText |
| 62 }; | 89 }; |
| 63 | 90 |
| 64 InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher, | 91 InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher, |
| 65 const void* target_interface) { | 92 const void* target_interface) { |
| 66 return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface); | 93 return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface); |
| 67 } | 94 } |
| 68 | 95 |
| 69 } // namespace | 96 } // namespace |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 INTERFACE_ID_PPB_FLASH_CLIPBOARD, | 111 INTERFACE_ID_PPB_FLASH_CLIPBOARD, |
| 85 false, | 112 false, |
| 86 &CreateFlashClipboardProxy | 113 &CreateFlashClipboardProxy |
| 87 }; | 114 }; |
| 88 return &info; | 115 return &info; |
| 89 } | 116 } |
| 90 | 117 |
| 91 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { | 118 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 92 bool handled = true; | 119 bool handled = true; |
| 93 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) | 120 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
| 121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, |
| 122 OnMsgIsFormatAvailable) |
| 94 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, | 123 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, |
| 95 OnMsgReadPlainText) | 124 OnMsgReadPlainText) |
| 96 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, | 125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, |
| 97 OnMsgWritePlainText) | 126 OnMsgWritePlainText) |
| 98 IPC_MESSAGE_UNHANDLED(handled = false) | 127 IPC_MESSAGE_UNHANDLED(handled = false) |
| 99 IPC_END_MESSAGE_MAP() | 128 IPC_END_MESSAGE_MAP() |
| 100 return handled; | 129 return handled; |
| 101 } | 130 } |
| 102 | 131 |
| 132 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( |
| 133 PP_Instance instance_id, |
| 134 int clipboard_type, |
| 135 int format, |
| 136 bool* result) { |
| 137 *result = PPBoolToBool(ppb_flash_clipboard_target()->IsFormatAvailable( |
| 138 instance_id, |
| 139 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 140 static_cast<PP_Flash_Clipboard_Format>(format))); |
| 141 } |
| 142 |
| 103 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( | 143 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( |
| 104 PP_Instance instance_id, | 144 PP_Instance instance_id, |
| 105 int clipboard_type, | 145 int clipboard_type, |
| 106 SerializedVarReturnValue result) { | 146 SerializedVarReturnValue result) { |
| 107 result.Return(dispatcher(), | 147 result.Return(dispatcher(), |
| 108 ppb_flash_clipboard_target()->ReadPlainText( | 148 ppb_flash_clipboard_target()->ReadPlainText( |
| 109 instance_id, | 149 instance_id, |
| 110 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); | 150 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); |
| 111 } | 151 } |
| 112 | 152 |
| 113 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( | 153 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( |
| 114 PP_Instance instance_id, | 154 PP_Instance instance_id, |
| 115 int clipboard_type, | 155 int clipboard_type, |
| 116 SerializedVarReceiveInput text) { | 156 SerializedVarReceiveInput text) { |
| 117 int32_t result = ppb_flash_clipboard_target()->WritePlainText( | 157 int32_t result = ppb_flash_clipboard_target()->WritePlainText( |
| 118 instance_id, | 158 instance_id, |
| 119 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 159 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 120 text.Get(dispatcher())); | 160 text.Get(dispatcher())); |
| 121 LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly."; | 161 LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly."; |
| 122 } | 162 } |
| 123 | 163 |
| 124 } // namespace proxy | 164 } // namespace proxy |
| 125 } // namespace pp | 165 } // namespace pp |
| OLD | NEW |