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

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

Issue 8365017: Convert the flash clipboard API to thunk system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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"
11 #include "ppapi/proxy/serialized_var.h" 11 #include "ppapi/proxy/serialized_var.h"
12 #include "ppapi/thunk/enter.h"
13
14 using ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI;
12 15
13 namespace ppapi { 16 namespace ppapi {
14 namespace proxy { 17 namespace proxy {
15 18
16 namespace { 19 namespace {
17 20
21 typedef thunk::EnterFunctionNoLock<PPB_Flash_Clipboard_FunctionAPI>
22 EnterFlashClipboardNoLock;
23
18 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { 24 bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) {
19 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || 25 return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
20 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION || 26 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION ||
21 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG; 27 clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG;
22 } 28 }
23 29
24 bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { 30 bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) {
25 // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|. 31 // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|.
26 return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || 32 return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT ||
27 format == PP_FLASH_CLIPBOARD_FORMAT_HTML; 33 format == PP_FLASH_CLIPBOARD_FORMAT_HTML;
28 } 34 }
29 35
30 PP_Bool IsFormatAvailable(PP_Instance instance_id, 36 } // namespace
31 PP_Flash_Clipboard_Type clipboard_type,
32 PP_Flash_Clipboard_Format format) {
33 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
34 if (!dispatcher)
35 return PP_FALSE;
36 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) {
37 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) 54 if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
38 return PP_FALSE; 55 return PP_FALSE;
39 56
40 bool result = false; 57 bool result = false;
41 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( 58 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable(
42 API_ID_PPB_FLASH_CLIPBOARD, 59 API_ID_PPB_FLASH_CLIPBOARD,
43 instance_id, 60 instance,
44 static_cast<int>(clipboard_type), 61 static_cast<int>(clipboard_type),
45 static_cast<int>(format), 62 static_cast<int>(format),
46 &result)); 63 &result));
47 return PP_FromBool(result); 64 return PP_FromBool(result);
48 } 65 }
49 66
50 PP_Var ReadPlainText(PP_Instance instance_id, 67 PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText(
51 PP_Flash_Clipboard_Type clipboard_type) { 68 PP_Instance instance,
52 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 69 PP_Flash_Clipboard_Type clipboard_type) {
53 if (!dispatcher)
54 return PP_MakeUndefined();
55
56 if (!IsValidClipboardType(clipboard_type)) 70 if (!IsValidClipboardType(clipboard_type))
57 return PP_MakeUndefined(); 71 return PP_MakeUndefined();
58 72
59 ReceiveSerializedVarReturnValue result; 73 ReceiveSerializedVarReturnValue result;
60 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( 74 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText(
61 API_ID_PPB_FLASH_CLIPBOARD, instance_id, 75 API_ID_PPB_FLASH_CLIPBOARD, instance,
62 static_cast<int>(clipboard_type), &result)); 76 static_cast<int>(clipboard_type), &result));
63 return result.Return(dispatcher); 77 return result.Return(dispatcher());
64 } 78 }
65 79
66 int32_t WritePlainText(PP_Instance instance_id, 80 int32_t PPB_Flash_Clipboard_Proxy::WritePlainText(
67 PP_Flash_Clipboard_Type clipboard_type, 81 PP_Instance instance,
68 PP_Var text) { 82 PP_Flash_Clipboard_Type clipboard_type,
69 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 83 const PP_Var& text) {
70 if (!dispatcher)
71 return PP_ERROR_BADARGUMENT;
72
73 if (!IsValidClipboardType(clipboard_type)) 84 if (!IsValidClipboardType(clipboard_type))
74 return PP_ERROR_BADARGUMENT; 85 return PP_ERROR_BADARGUMENT;
75 86
76 dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( 87 dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
77 API_ID_PPB_FLASH_CLIPBOARD, 88 API_ID_PPB_FLASH_CLIPBOARD,
78 instance_id, 89 instance,
79 static_cast<int>(clipboard_type), 90 static_cast<int>(clipboard_type),
80 SerializedVarSendInput(dispatcher, text))); 91 SerializedVarSendInput(dispatcher(), text)));
81 // Assume success, since it allows us to avoid a sync IPC. 92 // Assume success, since it allows us to avoid a sync IPC.
82 return PP_OK; 93 return PP_OK;
83 } 94 }
84 95
85 const PPB_Flash_Clipboard flash_clipboard_interface = {
86 &IsFormatAvailable,
87 &ReadPlainText,
88 &WritePlainText
89 };
90
91 InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher) {
92 return new PPB_Flash_Clipboard_Proxy(dispatcher);
93 }
94
95 } // namespace
96
97 PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher)
98 : InterfaceProxy(dispatcher),
99 ppb_flash_clipboard_impl_(NULL) {
100 if (!dispatcher->IsPlugin()) {
101 ppb_flash_clipboard_impl_ = static_cast<const PPB_Flash_Clipboard*>(
102 dispatcher->local_get_interface()(PPB_FLASH_CLIPBOARD_INTERFACE));
103 }
104 }
105
106 PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() {
107 }
108
109 // static
110 const PPB_Flash_Clipboard* PPB_Flash_Clipboard_Proxy::GetInterface() {
111 return &flash_clipboard_interface;
112 }
113
114 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { 96 bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
115 bool handled = true; 97 bool handled = true;
116 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) 98 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
117 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, 99 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
118 OnMsgIsFormatAvailable) 100 OnMsgIsFormatAvailable)
119 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, 101 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText,
120 OnMsgReadPlainText) 102 OnMsgReadPlainText)
121 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, 103 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText,
122 OnMsgWritePlainText) 104 OnMsgWritePlainText)
123 IPC_MESSAGE_UNHANDLED(handled = false) 105 IPC_MESSAGE_UNHANDLED(handled = false)
124 IPC_END_MESSAGE_MAP() 106 IPC_END_MESSAGE_MAP()
125 return handled; 107 return handled;
126 } 108 }
127 109
128 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( 110 void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
129 PP_Instance instance_id, 111 PP_Instance instance,
130 int clipboard_type, 112 int clipboard_type,
131 int format, 113 int format,
132 bool* result) { 114 bool* result) {
133 *result = PP_ToBool(ppb_flash_clipboard_impl_->IsFormatAvailable( 115 EnterFlashClipboardNoLock enter(instance, true);
134 instance_id, 116 if (enter.succeeded()) {
135 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), 117 *result = PP_ToBool(enter.functions()->IsFormatAvailable(
136 static_cast<PP_Flash_Clipboard_Format>(format))); 118 instance,
119 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
120 static_cast<PP_Flash_Clipboard_Format>(format)));
121 } else {
122 *result = false;
123 }
137 } 124 }
138 125
139 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( 126 void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText(
140 PP_Instance instance_id, 127 PP_Instance instance,
141 int clipboard_type, 128 int clipboard_type,
142 SerializedVarReturnValue result) { 129 SerializedVarReturnValue result) {
143 result.Return(dispatcher(), 130 EnterFlashClipboardNoLock enter(instance, true);
144 ppb_flash_clipboard_impl_->ReadPlainText( 131 if (enter.succeeded()) {
145 instance_id, 132 result.Return(dispatcher(),
146 static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); 133 enter.functions()->ReadPlainText(
134 instance,
135 static_cast<PP_Flash_Clipboard_Type>(clipboard_type)));
136 }
147 } 137 }
148 138
149 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( 139 void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText(
150 PP_Instance instance_id, 140 PP_Instance instance,
151 int clipboard_type, 141 int clipboard_type,
152 SerializedVarReceiveInput text) { 142 SerializedVarReceiveInput text) {
153 int32_t result = ppb_flash_clipboard_impl_->WritePlainText( 143 EnterFlashClipboardNoLock enter(instance, true);
154 instance_id, 144 if (enter.succeeded()) {
155 static_cast<PP_Flash_Clipboard_Type>(clipboard_type), 145 int32_t result = enter.functions()->WritePlainText(
156 text.Get(dispatcher())); 146 instance,
157 LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly."; 147 static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
148 text.Get(dispatcher()));
149 DLOG_IF(WARNING, result != PP_OK)
viettrungluu 2011/10/20 23:41:01 Why LOG_IF -> DLOG_IF? <shrug>
150 << "Write to clipboard failed unexpectedly.";
151 }
158 } 152 }
159 153
160 } // namespace proxy 154 } // namespace proxy
161 } // namespace ppapi 155 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698