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

Unified Diff: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc

Issue 6611034: Pepper/Flapper: Add very basic clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minus string.h Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc
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 0000000000000000000000000000000000000000..630a897a0db581bb7e275fcce6ee5e9a20e62b12
--- /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
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_clipboard_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698