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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc

Issue 711343003: [Merge] Cancel uninstall if the uninstall dialog's parent window is destroyed prior to the uninstal… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 1 month 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
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"
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/browser/ui/views/constrained_window_views.h" 12 #include "chrome/browser/ui/views/constrained_window_views.h"
13 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.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 virtual ~ExtensionUninstallDialogViews(); 41 virtual ~ExtensionUninstallDialogViews();
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 virtual void Show() OVERRIDE; 52 virtual 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 103
97 views::ImageView* icon_; 104 views::ImageView* icon_;
98 views::Label* heading_; 105 views::Label* heading_;
99 bool triggered_by_extension_; 106 bool triggered_by_extension_;
100 107
101 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); 108 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView);
102 }; 109 };
103 110
104 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( 111 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews(
105 Profile* profile, 112 Profile* profile,
106 gfx::NativeWindow parent, 113 aura::Window* parent,
107 extensions::ExtensionUninstallDialog::Delegate* delegate) 114 extensions::ExtensionUninstallDialog::Delegate* delegate)
108 : extensions::ExtensionUninstallDialog(profile, parent, delegate), 115 : extensions::ExtensionUninstallDialog(profile, delegate),
109 view_(NULL) { 116 view_(NULL),
117 parent_(parent) {
118 if (parent_)
119 parent_window_tracker_.Add(parent_);
110 } 120 }
111 121
112 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { 122 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() {
113 // Close the widget (the views framework will delete view_). 123 // Close the widget (the views framework will delete view_).
114 if (view_) { 124 if (view_) {
115 view_->DialogDestroyed(); 125 view_->DialogDestroyed();
116 view_->GetWidget()->CloseNow(); 126 view_->GetWidget()->CloseNow();
117 } 127 }
118 } 128 }
119 129
120 void ExtensionUninstallDialogViews::Show() { 130 void ExtensionUninstallDialogViews::Show() {
131 if (parent_ && !parent_window_tracker_.Contains(parent_)) {
132 delegate_->ExtensionUninstallCanceled();
133 return;
134 }
135
121 view_ = new ExtensionUninstallDialogDelegateView( 136 view_ = new ExtensionUninstallDialogDelegateView(
122 this, extension_, triggering_extension_, &icon_); 137 this, extension_, triggering_extension_, &icon_);
123 CreateBrowserModalDialogViews(view_, parent_)->Show(); 138 CreateBrowserModalDialogViews(view_, parent_)->Show();
124 } 139 }
125 140
126 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { 141 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() {
127 // The widget gets destroyed when the dialog is accepted. 142 // The widget gets destroyed when the dialog is accepted.
128 view_->DialogDestroyed(); 143 view_->DialogDestroyed();
129 view_ = NULL; 144 view_ = NULL;
130 delegate_->ExtensionUninstallAccepted(); 145 delegate_->ExtensionUninstallAccepted();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 249
235 } // namespace 250 } // namespace
236 251
237 // static 252 // static
238 extensions::ExtensionUninstallDialog* 253 extensions::ExtensionUninstallDialog*
239 extensions::ExtensionUninstallDialog::Create(Profile* profile, 254 extensions::ExtensionUninstallDialog::Create(Profile* profile,
240 gfx::NativeWindow parent, 255 gfx::NativeWindow parent,
241 Delegate* delegate) { 256 Delegate* delegate) {
242 return new ExtensionUninstallDialogViews(profile, parent, delegate); 257 return new ExtensionUninstallDialogViews(profile, parent, delegate);
243 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698