Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / mime_types_handler.h
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 CHROME_COMMON_EXTENSIONS_MIME_TYPES_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_MIME_TYPES_HANDLER_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/manifest_handler.h"
15
16 class MimeTypesHandler {
17  public:
18   // Returns list of extensions' ids that are allowed to use MIME type filters.
19   static std::vector<std::string> GetMIMETypeWhitelist();
20
21   static MimeTypesHandler* GetHandler(const extensions::Extension* extension);
22
23   MimeTypesHandler();
24   ~MimeTypesHandler();
25
26   // extension id
27   std::string extension_id() const { return extension_id_; }
28   void set_extension_id(const std::string& extension_id) {
29     extension_id_ = extension_id;
30   }
31
32   // Adds a MIME type filter to the handler.
33   void AddMIMEType(const std::string& mime_type);
34   // Tests if the handler has registered a filter for the MIME type.
35   bool CanHandleMIMEType(const std::string& mime_type) const;
36
37  private:
38   // The id for the extension this action belongs to (as defined in the
39   // extension manifest).
40   std::string extension_id_;
41
42   // A list of MIME type filters.
43   std::set<std::string> mime_type_set_;
44 };
45
46 class MimeTypesHandlerParser : public extensions::ManifestHandler {
47  public:
48   MimeTypesHandlerParser();
49   virtual ~MimeTypesHandlerParser();
50
51   virtual bool Parse(extensions::Extension* extension,
52                      base::string16* error) OVERRIDE;
53
54  private:
55   virtual const std::vector<std::string> Keys() const OVERRIDE;
56 };
57
58 #endif  // CHROME_COMMON_EXTENSIONS_MIME_TYPES_HANDLER_H_
59