Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser/extensions/extension_file_util.h" | 5 #include "chrome/browser/extensions/extension_file_util.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | |
| 7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 12 #include "chrome/browser/extensions/extension_l10n_util.h" | 13 #include "chrome/browser/extensions/extension_l10n_util.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" | 15 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "chrome/common/json_value_serializer.h" | 16 #include "chrome/common/json_value_serializer.h" |
| 16 #include "net/base/file_stream.h" | 17 #include "net/base/file_stream.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 88 |
| 88 if (!MoveDirSafely(src_dir, version_dir)) { | 89 if (!MoveDirSafely(src_dir, version_dir)) { |
| 89 *error = "Could not move extension directory into profile."; | 90 *error = "Could not move extension directory into profile."; |
| 90 return false; | 91 return false; |
| 91 } | 92 } |
| 92 | 93 |
| 93 scoped_version_dir.Take(); | 94 scoped_version_dir.Take(); |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| 96 | 97 |
| 97 Extension* LoadExtension(const FilePath& extension_path, bool require_key, | 98 Extension* LoadExtension(const FilePath& extension_path, |
| 99 bool require_key, | |
| 98 std::string* error) { | 100 std::string* error) { |
| 99 FilePath manifest_path = | 101 FilePath manifest_path = |
| 100 extension_path.AppendASCII(Extension::kManifestFilename); | 102 extension_path.AppendASCII(Extension::kManifestFilename); |
| 101 if (!file_util::PathExists(manifest_path)) { | 103 if (!file_util::PathExists(manifest_path)) { |
| 102 *error = extension_manifest_errors::kInvalidManifest; | 104 *error = extension_manifest_errors::kInvalidManifest; |
| 103 return NULL; | 105 return NULL; |
| 104 } | 106 } |
| 105 | 107 |
| 106 JSONFileValueSerializer serializer(manifest_path); | 108 JSONFileValueSerializer serializer(manifest_path); |
| 107 scoped_ptr<Value> root(serializer.Deserialize(error)); | 109 scoped_ptr<Value> root(serializer.Deserialize(error)); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 if (!extension_l10n_util::AddValidLocales(locale_path, | 227 if (!extension_l10n_util::AddValidLocales(locale_path, |
| 226 extension, | 228 extension, |
| 227 error)) { | 229 error)) { |
| 228 return false; | 230 return false; |
| 229 } | 231 } |
| 230 | 232 |
| 231 if (!extension_l10n_util::ValidateDefaultLocale(extension)) { | 233 if (!extension_l10n_util::ValidateDefaultLocale(extension)) { |
| 232 *error = extension_manifest_errors::kLocalesNoDefaultLocaleSpecified; | 234 *error = extension_manifest_errors::kLocalesNoDefaultLocaleSpecified; |
| 233 return false; | 235 return false; |
| 234 } | 236 } |
| 237 | |
| 238 // We can't call g_browser_process->GetApplicationLocale() since we are not | |
| 239 // on the main thread. | |
| 240 static const std::string& app_locale = l10n_util::GetApplicationLocale(L""); | |
|
Aaron Boodman
2009/08/31 21:42:55
This seems to check the prefs. Is it OK to do that
| |
| 241 extension->set_application_locale(app_locale); | |
| 242 if (!extension_l10n_util::LoadMessageCatalogs(locale_path, | |
| 243 extension, | |
| 244 error)) { | |
| 245 return NULL; | |
| 246 } | |
| 247 // Replace possible messages in the manifest name and description sections. | |
| 248 std::string value = extension->name(); | |
|
Aaron Boodman
2009/08/31 21:42:55
Instead of reading and then re-writing the name, w
| |
| 249 if (extension->message_handler()->ReplaceMessagesInString(&value)) { | |
| 250 extension->set_name(value); | |
| 251 } else { | |
| 252 *error = StringPrintf("Message \"%s\" is missing but used in a " | |
| 253 "extension name.", value.c_str()); | |
| 254 return NULL; | |
| 255 } | |
| 256 | |
| 257 value = extension->description(); | |
| 258 if (extension->message_handler()->ReplaceMessagesInString(&value)) { | |
| 259 extension->set_description(value); | |
| 260 } else { | |
| 261 *error = StringPrintf("Message \"%s\" is missing but used in a " | |
| 262 "extension description.", value.c_str()); | |
| 263 return NULL; | |
| 264 } | |
| 235 } | 265 } |
| 236 | 266 |
| 237 // Check children of extension root to see if any of them start with _ and is | 267 // Check children of extension root to see if any of them start with _ and is |
| 238 // not on the reserved list. | 268 // not on the reserved list. |
| 239 if (!CheckForIllegalFilenames(extension->path(), error)) { | 269 if (!CheckForIllegalFilenames(extension->path(), error)) { |
| 240 return false; | 270 return false; |
| 241 } | 271 } |
| 242 | 272 |
| 243 return true; | 273 return true; |
| 244 } | 274 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 "Filenames starting with \"_\" are reserved for use by the system", | 373 "Filenames starting with \"_\" are reserved for use by the system", |
| 344 filename.c_str()); | 374 filename.c_str()); |
| 345 return false; | 375 return false; |
| 346 } | 376 } |
| 347 } | 377 } |
| 348 | 378 |
| 349 return true; | 379 return true; |
| 350 } | 380 } |
| 351 | 381 |
| 352 } // extension_file_util | 382 } // extension_file_util |
| OLD | NEW |