summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ppapi/c/private/ppb_flash_clipboard.h33
-rw-r--r--ppapi/c/private/ppb_flash_menu.h2
-rw-r--r--ppapi/ppapi_cpp.gypi2
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc4
-rw-r--r--webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc102
-rw-r--r--webkit/plugins/ppapi/ppb_flash_clipboard_impl.h21
7 files changed, 164 insertions, 2 deletions
diff --git a/ppapi/c/private/ppb_flash_clipboard.h b/ppapi/c/private/ppb_flash_clipboard.h
new file mode 100644
index 0000000..c16ae36
--- /dev/null
+++ b/ppapi/c/private/ppb_flash_clipboard.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
+#define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
+
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_var.h"
+
+#define PPB_FLASH_CLIPBOARD_INTERFACE "PPB_Flash_Clipboard;2"
+
+typedef enum {
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD = 0,
+ PP_FLASH_CLIPBOARD_TYPE_SELECTION = 1,
+ PP_FLASH_CLIPBOARD_TYPE_DRAG = 2
+} PP_Flash_Clipboard_Type;
+
+struct PPB_Flash_Clipboard {
+ // Reads plain text data from the clipboard.
+ struct PP_Var (*ReadPlainText)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type);
+
+ // Writes plain text data to the clipboard. If |text| is too large, it will
+ // return |PP_ERROR_NOSPACE| (and not write to the clipboard).
+ int32_t (*WritePlainText)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type,
+ struct PP_Var text);
+
+ // TODO(vtl): More formats, a |IsFormatAvailable()|, ....
+};
+
+#endif // PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
diff --git a/ppapi/c/private/ppb_flash_menu.h b/ppapi/c/private/ppb_flash_menu.h
index b9a0b95..7fc62e5 100644
--- a/ppapi/c/private/ppb_flash_menu.h
+++ b/ppapi/c/private/ppb_flash_menu.h
@@ -10,8 +10,6 @@
#include "ppapi/c/pp_point.h"
#include "ppapi/c/pp_resource.h"
-// PPB_Flash -------------------------------------------------------------------
-
#define PPB_FLASH_MENU_INTERFACE "PPB_Flash_Menu;1"
struct PP_CompletionCallback;
diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi
index 36840d9..0724961 100644
--- a/ppapi/ppapi_cpp.gypi
+++ b/ppapi/ppapi_cpp.gypi
@@ -82,6 +82,8 @@
# Private interfaces.
'c/private/ppb_flash.h',
+ 'c/private/ppb_flash_clipboard.h',
+ 'c/private/ppb_flash_file.h',
'c/private/ppb_flash_menu.h',
'c/private/ppb_flash_net_connector.h',
'c/private/ppb_nacl_private.h',
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 45ca5db..0f27b75 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -297,6 +297,8 @@
'../plugins/ppapi/ppb_file_ref_impl.h',
'../plugins/ppapi/ppb_file_system_impl.cc',
'../plugins/ppapi/ppb_file_system_impl.h',
+ '../plugins/ppapi/ppb_flash_clipboard_impl.cc',
+ '../plugins/ppapi/ppb_flash_clipboard_impl.h',
'../plugins/ppapi/ppb_flash_file_impl.cc',
'../plugins/ppapi/ppb_flash_file_impl.h',
'../plugins/ppapi/ppb_flash_impl.cc',
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 1d7c091..6c670f9 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -50,6 +50,7 @@
#include "ppapi/c/ppp.h"
#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/private/ppb_flash.h"
+#include "ppapi/c/private/ppb_flash_clipboard.h"
#include "ppapi/c/private/ppb_flash_file.h"
#include "ppapi/c/private/ppb_flash_menu.h"
#include "ppapi/c/private/ppb_flash_net_connector.h"
@@ -70,6 +71,7 @@
#include "webkit/plugins/ppapi/ppb_file_io_impl.h"
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
#include "webkit/plugins/ppapi/ppb_file_system_impl.h"
+#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_file_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_impl.h"
#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h"
@@ -250,6 +252,8 @@ const void* GetInterface(const char* name) {
return PluginInstance::GetFindInterface();
if (strcmp(name, PPB_FLASH_INTERFACE) == 0)
return PPB_Flash_Impl::GetInterface();
+ if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE) == 0)
+ return PPB_Flash_Clipboard_Impl::GetInterface();
if (strcmp(name, PPB_FLASH_FILE_FILEREF_INTERFACE) == 0)
return PPB_Flash_File_FileRef_Impl::GetInterface();
if (strcmp(name, PPB_FLASH_FILE_MODULELOCAL_INTERFACE) == 0)
diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
new file mode 100644
index 0000000..630a897
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
@@ -0,0 +1,102 @@
+// 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 "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h"
+
+#include <algorithm>
+#include <string>
+
+#include "base/logging.h"
+#include "base/ref_counted.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/private/ppb_flash_clipboard.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebClipboard.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/resource_tracker.h"
+#include "webkit/plugins/ppapi/var.h"
+
+namespace webkit {
+namespace ppapi {
+
+namespace {
+
+const size_t kMaxClipboardWriteSize = 1000000;
+
+WebKit::WebClipboard::Buffer ConvertClipboardType(
+ PP_Flash_Clipboard_Type type) {
+ switch (type) {
+ case PP_FLASH_CLIPBOARD_TYPE_STANDARD:
+ return WebKit::WebClipboard::BufferStandard;
+ case PP_FLASH_CLIPBOARD_TYPE_SELECTION:
+ return WebKit::WebClipboard::BufferSelection;
+ case PP_FLASH_CLIPBOARD_TYPE_DRAG:
+ return WebKit::WebClipboard::BufferDrag;
+ default:
+ NOTREACHED();
+ return WebKit::WebClipboard::BufferStandard;
+ }
+}
+
+PP_Var ReadPlainText(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
+ if (!instance)
+ return PP_MakeNull();
+
+ WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
+ if (!web_clipboard) {
+ NOTREACHED();
+ return PP_MakeNull();
+ }
+
+ WebKit::WebCString s =
+ web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8();
+ return StringVar::StringToPPVar(instance->module(), s);
+}
+
+int32_t WritePlainText(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Var text) {
+ scoped_refptr<StringVar> text_string(StringVar::FromPPVar(text));
+ if (!text_string)
+ return PP_ERROR_BADARGUMENT;
+
+ if (text_string->value().length() > kMaxClipboardWriteSize)
+ return PP_ERROR_NOSPACE;
+
+ if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) {
+ NOTIMPLEMENTED();
+ return PP_ERROR_FAILED;
+ }
+
+ WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard();
+ if (!web_clipboard) {
+ NOTREACHED();
+ return PP_ERROR_FAILED;
+ }
+
+ web_clipboard->writePlainText(
+ WebKit::WebCString(text_string->value()).utf16());
+ return PP_OK;
+}
+
+const PPB_Flash_Clipboard ppb_flash_clipboard = {
+ &ReadPlainText,
+ &WritePlainText,
+};
+
+} // namespace
+
+// static
+const PPB_Flash_Clipboard*
+ PPB_Flash_Clipboard_Impl::GetInterface() {
+ return &ppb_flash_clipboard;
+}
+
+} // namespace ppapi
+} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h
new file mode 100644
index 0000000..2088595
--- /dev/null
+++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h
@@ -0,0 +1,21 @@
+// 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.
+
+#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
+#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_
+
+struct PPB_Flash_Clipboard;
+
+namespace webkit {
+namespace ppapi {
+
+class PPB_Flash_Clipboard_Impl {
+ public:
+ static const PPB_Flash_Clipboard* GetInterface();
+};
+
+} // namespace ppapi
+} // namespace webkit
+
+#endif // WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_