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