• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_
6 #define PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "base/basictypes.h"
12 #include "ppapi/c/private/ppb_flash_clipboard.h"
13 #include "ppapi/shared_impl/ppapi_shared_export.h"
14 
15 namespace ppapi {
16 
17 // This class manages custom clipboard formats that can be registered by a user
18 // of PPB_Flash_Clipboard. It is used by both the plugin and host side
19 // of the proxy. The host side is the definitive source of which formats
20 // have been registered but format registration is tracked on the plugin
21 // side to better handle error cases.
22 class PPAPI_SHARED_EXPORT FlashClipboardFormatRegistry {
23  public:
24   FlashClipboardFormatRegistry();
25   ~FlashClipboardFormatRegistry();
26 
27   // Registers a custom format with the given string. The ID of the format is
28   // returned if registered successfully, otherwise
29   // PP_FLASH_CLIPBOARD_FORMAT_INVALID is returned. If a format with a
30   // particular name is already registered, the ID associated with that name
31   // will be returned. The format name is checked for validity.
32   uint32_t RegisterFormat(const std::string& format_name);
33 
34   // This sets the name of a particular format in the registry. This is only
35   // used on the plugin side in order to track format IDs that are returned
36   // by the host.
37   void SetRegisteredFormat(const std::string& format_name, uint32_t format);
38 
39   // Checks whether the given custom format ID has been registered.
40   bool IsFormatRegistered(uint32_t format) const;
41 
42   // Returns the name of a particular format.
43   std::string GetFormatName(uint32_t format) const;
44 
45   // Gets the ID of a particular format name that has already been registered.
46   // PP_FLASH_CLIPBOARD_FORMAT_INVALID is returned if the format has not been
47   // registered.
48   uint32_t GetFormatID(const std::string& format_name) const;
49 
50   // Returns whether the given clipboard format is a valid predefined format
51   // (i.e. one defined in the PP_Flash_Clipboard_Format enum).
52   static bool IsValidPredefinedFormat(uint32_t format);
53 
54  private:
55   // A map of custom format ID to format name.
56   typedef std::map<uint32_t, std::string> FormatMap;
57   FormatMap custom_formats_;
58 
59   DISALLOW_COPY_AND_ASSIGN(FlashClipboardFormatRegistry);
60 };
61 
62 }  // ppapi
63 
64 #endif  // PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_
65