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