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

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

Issue 382133003: Refactored ExtensionUninstallDialog to take a NativeWindow instead of a Browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved Browser and GetParent() logic into constructor Created 6 years, 5 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_uninstall_dialog.h" 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/app_list/app_list_service.h" 11 #include "chrome/browser/ui/app_list/app_list_service.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/views/constrained_window_views.h" 13 #include "chrome/browser/ui/views/constrained_window_views.h"
15 #include "extensions/common/extension.h" 14 #include "extensions/common/extension.h"
16 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
17 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/compositor/compositor.h" 17 #include "ui/compositor/compositor.h"
19 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
20 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
21 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
22 #include "ui/views/layout/layout_constants.h" 21 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/view.h" 22 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
25 #include "ui/views/window/dialog_delegate.h" 24 #include "ui/views/window/dialog_delegate.h"
26 25
27 namespace { 26 namespace {
28 27
29 const int kRightColumnWidth = 210; 28 const int kRightColumnWidth = 210;
30 const int kIconSize = 64; 29 const int kIconSize = 64;
31 30
32 class ExtensionUninstallDialogDelegateView; 31 class ExtensionUninstallDialogDelegateView;
33 32
34 // Returns parent window for extension uninstall dialog.
35 gfx::NativeWindow GetParent(Browser* browser) {
36 if (browser && browser->window())
37 return browser->window()->GetNativeWindow();
38 return NULL;
39 }
40
41 // Views implementation of the uninstall dialog. 33 // Views implementation of the uninstall dialog.
42 class ExtensionUninstallDialogViews 34 class ExtensionUninstallDialogViews
43 : public extensions::ExtensionUninstallDialog { 35 : public extensions::ExtensionUninstallDialog {
44 public: 36 public:
45 ExtensionUninstallDialogViews( 37 ExtensionUninstallDialogViews(
46 Profile* profile, 38 Profile* profile,
47 Browser* browser, 39 Browser* browser,
40 gfx::NativeWindow parent,
48 extensions::ExtensionUninstallDialog::Delegate* delegate); 41 extensions::ExtensionUninstallDialog::Delegate* delegate);
49 virtual ~ExtensionUninstallDialogViews(); 42 virtual ~ExtensionUninstallDialogViews();
50 43
51 // Forwards the accept and cancels to the delegate. 44 // Forwards the accept and cancels to the delegate.
52 void ExtensionUninstallAccepted(); 45 void ExtensionUninstallAccepted();
53 void ExtensionUninstallCanceled(); 46 void ExtensionUninstallCanceled();
54 47
55 ExtensionUninstallDialogDelegateView* view() { return view_; } 48 ExtensionUninstallDialogDelegateView* view() { return view_; }
56 49
57 private: 50 private:
58 virtual void Show() OVERRIDE; 51 virtual void Show() OVERRIDE;
59 52
60 ExtensionUninstallDialogDelegateView* view_; 53 ExtensionUninstallDialogDelegateView* view_;
61 bool show_in_app_list_;
62 54
63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); 55 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
64 }; 56 };
65 57
66 // The dialog's view, owned by the views framework. 58 // The dialog's view, owned by the views framework.
67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { 59 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
68 public: 60 public:
69 ExtensionUninstallDialogDelegateView( 61 ExtensionUninstallDialogDelegateView(
70 ExtensionUninstallDialogViews* dialog_view, 62 ExtensionUninstallDialogViews* dialog_view,
71 const extensions::Extension* extension, 63 const extensions::Extension* extension,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 views::ImageView* icon_; 97 views::ImageView* icon_;
106 views::Label* heading_; 98 views::Label* heading_;
107 bool triggered_by_extension_; 99 bool triggered_by_extension_;
108 100
109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); 101 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
110 }; 102 };
111 103
112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( 104 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
113 Profile* profile, 105 Profile* profile,
114 Browser* browser, 106 Browser* browser,
107 gfx::NativeWindow parent,
115 extensions::ExtensionUninstallDialog::Delegate* delegate) 108 extensions::ExtensionUninstallDialog::Delegate* delegate)
116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), 109 : extensions::ExtensionUninstallDialog(profile, browser, parent, delegate),
117 view_(NULL), 110 view_(NULL) {
118 show_in_app_list_(!browser) {
119 } 111 }
120 112
121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { 113 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
122 // Close the widget (the views framework will delete view_). 114 // Close the widget (the views framework will delete view_).
123 if (view_) { 115 if (view_) {
124 view_->DialogDestroyed(); 116 view_->DialogDestroyed();
125 view_->GetWidget()->CloseNow(); 117 view_->GetWidget()->CloseNow();
126 } 118 }
127 } 119 }
128 120
129 void ExtensionUninstallDialogViews::Show() { 121 void ExtensionUninstallDialogViews::Show() {
130 // TODO(tapted): A true |desktop_type| needs to be passed in at creation time
131 // to remove reliance on GetActiveDesktop(). http://crbug.com/308360
132 gfx::NativeWindow parent = show_in_app_list_ ?
133 AppListService::Get(chrome::GetActiveDesktop())->GetAppListWindow() :
134 GetParent(browser_);
135 if (browser_ && !parent) {
136 delegate_->ExtensionUninstallCanceled();
137 return;
138 }
139
140 view_ = new ExtensionUninstallDialogDelegateView( 122 view_ = new ExtensionUninstallDialogDelegateView(
141 this, extension_, triggering_extension_, &icon_); 123 this, extension_, triggering_extension_, &icon_);
142 CreateBrowserModalDialogViews(view_, parent)->Show(); 124 CreateBrowserModalDialogViews(view_, parent_)->Show();
143 } 125 }
144 126
145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { 127 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
146 // The widget gets destroyed when the dialog is accepted. 128 // The widget gets destroyed when the dialog is accepted.
147 view_ = NULL; 129 view_ = NULL;
148 delegate_->ExtensionUninstallAccepted(); 130 delegate_->ExtensionUninstallAccepted();
149 } 131 }
150 132
151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { 133 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
152 // The widget gets destroyed when the dialog is canceled. 134 // The widget gets destroyed when the dialog is canceled.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 222 }
241 } 223 }
242 224
243 } // namespace 225 } // namespace
244 226
245 // static 227 // static
246 extensions::ExtensionUninstallDialog* 228 extensions::ExtensionUninstallDialog*
247 extensions::ExtensionUninstallDialog::Create(Profile* profile, 229 extensions::ExtensionUninstallDialog::Create(Profile* profile,
248 Browser* browser, 230 Browser* browser,
249 Delegate* delegate) { 231 Delegate* delegate) {
250 return new ExtensionUninstallDialogViews(profile, browser, delegate); 232 return new ExtensionUninstallDialogViews(profile, browser, NULL, delegate);
251 } 233 }
234
235 // static
236 extensions::ExtensionUninstallDialog*
237 extensions::ExtensionUninstallDialog::CreateModal(Profile* profile,
238 gfx::NativeWindow parent,
239 Delegate* delegate) {
240 return new ExtensionUninstallDialogViews(profile, NULL, parent, delegate);
241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698