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

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 12093036: Move Extension Location and Type enums to Manifest, and move InstallWarning to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 #include "chrome/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/api/extension_action/action_info.h" 22 #include "chrome/common/extensions/api/extension_action/action_info.h"
23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " 23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h "
24 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_l10n_util.h" 25 #include "chrome/common/extensions/extension_l10n_util.h"
26 #include "chrome/common/extensions/extension_manifest_constants.h" 26 #include "chrome/common/extensions/extension_manifest_constants.h"
27 #include "chrome/common/extensions/extension_messages.h" 27 #include "chrome/common/extensions/extension_messages.h"
28 #include "chrome/common/extensions/extension_resource.h" 28 #include "chrome/common/extensions/extension_resource.h"
29 #include "chrome/common/extensions/manifest.h"
29 #include "chrome/common/extensions/manifest_url_handler.h" 30 #include "chrome/common/extensions/manifest_url_handler.h"
30 #include "chrome/common/extensions/message_bundle.h" 31 #include "chrome/common/extensions/message_bundle.h"
31 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
32 #include "net/base/escape.h" 33 #include "net/base/escape.h"
33 #include "net/base/file_stream.h" 34 #include "net/base/file_stream.h"
34 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
35 36
36 using extensions::Extension; 37 using extensions::Extension;
38 using extensions::Manifest;
37 39
38 namespace errors = extension_manifest_errors; 40 namespace errors = extension_manifest_errors;
39 41
40 namespace { 42 namespace {
41 43
42 const FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); 44 const FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");
43 45
44 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set, 46 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set,
45 const Extension* extension, 47 const Extension* extension,
46 int error_message_id, 48 int error_message_id,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 131
130 void UninstallExtension(const FilePath& extensions_dir, 132 void UninstallExtension(const FilePath& extensions_dir,
131 const std::string& id) { 133 const std::string& id) {
132 // We don't care about the return value. If this fails (and it can, due to 134 // We don't care about the return value. If this fails (and it can, due to
133 // plugins that aren't unloaded yet, it will get cleaned up by 135 // plugins that aren't unloaded yet, it will get cleaned up by
134 // ExtensionService::GarbageCollectExtensions). 136 // ExtensionService::GarbageCollectExtensions).
135 file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive. 137 file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive.
136 } 138 }
137 139
138 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path, 140 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path,
139 Extension::Location location, 141 Manifest::Location location,
140 int flags, 142 int flags,
141 std::string* error) { 143 std::string* error) {
142 return LoadExtension(extension_path, std::string(), location, flags, error); 144 return LoadExtension(extension_path, std::string(), location, flags, error);
143 } 145 }
144 146
145 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path, 147 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path,
146 const std::string& extension_id, 148 const std::string& extension_id,
147 Extension::Location location, 149 Manifest::Location location,
148 int flags, 150 int flags,
149 std::string* error) { 151 std::string* error) {
150 scoped_ptr<DictionaryValue> manifest(LoadManifest(extension_path, error)); 152 scoped_ptr<DictionaryValue> manifest(LoadManifest(extension_path, error));
151 if (!manifest.get()) 153 if (!manifest.get())
152 return NULL; 154 return NULL;
153 if (!extension_l10n_util::LocalizeExtension(extension_path, manifest.get(), 155 if (!extension_l10n_util::LocalizeExtension(extension_path, manifest.get(),
154 error)) { 156 error)) {
155 return NULL; 157 return NULL;
156 } 158 }
157 159
158 scoped_refptr<Extension> extension(Extension::Create(extension_path, 160 scoped_refptr<Extension> extension(Extension::Create(extension_path,
159 location, 161 location,
160 *manifest, 162 *manifest,
161 flags, 163 flags,
162 extension_id, 164 extension_id,
163 error)); 165 error));
164 if (!extension.get()) 166 if (!extension.get())
165 return NULL; 167 return NULL;
166 168
167 Extension::InstallWarningVector warnings; 169 extensions::InstallWarning::Vector warnings;
168 if (!ValidateExtension(extension.get(), error, &warnings)) 170 if (!ValidateExtension(extension.get(), error, &warnings))
169 return NULL; 171 return NULL;
170 extension->AddInstallWarnings(warnings); 172 extension->AddInstallWarnings(warnings);
171 173
172 return extension; 174 return extension;
173 } 175 }
174 176
175 DictionaryValue* LoadManifest(const FilePath& extension_path, 177 DictionaryValue* LoadManifest(const FilePath& extension_path,
176 std::string* error) { 178 std::string* error) {
177 FilePath manifest_path = 179 FilePath manifest_path =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 !file_util::GetFileSize(path, &size) || 240 !file_util::GetFileSize(path, &size) ||
239 size == 0) { 241 size == 0) {
240 return false; 242 return false;
241 } 243 }
242 244
243 return true; 245 return true;
244 } 246 }
245 247
246 bool ValidateExtension(const Extension* extension, 248 bool ValidateExtension(const Extension* extension,
247 std::string* error, 249 std::string* error,
248 Extension::InstallWarningVector* warnings) { 250 extensions::InstallWarning::Vector* warnings) {
249 // Validate icons exist. 251 // Validate icons exist.
250 for (ExtensionIconSet::IconMap::const_iterator iter = 252 for (ExtensionIconSet::IconMap::const_iterator iter =
251 extension->icons().map().begin(); 253 extension->icons().map().begin();
252 iter != extension->icons().map().end(); 254 iter != extension->icons().map().end();
253 ++iter) { 255 ++iter) {
254 const FilePath path = extension->GetResource(iter->second).GetFilePath(); 256 const FilePath path = extension->GetResource(iter->second).GetFilePath();
255 if (!ValidateFilePath(path)) { 257 if (!ValidateFilePath(path)) {
256 *error = 258 *error =
257 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED, 259 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED,
258 UTF8ToUTF16(iter->second)); 260 UTF8ToUTF16(iter->second));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (!private_keys.empty()) { 408 if (!private_keys.empty()) {
407 // Only print one of the private keys because l10n_util doesn't have a way 409 // Only print one of the private keys because l10n_util doesn't have a way
408 // to translate a list of strings. 410 // to translate a list of strings.
409 *error = l10n_util::GetStringFUTF8( 411 *error = l10n_util::GetStringFUTF8(
410 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, 412 IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
411 private_keys.front().LossyDisplayName()); 413 private_keys.front().LossyDisplayName());
412 return false; 414 return false;
413 } 415 }
414 } else { 416 } else {
415 for (size_t i = 0; i < private_keys.size(); ++i) { 417 for (size_t i = 0; i < private_keys.size(); ++i) {
416 warnings->push_back(Extension::InstallWarning( 418 warnings->push_back(extensions::InstallWarning(
417 Extension::InstallWarning::FORMAT_TEXT, 419 extensions::InstallWarning::FORMAT_TEXT,
418 l10n_util::GetStringFUTF8( 420 l10n_util::GetStringFUTF8(
419 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, 421 IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
420 private_keys[i].LossyDisplayName()))); 422 private_keys[i].LossyDisplayName())));
421 } 423 }
422 // Only warn; don't block loading the extension. 424 // Only warn; don't block loading the extension.
423 } 425 }
424 return true; 426 return true;
425 } 427 }
426 428
427 void GarbageCollectExtensions( 429 void GarbageCollectExtensions(
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return FilePath(); 759 return FilePath();
758 } 760 }
759 return temp_path; 761 return temp_path;
760 } 762 }
761 763
762 void DeleteFile(const FilePath& path, bool recursive) { 764 void DeleteFile(const FilePath& path, bool recursive) {
763 file_util::Delete(path, recursive); 765 file_util::Delete(path, recursive);
764 } 766 }
765 767
766 } // namespace extension_file_util 768 } // namespace extension_file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698