Index: chrome/browser/extensions/extension_webstore_private_api.cc |
diff --git a/chrome/browser/extensions/extension_webstore_private_api.cc b/chrome/browser/extensions/extension_webstore_private_api.cc |
index dbfdb6732798d9d2a74d03047482d6852e680b85..838bb4aaf7f31bb102437f48ecaa432065fb8afd 100644 |
--- a/chrome/browser/extensions/extension_webstore_private_api.cc |
+++ b/chrome/browser/extensions/extension_webstore_private_api.cc |
@@ -21,6 +21,7 @@ |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "chrome/common/extensions/extension_error_utils.h" |
+#include "chrome/common/extensions/extension_l10n_util.h" |
#include "chrome/common/net/gaia/gaia_constants.h" |
#include "content/browser/tab_contents/tab_contents.h" |
#include "content/common/notification_details.h" |
@@ -33,8 +34,13 @@ |
namespace { |
+const char kIconDataKey[] = "iconData"; |
+const char kIdKey[] = "id"; |
+const char kLocalizedNameKey[] = "localizedName"; |
const char kLoginKey[] = "login"; |
+const char kManifestKey[] = "manifest"; |
const char kTokenKey[] = "token"; |
+ |
const char kImageDecodeError[] = "Image decode failed"; |
const char kInvalidIdError[] = "Invalid id"; |
const char kInvalidManifestError[] = "Invalid manifest"; |
@@ -292,15 +298,29 @@ bool BeginInstallWithManifestFunction::RunImpl() { |
return false; |
} |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_)); |
+ DictionaryValue* details = NULL; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
+ CHECK(details); |
+ |
+ // Read the id. |
Matt Perry
2011/05/25 01:46:06
these comments can go - the code is self explanato
asargent_no_longer_on_chrome
2011/05/25 04:42:00
Done.
|
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); |
if (!Extension::IdIsValid(id_)) { |
SetResult(INVALID_ID); |
error_ = kInvalidIdError; |
return false; |
} |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &icon_data_)); |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &manifest_)); |
+ // Read the manifest. |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); |
+ |
+ // Read the icon data. |
+ if (details->HasKey(kIconDataKey)) |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_)); |
+ |
+ // Read the localized name. |
+ if (details->HasKey(kLocalizedNameKey)) |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey, |
+ &localized_name_)); |
scoped_refptr<SafeBeginInstallHelper> helper = |
new SafeBeginInstallHelper(this, icon_data_, manifest_); |
@@ -363,6 +383,18 @@ void BeginInstallWithManifestFunction::OnParseSuccess( |
icon_ = icon; |
parsed_manifest_.reset(parsed_manifest); |
+ // If we were passed a localized name to use in the dialog, temporarily |
+ // replace the name in |parsed_manifest| with it. |
+ std::string original_name; |
+ if (!localized_name_.empty()) { |
+ if (!parsed_manifest->GetString(extension_manifest_keys::kName, |
+ &original_name)) { |
+ OnParseFailure(MANIFEST_ERROR, std::string(kInvalidManifestError)); |
+ return; |
+ } |
+ parsed_manifest->SetString(extension_manifest_keys::kName, localized_name_); |
+ } |
+ |
// Create a dummy extension and show the extension install confirmation |
// dialog. |
std::string init_errors; |
@@ -376,6 +408,13 @@ void BeginInstallWithManifestFunction::OnParseSuccess( |
OnParseFailure(MANIFEST_ERROR, std::string(kInvalidManifestError)); |
return; |
} |
+ |
+ // Restore the original name in |parsed_manifest| if we replaced it with a |
+ // localized one, so that the whitelist entry will have the right value for |
+ // comparison against the actual downloaded crx file's manifest. |
+ if (!original_name.empty()) |
+ parsed_manifest_->SetString(extension_manifest_keys::kName, original_name); |
Matt Perry
2011/05/25 01:46:06
This restoring feels a little dirty. How about ins
asargent_no_longer_on_chrome
2011/05/25 04:42:00
Done.
|
+ |
if (icon_.empty()) |
icon_ = Extension::GetDefaultIcon(dummy_extension_->is_app()); |
@@ -410,7 +449,10 @@ void BeginInstallWithManifestFunction::OnParseFailure( |
} |
void BeginInstallWithManifestFunction::InstallUIProceed() { |
- CrxInstaller::SetWhitelistedManifest(id_, parsed_manifest_.release()); |
+ CrxInstaller::WhitelistEntry* entry = new CrxInstaller::WhitelistEntry; |
+ entry->parsed_manifest.reset(parsed_manifest_.release()); |
+ entry->localized_name = localized_name_; |
+ CrxInstaller::SetWhitelistEntry(id_, entry); |
SetResult(ERROR_NONE); |
SendResponse(true); |
@@ -439,7 +481,7 @@ bool CompleteInstallFunction::RunImpl() { |
} |
if (!CrxInstaller::IsIdWhitelisted(id) && |
- !CrxInstaller::GetWhitelistedManifest(id)) { |
+ !CrxInstaller::GetWhitelistEntry(id)) { |
error_ = ExtensionErrorUtils::FormatErrorMessage( |
kNoPreviousBeginInstallError, id); |
return false; |