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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc

Issue 6721013: extensions: Refactor ExtensionInstallUI class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indentation 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
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 "base/file_util.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
6 #include "base/string_util.h" 7 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
10 #include "chrome/browser/extensions/extension_install_dialog.h" 11 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/views/window.h" 13 #include "chrome/browser/ui/views/window.h"
13 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "views/controls/button/checkbox.h" 17 #include "views/controls/button/checkbox.h"
17 #include "views/controls/image_view.h" 18 #include "views/controls/image_view.h"
18 #include "views/controls/label.h" 19 #include "views/controls/label.h"
19 #include "views/controls/link.h" 20 #include "views/controls/link.h"
20 #include "views/layout/layout_constants.h" 21 #include "views/layout/layout_constants.h"
21 #include "views/view.h" 22 #include "views/view.h"
22 #include "views/window/dialog_delegate.h" 23 #include "views/window/dialog_delegate.h"
23 #include "views/window/window.h" 24 #include "views/window/window.h"
24 25
25 namespace { 26 namespace {
26 27
27 const int kRightColumnWidth = 210; 28 const int kRightColumnWidth = 210;
28 const int kIconSize = 69; 29 const int kIconSize = 69;
29 30
30 // Implements the extension installation prompt for Windows. 31 class ExtensionUninstallDialogView : public views::View,
31 class InstallDialogContent : public views::View, public views::DialogDelegate { 32 public views::DialogDelegate {
32 public: 33 public:
33 InstallDialogContent(ExtensionInstallUI::Delegate* delegate, 34 ExtensionUninstallDialogView(ExtensionUninstallDialog::Delegate* delegate,
34 const Extension* extension, 35 const Extension* extension,
35 SkBitmap* icon, 36 SkBitmap* icon)
36 ExtensionInstallUI::PromptType type) 37 : delegate_(delegate),
37 : delegate_(delegate), icon_(NULL), type_(type) { 38 icon_(NULL) {
38 // Scale down to icon size, but allow smaller icons (don't scale up). 39 // Scale down to icon size, but allow smaller icons (don't scale up).
39 gfx::Size size(icon->width(), icon->height()); 40 gfx::Size size(icon->width(), icon->height());
40 if (size.width() > kIconSize || size.height() > kIconSize) 41 if (size.width() > kIconSize || size.height() > kIconSize)
41 size = gfx::Size(kIconSize, kIconSize); 42 size = gfx::Size(kIconSize, kIconSize);
42 icon_ = new views::ImageView(); 43 icon_ = new views::ImageView();
43 icon_->SetImageSize(size); 44 icon_->SetImageSize(size);
44 icon_->SetImage(*icon); 45 icon_->SetImage(*icon);
45 AddChildView(icon_); 46 AddChildView(icon_);
46 47
47 heading_ = new views::Label(UTF16ToWide( 48 heading_ = new views::Label(UTF16ToWide(
48 l10n_util::GetStringFUTF16(ExtensionInstallUI::kHeadingIds[type_], 49 l10n_util::GetStringFUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING,
49 UTF8ToUTF16(extension->name())))); 50 UTF8ToUTF16(extension->name()))));
50 heading_->SetMultiLine(true); 51 heading_->SetMultiLine(true);
51 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 52 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
52 AddChildView(heading_); 53 AddChildView(heading_);
53 } 54 }
54 55
55 private: 56 private:
56 // DialogDelegate 57 // views::DialogDelegate:
57 virtual std::wstring GetDialogButtonLabel( 58 virtual std::wstring GetDialogButtonLabel(
58 MessageBoxFlags::DialogButton button) const { 59 MessageBoxFlags::DialogButton button) const OVERRIDE {
59 switch (button) { 60 switch (button) {
60 case MessageBoxFlags::DIALOGBUTTON_OK: 61 case MessageBoxFlags::DIALOGBUTTON_OK:
61 return UTF16ToWide( 62 return UTF16ToWide(
62 l10n_util::GetStringUTF16(ExtensionInstallUI::kButtonIds[type_])); 63 l10n_util::GetStringUTF16(
64 IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON));
63 case MessageBoxFlags::DIALOGBUTTON_CANCEL: 65 case MessageBoxFlags::DIALOGBUTTON_CANCEL:
64 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)); 66 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
65 default: 67 default:
66 NOTREACHED(); 68 NOTREACHED();
67 return L""; 69 return L"";
68 } 70 }
69 } 71 }
70 72
71 virtual int GetDefaultDialogButton() const { 73 virtual int GetDefaultDialogButton() const OVERRIDE {
72 return MessageBoxFlags::DIALOGBUTTON_CANCEL; 74 return MessageBoxFlags::DIALOGBUTTON_CANCEL;
73 } 75 }
74 76
75 virtual bool Accept() { 77 virtual bool Accept() OVERRIDE {
76 delegate_->InstallUIProceed(); 78 delegate_->ExtensionDialogAccepted();
77 return true; 79 return true;
78 } 80 }
79 81
80 virtual bool Cancel() { 82 virtual bool Cancel() OVERRIDE {
81 delegate_->InstallUIAbort(); 83 delegate_->ExtensionDialogCanceled();
82 return true; 84 return true;
83 } 85 }
84 86
85 // WindowDelegate 87 // views::WindowDelegate:
86 virtual bool IsModal() const { return true; } 88 virtual bool IsModal() const OVERRIDE { return true; }
87 virtual std::wstring GetWindowTitle() const { 89 virtual std::wstring GetWindowTitle() const OVERRIDE {
88 return UTF16ToWide( 90 return UTF16ToWide(
89 l10n_util::GetStringUTF16(ExtensionInstallUI::kTitleIds[type_])); 91 l10n_util::GetStringUTF16(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE));
90 } 92 }
91 virtual views::View* GetContentsView() { return this; } 93 virtual views::View* GetContentsView() { return this; }
92 94
93 // View 95 // views::View:
94 virtual gfx::Size GetPreferredSize() { 96 virtual gfx::Size GetPreferredSize() OVERRIDE {
95 int width = kRightColumnWidth; 97 int width = kRightColumnWidth;
96 width += kIconSize; 98 width += kIconSize;
97 width += views::kPanelHorizMargin * 3; 99 width += views::kPanelHorizMargin * 3;
98 100
99 int height = views::kPanelVertMargin * 2; 101 int height = views::kPanelVertMargin * 2;
100 height += heading_->GetHeightForWidth(kRightColumnWidth); 102 height += heading_->GetHeightForWidth(kRightColumnWidth);
101 103
102 return gfx::Size(width, 104 return gfx::Size(width,
103 std::max(height, kIconSize + views::kPanelVertMargin * 2)); 105 std::max(height, kIconSize + views::kPanelVertMargin * 2));
104 } 106 }
105 107
106 virtual void Layout() { 108 virtual void Layout() OVERRIDE {
107 int x = views::kPanelHorizMargin; 109 int x = views::kPanelHorizMargin;
108 int y = views::kPanelVertMargin; 110 int y = views::kPanelVertMargin;
109 111
110 heading_->SizeToFit(kRightColumnWidth); 112 heading_->SizeToFit(kRightColumnWidth);
111 113
112 if (heading_->height() <= kIconSize) { 114 if (heading_->height() <= kIconSize) {
113 icon_->SetBounds(x, y, kIconSize, kIconSize); 115 icon_->SetBounds(x, y, kIconSize, kIconSize);
114 x += kIconSize; 116 x += kIconSize;
115 x += views::kPanelHorizMargin; 117 x += views::kPanelHorizMargin;
116 118
117 heading_->SetX(x); 119 heading_->SetX(x);
118 heading_->SetY(y + (kIconSize - heading_->height()) / 2); 120 heading_->SetY(y + (kIconSize - heading_->height()) / 2);
119 } else { 121 } else {
120 icon_->SetBounds(x, 122 icon_->SetBounds(x,
121 y + (heading_->height() - kIconSize) / 2, 123 y + (heading_->height() - kIconSize) / 2,
122 kIconSize, 124 kIconSize,
123 kIconSize); 125 kIconSize);
124 x += kIconSize; 126 x += kIconSize;
125 x += views::kPanelHorizMargin; 127 x += views::kPanelHorizMargin;
126 128
127 heading_->SetX(x); 129 heading_->SetX(x);
128 heading_->SetY(y); 130 heading_->SetY(y);
129 } 131 }
130 } 132 }
131 133
132 ExtensionInstallUI::Delegate* delegate_; 134 ExtensionUninstallDialog::Delegate* delegate_;
133 views::ImageView* icon_; 135 views::ImageView* icon_;
134 views::Label* heading_; 136 views::Label* heading_;
135 ExtensionInstallUI::PromptType type_;
136 137
137 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); 138 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogView);
138 }; 139 };
139 140
140 } // namespace 141 } // namespace
141 142
142 void ShowExtensionInstallDialog(Profile* profile, 143 // static
143 ExtensionInstallUI::Delegate* delegate, 144 void ExtensionUninstallDialog::Show(
144 const Extension* extension, 145 Profile* profile,
145 SkBitmap* icon, 146 ExtensionUninstallDialog::Delegate* delegate,
146 ExtensionInstallUI::PromptType type) { 147 const Extension* extension,
148 SkBitmap* icon) {
147 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 149 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
148 if (!browser) { 150 if (!browser) {
149 delegate->InstallUIAbort(); 151 delegate->ExtensionDialogCanceled();
150 return; 152 return;
151 } 153 }
152 154
153 BrowserWindow* window = browser->window(); 155 BrowserWindow* window = browser->window();
154 if (!window) { 156 if (!window) {
155 delegate->InstallUIAbort(); 157 delegate->ExtensionDialogCanceled();
156 return; 158 return;
157 } 159 }
158 160
159 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(), 161 browser::CreateViewsWindow(window->GetNativeHandle(), gfx::Rect(),
160 new InstallDialogContent(delegate, extension, icon, type))->Show(); 162 new ExtensionUninstallDialogView(delegate, extension, icon))->Show();
161 } 163 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc ('k') | chrome/browser/ui/webui/app_launcher_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698