| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_webstore_private_api.h" | 5 #include "chrome/browser/extensions/extension_webstore_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const char kNoPreviousBeginInstallError[] = | 50 const char kNoPreviousBeginInstallError[] = |
| 51 "* does not match a previous call to beginInstall"; | 51 "* does not match a previous call to beginInstall"; |
| 52 const char kUserCancelledError[] = "User cancelled install"; | 52 const char kUserCancelledError[] = "User cancelled install"; |
| 53 const char kUserGestureRequiredError[] = | 53 const char kUserGestureRequiredError[] = |
| 54 "This function must be called during a user gesture"; | 54 "This function must be called during a user gesture"; |
| 55 | 55 |
| 56 ProfileSyncService* test_sync_service = NULL; | 56 ProfileSyncService* test_sync_service = NULL; |
| 57 BrowserSignin* test_signin = NULL; | 57 BrowserSignin* test_signin = NULL; |
| 58 bool ignore_user_gesture_for_tests = false; | 58 bool ignore_user_gesture_for_tests = false; |
| 59 | 59 |
| 60 // A flag used for BeginInstallWithManifest::SetAutoConfirmForTests. | |
| 61 enum AutoConfirmForTest { | |
| 62 DO_NOT_SKIP = 0, | |
| 63 PROCEED, | |
| 64 ABORT | |
| 65 }; | |
| 66 AutoConfirmForTest auto_confirm_for_tests = DO_NOT_SKIP; | |
| 67 | |
| 68 | |
| 69 // Returns either the test sync service, or the real one from |profile|. | 60 // Returns either the test sync service, or the real one from |profile|. |
| 70 ProfileSyncService* GetSyncService(Profile* profile) { | 61 ProfileSyncService* GetSyncService(Profile* profile) { |
| 71 if (test_sync_service) | 62 if (test_sync_service) |
| 72 return test_sync_service; | 63 return test_sync_service; |
| 73 else | 64 else |
| 74 return profile->GetProfileSyncService(); | 65 return profile->GetProfileSyncService(); |
| 75 } | 66 } |
| 76 | 67 |
| 77 BrowserSignin* GetBrowserSignin(Profile* profile) { | 68 BrowserSignin* GetBrowserSignin(Profile* profile) { |
| 78 if (test_signin) | 69 if (test_signin) |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 CHECK(false); | 254 CHECK(false); |
| 264 } | 255 } |
| 265 } | 256 } |
| 266 | 257 |
| 267 // static | 258 // static |
| 268 void BeginInstallWithManifestFunction::SetIgnoreUserGestureForTests( | 259 void BeginInstallWithManifestFunction::SetIgnoreUserGestureForTests( |
| 269 bool ignore) { | 260 bool ignore) { |
| 270 ignore_user_gesture_for_tests = ignore; | 261 ignore_user_gesture_for_tests = ignore; |
| 271 } | 262 } |
| 272 | 263 |
| 273 void BeginInstallWithManifestFunction::SetAutoConfirmForTests( | |
| 274 bool should_proceed) { | |
| 275 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; | |
| 276 } | |
| 277 | |
| 278 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( | 264 void BeginInstallWithManifestFunction::OnWebstoreParseSuccess( |
| 279 const SkBitmap& icon, DictionaryValue* parsed_manifest) { | 265 const SkBitmap& icon, DictionaryValue* parsed_manifest) { |
| 280 CHECK(parsed_manifest); | 266 CHECK(parsed_manifest); |
| 281 icon_ = icon; | 267 icon_ = icon; |
| 282 parsed_manifest_.reset(parsed_manifest); | 268 parsed_manifest_.reset(parsed_manifest); |
| 283 | 269 |
| 284 // If we were passed a localized name to use in the dialog, create a copy | 270 ShowExtensionInstallDialogForManifest( |
| 285 // of the original manifest and replace the name in it. | 271 profile(), |
| 286 scoped_ptr<DictionaryValue> localized_manifest; | 272 this, |
| 287 if (!localized_name_.empty()) { | 273 parsed_manifest, |
| 288 localized_manifest.reset(parsed_manifest->DeepCopy()); | |
| 289 localized_manifest->SetString(extension_manifest_keys::kName, | |
| 290 localized_name_); | |
| 291 } | |
| 292 | |
| 293 // Create a dummy extension and show the extension install confirmation | |
| 294 // dialog. | |
| 295 std::string init_errors; | |
| 296 dummy_extension_ = Extension::CreateWithId( | |
| 297 FilePath(), | |
| 298 Extension::INTERNAL, | |
| 299 localized_manifest.get() ? *localized_manifest.get() : *parsed_manifest, | |
| 300 Extension::NO_FLAGS, | |
| 301 id_, | 274 id_, |
| 302 &init_errors); | 275 localized_name_, |
| 276 &icon_, |
| 277 ExtensionInstallUI::INSTALL_PROMPT, |
| 278 &dummy_extension_); |
| 303 if (!dummy_extension_.get()) { | 279 if (!dummy_extension_.get()) { |
| 304 OnWebstoreParseFailure(WebstoreInstallHelper::Delegate::MANIFEST_ERROR, | 280 OnWebstoreParseFailure(WebstoreInstallHelper::Delegate::MANIFEST_ERROR, |
| 305 kInvalidManifestError); | 281 kInvalidManifestError); |
| 306 return; | 282 return; |
| 307 } | 283 } |
| 308 | 284 |
| 309 if (icon_.empty()) | |
| 310 icon_ = Extension::GetDefaultIcon(dummy_extension_->is_app()); | |
| 311 | |
| 312 // In tests, we may have setup to proceed or abort without putting up the real | |
| 313 // confirmation dialog. | |
| 314 if (auto_confirm_for_tests != DO_NOT_SKIP) { | |
| 315 if (auto_confirm_for_tests == PROCEED) | |
| 316 this->InstallUIProceed(); | |
| 317 else | |
| 318 this->InstallUIAbort(true); | |
| 319 return; | |
| 320 } | |
| 321 | |
| 322 ShowExtensionInstallDialog(profile(), | |
| 323 this, | |
| 324 dummy_extension_.get(), | |
| 325 &icon_, | |
| 326 dummy_extension_->GetPermissionMessageStrings(), | |
| 327 ExtensionInstallUI::INSTALL_PROMPT); | |
| 328 | |
| 329 // Control flow finishes up in InstallUIProceed or InstallUIAbort. | 285 // Control flow finishes up in InstallUIProceed or InstallUIAbort. |
| 330 } | 286 } |
| 331 | 287 |
| 332 void BeginInstallWithManifestFunction::OnWebstoreParseFailure( | 288 void BeginInstallWithManifestFunction::OnWebstoreParseFailure( |
| 333 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, | 289 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, |
| 334 const std::string& error_message) { | 290 const std::string& error_message) { |
| 335 // Map from WebstoreInstallHelper's result codes to ours. | 291 // Map from WebstoreInstallHelper's result codes to ours. |
| 336 switch (result_code) { | 292 switch (result_code) { |
| 337 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: | 293 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: |
| 338 SetResult(UNKNOWN_ERROR); | 294 SetResult(UNKNOWN_ERROR); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 525 } |
| 570 | 526 |
| 571 DCHECK(waiting_for_token_); | 527 DCHECK(waiting_for_token_); |
| 572 | 528 |
| 573 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); | 529 result_.reset(CreateLoginResult(profile_->GetOriginalProfile())); |
| 574 SendResponse(true); | 530 SendResponse(true); |
| 575 | 531 |
| 576 // Matches the AddRef in RunImpl(). | 532 // Matches the AddRef in RunImpl(). |
| 577 Release(); | 533 Release(); |
| 578 } | 534 } |
| OLD | NEW |