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

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: Added CreateAsStandaloneDialog for extension_storage_monitor 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"
(...skipping 24 matching lines...) Expand all
35 gfx::NativeWindow GetParent(Browser* browser) { 35 gfx::NativeWindow GetParent(Browser* browser) {
36 if (browser && browser->window()) 36 if (browser && browser->window())
37 return browser->window()->GetNativeWindow(); 37 return browser->window()->GetNativeWindow();
38 return NULL; 38 return NULL;
39 } 39 }
40 40
41 // Views implementation of the uninstall dialog. 41 // Views implementation of the uninstall dialog.
42 class ExtensionUninstallDialogViews 42 class ExtensionUninstallDialogViews
43 : public extensions::ExtensionUninstallDialog { 43 : public extensions::ExtensionUninstallDialog {
44 public: 44 public:
45 // If |browser| is set, it will be used as the browser window that this dialog
46 // is launched from. If |parent| is set, it it used as the parent of the
47 // dialog instead. If both |browser| and |parent| are NULL, this is launched
48 // as a standalone window. Only at most one of |browser| and |parent| should
49 // be set.
45 ExtensionUninstallDialogViews( 50 ExtensionUninstallDialogViews(
46 Profile* profile, 51 Profile* profile,
47 Browser* browser, 52 Browser* browser,
53 gfx::NativeWindow parent,
48 extensions::ExtensionUninstallDialog::Delegate* delegate); 54 extensions::ExtensionUninstallDialog::Delegate* delegate);
49 virtual ~ExtensionUninstallDialogViews(); 55 virtual ~ExtensionUninstallDialogViews();
50 56
51 // Forwards the accept and cancels to the delegate. 57 // Forwards the accept and cancels to the delegate.
52 void ExtensionUninstallAccepted(); 58 void ExtensionUninstallAccepted();
53 void ExtensionUninstallCanceled(); 59 void ExtensionUninstallCanceled();
54 60
55 ExtensionUninstallDialogDelegateView* view() { return view_; } 61 ExtensionUninstallDialogDelegateView* view() { return view_; }
56 62
57 private: 63 private:
58 virtual void Show() OVERRIDE; 64 virtual void Show() OVERRIDE;
59 65
60 ExtensionUninstallDialogDelegateView* view_; 66 ExtensionUninstallDialogDelegateView* view_;
61 bool show_in_app_list_; 67 gfx::NativeWindow parent_;
62 68
63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); 69 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
64 }; 70 };
65 71
66 // The dialog's view, owned by the views framework. 72 // The dialog's view, owned by the views framework.
67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { 73 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
68 public: 74 public:
69 ExtensionUninstallDialogDelegateView( 75 ExtensionUninstallDialogDelegateView(
70 ExtensionUninstallDialogViews* dialog_view, 76 ExtensionUninstallDialogViews* dialog_view,
71 const extensions::Extension* extension, 77 const extensions::Extension* extension,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 views::ImageView* icon_; 111 views::ImageView* icon_;
106 views::Label* heading_; 112 views::Label* heading_;
107 bool triggered_by_extension_; 113 bool triggered_by_extension_;
108 114
109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); 115 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
110 }; 116 };
111 117
112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( 118 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
113 Profile* profile, 119 Profile* profile,
114 Browser* browser, 120 Browser* browser,
121 gfx::NativeWindow parent,
115 extensions::ExtensionUninstallDialog::Delegate* delegate) 122 extensions::ExtensionUninstallDialog::Delegate* delegate)
116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), 123 : extensions::ExtensionUninstallDialog(profile, browser, delegate),
117 view_(NULL), 124 view_(NULL),
118 show_in_app_list_(!browser) { 125 parent_(parent) {
119 } 126 }
120 127
121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { 128 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
122 // Close the widget (the views framework will delete view_). 129 // Close the widget (the views framework will delete view_).
123 if (view_) { 130 if (view_) {
124 view_->DialogDestroyed(); 131 view_->DialogDestroyed();
125 view_->GetWidget()->CloseNow(); 132 view_->GetWidget()->CloseNow();
126 } 133 }
127 } 134 }
128 135
129 void ExtensionUninstallDialogViews::Show() { 136 void ExtensionUninstallDialogViews::Show() {
130 // TODO(tapted): A true |desktop_type| needs to be passed in at creation time 137 // Callers of ExtensionUninstallDialog::Create() expect a non-NULL result, but
131 // to remove reliance on GetActiveDesktop(). http://crbug.com/308360 138 // it's possible that a browser window couldn't be found. In that case,
132 gfx::NativeWindow parent = show_in_app_list_ ? 139 // immediately cancel the dialog when shown.
133 AppListService::Get(chrome::GetActiveDesktop())->GetAppListWindow() : 140 if (browser_ && !GetParent(browser_)) {
134 GetParent(browser_);
135 if (browser_ && !parent) {
136 delegate_->ExtensionUninstallCanceled(); 141 delegate_->ExtensionUninstallCanceled();
137 return; 142 return;
138 } 143 }
139 144
140 view_ = new ExtensionUninstallDialogDelegateView( 145 view_ = new ExtensionUninstallDialogDelegateView(
141 this, extension_, triggering_extension_, &icon_); 146 this, extension_, triggering_extension_, &icon_);
142 CreateBrowserModalDialogViews(view_, parent)->Show(); 147 CreateBrowserModalDialogViews(view_, parent_ ? parent_ : GetParent(browser_))
148 ->Show();
143 } 149 }
144 150
145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { 151 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
146 // The widget gets destroyed when the dialog is accepted. 152 // The widget gets destroyed when the dialog is accepted.
147 view_ = NULL; 153 view_ = NULL;
148 delegate_->ExtensionUninstallAccepted(); 154 delegate_->ExtensionUninstallAccepted();
149 } 155 }
150 156
151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { 157 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
152 // The widget gets destroyed when the dialog is canceled. 158 // The widget gets destroyed when the dialog is canceled.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 246 }
241 } 247 }
242 248
243 } // namespace 249 } // namespace
244 250
245 // static 251 // static
246 extensions::ExtensionUninstallDialog* 252 extensions::ExtensionUninstallDialog*
247 extensions::ExtensionUninstallDialog::Create(Profile* profile, 253 extensions::ExtensionUninstallDialog::Create(Profile* profile,
248 Browser* browser, 254 Browser* browser,
249 Delegate* delegate) { 255 Delegate* delegate) {
250 return new ExtensionUninstallDialogViews(profile, browser, delegate); 256 return new ExtensionUninstallDialogViews(profile, browser, NULL, delegate);
251 } 257 }
258
259 // static
260 extensions::ExtensionUninstallDialog*
261 extensions::ExtensionUninstallDialog::CreateForAppList(Profile* profile,
262 gfx::NativeWindow parent,
263 Delegate* delegate) {
264 return new ExtensionUninstallDialogViews(profile, NULL, parent, delegate);
265 }
266
267 // static
268 extensions::ExtensionUninstallDialog*
269 extensions::ExtensionUninstallDialog::CreateAsStandaloneDialog(
270 Profile* profile,
271 Delegate* delegate) {
272 return new ExtensionUninstallDialogViews(profile, NULL, NULL, delegate);
273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698