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" |
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/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
13 #include "components/constrained_window/constrained_window_views.h" | 13 #include "components/constrained_window/constrained_window_views.h" |
14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "ui/aura/window_tracker.h" |
15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
17 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
18 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
20 #include "ui/views/layout/layout_constants.h" | 21 #include "ui/views/layout/layout_constants.h" |
21 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
23 #include "ui/views/window/dialog_delegate.h" | 24 #include "ui/views/window/dialog_delegate.h" |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 const int kRightColumnWidth = 210; | 28 const int kRightColumnWidth = 210; |
28 const int kIconSize = 64; | 29 const int kIconSize = 64; |
29 | 30 |
30 class ExtensionUninstallDialogDelegateView; | 31 class ExtensionUninstallDialogDelegateView; |
31 | 32 |
32 // Views implementation of the uninstall dialog. | 33 // Views implementation of the uninstall dialog. |
33 class ExtensionUninstallDialogViews | 34 class ExtensionUninstallDialogViews |
34 : public extensions::ExtensionUninstallDialog { | 35 : public extensions::ExtensionUninstallDialog { |
35 public: | 36 public: |
36 ExtensionUninstallDialogViews( | 37 ExtensionUninstallDialogViews( |
37 Profile* profile, | 38 Profile* profile, |
38 gfx::NativeWindow parent, | 39 aura::Window* parent, |
39 extensions::ExtensionUninstallDialog::Delegate* delegate); | 40 extensions::ExtensionUninstallDialog::Delegate* delegate); |
40 ~ExtensionUninstallDialogViews() override; | 41 ~ExtensionUninstallDialogViews() override; |
41 | 42 |
42 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make | 43 // Called when the ExtensionUninstallDialogDelegate has been destroyed to make |
43 // sure we invalidate pointers. | 44 // sure we invalidate pointers. |
44 void DialogDelegateDestroyed() { view_ = NULL; } | 45 void DialogDelegateDestroyed() { view_ = NULL; } |
45 | 46 |
46 // Forwards the accept and cancels to the delegate. | 47 // Forwards the accept and cancels to the delegate. |
47 void ExtensionUninstallAccepted(); | 48 void ExtensionUninstallAccepted(); |
48 void ExtensionUninstallCanceled(); | 49 void ExtensionUninstallCanceled(); |
49 | 50 |
50 private: | 51 private: |
51 void Show() override; | 52 void Show() override; |
52 | 53 |
53 ExtensionUninstallDialogDelegateView* view_; | 54 ExtensionUninstallDialogDelegateView* view_; |
54 | 55 |
| 56 // The dialog's parent window. |
| 57 aura::Window* parent_; |
| 58 |
| 59 // Tracks whether |parent_| got destroyed. |
| 60 aura::WindowTracker parent_window_tracker_; |
| 61 |
55 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 62 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
56 }; | 63 }; |
57 | 64 |
58 // The dialog's view, owned by the views framework. | 65 // The dialog's view, owned by the views framework. |
59 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { | 66 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
60 public: | 67 public: |
61 ExtensionUninstallDialogDelegateView( | 68 ExtensionUninstallDialogDelegateView( |
62 ExtensionUninstallDialogViews* dialog_view, | 69 ExtensionUninstallDialogViews* dialog_view, |
63 const extensions::Extension* extension, | 70 const extensions::Extension* extension, |
64 const extensions::Extension* triggering_extension, | 71 const extensions::Extension* triggering_extension, |
(...skipping 28 matching lines...) Expand all Loading... |
93 | 100 |
94 views::ImageView* icon_; | 101 views::ImageView* icon_; |
95 views::Label* heading_; | 102 views::Label* heading_; |
96 bool triggered_by_extension_; | 103 bool triggered_by_extension_; |
97 | 104 |
98 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); | 105 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); |
99 }; | 106 }; |
100 | 107 |
101 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( | 108 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( |
102 Profile* profile, | 109 Profile* profile, |
103 gfx::NativeWindow parent, | 110 aura::Window* parent, |
104 extensions::ExtensionUninstallDialog::Delegate* delegate) | 111 extensions::ExtensionUninstallDialog::Delegate* delegate) |
105 : extensions::ExtensionUninstallDialog(profile, parent, delegate), | 112 : extensions::ExtensionUninstallDialog(profile, delegate), |
106 view_(NULL) { | 113 view_(NULL), |
| 114 parent_(parent) { |
| 115 if (parent_) |
| 116 parent_window_tracker_.Add(parent_); |
107 } | 117 } |
108 | 118 |
109 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { | 119 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { |
110 // Close the widget (the views framework will delete view_). | 120 // Close the widget (the views framework will delete view_). |
111 if (view_) { | 121 if (view_) { |
112 view_->DialogDestroyed(); | 122 view_->DialogDestroyed(); |
113 view_->GetWidget()->CloseNow(); | 123 view_->GetWidget()->CloseNow(); |
114 } | 124 } |
115 } | 125 } |
116 | 126 |
117 void ExtensionUninstallDialogViews::Show() { | 127 void ExtensionUninstallDialogViews::Show() { |
| 128 if (parent_ && !parent_window_tracker_.Contains(parent_)) { |
| 129 delegate_->ExtensionUninstallCanceled(); |
| 130 return; |
| 131 } |
| 132 |
118 view_ = new ExtensionUninstallDialogDelegateView( | 133 view_ = new ExtensionUninstallDialogDelegateView( |
119 this, extension_, triggering_extension_, &icon_); | 134 this, extension_, triggering_extension_, &icon_); |
120 CreateBrowserModalDialogViews(view_, parent_)->Show(); | 135 CreateBrowserModalDialogViews(view_, parent_)->Show(); |
121 } | 136 } |
122 | 137 |
123 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 138 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
124 // The widget gets destroyed when the dialog is accepted. | 139 // The widget gets destroyed when the dialog is accepted. |
125 view_->DialogDestroyed(); | 140 view_->DialogDestroyed(); |
126 view_ = NULL; | 141 view_ = NULL; |
127 delegate_->ExtensionUninstallAccepted(); | 142 delegate_->ExtensionUninstallAccepted(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 246 |
232 } // namespace | 247 } // namespace |
233 | 248 |
234 // static | 249 // static |
235 extensions::ExtensionUninstallDialog* | 250 extensions::ExtensionUninstallDialog* |
236 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 251 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
237 gfx::NativeWindow parent, | 252 gfx::NativeWindow parent, |
238 Delegate* delegate) { | 253 Delegate* delegate) { |
239 return new ExtensionUninstallDialogViews(profile, parent, delegate); | 254 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
240 } | 255 } |
OLD | NEW |