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 f10848022e39bdb6fa91348974196f5693aedaf0..2afd389d347037d040b37e77fd68c9e2e73e4d53 100644 |
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc |
@@ -47,6 +47,17 @@ using content::GpuDataManager; |
namespace extensions { |
+namespace BeginInstallWithManifest3 = |
+ api::webstore_private::BeginInstallWithManifest3; |
+namespace CompleteInstall = api::webstore_private::CompleteInstall; |
+namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; |
+namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; |
+namespace GetStoreLogin = api::webstore_private::GetStoreLogin; |
+namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; |
+namespace InstallBundle = api::webstore_private::InstallBundle; |
+namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; |
+namespace SetStoreLogin = api::webstore_private::SetStoreLogin; |
+ |
namespace { |
// Holds the Approvals between the time we prompt and start the installs. |
@@ -142,15 +153,6 @@ static base::LazyInstance<PendingApprovals> g_pending_approvals = |
static base::LazyInstance<PendingInstalls> g_pending_installs = |
LAZY_INSTANCE_INITIALIZER; |
-const char kAppInstallBubbleKey[] = "appInstallBubble"; |
-const char kEnableLauncherKey[] = "enableLauncher"; |
-const char kIconDataKey[] = "iconData"; |
-const char kIconUrlKey[] = "iconUrl"; |
-const char kIdKey[] = "id"; |
-const char kLocalizedNameKey[] = "localizedName"; |
-const char kLoginKey[] = "login"; |
-const char kManifestKey[] = "manifest"; |
- |
// A preference set by the web store to indicate login information for |
// purchased apps. |
const char kWebstoreLogin[] = "extensions.webstore_login"; |
@@ -164,16 +166,6 @@ const char kNoPreviousBeginInstallWithManifestError[] = |
"* does not match a previous call to beginInstallWithManifest3"; |
const char kUserCancelledError[] = "User cancelled install"; |
-// Helper to create a dictionary with login properties set from the appropriate |
-// values in the passed-in |profile|. |
-base::DictionaryValue* CreateLoginResult(Profile* profile) { |
- base::DictionaryValue* dictionary = new base::DictionaryValue(); |
- std::string username = profile->GetPrefs()->GetString( |
- prefs::kGoogleServicesUsername); |
- dictionary->SetString(kLoginKey, username); |
- return dictionary; |
-} |
- |
WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; |
// We allow the web store to set a string containing login information when a |
@@ -210,11 +202,12 @@ WebstorePrivateInstallBundleFunction::WebstorePrivateInstallBundleFunction() {} |
WebstorePrivateInstallBundleFunction::~WebstorePrivateInstallBundleFunction() {} |
bool WebstorePrivateInstallBundleFunction::RunImpl() { |
- base::ListValue* extensions = NULL; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); |
+ scoped_ptr<InstallBundle::Params> params( |
+ InstallBundle::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
BundleInstaller::ItemList items; |
- if (!ReadBundleInfo(extensions, &items)) |
+ if (!ReadBundleInfo(*params, &items)) |
return false; |
bundle_ = new BundleInstaller(GetCurrentBrowser(), items); |
@@ -226,20 +219,13 @@ bool WebstorePrivateInstallBundleFunction::RunImpl() { |
} |
bool WebstorePrivateInstallBundleFunction:: |
- ReadBundleInfo(base::ListValue* extensions, |
+ ReadBundleInfo(const InstallBundle::Params& params, |
BundleInstaller::ItemList* items) { |
- for (size_t i = 0; i < extensions->GetSize(); ++i) { |
- base::DictionaryValue* details = NULL; |
- EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); |
- |
+ for (size_t i = 0; i < params.details.size(); ++i) { |
BundleInstaller::Item item; |
- EXTENSION_FUNCTION_VALIDATE(details->GetString( |
- kIdKey, &item.id)); |
- EXTENSION_FUNCTION_VALIDATE(details->GetString( |
- kManifestKey, &item.manifest)); |
- EXTENSION_FUNCTION_VALIDATE(details->GetString( |
- kLocalizedNameKey, &item.localized_name)); |
- |
+ item.id = params.details[i]->id; |
+ item.manifest = params.details[i]->manifest; |
+ item.localized_name = params.details[i]->localized_name; |
items->push_back(item); |
} |
@@ -271,40 +257,31 @@ void WebstorePrivateInstallBundleFunction::OnBundleInstallCompleted() { |
} |
WebstorePrivateBeginInstallWithManifest3Function:: |
- WebstorePrivateBeginInstallWithManifest3Function() |
- : use_app_installed_bubble_(false), enable_launcher_(false) {} |
+ WebstorePrivateBeginInstallWithManifest3Function() {} |
WebstorePrivateBeginInstallWithManifest3Function:: |
~WebstorePrivateBeginInstallWithManifest3Function() {} |
bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { |
- base::DictionaryValue* details = NULL; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
- CHECK(details); |
+ params_.reset(BeginInstallWithManifest3::Params::Create(*args_).release()); |
not at google - send to devlin
2013/08/14 14:58:13
better:
params_ = BeginInstallWithManifest3::Para
pals
2013/08/16 08:17:24
Done.
|
+ EXTENSION_FUNCTION_VALIDATE(params_); |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); |
- if (!extensions::Extension::IdIsValid(id_)) { |
+ if (!extensions::Extension::IdIsValid(params_->details.id)) { |
SetResultCode(INVALID_ID); |
error_ = kInvalidIdError; |
return false; |
} |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); |
- |
- if (details->HasKey(kIconDataKey) && details->HasKey(kIconUrlKey)) { |
+ if (params_->details.icon_data && params_->details.icon_url) { |
SetResultCode(ICON_ERROR); |
error_ = kCannotSpecifyIconDataAndUrlError; |
return false; |
} |
- if (details->HasKey(kIconDataKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_)); |
- |
GURL icon_url; |
- if (details->HasKey(kIconUrlKey)) { |
+ if (params_->details.icon_url) { |
std::string tmp_url; |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconUrlKey, &tmp_url)); |
- icon_url = source_url().Resolve(tmp_url); |
+ icon_url = source_url().Resolve(*params_->details.icon_url); |
if (!icon_url.is_valid()) { |
SetResultCode(INVALID_ICON_URL); |
error_ = kInvalidIconUrlError; |
@@ -312,22 +289,10 @@ bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { |
} |
} |
- if (details->HasKey(kLocalizedNameKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey, |
- &localized_name_)); |
- |
- if (details->HasKey(kAppInstallBubbleKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( |
- kAppInstallBubbleKey, &use_app_installed_bubble_)); |
- |
- if (details->HasKey(kEnableLauncherKey)) |
- EXTENSION_FUNCTION_VALIDATE(details->GetBoolean( |
- kEnableLauncherKey, &enable_launcher_)); |
- |
ExtensionService* service = |
extensions::ExtensionSystem::Get(profile_)->extension_service(); |
- if (service->GetInstalledExtension(id_) || |
- !g_pending_installs.Get().InsertInstall(profile_, id_)) { |
+ if (service->GetInstalledExtension(params_->details.id) || |
+ !g_pending_installs.Get().InsertInstall(profile_, params_->details.id)) { |
SetResultCode(ALREADY_INSTALLED); |
error_ = kAlreadyInstalledError; |
return false; |
@@ -338,7 +303,8 @@ bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { |
context_getter = profile()->GetRequestContext(); |
scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
- this, id_, manifest_, icon_data_, icon_url, context_getter); |
+ this, params_->details.id, params_->details.manifest, |
+ *params_->details.icon_data, icon_url, context_getter); |
not at google - send to devlin
2013/08/14 14:58:13
icon_data is optional and might be null here. I su
pals
2013/08/16 08:17:24
Done. Defaulted to std::string().
|
// The helper will call us back via OnWebstoreParseSuccess or |
// OnWebstoreParseFailure. |
@@ -352,50 +318,45 @@ bool WebstorePrivateBeginInstallWithManifest3Function::RunImpl() { |
return true; |
} |
- |
-void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( |
- ResultCode code) { |
+const char* WebstorePrivateBeginInstallWithManifest3Function:: |
+ ResultCodeToString(ResultCode code) { |
switch (code) { |
case ERROR_NONE: |
- SetResult(Value::CreateStringValue(std::string())); |
- break; |
+ return ""; |
case UNKNOWN_ERROR: |
- SetResult(Value::CreateStringValue("unknown_error")); |
- break; |
+ return "unknown_error"; |
case USER_CANCELLED: |
- SetResult(Value::CreateStringValue("user_cancelled")); |
- break; |
+ return "user_cancelled"; |
case MANIFEST_ERROR: |
- SetResult(Value::CreateStringValue("manifest_error")); |
- break; |
+ return "manifest_error"; |
case ICON_ERROR: |
- SetResult(Value::CreateStringValue("icon_error")); |
- break; |
+ return "icon_error"; |
case INVALID_ID: |
- SetResult(Value::CreateStringValue("invalid_id")); |
- break; |
+ return "invalid_id"; |
case PERMISSION_DENIED: |
- SetResult(Value::CreateStringValue("permission_denied")); |
- break; |
+ return "permission_denied"; |
case INVALID_ICON_URL: |
- SetResult(Value::CreateStringValue("invalid_icon_url")); |
- break; |
+ return "invalid_icon_url"; |
case SIGNIN_FAILED: |
- SetResult(Value::CreateStringValue("signin_failed")); |
- break; |
+ return "signin_failed"; |
case ALREADY_INSTALLED: |
- SetResult(Value::CreateStringValue("already_installed")); |
- break; |
- default: |
- CHECK(false); |
+ return "already_installed"; |
} |
+ NOTREACHED(); |
+ return ""; |
+} |
+ |
+void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( |
+ ResultCode code) { |
+ results_ = BeginInstallWithManifest3::Results::Create( |
+ ResultCodeToString(code)); |
} |
void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( |
const std::string& id, |
const SkBitmap& icon, |
base::DictionaryValue* parsed_manifest) { |
- CHECK_EQ(id_, id); |
+ CHECK_EQ(params_->details.id, id); |
CHECK(parsed_manifest); |
icon_ = icon; |
parsed_manifest_.reset(parsed_manifest); |
@@ -405,12 +366,12 @@ void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseSuccess( |
parsed_manifest_.get(), |
Extension::FROM_WEBSTORE, |
id, |
- localized_name_, |
+ *params_->details.localized_name, |
not at google - send to devlin
2013/08/14 14:58:13
this can also be null, needs to default to "".
pals
2013/08/16 08:17:24
Done.
|
std::string(), |
&error); |
if (!dummy_extension_.get()) { |
- OnWebstoreParseFailure(id_, |
+ OnWebstoreParseFailure(params_->details.id, |
WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
kInvalidManifestError); |
return; |
@@ -433,7 +394,7 @@ void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( |
const std::string& id, |
WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
const std::string& error_message) { |
- CHECK_EQ(id_, id); |
+ CHECK_EQ(params_->details.id, id); |
// Map from WebstoreInstallHelper's result codes to ours. |
switch (result_code) { |
@@ -463,7 +424,7 @@ void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed( |
SetResultCode(SIGNIN_FAILED); |
error_ = error.ToString(); |
- g_pending_installs.Get().EraseInstall(profile_, id_); |
+ g_pending_installs.Get().EraseInstall(profile_, params_->details.id); |
SendResponse(false); |
// Matches the AddRef in RunImpl(). |
@@ -496,12 +457,12 @@ void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { |
// entry is only valid for some number of minutes. |
scoped_ptr<WebstoreInstaller::Approval> approval( |
WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
- profile(), id_, parsed_manifest_.Pass())); |
- approval->use_app_installed_bubble = use_app_installed_bubble_; |
- approval->enable_launcher = enable_launcher_; |
+ profile(), params_->details.id, parsed_manifest_.Pass())); |
+ approval->use_app_installed_bubble = params_->details.app_install_bubble; |
+ approval->enable_launcher = params_->details.enable_launcher; |
// If we are enabling the launcher, we should not show the app list in order |
// to train the user to open it themselves at least once. |
- approval->skip_post_install_ui = enable_launcher_; |
+ approval->skip_post_install_ui = params_->details.enable_launcher; |
approval->installing_icon = gfx::ImageSkia::CreateFrom1xBitmap(icon_); |
g_pending_approvals.Get().PushApproval(approval.Pass()); |
@@ -522,7 +483,7 @@ void WebstorePrivateBeginInstallWithManifest3Function::InstallUIAbort( |
bool user_initiated) { |
error_ = kUserCancelledError; |
SetResultCode(USER_CANCELLED); |
- g_pending_installs.Get().EraseInstall(profile_, id_); |
+ g_pending_installs.Get().EraseInstall(profile_, params_->details.id); |
SendResponse(false); |
// The web store install histograms are a subset of the install histograms. |
@@ -551,17 +512,19 @@ WebstorePrivateCompleteInstallFunction:: |
~WebstorePrivateCompleteInstallFunction() {} |
bool WebstorePrivateCompleteInstallFunction::RunImpl() { |
- std::string id; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); |
- if (!extensions::Extension::IdIsValid(id)) { |
+ scoped_ptr<CompleteInstall::Params> params( |
+ CompleteInstall::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ if (!extensions::Extension::IdIsValid(params->expected_id)) { |
error_ = kInvalidIdError; |
return false; |
} |
- approval_ = g_pending_approvals.Get().PopApproval(profile(), id).Pass(); |
+ approval_ = g_pending_approvals.Get().PopApproval(profile(), |
+ params->expected_id).Pass(); |
if (!approval_) { |
error_ = ErrorUtils::FormatErrorMessage( |
- kNoPreviousBeginInstallWithManifestError, id); |
+ kNoPreviousBeginInstallWithManifestError, params->expected_id); |
return false; |
} |
@@ -583,7 +546,7 @@ bool WebstorePrivateCompleteInstallFunction::RunImpl() { |
scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
profile(), this, |
&(dispatcher()->delegate()->GetAssociatedWebContents()->GetController()), |
- id, approval_.Pass(), WebstoreInstaller::FLAG_NONE); |
+ params->expected_id, approval_.Pass(), WebstoreInstaller::FLAG_NONE); |
installer->Start(); |
return true; |
@@ -628,24 +591,27 @@ WebstorePrivateEnableAppLauncherFunction:: |
bool WebstorePrivateEnableAppLauncherFunction::RunImpl() { |
AppListService::Get()->EnableAppList(profile()); |
- SendResponse(true); |
return true; |
} |
bool WebstorePrivateGetBrowserLoginFunction::RunImpl() { |
- SetResult(CreateLoginResult(profile_->GetOriginalProfile())); |
+ GetBrowserLogin::Results::Info info; |
+ info.login = profile_->GetOriginalProfile()->GetPrefs()->GetString( |
+ prefs::kGoogleServicesUsername); |
+ results_ = GetBrowserLogin::Results::Create(info); |
return true; |
} |
bool WebstorePrivateGetStoreLoginFunction::RunImpl() { |
- SetResult(Value::CreateStringValue(GetWebstoreLogin(profile_))); |
+ results_ = GetStoreLogin::Results::Create(GetWebstoreLogin(profile_)); |
return true; |
} |
bool WebstorePrivateSetStoreLoginFunction::RunImpl() { |
- std::string login; |
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); |
- SetWebstoreLogin(profile_, login); |
+ scoped_ptr<SetStoreLogin::Params> params( |
+ SetStoreLogin::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params); |
+ SetWebstoreLogin(profile_, params->login); |
return true; |
} |
@@ -660,8 +626,8 @@ WebstorePrivateGetWebGLStatusFunction:: |
~WebstorePrivateGetWebGLStatusFunction() {} |
void WebstorePrivateGetWebGLStatusFunction::CreateResult(bool webgl_allowed) { |
- SetResult(Value::CreateStringValue( |
- webgl_allowed ? "webgl_allowed" : "webgl_blocked")); |
+ results_ = GetWebGLStatus::Results::Create(GetWebGLStatus::Results:: |
+ ParseWebgl_status(webgl_allowed ? "webgl_allowed" : "webgl_blocked")); |
} |
bool WebstorePrivateGetWebGLStatusFunction::RunImpl() { |
@@ -676,15 +642,14 @@ void WebstorePrivateGetWebGLStatusFunction:: |
} |
bool WebstorePrivateGetIsLauncherEnabledFunction::RunImpl() { |
- SetResult(Value::CreateBooleanValue(apps::IsAppLauncherEnabled())); |
- SendResponse(true); |
+ results_ = GetIsLauncherEnabled::Results::Create( |
+ apps::IsAppLauncherEnabled()); |
return true; |
} |
bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() { |
- SetResult( |
- Value::CreateBooleanValue(profile_ != profile_->GetOriginalProfile())); |
- SendResponse(true); |
+ results_ = IsInIncognitoMode::Results::Create( |
+ profile_ != profile_->GetOriginalProfile()); |
return true; |
} |