summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 01:24:54 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-14 01:24:54 +0000
commitcf0f7d9ed9f6dd06c3cdb5c3880d79d727d6356f (patch)
tree657ddb9bb042fedad91490a4e15230255092eeff /ppapi
parent7c46a708d26568178c1922edb22f8810473541f9 (diff)
downloadchromium_src-cf0f7d9ed9f6dd06c3cdb5c3880d79d727d6356f.zip
chromium_src-cf0f7d9ed9f6dd06c3cdb5c3880d79d727d6356f.tar.gz
chromium_src-cf0f7d9ed9f6dd06c3cdb5c3880d79d727d6356f.tar.bz2
Pepper/Flapper: Add C++ wrappers for PPB_Flash_Clipboard.
This makes the interface a bit easier to use and, more importantly, easier to update the interface while maintaining suitable compatibility. Review URL: http://codereview.chromium.org/9207012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/cpp/private/flash_clipboard.cc75
-rw-r--r--ppapi/cpp/private/flash_clipboard.h43
-rw-r--r--ppapi/ppapi_sources.gypi2
3 files changed, 120 insertions, 0 deletions
diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc
new file mode 100644
index 0000000..8634eaf
--- /dev/null
+++ b/ppapi/cpp/private/flash_clipboard.cc
@@ -0,0 +1,75 @@
+// Copyright (c) 2012 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/cpp/private/flash_clipboard.h"
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module_impl.h"
+#include "ppapi/cpp/var.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_Flash_Clipboard>() {
+ return PPB_FLASH_CLIPBOARD_INTERFACE;
+}
+
+} // namespace
+
+namespace flash {
+
+// static
+bool Clipboard::IsAvailable() {
+ return has_interface<PPB_Flash_Clipboard>();
+}
+
+// static
+bool Clipboard::IsFormatAvailable(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) {
+ bool rv = false;
+ if (has_interface<PPB_Flash_Clipboard>()) {
+ rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable(
+ instance->pp_instance(), clipboard_type, format));
+ }
+ return rv;
+}
+
+// static
+bool Clipboard::ReadPlainText(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ std::string* text_out) {
+ bool rv = false;
+ if (has_interface<PPB_Flash_Clipboard>()) {
+ Var v(Var::PassRef(),
+ get_interface<PPB_Flash_Clipboard>()->ReadPlainText(
+ instance->pp_instance(),
+ clipboard_type));
+ if (v.is_string()) {
+ rv = true;
+ *text_out = v.AsString();
+ }
+ }
+ return rv;
+}
+
+// static
+bool Clipboard::WritePlainText(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ const std::string& text) {
+ bool rv = false;
+ if (has_interface<PPB_Flash_Clipboard>()) {
+ rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText(
+ instance->pp_instance(),
+ clipboard_type,
+ Var(text).pp_var()) == PP_OK);
+ }
+ return rv;
+}
+
+} // namespace flash
+} // namespace pp
diff --git a/ppapi/cpp/private/flash_clipboard.h b/ppapi/cpp/private/flash_clipboard.h
new file mode 100644
index 0000000..db13ce6
--- /dev/null
+++ b/ppapi/cpp/private/flash_clipboard.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 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_CPP_PRIVATE_FLASH_CLIPBOARD_H_
+#define PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_
+
+#include <string>
+
+#include "ppapi/c/private/ppb_flash_clipboard.h"
+
+namespace pp {
+
+class Instance;
+
+namespace flash {
+
+class Clipboard {
+ public:
+ // Returns true if the required interface is available.
+ static bool IsAvailable();
+
+ // Returns true if the given format is available from the given clipboard.
+ static bool IsFormatAvailable(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format);
+
+ // Returns true on success, in which case |text_out| will be filled with plain
+ // text read from the given clipboard.
+ static bool ReadPlainText(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ std::string* text_out);
+
+ // Returns true on success (it may fail if |text| is too big).
+ static bool WritePlainText(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ const std::string& text);
+};
+
+} // namespace flash
+} // namespace pp
+
+#endif // PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_
diff --git a/ppapi/ppapi_sources.gypi b/ppapi/ppapi_sources.gypi
index a2c6884..a027a02 100644
--- a/ppapi/ppapi_sources.gypi
+++ b/ppapi/ppapi_sources.gypi
@@ -229,6 +229,8 @@
# Private interfaces.
'cpp/private/flash.cc',
'cpp/private/flash.h',
+ 'cpp/private/flash_clipboard.cc',
+ 'cpp/private/flash_clipboard.h',
'cpp/private/flash_fullscreen.cc',
'cpp/private/flash_fullscreen.h',
'cpp/private/flash_menu.cc',