OLD | NEW |
---|---|
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 Loading... | |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 | 110 |
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, |
msw
2014/07/14 17:38:31
The |browser| param is only ever used to get it's
sashab
2014/07/17 23:24:41
Not quite (I also thought this as I was refactorin
msw
2014/07/18 04:03:37
Yeah, I asked: "nit: why not just return a "standa
sashab
2014/07/21 02:50:30
I'm of mixed opinions on this one. Technically, if
| |
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 |
msw
2014/07/14 17:38:31
nit: why not just return a "standalone" dialog in
| |
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_); |
147 | |
148 gfx::NativeWindow parent = parent_ ? parent_ : GetParent(browser_); | |
142 CreateBrowserModalDialogViews(view_, parent)->Show(); | 149 CreateBrowserModalDialogViews(view_, parent)->Show(); |
143 } | 150 } |
144 | 151 |
145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 152 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
146 // The widget gets destroyed when the dialog is accepted. | 153 // The widget gets destroyed when the dialog is accepted. |
147 view_ = NULL; | 154 view_ = NULL; |
148 delegate_->ExtensionUninstallAccepted(); | 155 delegate_->ExtensionUninstallAccepted(); |
149 } | 156 } |
150 | 157 |
151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 158 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 } | 247 } |
241 } | 248 } |
242 | 249 |
243 } // namespace | 250 } // namespace |
244 | 251 |
245 // static | 252 // static |
246 extensions::ExtensionUninstallDialog* | 253 extensions::ExtensionUninstallDialog* |
247 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 254 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
248 Browser* browser, | 255 Browser* browser, |
249 Delegate* delegate) { | 256 Delegate* delegate) { |
250 return new ExtensionUninstallDialogViews(profile, browser, delegate); | 257 return new ExtensionUninstallDialogViews(profile, browser, NULL, delegate); |
251 } | 258 } |
259 | |
260 // static | |
261 extensions::ExtensionUninstallDialog* | |
262 extensions::ExtensionUninstallDialog::CreateForAppList(Profile* profile, | |
263 gfx::NativeWindow parent, | |
264 Delegate* delegate) { | |
265 return new ExtensionUninstallDialogViews(profile, NULL, parent, delegate); | |
266 } | |
267 | |
268 // static | |
269 extensions::ExtensionUninstallDialog* | |
270 extensions::ExtensionUninstallDialog::CreateAsStandaloneDialog( | |
271 Profile* profile, | |
272 Delegate* delegate) { | |
273 return new ExtensionUninstallDialogViews(profile, NULL, NULL, delegate); | |
274 } | |
OLD | NEW |