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

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
« no previous file with comments | « ppapi/proxy/ppb_flash_clipboard_proxy.h ('k') | ppapi/tests/test_flash_clipboard.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PP_Flash_Clipboard_Format formats[],
85 const PP_Var 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 std::vector<int> formats_vector(formats, formats + data_item_count);
90
91 std::vector<SerializedVar> data_items_vector;
92 SerializedVarSendInput::ConvertVector(
93 dispatcher(),
94 data_items,
95 data_item_count,
96 &data_items_vector);
97
98 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData(
87 API_ID_PPB_FLASH_CLIPBOARD, 99 API_ID_PPB_FLASH_CLIPBOARD,
88 instance, 100 instance,
89 static_cast<int>(clipboard_type), 101 static_cast<int>(clipboard_type),
90 SerializedVarSendInput(dispatcher(), text))); 102 formats_vector,
103 data_items_vector));
91 // Assume success, since it allows us to avoid a sync IPC. 104 // Assume success, since it allows us to avoid a sync IPC.
92 return PP_OK; 105 return PP_OK;
93 } 106 }
94 107
95 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { 108 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
96 bool handled = true; 109 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) 110 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, 111 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
99 OnMsgIsFormatAvailable) 112 OnMsgIsFormatAvailable)
100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, 113 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData,
101 OnMsgReadPlainText) 114 OnMsgReadData)
102 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, 115 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData,
103 OnMsgWritePlainText) 116 OnMsgWriteData)
104 IPC_MESSAGE_UNHANDLED(handled = false) 117 IPC_MESSAGE_UNHANDLED(handled = false)
105 IPC_END_MESSAGE_MAP() 118 IPC_END_MESSAGE_MAP()
106 return handled; 119 return handled;
107 } 120 }
108 121
109 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( 122 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
110 PP_Instance instance, 123 PP_Instance instance,
111 int clipboard_type, 124 int clipboard_type,
112 int format, 125 int format,
113 bool* result) { 126 bool* result) {
114 EnterFlashClipboardNoLock enter(instance, true); 127 EnterFlashClipboardNoLock enter(instance, true);
115 if (enter.succeeded()) { 128 if (enter.succeeded()) {
116 *result = PP_ToBool(enter.functions()->IsFormatAvailable( 129 *result = PP_ToBool(enter.functions()->IsFormatAvailable(
117 instance, 130 instance,
118 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), 131 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
119 static_cast<PP_Flash_Clipboard_Format>(format))); 132 static_cast<PP_Flash_Clipboard_Format>(format)));
120 } else { 133 } else {
121 *result = false; 134 *result = false;
122 } 135 }
123 } 136 }
124 137
125 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( 138 void PPB_Flash_Clipboard_Proxy::OnMsgReadData(
126 PP_Instance instance, 139 PP_Instance instance,
127 int clipboard_type, 140 int clipboard_type,
141 int format,
128 SerializedVarReturnValue result) { 142 SerializedVarReturnValue result) {
129 EnterFlashClipboardNoLock enter(instance, true); 143 EnterFlashClipboardNoLock enter(instance, true);
130 if (enter.succeeded()) { 144 if (enter.succeeded()) {
131 result.Return(dispatcher(), 145 result.Return(dispatcher(),
132 enter.functions()->ReadPlainText( 146 enter.functions()->ReadData(
133 instance, 147 instance,
134 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); 148 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
149 static_cast<PP_Flash_Clipboard_Format>(format)));
135 } 150 }
136 } 151 }
137 152
138 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( 153 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData(
139 PP_Instance instance, 154 PP_Instance instance,
140 int clipboard_type, 155 int clipboard_type,
141 SerializedVarReceiveInput text) { 156 std::vector<int> formats,
157 SerializedVarVectorReceiveInput data_items) {
142 EnterFlashClipboardNoLock enter(instance, true); 158 EnterFlashClipboardNoLock enter(instance, true);
143 if (enter.succeeded()) { 159 if (enter.succeeded()) {
144 int32_t result = enter.functions()->WritePlainText( 160 uint32_t data_item_count;
161 PP_Var* data_items_array = data_items.Get(dispatcher(), &data_item_count);
162 CHECK(data_item_count == formats.size());
163
164 scoped_array<PP_Flash_Clipboard_Format> formats_array(
165 new PP_Flash_Clipboard_Format[formats.size()]);
166 for (uint32_t i = 0; i < formats.size(); ++i) {
167 formats_array[i] = static_cast<PP_Flash_Clipboard_Format>(formats[i]);
168 }
169
170 int32_t result = enter.functions()->WriteData(
145 instance, 171 instance,
146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), 172 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
147 text.Get(dispatcher())); 173 data_item_count,
174 formats_array.get(),
175 data_items_array);
148 DLOG_IF(WARNING, result != PP_OK) 176 DLOG_IF(WARNING, result != PP_OK)
149 << "Write to clipboard failed unexpectedly."; 177 << "Write to clipboard failed unexpectedly.";
150 (void)result; // Prevent warning in release mode. 178 (void)result; // Prevent warning in release mode.
151 } 179 }
152 } 180 }
153 181
154 } // namespace proxy 182 } // namespace proxy
155 } // namespace ppapi 183 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_clipboard_proxy.h ('k') | ppapi/tests/test_flash_clipboard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698