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