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

Unified Diff: ppapi/shared_impl/flash_clipboard_format_registry.cc

Issue 11225021: Move flash clipboard to the new proxy and add custom format support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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
Index: ppapi/shared_impl/flash_clipboard_format_registry.cc
diff --git a/ppapi/shared_impl/flash_clipboard_format_registry.cc b/ppapi/shared_impl/flash_clipboard_format_registry.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1279c6f1813341b298c3b850b30b1b4e3c2663b1
--- /dev/null
+++ b/ppapi/shared_impl/flash_clipboard_format_registry.cc
@@ -0,0 +1,92 @@
+#include "ppapi/shared_impl/flash_clipboard_format_registry.h"
+
+#include <cctype>
+
+namespace ppapi {
+
+namespace {
+// These values are chosen arbitrarily. Flash will never exceed these but if
+// the interface becomes public, we can reconsider these.
+const size_t kMaxNumFormats = 10;
+const size_t kMaxFormatNameLength = 50;
+
+// All formats in PP_Flash_Clipboard_Format should be added here.
+const PP_Flash_Clipboard_Format kPredefinedFormats[] = {
+ PP_FLASH_CLIPBOARD_FORMAT_INVALID,
+ PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
+ PP_FLASH_CLIPBOARD_FORMAT_HTML,
+ PP_FLASH_CLIPBOARD_FORMAT_RTF
+};
+
+// The first custom format ID will be the ID after that max value in
+// PP_Flash_Clipboard_Format.
+const size_t kFirstCustomFormat = arraysize(kPredefinedFormats);
+
+// Checks the validity of the given format name.
+bool IsValidFormatName(const std::string& format_name) {
+ if (format_name.length() == 0 || format_name.length() > kMaxFormatNameLength)
dcheng 2012/10/30 00:52:33 Nit: it's slightly more canonical to say format_na
raymes 2012/10/30 01:57:16 Done.
+ return false;
+ return true;
+}
+
+} // namespace
+
+FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {
+ custom_formats_.resize(kFirstCustomFormat);
+}
+
+FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {
+}
+
+uint32_t FlashClipboardFormatRegistry::RegisterFormat(
+ const std::string& format_name) {
+ if (!IsValidFormatName(format_name) ||
+ custom_formats_.size() > kMaxNumFormats) {
+ return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
+ }
+ custom_formats_.push_back(format_name);
+ return custom_formats_.size() - 1;
+}
+
+void FlashClipboardFormatRegistry::SetRegisteredFormat(
+ const std::string& format_name,
+ uint32_t format) {
+ if (format >= custom_formats_.size())
+ custom_formats_.resize(format + 1);
+ custom_formats_[format] = format_name;
+}
+
+bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) {
+ return format >= kFirstCustomFormat && format < custom_formats_.size();
+}
+
+std::string FlashClipboardFormatRegistry::GetFormatName(uint32_t format) {
+ if (format >= kFirstCustomFormat && format < custom_formats_.size())
+ return custom_formats_[format];
+ return std::string();
+}
+
+uint32_t FlashClipboardFormatRegistry::GetFormatID(
+ const std::string& format_name) {
+ for (size_t i = kFirstCustomFormat; i < custom_formats_.size(); ++i) {
dcheng 2012/10/30 00:52:33 Nit: this should be indented two spaces.
raymes 2012/10/30 01:57:16 Done.
+ if (custom_formats_[i] == format_name)
+ return i;
+ }
+ return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
+}
+
+// static
+bool FlashClipboardFormatRegistry::IsValidClipboardType(
dcheng 2012/10/30 00:52:33 This validation function feels out of place. It ha
raymes 2012/10/30 01:57:16 Yes, it is slightly out of place. It's actually on
+ PP_Flash_Clipboard_Type type) {
+ return type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
+ type == PP_FLASH_CLIPBOARD_TYPE_SELECTION;
+}
+
+// static
+bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) {
+ if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID)
+ return false;
+ return format < kFirstCustomFormat;
+}
+
+} // ppapi

Powered by Google App Engine
This is Rietveld 408576698