Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 11150002: New post-sideload UI: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: !!! Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
38 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
39 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
40 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/gfx/image/image.h" 41 #include "ui/gfx/image/image.h"
42 42
43 using extensions::BundleInstaller; 43 using extensions::BundleInstaller;
44 using extensions::Extension; 44 using extensions::Extension;
45 using extensions::PermissionSet; 45 using extensions::PermissionSet;
46 46
47 namespace {
48
47 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 49 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
48 0, // The regular install prompt depends on what's being installed. 50 0, // The regular install prompt depends on what's being installed.
49 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, 51 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE,
50 IDS_EXTENSION_INSTALL_PROMPT_TITLE, 52 IDS_EXTENSION_INSTALL_PROMPT_TITLE,
51 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, 53 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE,
52 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE 54 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE,
55 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE,
53 }; 56 };
54 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 57 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
55 IDS_EXTENSION_INSTALL_PROMPT_HEADING, 58 IDS_EXTENSION_INSTALL_PROMPT_HEADING,
56 0, // Inline installs use the extension name. 59 0, // Inline installs use the extension name.
57 0, // Heading for bundle installs depends on the bundle contents. 60 0, // Heading for bundle installs depends on the bundle contents.
58 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, 61 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING,
59 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING 62 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING,
63 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_HEADING,
60 }; 64 };
61 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 65 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
62 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 66 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
63 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 67 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
64 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 68 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
65 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, 69 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
66 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON 70 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
71 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ACCEPT_BUTTON,
67 }; 72 };
68 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 73 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
69 0, // These all use the platform's default cancel label. 74 0, // These all use the platform's default cancel label.
70 0, 75 0,
71 0, 76 0,
72 0, 77 0,
73 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON 78 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
79 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON,
74 }; 80 };
75 static const int kPermissionsHeaderIds[ 81 static const int kPermissionsHeaderIds[
76 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 82 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
77 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 83 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
78 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 84 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
79 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, 85 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO,
80 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, 86 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO,
81 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, 87 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO,
88 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
82 }; 89 };
83 static const int kOAuthHeaderIds[ 90 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
84 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
85 IDS_EXTENSION_PROMPT_OAUTH_HEADER, 91 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
86 0, // Inline installs don't show OAuth permissions. 92 0, // Inline installs don't show OAuth permissions.
87 0, // Bundle installs don't show OAuth permissions. 93 0, // Bundle installs don't show OAuth permissions.
88 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, 94 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER,
89 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, 95 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER,
96 // TODO(mpcomplete): Do we need this for external install UI? If we do,
97 // we need to update FetchOAuthIssueAdviceIfNeeded.
98 0,
90 }; 99 };
91 100
92 namespace {
93
94 // Size of extension icon in top left of dialog. 101 // Size of extension icon in top left of dialog.
95 const int kIconSize = 69; 102 const int kIconSize = 69;
96 103
97 // Returns pixel size under maximal scale factor for the icon whose device 104 // Returns pixel size under maximal scale factor for the icon whose device
98 // independent size is |size_in_dip| 105 // independent size is |size_in_dip|
99 int GetSizeForMaxScaleFactor(int size_in_dip) { 106 int GetSizeForMaxScaleFactor(int size_in_dip) {
100 std::vector<ui::ScaleFactor> supported_scale_factors = 107 std::vector<ui::ScaleFactor> supported_scale_factors =
101 ui::GetSupportedScaleFactors(); 108 ui::GetSupportedScaleFactors();
102 // Scale factors are in ascending order, so the last one is the one we need. 109 // Scale factors are in ascending order, so the last one is the one we need.
103 ui::ScaleFactor max_scale_factor = supported_scale_factors.back(); 110 ui::ScaleFactor max_scale_factor = supported_scale_factors.back();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const { 196 string16 ExtensionInstallPrompt::Prompt::GetDialogTitle() const {
190 int resource_id = kTitleIds[type_]; 197 int resource_id = kTitleIds[type_];
191 198
192 if (type_ == INSTALL_PROMPT) { 199 if (type_ == INSTALL_PROMPT) {
193 if (extension_->is_app()) 200 if (extension_->is_app())
194 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; 201 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE;
195 else if (extension_->is_theme()) 202 else if (extension_->is_theme())
196 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; 203 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE;
197 else 204 else
198 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; 205 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE;
206 } else if (type_ == EXTERNAL_INSTALL_PROMPT) {
207 return l10n_util::GetStringFUTF16(
208 resource_id, UTF8ToUTF16(extension_->name()));
199 } 209 }
200 210
201 return l10n_util::GetStringUTF16(resource_id); 211 return l10n_util::GetStringUTF16(resource_id);
202 } 212 }
203 213
204 string16 ExtensionInstallPrompt::Prompt::GetHeading() const { 214 string16 ExtensionInstallPrompt::Prompt::GetHeading() const {
205 if (type_ == INLINE_INSTALL_PROMPT) { 215 if (type_ == INLINE_INSTALL_PROMPT) {
206 return UTF8ToUTF16(extension_->name()); 216 return UTF8ToUTF16(extension_->name());
207 } else if (type_ == BUNDLE_INSTALL_PROMPT) { 217 } else if (type_ == BUNDLE_INSTALL_PROMPT) {
208 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); 218 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING);
219 } else if (type_ == EXTERNAL_INSTALL_PROMPT) {
220 return l10n_util::GetStringUTF16(kHeadingIds[type_]);
209 } else { 221 } else {
210 return l10n_util::GetStringFUTF16( 222 return l10n_util::GetStringFUTF16(
211 kHeadingIds[type_], UTF8ToUTF16(extension_->name())); 223 kHeadingIds[type_], UTF8ToUTF16(extension_->name()));
212 } 224 }
213 } 225 }
214 226
215 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const { 227 string16 ExtensionInstallPrompt::Prompt::GetAcceptButtonLabel() const {
216 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]); 228 return l10n_util::GetStringUTF16(kAcceptButtonIds[type_]);
217 } 229 }
218 230
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 const Extension* extension) { 437 const Extension* extension) {
426 DCHECK(ui_loop_ == MessageLoop::current()); 438 DCHECK(ui_loop_ == MessageLoop::current());
427 extension_ = extension; 439 extension_ = extension;
428 permissions_ = extension->GetActivePermissions(); 440 permissions_ = extension->GetActivePermissions();
429 delegate_ = delegate; 441 delegate_ = delegate;
430 prompt_type_ = RE_ENABLE_PROMPT; 442 prompt_type_ = RE_ENABLE_PROMPT;
431 443
432 LoadImageIfNeeded(); 444 LoadImageIfNeeded();
433 } 445 }
434 446
447 void ExtensionInstallPrompt::ConfirmExternalInstall(
448 Delegate* delegate, const Extension* extension) {
449 DCHECK(ui_loop_ == MessageLoop::current());
450 extension_ = extension;
451 permissions_ = extension->GetActivePermissions();
452 delegate_ = delegate;
453 prompt_type_ = EXTERNAL_INSTALL_PROMPT;
454
455 LoadImageIfNeeded();
456 }
457
435 void ExtensionInstallPrompt::ConfirmPermissions( 458 void ExtensionInstallPrompt::ConfirmPermissions(
436 Delegate* delegate, 459 Delegate* delegate,
437 const Extension* extension, 460 const Extension* extension,
438 const PermissionSet* permissions) { 461 const PermissionSet* permissions) {
439 DCHECK(ui_loop_ == MessageLoop::current()); 462 DCHECK(ui_loop_ == MessageLoop::current());
440 extension_ = extension; 463 extension_ = extension;
441 permissions_ = permissions; 464 permissions_ = permissions;
442 delegate_ = delegate; 465 delegate_ = delegate;
443 prompt_type_ = PERMISSIONS_PROMPT; 466 prompt_type_ = PERMISSIONS_PROMPT;
444 467
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 tracker_.LoadImage(extension_, image, 535 tracker_.LoadImage(extension_, image,
513 gfx::Size(pixel_size, pixel_size), 536 gfx::Size(pixel_size, pixel_size),
514 ImageLoadingTracker::DONT_CACHE); 537 ImageLoadingTracker::DONT_CACHE);
515 } 538 }
516 539
517 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { 540 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() {
518 // |extension_| may be NULL, e.g. in the bundle install case. 541 // |extension_| may be NULL, e.g. in the bundle install case.
519 if (!extension_ || 542 if (!extension_ ||
520 prompt_type_ == BUNDLE_INSTALL_PROMPT || 543 prompt_type_ == BUNDLE_INSTALL_PROMPT ||
521 prompt_type_ == INLINE_INSTALL_PROMPT || 544 prompt_type_ == INLINE_INSTALL_PROMPT ||
545 prompt_type_ == EXTERNAL_INSTALL_PROMPT ||
522 prompt_.GetOAuthIssueCount() != 0U) { 546 prompt_.GetOAuthIssueCount() != 0U) {
523 ShowConfirmation(); 547 ShowConfirmation();
524 return; 548 return;
525 } 549 }
526 550
527 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info(); 551 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info();
528 if (oauth2_info.client_id.empty() || 552 if (oauth2_info.client_id.empty() ||
529 oauth2_info.scopes.empty()) { 553 oauth2_info.scopes.empty()) {
530 ShowConfirmation(); 554 ShowConfirmation();
531 return; 555 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if (permissions_) { 588 if (permissions_) {
565 Extension::Type extension_type = extension_ ? extension_->GetType() : 589 Extension::Type extension_type = extension_ ? extension_->GetType() :
566 Extension::TYPE_UNKNOWN; 590 Extension::TYPE_UNKNOWN;
567 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); 591 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type));
568 } 592 }
569 593
570 switch (prompt_type_) { 594 switch (prompt_type_) {
571 case PERMISSIONS_PROMPT: 595 case PERMISSIONS_PROMPT:
572 case RE_ENABLE_PROMPT: 596 case RE_ENABLE_PROMPT:
573 case INLINE_INSTALL_PROMPT: 597 case INLINE_INSTALL_PROMPT:
598 case EXTERNAL_INSTALL_PROMPT:
574 case INSTALL_PROMPT: { 599 case INSTALL_PROMPT: {
575 prompt_.set_extension(extension_); 600 prompt_.set_extension(extension_);
576 prompt_.set_icon(gfx::Image(icon_)); 601 prompt_.set_icon(gfx::Image(icon_));
577 break; 602 break;
578 } 603 }
579 case BUNDLE_INSTALL_PROMPT: { 604 case BUNDLE_INSTALL_PROMPT: {
580 prompt_.set_bundle(bundle_); 605 prompt_.set_bundle(bundle_);
581 break; 606 break;
582 } 607 }
583 default: 608 default:
(...skipping 16 matching lines...) Expand all
600 Browser* browser) { 625 Browser* browser) {
601 // |browser| can be NULL in unit tests. 626 // |browser| can be NULL in unit tests.
602 if (!browser) 627 if (!browser)
603 return new ExtensionInstallPrompt(NULL, NULL, NULL); 628 return new ExtensionInstallPrompt(NULL, NULL, NULL);
604 gfx::NativeWindow parent = 629 gfx::NativeWindow parent =
605 browser->window() ? browser->window()->GetNativeWindow() : NULL; 630 browser->window() ? browser->window()->GetNativeWindow() : NULL;
606 return new ExtensionInstallPrompt(parent, browser, browser->profile()); 631 return new ExtensionInstallPrompt(parent, browser, browser->profile());
607 } 632 }
608 633
609 } // namespace chrome 634 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698