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 3e9a605cfaa4274808788940b089f9da654d5eee..ca763e37addf54fdf1392470f8a040a7f75e59eb 100644 |
--- a/chrome/browser/extensions/extension_webstore_private_api.cc |
+++ b/chrome/browser/extensions/extension_webstore_private_api.cc |
@@ -52,6 +52,8 @@ const char kInvalidManifestError[] = "Invalid manifest"; |
const char kNoPreviousBeginInstallWithManifestError[] = |
"* does not match a previous call to beginInstallWithManifest3"; |
const char kUserCancelledError[] = "User cancelled install"; |
+const char kNoPermissionError[] = |
+ "You do not have permission to use this method."; |
ProfileSyncService* test_sync_service = NULL; |
@@ -109,6 +111,92 @@ void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( |
test_webstore_installer_delegate = delegate; |
} |
+InstallBundleFunction::InstallBundleFunction() {} |
+InstallBundleFunction::~InstallBundleFunction() {} |
+ |
+bool InstallBundleFunction::RunImpl() { |
+ if (!IsWebStoreURL(profile_, source_url())) { |
+ SetResult(PERMISSION_DENIED); |
+ return false; |
+ } |
+ |
+ ListValue* extensions = NULL; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); |
+ |
+ WebstoreBundle::ItemList items; |
+ if (!ReadBundleInfo(extensions, &items)) |
+ return false; |
+ |
+ bundle_ = new WebstoreBundle(profile(), &items); |
+ |
+ AddRef(); // Balanced in OnBundleInstallApproved and OnBundleInstallCanceled. |
+ |
+ bundle_->PromptForApproval(this); |
+ return true; |
+} |
+ |
+bool InstallBundleFunction::ReadBundleInfo( |
+ ListValue* extensions, WebstoreBundle::ItemList* items) { |
+ for (size_t i = 0; i < extensions->GetSize(); ++i) { |
+ DictionaryValue* details = NULL; |
+ EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); |
+ |
+ std::string id; |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id)); |
+ |
+ std::string manifest; |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest)); |
+ |
+ std::string localized_name; |
+ EXTENSION_FUNCTION_VALIDATE(details->GetString( |
+ kLocalizedNameKey, &localized_name)); |
+ |
+ // WebstoreBundle::Item ownership will be passed to WebstoreBundle. |
+ items->push_back(new WebstoreBundle::Item(id, manifest, localized_name)); |
+ } |
+ |
+ return true; |
+} |
+ |
+void InstallBundleFunction::OnBundleInstallApproved() { |
+ bundle_->CompleteInstall( |
+ &(dispatcher()->delegate()->GetAssociatedTabContents()->controller()), |
+ this); |
+} |
+ |
+void InstallBundleFunction::OnBundleInstallCanceled(bool user_initiated) { |
+ SetResult(user_initiated ? USER_CANCELLED : UNKNOWN_ERROR); |
+ SendResponse(false); |
+ |
+ Release(); // Balanced in RunImpl(). |
+} |
+ |
+void InstallBundleFunction::OnBundleInstallCompleted() { |
+ SetResult(ERROR_NONE); |
+ SendResponse(true); |
+ |
+ Release(); // Balanced in RunImpl(). |
+} |
+ |
+void InstallBundleFunction::SetResult(ErrorCode code) { |
+ switch (code) { |
+ case ERROR_NONE: |
+ result_.reset(Value::CreateStringValue("")); |
+ break; |
+ case UNKNOWN_ERROR: |
+ result_.reset(Value::CreateStringValue("unknown_error")); |
+ break; |
+ case USER_CANCELLED: |
+ result_.reset(Value::CreateStringValue("user_cancelled")); |
+ break; |
+ case PERMISSION_DENIED: |
+ result_.reset(Value::CreateStringValue("permission_denied")); |
+ break; |
+ default: |
+ CHECK(false); |
+ } |
+} |
+ |
BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() |
: use_app_installed_bubble_(false) {} |