Chromium Code Reviews| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/extensions/crx_installer.h" | 14 #include "chrome/browser/extensions/crx_installer.h" |
| 15 #include "chrome/browser/extensions/extension_install_dialog.h" | 15 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/net/gaia/token_service.h" | 18 #include "chrome/browser/net/gaia/token_service.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/extensions/extension_error_utils.h" | 23 #include "chrome/common/extensions/extension_error_utils.h" |
| 24 #include "chrome/common/extensions/extension_l10n_util.h" | |
| 24 #include "chrome/common/net/gaia/gaia_constants.h" | 25 #include "chrome/common/net/gaia/gaia_constants.h" |
| 25 #include "content/browser/tab_contents/tab_contents.h" | 26 #include "content/browser/tab_contents/tab_contents.h" |
| 26 #include "content/common/notification_details.h" | 27 #include "content/common/notification_details.h" |
| 27 #include "content/common/notification_source.h" | 28 #include "content/common/notification_source.h" |
| 28 #include "content/common/notification_type.h" | 29 #include "content/common/notification_type.h" |
| 29 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 37 const char kIconDataKey[] = "iconData"; | |
| 38 const char kIdKey[] = "id"; | |
| 39 const char kLocalizedNameKey[] = "localizedName"; | |
| 36 const char kLoginKey[] = "login"; | 40 const char kLoginKey[] = "login"; |
| 41 const char kManifestKey[] = "manifest"; | |
| 37 const char kTokenKey[] = "token"; | 42 const char kTokenKey[] = "token"; |
| 43 | |
| 38 const char kImageDecodeError[] = "Image decode failed"; | 44 const char kImageDecodeError[] = "Image decode failed"; |
| 39 const char kInvalidIdError[] = "Invalid id"; | 45 const char kInvalidIdError[] = "Invalid id"; |
| 40 const char kInvalidManifestError[] = "Invalid manifest"; | 46 const char kInvalidManifestError[] = "Invalid manifest"; |
| 41 const char kNoPreviousBeginInstallError[] = | 47 const char kNoPreviousBeginInstallError[] = |
| 42 "* does not match a previous call to beginInstall"; | 48 "* does not match a previous call to beginInstall"; |
| 43 const char kUserCancelledError[] = "User cancelled install"; | 49 const char kUserCancelledError[] = "User cancelled install"; |
| 44 const char kUserGestureRequiredError[] = | 50 const char kUserGestureRequiredError[] = |
| 45 "This function must be called during a user gesture"; | 51 "This function must be called during a user gesture"; |
| 46 | 52 |
| 47 ProfileSyncService* test_sync_service = NULL; | 53 ProfileSyncService* test_sync_service = NULL; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 SetResult(PERMISSION_DENIED); | 291 SetResult(PERMISSION_DENIED); |
| 286 return false; | 292 return false; |
| 287 } | 293 } |
| 288 | 294 |
| 289 if (!user_gesture() && !ignore_user_gesture_for_tests) { | 295 if (!user_gesture() && !ignore_user_gesture_for_tests) { |
| 290 SetResult(NO_GESTURE); | 296 SetResult(NO_GESTURE); |
| 291 error_ = kUserGestureRequiredError; | 297 error_ = kUserGestureRequiredError; |
| 292 return false; | 298 return false; |
| 293 } | 299 } |
| 294 | 300 |
| 295 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_)); | 301 DictionaryValue* details = NULL; |
| 302 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | |
| 303 CHECK(details); | |
| 304 | |
| 305 // Read the id. | |
|
Matt Perry
2011/05/25 01:46:06
these comments can go - the code is self explanato
asargent_no_longer_on_chrome
2011/05/25 04:42:00
Done.
| |
| 306 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIdKey, &id_)); | |
| 296 if (!Extension::IdIsValid(id_)) { | 307 if (!Extension::IdIsValid(id_)) { |
| 297 SetResult(INVALID_ID); | 308 SetResult(INVALID_ID); |
| 298 error_ = kInvalidIdError; | 309 error_ = kInvalidIdError; |
| 299 return false; | 310 return false; |
| 300 } | 311 } |
| 301 | 312 |
| 302 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &icon_data_)); | 313 // Read the manifest. |
| 303 EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &manifest_)); | 314 EXTENSION_FUNCTION_VALIDATE(details->GetString(kManifestKey, &manifest_)); |
| 315 | |
| 316 // Read the icon data. | |
| 317 if (details->HasKey(kIconDataKey)) | |
| 318 EXTENSION_FUNCTION_VALIDATE(details->GetString(kIconDataKey, &icon_data_)); | |
| 319 | |
| 320 // Read the localized name. | |
| 321 if (details->HasKey(kLocalizedNameKey)) | |
| 322 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLocalizedNameKey, | |
| 323 &localized_name_)); | |
| 304 | 324 |
| 305 scoped_refptr<SafeBeginInstallHelper> helper = | 325 scoped_refptr<SafeBeginInstallHelper> helper = |
| 306 new SafeBeginInstallHelper(this, icon_data_, manifest_); | 326 new SafeBeginInstallHelper(this, icon_data_, manifest_); |
| 307 // The helper will call us back via OnParseSucces or OnParseFailure. | 327 // The helper will call us back via OnParseSucces or OnParseFailure. |
| 308 helper->Start(); | 328 helper->Start(); |
| 309 | 329 |
| 310 // Matched with a Release in OnSuccess/OnFailure. | 330 // Matched with a Release in OnSuccess/OnFailure. |
| 311 AddRef(); | 331 AddRef(); |
| 312 | 332 |
| 313 // The response is sent asynchronously in OnSuccess/OnFailure. | 333 // The response is sent asynchronously in OnSuccess/OnFailure. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 bool should_proceed) { | 376 bool should_proceed) { |
| 357 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; | 377 auto_confirm_for_tests = should_proceed ? PROCEED : ABORT; |
| 358 } | 378 } |
| 359 | 379 |
| 360 void BeginInstallWithManifestFunction::OnParseSuccess( | 380 void BeginInstallWithManifestFunction::OnParseSuccess( |
| 361 const SkBitmap& icon, DictionaryValue* parsed_manifest) { | 381 const SkBitmap& icon, DictionaryValue* parsed_manifest) { |
| 362 CHECK(parsed_manifest); | 382 CHECK(parsed_manifest); |
| 363 icon_ = icon; | 383 icon_ = icon; |
| 364 parsed_manifest_.reset(parsed_manifest); | 384 parsed_manifest_.reset(parsed_manifest); |
| 365 | 385 |
| 386 // If we were passed a localized name to use in the dialog, temporarily | |
| 387 // replace the name in |parsed_manifest| with it. | |
| 388 std::string original_name; | |
| 389 if (!localized_name_.empty()) { | |
| 390 if (!parsed_manifest->GetString(extension_manifest_keys::kName, | |
| 391 &original_name)) { | |
| 392 OnParseFailure(MANIFEST_ERROR, std::string(kInvalidManifestError)); | |
| 393 return; | |
| 394 } | |
| 395 parsed_manifest->SetString(extension_manifest_keys::kName, localized_name_); | |
| 396 } | |
| 397 | |
| 366 // Create a dummy extension and show the extension install confirmation | 398 // Create a dummy extension and show the extension install confirmation |
| 367 // dialog. | 399 // dialog. |
| 368 std::string init_errors; | 400 std::string init_errors; |
| 369 dummy_extension_ = Extension::Create( | 401 dummy_extension_ = Extension::Create( |
| 370 FilePath(), | 402 FilePath(), |
| 371 Extension::INTERNAL, | 403 Extension::INTERNAL, |
| 372 *static_cast<DictionaryValue*>(parsed_manifest_.get()), | 404 *static_cast<DictionaryValue*>(parsed_manifest_.get()), |
| 373 Extension::NO_FLAGS, | 405 Extension::NO_FLAGS, |
| 374 &init_errors); | 406 &init_errors); |
| 375 if (!dummy_extension_.get()) { | 407 if (!dummy_extension_.get()) { |
| 376 OnParseFailure(MANIFEST_ERROR, std::string(kInvalidManifestError)); | 408 OnParseFailure(MANIFEST_ERROR, std::string(kInvalidManifestError)); |
| 377 return; | 409 return; |
| 378 } | 410 } |
| 411 | |
| 412 // Restore the original name in |parsed_manifest| if we replaced it with a | |
| 413 // localized one, so that the whitelist entry will have the right value for | |
| 414 // comparison against the actual downloaded crx file's manifest. | |
| 415 if (!original_name.empty()) | |
| 416 parsed_manifest_->SetString(extension_manifest_keys::kName, original_name); | |
|
Matt Perry
2011/05/25 01:46:06
This restoring feels a little dirty. How about ins
asargent_no_longer_on_chrome
2011/05/25 04:42:00
Done.
| |
| 417 | |
| 379 if (icon_.empty()) | 418 if (icon_.empty()) |
| 380 icon_ = Extension::GetDefaultIcon(dummy_extension_->is_app()); | 419 icon_ = Extension::GetDefaultIcon(dummy_extension_->is_app()); |
| 381 | 420 |
| 382 // In tests, we may have setup to proceed or abort without putting up the real | 421 // In tests, we may have setup to proceed or abort without putting up the real |
| 383 // confirmation dialog. | 422 // confirmation dialog. |
| 384 if (auto_confirm_for_tests != DO_NOT_SKIP) { | 423 if (auto_confirm_for_tests != DO_NOT_SKIP) { |
| 385 if (auto_confirm_for_tests == PROCEED) | 424 if (auto_confirm_for_tests == PROCEED) |
| 386 this->InstallUIProceed(); | 425 this->InstallUIProceed(); |
| 387 else | 426 else |
| 388 this->InstallUIAbort(); | 427 this->InstallUIAbort(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 403 ResultCode result_code, const std::string& error_message) { | 442 ResultCode result_code, const std::string& error_message) { |
| 404 SetResult(result_code); | 443 SetResult(result_code); |
| 405 error_ = error_message; | 444 error_ = error_message; |
| 406 SendResponse(false); | 445 SendResponse(false); |
| 407 | 446 |
| 408 // Matches the AddRef in RunImpl(). | 447 // Matches the AddRef in RunImpl(). |
| 409 Release(); | 448 Release(); |
| 410 } | 449 } |
| 411 | 450 |
| 412 void BeginInstallWithManifestFunction::InstallUIProceed() { | 451 void BeginInstallWithManifestFunction::InstallUIProceed() { |
| 413 CrxInstaller::SetWhitelistedManifest(id_, parsed_manifest_.release()); | 452 CrxInstaller::WhitelistEntry* entry = new CrxInstaller::WhitelistEntry; |
| 453 entry->parsed_manifest.reset(parsed_manifest_.release()); | |
| 454 entry->localized_name = localized_name_; | |
| 455 CrxInstaller::SetWhitelistEntry(id_, entry); | |
| 414 SetResult(ERROR_NONE); | 456 SetResult(ERROR_NONE); |
| 415 SendResponse(true); | 457 SendResponse(true); |
| 416 | 458 |
| 417 // Matches the AddRef in RunImpl(). | 459 // Matches the AddRef in RunImpl(). |
| 418 Release(); | 460 Release(); |
| 419 } | 461 } |
| 420 | 462 |
| 421 void BeginInstallWithManifestFunction::InstallUIAbort() { | 463 void BeginInstallWithManifestFunction::InstallUIAbort() { |
| 422 error_ = std::string(kUserCancelledError); | 464 error_ = std::string(kUserCancelledError); |
| 423 SetResult(USER_CANCELLED); | 465 SetResult(USER_CANCELLED); |
| 424 SendResponse(false); | 466 SendResponse(false); |
| 425 | 467 |
| 426 // Matches the AddRef in RunImpl(). | 468 // Matches the AddRef in RunImpl(). |
| 427 Release(); | 469 Release(); |
| 428 } | 470 } |
| 429 | 471 |
| 430 bool CompleteInstallFunction::RunImpl() { | 472 bool CompleteInstallFunction::RunImpl() { |
| 431 if (!IsWebStoreURL(profile_, source_url())) | 473 if (!IsWebStoreURL(profile_, source_url())) |
| 432 return false; | 474 return false; |
| 433 | 475 |
| 434 std::string id; | 476 std::string id; |
| 435 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); | 477 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id)); |
| 436 if (!Extension::IdIsValid(id)) { | 478 if (!Extension::IdIsValid(id)) { |
| 437 error_ = kInvalidIdError; | 479 error_ = kInvalidIdError; |
| 438 return false; | 480 return false; |
| 439 } | 481 } |
| 440 | 482 |
| 441 if (!CrxInstaller::IsIdWhitelisted(id) && | 483 if (!CrxInstaller::IsIdWhitelisted(id) && |
| 442 !CrxInstaller::GetWhitelistedManifest(id)) { | 484 !CrxInstaller::GetWhitelistEntry(id)) { |
| 443 error_ = ExtensionErrorUtils::FormatErrorMessage( | 485 error_ = ExtensionErrorUtils::FormatErrorMessage( |
| 444 kNoPreviousBeginInstallError, id); | 486 kNoPreviousBeginInstallError, id); |
| 445 return false; | 487 return false; |
| 446 } | 488 } |
| 447 | 489 |
| 448 std::vector<std::string> params; | 490 std::vector<std::string> params; |
| 449 params.push_back("id=" + id); | 491 params.push_back("id=" + id); |
| 450 params.push_back("lang=" + g_browser_process->GetApplicationLocale()); | 492 params.push_back("lang=" + g_browser_process->GetApplicationLocale()); |
| 451 params.push_back("uc"); | 493 params.push_back("uc"); |
| 452 std::string url_string = Extension::GalleryUpdateUrl(true).spec(); | 494 std::string url_string = Extension::GalleryUpdateUrl(true).spec(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 } | 649 } |
| 608 | 650 |
| 609 DCHECK(waiting_for_token_); | 651 DCHECK(waiting_for_token_); |
| 610 | 652 |
| 611 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); | 653 result_.reset(CreateLoginResult(GetDefaultProfile(profile_))); |
| 612 SendResponse(true); | 654 SendResponse(true); |
| 613 | 655 |
| 614 // Matches the AddRef in RunImpl(). | 656 // Matches the AddRef in RunImpl(). |
| 615 Release(); | 657 Release(); |
| 616 } | 658 } |
| OLD | NEW |