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

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

Issue 10163012: Move the FlashClipboard API into the Flash one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/ppb_flash_clipboard_proxy.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/private/ppb_flash_clipboard.h"
9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/proxy/serialized_var.h"
12 #include "ppapi/thunk/enter.h"
13
14 using ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI;
15
16 namespace ppapi {
17 namespace proxy {
18
19 namespace {
20
21 typedef thunk::EnterFunctionNoLock<PPB_Flash_Clipboard_FunctionAPI>
22 EnterFlashClipboardNoLock;
23
24 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) {
25 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
26 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION;
27 }
28
29 bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) {
30 // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|.
31 return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT ||
32 format == PP_FLASH_CLIPBOARD_FORMAT_HTML ||
33 format == PP_FLASH_CLIPBOARD_FORMAT_RTF;
34 }
35
36 } // namespace
37
38 PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher)
39 : InterfaceProxy(dispatcher) {
40 }
41
42 PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() {
43 }
44
45 PPB_Flash_Clipboard_FunctionAPI*
46 PPB_Flash_Clipboard_Proxy::AsPPB_Flash_Clipboard_FunctionAPI() {
47 return this;
48 }
49
50 PP_Bool PPB_Flash_Clipboard_Proxy::IsFormatAvailable(
51 PP_Instance instance,
52 PP_Flash_Clipboard_Type clipboard_type,
53 PP_Flash_Clipboard_Format format) {
54 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
55 return PP_FALSE;
56
57 bool result = false;
58 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable(
59 API_ID_PPB_FLASH_CLIPBOARD,
60 instance,
61 static_cast<int>(clipboard_type),
62 static_cast<int>(format),
63 &result));
64 return PP_FromBool(result);
65 }
66 PP_Var PPB_Flash_Clipboard_Proxy::ReadData(
67 PP_Instance instance,
68 PP_Flash_Clipboard_Type clipboard_type,
69 PP_Flash_Clipboard_Format format) {
70 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
71 return PP_MakeUndefined();
72
73 ReceiveSerializedVarReturnValue result;
74 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadData(
75 API_ID_PPB_FLASH_CLIPBOARD, instance,
76 static_cast<int>(clipboard_type), static_cast<int>(format), &result));
77 return result.Return(dispatcher());
78 }
79
80
81 int32_t PPB_Flash_Clipboard_Proxy::WriteData(
82 PP_Instance instance,
83 PP_Flash_Clipboard_Type clipboard_type,
84 uint32_t data_item_count,
85 const PP_Flash_Clipboard_Format formats[],
86 const PP_Var data_items[]) {
87 if (!IsValidClipboardType(clipboard_type))
88 return PP_ERROR_BADARGUMENT;
89
90 for (size_t i = 0; i < data_item_count; ++i) {
91 if (!IsValidClipboardFormat(formats[i]))
92 return PP_ERROR_BADARGUMENT;
93 }
94
95 std::vector<int> formats_vector(formats, formats + data_item_count);
96
97 std::vector<SerializedVar> data_items_vector;
98 SerializedVarSendInput::ConvertVector(
99 dispatcher(),
100 data_items,
101 data_item_count,
102 &data_items_vector);
103
104 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData(
105 API_ID_PPB_FLASH_CLIPBOARD,
106 instance,
107 static_cast<int>(clipboard_type),
108 formats_vector,
109 data_items_vector));
110 // Assume success, since it allows us to avoid a sync IPC.
111 return PP_OK;
112 }
113
114 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
115 bool handled = true;
116 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
117 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
118 OnMsgIsFormatAvailable)
119 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData,
120 OnMsgReadData)
121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData,
122 OnMsgWriteData)
123 IPC_MESSAGE_UNHANDLED(handled = false)
124 IPC_END_MESSAGE_MAP()
125 return handled;
126 }
127
128 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
129 PP_Instance instance,
130 int clipboard_type,
131 int format,
132 bool* result) {
133 EnterFlashClipboardNoLock enter(instance, true);
134 if (enter.succeeded()) {
135 *result = PP_ToBool(enter.functions()->IsFormatAvailable(
136 instance,
137 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
138 static_cast<PP_Flash_Clipboard_Format>(format)));
139 } else {
140 *result = false;
141 }
142 }
143
144 void PPB_Flash_Clipboard_Proxy::OnMsgReadData(
145 PP_Instance instance,
146 int clipboard_type,
147 int format,
148 SerializedVarReturnValue result) {
149 EnterFlashClipboardNoLock enter(instance, true);
150 if (enter.succeeded()) {
151 result.Return(dispatcher(),
152 enter.functions()->ReadData(
153 instance,
154 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
155 static_cast<PP_Flash_Clipboard_Format>(format)));
156 }
157 }
158
159 void PPB_Flash_Clipboard_Proxy::OnMsgWriteData(
160 PP_Instance instance,
161 int clipboard_type,
162 const std::vector<int>& formats,
163 SerializedVarVectorReceiveInput data_items) {
164 EnterFlashClipboardNoLock enter(instance, true);
165 if (enter.succeeded()) {
166 uint32_t data_item_count;
167 PP_Var* data_items_array = data_items.Get(dispatcher(), &data_item_count);
168 CHECK(data_item_count == formats.size());
169
170 scoped_array<PP_Flash_Clipboard_Format> formats_array(
171 new PP_Flash_Clipboard_Format[formats.size()]);
172 for (uint32_t i = 0; i < formats.size(); ++i) {
173 formats_array[i] = static_cast<PP_Flash_Clipboard_Format>(formats[i]);
174 }
175
176 int32_t result = enter.functions()->WriteData(
177 instance,
178 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
179 data_item_count,
180 formats_array.get(),
181 data_items_array);
182 DLOG_IF(WARNING, result != PP_OK)
183 << "Write to clipboard failed unexpectedly.";
184 (void)result; // Prevent warning in release mode.
185 }
186 }
187
188 } // namespace proxy
189 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698