Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_action.h" | 20 #include "chrome/common/extensions/extension_action.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/common/extensions/extension_l10n_util.h" | 22 #include "chrome/common/extensions/extension_l10n_util.h" |
| 23 #include "chrome/common/extensions/extension_messages.h" | |
| 24 #include "chrome/common/extensions/extension_message_bundle.h" | |
| 23 #include "chrome/common/extensions/extension_resource.h" | 25 #include "chrome/common/extensions/extension_resource.h" |
| 24 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 26 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
| 25 #include "content/common/json_value_serializer.h" | 27 #include "content/common/json_value_serializer.h" |
| 26 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 27 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
| 28 #include "net/base/file_stream.h" | 30 #include "net/base/file_stream.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 30 | 32 |
| 31 namespace errors = extension_manifest_errors; | 33 namespace errors = extension_manifest_errors; |
| 32 | 34 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 extension_l10n_util::LoadMessageCatalogs( | 395 extension_l10n_util::LoadMessageCatalogs( |
| 394 locale_path, | 396 locale_path, |
| 395 default_locale, | 397 default_locale, |
| 396 extension_l10n_util::CurrentLocaleOrDefault(), | 398 extension_l10n_util::CurrentLocaleOrDefault(), |
| 397 locales, | 399 locales, |
| 398 error); | 400 error); |
| 399 | 401 |
| 400 return message_bundle; | 402 return message_bundle; |
| 401 } | 403 } |
| 402 | 404 |
| 405 SubstitutionMap* LoadExtensionMessageBundleSubstitutionMap( | |
| 406 const FilePath& extension_path, | |
| 407 const std::string& extension_id, | |
| 408 const std::string& default_locale) { | |
| 409 SubstitutionMap* returnValue = new SubstitutionMap(); | |
| 410 if (!default_locale.empty()) { | |
| 411 // Touch disk only if extension is localized. | |
| 412 std::string error; | |
| 413 scoped_ptr<ExtensionMessageBundle> bundle( | |
| 414 extension_file_util::LoadExtensionMessageBundle( | |
|
Mihai Parparita -not on Chrome
2011/08/11 01:58:34
extension_file_util:: namespace prefix is unnecess
adriansc
2011/08/11 21:25:08
Done.
| |
| 415 extension_path, default_locale, &error)); | |
| 416 | |
| 417 if (bundle.get()) | |
| 418 *returnValue = *bundle->dictionary(); | |
| 419 } | |
| 420 | |
| 421 // Add @@extension_id reserved message here, so it's available to | |
| 422 // non-localized extensions too. | |
| 423 returnValue->insert( | |
| 424 std::make_pair(ExtensionMessageBundle::kExtensionIdKey, extension_id)); | |
| 425 | |
| 426 return returnValue; | |
| 427 } | |
| 428 | |
| 403 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) { | 429 static bool ValidateLocaleInfo(const Extension& extension, std::string* error) { |
| 404 // default_locale and _locales have to be both present or both missing. | 430 // default_locale and _locales have to be both present or both missing. |
| 405 const FilePath path = extension.path().Append(Extension::kLocaleFolder); | 431 const FilePath path = extension.path().Append(Extension::kLocaleFolder); |
| 406 bool path_exists = file_util::PathExists(path); | 432 bool path_exists = file_util::PathExists(path); |
| 407 std::string default_locale = extension.default_locale(); | 433 std::string default_locale = extension.default_locale(); |
| 408 | 434 |
| 409 // If both default locale and _locales folder are empty, skip verification. | 435 // If both default locale and _locales folder are empty, skip verification. |
| 410 if (default_locale.empty() && !path_exists) | 436 if (default_locale.empty() && !path_exists) |
| 411 return true; | 437 return true; |
| 412 | 438 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 return temp_path; | 640 return temp_path; |
| 615 | 641 |
| 616 return FilePath(); | 642 return FilePath(); |
| 617 } | 643 } |
| 618 | 644 |
| 619 void DeleteFile(const FilePath& path, bool recursive) { | 645 void DeleteFile(const FilePath& path, bool recursive) { |
| 620 file_util::Delete(path, recursive); | 646 file_util::Delete(path, recursive); |
| 621 } | 647 } |
| 622 | 648 |
| 623 } // namespace extension_file_util | 649 } // namespace extension_file_util |
| OLD | NEW |