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

Side by Side Diff: ppapi/shared_impl/flash_clipboard_format_registry.cc

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 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 unified diff | Download patch
« no previous file with comments | « ppapi/shared_impl/flash_clipboard_format_registry.h ('k') | ppapi/shared_impl/host_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/flash_clipboard_format_registry.h" 5 #include "ppapi/shared_impl/flash_clipboard_format_registry.h"
6 6
7 #include <cctype> 7 #include <cctype>
8 8
9 namespace ppapi { 9 namespace ppapi {
10 10
11 namespace { 11 namespace {
12 12
13 // These values are chosen arbitrarily. Flash will never exceed these but if 13 // These values are chosen arbitrarily. Flash will never exceed these but if
14 // the interface becomes public, we can reconsider these. 14 // the interface becomes public, we can reconsider these.
15 const size_t kMaxNumFormats = 10; 15 const size_t kMaxNumFormats = 10;
16 const size_t kMaxFormatNameLength = 50; 16 const size_t kMaxFormatNameLength = 50;
17 17
18 // All formats in PP_Flash_Clipboard_Format should be added here. 18 // All formats in PP_Flash_Clipboard_Format should be added here.
19 const PP_Flash_Clipboard_Format kPredefinedFormats[] = { 19 const PP_Flash_Clipboard_Format kPredefinedFormats[] = {
20 PP_FLASH_CLIPBOARD_FORMAT_INVALID, 20 PP_FLASH_CLIPBOARD_FORMAT_INVALID, PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
21 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, 21 PP_FLASH_CLIPBOARD_FORMAT_HTML, PP_FLASH_CLIPBOARD_FORMAT_RTF};
22 PP_FLASH_CLIPBOARD_FORMAT_HTML,
23 PP_FLASH_CLIPBOARD_FORMAT_RTF
24 };
25 22
26 // The first custom format ID will be the ID after that max value in 23 // The first custom format ID will be the ID after that max value in
27 // PP_Flash_Clipboard_Format. 24 // PP_Flash_Clipboard_Format.
28 const size_t kFirstCustomFormat = arraysize(kPredefinedFormats); 25 const size_t kFirstCustomFormat = arraysize(kPredefinedFormats);
29 26
30 // Checks the validity of the given format name. 27 // Checks the validity of the given format name.
31 bool IsValidFormatName(const std::string& format_name) { 28 bool IsValidFormatName(const std::string& format_name) {
32 if (format_name.empty() || format_name.length() > kMaxFormatNameLength) 29 if (format_name.empty() || format_name.length() > kMaxFormatNameLength)
33 return false; 30 return false;
34 return true; 31 return true;
35 } 32 }
36 33
37 } // namespace 34 } // namespace
38 35
39 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() { 36 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {}
40 }
41 37
42 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() { 38 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {}
43 }
44 39
45 uint32_t FlashClipboardFormatRegistry::RegisterFormat( 40 uint32_t FlashClipboardFormatRegistry::RegisterFormat(
46 const std::string& format_name) { 41 const std::string& format_name) {
47 if (!IsValidFormatName(format_name) || 42 if (!IsValidFormatName(format_name) ||
48 custom_formats_.size() > kMaxNumFormats) { 43 custom_formats_.size() > kMaxNumFormats) {
49 return PP_FLASH_CLIPBOARD_FORMAT_INVALID; 44 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
50 } 45 }
51 uint32_t key = kFirstCustomFormat + custom_formats_.size(); 46 uint32_t key = kFirstCustomFormat + custom_formats_.size();
52 custom_formats_[key] = format_name; 47 custom_formats_[key] = format_name;
53 return key; 48 return key;
54 } 49 }
55 50
56 void FlashClipboardFormatRegistry::SetRegisteredFormat( 51 void FlashClipboardFormatRegistry::SetRegisteredFormat(
57 const std::string& format_name, 52 const std::string& format_name,
58 uint32_t format) { 53 uint32_t format) {
59 custom_formats_[format] = format_name; 54 custom_formats_[format] = format_name;
60 } 55 }
61 56
62 bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) const { 57 bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) const {
63 return custom_formats_.find(format) != custom_formats_.end(); 58 return custom_formats_.find(format) != custom_formats_.end();
64 } 59 }
65 60
66 std::string FlashClipboardFormatRegistry::GetFormatName( 61 std::string FlashClipboardFormatRegistry::GetFormatName(uint32_t format) const {
67 uint32_t format) const {
68 FormatMap::const_iterator it = custom_formats_.find(format); 62 FormatMap::const_iterator it = custom_formats_.find(format);
69 if (it == custom_formats_.end()) 63 if (it == custom_formats_.end())
70 return std::string(); 64 return std::string();
71 return it->second; 65 return it->second;
72 } 66 }
73 67
74 uint32_t FlashClipboardFormatRegistry::GetFormatID( 68 uint32_t FlashClipboardFormatRegistry::GetFormatID(
75 const std::string& format_name) const { 69 const std::string& format_name) const {
76 for (FormatMap::const_iterator it = custom_formats_.begin(); 70 for (FormatMap::const_iterator it = custom_formats_.begin();
77 it != custom_formats_.end(); ++it) { 71 it != custom_formats_.end();
72 ++it) {
78 if (it->second == format_name) 73 if (it->second == format_name)
79 return it->first; 74 return it->first;
80 } 75 }
81 return PP_FLASH_CLIPBOARD_FORMAT_INVALID; 76 return PP_FLASH_CLIPBOARD_FORMAT_INVALID;
82 } 77 }
83 78
84 // static 79 // static
85 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) { 80 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) {
86 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) 81 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID)
87 return false; 82 return false;
88 return format < kFirstCustomFormat; 83 return format < kFirstCustomFormat;
89 } 84 }
90 85
91 } // namespace ppapi 86 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/flash_clipboard_format_registry.h ('k') | ppapi/shared_impl/host_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698