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

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: jyasskin + forward declaring 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"
32 #include "extensions/common/install_warning.h"
31 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
32 #include "net/base/escape.h" 34 #include "net/base/escape.h"
33 #include "net/base/file_stream.h" 35 #include "net/base/file_stream.h"
34 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
35 37
36 using extensions::Extension; 38 using extensions::Extension;
39 using extensions::Manifest;
37 40
38 namespace errors = extension_manifest_errors; 41 namespace errors = extension_manifest_errors;
39 42
40 namespace { 43 namespace {
41 44
42 const FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp"); 45 const FilePath::CharType kTempDirectoryName[] = FILE_PATH_LITERAL("Temp");
43 46
44 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set, 47 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set,
45 const Extension* extension, 48 const Extension* extension,
46 int error_message_id, 49 int error_message_id,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 132
130 void UninstallExtension(const FilePath& extensions_dir, 133 void UninstallExtension(const FilePath& extensions_dir,
131 const std::string& id) { 134 const std::string& id) {
132 // We don't care about the return value. If this fails (and it can, due to 135 // 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 136 // plugins that aren't unloaded yet, it will get cleaned up by
134 // ExtensionService::GarbageCollectExtensions). 137 // ExtensionService::GarbageCollectExtensions).
135 file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive. 138 file_util::Delete(extensions_dir.AppendASCII(id), true); // recursive.
136 } 139 }
137 140
138 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path, 141 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path,
139 Extension::Location location, 142 Manifest::Location location,
140 int flags, 143 int flags,
141 std::string* error) { 144 std::string* error) {
142 return LoadExtension(extension_path, std::string(), location, flags, error); 145 return LoadExtension(extension_path, std::string(), location, flags, error);
143 } 146 }
144 147
145 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path, 148 scoped_refptr<Extension> LoadExtension(const FilePath& extension_path,
146 const std::string& extension_id, 149 const std::string& extension_id,
147 Extension::Location location, 150 Manifest::Location location,
148 int flags, 151 int flags,
149 std::string* error) { 152 std::string* error) {
150 scoped_ptr<DictionaryValue> manifest(LoadManifest(extension_path, error)); 153 scoped_ptr<DictionaryValue> manifest(LoadManifest(extension_path, error));
151 if (!manifest.get()) 154 if (!manifest.get())
152 return NULL; 155 return NULL;
153 if (!extension_l10n_util::LocalizeExtension(extension_path, manifest.get(), 156 if (!extension_l10n_util::LocalizeExtension(extension_path, manifest.get(),
154 error)) { 157 error)) {
155 return NULL; 158 return NULL;
156 } 159 }
157 160
158 scoped_refptr<Extension> extension(Extension::Create(extension_path, 161 scoped_refptr<Extension> extension(Extension::Create(extension_path,
159 location, 162 location,
160 *manifest, 163 *manifest,
161 flags, 164 flags,
162 extension_id, 165 extension_id,
163 error)); 166 error));
164 if (!extension.get()) 167 if (!extension.get())
165 return NULL; 168 return NULL;
166 169
167 Extension::InstallWarningVector warnings; 170 std::vector<extensions::InstallWarning> warnings;
168 if (!ValidateExtension(extension.get(), error, &warnings)) 171 if (!ValidateExtension(extension.get(), error, &warnings))
169 return NULL; 172 return NULL;
170 extension->AddInstallWarnings(warnings); 173 extension->AddInstallWarnings(warnings);
171 174
172 return extension; 175 return extension;
173 } 176 }
174 177
175 DictionaryValue* LoadManifest(const FilePath& extension_path, 178 DictionaryValue* LoadManifest(const FilePath& extension_path,
176 std::string* error) { 179 std::string* error) {
177 FilePath manifest_path = 180 FilePath manifest_path =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 !file_util::GetFileSize(path, &size) || 241 !file_util::GetFileSize(path, &size) ||
239 size == 0) { 242 size == 0) {
240 return false; 243 return false;
241 } 244 }
242 245
243 return true; 246 return true;
244 } 247 }
245 248
246 bool ValidateExtension(const Extension* extension, 249 bool ValidateExtension(const Extension* extension,
247 std::string* error, 250 std::string* error,
248 Extension::InstallWarningVector* warnings) { 251 std::vector<extensions::InstallWarning>* warnings) {
249 // Validate icons exist. 252 // Validate icons exist.
250 for (ExtensionIconSet::IconMap::const_iterator iter = 253 for (ExtensionIconSet::IconMap::const_iterator iter =
251 extension->icons().map().begin(); 254 extension->icons().map().begin();
252 iter != extension->icons().map().end(); 255 iter != extension->icons().map().end();
253 ++iter) { 256 ++iter) {
254 const FilePath path = extension->GetResource(iter->second).GetFilePath(); 257 const FilePath path = extension->GetResource(iter->second).GetFilePath();
255 if (!ValidateFilePath(path)) { 258 if (!ValidateFilePath(path)) {
256 *error = 259 *error =
257 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED, 260 l10n_util::GetStringFUTF8(IDS_EXTENSION_LOAD_ICON_FAILED,
258 UTF8ToUTF16(iter->second)); 261 UTF8ToUTF16(iter->second));
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (!private_keys.empty()) { 409 if (!private_keys.empty()) {
407 // Only print one of the private keys because l10n_util doesn't have a way 410 // Only print one of the private keys because l10n_util doesn't have a way
408 // to translate a list of strings. 411 // to translate a list of strings.
409 *error = l10n_util::GetStringFUTF8( 412 *error = l10n_util::GetStringFUTF8(
410 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, 413 IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
411 private_keys.front().LossyDisplayName()); 414 private_keys.front().LossyDisplayName());
412 return false; 415 return false;
413 } 416 }
414 } else { 417 } else {
415 for (size_t i = 0; i < private_keys.size(); ++i) { 418 for (size_t i = 0; i < private_keys.size(); ++i) {
416 warnings->push_back(Extension::InstallWarning( 419 warnings->push_back(extensions::InstallWarning(
417 Extension::InstallWarning::FORMAT_TEXT, 420 extensions::InstallWarning::FORMAT_TEXT,
418 l10n_util::GetStringFUTF8( 421 l10n_util::GetStringFUTF8(
419 IDS_EXTENSION_CONTAINS_PRIVATE_KEY, 422 IDS_EXTENSION_CONTAINS_PRIVATE_KEY,
420 private_keys[i].LossyDisplayName()))); 423 private_keys[i].LossyDisplayName())));
421 } 424 }
422 // Only warn; don't block loading the extension. 425 // Only warn; don't block loading the extension.
423 } 426 }
424 return true; 427 return true;
425 } 428 }
426 429
427 void GarbageCollectExtensions( 430 void GarbageCollectExtensions(
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 return FilePath(); 760 return FilePath();
758 } 761 }
759 return temp_path; 762 return temp_path;
760 } 763 }
761 764
762 void DeleteFile(const FilePath& path, bool recursive) { 765 void DeleteFile(const FilePath& path, bool recursive) {
763 file_util::Delete(path, recursive); 766 file_util::Delete(path, recursive);
764 } 767 }
765 768
766 } // namespace extension_file_util 769 } // namespace extension_file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698