Chromium Code Reviews| 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" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 instance, | 59 instance, |
| 60 static_cast<int>(clipboard_type), | 60 static_cast<int>(clipboard_type), |
| 61 static_cast<int>(format), | 61 static_cast<int>(format), |
| 62 &result)); | 62 &result)); |
| 63 return PP_FromBool(result); | 63 return PP_FromBool(result); |
| 64 } | 64 } |
| 65 | 65 |
| 66 PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText( | 66 PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText( |
| 67 PP_Instance instance, | 67 PP_Instance instance, |
| 68 PP_Flash_Clipboard_Type clipboard_type) { | 68 PP_Flash_Clipboard_Type clipboard_type) { |
| 69 if (!IsValidClipboardType(clipboard_type)) | 69 return ReadData(instance, clipboard_type, |
| 70 return PP_MakeUndefined(); | 70 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); |
| 71 | |
| 72 ReceiveSerializedVarReturnValue result; | |
| 73 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( | |
| 74 API_ID_PPB_FLASH_CLIPBOARD, instance, | |
| 75 static_cast<int>(clipboard_type), &result)); | |
| 76 return result.Return(dispatcher()); | |
| 77 } | 71 } |
| 78 | 72 |
| 79 int32_t PPB_Flash_Clipboard_Proxy::WritePlainText( | 73 int32_t PPB_Flash_Clipboard_Proxy::WritePlainText( |
| 80 PP_Instance instance, | 74 PP_Instance instance, |
| 81 PP_Flash_Clipboard_Type clipboard_type, | 75 PP_Flash_Clipboard_Type clipboard_type, |
| 82 const PP_Var& text) { | 76 const PP_Var& text) { |
| 77 PP_Flash_Clipboard_Data_Item data_item = | |
| 78 {PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, text}; | |
|
viettrungluu
2012/02/08 22:25:01
style nit: indentation is off (and I think we want
raymes
2012/02/09 00:20:27
Done. Spaces inside the braces are optional accord
| |
| 79 return WriteData(instance, clipboard_type, 1, &data_item); | |
| 80 } | |
| 81 | |
| 82 PP_Var PPB_Flash_Clipboard_Proxy::ReadData( | |
| 83 PP_Instance instance, | |
| 84 PP_Flash_Clipboard_Type clipboard_type, | |
| 85 PP_Flash_Clipboard_Format format) { | |
| 86 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) | |
| 87 return PP_MakeUndefined(); | |
| 88 | |
| 89 ReceiveSerializedVarReturnValue result; | |
| 90 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadData( | |
| 91 API_ID_PPB_FLASH_CLIPBOARD, instance, | |
| 92 static_cast<int>(clipboard_type), static_cast<int>(format), &result)); | |
| 93 return result.Return(dispatcher()); | |
| 94 } | |
| 95 | |
| 96 | |
| 97 int32_t PPB_Flash_Clipboard_Proxy::WriteData( | |
| 98 PP_Instance instance, | |
| 99 PP_Flash_Clipboard_Type clipboard_type, | |
| 100 uint32_t data_item_count, | |
| 101 const struct | |
| 102 PP_Flash_Clipboard_Data_Item data_items[]) { | |
| 83 if (!IsValidClipboardType(clipboard_type)) | 103 if (!IsValidClipboardType(clipboard_type)) |
| 84 return PP_ERROR_BADARGUMENT; | 104 return PP_ERROR_BADARGUMENT; |
| 85 | 105 |
| 86 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( | 106 // Convert the array of PP_Flash_Clipboard_Data_Item into two parallel |
| 107 // arrays of format and corresponding data. | |
| 108 PP_Var formats[data_item_count]; | |
| 109 PP_Var data[data_item_count]; | |
| 110 | |
| 111 for (uint32_t i = 0; i < data_item_count; ++i) { | |
| 112 formats[i] = PP_MakeInt32(data_items[i].format); | |
| 113 data[i] = data_items[i].data; | |
| 114 } | |
| 115 | |
| 116 std::vector<SerializedVar> formats_converted; | |
| 117 std::vector<SerializedVar> data_converted; | |
| 118 SerializedVarSendInput::ConvertVector(dispatcher(), formats, data_item_count, | |
| 119 &formats_converted); | |
| 120 SerializedVarSendInput::ConvertVector(dispatcher(), data, data_item_count, | |
| 121 &data_converted); | |
| 122 | |
| 123 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData( | |
| 87 API_ID_PPB_FLASH_CLIPBOARD, | 124 API_ID_PPB_FLASH_CLIPBOARD, |
| 88 instance, | 125 instance, |
| 89 static_cast<int>(clipboard_type), | 126 static_cast<int>(clipboard_type), |
| 90 SerializedVarSendInput(dispatcher(), text))); | 127 formats_converted, |
| 128 data_converted)); | |
| 91 // Assume success, since it allows us to avoid a sync IPC. | 129 // Assume success, since it allows us to avoid a sync IPC. |
| 92 return PP_OK; | 130 return PP_OK; |
| 93 } | 131 } |
| 94 | 132 |
| 95 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { | 133 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 96 bool handled = true; | 134 bool handled = true; |
| 97 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) | 135 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
| 98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, | 136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, |
| 99 OnMsgIsFormatAvailable) | 137 OnMsgIsFormatAvailable) |
| 100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, | 138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData, |
| 101 OnMsgReadPlainText) | 139 OnMsgReadData) |
|
viettrungluu
2012/02/08 22:25:01
nit: alignment
raymes
2012/02/09 00:20:27
Done.
| |
| 102 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, | 140 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData, |
| 103 OnMsgWritePlainText) | 141 OnMsgWriteData) |
| 104 IPC_MESSAGE_UNHANDLED(handled = false) | 142 IPC_MESSAGE_UNHANDLED(handled = false) |
| 105 IPC_END_MESSAGE_MAP() | 143 IPC_END_MESSAGE_MAP() |
| 106 return handled; | 144 return handled; |
| 107 } | 145 } |
| 108 | 146 |
| 109 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( | 147 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( |
| 110 PP_Instance instance, | 148 PP_Instance instance, |
| 111 int clipboard_type, | 149 int clipboard_type, |
| 112 int format, | 150 int format, |
| 113 bool* result) { | 151 bool* result) { |
| 114 EnterFlashClipboardNoLock enter(instance, true); | 152 EnterFlashClipboardNoLock enter(instance, true); |
| 115 if (enter.succeeded()) { | 153 if (enter.succeeded()) { |
| 116 *result = PP_ToBool(enter.functions()->IsFormatAvailable( | 154 *result = PP_ToBool(enter.functions()->IsFormatAvailable( |
| 117 instance, | 155 instance, |
| 118 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 156 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 119 static_cast<PP_Flash_Clipboard_Format>(format))); | 157 static_cast<PP_Flash_Clipboard_Format>(format))); |
| 120 } else { | 158 } else { |
| 121 *result = false; | 159 *result = false; |
| 122 } | 160 } |
| 123 } | 161 } |
| 124 | 162 |
| 125 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( | 163 void PPB_Flash_Clipboard_Proxy::OnMsgReadData( |
| 126 PP_Instance instance, | 164 PP_Instance instance, |
| 127 int clipboard_type, | 165 int clipboard_type, |
| 166 int format, | |
| 128 SerializedVarReturnValue result) { | 167 SerializedVarReturnValue result) { |
| 129 EnterFlashClipboardNoLock enter(instance, true); | 168 EnterFlashClipboardNoLock enter(instance, true); |
| 130 if (enter.succeeded()) { | 169 if (enter.succeeded()) { |
| 131 result.Return(dispatcher(), | 170 result.Return(dispatcher(), |
| 132 enter.functions()->ReadPlainText( | 171 enter.functions()->ReadData( |
| 133 instance, | 172 instance, |
| 134 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); | 173 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 174 static_cast<PP_Flash_Clipboard_Format>(format))); | |
| 135 } | 175 } |
| 136 } | 176 } |
| 137 | 177 |
| 138 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( | 178 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData( |
| 139 PP_Instance instance, | 179 PP_Instance instance, |
| 140 int clipboard_type, | 180 int clipboard_type, |
| 141 SerializedVarReceiveInput text) { | 181 SerializedVarVectorReceiveInput formats_vector, |
| 182 SerializedVarVectorReceiveInput data_vector) { | |
| 142 EnterFlashClipboardNoLock enter(instance, true); | 183 EnterFlashClipboardNoLock enter(instance, true); |
| 143 if (enter.succeeded()) { | 184 if (enter.succeeded()) { |
| 144 int32_t result = enter.functions()->WritePlainText( | 185 // Convert parallel arrays of PP_Var into an array of |
| 186 // PP_Flash_Clipboard_Data_Item structs. | |
| 187 uint32_t formats_size; | |
| 188 uint32_t data_size; | |
| 189 PP_Var* formats = formats_vector.Get(dispatcher(), &formats_size); | |
| 190 PP_Var* data = data_vector.Get(dispatcher(), &data_size); | |
| 191 DCHECK(formats_size == data_size); | |
|
viettrungluu
2012/02/08 22:25:01
This may as well be a CHECK, imo.
raymes
2012/02/09 00:20:27
Done.
| |
| 192 | |
| 193 struct PP_Flash_Clipboard_Data_Item data_items[formats_size]; | |
|
viettrungluu
2012/02/08 22:25:01
nit: no struct
raymes
2012/02/09 00:20:27
Done.
| |
| 194 | |
| 195 for (uint32_t i = 0; i < formats_size; ++i) { | |
| 196 data_items[i].format = | |
| 197 static_cast<PP_Flash_Clipboard_Format>(formats[i].value.as_int); | |
| 198 data_items[i].data = data[i]; | |
| 199 } | |
| 200 | |
| 201 int32_t result = enter.functions()->WriteData( | |
| 145 instance, | 202 instance, |
| 146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 203 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 147 text.Get(dispatcher())); | 204 data_size, |
| 205 data_items); | |
| 148 DLOG_IF(WARNING, result != PP_OK) | 206 DLOG_IF(WARNING, result != PP_OK) |
| 149 << "Write to clipboard failed unexpectedly."; | 207 << "Write to clipboard failed unexpectedly."; |
| 150 (void)result; // Prevent warning in release mode. | 208 (void)result; // Prevent warning in release mode. |
| 151 } | 209 } |
| 152 } | 210 } |
| 153 | 211 |
| 154 } // namespace proxy | 212 } // namespace proxy |
| 155 } // namespace ppapi | 213 } // namespace ppapi |
| OLD | NEW |