Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 211 bundle_(NULL), | 219 bundle_(NULL), |
| 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 |
| 229 ExtensionInstallPrompt::Prompt::InstallPromptPermissions& | |
|
Devlin
2014/09/10 22:00:44
nit: Same order as in the header file (to the exte
gpdavis
2014/09/11 20:09:21
Done.
| |
| 230 ExtensionInstallPrompt::Prompt::GetPermissionsToUse( | |
| 231 PermissionsType permissions_type) { | |
| 232 DCHECK_NE(ALL_PERMISSIONS, permissions_type); | |
| 233 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ : | |
| 234 withheld_prompt_permissions_; | |
| 235 } | |
| 236 | |
| 237 const ExtensionInstallPrompt::Prompt::InstallPromptPermissions& | |
| 238 ExtensionInstallPrompt::Prompt::GetPermissionsToUse( | |
| 239 PermissionsType permissions_type) const { | |
| 240 DCHECK_NE(ALL_PERMISSIONS, permissions_type); | |
| 241 return permissions_type == REGULAR_PERMISSIONS ? prompt_permissions_ : | |
| 242 withheld_prompt_permissions_; | |
| 243 } | |
| 244 | |
| 221 void ExtensionInstallPrompt::Prompt::SetPermissions( | 245 void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 222 const std::vector<base::string16>& permissions) { | 246 const std::vector<base::string16>& permissions, |
| 223 permissions_ = permissions; | 247 PermissionsType permissions_type) { |
| 248 GetPermissionsToUse(permissions_type).permissions = permissions; | |
| 224 } | 249 } |
| 225 | 250 |
| 226 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( | 251 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
| 227 const std::vector<base::string16>& details) { | 252 const std::vector<base::string16>& details, |
| 228 details_ = details; | 253 PermissionsType permissions_type) { |
| 229 is_showing_details_for_permissions_.clear(); | 254 InstallPromptPermissions& install_permissions = |
| 230 for (size_t i = 0; i < details.size(); ++i) | 255 GetPermissionsToUse(permissions_type); |
|
Devlin
2014/09/10 22:00:44
ahh, so much cleaner. :D
gpdavis
2014/09/11 20:09:21
Agreed! (:
| |
| 231 is_showing_details_for_permissions_.push_back(false); | 256 install_permissions.details = details; |
| 257 install_permissions.is_showing_details.clear(); | |
| 258 install_permissions.is_showing_details.insert( | |
| 259 install_permissions.is_showing_details.begin(), details.size(), false); | |
| 232 } | 260 } |
| 233 | 261 |
| 234 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( | 262 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 235 DetailsType type, | 263 DetailsType type, |
| 236 size_t index, | 264 size_t index, |
| 237 bool is_showing_details) { | 265 bool is_showing_details) { |
| 238 switch (type) { | 266 switch (type) { |
| 239 case PERMISSIONS_DETAILS: | 267 case PERMISSIONS_DETAILS: |
| 240 is_showing_details_for_permissions_[index] = is_showing_details; | 268 prompt_permissions_.is_showing_details[index] = is_showing_details; |
| 269 break; | |
| 270 case WITHHELD_PERMISSIONS_DETAILS: | |
| 271 withheld_prompt_permissions_.is_showing_details[index] = | |
| 272 is_showing_details; | |
| 241 break; | 273 break; |
| 242 case RETAINED_FILES_DETAILS: | 274 case RETAINED_FILES_DETAILS: |
| 243 is_showing_details_for_retained_files_ = is_showing_details; | 275 is_showing_details_for_retained_files_ = is_showing_details; |
| 244 break; | 276 break; |
| 245 } | 277 } |
| 246 } | 278 } |
| 247 | 279 |
| 248 void ExtensionInstallPrompt::Prompt::SetWebstoreData( | 280 void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
| 249 const std::string& localized_user_count, | 281 const std::string& localized_user_count, |
| 250 bool show_user_count, | 282 bool show_user_count, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 return kAbortButtonIds[type_] > 0; | 379 return kAbortButtonIds[type_] > 0; |
| 348 } | 380 } |
| 349 | 381 |
| 350 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { | 382 base::string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
| 351 CHECK(HasAbortButtonLabel()); | 383 CHECK(HasAbortButtonLabel()); |
| 352 if (ShouldShowExplanationText()) | 384 if (ShouldShowExplanationText()) |
| 353 return experiment_->GetCancelButtonText(); | 385 return experiment_->GetCancelButtonText(); |
| 354 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); | 386 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); |
| 355 } | 387 } |
| 356 | 388 |
| 357 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { | 389 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading( |
| 358 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); | 390 PermissionsType permissions_type) const { |
| 391 switch (permissions_type) { | |
| 392 case REGULAR_PERMISSIONS: | |
| 393 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); | |
| 394 case WITHHELD_PERMISSIONS: | |
| 395 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WITHHELD); | |
| 396 case ALL_PERMISSIONS: | |
| 397 NOTREACHED(); | |
| 398 return base::string16(); | |
| 399 } | |
| 359 } | 400 } |
| 360 | 401 |
| 361 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { | 402 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
| 362 const int kRetainedFilesMessageIDs[6] = { | 403 const int kRetainedFilesMessageIDs[6] = { |
| 363 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, | 404 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
| 364 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, | 405 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
| 365 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, | 406 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
| 366 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, | 407 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
| 367 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, | 408 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
| 368 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, | 409 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
| 369 }; | 410 }; |
| 370 std::vector<int> message_ids; | 411 std::vector<int> message_ids; |
| 371 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { | 412 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { |
| 372 message_ids.push_back(kRetainedFilesMessageIDs[i]); | 413 message_ids.push_back(kRetainedFilesMessageIDs[i]); |
| 373 } | 414 } |
| 374 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); | 415 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
| 375 } | 416 } |
| 376 | 417 |
| 377 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { | 418 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
| 378 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; | 419 return GetPermissionCount(ALL_PERMISSIONS) > 0 || |
| 420 type_ == POST_INSTALL_PERMISSIONS_PROMPT; | |
| 379 } | 421 } |
| 380 | 422 |
| 381 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 423 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 382 StarAppender appender, void* data) const { | 424 StarAppender appender, void* data) const { |
| 383 CHECK(appender); | 425 CHECK(appender); |
| 384 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 426 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 385 int rating_integer = floor(average_rating_); | 427 int rating_integer = floor(average_rating_); |
| 386 double rating_fractional = average_rating_ - rating_integer; | 428 double rating_fractional = average_rating_ - rating_integer; |
| 387 | 429 |
| 388 if (rating_fractional > 0.66) { | 430 if (rating_fractional > 0.66) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 416 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { | 458 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
| 417 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 459 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 418 | 460 |
| 419 if (show_user_count_) { | 461 if (show_user_count_) { |
| 420 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, | 462 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 421 base::UTF8ToUTF16(localized_user_count_)); | 463 base::UTF8ToUTF16(localized_user_count_)); |
| 422 } | 464 } |
| 423 return base::string16(); | 465 return base::string16(); |
| 424 } | 466 } |
| 425 | 467 |
| 426 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { | 468 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount( |
| 427 return permissions_.size(); | 469 PermissionsType permissions_type) const { |
| 470 switch (permissions_type) { | |
| 471 case REGULAR_PERMISSIONS: | |
| 472 return prompt_permissions_.permissions.size(); | |
| 473 case WITHHELD_PERMISSIONS: | |
| 474 return withheld_prompt_permissions_.permissions.size(); | |
| 475 case ALL_PERMISSIONS: | |
| 476 return prompt_permissions_.permissions.size() + | |
| 477 withheld_prompt_permissions_.permissions.size(); | |
| 478 } | |
| 428 } | 479 } |
| 429 | 480 |
| 430 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { | 481 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount( |
| 431 return details_.size(); | 482 PermissionsType permissions_type) const { |
| 483 switch (permissions_type) { | |
| 484 case REGULAR_PERMISSIONS: | |
| 485 return prompt_permissions_.details.size(); | |
| 486 case WITHHELD_PERMISSIONS: | |
| 487 return withheld_prompt_permissions_.details.size(); | |
| 488 case ALL_PERMISSIONS: | |
| 489 return prompt_permissions_.details.size() + | |
| 490 withheld_prompt_permissions_.details.size(); | |
| 491 } | |
| 432 } | 492 } |
| 433 | 493 |
| 434 base::string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) | 494 base::string16 ExtensionInstallPrompt::Prompt::GetPermission( |
| 435 const { | 495 size_t index, |
| 436 CHECK_LT(index, permissions_.size()); | 496 PermissionsType permissions_type) const { |
| 437 return permissions_[index]; | 497 const InstallPromptPermissions& install_permissions = |
| 498 GetPermissionsToUse(permissions_type); | |
| 499 CHECK_LT(index, install_permissions.permissions.size()); | |
| 500 return install_permissions.permissions[index]; | |
| 438 } | 501 } |
| 439 | 502 |
| 440 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( | 503 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
| 441 size_t index) const { | 504 size_t index, |
| 442 CHECK_LT(index, details_.size()); | 505 PermissionsType permissions_type) const { |
| 443 return details_[index]; | 506 const InstallPromptPermissions& install_permissions = |
| 507 GetPermissionsToUse(permissions_type); | |
| 508 CHECK_LT(index, install_permissions.details.size()); | |
| 509 return install_permissions.details[index]; | |
| 444 } | 510 } |
| 445 | 511 |
| 446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( | 512 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 447 DetailsType type, size_t index) const { | 513 DetailsType type, size_t index) const { |
| 448 switch (type) { | 514 switch (type) { |
| 449 case PERMISSIONS_DETAILS: | 515 case PERMISSIONS_DETAILS: |
| 450 CHECK_LT(index, is_showing_details_for_permissions_.size()); | 516 CHECK_LT(index, prompt_permissions_.is_showing_details.size()); |
| 451 return is_showing_details_for_permissions_[index]; | 517 return prompt_permissions_.is_showing_details[index]; |
| 518 case WITHHELD_PERMISSIONS_DETAILS: | |
| 519 CHECK_LT(index, withheld_prompt_permissions_.is_showing_details.size()); | |
| 520 return withheld_prompt_permissions_.is_showing_details[index]; | |
| 452 case RETAINED_FILES_DETAILS: | 521 case RETAINED_FILES_DETAILS: |
| 453 return is_showing_details_for_retained_files_; | 522 return is_showing_details_for_retained_files_; |
| 454 } | 523 } |
| 455 return false; | 524 return false; |
| 456 } | 525 } |
| 457 | 526 |
| 458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { | 527 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 459 return retained_files_.size(); | 528 return retained_files_.size(); |
| 460 } | 529 } |
| 461 | 530 |
| (...skipping 74 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 don't end up in the install prompt. | |
| 812 extensions::PermissionsUpdater(install_ui_->profile()) | |
| 813 .InitializePermissions( | |
| 814 extension_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT); | |
| 815 permissions_to_display = | |
| 816 extension_->permissions_data()->active_permissions(); | |
| 817 } | |
| 818 | |
| 819 if (permissions_to_display.get() && | |
| 743 (!extension_ || | 820 (!extension_ || |
| 744 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 821 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 745 extension_->id()))) { | 822 extension_->id()))) { |
| 746 Manifest::Type type = | 823 Manifest::Type type = |
| 747 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; | 824 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 748 const extensions::PermissionMessageProvider* message_provider = | 825 const extensions::PermissionMessageProvider* message_provider = |
| 749 extensions::PermissionMessageProvider::Get(); | 826 extensions::PermissionMessageProvider::Get(); |
| 750 prompt_->SetPermissions( | 827 prompt_->SetPermissions(message_provider->GetWarningMessages( |
| 751 message_provider->GetWarningMessages(permissions_.get(), type)); | 828 permissions_to_display.get(), type), |
| 752 prompt_->SetPermissionsDetails( | 829 REGULAR_PERMISSIONS); |
| 753 message_provider->GetWarningMessagesDetails(permissions_.get(), type)); | 830 prompt_->SetPermissionsDetails(message_provider->GetWarningMessagesDetails( |
| 831 permissions_to_display.get(), type), | |
| 832 REGULAR_PERMISSIONS); | |
| 833 | |
| 834 scoped_refptr<const extensions::PermissionSet> withheld = | |
| 835 extension_->permissions_data()->withheld_permissions(); | |
| 836 if (!withheld->IsEmpty()) { | |
| 837 prompt_->SetPermissions( | |
| 838 message_provider->GetWarningMessages(withheld.get(), type), | |
| 839 PermissionsType::WITHHELD_PERMISSIONS); | |
| 840 prompt_->SetPermissionsDetails( | |
| 841 message_provider->GetWarningMessagesDetails(withheld.get(), type), | |
| 842 PermissionsType::WITHHELD_PERMISSIONS); | |
| 843 } | |
| 754 } | 844 } |
| 755 | 845 |
| 756 switch (prompt_->type()) { | 846 switch (prompt_->type()) { |
| 757 case PERMISSIONS_PROMPT: | 847 case PERMISSIONS_PROMPT: |
| 758 case RE_ENABLE_PROMPT: | 848 case RE_ENABLE_PROMPT: |
| 759 case INLINE_INSTALL_PROMPT: | 849 case INLINE_INSTALL_PROMPT: |
| 760 case EXTERNAL_INSTALL_PROMPT: | 850 case EXTERNAL_INSTALL_PROMPT: |
| 761 case INSTALL_PROMPT: | 851 case INSTALL_PROMPT: |
| 762 case LAUNCH_PROMPT: | 852 case LAUNCH_PROMPT: |
| 763 case POST_INSTALL_PERMISSIONS_PROMPT: | 853 case POST_INSTALL_PERMISSIONS_PROMPT: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 776 } | 866 } |
| 777 | 867 |
| 778 if (AutoConfirmPrompt(delegate_)) | 868 if (AutoConfirmPrompt(delegate_)) |
| 779 return; | 869 return; |
| 780 | 870 |
| 781 if (show_dialog_callback_.is_null()) | 871 if (show_dialog_callback_.is_null()) |
| 782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 872 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 783 else | 873 else |
| 784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 874 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 785 } | 875 } |
| OLD | NEW |