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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 84 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
85 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, | 85 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, |
86 }; | 86 }; |
87 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 87 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
89 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 89 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
90 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 90 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
91 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, | 91 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
92 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, | 92 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, |
93 0, // External installs use different strings for extensions/apps. | 93 0, // External installs use different strings for extensions/apps. |
94 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, | 94 0, // Different strings depending on the files and devices retained. |
95 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, | 95 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, |
96 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, | 96 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON, |
97 }; | 97 }; |
98 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 98 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
99 0, // These all use the platform's default cancel label. | 99 0, // These all use the platform's default cancel label. |
100 0, | 100 0, |
101 0, | 101 0, |
102 0, | 102 0, |
103 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, | 103 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, |
104 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, | 104 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: | 200 case ExtensionInstallPrompt::UNSET_PROMPT_TYPE: |
201 case ExtensionInstallPrompt::NUM_PROMPT_TYPES: | 201 case ExtensionInstallPrompt::NUM_PROMPT_TYPES: |
202 break; | 202 break; |
203 } | 203 } |
204 return "OTHER"; | 204 return "OTHER"; |
205 } | 205 } |
206 | 206 |
207 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) | 207 ExtensionInstallPrompt::Prompt::Prompt(PromptType type) |
208 : type_(type), | 208 : type_(type), |
209 is_showing_details_for_retained_files_(false), | 209 is_showing_details_for_retained_files_(false), |
210 is_showing_details_for_retained_devices_(false), | |
210 extension_(NULL), | 211 extension_(NULL), |
211 bundle_(NULL), | 212 bundle_(NULL), |
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 } |
(...skipping 15 matching lines...) Expand all Loading... | |
235 DetailsType type, | 236 DetailsType type, |
236 size_t index, | 237 size_t index, |
237 bool is_showing_details) { | 238 bool is_showing_details) { |
238 switch (type) { | 239 switch (type) { |
239 case PERMISSIONS_DETAILS: | 240 case PERMISSIONS_DETAILS: |
240 is_showing_details_for_permissions_[index] = is_showing_details; | 241 is_showing_details_for_permissions_[index] = is_showing_details; |
241 break; | 242 break; |
242 case RETAINED_FILES_DETAILS: | 243 case RETAINED_FILES_DETAILS: |
243 is_showing_details_for_retained_files_ = is_showing_details; | 244 is_showing_details_for_retained_files_ = is_showing_details; |
244 break; | 245 break; |
246 case RETAINED_DEVICES_DETAILS: | |
247 is_showing_details_for_retained_devices_ = is_showing_details; | |
248 break; | |
245 } | 249 } |
246 } | 250 } |
247 | 251 |
248 void ExtensionInstallPrompt::Prompt::SetWebstoreData( | 252 void ExtensionInstallPrompt::Prompt::SetWebstoreData( |
249 const std::string& localized_user_count, | 253 const std::string& localized_user_count, |
250 bool show_user_count, | 254 bool show_user_count, |
251 double average_rating, | 255 double average_rating, |
252 int rating_count) { | 256 int rating_count) { |
253 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 257 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
254 localized_user_count_ = localized_user_count; | 258 localized_user_count_ = localized_user_count; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 else | 299 else |
296 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; | 300 resource_id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING_EXTENSION; |
297 return l10n_util::GetStringUTF16(resource_id); | 301 return l10n_util::GetStringUTF16(resource_id); |
298 } else { | 302 } else { |
299 return l10n_util::GetStringFUTF16( | 303 return l10n_util::GetStringFUTF16( |
300 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); | 304 kHeadingIds[type_], base::UTF8ToUTF16(extension_->name())); |
301 } | 305 } |
302 } | 306 } |
303 | 307 |
304 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { | 308 int ExtensionInstallPrompt::Prompt::GetDialogButtons() const { |
305 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && | 309 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT && ShouldDisplayRevokeButton()) { |
306 ShouldDisplayRevokeFilesButton()) { | |
307 return kButtons[type_] | ui::DIALOG_BUTTON_OK; | 310 return kButtons[type_] | ui::DIALOG_BUTTON_OK; |
308 } | 311 } |
Finnur
2014/09/23 09:46:03
nit: No need for braces (single-line).
Reilly Grant (use Gerrit)
2014/09/25 17:06:21
The C++ style guide allows braces for single-line
| |
309 | 312 |
310 return kButtons[type_]; | 313 return kButtons[type_]; |
311 } | 314 } |
312 | 315 |
313 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { | 316 bool ExtensionInstallPrompt::Prompt::ShouldShowExplanationText() const { |
314 return type_ == INSTALL_PROMPT && extension_->is_extension() && | 317 return type_ == INSTALL_PROMPT && extension_->is_extension() && |
315 experiment_.get() && experiment_->text_only(); | 318 experiment_.get() && experiment_->text_only(); |
316 } | 319 } |
317 | 320 |
318 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { | 321 bool ExtensionInstallPrompt::Prompt::HasAcceptButtonLabel() const { |
322 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) | |
323 return ShouldDisplayRevokeButton(); | |
324 | |
319 if (kAcceptButtonIds[type_] == 0) | 325 if (kAcceptButtonIds[type_] == 0) |
320 return false; | 326 return false; |
321 | 327 |
322 if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) | |
323 return ShouldDisplayRevokeFilesButton(); | |
324 | |
325 return true; | 328 return true; |
326 } | 329 } |
327 | 330 |
328 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { | 331 base::string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { |
329 if (type_ == EXTERNAL_INSTALL_PROMPT) { | 332 if (type_ == EXTERNAL_INSTALL_PROMPT) { |
330 int id = -1; | 333 int id = -1; |
331 if (extension_->is_app()) | 334 if (extension_->is_app()) |
332 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; | 335 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_APP; |
333 else if (extension_->is_theme()) | 336 else if (extension_->is_theme()) |
334 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; | 337 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_THEME; |
335 else | 338 else |
336 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; | 339 id = IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON_EXTENSION; |
337 return l10n_util::GetStringUTF16(id); | 340 return l10n_util::GetStringUTF16(id); |
341 } else if (type_ == POST_INSTALL_PERMISSIONS_PROMPT) { | |
342 int id = -1; | |
343 if (GetRetainedFileCount() && GetRetainedDeviceCount()) { | |
344 id = | |
345 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_AND_DEVICES_BUTT ON; | |
346 } else if (GetRetainedFileCount()) { | |
347 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON; | |
348 } else { | |
Finnur
2014/09/23 09:46:03
Ummm... Won't this use the RetainedDevices label w
Reilly Grant (use Gerrit)
2014/09/25 17:06:21
Since HasAcceptButtonLabel() will return false whe
| |
349 DCHECK_LT(0U, GetRetainedDeviceCount()); | |
350 id = IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_DEVICES_BUTTON; | |
351 } | |
352 return l10n_util::GetStringUTF16(id); | |
338 } | 353 } |
339 if (ShouldShowExplanationText()) | 354 if (ShouldShowExplanationText()) |
340 return experiment_->GetOkButtonText(); | 355 return experiment_->GetOkButtonText(); |
341 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); | 356 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); |
342 } | 357 } |
343 | 358 |
344 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { | 359 bool ExtensionInstallPrompt::Prompt::HasAbortButtonLabel() const { |
345 if (ShouldShowExplanationText()) | 360 if (ShouldShowExplanationText()) |
346 return true; | 361 return true; |
347 return kAbortButtonIds[type_] > 0; | 362 return kAbortButtonIds[type_] > 0; |
(...skipping 12 matching lines...) Expand all Loading... | |
360 | 375 |
361 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { | 376 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFilesHeading() const { |
362 const int kRetainedFilesMessageIDs[6] = { | 377 const int kRetainedFilesMessageIDs[6] = { |
363 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, | 378 IDS_EXTENSION_PROMPT_RETAINED_FILES_DEFAULT, |
364 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, | 379 IDS_EXTENSION_PROMPT_RETAINED_FILE_SINGULAR, |
365 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, | 380 IDS_EXTENSION_PROMPT_RETAINED_FILES_ZERO, |
366 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, | 381 IDS_EXTENSION_PROMPT_RETAINED_FILES_TWO, |
367 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, | 382 IDS_EXTENSION_PROMPT_RETAINED_FILES_FEW, |
368 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, | 383 IDS_EXTENSION_PROMPT_RETAINED_FILES_MANY, |
369 }; | 384 }; |
370 std::vector<int> message_ids; | 385 std::vector<int> message_ids( |
371 for (size_t i = 0; i < arraysize(kRetainedFilesMessageIDs); i++) { | 386 kRetainedFilesMessageIDs, |
372 message_ids.push_back(kRetainedFilesMessageIDs[i]); | 387 kRetainedFilesMessageIDs + arraysize(kRetainedFilesMessageIDs)); |
373 } | 388 |
374 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); | 389 return l10n_util::GetPluralStringFUTF16(message_ids, GetRetainedFileCount()); |
375 } | 390 } |
376 | 391 |
392 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDevicesHeading() | |
393 const { | |
394 const int kRetainedDevicesMessageIDs[6] = { | |
395 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_DEFAULT, | |
396 IDS_EXTENSION_PROMPT_RETAINED_DEVICE_SINGULAR, | |
397 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_ZERO, | |
398 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_TWO, | |
399 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_FEW, | |
400 IDS_EXTENSION_PROMPT_RETAINED_DEVICES_MANY, | |
401 }; | |
402 std::vector<int> message_ids( | |
403 kRetainedDevicesMessageIDs, | |
404 kRetainedDevicesMessageIDs + arraysize(kRetainedDevicesMessageIDs)); | |
405 | |
406 return l10n_util::GetPluralStringFUTF16(message_ids, | |
407 GetRetainedDeviceCount()); | |
408 } | |
409 | |
377 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { | 410 bool ExtensionInstallPrompt::Prompt::ShouldShowPermissions() const { |
378 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; | 411 return GetPermissionCount() > 0 || type_ == POST_INSTALL_PERMISSIONS_PROMPT; |
379 } | 412 } |
380 | 413 |
381 void ExtensionInstallPrompt::Prompt::AppendRatingStars( | 414 void ExtensionInstallPrompt::Prompt::AppendRatingStars( |
382 StarAppender appender, void* data) const { | 415 StarAppender appender, void* data) const { |
383 CHECK(appender); | 416 CHECK(appender); |
384 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); | 417 CHECK(type_ == INLINE_INSTALL_PROMPT || type_ == EXTERNAL_INSTALL_PROMPT); |
385 int rating_integer = floor(average_rating_); | 418 int rating_integer = floor(average_rating_); |
386 double rating_fractional = average_rating_ - rating_integer; | 419 double rating_fractional = average_rating_ - rating_integer; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 } | 477 } |
445 | 478 |
446 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( | 479 bool ExtensionInstallPrompt::Prompt::GetIsShowingDetails( |
447 DetailsType type, size_t index) const { | 480 DetailsType type, size_t index) const { |
448 switch (type) { | 481 switch (type) { |
449 case PERMISSIONS_DETAILS: | 482 case PERMISSIONS_DETAILS: |
450 CHECK_LT(index, is_showing_details_for_permissions_.size()); | 483 CHECK_LT(index, is_showing_details_for_permissions_.size()); |
451 return is_showing_details_for_permissions_[index]; | 484 return is_showing_details_for_permissions_[index]; |
452 case RETAINED_FILES_DETAILS: | 485 case RETAINED_FILES_DETAILS: |
453 return is_showing_details_for_retained_files_; | 486 return is_showing_details_for_retained_files_; |
487 case RETAINED_DEVICES_DETAILS: | |
488 return is_showing_details_for_retained_devices_; | |
454 } | 489 } |
455 return false; | 490 return false; |
456 } | 491 } |
457 | 492 |
458 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { | 493 size_t ExtensionInstallPrompt::Prompt::GetRetainedFileCount() const { |
459 return retained_files_.size(); | 494 return retained_files_.size(); |
460 } | 495 } |
461 | 496 |
462 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) | 497 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedFile(size_t index) |
463 const { | 498 const { |
464 CHECK_LT(index, retained_files_.size()); | 499 CHECK_LT(index, retained_files_.size()); |
465 return retained_files_[index].AsUTF16Unsafe(); | 500 return retained_files_[index].AsUTF16Unsafe(); |
466 } | 501 } |
467 | 502 |
468 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeFilesButton() const { | 503 size_t ExtensionInstallPrompt::Prompt::GetRetainedDeviceCount() const { |
469 return !retained_files_.empty(); | 504 return retained_device_messages_.size(); |
505 } | |
506 | |
507 bool ExtensionInstallPrompt::Prompt::ShouldDisplayRevokeButton() const { | |
508 return !retained_files_.empty() || !retained_device_messages_.empty(); | |
509 } | |
510 | |
511 base::string16 ExtensionInstallPrompt::Prompt::GetRetainedDeviceMessageString( | |
512 size_t index) const { | |
513 CHECK_LT(index, retained_device_messages_.size()); | |
514 return retained_device_messages_[index]; | |
470 } | 515 } |
471 | 516 |
472 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) | 517 ExtensionInstallPrompt::ShowParams::ShowParams(content::WebContents* contents) |
473 : parent_web_contents(contents), | 518 : parent_web_contents(contents), |
474 parent_window(NativeWindowForWebContents(contents)), | 519 parent_window(NativeWindowForWebContents(contents)), |
475 navigator(contents) { | 520 navigator(contents) { |
476 } | 521 } |
477 | 522 |
478 ExtensionInstallPrompt::ShowParams::ShowParams( | 523 ExtensionInstallPrompt::ShowParams::ShowParams( |
479 gfx::NativeWindow window, | 524 gfx::NativeWindow window, |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 permissions_ = permissions; | 700 permissions_ = permissions; |
656 delegate_ = delegate; | 701 delegate_ = delegate; |
657 prompt_ = new Prompt(PERMISSIONS_PROMPT); | 702 prompt_ = new Prompt(PERMISSIONS_PROMPT); |
658 | 703 |
659 LoadImageIfNeeded(); | 704 LoadImageIfNeeded(); |
660 } | 705 } |
661 | 706 |
662 void ExtensionInstallPrompt::ReviewPermissions( | 707 void ExtensionInstallPrompt::ReviewPermissions( |
663 Delegate* delegate, | 708 Delegate* delegate, |
664 const Extension* extension, | 709 const Extension* extension, |
665 const std::vector<base::FilePath>& retained_file_paths) { | 710 const std::vector<base::FilePath>& retained_file_paths, |
711 const std::vector<base::string16>& retained_device_messages) { | |
666 DCHECK(ui_loop_ == base::MessageLoop::current()); | 712 DCHECK(ui_loop_ == base::MessageLoop::current()); |
667 extension_ = extension; | 713 extension_ = extension; |
668 permissions_ = extension->permissions_data()->active_permissions(); | 714 permissions_ = extension->permissions_data()->active_permissions(); |
669 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); | 715 prompt_ = new Prompt(POST_INSTALL_PERMISSIONS_PROMPT); |
670 prompt_->set_retained_files(retained_file_paths); | 716 prompt_->set_retained_files(retained_file_paths); |
717 prompt_->set_retained_device_messages(retained_device_messages); | |
671 delegate_ = delegate; | 718 delegate_ = delegate; |
672 | 719 |
673 LoadImageIfNeeded(); | 720 LoadImageIfNeeded(); |
674 } | 721 } |
675 | 722 |
676 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 723 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
677 SkBitmap* icon) { | 724 SkBitmap* icon) { |
678 extension_ = extension; | 725 extension_ = extension; |
679 SetIcon(icon); | 726 SetIcon(icon); |
680 | 727 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 } | 823 } |
777 | 824 |
778 if (AutoConfirmPrompt(delegate_)) | 825 if (AutoConfirmPrompt(delegate_)) |
779 return; | 826 return; |
780 | 827 |
781 if (show_dialog_callback_.is_null()) | 828 if (show_dialog_callback_.is_null()) |
782 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 829 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
783 else | 830 else |
784 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 831 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
785 } | 832 } |
OLD | NEW |