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

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

Issue 6721013: extensions: Refactor ExtensionInstallUI class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the file Created 9 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_generic_dialog.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_icon_set.h"
12 #include "chrome/common/extensions/extension_resource.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/resource/resource_bundle.h"
16
17 // Size of extension icon in top left of dialog.
18 static const int kIconSize = 69;
19
20 // static
21 const int ExtensionGenericDialog::kTitleIds[DIALOG_NUM_TYPES] = {
22 IDS_EXTENSION_UNINSTALL_PROMPT_TITLE,
23 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE
24 };
25 // static
26 const int ExtensionGenericDialog::kHeadingIds[DIALOG_NUM_TYPES] = {
27 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
28 IDS_EXTENSION_RE_ENABLE_PROMPT_HEADING
29 };
30 // static
31 const int ExtensionGenericDialog::kButtonIds[DIALOG_NUM_TYPES] = {
32 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON,
33 IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON
34 };
35
36 ExtensionGenericDialog::ExtensionGenericDialog(Profile* profile)
37 : profile_(profile),
38 ui_loop_(MessageLoop::current()),
39 delegate_(NULL),
40 extension_(NULL),
41 dialog_type_(DIALOG_NUM_TYPES),
42 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
43 }
44
45 ExtensionGenericDialog::~ExtensionGenericDialog() {
46 }
47
48 void ExtensionGenericDialog::ConfirmUninstall(Delegate* delegate,
49 const Extension* extension) {
50 DCHECK(ui_loop_ == MessageLoop::current());
51 delegate_ = delegate;
52 extension_ = extension;
53
54 ShowConfirmation(DIALOG_UNINSTALL);
55 }
56
57 void ExtensionGenericDialog::ConfirmReenable(Delegate* delegate,
58 const Extension* extension) {
59 DCHECK(ui_loop_ == MessageLoop::current());
60 delegate_ = delegate;
61 extension_ = extension;
62
63 ShowConfirmation(DIALOG_RE_ENABLE);
64 }
65
66 void ExtensionGenericDialog::ShowConfirmation(DialogType dialog_type) {
67 dialog_type_ = dialog_type;
68 ExtensionResource image =
69 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE,
70 ExtensionIconSet::MATCH_EXACTLY);
71 // Load the image asynchronously. The response will be sent to OnImageLoaded.
72 tracker_.LoadImage(extension_, image,
73 gfx::Size(kIconSize, kIconSize),
74 ImageLoadingTracker::DONT_CACHE);
75 }
76
77 void ExtensionGenericDialog::SetIcon(SkBitmap* image) {
78 if (image)
79 icon_ = *image;
80 else
81 icon_ = SkBitmap();
82 if (icon_.empty()) {
83 if (extension_->is_app()) {
84 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed(
85 IDR_APP_DEFAULT_ICON);
86 } else {
87 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed(
88 IDR_EXTENSION_DEFAULT_ICON);
89 }
90 }
91 }
92
93 void ExtensionGenericDialog::OnImageLoaded(SkBitmap* image,
94 const ExtensionResource& resource,
95 int index) {
96 SetIcon(image);
97
98 switch (dialog_type_) {
99 case DIALOG_UNINSTALL: {
100 Show(profile_, delegate_, extension_, &icon_, DIALOG_UNINSTALL);
101 break;
102 }
103 default:
104 NOTREACHED() << "Unknown message";
105 break;
106 }
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698