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

Side by Side 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, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #include "ppapi/shared_impl/flash_clipboard_format_registry.h"
2
3 #include <cctype>
4
5 namespace ppapi {
6
7 namespace {
8 // These values are chosen arbitrarily. Flash will never exceed these but if
9 // the interface becomes public, we can reconsider these.
10 const size_t kMaxNumFormats = 10;
11 const size_t kMaxFormatNameLength = 50;
12
13 // All formats in PP_Flash_Clipboard_Format should be added here.
14 const PP_Flash_Clipboard_Format kPredefinedFormats[] = {
15 PP_FLASH_CLIPBOARD_FORMAT_INVALID,
16 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
17 PP_FLASH_CLIPBOARD_FORMAT_HTML,
18 PP_FLASH_CLIPBOARD_FORMAT_RTF
19 };
20
21 // The first custom format ID will be the ID after that max value in
22 // PP_Flash_Clipboard_Format.
23 const size_t kFirstCustomFormat =
24 sizeof(kPredefinedFormats) / sizeof(kPredefinedFormats[0]);
dcheng 2012/10/29 20:26:29 You can just use the arraysize macro in base/basic
raymes 2012/10/29 23:30:00 Thanks didn't know about this. Done On 2012/10/2
25
26 // Checks the validity of the given format name.
27 bool IsValidFormatName(const std::string& format_name) {
28 if (format_name.length() == 0 || format_name.length() > kMaxFormatNameLength)
29 return false;
30 return true;
31 }
32
33 } // namespace
34
35 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {
36 custom_formats_.resize(kFirstCustomFormat);
37 }
38
39 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {
40 }
41
42 uint32_t FlashClipboardFormatRegistry::RegisterFormat(
43 const std::string& format_name) {
44 if (!IsValidFormatName(format_name) ||
45 custom_formats_.size() > kMaxNumFormats) {
46 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
47 }
48 custom_formats_.push_back(format_name);
49 return custom_formats_.size() - 1;
50 }
51
52 void FlashClipboardFormatRegistry::SetRegisteredFormat(
53 const std::string& format_name,
54 uint32_t format) {
55 if (format >= custom_formats_.size())
56 custom_formats_.resize(format + 1);
57 custom_formats_[format] = format_name;
58 }
59
60 bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) {
61 return format >= kFirstCustomFormat && format < custom_formats_.size();
62 }
63
64 std::string FlashClipboardFormatRegistry::GetFormatName(uint32_t format) {
65 if (format >= kFirstCustomFormat && format < custom_formats_.size())
66 return custom_formats_[format];
67 return std::string();
68 }
69
70 uint32_t FlashClipboardFormatRegistry::GetFormatID(
71 const std::string& format_name) {
72 for (size_t i = kFirstCustomFormat; i < custom_formats_.size(); ++i) {
73 if (custom_formats_[i] == format_name)
74 return i;
75 }
76 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
77 }
78
79 // static
80 bool FlashClipboardFormatRegistry::IsValidClipboardType(
81 PP_Flash_Clipboard_Type type) {
82 return type == PP_FLASH_CLIPBOARD_TYPE_STANDARD ||
83 type == PP_FLASH_CLIPBOARD_TYPE_SELECTION;
84 }
85
86 // static
87 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) {
88 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID)
89 return false;
90 return format < kFirstCustomFormat;
91 }
92
93 } // ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698