OLD | NEW |
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 #include "base/numerics/safe_conversions.h" |
| 10 |
9 namespace ppapi { | 11 namespace ppapi { |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 // These values are chosen arbitrarily. Flash will never exceed these but if | 15 // These values are chosen arbitrarily. Flash will never exceed these but if |
14 // the interface becomes public, we can reconsider these. | 16 // the interface becomes public, we can reconsider these. |
15 const size_t kMaxNumFormats = 10; | 17 const size_t kMaxNumFormats = 10; |
16 const size_t kMaxFormatNameLength = 50; | 18 const size_t kMaxFormatNameLength = 50; |
17 | 19 |
18 // All formats in PP_Flash_Clipboard_Format should be added here. | 20 // All formats in PP_Flash_Clipboard_Format should be added here. |
(...skipping 17 matching lines...) Expand all Loading... |
36 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {} | 38 FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() {} |
37 | 39 |
38 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {} | 40 FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() {} |
39 | 41 |
40 uint32_t FlashClipboardFormatRegistry::RegisterFormat( | 42 uint32_t FlashClipboardFormatRegistry::RegisterFormat( |
41 const std::string& format_name) { | 43 const std::string& format_name) { |
42 if (!IsValidFormatName(format_name) || | 44 if (!IsValidFormatName(format_name) || |
43 custom_formats_.size() > kMaxNumFormats) { | 45 custom_formats_.size() > kMaxNumFormats) { |
44 return PP_FLASH_CLIPBOARD_FORMAT_INVALID; | 46 return PP_FLASH_CLIPBOARD_FORMAT_INVALID; |
45 } | 47 } |
46 uint32_t key = kFirstCustomFormat + custom_formats_.size(); | 48 uint32_t key = kFirstCustomFormat + |
| 49 base::checked_cast<uint32_t>(custom_formats_.size()); |
47 custom_formats_[key] = format_name; | 50 custom_formats_[key] = format_name; |
48 return key; | 51 return key; |
49 } | 52 } |
50 | 53 |
51 void FlashClipboardFormatRegistry::SetRegisteredFormat( | 54 void FlashClipboardFormatRegistry::SetRegisteredFormat( |
52 const std::string& format_name, | 55 const std::string& format_name, |
53 uint32_t format) { | 56 uint32_t format) { |
54 custom_formats_[format] = format_name; | 57 custom_formats_[format] = format_name; |
55 } | 58 } |
56 | 59 |
(...skipping 20 matching lines...) Expand all Loading... |
77 } | 80 } |
78 | 81 |
79 // static | 82 // static |
80 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) { | 83 bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) { |
81 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) | 84 if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) |
82 return false; | 85 return false; |
83 return format < kFirstCustomFormat; | 86 return format < kFirstCustomFormat; |
84 } | 87 } |
85 | 88 |
86 } // namespace ppapi | 89 } // namespace ppapi |
OLD | NEW |