| 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.h" | 10 #include "base/message_loop.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 ExtensionInstallPrompt::Prompt::~Prompt() { | 197 ExtensionInstallPrompt::Prompt::~Prompt() { |
| 198 } | 198 } |
| 199 | 199 |
| 200 void ExtensionInstallPrompt::Prompt::SetPermissions( | 200 void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 201 const std::vector<string16>& permissions) { | 201 const std::vector<string16>& permissions) { |
| 202 permissions_ = permissions; | 202 permissions_ = permissions; |
| 203 } | 203 } |
| 204 | 204 |
| 205 void ExtensionInstallPrompt::Prompt::SetPermissionsDetails( |
| 206 const std::vector<string16>& details) { |
| 207 details_ = details; |
| 208 } |
| 209 |
| 205 void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice( | 210 void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice( |
| 206 const IssueAdviceInfo& issue_advice) { | 211 const IssueAdviceInfo& issue_advice) { |
| 207 oauth_issue_advice_ = issue_advice; | 212 oauth_issue_advice_ = issue_advice; |
| 208 } | 213 } |
| 209 | 214 |
| 210 void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) { | 215 void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) { |
| 211 // |profile| can be NULL in unit tests. | 216 // |profile| can be NULL in unit tests. |
| 212 if (profile) { | 217 if (profile) { |
| 213 oauth_user_name_ = UTF8ToUTF16(profile->GetPrefs()->GetString( | 218 oauth_user_name_ = UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 214 prefs::kGoogleServicesUsername)); | 219 prefs::kGoogleServicesUsername)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 314 |
| 310 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { | 315 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { |
| 311 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); | 316 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); |
| 312 } | 317 } |
| 313 | 318 |
| 314 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { | 319 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { |
| 315 return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_); | 320 return l10n_util::GetStringFUTF16(kOAuthHeaderIds[type_], oauth_user_name_); |
| 316 } | 321 } |
| 317 | 322 |
| 318 string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { | 323 string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
| 324 // TODO(finnur): Remove this once all platforms are using |
| 325 // GetRetainedFilesHeadingWithCount(). |
| 319 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_RETAINED_FILES); | 326 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_RETAINED_FILES); |
| 320 } | 327 } |
| 321 | 328 |
| 329 string16 |
| 330 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeadingWithCount() const { |
| 331 return l10n_util::GetStringFUTF16( |
| 332 IDS_EXTENSION_PROMPT_RETAINED_FILES_WITH_COUNT, |
| 333 base::IntToString16(GetRetainedFileCount())); |
| 334 } |
| 335 |
| 322 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { | 336 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
| 323 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; | 337 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
| 324 } | 338 } |
| 325 | 339 |
| 326 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 340 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 327 StarAppender appender, void* data) const { | 341 StarAppender appender, void* data) const { |
| 328 CHECK(appender); | 342 CHECK(appender); |
| 329 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 343 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
| 330 int rating_integer = floor(average_rating_); | 344 int rating_integer = floor(average_rating_); |
| 331 double rating_fractional = average_rating_ - rating_integer; | 345 double rating_fractional = average_rating_ - rating_integer; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 377 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
| 364 return l10n_util::GetStringFUTF16( | 378 return l10n_util::GetStringFUTF16( |
| 365 IDS_EXTENSION_USER_COUNT, | 379 IDS_EXTENSION_USER_COUNT, |
| 366 UTF8ToUTF16(localized_user_count_)); | 380 UTF8ToUTF16(localized_user_count_)); |
| 367 } | 381 } |
| 368 | 382 |
| 369 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { | 383 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { |
| 370 return permissions_.size(); | 384 return permissions_.size(); |
| 371 } | 385 } |
| 372 | 386 |
| 387 size_t ExtensionInstallPrompt::Prompt::GetPermissionsDetailsCount() const { |
| 388 return details_.size(); |
| 389 } |
| 390 |
| 373 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const { | 391 string16 ExtensionInstallPrompt::Prompt::GetPermission(size_t index) const { |
| 374 CHECK_LT(index, permissions_.size()); | 392 CHECK_LT(index, permissions_.size()); |
| 375 return permissions_[index]; | 393 return permissions_[index]; |
| 376 } | 394 } |
| 377 | 395 |
| 396 string16 ExtensionInstallPrompt::Prompt::GetPermissionsDetails( |
| 397 size_t index) const { |
| 398 CHECK_LT(index, details_.size()); |
| 399 return details_[index]; |
| 400 } |
| 401 |
| 378 size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const { | 402 size_t ExtensionInstallPrompt::Prompt::GetOAuthIssueCount() const { |
| 379 return oauth_issue_advice_.size(); | 403 return oauth_issue_advice_.size(); |
| 380 } | 404 } |
| 381 | 405 |
| 382 const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue( | 406 const IssueAdviceInfoEntry& ExtensionInstallPrompt::Prompt::GetOAuthIssue( |
| 383 size_t index) const { | 407 size_t index) const { |
| 384 CHECK_LT(index, oauth_issue_advice_.size()); | 408 CHECK_LT(index, oauth_issue_advice_.size()); |
| 385 return oauth_issue_advice_[index]; | 409 return oauth_issue_advice_[index]; |
| 386 } | 410 } |
| 387 | 411 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 ShowConfirmation(); | 736 ShowConfirmation(); |
| 713 } | 737 } |
| 714 | 738 |
| 715 void ExtensionInstallPrompt::ShowConfirmation() { | 739 void ExtensionInstallPrompt::ShowConfirmation() { |
| 716 if (permissions_.get() && | 740 if (permissions_.get() && |
| 717 (!extension_ || | 741 (!extension_ || |
| 718 !extensions::PermissionsData::ShouldSkipPermissionWarnings( | 742 !extensions::PermissionsData::ShouldSkipPermissionWarnings( |
| 719 extension_))) { | 743 extension_))) { |
| 720 Manifest::Type extension_type = extension_ ? | 744 Manifest::Type extension_type = extension_ ? |
| 721 extension_->GetType() : Manifest::TYPE_UNKNOWN; | 745 extension_->GetType() : Manifest::TYPE_UNKNOWN; |
| 722 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 746 prompt_.SetPermissions( |
| 747 permissions_->GetWarningMessages(extension_type)); |
| 748 prompt_.SetPermissionsDetails( |
| 749 permissions_->GetWarningMessagesDetails(extension_type)); |
| 723 } | 750 } |
| 724 | 751 |
| 725 switch (prompt_.type()) { | 752 switch (prompt_.type()) { |
| 726 case PERMISSIONS_PROMPT: | 753 case PERMISSIONS_PROMPT: |
| 727 case RE_ENABLE_PROMPT: | 754 case RE_ENABLE_PROMPT: |
| 728 case INLINE_INSTALL_PROMPT: | 755 case INLINE_INSTALL_PROMPT: |
| 729 case EXTERNAL_INSTALL_PROMPT: | 756 case EXTERNAL_INSTALL_PROMPT: |
| 730 case INSTALL_PROMPT: | 757 case INSTALL_PROMPT: |
| 731 case POST_INSTALL_PERMISSIONS_PROMPT: { | 758 case POST_INSTALL_PERMISSIONS_PROMPT: { |
| 732 prompt_.set_extension(extension_); | 759 prompt_.set_extension(extension_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 743 } | 770 } |
| 744 | 771 |
| 745 if (AutoConfirmPrompt(delegate_)) | 772 if (AutoConfirmPrompt(delegate_)) |
| 746 return; | 773 return; |
| 747 | 774 |
| 748 if (show_dialog_callback_.is_null()) | 775 if (show_dialog_callback_.is_null()) |
| 749 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 776 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 750 else | 777 else |
| 751 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 778 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 752 } | 779 } |
| OLD | NEW |