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

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 = arraysize(kPredefinedFormats);
24
25 // Checks the validity of the given format name.
26 bool IsValidFormatName(const std::string& format_name) {
27 if (format_name.empty() || format_name.length() > kMaxFormatNameLength)
28 return false;
29 return true;
30 }
31
32 } // namespace
33
34 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {
35 }
36
37 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {
38 }
39
40 uint32_t FlashClipboardFormatRegistry::RegisterFormat(
41 const std::string& format_name) {
42 if (!IsValidFormatName(format_name) ||
43 custom_formats_.size() > kMaxNumFormats) {
44 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
45 }
46 uint32_t key = kFirstCustomFormat + custom_formats_.size();
47 custom_formats_[key] = format_name;
48 return key;
49 }
50
51 void FlashClipboardFormatRegistry::SetRegisteredFormat(
52 const std::string& format_name,
53 uint32_t format) {
54 custom_formats_[format] = format_name;
55 }
56
57 bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) {
dcheng 2012/10/30 02:21:14 const
raymes 2012/10/30 02:53:03 Done.
58 return custom_formats_.count(format) == 1;
dcheng 2012/10/30 02:21:14 custom_formats_.find(format) != custom_formats.end
raymes 2012/10/30 02:53:03 Done.
59 }
60
61 std::string FlashClipboardFormatRegistry::GetFormatName(uint32_t format) {
dcheng 2012/10/30 02:21:14 const
raymes 2012/10/30 02:53:03 Done.
62 FormatMap::iterator it = custom_formats_.find(format);
dcheng 2012/10/30 02:21:14 const_iterator
raymes 2012/10/30 02:53:03 Done.
63 if (it == custom_formats_.end())
64 return std::string();
65 return it->second;
66 }
67
68 uint32_t FlashClipboardFormatRegistry::GetFormatID(
69 const std::string& format_name) {
dcheng 2012/10/30 02:21:14 This method can be const.
raymes 2012/10/30 02:53:03 Done.
70 for (FormatMap::iterator it = custom_formats_.begin();
dcheng 2012/10/30 02:21:14 const_iterator
raymes 2012/10/30 02:53:03 Done.
71 it != custom_formats_.end(); ++it) {
72 if (it->second == format_name)
73 return it->first;
74 }
75 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
76 }
77
78 // static
79 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) {
80 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID)
81 return false;
82 return format < kFirstCustomFormat;
83 }
84
85 } // ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/flash_clipboard_format_registry.h ('k') | ppapi/shared_impl/ppb_flash_shared.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698