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

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: 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 // Exactly one of |browser| and |parent| should be NULL. If |browser| is set,
46 // this is for launching from a browser window. If |parent| is set, this is
47 // launching from a non-browser window.
45 ExtensionUninstallDialogViews( 48 ExtensionUninstallDialogViews(
46 Profile* profile, 49 Profile* profile,
47 Browser* browser, 50 Browser* browser,
51 gfx::NativeWindow parent,
48 extensions::ExtensionUninstallDialog::Delegate* delegate); 52 extensions::ExtensionUninstallDialog::Delegate* delegate);
49 virtual ~ExtensionUninstallDialogViews(); 53 virtual ~ExtensionUninstallDialogViews();
50 54
51 // Forwards the accept and cancels to the delegate. 55 // Forwards the accept and cancels to the delegate.
52 void ExtensionUninstallAccepted(); 56 void ExtensionUninstallAccepted();
53 void ExtensionUninstallCanceled(); 57 void ExtensionUninstallCanceled();
54 58
55 ExtensionUninstallDialogDelegateView* view() { return view_; } 59 ExtensionUninstallDialogDelegateView* view() { return view_; }
56 60
57 private: 61 private:
58 virtual void Show() OVERRIDE; 62 virtual void Show() OVERRIDE;
59 63
60 ExtensionUninstallDialogDelegateView* view_; 64 ExtensionUninstallDialogDelegateView* view_;
61 bool show_in_app_list_; 65 gfx::NativeWindow parent_;
62 66
63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); 67 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews);
64 }; 68 };
65 69
66 // The dialog's view, owned by the views framework. 70 // The dialog's view, owned by the views framework.
67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { 71 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView {
68 public: 72 public:
69 ExtensionUninstallDialogDelegateView( 73 ExtensionUninstallDialogDelegateView(
70 ExtensionUninstallDialogViews* dialog_view, 74 ExtensionUninstallDialogViews* dialog_view,
71 const extensions::Extension* extension, 75 const extensions::Extension* extension,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 views::ImageView* icon_; 109 views::ImageView* icon_;
106 views::Label* heading_; 110 views::Label* heading_;
107 bool triggered_by_extension_; 111 bool triggered_by_extension_;
108 112
109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); 113 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
110 }; 114 };
111 115
112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( 116 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
113 Profile* profile, 117 Profile* profile,
114 Browser* browser, 118 Browser* browser,
119 gfx::NativeWindow parent,
115 extensions::ExtensionUninstallDialog::Delegate* delegate) 120 extensions::ExtensionUninstallDialog::Delegate* delegate)
116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), 121 : extensions::ExtensionUninstallDialog(profile, browser, delegate),
117 view_(NULL), 122 view_(NULL),
118 show_in_app_list_(!browser) { 123 parent_(parent) {
119 } 124 }
120 125
121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { 126 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
122 // Close the widget (the views framework will delete view_). 127 // Close the widget (the views framework will delete view_).
123 if (view_) { 128 if (view_) {
124 view_->DialogDestroyed(); 129 view_->DialogDestroyed();
125 view_->GetWidget()->CloseNow(); 130 view_->GetWidget()->CloseNow();
126 } 131 }
127 } 132 }
128 133
129 void ExtensionUninstallDialogViews::Show() { 134 void ExtensionUninstallDialogViews::Show() {
130 // TODO(tapted): A true |desktop_type| needs to be passed in at creation time 135 if (browser_ && !GetParent(browser_)) {
tapted 2014/07/11 04:39:15 From the earlier CL, this needed a comment - If I
sashab 2014/07/11 05:58:57 Yup, I understand. Done.
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(); 136 delegate_->ExtensionUninstallCanceled();
137 return; 137 return;
138 } 138 }
139 139
140 view_ = new ExtensionUninstallDialogDelegateView( 140 view_ = new ExtensionUninstallDialogDelegateView(
141 this, extension_, triggering_extension_, &icon_); 141 this, extension_, triggering_extension_, &icon_);
142 CreateBrowserModalDialogViews(view_, parent)->Show(); 142 CreateBrowserModalDialogViews(view_, parent_ ? parent_ : GetParent(browser_))
tapted 2014/07/11 04:39:15 What happens if both browser_ and parent_ are NULL
sashab 2014/07/11 05:58:57 If you follow the logic carefully, this is actuall
tapted 2014/07/11 06:10:40 ah - I think I read it as ... : GetParent(browser
sashab 2014/07/13 22:57:25 Done.
143 ->Show();
143 } 144 }
144 145
145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { 146 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
146 // The widget gets destroyed when the dialog is accepted. 147 // The widget gets destroyed when the dialog is accepted.
147 view_ = NULL; 148 view_ = NULL;
148 delegate_->ExtensionUninstallAccepted(); 149 delegate_->ExtensionUninstallAccepted();
149 } 150 }
150 151
151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { 152 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() {
152 // The widget gets destroyed when the dialog is canceled. 153 // The widget gets destroyed when the dialog is canceled.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 241 }
241 } 242 }
242 243
243 } // namespace 244 } // namespace
244 245
245 // static 246 // static
246 extensions::ExtensionUninstallDialog* 247 extensions::ExtensionUninstallDialog*
247 extensions::ExtensionUninstallDialog::Create(Profile* profile, 248 extensions::ExtensionUninstallDialog::Create(Profile* profile,
248 Browser* browser, 249 Browser* browser,
249 Delegate* delegate) { 250 Delegate* delegate) {
250 return new ExtensionUninstallDialogViews(profile, browser, delegate); 251 return new ExtensionUninstallDialogViews(profile, browser, NULL, delegate);
251 } 252 }
253
254 // static
255 extensions::ExtensionUninstallDialog*
256 extensions::ExtensionUninstallDialog::CreateForNonBrowserWindow(
tapted 2014/07/11 04:39:15 You'll need a mac version of this too
sashab 2014/07/11 05:58:57 Done. Please test that the Uninstall dialog still
257 Profile* profile,
258 gfx::NativeWindow parent,
259 Delegate* delegate) {
260 return new ExtensionUninstallDialogViews(profile, NULL, parent, delegate);
261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698