| 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" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) | 194 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
| 195 : type_(type), | 195 : type_(type), |
| 196 is_showing_details_for_retained_files_(false), | 196 is_showing_details_for_retained_files_(false), |
| 197 extension_(NULL), | 197 extension_(NULL), |
| 198 bundle_(NULL), | 198 bundle_(NULL), |
| 199 average_rating_(0.0), | 199 average_rating_(0.0), |
| 200 rating_count_(0), | 200 rating_count_(0), |
| 201 show_user_count_(false) { | 201 show_user_count_(false), |
| 202 has_webstore_data_(false) { |
| 202 } | 203 } |
| 203 | 204 |
| 204 ExtensionInstallPrompt::Prompt::~Prompt() { | 205 ExtensionInstallPrompt::Prompt::~Prompt() { |
| 205 } | 206 } |
| 206 | 207 |
| 207 void ExtensionInstallPrompt::Prompt::SetPermissions( | 208 void ExtensionInstallPrompt::Prompt::SetPermissions( |
| 208 const std::vector<base::string16>& permissions) { | 209 const std::vector<base::string16>& permissions) { |
| 209 permissions_ = permissions; | 210 permissions_ = permissions; |
| 210 } | 211 } |
| 211 | 212 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) { | 247 void ExtensionInstallPrompt::Prompt::SetUserNameFromProfile(Profile* profile) { |
| 247 // |profile| can be NULL in unit tests. | 248 // |profile| can be NULL in unit tests. |
| 248 if (profile) { | 249 if (profile) { |
| 249 oauth_user_name_ = base::UTF8ToUTF16(profile->GetPrefs()->GetString( | 250 oauth_user_name_ = base::UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 250 prefs::kGoogleServicesUsername)); | 251 prefs::kGoogleServicesUsername)); |
| 251 } else { | 252 } else { |
| 252 oauth_user_name_.clear(); | 253 oauth_user_name_.clear(); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( | 257 void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
| 257 const std::string& localized_user_count, | 258 const std::string& localized_user_count, |
| 258 bool show_user_count, | 259 bool show_user_count, |
| 259 double average_rating, | 260 double average_rating, |
| 260 int rating_count) { | 261 int rating_count) { |
| 261 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 262 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 262 localized_user_count_ = localized_user_count; | 263 localized_user_count_ = localized_user_count; |
| 263 show_user_count_ = show_user_count; | 264 show_user_count_ = show_user_count; |
| 264 average_rating_ = average_rating; | 265 average_rating_ = average_rating; |
| 265 rating_count_ = rating_count; | 266 rating_count_ = rating_count; |
| 267 has_webstore_data_ = true; |
| 266 } | 268 } |
| 267 | 269 |
| 268 base::string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { | 270 base::string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
| 269 int resource_id = kTitleIds[type_]; | 271 int resource_id = kTitleIds[type_]; |
| 270 | 272 |
| 271 if (type_ == INSTALL_PROMPT) { | 273 if (type_ == INSTALL_PROMPT) { |
| 272 if (extension_->is_app()) | 274 if (extension_->is_app()) |
| 273 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; | 275 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; |
| 274 else if (extension_->is_theme()) | 276 else if (extension_->is_theme()) |
| 275 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; | 277 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); | 382 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
| 381 } | 383 } |
| 382 | 384 |
| 383 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { | 385 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
| 384 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; | 386 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
| 385 } | 387 } |
| 386 | 388 |
| 387 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 389 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
| 388 StarAppender appender, void* data) const { | 390 StarAppender appender, void* data) const { |
| 389 CHECK(appender); | 391 CHECK(appender); |
| 390 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 392 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 391 int rating_integer = floor(average_rating_); | 393 int rating_integer = floor(average_rating_); |
| 392 double rating_fractional = average_rating_ - rating_integer; | 394 double rating_fractional = average_rating_ - rating_integer; |
| 393 | 395 |
| 394 if (rating_fractional > 0.66) { | 396 if (rating_fractional > 0.66) { |
| 395 rating_integer++; | 397 rating_integer++; |
| 396 } | 398 } |
| 397 | 399 |
| 398 if (rating_fractional < 0.33 || rating_fractional > 0.66) { | 400 if (rating_fractional < 0.33 || rating_fractional > 0.66) { |
| 399 rating_fractional = 0; | 401 rating_fractional = 0; |
| 400 } | 402 } |
| 401 | 403 |
| 402 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 404 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 403 int i; | 405 int i; |
| 404 for (i = 0; i < rating_integer; i++) { | 406 for (i = 0; i < rating_integer; i++) { |
| 405 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data); | 407 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_ON), data); |
| 406 } | 408 } |
| 407 if (rating_fractional) { | 409 if (rating_fractional) { |
| 408 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data); | 410 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_HALF_LEFT), data); |
| 409 i++; | 411 i++; |
| 410 } | 412 } |
| 411 for (; i < kMaxExtensionRating; i++) { | 413 for (; i < kMaxExtensionRating; i++) { |
| 412 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data); | 414 appender(rb.GetImageSkiaNamed(IDR_EXTENSIONS_RATING_STAR_OFF), data); |
| 413 } | 415 } |
| 414 } | 416 } |
| 415 | 417 |
| 416 base::string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const { | 418 base::string16 ExtensionInstallPrompt::Prompt::GetRatingCount() const { |
| 417 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 419 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 418 return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT, | 420 return l10n_util::GetStringFUTF16(IDS_EXTENSION_RATING_COUNT, |
| 419 base::IntToString16(rating_count_)); | 421 base::IntToString16(rating_count_)); |
| 420 } | 422 } |
| 421 | 423 |
| 422 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { | 424 base::string16 ExtensionInstallPrompt::Prompt::GetUserCount() const { |
| 423 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 425 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
| 424 | 426 |
| 425 if (show_user_count_) { | 427 if (show_user_count_) { |
| 426 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, | 428 return l10n_util::GetStringFUTF16(IDS_EXTENSION_USER_COUNT, |
| 427 base::UTF8ToUTF16(localized_user_count_)); | 429 base::UTF8ToUTF16(localized_user_count_)); |
| 428 } | 430 } |
| 429 return base::string16(); | 431 return base::string16(); |
| 430 } | 432 } |
| 431 | 433 |
| 432 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { | 434 size_t ExtensionInstallPrompt::Prompt::GetPermissionCount() const { |
| 433 return permissions_.size(); | 435 return permissions_.size(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 delegate_ = delegate; | 642 delegate_ = delegate; |
| 641 prompt_.set_type(extension->is_ephemeral() ? LAUNCH_PROMPT : | 643 prompt_.set_type(extension->is_ephemeral() ? LAUNCH_PROMPT : |
| 642 RE_ENABLE_PROMPT); | 644 RE_ENABLE_PROMPT); |
| 643 | 645 |
| 644 LoadImageIfNeeded(); | 646 LoadImageIfNeeded(); |
| 645 } | 647 } |
| 646 | 648 |
| 647 void ExtensionInstallPrompt::ConfirmExternalInstall( | 649 void ExtensionInstallPrompt::ConfirmExternalInstall( |
| 648 Delegate* delegate, | 650 Delegate* delegate, |
| 649 const Extension* extension, | 651 const Extension* extension, |
| 650 const ShowDialogCallback& show_dialog_callback) { | 652 const ShowDialogCallback& show_dialog_callback, |
| 653 const Prompt& prompt) { |
| 651 DCHECK(ui_loop_ == base::MessageLoop::current()); | 654 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 652 extension_ = extension; | 655 extension_ = extension; |
| 653 permissions_ = extension->GetActivePermissions(); | 656 permissions_ = extension->GetActivePermissions(); |
| 654 delegate_ = delegate; | 657 delegate_ = delegate; |
| 655 prompt_.set_type(EXTERNAL_INSTALL_PROMPT); | 658 prompt_ = prompt; |
| 656 show_dialog_callback_ = show_dialog_callback; | 659 show_dialog_callback_ = show_dialog_callback; |
| 657 | 660 |
| 658 LoadImageIfNeeded(); | 661 LoadImageIfNeeded(); |
| 659 } | 662 } |
| 660 | 663 |
| 661 void ExtensionInstallPrompt::ConfirmPermissions( | 664 void ExtensionInstallPrompt::ConfirmPermissions( |
| 662 Delegate* delegate, | 665 Delegate* delegate, |
| 663 const Extension* extension, | 666 const Extension* extension, |
| 664 const PermissionSet* permissions) { | 667 const PermissionSet* permissions) { |
| 665 DCHECK(ui_loop_ == base::MessageLoop::current()); | 668 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 841 } |
| 839 | 842 |
| 840 if (AutoConfirmPrompt(delegate_)) | 843 if (AutoConfirmPrompt(delegate_)) |
| 841 return; | 844 return; |
| 842 | 845 |
| 843 if (show_dialog_callback_.is_null()) | 846 if (show_dialog_callback_.is_null()) |
| 844 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 847 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 845 else | 848 else |
| 846 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 849 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 847 } | 850 } |
| OLD | NEW |