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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 bool result = false; | 56 bool result = false; |
57 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( | 57 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( |
58 API_ID_PPB_FLASH_CLIPBOARD, | 58 API_ID_PPB_FLASH_CLIPBOARD, |
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 PP_Var PPB_Flash_Clipboard_Proxy::ReadData( |
66 PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText( | |
67 PP_Instance instance, | 66 PP_Instance instance, |
68 PP_Flash_Clipboard_Type clipboard_type) { | 67 PP_Flash_Clipboard_Type clipboard_type, |
69 if (!IsValidClipboardType(clipboard_type)) | 68 PP_Flash_Clipboard_Format format) { |
| 69 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) |
70 return PP_MakeUndefined(); | 70 return PP_MakeUndefined(); |
71 | 71 |
72 ReceiveSerializedVarReturnValue result; | 72 ReceiveSerializedVarReturnValue result; |
73 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( | 73 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadData( |
74 API_ID_PPB_FLASH_CLIPBOARD, instance, | 74 API_ID_PPB_FLASH_CLIPBOARD, instance, |
75 static_cast<int>(clipboard_type), &result)); | 75 static_cast<int>(clipboard_type), static_cast<int>(format), &result)); |
76 return result.Return(dispatcher()); | 76 return result.Return(dispatcher()); |
77 } | 77 } |
78 | 78 |
79 int32_t PPB_Flash_Clipboard_Proxy::WritePlainText( | 79 |
| 80 int32_t PPB_Flash_Clipboard_Proxy::WriteData( |
80 PP_Instance instance, | 81 PP_Instance instance, |
81 PP_Flash_Clipboard_Type clipboard_type, | 82 PP_Flash_Clipboard_Type clipboard_type, |
82 const PP_Var& text) { | 83 uint32_t data_item_count, |
| 84 const struct |
| 85 PP_Flash_Clipboard_Data_Item data_items[]) { |
83 if (!IsValidClipboardType(clipboard_type)) | 86 if (!IsValidClipboardType(clipboard_type)) |
84 return PP_ERROR_BADARGUMENT; | 87 return PP_ERROR_BADARGUMENT; |
85 | 88 |
86 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( | 89 // Convert the array of PP_Flash_Clipboard_Data_Item into two parallel |
| 90 // arrays of format and corresponding data. |
| 91 PP_Var formats[data_item_count]; |
| 92 PP_Var data[data_item_count]; |
| 93 |
| 94 for (uint32_t i = 0; i < data_item_count; ++i) { |
| 95 formats[i] = PP_MakeInt32(data_items[i].format); |
| 96 data[i] = data_items[i].data; |
| 97 } |
| 98 |
| 99 std::vector<SerializedVar> formats_converted; |
| 100 std::vector<SerializedVar> data_converted; |
| 101 SerializedVarSendInput::ConvertVector(dispatcher(), formats, data_item_count, |
| 102 &formats_converted); |
| 103 SerializedVarSendInput::ConvertVector(dispatcher(), data, data_item_count, |
| 104 &data_converted); |
| 105 |
| 106 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData( |
87 API_ID_PPB_FLASH_CLIPBOARD, | 107 API_ID_PPB_FLASH_CLIPBOARD, |
88 instance, | 108 instance, |
89 static_cast<int>(clipboard_type), | 109 static_cast<int>(clipboard_type), |
90 SerializedVarSendInput(dispatcher(), text))); | 110 formats_converted, |
| 111 data_converted)); |
91 // Assume success, since it allows us to avoid a sync IPC. | 112 // Assume success, since it allows us to avoid a sync IPC. |
92 return PP_OK; | 113 return PP_OK; |
93 } | 114 } |
94 | 115 |
95 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { | 116 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
96 bool handled = true; | 117 bool handled = true; |
97 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) | 118 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, | 119 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, |
99 OnMsgIsFormatAvailable) | 120 OnMsgIsFormatAvailable) |
100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, | 121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData, |
101 OnMsgReadPlainText) | 122 OnMsgReadData) |
102 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, | 123 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData, |
103 OnMsgWritePlainText) | 124 OnMsgWriteData) |
104 IPC_MESSAGE_UNHANDLED(handled = false) | 125 IPC_MESSAGE_UNHANDLED(handled = false) |
105 IPC_END_MESSAGE_MAP() | 126 IPC_END_MESSAGE_MAP() |
106 return handled; | 127 return handled; |
107 } | 128 } |
108 | 129 |
109 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( | 130 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( |
110 PP_Instance instance, | 131 PP_Instance instance, |
111 int clipboard_type, | 132 int clipboard_type, |
112 int format, | 133 int format, |
113 bool* result) { | 134 bool* result) { |
114 EnterFlashClipboardNoLock enter(instance, true); | 135 EnterFlashClipboardNoLock enter(instance, true); |
115 if (enter.succeeded()) { | 136 if (enter.succeeded()) { |
116 *result = PP_ToBool(enter.functions()->IsFormatAvailable( | 137 *result = PP_ToBool(enter.functions()->IsFormatAvailable( |
117 instance, | 138 instance, |
118 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 139 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
119 static_cast<PP_Flash_Clipboard_Format>(format))); | 140 static_cast<PP_Flash_Clipboard_Format>(format))); |
120 } else { | 141 } else { |
121 *result = false; | 142 *result = false; |
122 } | 143 } |
123 } | 144 } |
124 | 145 |
125 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( | 146 void PPB_Flash_Clipboard_Proxy::OnMsgReadData( |
126 PP_Instance instance, | 147 PP_Instance instance, |
127 int clipboard_type, | 148 int clipboard_type, |
| 149 int format, |
128 SerializedVarReturnValue result) { | 150 SerializedVarReturnValue result) { |
129 EnterFlashClipboardNoLock enter(instance, true); | 151 EnterFlashClipboardNoLock enter(instance, true); |
130 if (enter.succeeded()) { | 152 if (enter.succeeded()) { |
131 result.Return(dispatcher(), | 153 result.Return(dispatcher(), |
132 enter.functions()->ReadPlainText( | 154 enter.functions()->ReadData( |
133 instance, | 155 instance, |
134 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); | 156 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
| 157 static_cast<PP_Flash_Clipboard_Format>(format))); |
135 } | 158 } |
136 } | 159 } |
137 | 160 |
138 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( | 161 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData( |
139 PP_Instance instance, | 162 PP_Instance instance, |
140 int clipboard_type, | 163 int clipboard_type, |
141 SerializedVarReceiveInput text) { | 164 SerializedVarVectorReceiveInput formats_vector, |
| 165 SerializedVarVectorReceiveInput data_vector) { |
142 EnterFlashClipboardNoLock enter(instance, true); | 166 EnterFlashClipboardNoLock enter(instance, true); |
143 if (enter.succeeded()) { | 167 if (enter.succeeded()) { |
144 int32_t result = enter.functions()->WritePlainText( | 168 // Convert parallel arrays of PP_Var into an array of |
| 169 // PP_Flash_Clipboard_Data_Item structs. |
| 170 uint32_t formats_size; |
| 171 uint32_t data_size; |
| 172 PP_Var* formats = formats_vector.Get(dispatcher(), &formats_size); |
| 173 PP_Var* data = data_vector.Get(dispatcher(), &data_size); |
| 174 CHECK(formats_size == data_size); |
| 175 |
| 176 PP_Flash_Clipboard_Data_Item data_items[formats_size]; |
| 177 |
| 178 for (uint32_t i = 0; i < formats_size; ++i) { |
| 179 data_items[i].format = |
| 180 static_cast<PP_Flash_Clipboard_Format>(formats[i].value.as_int); |
| 181 data_items[i].data = data[i]; |
| 182 } |
| 183 |
| 184 int32_t result = enter.functions()->WriteData( |
145 instance, | 185 instance, |
146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 186 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
147 text.Get(dispatcher())); | 187 data_size, |
| 188 data_items); |
148 DLOG_IF(WARNING, result != PP_OK) | 189 DLOG_IF(WARNING, result != PP_OK) |
149 << "Write to clipboard failed unexpectedly."; | 190 << "Write to clipboard failed unexpectedly."; |
150 (void)result; // Prevent warning in release mode. | 191 (void)result; // Prevent warning in release mode. |
151 } | 192 } |
152 } | 193 } |
153 | 194 |
154 } // namespace proxy | 195 } // namespace proxy |
155 } // namespace ppapi | 196 } // namespace ppapi |
OLD | NEW |