| 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/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/permissions_updater.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" |
| 25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
| 28 #include "extensions/browser/extension_util.h" | 29 #include "extensions/browser/extension_util.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 166 |
| 166 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { | 167 gfx::NativeWindow NativeWindowForWebContents(content::WebContents* contents) { |
| 167 if (!contents) | 168 if (!contents) |
| 168 return NULL; | 169 return NULL; |
| 169 | 170 |
| 170 return contents->GetTopLevelNativeWindow(); | 171 return contents->GetTopLevelNativeWindow(); |
| 171 } | 172 } |
| 172 | 173 |
| 173 } // namespace | 174 } // namespace |
| 174 | 175 |
| 176 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 177 InstallPromptPermissions() { |
| 178 } |
| 179 ExtensionInstallPrompt::Prompt::InstallPromptPermissions:: |
| 180 ~InstallPromptPermissions() { |
| 181 } |
| 182 |
| 175 // static | 183 // static |
| 176 ExtensionInstallPrompt::AutoConfirmForTests | 184 ExtensionInstallPrompt::AutoConfirmForTests |
| 177 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; | 185 ExtensionInstallPrompt::g_auto_confirm_for_tests = ExtensionInstallPrompt::NONE; |
| 178 | 186 |
| 179 // This should match the PromptType enum. | 187 // This should match the PromptType enum. |
| 180 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { | 188 std::string ExtensionInstallPrompt::PromptTypeToString(PromptType type) { |
| 181 switch (type) { | 189 switch (type) { |
| 182 case ExtensionInstallPrompt::INSTALL_PROMPT: | 190 case ExtensionInstallPrompt::INSTALL_PROMPT: |
| 183 return "INSTALL_PROMPT"; | 191 return "INSTALL_PROMPT"; |
| 184 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: | 192 case ExtensionInstallPrompt::INLINE_INSTALL_PROMPT: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 212 average_rating_(0.0), | 220 average_rating_(0.0), |
| 213 rating_count_(0), | 221 rating_count_(0), |
| 214 show_user_count_(false), | 222 show_user_count_(false), |
| 215 has_webstore_data_(false) { | 223 has_webstore_data_(false) { |
| 216 } | 224 } |
| 217 | 225 |
| 218 ExtensionInstallPrompt::Prompt::~Prompt() { | 226 ExtensionInstallPrompt::Prompt::~Prompt() { |
| 219 } | 227 } |
| 220 | 228 |
| 221 void ExtensionInstallPrompt::Prompt::SetPermissions( | 229 void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 222 const std::vector<base::string16>& permissions) { | 230 const std::vector<base::string16>& permissions, |
| 223 permissions_ = permissions; | 231 PermissionsType permissions_type) { |
| 232 GetPermissionsForType(permissions_type).permissions = permissions; |
| 224 } | 233 } |
| 225 | 234 |
| 226 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( | 235 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
| 227 const std::vector<base::string16>& details) { | 236 const std::vector<base::string16>& details, |
| 228 details_ = details; | 237 PermissionsType permissions_type) { |
| 229 is_showing_details_for_permissions_.clear(); | 238 InstallPromptPermissions& install_permissions = |
| 230 for (size_t i = 0; i < details.size(); ++i) | 239 GetPermissionsForType(permissions_type); |
| 231 is_showing_details_for_permissions_.push_back(false); | 240 install_permissions.details = details; |
| 241 install_permissions.is_showing_details.clear(); |
| 242 install_permissions.is_showing_details.insert( |
| 243 install_permissions.is_showing_details.begin(), details.size(), false); |
| 232 } | 244 } |
| 233 | 245 |
| 234 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( | 246 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 235 DetailsType type, | 247 DetailsType type, |
| 236 size_t index, | 248 size_t index, |
| 237 bool is_showing_details) { | 249 bool is_showing_details) { |
| 238 switch (type) { | 250 switch (type) { |
| 239 case PERMISSIONS_DETAILS: | 251 case PERMISSIONS_DETAILS: |
| 240 is_showing_details_for_permissions_[index] = is_showing_details; | 252 prompt_permissions_.is_showing_details[index] = is_showing_details; |
| 253 break; |
| 254 case WITHHELD_PERMISSIONS_DETAILS: |
| 255 withheld_prompt_permissions_.is_showing_details[index] = |
| 256 is_showing_details; |
| 241 break; | 257 break; |
| 242 case RETAINED_FILES_DETAILS: | 258 case RETAINED_FILES_DETAILS: |
| 243 is_showing_details_for_retained_files_ = is_showing_details; | 259 is_showing_details_for_retained_files_ = is_showing_details; |
| 244 break; | 260 break; |
| 245 } | 261 } |
| 246 } | 262 } |
| 247 | 263 |
| 248 void ExtensionInstallPrompt::Prompt::SetWebstoreData( | 264 void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
| 249 const std::string& localized_user_count, | 265 const std::string& localized_user_count, |
| 250 bool show_user_count, | 266 bool show_user_count, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 return kAbortButtonIds[type_] > 0; | 363 return kAbortButtonIds[type_] > 0; |
| 348 } | 364 } |
| 349 | 365 |
| 350 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { | 366 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
| 351 CHECK(HasAbortButtonLabel()); | 367 CHECK(HasAbortButtonLabel()); |
| 352 if (ShouldShowExplanationText()) | 368 if (ShouldShowExplanationText()) |
| 353 return experiment_->GetCancelButtonText(); | 369 return experiment_->GetCancelButtonText(); |
| 354 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); | 370 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); |
| 355 } | 371 } |
| 356 | 372 |
| 357 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { | 373 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading( |
| 358 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); | 374 PermissionsType permissions_type) const { |
| 375 switch (permissions_type) { |
| 376 case REGULAR_PERMISSIONS: |
| 377 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); |
| 378 case WITHHELD_PERMISSIONS: |
| 379 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WITHHELD); |
| 380 case ALL_PERMISSIONS: |
| 381 NOTREACHED(); |
| 382 return base::string16(); |
| 383 } |
| 359 } | 384 } |
| 360 | 385 |
| 361 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { | 386 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
| 362 const int kRetainedFilesMessageIDs[6] = { | 387 const int kRetainedFilesMessageIDs[6] = { |
| 363 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, | 388 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
| 364 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, | 389 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
| 365 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, | 390 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
| 366 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, | 391 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
| 367 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, | 392 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
| 368 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, | 393 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
| 369 }; | 394 }; |
| 370 std::vector<int> message_ids; | 395 std::vector<int> message_ids; |
| 371 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { | 396 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { |
| 372 message_ids.push_back(kRetainedFilesMessageIDs[i]); | 397 message_ids.push_back(kRetainedFilesMessageIDs[i]); |
| 373 } | 398 } |
| 374 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); | 399 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
| 375 } | 400 } |
| 376 | 401 |
| 377 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { | 402 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
| 378 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; | 403 return GetPermissionCount(ALL_PERMISSIONS) > 0 || |
| 404 type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
| 379 } | 405 } |
| 380 | 406 |
| 381 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 407 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 382 StarAppender appender, void* data) const { | 408 StarAppender appender, void* data) const { |
| 383 CHECK(appender); | 409 CHECK(appender); |
| 384 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 410 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 385 int rating_integer = floor(average_rating_); | 411 int rating_integer = floor(average_rating_); |
| 386 double rating_fractional = average_rating_ - rating_integer; | 412 double rating_fractional = average_rating_ - rating_integer; |
| 387 | 413 |
| 388 if (rating_fractional > 0.66) { | 414 if (rating_fractional > 0.66) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 416 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { | 442 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
| 417 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 443 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 418 | 444 |
| 419 if (show_user_count_) { | 445 if (show_user_count_) { |
| 420 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, | 446 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 421 base::UTF8ToUTF16(localized_user_count_)); | 447 base::UTF8ToUTF16(localized_user_count_)); |
| 422 } | 448 } |
| 423 return base::string16(); | 449 return base::string16(); |
| 424 } | 450 } |
| 425 | 451 |
| 426 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { | 452 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount( |
| 427 return permissions_.size(); | 453 PermissionsType permissions_type) const { |
| 454 switch (permissions_type) { |
| 455 case REGULAR_PERMISSIONS: |
| 456 return prompt_permissions_.permissions.size(); |
| 457 case WITHHELD_PERMISSIONS: |
| 458 return withheld_prompt_permissions_.permissions.size(); |
| 459 case ALL_PERMISSIONS: |
| 460 return prompt_permissions_.permissions.size() + |
| 461 withheld_prompt_permissions_.permissions.size(); |
| 462 } |
| 428 } | 463 } |
| 429 | 464 |
| 430 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { | 465 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount( |
| 431 return details_.size(); | 466 PermissionsType permissions_type) const { |
| 467 switch (permissions_type) { |
| 468 case REGULAR_PERMISSIONS: |
| 469 return prompt_permissions_.details.size(); |
| 470 case WITHHELD_PERMISSIONS: |
| 471 return withheld_prompt_permissions_.details.size(); |
| 472 case ALL_PERMISSIONS: |
| 473 return prompt_permissions_.details.size() + |
| 474 withheld_prompt_permissions_.details.size(); |
| 475 } |
| 432 } | 476 } |
| 433 | 477 |
| 434 base::string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) | 478 base::string16 ExtensionInstallPrompt::Prompt::GetPermission( |
| 435 const { | 479 size_t index, |
| 436 CHECK_LT(index, permissions_.size()); | 480 PermissionsType permissions_type) const { |
| 437 return permissions_[index]; | 481 const InstallPromptPermissions& install_permissions = |
| 482 GetPermissionsForType(permissions_type); |
| 483 CHECK_LT(index, install_permissions.permissions.size()); |
| 484 return install_permissions.permissions[index]; |
| 438 } | 485 } |
| 439 | 486 |
| 440 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( | 487 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
| 441 size_t index) const { | 488 size_t index, |
| 442 CHECK_LT(index, details_.size()); | 489 PermissionsType permissions_type) const { |
| 443 return details_[index]; | 490 const InstallPromptPermissions& install_permissions = |
| 491 GetPermissionsForType(permissions_type); |
| 492 CHECK_LT(index, install_permissions.details.size()); |
| 493 return install_permissions.details[index]; |
| 444 } | 494 } |
| 445 | 495 |
| 446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( | 496 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 447 DetailsType type, size_t index) const { | 497 DetailsType type, size_t index) const { |
| 448 switch (type) { | 498 switch (type) { |
| 449 case PERMISSIONS_DETAILS: | 499 case PERMISSIONS_DETAILS: |
| 450 CHECK_LT(index, is_showing_details_for_permissions_.size()); | 500 CHECK_LT(index, prompt_permissions_.is_showing_details.size()); |
| 451 return is_showing_details_for_permissions_[index]; | 501 return prompt_permissions_.is_showing_details[index]; |
| 502 case WITHHELD_PERMISSIONS_DETAILS: |
| 503 CHECK_LT(index, withheld_prompt_permissions_.is_showing_details.size()); |
| 504 return withheld_prompt_permissions_.is_showing_details[index]; |
| 452 case RETAINED_FILES_DETAILS: | 505 case RETAINED_FILES_DETAILS: |
| 453 return is_showing_details_for_retained_files_; | 506 return is_showing_details_for_retained_files_; |
| 454 } | 507 } |
| 455 return false; | 508 return false; |
| 456 } | 509 } |
| 457 | 510 |
| 458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { | 511 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 459 return retained_files_.size(); | 512 return retained_files_.size(); |
| 460 } | 513 } |
| 461 | 514 |
| 462 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) | 515 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) |
| 463 const { | 516 const { |
| 464 CHECK_LT(index, retained_files_.size()); | 517 CHECK_LT(index, retained_files_.size()); |
| 465 return retained_files_[index].AsUTF16Unsafe(); | 518 return retained_files_[index].AsUTF16Unsafe(); |
| 466 } | 519 } |
| 467 | 520 |
| 521 ExtensionInstallPrompt::Prompt::InstallPromptPermissions& |
| 522 ExtensionInstallPrompt::Prompt::GetPermissionsForType( |
| 523 PermissionsType permissions_type) { |
| 524 DCHECK_NE(ALL_PERMISSIONS, permissions_type); |
| 525 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ |
| 526 : withheld_prompt_permissions_; |
| 527 } |
| 528 |
| 529 const ExtensionInstallPrompt::Prompt::InstallPromptPermissions& |
| 530 ExtensionInstallPrompt::Prompt::GetPermissionsForType( |
| 531 PermissionsType permissions_type) const { |
| 532 DCHECK_NE(ALL_PERMISSIONS, permissions_type); |
| 533 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ |
| 534 : withheld_prompt_permissions_; |
| 535 } |
| 536 |
| 468 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { | 537 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { |
| 469 return !retained_files_.empty(); | 538 return !retained_files_.empty(); |
| 470 } | 539 } |
| 471 | 540 |
| 472 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) | 541 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) |
| 473 : parent_web_contents(contents), | 542 : parent_web_contents(contents), |
| 474 parent_window(NativeWindowForWebContents(contents)), | 543 parent_window(NativeWindowForWebContents(contents)), |
| 475 navigator(contents) { | 544 navigator(contents) { |
| 476 } | 545 } |
| 477 | 546 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 605 } |
| 537 | 606 |
| 538 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 607 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 539 } | 608 } |
| 540 | 609 |
| 541 void ExtensionInstallPrompt::ConfirmBundleInstall( | 610 void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 542 extensions::BundleInstaller* bundle, | 611 extensions::BundleInstaller* bundle, |
| 543 const PermissionSet* permissions) { | 612 const PermissionSet* permissions) { |
| 544 DCHECK(ui_loop_ == base::MessageLoop::current()); | 613 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 545 bundle_ = bundle; | 614 bundle_ = bundle; |
| 546 permissions_ = permissions; | 615 custom_permissions_ = permissions; |
| 547 delegate_ = bundle; | 616 delegate_ = bundle; |
| 548 prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT); | 617 prompt_ = new Prompt(BUNDLE_INSTALL_PROMPT); |
| 549 | 618 |
| 550 ShowConfirmation(); | 619 ShowConfirmation(); |
| 551 } | 620 } |
| 552 | 621 |
| 553 void ExtensionInstallPrompt::ConfirmStandaloneInstall( | 622 void ExtensionInstallPrompt::ConfirmStandaloneInstall( |
| 554 Delegate* delegate, | 623 Delegate* delegate, |
| 555 const Extension* extension, | 624 const Extension* extension, |
| 556 SkBitmap* icon, | 625 SkBitmap* icon, |
| 557 scoped_refptr<Prompt> prompt) { | 626 scoped_refptr<Prompt> prompt) { |
| 558 DCHECK(ui_loop_ == base::MessageLoop::current()); | 627 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 559 extension_ = extension; | 628 extension_ = extension; |
| 560 permissions_ = extension->permissions_data()->active_permissions(); | |
| 561 delegate_ = delegate; | 629 delegate_ = delegate; |
| 562 prompt_ = prompt; | 630 prompt_ = prompt; |
| 563 | 631 |
| 564 SetIcon(icon); | 632 SetIcon(icon); |
| 565 ShowConfirmation(); | 633 ShowConfirmation(); |
| 566 } | 634 } |
| 567 | 635 |
| 568 void ExtensionInstallPrompt::ConfirmWebstoreInstall( | 636 void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
| 569 Delegate* delegate, | 637 Delegate* delegate, |
| 570 const Extension* extension, | 638 const Extension* extension, |
| 571 const SkBitmap* icon, | 639 const SkBitmap* icon, |
| 572 const ShowDialogCallback& show_dialog_callback) { | 640 const ShowDialogCallback& show_dialog_callback) { |
| 573 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the | 641 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
| 574 // remaining fields. | 642 // remaining fields. |
| 575 extension_ = extension; | 643 extension_ = extension; |
| 576 SetIcon(icon); | 644 SetIcon(icon); |
| 577 ConfirmInstall(delegate, extension, show_dialog_callback); | 645 ConfirmInstall(delegate, extension, show_dialog_callback); |
| 578 } | 646 } |
| 579 | 647 |
| 580 void ExtensionInstallPrompt::ConfirmInstall( | 648 void ExtensionInstallPrompt::ConfirmInstall( |
| 581 Delegate* delegate, | 649 Delegate* delegate, |
| 582 const Extension* extension, | 650 const Extension* extension, |
| 583 const ShowDialogCallback& show_dialog_callback) { | 651 const ShowDialogCallback& show_dialog_callback) { |
| 584 DCHECK(ui_loop_ == base::MessageLoop::current()); | 652 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 585 extension_ = extension; | 653 extension_ = extension; |
| 586 permissions_ = extension->permissions_data()->active_permissions(); | |
| 587 delegate_ = delegate; | 654 delegate_ = delegate; |
| 588 prompt_ = new Prompt(INSTALL_PROMPT); | 655 prompt_ = new Prompt(INSTALL_PROMPT); |
| 589 show_dialog_callback_ = show_dialog_callback; | 656 show_dialog_callback_ = show_dialog_callback; |
| 590 | 657 |
| 591 // We special-case themes to not show any confirm UI. Instead they are | 658 // We special-case themes to not show any confirm UI. Instead they are |
| 592 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 659 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 593 // to allow the user to revert if they don't like it. | 660 // to allow the user to revert if they don't like it. |
| 594 // | 661 // |
| 595 // We don't do this in the case where off-store extension installs are | 662 // We don't do this in the case where off-store extension installs are |
| 596 // disabled because in that case, we don't show the dangerous download UI, so | 663 // disabled because in that case, we don't show the dangerous download UI, so |
| 597 // we need the UI confirmation. | 664 // we need the UI confirmation. |
| 598 if (extension->is_theme()) { | 665 if (extension->is_theme()) { |
| 599 if (extension->from_webstore() || | 666 if (extension->from_webstore() || |
| 600 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { | 667 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { |
| 601 delegate->InstallUIProceed(); | 668 delegate->InstallUIProceed(); |
| 602 return; | 669 return; |
| 603 } | 670 } |
| 604 } | 671 } |
| 605 | 672 |
| 606 LoadImageIfNeeded(); | 673 LoadImageIfNeeded(); |
| 607 } | 674 } |
| 608 | 675 |
| 609 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, | 676 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 610 const Extension* extension) { | 677 const Extension* extension) { |
| 611 DCHECK(ui_loop_ == base::MessageLoop::current()); | 678 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 612 extension_ = extension; | 679 extension_ = extension; |
| 613 permissions_ = extension->permissions_data()->active_permissions(); | |
| 614 delegate_ = delegate; | 680 delegate_ = delegate; |
| 615 bool is_remote_install = | 681 bool is_remote_install = |
| 616 install_ui_->profile() && | 682 install_ui_->profile() && |
| 617 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( | 683 extensions::ExtensionPrefs::Get(install_ui_->profile())->HasDisableReason( |
| 618 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); | 684 extension->id(), extensions::Extension::DISABLE_REMOTE_INSTALL); |
| 619 bool is_ephemeral = | 685 bool is_ephemeral = |
| 620 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); | 686 extensions::util::IsEphemeralApp(extension->id(), install_ui_->profile()); |
| 621 | 687 |
| 622 PromptType type = UNSET_PROMPT_TYPE; | 688 PromptType type = UNSET_PROMPT_TYPE; |
| 623 if (is_ephemeral) | 689 if (is_ephemeral) |
| 624 type = LAUNCH_PROMPT; | 690 type = LAUNCH_PROMPT; |
| 625 else if (is_remote_install) | 691 else if (is_remote_install) |
| 626 type = REMOTE_INSTALL_PROMPT; | 692 type = REMOTE_INSTALL_PROMPT; |
| 627 else | 693 else |
| 628 type = RE_ENABLE_PROMPT; | 694 type = RE_ENABLE_PROMPT; |
| 629 prompt_ = new Prompt(type); | 695 prompt_ = new Prompt(type); |
| 630 | 696 |
| 631 LoadImageIfNeeded(); | 697 LoadImageIfNeeded(); |
| 632 } | 698 } |
| 633 | 699 |
| 634 void ExtensionInstallPrompt::ConfirmExternalInstall( | 700 void ExtensionInstallPrompt::ConfirmExternalInstall( |
| 635 Delegate* delegate, | 701 Delegate* delegate, |
| 636 const Extension* extension, | 702 const Extension* extension, |
| 637 const ShowDialogCallback& show_dialog_callback, | 703 const ShowDialogCallback& show_dialog_callback, |
| 638 scoped_refptr<Prompt> prompt) { | 704 scoped_refptr<Prompt> prompt) { |
| 639 DCHECK(ui_loop_ == base::MessageLoop::current()); | 705 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 640 extension_ = extension; | 706 extension_ = extension; |
| 641 permissions_ = extension->permissions_data()->active_permissions(); | |
| 642 delegate_ = delegate; | 707 delegate_ = delegate; |
| 643 prompt_ = prompt; | 708 prompt_ = prompt; |
| 644 show_dialog_callback_ = show_dialog_callback; | 709 show_dialog_callback_ = show_dialog_callback; |
| 645 | 710 |
| 646 LoadImageIfNeeded(); | 711 LoadImageIfNeeded(); |
| 647 } | 712 } |
| 648 | 713 |
| 649 void ExtensionInstallPrompt::ConfirmPermissions( | 714 void ExtensionInstallPrompt::ConfirmPermissions( |
| 650 Delegate* delegate, | 715 Delegate* delegate, |
| 651 const Extension* extension, | 716 const Extension* extension, |
| 652 const PermissionSet* permissions) { | 717 const PermissionSet* permissions) { |
| 653 DCHECK(ui_loop_ == base::MessageLoop::current()); | 718 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 654 extension_ = extension; | 719 extension_ = extension; |
| 655 permissions_ = permissions; | 720 custom_permissions_ = permissions; |
| 656 delegate_ = delegate; | 721 delegate_ = delegate; |
| 657 prompt_ = new Prompt(PERMISSIONS_PROMPT); | 722 prompt_ = new Prompt(PERMISSIONS_PROMPT); |
| 658 | 723 |
| 659 LoadImageIfNeeded(); | 724 LoadImageIfNeeded(); |
| 660 } | 725 } |
| 661 | 726 |
| 662 void ExtensionInstallPrompt::ReviewPermissions( | 727 void ExtensionInstallPrompt::ReviewPermissions( |
| 663 Delegate* delegate, | 728 Delegate* delegate, |
| 664 const Extension* extension, | 729 const Extension* extension, |
| 665 const std::vector<base::FilePath>& retained_file_paths) { | 730 const std::vector<base::FilePath>& retained_file_paths) { |
| 666 DCHECK(ui_loop_ == base::MessageLoop::current()); | 731 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 667 extension_ = extension; | 732 extension_ = extension; |
| 668 permissions_ = extension->permissions_data()->active_permissions(); | |
| 669 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); | 733 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); |
| 670 prompt_->set_retained_files(retained_file_paths); | 734 prompt_->set_retained_files(retained_file_paths); |
| 671 delegate_ = delegate; | 735 delegate_ = delegate; |
| 672 | 736 |
| 673 LoadImageIfNeeded(); | 737 LoadImageIfNeeded(); |
| 674 } | 738 } |
| 675 | 739 |
| 676 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 740 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
| 677 SkBitmap* icon) { | 741 SkBitmap* icon) { |
| 678 extension_ = extension; | 742 extension_ = extension; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 images_list, | 796 images_list, |
| 733 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); | 797 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
| 734 } | 798 } |
| 735 | 799 |
| 736 void ExtensionInstallPrompt::ShowConfirmation() { | 800 void ExtensionInstallPrompt::ShowConfirmation() { |
| 737 if (prompt_->type() == INSTALL_PROMPT) | 801 if (prompt_->type() == INSTALL_PROMPT) |
| 738 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); | 802 prompt_->set_experiment(ExtensionInstallPromptExperiment::Find()); |
| 739 else | 803 else |
| 740 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 804 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
| 741 | 805 |
| 742 if (permissions_.get() && | 806 scoped_refptr<const PermissionSet> permissions_to_display; |
| 807 if (custom_permissions_.get()) { |
| 808 permissions_to_display = custom_permissions_; |
| 809 } else if (extension_) { |
| 810 // Initialize permissions if they have not already been set so that |
| 811 // withheld permissions are displayed properly in the install prompt. |
| 812 extensions::PermissionsUpdater( |
| 813 install_ui_->profile(), |
| 814 extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT) |
| 815 .InitializePermissions(extension_); |
| 816 permissions_to_display = |
| 817 extension_->permissions_data()->active_permissions(); |
| 818 } |
| 819 |
| 820 if (permissions_to_display.get() && |
| 743 (!extension_ || | 821 (!extension_ || |
| 744 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 822 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 745 extension_->id()))) { | 823 extension_->id()))) { |
| 746 Manifest::Type type = | 824 Manifest::Type type = |
| 747 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; | 825 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 748 const extensions::PermissionMessageProvider* message_provider = | 826 const extensions::PermissionMessageProvider* message_provider = |
| 749 extensions::PermissionMessageProvider::Get(); | 827 extensions::PermissionMessageProvider::Get(); |
| 750 prompt_->SetPermissions( | 828 prompt_->SetPermissions(message_provider->GetWarningMessages( |
| 751 message_provider->GetWarningMessages(permissions_.get(), type)); | 829 permissions_to_display.get(), type), |
| 752 prompt_->SetPermissionsDetails( | 830 REGULAR_PERMISSIONS); |
| 753 message_provider->GetWarningMessagesDetails(permissions_.get(), type)); | 831 prompt_->SetPermissionsDetails(message_provider->GetWarningMessagesDetails( |
| 832 permissions_to_display.get(), type), |
| 833 REGULAR_PERMISSIONS); |
| 834 |
| 835 scoped_refptr<const extensions::PermissionSet> withheld = |
| 836 extension_->permissions_data()->withheld_permissions(); |
| 837 if (!withheld->IsEmpty()) { |
| 838 prompt_->SetPermissions( |
| 839 message_provider->GetWarningMessages(withheld.get(), type), |
| 840 PermissionsType::WITHHELD_PERMISSIONS); |
| 841 prompt_->SetPermissionsDetails( |
| 842 message_provider->GetWarningMessagesDetails(withheld.get(), type), |
| 843 PermissionsType::WITHHELD_PERMISSIONS); |
| 844 } |
| 754 } | 845 } |
| 755 | 846 |
| 756 switch (prompt_->type()) { | 847 switch (prompt_->type()) { |
| 757 case PERMISSIONS_PROMPT: | 848 case PERMISSIONS_PROMPT: |
| 758 case RE_ENABLE_PROMPT: | 849 case RE_ENABLE_PROMPT: |
| 759 case INLINE_INSTALL_PROMPT: | 850 case INLINE_INSTALL_PROMPT: |
| 760 case EXTERNAL_INSTALL_PROMPT: | 851 case EXTERNAL_INSTALL_PROMPT: |
| 761 case INSTALL_PROMPT: | 852 case INSTALL_PROMPT: |
| 762 case LAUNCH_PROMPT: | 853 case LAUNCH_PROMPT: |
| 763 case POST_INSTALL_PERMISSIONS_PROMPT: | 854 case POST_INSTALL_PERMISSIONS_PROMPT: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 776 } | 867 } |
| 777 | 868 |
| 778 if (AutoConfirmPrompt(delegate_)) | 869 if (AutoConfirmPrompt(delegate_)) |
| 779 return; | 870 return; |
| 780 | 871 |
| 781 if (show_dialog_callback_.is_null()) | 872 if (show_dialog_callback_.is_null()) |
| 782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 873 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 783 else | 874 else |
| 784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 875 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 785 } | 876 } |
| OLD | NEW |