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

Side by Side Diff: chrome/common/extensions/manifest_handler.h

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working on adding ManifestPermissionSet to PermissionSet. Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual const std::vector<std::string> PrerequisiteKeys() const; 57 virtual const std::vector<std::string> PrerequisiteKeys() const;
58 58
59 // Associate us with our keys() in the manifest. A handler can register 59 // Associate us with our keys() in the manifest. A handler can register
60 // for multiple keys. The global registry takes ownership of this; 60 // for multiple keys. The global registry takes ownership of this;
61 // if it has an existing handler for |key|, it replaces it with this. 61 // if it has an existing handler for |key|, it replaces it with this.
62 // Manifest handlers must be registered at process startup in 62 // Manifest handlers must be registered at process startup in
63 // chrome_manifest_handlers.cc: 63 // chrome_manifest_handlers.cc:
64 // (new MyManifestHandler)->Register(); 64 // (new MyManifestHandler)->Register();
65 void Register(); 65 void Register();
66 66
67 virtual void AddPermissionWarningMessages(
68 const Extension* extension,
69 std::vector<string16>& messages) const;
70 virtual void AddPermissionWarningMessagesDetails(
71 const Extension* extension,
72 std::vector<string16>& messages) const;
73
67 // Calling FinalizeRegistration indicates that there are no more 74 // Calling FinalizeRegistration indicates that there are no more
68 // manifest handlers to be registered. 75 // manifest handlers to be registered.
69 static void FinalizeRegistration(); 76 static void FinalizeRegistration();
70 77
71 static bool IsRegistrationFinalized(); 78 static bool IsRegistrationFinalized();
72 79
73 // Call Parse on all registered manifest handlers that should parse 80 // Call Parse on all registered manifest handlers that should parse
74 // this extension. 81 // this extension.
75 static bool ParseExtension(Extension* extension, string16* error); 82 static bool ParseExtension(Extension* extension, string16* error);
76 83
77 // Call Validate on all registered manifest handlers for this extension. 84 // Call Validate on all registered manifest handlers for this extension.
78 static bool ValidateExtension(const Extension* extension, 85 static bool ValidateExtension(const Extension* extension,
79 std::string* error, 86 std::string* error,
80 std::vector<InstallWarning>* warnings); 87 std::vector<InstallWarning>* warnings);
81 88
89 static std::vector<string16> GetExtensionPermissionWarningMessages(
90 const Extension* extension);
91 static std::vector<string16> GetExtensionPermissionWarningMessagesDetails(
92 const Extension* extension);
93
82 protected: 94 protected:
83 // A convenience method for handlers that only register for 1 key, 95 // A convenience method for handlers that only register for 1 key,
84 // so that they can define keys() { return SingleKey(kKey); } 96 // so that they can define keys() { return SingleKey(kKey); }
85 static const std::vector<std::string> SingleKey(const std::string& key); 97 static const std::vector<std::string> SingleKey(const std::string& key);
86 98
87 private: 99 private:
88 // The keys to register us for (in Register). 100 // The keys to register us for (in Register).
89 virtual const std::vector<std::string> Keys() const = 0; 101 virtual const std::vector<std::string> Keys() const = 0;
90 }; 102 };
91 103
92 // The global registry for manifest handlers. 104 // The global registry for manifest handlers.
93 class ManifestHandlerRegistry { 105 class ManifestHandlerRegistry {
94 private: 106 private:
95 friend class ManifestHandler; 107 friend class ManifestHandler;
96 friend class ScopedTestingManifestHandlerRegistry; 108 friend class ScopedTestingManifestHandlerRegistry;
97 friend struct base::DefaultLazyInstanceTraits<ManifestHandlerRegistry>; 109 friend struct base::DefaultLazyInstanceTraits<ManifestHandlerRegistry>;
98 110
99 ManifestHandlerRegistry(); 111 ManifestHandlerRegistry();
100 ~ManifestHandlerRegistry(); 112 ~ManifestHandlerRegistry();
101 113
102 void Finalize(); 114 void Finalize();
103 115
104 void RegisterManifestHandler(const std::string& key, 116 void RegisterManifestHandler(const std::string& key,
105 linked_ptr<ManifestHandler> handler); 117 linked_ptr<ManifestHandler> handler);
106 bool ParseExtension(Extension* extension, string16* error); 118 bool ParseExtension(Extension* extension, string16* error);
107 bool ValidateExtension(const Extension* extension, 119 bool ValidateExtension(const Extension* extension,
108 std::string* error, 120 std::string* error,
109 std::vector<InstallWarning>* warnings); 121 std::vector<InstallWarning>* warnings);
110 122
123 std::vector<string16> GetExtensionPermissionWarningMessages(
124 const Extension* extension);
125 std::vector<string16> GetExtensionPermissionWarningMessagesDetails(
126 const Extension* extension);
127
111 // Overrides the current global ManifestHandlerRegistry with 128 // Overrides the current global ManifestHandlerRegistry with
112 // |registry|, returning the current one. 129 // |registry|, returning the current one.
113 static ManifestHandlerRegistry* SetForTesting( 130 static ManifestHandlerRegistry* SetForTesting(
114 ManifestHandlerRegistry* new_registry); 131 ManifestHandlerRegistry* new_registry);
115 132
116 typedef std::map<std::string, linked_ptr<ManifestHandler> > 133 typedef std::map<std::string, linked_ptr<ManifestHandler> >
117 ManifestHandlerMap; 134 ManifestHandlerMap;
118 typedef std::map<ManifestHandler*, int> ManifestHandlerPriorityMap; 135 typedef std::map<ManifestHandler*, int> ManifestHandlerPriorityMap;
119 136
120 // Puts the manifest handlers in order such that each handler comes after 137 // Puts the manifest handlers in order such that each handler comes after
121 // any handlers for their PrerequisiteKeys. If there is no handler for 138 // any handlers for their PrerequisiteKeys. If there is no handler for
122 // a prerequisite key, that dependency is simply ignored. 139 // a prerequisite key, that dependency is simply ignored.
123 // CHECKs that there are no manifest handlers with circular dependencies. 140 // CHECKs that there are no manifest handlers with circular dependencies.
124 void SortManifestHandlers(); 141 void SortManifestHandlers();
125 142
126 // All registered manifest handlers. 143 // All registered manifest handlers.
127 ManifestHandlerMap handlers_; 144 ManifestHandlerMap handlers_;
128 145
129 // The priority for each manifest handler. Handlers with lower priority 146 // The priority for each manifest handler. Handlers with lower priority
130 // values are evaluated first. 147 // values are evaluated first.
131 ManifestHandlerPriorityMap priority_map_; 148 ManifestHandlerPriorityMap priority_map_;
132 149
133 bool is_finalized_; 150 bool is_finalized_;
134 }; 151 };
135 152
136 } // namespace extensions 153 } // namespace extensions
137 154
138 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 155 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698