Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(862)

Side by Side Diff: ppapi/proxy/ppb_flash_clipboard_proxy.cc

Issue 9212066: Modified the flash cipboard interface to add html clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( 86 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
87 API_ID_PPB_FLASH_CLIPBOARD, 87 API_ID_PPB_FLASH_CLIPBOARD,
88 instance, 88 instance,
89 static_cast<int>(clipboard_type), 89 static_cast<int>(clipboard_type),
90 SerializedVarSendInput(dispatcher(), text))); 90 SerializedVarSendInput(dispatcher(), text)));
91 // Assume success, since it allows us to avoid a sync IPC. 91 // Assume success, since it allows us to avoid a sync IPC.
92 return PP_OK; 92 return PP_OK;
93 } 93 }
94 94
95 PP_Var PPB_Flash_Clipboard_Proxy::ReadData(
96 PP_Instance instance,
97 PP_Flash_Clipboard_Type clipboard_type,
98 PP_Flash_Clipboard_Format format) {
99 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
100 return PP_MakeUndefined();
101
102 ReceiveSerializedVarReturnValue result;
103 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadData(
104 API_ID_PPB_FLASH_CLIPBOARD, instance,
105 static_cast<int>(clipboard_type), static_cast<int>(format), &result));
106 return result.Return(dispatcher());
107 }
108
109
110 int32_t PPB_Flash_Clipboard_Proxy::WriteData(
111 PP_Instance instance,
112 PP_Flash_Clipboard_Type clipboard_type,
113 uint32_t data_item_count,
114 const struct
115 PP_Flash_Clipboard_Data_Item data_items[]) {
116 if (!IsValidClipboardType(clipboard_type))
117 return PP_ERROR_BADARGUMENT;
118
119 // Convert the array of PP_Flash_Clipboard_Data_Item into two parallel
120 // arrays of format and corresponding data.
121 PP_Var formats[data_item_count];
122 PP_Var data[data_item_count];
123
124 for (uint32_t i = 0; i < data_item_count; ++i) {
125 formats[i] = PP_MakeInt32(data_items[i].format);
126 data[i] = data_items[i].data;
127 }
128
129 std::vector<SerializedVar> formats_converted;
130 std::vector<SerializedVar> data_converted;
131 SerializedVarSendInput::ConvertVector(dispatcher(), formats, data_item_count,
132 &formats_converted);
133 SerializedVarSendInput::ConvertVector(dispatcher(), data, data_item_count,
134 &data_converted);
135
136 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData(
137 API_ID_PPB_FLASH_CLIPBOARD,
138 instance,
139 static_cast<int>(clipboard_type),
140 formats_converted,
141 data_converted));
142 // Assume success, since it allows us to avoid a sync IPC.
143 return PP_OK;
144 }
145
95 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { 146 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
96 bool handled = true; 147 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) 148 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, 149 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
99 OnMsgIsFormatAvailable) 150 OnMsgIsFormatAvailable)
100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, 151 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText,
101 OnMsgReadPlainText) 152 OnMsgReadPlainText)
102 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, 153 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText,
103 OnMsgWritePlainText) 154 OnMsgWritePlainText)
155 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData,
156 OnMsgReadData)
157 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData,
158 OnMsgWriteData)
104 IPC_MESSAGE_UNHANDLED(handled = false) 159 IPC_MESSAGE_UNHANDLED(handled = false)
105 IPC_END_MESSAGE_MAP() 160 IPC_END_MESSAGE_MAP()
106 return handled; 161 return handled;
107 } 162 }
108 163
109 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( 164 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
110 PP_Instance instance, 165 PP_Instance instance,
111 int clipboard_type, 166 int clipboard_type,
112 int format, 167 int format,
113 bool* result) { 168 bool* result) {
(...skipping 30 matching lines...) Expand all
144 int32_t result = enter.functions()->WritePlainText( 199 int32_t result = enter.functions()->WritePlainText(
145 instance, 200 instance,
146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), 201 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
147 text.Get(dispatcher())); 202 text.Get(dispatcher()));
148 DLOG_IF(WARNING, result != PP_OK) 203 DLOG_IF(WARNING, result != PP_OK)
149 << "Write to clipboard failed unexpectedly."; 204 << "Write to clipboard failed unexpectedly.";
150 (void)result; // Prevent warning in release mode. 205 (void)result; // Prevent warning in release mode.
151 } 206 }
152 } 207 }
153 208
209 void PPB_Flash_Clipboard_Proxy::OnMsgReadData(
210 PP_Instance instance,
211 int clipboard_type,
212 int format,
213 SerializedVarReturnValue result) {
214 EnterFlashClipboardNoLock enter(instance, true);
215 if (enter.succeeded()) {
216 result.Return(dispatcher(),
217 enter.functions()->ReadData(
218 instance,
219 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
220 static_cast<PP_Flash_Clipboard_Format>(format)));
221 }
222 }
223
224 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData(
225 PP_Instance instance,
226 int clipboard_type,
227 SerializedVarVectorReceiveInput formats_vector,
228 SerializedVarVectorReceiveInput data_vector) {
229 EnterFlashClipboardNoLock enter(instance, true);
230 if (enter.succeeded()) {
231 // Convert parallel arrays of PP_Var into an array of
232 // PP_Flash_Clipboard_Data_Item structs.
233 uint32_t formats_size;
234 uint32_t data_size;
235 PP_Var* formats = formats_vector.Get(dispatcher(), &formats_size);
236 PP_Var* data = data_vector.Get(dispatcher(), &data_size);
237 DCHECK(formats_size == data_size);
238
239 struct PP_Flash_Clipboard_Data_Item data_items[formats_size];
240
241 for (uint32_t i = 0; i < formats_size; ++i) {
242 data_items[i].format =
243 static_cast<PP_Flash_Clipboard_Format>(formats[i].value.as_int);
244 data_items[i].data = data[i];
245 }
246
247 int32_t result = enter.functions()->WriteData(
248 instance,
249 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
250 data_size,
251 data_items);
252 DLOG_IF(WARNING, result != PP_OK)
253 << "Write to clipboard failed unexpectedly.";
254 (void)result; // Prevent warning in release mode.
255 }
256 }
257
154 } // namespace proxy 258 } // namespace proxy
155 } // namespace ppapi 259 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698