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

Unified Diff: chrome/browser/extensions/extension_webstore_private_api.cc

Issue 6992047: Change the web store private install API to accept a localized extension name. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698