OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DCHECK(hosts.size() == 0); | 120 DCHECK(hosts.size() == 0); |
121 if (extension->api_permissions().empty()) | 121 if (extension->api_permissions().empty()) |
122 return L""; | 122 return L""; |
123 else | 123 else |
124 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); | 124 return l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_NEW_BROWSER); |
125 } | 125 } |
126 | 126 |
127 } // namespace | 127 } // namespace |
128 | 128 |
129 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 129 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
130 : profile_(profile), ui_loop_(MessageLoop::current()) | 130 : profile_(profile), |
| 131 ui_loop_(MessageLoop::current()), |
| 132 extension_(NULL), |
| 133 delegate_(NULL), |
| 134 prompt_type_(NUM_PROMPT_TYPES), |
| 135 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) |
131 #if defined(TOOLKIT_GTK) | 136 #if defined(TOOLKIT_GTK) |
132 ,previous_use_gtk_theme_(false) | 137 , previous_use_gtk_theme_(false) |
133 #endif | 138 #endif |
134 {} | 139 {} |
135 | 140 |
136 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, | 141 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, |
137 Extension* extension, | 142 Extension* extension) { |
138 SkBitmap* install_icon) { | |
139 DCHECK(ui_loop_ == MessageLoop::current()); | 143 DCHECK(ui_loop_ == MessageLoop::current()); |
| 144 extension_ = extension; |
| 145 delegate_ = delegate; |
140 | 146 |
141 // We special-case themes to not show any confirm UI. Instead they are | 147 // We special-case themes to not show any confirm UI. Instead they are |
142 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 148 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
143 // to allow the user to revert if they don't like it. | 149 // to allow the user to revert if they don't like it. |
144 if (extension->IsTheme()) { | 150 if (extension->IsTheme()) { |
145 // Remember the current theme in case the user pressed undo. | 151 // Remember the current theme in case the user pressed undo. |
146 Extension* previous_theme = profile_->GetTheme(); | 152 Extension* previous_theme = profile_->GetTheme(); |
147 if (previous_theme) | 153 if (previous_theme) |
148 previous_theme_id_ = previous_theme->id(); | 154 previous_theme_id_ = previous_theme->id(); |
149 | 155 |
150 #if defined(TOOLKIT_GTK) | 156 #if defined(TOOLKIT_GTK) |
151 // On linux, we also need to take the user's system settings into account | 157 // On Linux, we also need to take the user's system settings into account |
152 // to undo theme installation. | 158 // to undo theme installation. |
153 previous_use_gtk_theme_ = | 159 previous_use_gtk_theme_ = |
154 GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); | 160 GtkThemeProvider::GetFrom(profile_)->UseGtkTheme(); |
155 #endif | 161 #endif |
156 | 162 |
157 delegate->InstallUIProceed(false); | 163 delegate->InstallUIProceed(false); |
158 return; | 164 return; |
159 } | 165 } |
160 | 166 |
161 if (!install_icon) { | 167 ShowConfirmation(INSTALL_PROMPT); |
162 install_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
163 IDR_EXTENSION_DEFAULT_ICON); | |
164 } | |
165 icon_ = *install_icon; | |
166 | |
167 NotificationService* service = NotificationService::current(); | |
168 service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, | |
169 Source<ExtensionInstallUI>(this), | |
170 NotificationService::NoDetails()); | |
171 | |
172 ShowExtensionInstallUIPromptImpl( | |
173 profile_, delegate, extension, &icon_, | |
174 WideToUTF16Hack(GetInstallWarning(extension)), INSTALL_PROMPT); | |
175 } | 168 } |
176 | 169 |
177 void ExtensionInstallUI::ConfirmUninstall(Delegate* delegate, | 170 void ExtensionInstallUI::ConfirmUninstall(Delegate* delegate, |
178 Extension* extension, | 171 Extension* extension) { |
179 SkBitmap* icon) { | |
180 DCHECK(ui_loop_ == MessageLoop::current()); | 172 DCHECK(ui_loop_ == MessageLoop::current()); |
| 173 extension_ = extension; |
| 174 delegate_ = delegate; |
181 | 175 |
182 if (!icon) { | 176 ShowConfirmation(UNINSTALL_PROMPT); |
183 icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
184 IDR_EXTENSION_DEFAULT_ICON); | |
185 } | |
186 | |
187 string16 message = | |
188 l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); | |
189 ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, | |
190 message, UNINSTALL_PROMPT); | |
191 } | 177 } |
192 | 178 |
193 void ExtensionInstallUI::ConfirmEnableIncognito(Delegate* delegate, | 179 void ExtensionInstallUI::ConfirmEnableIncognito(Delegate* delegate, |
194 Extension* extension, | 180 Extension* extension) { |
195 SkBitmap* icon) { | |
196 DCHECK(ui_loop_ == MessageLoop::current()); | 181 DCHECK(ui_loop_ == MessageLoop::current()); |
| 182 extension_ = extension; |
| 183 delegate_ = delegate; |
197 | 184 |
198 if (!icon) { | 185 ShowConfirmation(ENABLE_INCOGNITO_PROMPT); |
199 icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
200 IDR_EXTENSION_DEFAULT_ICON); | |
201 } | |
202 | |
203 string16 message = | |
204 l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, | |
205 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
206 ShowExtensionInstallUIPromptImpl(profile_, delegate, extension, icon, | |
207 message, ENABLE_INCOGNITO_PROMPT); | |
208 } | 186 } |
209 | 187 |
210 void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { | 188 void ExtensionInstallUI::OnInstallSuccess(Extension* extension) { |
211 if (extension->IsTheme()) { | 189 if (extension->IsTheme()) { |
212 ShowThemeInfoBar(extension); | 190 ShowThemeInfoBar(extension); |
213 return; | 191 return; |
214 } | 192 } |
215 | 193 |
216 // GetLastActiveWithProfile will fail on the build bots. This needs to | 194 // GetLastActiveWithProfile will fail on the build bots. This needs to be |
217 // implemented differently if any test is created which depends on | 195 // implemented differently if any test is created which depends on |
218 // ExtensionInstalledBubble showing. | 196 // ExtensionInstalledBubble showing. |
219 #if defined(TOOLKIT_VIEWS) | 197 #if defined(TOOLKIT_VIEWS) |
220 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 198 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
221 if (!browser) | 199 if (!browser) |
222 return; | 200 return; |
223 | 201 |
224 ExtensionInstalledBubble::Show(extension, browser, icon_); | 202 ExtensionInstalledBubble::Show(extension, browser, icon_); |
225 #elif defined(OS_MACOSX) | 203 #elif defined(OS_MACOSX) |
226 if (extension->browser_action() || | 204 if (extension->browser_action() || |
(...skipping 24 matching lines...) Expand all Loading... |
251 platform_util::SimpleErrorBox( | 229 platform_util::SimpleErrorBox( |
252 browser ? browser->window()->GetNativeHandle() : NULL, | 230 browser ? browser->window()->GetNativeHandle() : NULL, |
253 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_FAILURE_TITLE), | 231 l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_FAILURE_TITLE), |
254 UTF8ToUTF16(error)); | 232 UTF8ToUTF16(error)); |
255 } | 233 } |
256 | 234 |
257 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { | 235 void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { |
258 ShowThemeInfoBar(extension); | 236 ShowThemeInfoBar(extension); |
259 } | 237 } |
260 | 238 |
| 239 void ExtensionInstallUI::OnImageLoaded( |
| 240 SkBitmap* image, ExtensionResource resource, int index) { |
| 241 if (image) |
| 242 icon_ = *image; |
| 243 else |
| 244 icon_ = SkBitmap(); |
| 245 if (icon_.empty()) { |
| 246 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 247 IDR_EXTENSION_DEFAULT_ICON); |
| 248 } |
| 249 |
| 250 switch (prompt_type_) { |
| 251 case INSTALL_PROMPT: { |
| 252 NotificationService* service = NotificationService::current(); |
| 253 service->Notify(NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, |
| 254 Source<ExtensionInstallUI>(this), |
| 255 NotificationService::NoDetails()); |
| 256 |
| 257 ShowExtensionInstallUIPromptImpl( |
| 258 profile_, delegate_, extension_, &icon_, |
| 259 WideToUTF16Hack(GetInstallWarning(extension_)), INSTALL_PROMPT); |
| 260 break; |
| 261 } |
| 262 case UNINSTALL_PROMPT: { |
| 263 string16 message = |
| 264 l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_CONFIRMATION); |
| 265 ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, |
| 266 message, UNINSTALL_PROMPT); |
| 267 break; |
| 268 } |
| 269 case ENABLE_INCOGNITO_PROMPT: { |
| 270 string16 message = |
| 271 l10n_util::GetStringFUTF16(IDS_EXTENSION_PROMPT_WARNING_INCOGNITO, |
| 272 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 273 ShowExtensionInstallUIPromptImpl(profile_, delegate_, extension_, &icon_, |
| 274 message, ENABLE_INCOGNITO_PROMPT); |
| 275 break; |
| 276 } |
| 277 default: |
| 278 NOTREACHED() << "Unknown message"; |
| 279 break; |
| 280 } |
| 281 } |
| 282 |
261 void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { | 283 void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { |
262 if (!new_theme->IsTheme()) | 284 if (!new_theme->IsTheme()) |
263 return; | 285 return; |
264 | 286 |
265 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 287 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
266 if (!browser) | 288 if (!browser) |
267 return; | 289 return; |
268 | 290 |
269 TabContents* tab_contents = browser->GetSelectedTabContents(); | 291 TabContents* tab_contents = browser->GetSelectedTabContents(); |
270 if (!tab_contents) | 292 if (!tab_contents) |
(...skipping 12 matching lines...) Expand all Loading... |
283 // Then either replace that old one or add a new one. | 305 // Then either replace that old one or add a new one. |
284 InfoBarDelegate* new_delegate = GetNewInfoBarDelegate(new_theme, | 306 InfoBarDelegate* new_delegate = GetNewInfoBarDelegate(new_theme, |
285 tab_contents); | 307 tab_contents); |
286 | 308 |
287 if (old_delegate) | 309 if (old_delegate) |
288 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); | 310 tab_contents->ReplaceInfoBar(old_delegate, new_delegate); |
289 else | 311 else |
290 tab_contents->AddInfoBar(new_delegate); | 312 tab_contents->AddInfoBar(new_delegate); |
291 } | 313 } |
292 | 314 |
| 315 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { |
| 316 // Load the image asynchronously. For the response, check OnImageLoaded. |
| 317 prompt_type_ = prompt_type; |
| 318 ExtensionResource image = |
| 319 extension_->GetIconPath(Extension::EXTENSION_ICON_LARGE); |
| 320 tracker_.LoadImage(image, |
| 321 gfx::Size(Extension::EXTENSION_ICON_LARGE, |
| 322 Extension::EXTENSION_ICON_LARGE)); |
| 323 } |
| 324 |
293 #if defined(OS_MACOSX) | 325 #if defined(OS_MACOSX) |
294 void ExtensionInstallUI::ShowGenericExtensionInstalledInfoBar( | 326 void ExtensionInstallUI::ShowGenericExtensionInstalledInfoBar( |
295 Extension* new_extension) { | 327 Extension* new_extension) { |
296 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 328 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
297 if (!browser) | 329 if (!browser) |
298 return; | 330 return; |
299 | 331 |
300 TabContents* tab_contents = browser->GetSelectedTabContents(); | 332 TabContents* tab_contents = browser->GetSelectedTabContents(); |
301 if (!tab_contents) | 333 if (!tab_contents) |
302 return; | 334 return; |
(...skipping 10 matching lines...) Expand all Loading... |
313 InfoBarDelegate* ExtensionInstallUI::GetNewInfoBarDelegate( | 345 InfoBarDelegate* ExtensionInstallUI::GetNewInfoBarDelegate( |
314 Extension* new_theme, TabContents* tab_contents) { | 346 Extension* new_theme, TabContents* tab_contents) { |
315 #if defined(TOOLKIT_GTK) | 347 #if defined(TOOLKIT_GTK) |
316 return new GtkThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 348 return new GtkThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
317 previous_theme_id_, previous_use_gtk_theme_); | 349 previous_theme_id_, previous_use_gtk_theme_); |
318 #else | 350 #else |
319 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 351 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
320 previous_theme_id_); | 352 previous_theme_id_); |
321 #endif | 353 #endif |
322 } | 354 } |
OLD | NEW |