Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/extensions/permissions_updater.h" | |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" |
| 25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/browser/extension_prefs.h" | 28 #include "extensions/browser/extension_prefs.h" |
| 28 #include "extensions/browser/extension_util.h" | 29 #include "extensions/browser/extension_util.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 average_rating_(0.0), | 213 average_rating_(0.0), |
| 213 rating_count_(0), | 214 rating_count_(0), |
| 214 show_user_count_(false), | 215 show_user_count_(false), |
| 215 has_webstore_data_(false) { | 216 has_webstore_data_(false) { |
| 216 } | 217 } |
| 217 | 218 |
| 218 ExtensionInstallPrompt::Prompt::~Prompt() { | 219 ExtensionInstallPrompt::Prompt::~Prompt() { |
| 219 } | 220 } |
| 220 | 221 |
| 221 void ExtensionInstallPrompt::Prompt::SetPermissions( | 222 void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 222 const std::vector<base::string16>& permissions) { | 223 const std::vector<base::string16>& permissions, |
| 223 permissions_ = permissions; | 224 bool withheld) { |
|
gpdavis
2014/08/29 01:12:16
Figured I'd add a parameter to these two methods,
| |
| 225 if (withheld) | |
| 226 withheld_permissions_ = permissions; | |
| 227 else | |
| 228 permissions_ = permissions; | |
| 224 } | 229 } |
| 225 | 230 |
| 226 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( | 231 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
| 227 const std::vector<base::string16>& details) { | 232 const std::vector<base::string16>& details, |
| 228 details_ = details; | 233 bool withheld) { |
| 229 is_showing_details_for_permissions_.clear(); | 234 if (withheld) { |
| 230 for (size_t i = 0; i < details.size(); ++i) | 235 withheld_details_ = details; |
| 231 is_showing_details_for_permissions_.push_back(false); | 236 is_showing_details_for_withheld_permissions_.clear(); |
| 237 for (size_t i = 0; i < details.size(); ++i) | |
| 238 is_showing_details_for_withheld_permissions_.push_back(false); | |
| 239 } else { | |
| 240 details_ = details; | |
| 241 is_showing_details_for_permissions_.clear(); | |
| 242 for (size_t i = 0; i < details.size(); ++i) | |
| 243 is_showing_details_for_permissions_.push_back(false); | |
| 244 } | |
| 232 } | 245 } |
| 233 | 246 |
| 234 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( | 247 void ExtensionInstallPrompt::Prompt::SetIsShowingDetails( |
| 235 DetailsType type, | 248 DetailsType type, |
| 236 size_t index, | 249 size_t index, |
| 237 bool is_showing_details) { | 250 bool is_showing_details) { |
| 238 switch (type) { | 251 switch (type) { |
| 239 case PERMISSIONS_DETAILS: | 252 case PERMISSIONS_DETAILS: |
| 240 is_showing_details_for_permissions_[index] = is_showing_details; | 253 is_showing_details_for_permissions_[index] = is_showing_details; |
| 241 break; | 254 break; |
| 255 case WITHHELD_PERMISSIONS_DETAILS: | |
|
gpdavis
2014/08/29 01:12:16
This is necessary for the cocoa implementation, wh
| |
| 256 is_showing_details_for_withheld_permissions_[index] = is_showing_details; | |
| 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, |
| 251 double average_rating, | 267 double average_rating, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; | 310 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_THEME; |
| 295 else | 311 else |
| 296 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; | 312 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; |
| 297 return l10n_util::GetStringUTF16(resource_id); | 313 return l10n_util::GetStringUTF16(resource_id); |
| 298 } else { | 314 } else { |
| 299 return l10n_util::GetStringFUTF16( | 315 return l10n_util::GetStringFUTF16( |
| 300 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); | 316 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); |
| 301 } | 317 } |
| 302 } | 318 } |
| 303 | 319 |
| 320 base::string16 ExtensionInstallPrompt::Prompt::GetWithheldHeading() const { | |
| 321 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WITHHELD); | |
| 322 } | |
| 323 | |
| 304 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { | 324 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
| 305 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && | 325 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && |
| 306 ShouldDisplayRevokeFilesButton()) { | 326 ShouldDisplayRevokeFilesButton()) { |
| 307 return kButtons[type_] | ui::DIALOG_BUTTON_OK; | 327 return kButtons[type_] | ui::DIALOG_BUTTON_OK; |
| 308 } | 328 } |
| 309 | 329 |
| 310 return kButtons[type_]; | 330 return kButtons[type_]; |
| 311 } | 331 } |
| 312 | 332 |
| 313 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { | 333 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 CHECK_LT(index, permissions_.size()); | 456 CHECK_LT(index, permissions_.size()); |
| 437 return permissions_[index]; | 457 return permissions_[index]; |
| 438 } | 458 } |
| 439 | 459 |
| 440 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( | 460 base::string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
| 441 size_t index) const { | 461 size_t index) const { |
| 442 CHECK_LT(index, details_.size()); | 462 CHECK_LT(index, details_.size()); |
| 443 return details_[index]; | 463 return details_[index]; |
| 444 } | 464 } |
| 445 | 465 |
| 466 size_t ExtensionInstallPrompt::Prompt::GetWithheldPermissionCount() const { | |
| 467 return withheld_permissions_.size(); | |
| 468 } | |
| 469 | |
| 470 size_t ExtensionInstallPrompt::Prompt::GetWithheldPermissionsDetailsCount() | |
| 471 const { | |
| 472 return withheld_details_.size(); | |
| 473 } | |
| 474 | |
| 475 base::string16 ExtensionInstallPrompt::Prompt::GetWithheldPermission( | |
| 476 size_t index) const { | |
| 477 CHECK_LT(index, withheld_permissions_.size()); | |
| 478 return withheld_permissions_[index]; | |
| 479 } | |
| 480 | |
| 481 base::string16 ExtensionInstallPrompt::Prompt::GetWithheldPermissionsDetails( | |
| 482 size_t index) const { | |
| 483 CHECK_LT(index, withheld_details_.size()); | |
| 484 return withheld_details_[index]; | |
| 485 } | |
| 486 | |
| 446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( | 487 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
| 447 DetailsType type, size_t index) const { | 488 DetailsType type, size_t index) const { |
| 448 switch (type) { | 489 switch (type) { |
| 449 case PERMISSIONS_DETAILS: | 490 case PERMISSIONS_DETAILS: |
| 450 CHECK_LT(index, is_showing_details_for_permissions_.size()); | 491 CHECK_LT(index, is_showing_details_for_permissions_.size()); |
| 451 return is_showing_details_for_permissions_[index]; | 492 return is_showing_details_for_permissions_[index]; |
| 493 case WITHHELD_PERMISSIONS_DETAILS: | |
| 494 CHECK_LT(index, is_showing_details_for_withheld_permissions_.size()); | |
| 495 return is_showing_details_for_withheld_permissions_[index]; | |
| 452 case RETAINED_FILES_DETAILS: | 496 case RETAINED_FILES_DETAILS: |
| 453 return is_showing_details_for_retained_files_; | 497 return is_showing_details_for_retained_files_; |
| 454 } | 498 } |
| 455 return false; | 499 return false; |
| 456 } | 500 } |
| 457 | 501 |
| 458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { | 502 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
| 459 return retained_files_.size(); | 503 return retained_files_.size(); |
| 460 } | 504 } |
| 461 | 505 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); | 784 prompt_->set_experiment(ExtensionInstallPromptExperiment::ControlGroup()); |
| 741 | 785 |
| 742 if (permissions_.get() && | 786 if (permissions_.get() && |
| 743 (!extension_ || | 787 (!extension_ || |
| 744 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 788 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 745 extension_->id()))) { | 789 extension_->id()))) { |
| 746 Manifest::Type type = | 790 Manifest::Type type = |
| 747 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; | 791 extension_ ? extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 748 const extensions::PermissionMessageProvider* message_provider = | 792 const extensions::PermissionMessageProvider* message_provider = |
| 749 extensions::PermissionMessageProvider::Get(); | 793 extensions::PermissionMessageProvider::Get(); |
| 794 | |
| 795 // Initialize permissions so that withheld permissions don't end up in the | |
| 796 // install prompt. | |
| 797 if (extension_) { | |
| 798 extensions::PermissionsUpdater(install_ui_->profile()) | |
| 799 .InitializePermissions( | |
| 800 extension_, extensions::PermissionsUpdater::INIT_FLAG_TRANSIENT); | |
| 801 permissions_ = extension_->permissions_data()->active_permissions(); | |
| 802 } | |
| 750 prompt_->SetPermissions( | 803 prompt_->SetPermissions( |
| 751 message_provider->GetWarningMessages(permissions_.get(), type)); | 804 message_provider->GetWarningMessages(permissions_.get(), type), |
| 805 false); // withheld | |
| 752 prompt_->SetPermissionsDetails( | 806 prompt_->SetPermissionsDetails( |
| 753 message_provider->GetWarningMessagesDetails(permissions_.get(), type)); | 807 message_provider->GetWarningMessagesDetails(permissions_.get(), type), |
| 808 false); // withheld | |
| 809 | |
| 810 scoped_refptr<const extensions::PermissionSet> withheld = | |
| 811 extension_->permissions_data()->withheld_permissions(); | |
| 812 if (!withheld->IsEmpty()) { | |
| 813 prompt_->SetPermissions( | |
| 814 message_provider->GetWarningMessages(withheld.get(), type), | |
| 815 true); // withheld | |
| 816 prompt_->SetPermissionsDetails( | |
| 817 message_provider->GetWarningMessagesDetails(withheld.get(), type), | |
| 818 true); // withheld | |
| 819 } | |
| 754 } | 820 } |
| 755 | 821 |
| 756 switch (prompt_->type()) { | 822 switch (prompt_->type()) { |
| 757 case PERMISSIONS_PROMPT: | 823 case PERMISSIONS_PROMPT: |
| 758 case RE_ENABLE_PROMPT: | 824 case RE_ENABLE_PROMPT: |
| 759 case INLINE_INSTALL_PROMPT: | 825 case INLINE_INSTALL_PROMPT: |
| 760 case EXTERNAL_INSTALL_PROMPT: | 826 case EXTERNAL_INSTALL_PROMPT: |
| 761 case INSTALL_PROMPT: | 827 case INSTALL_PROMPT: |
| 762 case LAUNCH_PROMPT: | 828 case LAUNCH_PROMPT: |
| 763 case POST_INSTALL_PERMISSIONS_PROMPT: | 829 case POST_INSTALL_PERMISSIONS_PROMPT: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 776 } | 842 } |
| 777 | 843 |
| 778 if (AutoConfirmPrompt(delegate_)) | 844 if (AutoConfirmPrompt(delegate_)) |
| 779 return; | 845 return; |
| 780 | 846 |
| 781 if (show_dialog_callback_.is_null()) | 847 if (show_dialog_callback_.is_null()) |
| 782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 848 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 783 else | 849 else |
| 784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 850 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 785 } | 851 } |
| OLD | NEW |