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

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

Issue 264763002: Support remote installation of extensions and apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/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_ui.h" 17 #include "chrome/browser/extensions/extension_install_ui.h"
18 #include "chrome/browser/extensions/image_loader.h" 18 #include "chrome/browser/extensions/image_loader.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" 24 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" 26 #include "components/signin/core/browser/profile_oauth2_token_service.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_view.h" 28 #include "content/public/browser/web_contents_view.h"
29 #include "extensions/browser/extension_prefs.h"
29 #include "extensions/common/constants.h" 30 #include "extensions/common/constants.h"
30 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
31 #include "extensions/common/extension_icon_set.h" 32 #include "extensions/common/extension_icon_set.h"
32 #include "extensions/common/extension_resource.h" 33 #include "extensions/common/extension_resource.h"
33 #include "extensions/common/feature_switch.h" 34 #include "extensions/common/feature_switch.h"
34 #include "extensions/common/manifest.h" 35 #include "extensions/common/manifest.h"
35 #include "extensions/common/manifest_constants.h" 36 #include "extensions/common/manifest_constants.h"
36 #include "extensions/common/manifest_handlers/icons_handler.h" 37 #include "extensions/common/manifest_handlers/icons_handler.h"
37 #include "extensions/common/permissions/permission_message_provider.h" 38 #include "extensions/common/permissions/permission_message_provider.h"
38 #include "extensions/common/permissions/permission_set.h" 39 #include "extensions/common/permissions/permission_set.h"
39 #include "extensions/common/permissions/permissions_data.h" 40 #include "extensions/common/permissions/permissions_data.h"
40 #include "extensions/common/url_pattern.h" 41 #include "extensions/common/url_pattern.h"
41 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
42 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
43 #include "grit/theme_resources.h" 44 #include "grit/theme_resources.h"
44 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/gfx/image/image.h" 47 #include "ui/gfx/image/image.h"
47 48
48 using extensions::BundleInstaller; 49 using extensions::BundleInstaller;
49 using extensions::Extension; 50 using extensions::Extension;
50 using extensions::Manifest; 51 using extensions::Manifest;
51 using extensions::PermissionSet; 52 using extensions::PermissionSet;
52 53
53 namespace { 54 namespace {
54 55
55 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 56 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
56 0, // The regular install prompt depends on what's being installed. 57 0, // The regular install prompt depends on what's being installed.
57 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, 58 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE,
58 IDS_EXTENSION_INSTALL_PROMPT_TITLE, 59 IDS_EXTENSION_INSTALL_PROMPT_TITLE,
59 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, 60 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE,
60 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE, 61 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE,
61 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE, 62 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_TITLE,
62 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE, 63 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_TITLE,
63 IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE, 64 IDS_EXTENSION_LAUNCH_APP_PROMPT_TITLE,
65 0, // The remote install prompt depends on what's being installed.
64 }; 66 };
65 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 67 static const int kHeadingIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
66 IDS_EXTENSION_INSTALL_PROMPT_HEADING, 68 IDS_EXTENSION_INSTALL_PROMPT_HEADING,
67 0, // Inline installs use the extension name. 69 0, // Inline installs use the extension name.
68 0, // Heading for bundle installs depends on the bundle contents. 70 0, // Heading for bundle installs depends on the bundle contents.
69 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, 71 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING,
70 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING, 72 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING,
71 0, // External installs use different strings for extensions/apps. 73 0, // External installs use different strings for extensions/apps.
72 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING, 74 IDS_EXTENSION_POST_INSTALL_PERMISSIONS_PROMPT_HEADING,
73 IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING, 75 IDS_EXTENSION_LAUNCH_APP_PROMPT_HEADING,
76 IDS_EXTENSION_REMOTE_INSTALL_PROMPT_HEADING,
74 }; 77 };
75 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 78 static const int kButtons[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
76 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 79 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
77 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 80 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
78 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 81 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
79 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 82 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
80 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 83 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
81 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 84 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
82 ui::DIALOG_BUTTON_CANCEL, 85 ui::DIALOG_BUTTON_CANCEL,
83 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL, 86 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
87 ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL,
84 }; 88 };
85 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 89 static const int kAcceptButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
86 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 90 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
87 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 91 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
88 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, 92 IDS_EXTENSION_PROMPT_INSTALL_BUTTON,
89 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, 93 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON,
90 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON, 94 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON,
91 0, // External installs use different strings for extensions/apps. 95 0, // External installs use different strings for extensions/apps.
92 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON, 96 IDS_EXTENSION_PROMPT_PERMISSIONS_CLEAR_RETAINED_FILES_BUTTON,
93 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON, 97 IDS_EXTENSION_PROMPT_LAUNCH_BUTTON,
98 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON,
94 }; 99 };
95 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 100 static const int kAbortButtonIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
96 0, // These all use the platform's default cancel label. 101 0, // These all use the platform's default cancel label.
97 0, 102 0,
98 0, 103 0,
99 0, 104 0,
100 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON, 105 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON,
101 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON, 106 IDS_EXTENSION_EXTERNAL_INSTALL_PROMPT_ABORT_BUTTON,
102 IDS_CLOSE, 107 IDS_CLOSE,
103 0, // Platform dependent cancel button. 108 0, // Platform dependent cancel button.
109 0,
104 }; 110 };
105 static const int kPermissionsHeaderIds[ 111 static const int
106 ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 112 kPermissionsHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
107 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 113 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
108 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 114 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
109 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO, 115 IDS_EXTENSION_PROMPT_THESE_WILL_HAVE_ACCESS_TO,
110 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, 116 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO,
111 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, 117 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO,
112 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 118 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
113 IDS_EXTENSION_PROMPT_CAN_ACCESS, 119 IDS_EXTENSION_PROMPT_CAN_ACCESS,
114 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, 120 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
121 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO,
115 }; 122 };
116 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { 123 static const int kOAuthHeaderIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = {
117 IDS_EXTENSION_PROMPT_OAUTH_HEADER, 124 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
118 0, // Inline installs don't show OAuth permissions. 125 0, // Inline installs don't show OAuth permissions.
119 0, // Bundle installs don't show OAuth permissions. 126 0, // Bundle installs don't show OAuth permissions.
120 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER, 127 IDS_EXTENSION_PROMPT_OAUTH_REENABLE_HEADER,
121 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER, 128 IDS_EXTENSION_PROMPT_OAUTH_PERMISSIONS_HEADER,
122 0, 129 0,
123 0, 130 0,
124 IDS_EXTENSION_PROMPT_OAUTH_HEADER, 131 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
132 IDS_EXTENSION_PROMPT_OAUTH_HEADER,
125 }; 133 };
126 134
127 // Size of extension icon in top left of dialog. 135 // Size of extension icon in top left of dialog.
128 const int kIconSize = 69; 136 const int kIconSize = 69;
129 137
130 // Returns pixel size under maximal scale factor for the icon whose device 138 // Returns pixel size under maximal scale factor for the icon whose device
131 // independent size is |size_in_dip| 139 // independent size is |size_in_dip|
132 int GetSizeForMaxScaleFactor(int size_in_dip) { 140 int GetSizeForMaxScaleFactor(int size_in_dip) {
133 return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale()); 141 return static_cast<int>(size_in_dip * gfx::ImageSkia::GetMaxSupportedScale());
134 } 142 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (type_ == INSTALL_PROMPT) { 281 if (type_ == INSTALL_PROMPT) {
274 if (extension_->is_app()) 282 if (extension_->is_app())
275 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE; 283 resource_id = IDS_EXTENSION_INSTALL_APP_PROMPT_TITLE;
276 else if (extension_->is_theme()) 284 else if (extension_->is_theme())
277 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE; 285 resource_id = IDS_EXTENSION_INSTALL_THEME_PROMPT_TITLE;
278 else 286 else
279 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE; 287 resource_id = IDS_EXTENSION_INSTALL_EXTENSION_PROMPT_TITLE;
280 } else if (type_ == EXTERNAL_INSTALL_PROMPT) { 288 } else if (type_ == EXTERNAL_INSTALL_PROMPT) {
281 return l10n_util::GetStringFUTF16( 289 return l10n_util::GetStringFUTF16(
282 resource_id, base::UTF8ToUTF16(extension_->name())); 290 resource_id, base::UTF8ToUTF16(extension_->name()));
291 } else if (type_ == REMOTE_INSTALL_PROMPT) {
292 if (extension_->is_app())
293 resource_id = IDS_EXTENSION_REMOTE_INSTALL_APP_PROMPT_TITLE;
294 else
295 resource_id = IDS_EXTENSION_REMOTE_INSTALL_EXTENSION_PROMPT_TITLE;
283 } 296 }
284 297
285 return l10n_util::GetStringUTF16(resource_id); 298 return l10n_util::GetStringUTF16(resource_id);
286 } 299 }
287 300
288 base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const { 301 base::string16 ExtensionInstallPrompt::Prompt::GetHeading() const {
289 if (type_ == INLINE_INSTALL_PROMPT) { 302 if (type_ == INLINE_INSTALL_PROMPT) {
290 return base::UTF8ToUTF16(extension_->name()); 303 return base::UTF8ToUTF16(extension_->name());
291 } else if (type_ == BUNDLE_INSTALL_PROMPT) { 304 } else if (type_ == BUNDLE_INSTALL_PROMPT) {
292 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING); 305 return bundle_->GetHeadingTextFor(BundleInstaller::Item::STATE_PENDING);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 647
635 LoadImageIfNeeded(); 648 LoadImageIfNeeded();
636 } 649 }
637 650
638 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, 651 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate,
639 const Extension* extension) { 652 const Extension* extension) {
640 DCHECK(ui_loop_ == base::MessageLoop::current()); 653 DCHECK(ui_loop_ == base::MessageLoop::current());
641 extension_ = extension; 654 extension_ = extension;
642 permissions_ = extension->GetActivePermissions(); 655 permissions_ = extension->GetActivePermissions();
643 delegate_ = delegate; 656 delegate_ = delegate;
644 prompt_.set_type(extension->is_ephemeral() ? LAUNCH_PROMPT : 657 int reasons = 0;
645 RE_ENABLE_PROMPT); 658 if (install_ui_->profile()) {
659 reasons = extensions::ExtensionPrefs::Get(install_ui_->profile())
660 ->GetDisableReasons(extension->id());
661 }
662 prompt_.set_type(extension->is_ephemeral()
663 ? LAUNCH_PROMPT
664 : reasons & extensions::Extension::DISABLE_REMOTE_INSTALL
665 ? REMOTE_INSTALL_PROMPT
666 : RE_ENABLE_PROMPT);
646 667
647 LoadImageIfNeeded(); 668 LoadImageIfNeeded();
648 } 669 }
649 670
650 void ExtensionInstallPrompt::ConfirmExternalInstall( 671 void ExtensionInstallPrompt::ConfirmExternalInstall(
651 Delegate* delegate, 672 Delegate* delegate,
652 const Extension* extension, 673 const Extension* extension,
653 const ShowDialogCallback& show_dialog_callback, 674 const ShowDialogCallback& show_dialog_callback,
654 const Prompt& prompt) { 675 const Prompt& prompt) {
655 DCHECK(ui_loop_ == base::MessageLoop::current()); 676 DCHECK(ui_loop_ == base::MessageLoop::current());
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 GetWarningMessagesDetails(permissions_, extension_type)); 841 GetWarningMessagesDetails(permissions_, extension_type));
821 } 842 }
822 843
823 switch (prompt_.type()) { 844 switch (prompt_.type()) {
824 case PERMISSIONS_PROMPT: 845 case PERMISSIONS_PROMPT:
825 case RE_ENABLE_PROMPT: 846 case RE_ENABLE_PROMPT:
826 case INLINE_INSTALL_PROMPT: 847 case INLINE_INSTALL_PROMPT:
827 case EXTERNAL_INSTALL_PROMPT: 848 case EXTERNAL_INSTALL_PROMPT:
828 case INSTALL_PROMPT: 849 case INSTALL_PROMPT:
829 case LAUNCH_PROMPT: 850 case LAUNCH_PROMPT:
830 case POST_INSTALL_PERMISSIONS_PROMPT: { 851 case POST_INSTALL_PERMISSIONS_PROMPT:
852 case REMOTE_INSTALL_PROMPT: {
831 prompt_.set_extension(extension_); 853 prompt_.set_extension(extension_);
832 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_)); 854 prompt_.set_icon(gfx::Image::CreateFrom1xBitmap(icon_));
833 break; 855 break;
834 } 856 }
835 case BUNDLE_INSTALL_PROMPT: { 857 case BUNDLE_INSTALL_PROMPT: {
836 prompt_.set_bundle(bundle_); 858 prompt_.set_bundle(bundle_);
837 break; 859 break;
838 } 860 }
839 default: 861 default:
840 NOTREACHED() << "Unknown message"; 862 NOTREACHED() << "Unknown message";
841 return; 863 return;
842 } 864 }
843 865
844 if (AutoConfirmPrompt(delegate_)) 866 if (AutoConfirmPrompt(delegate_))
845 return; 867 return;
846 868
847 if (show_dialog_callback_.is_null()) 869 if (show_dialog_callback_.is_null())
848 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 870 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
849 else 871 else
850 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 872 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
851 } 873 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698