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 6453e460a25e6fe2f33359311421fb5a5c9205d3..4c1a0f1d9f267baa0033f4d069aea6f6d0b1bf38 100644 |
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
@@ -46,6 +46,8 @@ namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; |
namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
+namespace ShowPermissionPromptForDelegatedInstall = |
+ api::webstore_private::ShowPermissionPromptForDelegatedInstall; |
namespace { |
@@ -133,6 +135,20 @@ api::webstore_private::Result WebstoreInstallResultToApiResult( |
return api::webstore_private::RESULT_NONE; |
} |
+api::webstore_private::Result WebstoreInstallHelperResultToApiResult( |
+ WebstoreInstallHelper::Delegate::InstallHelperResultCode result) { |
+ switch (result) { |
+ case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
+ return api::webstore_private::RESULT_UNKNOWN_ERROR; |
+ case WebstoreInstallHelper::Delegate::ICON_ERROR: |
+ return api::webstore_private::RESULT_ICON_ERROR; |
+ case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
+ return api::webstore_private::RESULT_MANIFEST_ERROR; |
+ } |
+ NOTREACHED(); |
+ return api::webstore_private::RESULT_NONE; |
+} |
+ |
static base::LazyInstance<PendingApprovals> g_pending_approvals = |
LAZY_INSTANCE_INITIALIZER; |
@@ -306,22 +322,8 @@ void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( |
const std::string& error_message) { |
CHECK_EQ(params_->details.id, id); |
- // Map from WebstoreInstallHelper's result codes to ours. |
- api::webstore_private::Result api_result = |
- api::webstore_private::RESULT_NONE; |
- switch (result) { |
- case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
- api_result = api::webstore_private::RESULT_UNKNOWN_ERROR; |
- break; |
- case WebstoreInstallHelper::Delegate::ICON_ERROR: |
- api_result = api::webstore_private::RESULT_ICON_ERROR; |
- break; |
- case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: |
- api_result = api::webstore_private::RESULT_MANIFEST_ERROR; |
- break; |
- } |
- DCHECK_NE(api_result, api::webstore_private::RESULT_NONE); |
- Respond(BuildResponseForError(api_result, error_message)); |
+ Respond(BuildResponseForError(WebstoreInstallHelperResultToApiResult(result), |
+ error_message)); |
// Matches the AddRef in Run(). |
Release(); |
@@ -516,6 +518,149 @@ void WebstorePrivateCompleteInstallFunction::OnInstallSuccess( |
test_webstore_installer_delegate->OnExtensionInstallSuccess(id); |
} |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
+} |
+ |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ ~WebstorePrivateShowPermissionPromptForDelegatedInstallFunction() { |
+} |
+ |
+ExtensionFunction::ResponseAction |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::Run() { |
not at google - send to devlin
2015/02/24 18:30:00
Is there a nice way to factor this that shares the
Marc Treib
2015/02/25 13:38:47
Done (not sure on the "nice" part, though).
I've e
|
+ params_ = ShowPermissionPromptForDelegatedInstall::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(params_); |
+ |
+ if (!crx_file::id_util::IdIsValid(params_->details.id)) { |
+ return RespondNow(BuildResponse(api::webstore_private::RESULT_INVALID_ID, |
+ kInvalidIdError)); |
+ } |
+ |
+ if (params_->details.icon_data && params_->details.icon_url) { |
+ return RespondNow(BuildResponse(api::webstore_private::RESULT_ICON_ERROR, |
+ kCannotSpecifyIconDataAndUrlError)); |
+ } |
+ |
+ GURL icon_url; |
+ if (params_->details.icon_url) { |
+ std::string tmp_url; |
not at google - send to devlin
2015/02/24 18:30:00
Unused? (also unused above)
Marc Treib
2015/02/25 13:38:47
Done, thanks! (copy&paste ftl)
|
+ icon_url = source_url().Resolve(*params_->details.icon_url); |
+ if (!icon_url.is_valid()) { |
+ return RespondNow(BuildResponse( |
+ api::webstore_private::RESULT_INVALID_ICON_URL, |
+ kInvalidIconUrlError)); |
+ } |
+ } |
+ |
+ 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 = browser_context()->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 RespondLater(); |
+} |
+ |
+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. |
+ Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, |
+ kUserCancelledError)); |
+ // Matches the AddRef in Run(). |
+ Release(); |
+ 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, |
+ const std::string& error_message) { |
+ CHECK_EQ(params_->details.id, id); |
+ |
+ Respond(BuildResponse(WebstoreInstallHelperResultToApiResult(result), |
+ error_message)); |
+ |
+ // Matches the AddRef in Run(). |
+ Release(); |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ InstallUIProceed() { |
+ Respond(BuildResponse(api::webstore_private::RESULT_SUCCESS, std::string())); |
+ |
+ // Matches the AddRef in Run(). |
+ Release(); |
+} |
+ |
+void WebstorePrivateShowPermissionPromptForDelegatedInstallFunction:: |
+ InstallUIAbort(bool user_initiated) { |
+ Respond(BuildResponse(api::webstore_private::RESULT_USER_CANCELLED, |
+ kUserCancelledError)); |
+ |
+ // Matches the AddRef in Run(). |
+ Release(); |
+} |
+ |
+ExtensionFunction::ResponseValue |
+WebstorePrivateShowPermissionPromptForDelegatedInstallFunction::BuildResponse( |
+ api::webstore_private::Result result, const std::string& error) { |
+ if (result != api::webstore_private::RESULT_SUCCESS) { |
+ return ErrorWithArguments( |
+ ShowPermissionPromptForDelegatedInstall::Results::Create(result), |
+ error); |
+ } |
+ return ArgumentList( |
+ ShowPermissionPromptForDelegatedInstall::Results::Create(result)); |
+} |
+ |
WebstorePrivateEnableAppLauncherFunction:: |
WebstorePrivateEnableAppLauncherFunction() : chrome_details_(this) {} |