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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_handler.h

Issue 12381035: Move Mime type handling to streamsPrivate API, so that it works on Desktop Chrome. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initialize test variable Created 7 years, 9 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 | « no previous file | chrome/browser/chromeos/extensions/file_browser_handler.cc » ('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 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/manifest_handler.h" 14 #include "chrome/common/extensions/manifest_handler.h"
15 #include "extensions/common/url_pattern.h" 15 #include "extensions/common/url_pattern.h"
16 #include "extensions/common/url_pattern_set.h" 16 #include "extensions/common/url_pattern_set.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 18
19 class URLPattern; 19 class URLPattern;
20 20
21 // FileBrowserHandler encapsulates the state of a file browser action. 21 // FileBrowserHandler encapsulates the state of a file browser action.
22 class FileBrowserHandler { 22 class FileBrowserHandler {
23 public: 23 public:
24 typedef std::vector<linked_ptr<FileBrowserHandler> > List; 24 typedef std::vector<linked_ptr<FileBrowserHandler> > List;
25 25
26 // Returns true iff the extension with id |extension_id| is allowed to use
27 // MIME type filters.
28 static bool ExtensionWhitelistedForMIMETypes(const std::string& extension_id);
29
30 // Returns list of extensions' ids that are allowed to use MIME type filters.
31 static std::vector<std::string> GetMIMETypeWhitelist();
32
33 // Whitelists the extension to use MIME type filters for a test.
34 // |extension_id| should be owned by the test code.
35 static void set_extension_whitelisted_for_test(std::string* extension_id) {
36 g_test_extension_id_ = extension_id;
37 }
38
39 FileBrowserHandler(); 26 FileBrowserHandler();
40 ~FileBrowserHandler(); 27 ~FileBrowserHandler();
41 28
42 // extension id 29 // extension id
43 std::string extension_id() const { return extension_id_; } 30 std::string extension_id() const { return extension_id_; }
44 void set_extension_id(const std::string& extension_id) { 31 void set_extension_id(const std::string& extension_id) {
45 extension_id_ = extension_id; 32 extension_id_ = extension_id;
46 } 33 }
47 34
48 // action id 35 // action id
49 const std::string& id() const { return id_; } 36 const std::string& id() const { return id_; }
50 void set_id(const std::string& id) { id_ = id; } 37 void set_id(const std::string& id) { id_ = id; }
51 38
52 // default title 39 // default title
53 const std::string& title() const { return title_; } 40 const std::string& title() const { return title_; }
54 void set_title(const std::string& title) { title_ = title; } 41 void set_title(const std::string& title) { title_ = title; }
55 42
56 // File schema URL patterns. 43 // File schema URL patterns.
57 const extensions::URLPatternSet& file_url_patterns() const { 44 const extensions::URLPatternSet& file_url_patterns() const {
58 return url_set_; 45 return url_set_;
59 } 46 }
60 void AddPattern(const URLPattern& pattern); 47 void AddPattern(const URLPattern& pattern);
61 bool MatchesURL(const GURL& url) const; 48 bool MatchesURL(const GURL& url) const;
62 void ClearPatterns(); 49 void ClearPatterns();
63 50
64 // Adds a MIME type filter to the handler.
65 void AddMIMEType(const std::string& mime_type);
66 // Tests if the handler has registered a filter for the MIME type.
67 bool CanHandleMIMEType(const std::string& mime_type) const;
68
69 // Action icon path. 51 // Action icon path.
70 const std::string icon_path() const { return default_icon_path_; } 52 const std::string icon_path() const { return default_icon_path_; }
71 void set_icon_path(const std::string& path) { 53 void set_icon_path(const std::string& path) {
72 default_icon_path_ = path; 54 default_icon_path_ = path;
73 } 55 }
74 56
75 // File access permissions. 57 // File access permissions.
76 // Adjusts file_access_permission_flags_ to allow specified permission. 58 // Adjusts file_access_permission_flags_ to allow specified permission.
77 bool AddFileAccessPermission(const std::string& permission_str); 59 bool AddFileAccessPermission(const std::string& permission_str);
78 // Checks that specified file access permissions are valid (all set 60 // Checks that specified file access permissions are valid (all set
79 // permissions are valid and there is no other permission specified with 61 // permissions are valid and there is no other permission specified with
80 // "create") 62 // "create")
81 // If no access permissions were set, initialize them to default value. 63 // If no access permissions were set, initialize them to default value.
82 bool ValidateFileAccessPermissions(); 64 bool ValidateFileAccessPermissions();
83 // Checks if handler has read access. 65 // Checks if handler has read access.
84 bool CanRead() const; 66 bool CanRead() const;
85 // Checks if handler has write access. 67 // Checks if handler has write access.
86 bool CanWrite() const; 68 bool CanWrite() const;
87 // Checks if handler has "create" access specified. 69 // Checks if handler has "create" access specified.
88 bool HasCreateAccessPermission() const; 70 bool HasCreateAccessPermission() const;
89 71
90 // Returns the file browser handlers associated with the |extension|. 72 // Returns the file browser handlers associated with the |extension|.
91 static List* GetHandlers(const extensions::Extension* extension); 73 static List* GetHandlers(const extensions::Extension* extension);
92 74
93 private: 75 private:
94 // The id of the extension that will be whitelisted to use MIME type filters
95 // during tests.
96 static std::string* g_test_extension_id_;
97
98 // The id for the extension this action belongs to (as defined in the 76 // The id for the extension this action belongs to (as defined in the
99 // extension manifest). 77 // extension manifest).
100 std::string extension_id_; 78 std::string extension_id_;
101 std::string title_; 79 std::string title_;
102 std::string default_icon_path_; 80 std::string default_icon_path_;
103 // The id for the FileBrowserHandler, for example: "PdfFileAction". 81 // The id for the FileBrowserHandler, for example: "PdfFileAction".
104 std::string id_; 82 std::string id_;
105 unsigned int file_access_permission_flags_; 83 unsigned int file_access_permission_flags_;
106 84
107 // A list of file filters. 85 // A list of file filters.
108 extensions::URLPatternSet url_set_; 86 extensions::URLPatternSet url_set_;
109 // A list of MIME type filters.
110 std::set<std::string> mime_type_set_;
111 }; 87 };
112 88
113 // Parses the "file_browser_handlers" extension manifest key. 89 // Parses the "file_browser_handlers" extension manifest key.
114 class FileBrowserHandlerParser : public extensions::ManifestHandler { 90 class FileBrowserHandlerParser : public extensions::ManifestHandler {
115 public: 91 public:
116 FileBrowserHandlerParser(); 92 FileBrowserHandlerParser();
117 virtual ~FileBrowserHandlerParser(); 93 virtual ~FileBrowserHandlerParser();
118 94
119 virtual bool Parse(extensions::Extension* extension, 95 virtual bool Parse(extensions::Extension* extension,
120 string16* error) OVERRIDE; 96 string16* error) OVERRIDE;
121 97
122 private: 98 private:
123 virtual const std::vector<std::string> Keys() const OVERRIDE; 99 virtual const std::vector<std::string> Keys() const OVERRIDE;
124 }; 100 };
125 101
126 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_ 102 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698