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[]) { | |
dmichael (off chromium)
2012/02/23 18:13:25
nit: shouldn't this be on line 84?
raymes
2012/02/24 07:28:28
Done.
| |
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 scoped_array<PP_Var> formats(new PP_Var[data_item_count]); | |
92 scoped_array<PP_Var> data(new PP_Var[data_item_count]); | |
93 | |
94 for (uint32_t i = 0; i < data_item_count; ++i) { | |
95 formats[i] = PP_MakeInt32(data_items[i].format); | |
dmichael (off chromium)
2012/02/23 18:13:25
Can't you just send a vector of int32? Why turn th
raymes
2012/02/24 07:28:28
Ah I didn't know about this. Done.
On 2012/02/23
| |
96 data[i] = data_items[i].data; | |
97 } | |
98 | |
99 std::vector<SerializedVar> formats_converted; | |
100 std::vector<SerializedVar> data_converted; | |
101 SerializedVarSendInput::ConvertVector( | |
102 dispatcher(), | |
103 formats.get(), | |
104 data_item_count, | |
105 &formats_converted); | |
106 SerializedVarSendInput::ConvertVector( | |
107 dispatcher(), | |
108 data.get(), | |
109 data_item_count, | |
110 &data_converted); | |
111 | |
112 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData( | |
87 API_ID_PPB_FLASH_CLIPBOARD, | 113 API_ID_PPB_FLASH_CLIPBOARD, |
88 instance, | 114 instance, |
89 static_cast<int>(clipboard_type), | 115 static_cast<int>(clipboard_type), |
90 SerializedVarSendInput(dispatcher(), text))); | 116 formats_converted, |
117 data_converted)); | |
91 // Assume success, since it allows us to avoid a sync IPC. | 118 // Assume success, since it allows us to avoid a sync IPC. |
92 return PP_OK; | 119 return PP_OK; |
93 } | 120 } |
94 | 121 |
95 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { | 122 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { |
96 bool handled = true; | 123 bool handled = true; |
97 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) | 124 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) |
98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, | 125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, |
99 OnMsgIsFormatAvailable) | 126 OnMsgIsFormatAvailable) |
100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, | 127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData, |
101 OnMsgReadPlainText) | 128 OnMsgReadData) |
102 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, | 129 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData, |
103 OnMsgWritePlainText) | 130 OnMsgWriteData) |
104 IPC_MESSAGE_UNHANDLED(handled = false) | 131 IPC_MESSAGE_UNHANDLED(handled = false) |
105 IPC_END_MESSAGE_MAP() | 132 IPC_END_MESSAGE_MAP() |
106 return handled; | 133 return handled; |
107 } | 134 } |
108 | 135 |
109 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( | 136 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( |
110 PP_Instance instance, | 137 PP_Instance instance, |
111 int clipboard_type, | 138 int clipboard_type, |
112 int format, | 139 int format, |
113 bool* result) { | 140 bool* result) { |
114 EnterFlashClipboardNoLock enter(instance, true); | 141 EnterFlashClipboardNoLock enter(instance, true); |
115 if (enter.succeeded()) { | 142 if (enter.succeeded()) { |
116 *result = PP_ToBool(enter.functions()->IsFormatAvailable( | 143 *result = PP_ToBool(enter.functions()->IsFormatAvailable( |
117 instance, | 144 instance, |
118 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 145 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
119 static_cast<PP_Flash_Clipboard_Format>(format))); | 146 static_cast<PP_Flash_Clipboard_Format>(format))); |
120 } else { | 147 } else { |
121 *result = false; | 148 *result = false; |
122 } | 149 } |
123 } | 150 } |
124 | 151 |
125 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( | 152 void PPB_Flash_Clipboard_Proxy::OnMsgReadData( |
126 PP_Instance instance, | 153 PP_Instance instance, |
127 int clipboard_type, | 154 int clipboard_type, |
155 int format, | |
128 SerializedVarReturnValue result) { | 156 SerializedVarReturnValue result) { |
129 EnterFlashClipboardNoLock enter(instance, true); | 157 EnterFlashClipboardNoLock enter(instance, true); |
130 if (enter.succeeded()) { | 158 if (enter.succeeded()) { |
131 result.Return(dispatcher(), | 159 result.Return(dispatcher(), |
132 enter.functions()->ReadPlainText( | 160 enter.functions()->ReadData( |
133 instance, | 161 instance, |
134 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); | 162 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
163 static_cast<PP_Flash_Clipboard_Format>(format))); | |
135 } | 164 } |
136 } | 165 } |
137 | 166 |
138 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( | 167 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData( |
139 PP_Instance instance, | 168 PP_Instance instance, |
140 int clipboard_type, | 169 int clipboard_type, |
141 SerializedVarReceiveInput text) { | 170 SerializedVarVectorReceiveInput formats_vector, |
171 SerializedVarVectorReceiveInput data_vector) { | |
142 EnterFlashClipboardNoLock enter(instance, true); | 172 EnterFlashClipboardNoLock enter(instance, true); |
143 if (enter.succeeded()) { | 173 if (enter.succeeded()) { |
144 int32_t result = enter.functions()->WritePlainText( | 174 // Convert parallel arrays of PP_Var into an array of |
175 // PP_Flash_Clipboard_Data_Item structs. | |
176 uint32_t formats_size; | |
177 uint32_t data_size; | |
178 PP_Var* formats = formats_vector.Get(dispatcher(), &formats_size); | |
179 PP_Var* data = data_vector.Get(dispatcher(), &data_size); | |
180 CHECK(formats_size == data_size); | |
181 | |
182 scoped_array<PP_Flash_Clipboard_Data_Item> data_items( | |
183 new PP_Flash_Clipboard_Data_Item[formats_size]); | |
184 | |
185 for (uint32_t i = 0; i < formats_size; ++i) { | |
186 data_items[i].format = | |
187 static_cast<PP_Flash_Clipboard_Format>(formats[i].value.as_int); | |
188 data_items[i].data = data[i]; | |
189 } | |
190 | |
191 int32_t result = enter.functions()->WriteData( | |
145 instance, | 192 instance, |
146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), | 193 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), |
147 text.Get(dispatcher())); | 194 data_size, |
195 data_items.get()); | |
148 DLOG_IF(WARNING, result != PP_OK) | 196 DLOG_IF(WARNING, result != PP_OK) |
149 << "Write to clipboard failed unexpectedly."; | 197 << "Write to clipboard failed unexpectedly."; |
150 (void)result; // Prevent warning in release mode. | 198 (void)result; // Prevent warning in release mode. |
151 } | 199 } |
152 } | 200 } |
153 | 201 |
154 } // namespace proxy | 202 } // namespace proxy |
155 } // namespace ppapi | 203 } // namespace ppapi |
OLD | NEW |