summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/ppb_flash_clipboard_proxy.cc
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:00:05 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:00:05 +0000
commit5cf8a5b6283f30685a063a52efd9800cf23ab1f6 (patch)
tree719ae2b30e036b7995bfb761c46ff52892fe1af7 /ppapi/proxy/ppb_flash_clipboard_proxy.cc
parent0934de8ac6f5ea6f4f53e5beb44413b3b5fd2c36 (diff)
downloadchromium_src-5cf8a5b6283f30685a063a52efd9800cf23ab1f6.zip
chromium_src-5cf8a5b6283f30685a063a52efd9800cf23ab1f6.tar.gz
chromium_src-5cf8a5b6283f30685a063a52efd9800cf23ab1f6.tar.bz2
Pepper/Flapper: Implement proxy for clipboard stuff.
BUG=none TEST=none Review URL: http://codereview.chromium.org/6650029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_flash_clipboard_proxy.cc')
-rw-r--r--ppapi/proxy/ppb_flash_clipboard_proxy.cc125
1 files changed, 125 insertions, 0 deletions
diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc
new file mode 100644
index 0000000..a849071
--- /dev/null
+++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc
@@ -0,0 +1,125 @@
+// 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 pp {
+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;
+}
+
+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 = {
+ &ReadPlainText,
+ &WritePlainText
+};
+
+InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher,
+ const void* target_interface) {
+ return new PPB_Flash_Clipboard_Proxy(dispatcher, target_interface);
+}
+
+} // namespace
+
+PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(
+ Dispatcher* dispatcher, const void* target_interface)
+ : InterfaceProxy(dispatcher, target_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_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::OnMsgReadPlainText(
+ PP_Instance instance_id,
+ int clipboard_type,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(),
+ ppb_flash_clipboard_target()->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_target()->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 pp