OLD | NEW |
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 #include "chrome/common/extensions/manifest_handler.h" | 5 #include "chrome/common/extensions/manifest_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 return std::vector<std::string>(); | 50 return std::vector<std::string>(); |
51 } | 51 } |
52 | 52 |
53 void ManifestHandler::Register() { | 53 void ManifestHandler::Register() { |
54 linked_ptr<ManifestHandler> this_linked(this); | 54 linked_ptr<ManifestHandler> this_linked(this); |
55 const std::vector<std::string> keys = Keys(); | 55 const std::vector<std::string> keys = Keys(); |
56 for (size_t i = 0; i < keys.size(); ++i) | 56 for (size_t i = 0; i < keys.size(); ++i) |
57 GetRegistry()->RegisterManifestHandler(keys[i], this_linked); | 57 GetRegistry()->RegisterManifestHandler(keys[i], this_linked); |
58 } | 58 } |
59 | 59 |
| 60 void ManifestHandler::AddPermissionWarningMessages( |
| 61 const Extension* extension, |
| 62 std::vector<string16>& messages) const { |
| 63 // Nothing by default |
| 64 } |
| 65 |
| 66 void ManifestHandler::AddPermissionWarningMessagesDetails( |
| 67 const Extension* extension, |
| 68 std::vector<string16>& messages) const { |
| 69 // Nothing by default |
| 70 } |
| 71 |
60 // static | 72 // static |
61 void ManifestHandler::FinalizeRegistration() { | 73 void ManifestHandler::FinalizeRegistration() { |
62 GetRegistry()->Finalize(); | 74 GetRegistry()->Finalize(); |
63 } | 75 } |
64 | 76 |
65 // static | 77 // static |
66 bool ManifestHandler::IsRegistrationFinalized() { | 78 bool ManifestHandler::IsRegistrationFinalized() { |
67 return GetRegistry()->is_finalized_; | 79 return GetRegistry()->is_finalized_; |
68 } | 80 } |
69 | 81 |
70 // static | 82 // static |
71 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { | 83 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { |
72 return GetRegistry()->ParseExtension(extension, error); | 84 return GetRegistry()->ParseExtension(extension, error); |
73 } | 85 } |
74 | 86 |
75 // static | 87 // static |
76 bool ManifestHandler::ValidateExtension(const Extension* extension, | 88 bool ManifestHandler::ValidateExtension(const Extension* extension, |
77 std::string* error, | 89 std::string* error, |
78 std::vector<InstallWarning>* warnings) { | 90 std::vector<InstallWarning>* warnings) { |
79 return GetRegistry()->ValidateExtension(extension, error, warnings); | 91 return GetRegistry()->ValidateExtension(extension, error, warnings); |
80 } | 92 } |
81 | 93 |
82 // static | 94 // static |
| 95 std::vector<string16> ManifestHandler:: |
| 96 GetExtensionPermissionWarningMessages(const Extension* extension) { |
| 97 return GetRegistry()->GetExtensionPermissionWarningMessages(extension); |
| 98 } |
| 99 |
| 100 // static |
| 101 std::vector<string16> ManifestHandler:: |
| 102 GetExtensionPermissionWarningMessagesDetails(const Extension* extension) { |
| 103 return GetRegistry()->GetExtensionPermissionWarningMessagesDetails(extension); |
| 104 } |
| 105 |
| 106 // static |
83 const std::vector<std::string> ManifestHandler::SingleKey( | 107 const std::vector<std::string> ManifestHandler::SingleKey( |
84 const std::string& key) { | 108 const std::string& key) { |
85 return std::vector<std::string>(1, key); | 109 return std::vector<std::string>(1, key); |
86 } | 110 } |
87 | 111 |
88 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) { | 112 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) { |
89 } | 113 } |
90 | 114 |
91 ManifestHandlerRegistry::~ManifestHandlerRegistry() { | 115 ManifestHandlerRegistry::~ManifestHandlerRegistry() { |
92 } | 116 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 161 } |
138 } | 162 } |
139 for (std::set<ManifestHandler*>::iterator iter = handlers.begin(); | 163 for (std::set<ManifestHandler*>::iterator iter = handlers.begin(); |
140 iter != handlers.end(); ++iter) { | 164 iter != handlers.end(); ++iter) { |
141 if (!(*iter)->Validate(extension, error, warnings)) | 165 if (!(*iter)->Validate(extension, error, warnings)) |
142 return false; | 166 return false; |
143 } | 167 } |
144 return true; | 168 return true; |
145 } | 169 } |
146 | 170 |
| 171 std::vector<string16> ManifestHandlerRegistry:: |
| 172 GetExtensionPermissionWarningMessages(const Extension* extension) { |
| 173 std::vector<string16> result; |
| 174 for (ManifestHandlerMap::iterator iter = handlers_.begin(); |
| 175 iter != handlers_.end(); ++iter) { |
| 176 ManifestHandler* handler = iter->second.get(); |
| 177 handler->AddPermissionWarningMessages(extension, result); |
| 178 } |
| 179 return result; |
| 180 } |
| 181 |
| 182 std::vector<string16> ManifestHandlerRegistry:: |
| 183 GetExtensionPermissionWarningMessagesDetails(const Extension* extension) { |
| 184 std::vector<string16> result; |
| 185 for (ManifestHandlerMap::iterator iter = handlers_.begin(); |
| 186 iter != handlers_.end(); ++iter) { |
| 187 ManifestHandler* handler = iter->second.get(); |
| 188 handler->AddPermissionWarningMessagesDetails(extension, result); |
| 189 } |
| 190 return result; |
| 191 } |
| 192 |
147 // static | 193 // static |
148 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting( | 194 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting( |
149 ManifestHandlerRegistry* new_registry) { | 195 ManifestHandlerRegistry* new_registry) { |
150 ManifestHandlerRegistry* old_registry = GetRegistry(); | 196 ManifestHandlerRegistry* old_registry = GetRegistry(); |
151 if (new_registry != g_registry.Pointer()) | 197 if (new_registry != g_registry.Pointer()) |
152 g_registry_override = new_registry; | 198 g_registry_override = new_registry; |
153 else | 199 else |
154 g_registry_override = NULL; | 200 g_registry_override = NULL; |
155 return old_registry; | 201 return old_registry; |
156 } | 202 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 unsorted_handlers.swap(next_unsorted_handlers); | 242 unsorted_handlers.swap(next_unsorted_handlers); |
197 } | 243 } |
198 | 244 |
199 // If there are any leftover unsorted handlers, they must have had | 245 // If there are any leftover unsorted handlers, they must have had |
200 // circular dependencies. | 246 // circular dependencies. |
201 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " | 247 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " |
202 << "circular dependencies!"; | 248 << "circular dependencies!"; |
203 } | 249 } |
204 | 250 |
205 } // namespace extensions | 251 } // namespace extensions |
OLD | NEW |