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