| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ui.h" | 5 #include "chrome/browser/extensions/extension_install_ui.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 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 33 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
| 34 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
| 35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 36 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 const int ExtensionInstallUI::kTitleIds[NUM_PROMPT_TYPES] = { | 40 const int ExtensionInstallUI::kTitleIds[NUM_PROMPT_TYPES] = { |
| 41 IDS_EXTENSION_INSTALL_PROMPT_TITLE, | 41 IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
| 42 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE | 42 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
| 43 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE |
| 43 }; | 44 }; |
| 44 // static | 45 // static |
| 45 const int ExtensionInstallUI::kHeadingIds[NUM_PROMPT_TYPES] = { | 46 const int ExtensionInstallUI::kHeadingIds[NUM_PROMPT_TYPES] = { |
| 46 IDS_EXTENSION_INSTALL_PROMPT_HEADING, | 47 IDS_EXTENSION_INSTALL_PROMPT_HEADING, |
| 47 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING | 48 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING, |
| 49 IDS_EXTENSION_PERMISSIONS_PROMPT_HEADING |
| 48 }; | 50 }; |
| 49 // static | 51 // static |
| 50 const int ExtensionInstallUI::kButtonIds[NUM_PROMPT_TYPES] = { | 52 const int ExtensionInstallUI::kButtonIds[NUM_PROMPT_TYPES] = { |
| 51 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, | 53 IDS_EXTENSION_PROMPT_INSTALL_BUTTON, |
| 52 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON | 54 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON, |
| 55 IDS_EXTENSION_PROMPT_PERMISSIONS_BUTTON |
| 56 }; |
| 57 // static |
| 58 const int ExtensionInstallUI::kAbortButtonIds[NUM_PROMPT_TYPES] = { |
| 59 0, |
| 60 0, |
| 61 IDS_EXTENSION_PROMPT_PERMISSIONS_ABORT_BUTTON |
| 53 }; | 62 }; |
| 54 // static | 63 // static |
| 55 const int ExtensionInstallUI::kWarningIds[NUM_PROMPT_TYPES] = { | 64 const int ExtensionInstallUI::kWarningIds[NUM_PROMPT_TYPES] = { |
| 56 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 65 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
| 57 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO | 66 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
| 67 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
| 58 }; | 68 }; |
| 59 | 69 |
| 60 namespace { | 70 namespace { |
| 61 | 71 |
| 62 // Size of extension icon in top left of dialog. | 72 // Size of extension icon in top left of dialog. |
| 63 const int kIconSize = 69; | 73 const int kIconSize = 69; |
| 64 | 74 |
| 65 // Shows the application install animation on the new tab page for the app | 75 // Shows the application install animation on the new tab page for the app |
| 66 // with |app_id|. If a NTP already exists on the active |browser|, this will | 76 // with |app_id|. If a NTP already exists on the active |browser|, this will |
| 67 // select that tab and show the animation there. Otherwise, it will create | 77 // select that tab and show the animation there. Otherwise, it will create |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 115 } |
| 106 } | 116 } |
| 107 | 117 |
| 108 ExtensionInstallUI::~ExtensionInstallUI() { | 118 ExtensionInstallUI::~ExtensionInstallUI() { |
| 109 } | 119 } |
| 110 | 120 |
| 111 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, | 121 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, |
| 112 const Extension* extension) { | 122 const Extension* extension) { |
| 113 DCHECK(ui_loop_ == MessageLoop::current()); | 123 DCHECK(ui_loop_ == MessageLoop::current()); |
| 114 extension_ = extension; | 124 extension_ = extension; |
| 125 permissions_ = extension->GetActivePermissions(); |
| 115 delegate_ = delegate; | 126 delegate_ = delegate; |
| 116 | 127 |
| 117 // We special-case themes to not show any confirm UI. Instead they are | 128 // We special-case themes to not show any confirm UI. Instead they are |
| 118 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 129 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 119 // to allow the user to revert if they don't like it. | 130 // to allow the user to revert if they don't like it. |
| 120 if (extension->is_theme()) { | 131 if (extension->is_theme()) { |
| 121 delegate->InstallUIProceed(); | 132 delegate->InstallUIProceed(); |
| 122 return; | 133 return; |
| 123 } | 134 } |
| 124 | 135 |
| 125 ShowConfirmation(INSTALL_PROMPT); | 136 ShowConfirmation(INSTALL_PROMPT); |
| 126 } | 137 } |
| 127 | 138 |
| 128 void ExtensionInstallUI::ConfirmReEnable(Delegate* delegate, | 139 void ExtensionInstallUI::ConfirmReEnable(Delegate* delegate, |
| 129 const Extension* extension) { | 140 const Extension* extension) { |
| 130 DCHECK(ui_loop_ == MessageLoop::current()); | 141 DCHECK(ui_loop_ == MessageLoop::current()); |
| 131 extension_ = extension; | 142 extension_ = extension; |
| 143 permissions_ = extension->GetActivePermissions(); |
| 132 delegate_ = delegate; | 144 delegate_ = delegate; |
| 133 | 145 |
| 134 ShowConfirmation(RE_ENABLE_PROMPT); | 146 ShowConfirmation(RE_ENABLE_PROMPT); |
| 135 } | 147 } |
| 136 | 148 |
| 149 void ExtensionInstallUI::ConfirmPermissions( |
| 150 Delegate* delegate, |
| 151 const Extension* extension, |
| 152 const ExtensionPermissionSet* permissions) { |
| 153 DCHECK(ui_loop_ == MessageLoop::current()); |
| 154 extension_ = extension; |
| 155 permissions_ = permissions; |
| 156 delegate_ = delegate; |
| 157 |
| 158 ShowConfirmation(PERMISSIONS_PROMPT); |
| 159 } |
| 160 |
| 137 void ExtensionInstallUI::OnInstallSuccess(const Extension* extension, | 161 void ExtensionInstallUI::OnInstallSuccess(const Extension* extension, |
| 138 SkBitmap* icon) { | 162 SkBitmap* icon) { |
| 139 extension_ = extension; | 163 extension_ = extension; |
| 140 SetIcon(icon); | 164 SetIcon(icon); |
| 141 | 165 |
| 142 if (extension->is_theme()) { | 166 if (extension->is_theme()) { |
| 143 ShowThemeInfoBar(previous_theme_id_, previous_using_native_theme_, | 167 ShowThemeInfoBar(previous_theme_id_, previous_using_native_theme_, |
| 144 extension, profile_); | 168 extension, profile_); |
| 145 return; | 169 return; |
| 146 } | 170 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 icon_ = SkBitmap(); | 210 icon_ = SkBitmap(); |
| 187 if (icon_.empty()) | 211 if (icon_.empty()) |
| 188 icon_ = Extension::GetDefaultIcon(extension_->is_app()); | 212 icon_ = Extension::GetDefaultIcon(extension_->is_app()); |
| 189 } | 213 } |
| 190 | 214 |
| 191 void ExtensionInstallUI::OnImageLoaded( | 215 void ExtensionInstallUI::OnImageLoaded( |
| 192 SkBitmap* image, const ExtensionResource& resource, int index) { | 216 SkBitmap* image, const ExtensionResource& resource, int index) { |
| 193 SetIcon(image); | 217 SetIcon(image); |
| 194 | 218 |
| 195 switch (prompt_type_) { | 219 switch (prompt_type_) { |
| 220 case PERMISSIONS_PROMPT: |
| 196 case RE_ENABLE_PROMPT: | 221 case RE_ENABLE_PROMPT: |
| 197 case INSTALL_PROMPT: { | 222 case INSTALL_PROMPT: { |
| 198 // TODO(jcivelli): http://crbug.com/44771 We should not show an install | 223 // TODO(jcivelli): http://crbug.com/44771 We should not show an install |
| 199 // dialog when installing an app from the gallery. | 224 // dialog when installing an app from the gallery. |
| 200 NotificationService* service = NotificationService::current(); | 225 NotificationService* service = NotificationService::current(); |
| 201 service->Notify(chrome::NOTIFICATION_EXTENSION_WILL_SHOW_CONFIRM_DIALOG, | 226 service->Notify(chrome::NOTIFICATION_EXTENSION_WILL_SHOW_CONFIRM_DIALOG, |
| 202 Source<ExtensionInstallUI>(this), | 227 Source<ExtensionInstallUI>(this), |
| 203 NotificationService::NoDetails()); | 228 NotificationService::NoDetails()); |
| 204 | 229 |
| 205 std::vector<string16> warnings = | 230 std::vector<string16> warnings = |
| 206 extension_->GetPermissionMessageStrings(); | 231 permissions_->GetWarningMessages(); |
| 207 ShowExtensionInstallDialog( | 232 ShowExtensionInstallDialog( |
| 208 profile_, delegate_, extension_, &icon_, warnings, prompt_type_); | 233 profile_, delegate_, extension_, &icon_, warnings, prompt_type_); |
| 209 break; | 234 break; |
| 210 } | 235 } |
| 211 default: | 236 default: |
| 212 NOTREACHED() << "Unknown message"; | 237 NOTREACHED() << "Unknown message"; |
| 213 break; | 238 break; |
| 214 } | 239 } |
| 215 } | 240 } |
| 216 | 241 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 301 |
| 277 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 302 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
| 278 TabContents* tab_contents, | 303 TabContents* tab_contents, |
| 279 const Extension* new_theme, | 304 const Extension* new_theme, |
| 280 const std::string& previous_theme_id, | 305 const std::string& previous_theme_id, |
| 281 bool previous_using_native_theme) { | 306 bool previous_using_native_theme) { |
| 282 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 307 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
| 283 previous_theme_id, | 308 previous_theme_id, |
| 284 previous_using_native_theme); | 309 previous_using_native_theme); |
| 285 } | 310 } |
| OLD | NEW |