1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/proxy/ppb_flash_clipboard_proxy.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/serialized_var.h"
namespace ppapi {
namespace proxy {
namespace {
bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) {
return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION ||
clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG;
}
bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) {
// Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|.
return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT ||
format == PP_FLASH_CLIPBOARD_FORMAT_HTML;
}
PP_Bool IsFormatAvailable(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_FALSE;
if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
return PP_FALSE;
bool result = false;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable(
INTERFACE_ID_PPB_FLASH_CLIPBOARD,
instance_id,
static_cast<int>(clipboard_type),
static_cast<int>(format),
&result));
return PP_FromBool(result);
}
PP_Var ReadPlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_MakeUndefined();
if (!IsValidClipboardType(clipboard_type))
return PP_MakeUndefined();
ReceiveSerializedVarReturnValue result;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText(
INTERFACE_ID_PPB_FLASH_CLIPBOARD, instance_id,
static_cast<int>(clipboard_type), &result));
return result.Return(dispatcher);
}
int32_t WritePlainText(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
PP_Var text) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
if (!dispatcher)
return PP_ERROR_BADARGUMENT;
if (!IsValidClipboardType(clipboard_type))
return PP_ERROR_BADARGUMENT;
dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
INTERFACE_ID_PPB_FLASH_CLIPBOARD,
instance_id,
static_cast<int>(clipboard_type),
SerializedVarSendInput(dispatcher, text)));
// Assume success, since it allows us to avoid a sync IPC.
return PP_OK;
}
const PPB_Flash_Clipboard flash_clipboard_interface = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText
};
InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher) {
return new PPB_Flash_Clipboard_Proxy(dispatcher);
}
} // namespace
PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher),
ppb_flash_clipboard_impl_(NULL) {
if (!dispatcher->IsPlugin()) {
ppb_flash_clipboard_impl_ = static_cast<const PPB_Flash_Clipboard*>(
dispatcher->local_get_interface()(PPB_FLASH_CLIPBOARD_INTERFACE));
}
}
PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() {
}
// static
const InterfaceProxy::Info* PPB_Flash_Clipboard_Proxy::GetInfo() {
static const Info info = {
&flash_clipboard_interface,
PPB_FLASH_CLIPBOARD_INTERFACE,
INTERFACE_ID_PPB_FLASH_CLIPBOARD,
false,
&CreateFlashClipboardProxy
};
return &info;
}
bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
OnMsgIsFormatAvailable)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText,
OnMsgReadPlainText)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText,
OnMsgWritePlainText)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
PP_Instance instance_id,
int clipboard_type,
int format,
bool* result) {
*result = PP_ToBool(ppb_flash_clipboard_impl_->IsFormatAvailable(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
static_cast<PP_Flash_Clipboard_Format>(format)));
}
void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText(
PP_Instance instance_id,
int clipboard_type,
SerializedVarReturnValue result) {
result.Return(dispatcher(),
ppb_flash_clipboard_impl_->ReadPlainText(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type)));
}
void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText(
PP_Instance instance_id,
int clipboard_type,
SerializedVarReceiveInput text) {
int32_t result = ppb_flash_clipboard_impl_->WritePlainText(
instance_id,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
text.Get(dispatcher()));
LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly.";
}
} // namespace proxy
} // namespace ppapi
|