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