| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" | 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 6 | 6 |
| 7 #include "apps/app_launcher.h" | 7 #include "apps/app_launcher.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 "You cannot specify both icon data and an icon url"; | 161 "You cannot specify both icon data and an icon url"; |
| 162 const char kInvalidIconUrlError[] = "Invalid icon url"; | 162 const char kInvalidIconUrlError[] = "Invalid icon url"; |
| 163 const char kInvalidIdError[] = "Invalid id"; | 163 const char kInvalidIdError[] = "Invalid id"; |
| 164 const char kInvalidManifestError[] = "Invalid manifest"; | 164 const char kInvalidManifestError[] = "Invalid manifest"; |
| 165 const char kNoPreviousBeginInstallWithManifestError[] = | 165 const char kNoPreviousBeginInstallWithManifestError[] = |
| 166 "* does not match a previous call to beginInstallWithManifest3"; | 166 "* does not match a previous call to beginInstallWithManifest3"; |
| 167 const char kUserCancelledError[] = "User cancelled install"; | 167 const char kUserCancelledError[] = "User cancelled install"; |
| 168 | 168 |
| 169 // Helper to create a dictionary with login properties set from the appropriate | 169 // Helper to create a dictionary with login properties set from the appropriate |
| 170 // values in the passed-in |profile|. | 170 // values in the passed-in |profile|. |
| 171 DictionaryValue* CreateLoginResult(Profile* profile) { | 171 base::DictionaryValue* CreateLoginResult(Profile* profile) { |
| 172 DictionaryValue* dictionary = new DictionaryValue(); | 172 base::DictionaryValue* dictionary = new base::DictionaryValue(); |
| 173 std::string username = profile->GetPrefs()->GetString( | 173 std::string username = profile->GetPrefs()->GetString( |
| 174 prefs::kGoogleServicesUsername); | 174 prefs::kGoogleServicesUsername); |
| 175 dictionary->SetString(kLoginKey, username); | 175 dictionary->SetString(kLoginKey, username); |
| 176 return dictionary; | 176 return dictionary; |
| 177 } | 177 } |
| 178 | 178 |
| 179 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; | 179 WebstoreInstaller::Delegate* test_webstore_installer_delegate = NULL; |
| 180 | 180 |
| 181 void EnableAppLauncher(base::Callback<void(bool)> callback) { | 181 void EnableAppLauncher(base::Callback<void(bool)> callback) { |
| 182 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 scoped_ptr<WebstoreInstaller::Approval> | 215 scoped_ptr<WebstoreInstaller::Approval> |
| 216 WebstorePrivateApi::PopApprovalForTesting( | 216 WebstorePrivateApi::PopApprovalForTesting( |
| 217 Profile* profile, const std::string& extension_id) { | 217 Profile* profile, const std::string& extension_id) { |
| 218 return g_pending_approvals.Get().PopApproval(profile, extension_id); | 218 return g_pending_approvals.Get().PopApproval(profile, extension_id); |
| 219 } | 219 } |
| 220 | 220 |
| 221 InstallBundleFunction::InstallBundleFunction() {} | 221 InstallBundleFunction::InstallBundleFunction() {} |
| 222 InstallBundleFunction::~InstallBundleFunction() {} | 222 InstallBundleFunction::~InstallBundleFunction() {} |
| 223 | 223 |
| 224 bool InstallBundleFunction::RunImpl() { | 224 bool InstallBundleFunction::RunImpl() { |
| 225 ListValue* extensions = NULL; | 225 base::ListValue* extensions = NULL; |
| 226 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); | 226 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); |
| 227 | 227 |
| 228 BundleInstaller::ItemList items; | 228 BundleInstaller::ItemList items; |
| 229 if (!ReadBundleInfo(extensions, &items)) | 229 if (!ReadBundleInfo(extensions, &items)) |
| 230 return false; | 230 return false; |
| 231 | 231 |
| 232 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); | 232 bundle_ = new BundleInstaller(GetCurrentBrowser(), items); |
| 233 | 233 |
| 234 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled. | 234 AddRef(); // Balanced in OnBundleInstallCompleted / OnBundleInstallCanceled. |
| 235 | 235 |
| 236 bundle_->PromptForApproval(this); | 236 bundle_->PromptForApproval(this); |
| 237 return true; | 237 return true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 bool InstallBundleFunction::ReadBundleInfo(ListValue* extensions, | 240 bool InstallBundleFunction::ReadBundleInfo(base::ListValue* extensions, |
| 241 BundleInstaller::ItemList* items) { | 241 BundleInstaller::ItemList* items) { |
| 242 for (size_t i = 0; i < extensions->GetSize(); ++i) { | 242 for (size_t i = 0; i < extensions->GetSize(); ++i) { |
| 243 DictionaryValue* details = NULL; | 243 base::DictionaryValue* details = NULL; |
| 244 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); | 244 EXTENSION_FUNCTION_VALIDATE(extensions->GetDictionary(i, &details)); |
| 245 | 245 |
| 246 BundleInstaller::Item item; | 246 BundleInstaller::Item item; |
| 247 EXTENSION_FUNCTION_VALIDATE(details->GetString( | 247 EXTENSION_FUNCTION_VALIDATE(details->GetString( |
| 248 kIdKey, &item.id)); | 248 kIdKey, &item.id)); |
| 249 EXTENSION_FUNCTION_VALIDATE(details->GetString( | 249 EXTENSION_FUNCTION_VALIDATE(details->GetString( |
| 250 kManifestKey, &item.manifest)); | 250 kManifestKey, &item.manifest)); |
| 251 EXTENSION_FUNCTION_VALIDATE(details->GetString( | 251 EXTENSION_FUNCTION_VALIDATE(details->GetString( |
| 252 kLocalizedNameKey, &item.localized_name)); | 252 kLocalizedNameKey, &item.localized_name)); |
| 253 | 253 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 279 | 279 |
| 280 Release(); // Balanced in RunImpl(). | 280 Release(); // Balanced in RunImpl(). |
| 281 } | 281 } |
| 282 | 282 |
| 283 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() | 283 BeginInstallWithManifestFunction::BeginInstallWithManifestFunction() |
| 284 : use_app_installed_bubble_(false), enable_launcher_(false) {} | 284 : use_app_installed_bubble_(false), enable_launcher_(false) {} |
| 285 | 285 |
| 286 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} | 286 BeginInstallWithManifestFunction::~BeginInstallWithManifestFunction() {} |
| 287 | 287 |
| 288 bool BeginInstallWithManifestFunction::RunImpl() { | 288 bool BeginInstallWithManifestFunction::RunImpl() { |
| 289 DictionaryValue* details = NULL; | 289 base::DictionaryValue* details = NULL; |
| 290 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 290 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| 291 CHECK(details); | 291 CHECK(details); |
| 292 | 292 |
| 293 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); | 293 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); |
| 294 if (!extensions::Extension::IdIsValid(id_)) { | 294 if (!extensions::Extension::IdIsValid(id_)) { |
| 295 SetResultCode(INVALID_ID); | 295 SetResultCode(INVALID_ID); |
| 296 error_ = kInvalidIdError; | 296 error_ = kInvalidIdError; |
| 297 return false; | 297 return false; |
| 298 } | 298 } |
| 299 | 299 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 SetResult(Value::CreateStringValue("already_installed")); | 394 SetResult(Value::CreateStringValue("already_installed")); |
| 395 break; | 395 break; |
| 396 default: | 396 default: |
| 397 CHECK(false); | 397 CHECK(false); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( | 401 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( |
| 402 const std::string& id, | 402 const std::string& id, |
| 403 const SkBitmap& icon, | 403 const SkBitmap& icon, |
| 404 DictionaryValue* parsed_manifest) { | 404 base::DictionaryValue* parsed_manifest) { |
| 405 CHECK_EQ(id_, id); | 405 CHECK_EQ(id_, id); |
| 406 CHECK(parsed_manifest); | 406 CHECK(parsed_manifest); |
| 407 icon_ = icon; | 407 icon_ = icon; |
| 408 parsed_manifest_.reset(parsed_manifest); | 408 parsed_manifest_.reset(parsed_manifest); |
| 409 | 409 |
| 410 std::string error; | 410 std::string error; |
| 411 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( | 411 dummy_extension_ = ExtensionInstallPrompt::GetLocalizedExtensionForDisplay( |
| 412 parsed_manifest_.get(), | 412 parsed_manifest_.get(), |
| 413 Extension::FROM_WEBSTORE, | 413 Extension::FROM_WEBSTORE, |
| 414 id, | 414 id, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 SendResponse(true); | 708 SendResponse(true); |
| 709 } | 709 } |
| 710 | 710 |
| 711 bool GetIsLauncherEnabledFunction::RunImpl() { | 711 bool GetIsLauncherEnabledFunction::RunImpl() { |
| 712 SetResult(Value::CreateBooleanValue(apps::IsAppLauncherEnabled())); | 712 SetResult(Value::CreateBooleanValue(apps::IsAppLauncherEnabled())); |
| 713 SendResponse(true); | 713 SendResponse(true); |
| 714 return true; | 714 return true; |
| 715 } | 715 } |
| 716 | 716 |
| 717 } // namespace extensions | 717 } // namespace extensions |
| OLD | NEW |