Index: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
index 52aa1b88a57fc79a9d2e9ed1e71c07f1ea9f2f0a..46f5242efa28302e1be0786d12aa28d7a9702d76 100644 |
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
@@ -65,6 +65,8 @@ namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; |
namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results; |
namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
+namespace ShowPermissionPromptForDelegatedInstall = |
+ api::webstore_private::ShowPermissionPromptForDelegatedInstall; |
namespace { |
@@ -509,6 +511,177 @@ void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( |
SendResponse(true); |
} |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
+} |
+ |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
+} |
+ |
+bool WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ RunAsync() { |
+ params_ = ShowPermissionPromptForDelegatedInstall::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(params_); |
+ |
+ if (!crx_file::id_util::IdIsValid(params_->details.id)) { |
+ SetResultCode(INVALID_ID); |
+ error_ = kInvalidIdError; |
+ return false; |
+ } |
+ |
+ if (params_->details.icon_data && params_->details.icon_url) { |
+ SetResultCode(ICON_ERROR); |
+ error_ = kCannotSpecifyIconDataAndUrlError; |
+ return false; |
+ } |
+ |
+ GURL icon_url; |
+ if (params_->details.icon_url) { |
+ std::string tmp_url; |
+ icon_url = source_url().Resolve(*params_->details.icon_url); |
+ if (!icon_url.is_valid()) { |
+ SetResultCode(INVALID_ICON_URL); |
+ error_ = kInvalidIconUrlError; |
+ return false; |
+ } |
+ } |
+ |
+ std::string icon_data = params_->details.icon_data ? |
+ *params_->details.icon_data : std::string(); |
+ |
+ net::URLRequestContextGetter* context_getter = NULL; |
+ if (!icon_url.is_empty()) |
+ context_getter = GetProfile()->GetRequestContext(); |
+ |
+ scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
+ this, params_->details.id, params_->details.manifest, icon_data, icon_url, |
+ context_getter); |
+ |
+ // The helper will call us back via OnWebstoreParseSuccess or |
+ // OnWebstoreParseFailure. |
+ helper->Start(); |
+ |
+ // Matched with a Release in OnWebstoreParseSuccess/OnWebstoreParseFailure. |
+ AddRef(); |
+ |
+ // The response is sent asynchronously in OnWebstoreParseSuccess/ |
+ // OnWebstoreParseFailure. |
+ return true; |
+} |
+ |
+const char* WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ ResultCodeToString(ResultCode code) { |
+ switch (code) { |
+ case ERROR_NONE: |
+ return ""; |
+ case UNKNOWN_ERROR: |
+ return "unknown_error"; |
+ case USER_CANCELLED: |
+ return "user_cancelled"; |
+ case MANIFEST_ERROR: |
+ return "manifest_error"; |
+ case ICON_ERROR: |
+ return "icon_error"; |
+ case INVALID_ID: |
+ return "invalid_id"; |
+ case INVALID_ICON_URL: |
+ return "invalid_icon_url"; |
+ } |
+ NOTREACHED(); |
+ return ""; |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ SetResultCode(ResultCode code) { |
+ results_ = ShowPermissionPromptForDelegatedInstall::Results::Create( |
+ ResultCodeToString(code)); |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ OnWebstoreParseSuccess(const std::string& id, |
+ const SkBitmap& icon, |
+ base::DictionaryValue* parsed_manifest) { |
+ CHECK_EQ(params_->details.id, id); |
+ CHECK(parsed_manifest); |
+ icon_ = icon; |
+ parsed_manifest_.reset(parsed_manifest); |
+ |
+ std::string localized_name = params_->details.localized_name ? |
+ *params_->details.localized_name : std::string(); |
+ |
+ std::string error; |
+ dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
+ parsed_manifest_.get(), |
+ Extension::FROM_WEBSTORE, |
+ id, |
+ localized_name, |
+ std::string(), |
+ &error); |
+ |
+ if (!dummy_extension_.get()) { |
+ OnWebstoreParseFailure(params_->details.id, |
+ WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
+ kInvalidManifestError); |
+ return; |
+ } |
+ |
+ content::WebContents* web_contents = GetAssociatedWebContents(); |
+ if (!web_contents) // The browser window has gone away. |
+ return; |
+ install_prompt_.reset(new ExtensionInstallPrompt(web_contents)); |
+ install_prompt_->ConfirmPermissionsForDelegatedInstall( |
+ this, dummy_extension_.get(), params_->details.delegated_user, &icon_); |
+ // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ OnWebstoreParseFailure( |
+ const std::string& id, |
+ WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
+ const std::string& error_message) { |
+ CHECK_EQ(params_->details.id, id); |
+ |
+ // Map from WebstoreInstallHelper's result codes to ours. |
+ switch (result_code) { |
+ case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
+ SetResultCode(UNKNOWN_ERROR); |
+ break; |
+ case WebstoreInstallHelper::Delegate::ICON_ERROR: |
+ SetResultCode(ICON_ERROR); |
+ break; |
+ case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
+ SetResultCode(MANIFEST_ERROR); |
+ break; |
+ default: |
+ CHECK(false); |
+ } |
+ error_ = error_message; |
+ SendResponse(false); |
+ |
+ // Matches the AddRef in RunAsync(). |
+ Release(); |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ InstallUIProceed() { |
+ SetResultCode(ERROR_NONE); |
+ SendResponse(true); |
+ |
+ // Matches the AddRef in RunAsync(). |
+ Release(); |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ InstallUIAbort(bool user_initiated) { |
+ error_ = kUserCancelledError; |
+ SetResultCode(USER_CANCELLED); |
+ SendResponse(false); |
+ |
+ // Matches the AddRef in RunAsync(). |
+ Release(); |
+} |
+ |
WebstorePrivateEnableAppLauncherFunction:: |
WebstorePrivateEnableAppLauncherFunction() {} |