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

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

Issue 10010038: Do not show the install prompt for themes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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_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 15 matching lines...) Expand all
26 #include "chrome/browser/ui/browser_dialogs.h" 26 #include "chrome/browser/ui/browser_dialogs.h"
27 #include "chrome/browser/ui/browser_list.h" 27 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_navigator.h" 28 #include "chrome/browser/ui/browser_navigator.h"
29 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
31 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 31 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
32 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/extensions/extension.h" 34 #include "chrome/common/extensions/extension.h"
35 #include "chrome/common/extensions/extension_icon_set.h" 35 #include "chrome/common/extensions/extension_icon_set.h"
36 #include "chrome/common/extensions/extension_manifest_constants.h"
36 #include "chrome/common/extensions/extension_resource.h" 37 #include "chrome/common/extensions/extension_resource.h"
37 #include "chrome/common/extensions/url_pattern.h" 38 #include "chrome/common/extensions/url_pattern.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
39 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
40 #include "grit/chromium_strings.h" 41 #include "grit/chromium_strings.h"
41 #include "grit/generated_resources.h" 42 #include "grit/generated_resources.h"
42 #include "grit/theme_resources.h" 43 #include "grit/theme_resources.h"
43 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
45 #include "ui/gfx/image/image.h" 46 #include "ui/gfx/image/image.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 size_t ExtensionInstallUI::Prompt::GetPermissionCount() const { 205 size_t ExtensionInstallUI::Prompt::GetPermissionCount() const {
205 return permissions_.size(); 206 return permissions_.size();
206 } 207 }
207 208
208 string16 ExtensionInstallUI::Prompt::GetPermission(size_t index) const { 209 string16 ExtensionInstallUI::Prompt::GetPermission(size_t index) const {
209 CHECK_LT(index, permissions_.size()); 210 CHECK_LT(index, permissions_.size());
210 return l10n_util::GetStringFUTF16( 211 return l10n_util::GetStringFUTF16(
211 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]); 212 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]);
212 } 213 }
213 214
215 // static
216 scoped_refptr<Extension> ExtensionInstallUI::GetLocalizedExtensionForDisplay(
217 const DictionaryValue* manifest,
218 const std::string& id,
219 const std::string& localized_name,
220 const std::string& localized_description,
221 std::string* error) {
222 scoped_ptr<DictionaryValue> localized_manifest;
223 if (!localized_name.empty() || !localized_description.empty()) {
224 localized_manifest.reset(manifest->DeepCopy());
225 if (!localized_name.empty()) {
226 localized_manifest->SetString(extension_manifest_keys::kName,
227 localized_name);
228 }
229 if (!localized_description.empty()) {
230 localized_manifest->SetString(extension_manifest_keys::kDescription,
231 localized_description);
232 }
233 }
234
235 return Extension::Create(
236 FilePath(),
237 Extension::INTERNAL,
238 localized_manifest.get() ? *localized_manifest.get() : *manifest,
239 Extension::NO_FLAGS,
240 id,
241 error);
242 }
243
214 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) 244 ExtensionInstallUI::ExtensionInstallUI(Profile* profile)
215 : profile_(profile), 245 : profile_(profile),
216 ui_loop_(MessageLoop::current()), 246 ui_loop_(MessageLoop::current()),
217 previous_using_native_theme_(false), 247 previous_using_native_theme_(false),
218 extension_(NULL), 248 extension_(NULL),
219 delegate_(NULL), 249 delegate_(NULL),
220 prompt_type_(NUM_PROMPT_TYPES), 250 prompt_(UNSET_PROMPT_TYPE),
251 prompt_type_(UNSET_PROMPT_TYPE),
221 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), 252 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)),
222 use_app_installed_bubble_(false), 253 use_app_installed_bubble_(false),
223 skip_post_install_ui_(false) { 254 skip_post_install_ui_(false) {
224 // Remember the current theme in case the user presses undo. 255 // Remember the current theme in case the user presses undo.
225 if (profile_) { 256 if (profile_) {
226 const Extension* previous_theme = 257 const Extension* previous_theme =
227 ThemeServiceFactory::GetThemeForProfile(profile_); 258 ThemeServiceFactory::GetThemeForProfile(profile_);
228 if (previous_theme) 259 if (previous_theme)
229 previous_theme_id_ = previous_theme->id(); 260 previous_theme_id_ = previous_theme->id();
230 previous_using_native_theme_ = 261 previous_using_native_theme_ =
231 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme(); 262 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme();
232 } 263 }
233 } 264 }
234 265
235 ExtensionInstallUI::~ExtensionInstallUI() { 266 ExtensionInstallUI::~ExtensionInstallUI() {
236 } 267 }
237 268
269 void ExtensionInstallUI::ConfirmBundleInstall(
270 extensions::BundleInstaller* bundle,
271 const ExtensionPermissionSet* permissions) {
272 DCHECK(ui_loop_ == MessageLoop::current());
273 bundle_ = bundle;
274 permissions_ = permissions;
275 delegate_ = bundle;
276 prompt_type_ = BUNDLE_INSTALL_PROMPT;
277
278 ShowConfirmation();
279 }
280
281 void ExtensionInstallUI::ConfirmInlineInstall(
282 Delegate* delegate,
283 const Extension* extension,
284 SkBitmap* icon,
285 ExtensionInstallUI::Prompt prompt) {
286 DCHECK(ui_loop_ == MessageLoop::current());
287 extension_ = extension;
288 permissions_ = extension->GetActivePermissions();
289 delegate_ = delegate;
290 prompt_ = prompt;
291 prompt_type_ = INLINE_INSTALL_PROMPT;
292
293 SetIcon(icon);
294 ShowConfirmation();
295 }
296
297 void ExtensionInstallUI::ConfirmWebstoreInstall(Delegate* delegate,
298 const Extension* extension,
299 const SkBitmap* icon) {
300 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
301 // remaining fields.
302 extension_ = extension;
303 SetIcon(icon);
304 ConfirmInstall(delegate, extension);
305 }
306
238 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, 307 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate,
239 const Extension* extension) { 308 const Extension* extension) {
240 DCHECK(ui_loop_ == MessageLoop::current()); 309 DCHECK(ui_loop_ == MessageLoop::current());
241 extension_ = extension; 310 extension_ = extension;
242 permissions_ = extension->GetActivePermissions(); 311 permissions_ = extension->GetActivePermissions();
243 delegate_ = delegate; 312 delegate_ = delegate;
313 prompt_type_ = INSTALL_PROMPT;
244 314
245 // We special-case themes to not show any confirm UI. Instead they are 315 // We special-case themes to not show any confirm UI. Instead they are
246 // immediately installed, and then we show an infobar (see OnInstallSuccess) 316 // immediately installed, and then we show an infobar (see OnInstallSuccess)
247 // to allow the user to revert if they don't like it. 317 // to allow the user to revert if they don't like it.
248 if (extension->is_theme()) { 318 if (extension->is_theme()) {
249 delegate->InstallUIProceed(); 319 delegate->InstallUIProceed();
250 return; 320 return;
251 } 321 }
252 322
253 ShowConfirmation(INSTALL_PROMPT); 323 LoadImageIfNeeded();
254 } 324 }
255 325
256 void ExtensionInstallUI::ConfirmReEnable(Delegate* delegate, 326 void ExtensionInstallUI::ConfirmReEnable(Delegate* delegate,
257 const Extension* extension) { 327 const Extension* extension) {
258 DCHECK(ui_loop_ == MessageLoop::current()); 328 DCHECK(ui_loop_ == MessageLoop::current());
259 extension_ = extension; 329 extension_ = extension;
260 permissions_ = extension->GetActivePermissions(); 330 permissions_ = extension->GetActivePermissions();
261 delegate_ = delegate; 331 delegate_ = delegate;
332 prompt_type_ = RE_ENABLE_PROMPT;
262 333
263 ShowConfirmation(RE_ENABLE_PROMPT); 334 LoadImageIfNeeded();
264 } 335 }
265 336
266 void ExtensionInstallUI::ConfirmPermissions( 337 void ExtensionInstallUI::ConfirmPermissions(
267 Delegate* delegate, 338 Delegate* delegate,
268 const Extension* extension, 339 const Extension* extension,
269 const ExtensionPermissionSet* permissions) { 340 const ExtensionPermissionSet* permissions) {
270 DCHECK(ui_loop_ == MessageLoop::current()); 341 DCHECK(ui_loop_ == MessageLoop::current());
271 extension_ = extension; 342 extension_ = extension;
272 permissions_ = permissions; 343 permissions_ = permissions;
273 delegate_ = delegate; 344 delegate_ = delegate;
345 prompt_type_ = PERMISSIONS_PROMPT;
274 346
275 ShowConfirmation(PERMISSIONS_PROMPT); 347 LoadImageIfNeeded();
276 } 348 }
277 349
278 void ExtensionInstallUI::OnInstallSuccess(const Extension* extension, 350 void ExtensionInstallUI::OnInstallSuccess(const Extension* extension,
279 SkBitmap* icon) { 351 SkBitmap* icon) {
280 if (skip_post_install_ui_) 352 if (skip_post_install_ui_)
281 return; 353 return;
282 354
283 extension_ = extension; 355 extension_ = extension;
284 SetIcon(icon); 356 SetIcon(icon);
285 357
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 else 409 else
338 icon_ = SkBitmap(); 410 icon_ = SkBitmap();
339 if (icon_.empty()) 411 if (icon_.empty())
340 icon_ = Extension::GetDefaultIcon(extension_->is_app()); 412 icon_ = Extension::GetDefaultIcon(extension_->is_app());
341 } 413 }
342 414
343 void ExtensionInstallUI::OnImageLoaded(const gfx::Image& image, 415 void ExtensionInstallUI::OnImageLoaded(const gfx::Image& image,
344 const std::string& extension_id, 416 const std::string& extension_id,
345 int index) { 417 int index) {
346 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 418 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
347 419 ShowConfirmation();
348 switch (prompt_type_) {
349 case PERMISSIONS_PROMPT:
350 case RE_ENABLE_PROMPT:
351 case INSTALL_PROMPT: {
352 content::NotificationService* service =
353 content::NotificationService::current();
354 service->Notify(chrome::NOTIFICATION_EXTENSION_WILL_SHOW_CONFIRM_DIALOG,
355 content::Source<ExtensionInstallUI>(this),
356 content::NotificationService::NoDetails());
357
358 Prompt prompt(prompt_type_);
359 prompt.SetPermissions(permissions_->GetWarningMessages());
360 prompt.set_extension(extension_);
361 prompt.set_icon(gfx::Image(new SkBitmap(icon_)));
362 ShowExtensionInstallDialog(profile_, delegate_, prompt);
363 break;
364 }
365 default:
366 NOTREACHED() << "Unknown message";
367 break;
368 }
369 } 420 }
370 421
371 // static 422 // static
372 void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser, 423 void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser,
373 const std::string& app_id) { 424 const std::string& app_id) {
374 425
375 if (NewTabUI::ShouldShowApps()) { 426 if (NewTabUI::ShouldShowApps()) {
376 browser::NavigateParams params = browser->GetSingletonTabNavigateParams( 427 browser::NavigateParams params = browser->GetSingletonTabNavigateParams(
377 GURL(chrome::kChromeUINewTabURL)); 428 GURL(chrome::kChromeUINewTabURL));
378 browser::Navigate(&params); 429 browser::Navigate(&params);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Then either replace that old one or add a new one. 488 // Then either replace that old one or add a new one.
438 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( 489 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate(
439 tab_contents, new_theme, previous_theme_id, previous_using_native_theme); 490 tab_contents, new_theme, previous_theme_id, previous_using_native_theme);
440 491
441 if (old_delegate) 492 if (old_delegate)
442 infobar_helper->ReplaceInfoBar(old_delegate, new_delegate); 493 infobar_helper->ReplaceInfoBar(old_delegate, new_delegate);
443 else 494 else
444 infobar_helper->AddInfoBar(new_delegate); 495 infobar_helper->AddInfoBar(new_delegate);
445 } 496 }
446 497
447 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { 498 void ExtensionInstallUI::LoadImageIfNeeded() {
499 // Bundle install prompts do not have an icon.
500 if (!icon_.empty() || prompt_type_ == BUNDLE_INSTALL_PROMPT) {
Yoyo Zhou 2012/04/20 18:06:11 ...and you don't need to check for bundle here
jstritar 2012/04/20 18:08:39 oh yeah, thanks
501 ShowConfirmation();
502 return;
503 }
504
448 // Load the image asynchronously. For the response, check OnImageLoaded. 505 // Load the image asynchronously. For the response, check OnImageLoaded.
449 prompt_type_ = prompt_type;
450 ExtensionResource image = 506 ExtensionResource image =
451 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, 507 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE,
452 ExtensionIconSet::MATCH_BIGGER); 508 ExtensionIconSet::MATCH_BIGGER);
453 tracker_.LoadImage(extension_, image, 509 tracker_.LoadImage(extension_, image,
454 gfx::Size(kIconSize, kIconSize), 510 gfx::Size(kIconSize, kIconSize),
455 ImageLoadingTracker::DONT_CACHE); 511 ImageLoadingTracker::DONT_CACHE);
456 } 512 }
457 513
514 void ExtensionInstallUI::ShowConfirmation() {
515 prompt_.set_type(prompt_type_);
516 prompt_.SetPermissions(permissions_->GetWarningMessages());
517
518 switch (prompt_type_) {
519 case PERMISSIONS_PROMPT:
520 case RE_ENABLE_PROMPT:
521 case INLINE_INSTALL_PROMPT:
522 case INSTALL_PROMPT: {
523 prompt_.set_extension(extension_);
524 prompt_.set_icon(gfx::Image(new SkBitmap(icon_)));
525 ShowExtensionInstallDialog(profile_, delegate_, prompt_);
526 break;
527 }
528 case BUNDLE_INSTALL_PROMPT: {
529 prompt_.set_bundle(bundle_);
530 ShowExtensionInstallDialog(profile_, delegate_, prompt_);
531 break;
532 }
533 default:
534 NOTREACHED() << "Unknown message";
535 break;
536 }
537 }
538
458 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( 539 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate(
459 TabContentsWrapper* tab_contents, 540 TabContentsWrapper* tab_contents,
460 const Extension* new_theme, 541 const Extension* new_theme,
461 const std::string& previous_theme_id, 542 const std::string& previous_theme_id,
462 bool previous_using_native_theme) { 543 bool previous_using_native_theme) {
463 Profile* profile = tab_contents->profile(); 544 Profile* profile = tab_contents->profile();
464 return new ThemeInstalledInfoBarDelegate( 545 return new ThemeInstalledInfoBarDelegate(
465 tab_contents->infobar_tab_helper(), 546 tab_contents->infobar_tab_helper(),
466 profile->GetExtensionService(), 547 profile->GetExtensionService(),
467 ThemeServiceFactory::GetForProfile(profile), 548 ThemeServiceFactory::GetForProfile(profile),
468 new_theme, 549 new_theme,
469 previous_theme_id, 550 previous_theme_id,
470 previous_using_native_theme); 551 previous_using_native_theme);
471 } 552 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_ui.h ('k') | chrome/browser/extensions/extension_webstore_private_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698