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/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/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_dialog.h" | 17 #include "chrome/browser/extensions/extension_install_dialog.h" |
18 #include "chrome/browser/extensions/extension_install_ui.h" | 18 #include "chrome/browser/extensions/extension_install_ui.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
21 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_icon_set.h" | 28 #include "chrome/common/extensions/extension_icon_set.h" |
28 #include "chrome/common/extensions/extension_manifest_constants.h" | 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
29 #include "chrome/common/extensions/extension_resource.h" | 30 #include "chrome/common/extensions/extension_resource.h" |
30 #include "chrome/common/extensions/extension_switch_utils.h" | 31 #include "chrome/common/extensions/extension_switch_utils.h" |
31 #include "chrome/common/extensions/permissions/permission_set.h" | 32 #include "chrome/common/extensions/permissions/permission_set.h" |
32 #include "chrome/common/extensions/url_pattern.h" | 33 #include "chrome/common/extensions/url_pattern.h" |
| 34 #include "chrome/common/pref_names.h" |
33 #include "content/public/browser/page_navigator.h" | 35 #include "content/public/browser/page_navigator.h" |
34 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
36 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/gfx/image/image.h" | 41 #include "ui/gfx/image/image.h" |
40 | 42 |
41 using extensions::BundleInstaller; | 43 using extensions::BundleInstaller; |
42 using extensions::Extension; | 44 using extensions::Extension; |
(...skipping 28 matching lines...) Expand all Loading... |
71 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON | 73 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON |
72 }; | 74 }; |
73 static const int kPermissionsHeaderIds[ | 75 static const int kPermissionsHeaderIds[ |
74 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 76 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
75 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 77 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
76 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 78 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
77 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, | 79 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, |
78 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 80 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
79 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 81 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
80 }; | 82 }; |
| 83 static const int kOAuthHeaderIds[ |
| 84 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 85 IDS_EXTENSION_PROMPT_OAUTH_HEADER, |
| 86 0, // Inline installs don't show OAuth permissions. |
| 87 0, // Bundle installs don't show OAuth permissions. |
| 88 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, |
| 89 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, |
| 90 }; |
81 | 91 |
82 namespace { | 92 namespace { |
83 | 93 |
84 // Size of extension icon in top left of dialog. | 94 // Size of extension icon in top left of dialog. |
85 const int kIconSize = 69; | 95 const int kIconSize = 69; |
86 | 96 |
87 } // namespace | 97 } // namespace |
88 | 98 |
89 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) | 99 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) |
90 : type_(type), | 100 : type_(type), |
91 extension_(NULL), | 101 extension_(NULL), |
92 bundle_(NULL), | 102 bundle_(NULL), |
93 average_rating_(0.0), | 103 average_rating_(0.0), |
94 rating_count_(0) { | 104 rating_count_(0), |
| 105 profile_(profile) { |
95 } | 106 } |
96 | 107 |
97 ExtensionInstallPrompt::Prompt::~Prompt() { | 108 ExtensionInstallPrompt::Prompt::~Prompt() { |
98 } | 109 } |
99 | 110 |
100 void ExtensionInstallPrompt::Prompt::SetPermissions( | 111 void ExtensionInstallPrompt::Prompt::SetPermissions( |
101 const std::vector<string16>& permissions) { | 112 const std::vector<string16>& permissions) { |
102 permissions_ = permissions; | 113 permissions_ = permissions; |
103 } | 114 } |
104 | 115 |
105 void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice( | 116 void ExtensionInstallPrompt::Prompt::SetOAuthIssueAdvice( |
106 const IssueAdviceInfo& issue_advice) { | 117 const IssueAdviceInfo& issue_advice) { |
107 oauth_issue_advice_ = issue_advice; | 118 oauth_issue_advice_ = issue_advice; |
108 } | 119 } |
109 | 120 |
110 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( | 121 void ExtensionInstallPrompt::Prompt::SetInlineInstallWebstoreData( |
111 const std::string& localized_user_count, | 122 const std::string& localized_user_count, |
112 double average_rating, | 123 double average_rating, |
113 int rating_count) { | 124 int rating_count) { |
114 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 125 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
115 localized_user_count_ = localized_user_count; | 126 localized_user_count_ = localized_user_count; |
116 average_rating_ = average_rating; | 127 average_rating_ = average_rating; |
117 rating_count_ = rating_count; | 128 rating_count_ = rating_count; |
118 } | 129 } |
119 | 130 |
120 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { | 131 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { |
121 | |
122 int resource_id = kTitleIds[type_]; | 132 int resource_id = kTitleIds[type_]; |
123 | 133 |
124 if (type_ == INSTALL_PROMPT) { | 134 if (type_ == INSTALL_PROMPT) { |
125 if (extension_->is_app()) | 135 if (extension_->is_app()) |
126 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; | 136 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; |
127 else if (extension_->is_theme()) | 137 else if (extension_->is_theme()) |
128 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; | 138 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; |
129 else | 139 else |
130 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; | 140 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; |
131 } | 141 } |
(...skipping 23 matching lines...) Expand all Loading... |
155 string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { | 165 string16 ExtensionInstallPrompt::Prompt::GetAbortButtonLabel() const { |
156 CHECK(HasAbortButtonLabel()); | 166 CHECK(HasAbortButtonLabel()); |
157 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); | 167 return l10n_util::GetStringUTF16(kAbortButtonIds[type_]); |
158 } | 168 } |
159 | 169 |
160 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { | 170 string16 ExtensionInstallPrompt::Prompt::GetPermissionsHeading() const { |
161 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); | 171 return l10n_util::GetStringUTF16(kPermissionsHeaderIds[type_]); |
162 } | 172 } |
163 | 173 |
164 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { | 174 string16 ExtensionInstallPrompt::Prompt::GetOAuthHeading() const { |
165 // TODO(estade): this should change based on type_. | 175 string16 username(ASCIIToUTF16("username@example.com")); |
166 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_SCOPES_HEADING); | 176 // |profile_| can be NULL in unit tests. |
| 177 if (profile_) { |
| 178 username = UTF8ToUTF16(profile_->GetPrefs()->GetString( |
| 179 prefs::kGoogleServicesUsername)); |
| 180 } |
| 181 int resource_id = kOAuthHeaderIds[type_]; |
| 182 return l10n_util::GetStringFUTF16(resource_id, username); |
167 } | 183 } |
168 | 184 |
169 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 185 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
170 StarAppender appender, void* data) const { | 186 StarAppender appender, void* data) const { |
171 CHECK(appender); | 187 CHECK(appender); |
172 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); | 188 CHECK_EQ(INLINE_INSTALL_PROMPT, type_); |
173 int rating_integer = floor(average_rating_); | 189 int rating_integer = floor(average_rating_); |
174 double rating_fractional = average_rating_ - rating_integer; | 190 double rating_fractional = average_rating_ - rating_integer; |
175 | 191 |
176 if (rating_fractional > 0.66) { | 192 if (rating_fractional > 0.66) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 gfx::NativeWindow parent, | 279 gfx::NativeWindow parent, |
264 content::PageNavigator* navigator, | 280 content::PageNavigator* navigator, |
265 Profile* profile) | 281 Profile* profile) |
266 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()), | 282 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()), |
267 parent_(parent), | 283 parent_(parent), |
268 navigator_(navigator), | 284 navigator_(navigator), |
269 ui_loop_(MessageLoop::current()), | 285 ui_loop_(MessageLoop::current()), |
270 extension_(NULL), | 286 extension_(NULL), |
271 install_ui_(ExtensionInstallUI::Create(profile)), | 287 install_ui_(ExtensionInstallUI::Create(profile)), |
272 delegate_(NULL), | 288 delegate_(NULL), |
273 prompt_(UNSET_PROMPT_TYPE), | 289 prompt_(profile, UNSET_PROMPT_TYPE), |
274 prompt_type_(UNSET_PROMPT_TYPE), | 290 prompt_type_(UNSET_PROMPT_TYPE), |
275 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 291 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
276 } | 292 } |
277 | 293 |
278 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 294 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
279 } | 295 } |
280 | 296 |
281 void ExtensionInstallPrompt::ConfirmBundleInstall( | 297 void ExtensionInstallPrompt::ConfirmBundleInstall( |
282 extensions::BundleInstaller* bundle, | 298 extensions::BundleInstaller* bundle, |
283 const PermissionSet* permissions) { | 299 const PermissionSet* permissions) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 Browser* browser) { | 523 Browser* browser) { |
508 // |browser| can be NULL in unit tests. | 524 // |browser| can be NULL in unit tests. |
509 if (!browser) | 525 if (!browser) |
510 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 526 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
511 gfx::NativeWindow parent = | 527 gfx::NativeWindow parent = |
512 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 528 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
513 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 529 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
514 } | 530 } |
515 | 531 |
516 } // namespace chrome | 532 } // namespace chrome |
OLD | NEW |