Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 25 #include "ui/views/window/dialog_delegate.h" | 25 #include "ui/views/window/dialog_delegate.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const int kRightColumnWidth = 210; | 29 const int kRightColumnWidth = 210; |
| 30 const int kIconSize = 64; | 30 const int kIconSize = 64; |
| 31 | 31 |
| 32 class ExtensionUninstallDialogDelegateView; | 32 class ExtensionUninstallDialogDelegateView; |
| 33 | 33 |
| 34 // Returns parent window for extension uninstall dialog. | |
| 35 gfx::NativeWindow GetParent(Browser* browser) { | |
| 36 if (browser && browser->window()) | |
| 37 return browser->window()->GetNativeWindow(); | |
| 38 return NULL; | |
| 39 } | |
| 40 | |
| 41 // Views implementation of the uninstall dialog. | 34 // Views implementation of the uninstall dialog. |
| 42 class ExtensionUninstallDialogViews | 35 class ExtensionUninstallDialogViews |
| 43 : public extensions::ExtensionUninstallDialog { | 36 : public extensions::ExtensionUninstallDialog { |
| 44 public: | 37 public: |
| 45 ExtensionUninstallDialogViews( | 38 ExtensionUninstallDialogViews( |
| 46 Profile* profile, | 39 Profile* profile, |
| 47 Browser* browser, | 40 gfx::NativeWindow parent, |
| 48 extensions::ExtensionUninstallDialog::Delegate* delegate); | 41 extensions::ExtensionUninstallDialog::Delegate* delegate); |
| 49 virtual ~ExtensionUninstallDialogViews(); | 42 virtual ~ExtensionUninstallDialogViews(); |
| 50 | 43 |
| 51 // Forwards the accept and cancels to the delegate. | 44 // Forwards the accept and cancels to the delegate. |
| 52 void ExtensionUninstallAccepted(); | 45 void ExtensionUninstallAccepted(); |
| 53 void ExtensionUninstallCanceled(); | 46 void ExtensionUninstallCanceled(); |
| 54 | 47 |
| 55 ExtensionUninstallDialogDelegateView* view() { return view_; } | 48 ExtensionUninstallDialogDelegateView* view() { return view_; } |
| 56 | 49 |
| 57 private: | 50 private: |
| 58 virtual void Show() OVERRIDE; | 51 virtual void Show() OVERRIDE; |
| 59 | 52 |
| 60 ExtensionUninstallDialogDelegateView* view_; | 53 ExtensionUninstallDialogDelegateView* view_; |
| 61 bool show_in_app_list_; | |
| 62 | 54 |
| 63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 55 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
| 64 }; | 56 }; |
| 65 | 57 |
| 66 // The dialog's view, owned by the views framework. | 58 // The dialog's view, owned by the views framework. |
| 67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { | 59 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
| 68 public: | 60 public: |
| 69 ExtensionUninstallDialogDelegateView( | 61 ExtensionUninstallDialogDelegateView( |
| 70 ExtensionUninstallDialogViews* dialog_view, | 62 ExtensionUninstallDialogViews* dialog_view, |
| 71 const extensions::Extension* extension, | 63 const extensions::Extension* extension, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 96 |
| 105 views::ImageView* icon_; | 97 views::ImageView* icon_; |
| 106 views::Label* heading_; | 98 views::Label* heading_; |
| 107 bool triggered_by_extension_; | 99 bool triggered_by_extension_; |
| 108 | 100 |
| 109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); | 101 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); |
| 110 }; | 102 }; |
| 111 | 103 |
| 112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( | 104 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( |
| 113 Profile* profile, | 105 Profile* profile, |
| 114 Browser* browser, | 106 gfx::NativeWindow parent, |
| 115 extensions::ExtensionUninstallDialog::Delegate* delegate) | 107 extensions::ExtensionUninstallDialog::Delegate* delegate) |
| 116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), | 108 : extensions::ExtensionUninstallDialog(profile, parent, delegate), |
| 117 view_(NULL), | 109 view_(NULL) { |
| 118 show_in_app_list_(!browser) { | |
| 119 } | 110 } |
| 120 | 111 |
| 121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { | 112 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { |
| 122 // Close the widget (the views framework will delete view_). | 113 // Close the widget (the views framework will delete view_). |
| 123 if (view_) { | 114 if (view_) { |
| 124 view_->DialogDestroyed(); | 115 view_->DialogDestroyed(); |
| 125 view_->GetWidget()->CloseNow(); | 116 view_->GetWidget()->CloseNow(); |
| 126 } | 117 } |
| 127 } | 118 } |
| 128 | 119 |
| 129 void ExtensionUninstallDialogViews::Show() { | 120 void ExtensionUninstallDialogViews::Show() { |
| 130 // TODO(tapted): A true |desktop_type| needs to be passed in at creation time | |
| 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(); | |
| 137 return; | |
| 138 } | |
| 139 | |
| 140 view_ = new ExtensionUninstallDialogDelegateView( | 121 view_ = new ExtensionUninstallDialogDelegateView( |
| 141 this, extension_, triggering_extension_, &icon_); | 122 this, extension_, triggering_extension_, &icon_); |
| 142 CreateBrowserModalDialogViews(view_, parent)->Show(); | 123 CreateBrowserModalDialogViews(view_, parent_)->Show(); |
|
tapted
2014/07/24 07:46:33
Actually .. I think there's still an annoying life
sashab
2014/07/25 02:44:33
Opened crbug.com/397396 to track this and added a
| |
| 143 } | 124 } |
| 144 | 125 |
| 145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 126 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
| 146 // The widget gets destroyed when the dialog is accepted. | 127 // The widget gets destroyed when the dialog is accepted. |
| 147 view_ = NULL; | 128 view_ = NULL; |
| 148 delegate_->ExtensionUninstallAccepted(); | 129 delegate_->ExtensionUninstallAccepted(); |
| 149 } | 130 } |
| 150 | 131 |
| 151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 132 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
| 152 // The widget gets destroyed when the dialog is canceled. | 133 // The widget gets destroyed when the dialog is canceled. |
| 153 view_ = NULL; | 134 view_ = NULL; |
| 154 delegate_->ExtensionUninstallCanceled(); | 135 delegate_->ExtensionUninstallCanceled(); |
| 155 } | 136 } |
| 156 | 137 |
| 157 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( | 138 ExtensionUninstallDialogDelegateView::ExtensionUninstallDialogDelegateView( |
| 158 ExtensionUninstallDialogViews* dialog_view, | 139 ExtensionUninstallDialogViews* dialog_view, |
| 159 const extensions::Extension* extension, | 140 const extensions::Extension* extension, |
| 160 const extensions::Extension* triggering_extension, | 141 const extensions::Extension* triggering_extension, |
| 161 gfx::ImageSkia* icon) | 142 gfx::ImageSkia* icon) |
|
tapted
2014/07/24 07:09:55
nit: not stuff you're adding, but it's really conf
sashab
2014/07/24 08:02:14
Np, agreed, this was confusing me earlier. Done.
| |
| 162 : dialog_(dialog_view), | 143 : dialog_(dialog_view), |
| 163 triggered_by_extension_(triggering_extension != NULL) { | 144 triggered_by_extension_(triggering_extension != NULL) { |
| 164 // Scale down to icon size, but allow smaller icons (don't scale up). | 145 // Scale down to icon size, but allow smaller icons (don't scale up). |
| 165 gfx::Size size(icon->width(), icon->height()); | 146 gfx::Size size(icon->width(), icon->height()); |
| 166 if (size.width() > kIconSize || size.height() > kIconSize) | 147 if (size.width() > kIconSize || size.height() > kIconSize) |
| 167 size = gfx::Size(kIconSize, kIconSize); | 148 size = gfx::Size(kIconSize, kIconSize); |
| 168 icon_ = new views::ImageView(); | 149 icon_ = new views::ImageView(); |
| 169 icon_->SetImageSize(size); | 150 icon_->SetImageSize(size); |
| 170 icon_->SetImage(*icon); | 151 icon_->SetImage(*icon); |
| 171 AddChildView(icon_); | 152 AddChildView(icon_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 heading_->SetX(x); | 219 heading_->SetX(x); |
| 239 heading_->SetY(y); | 220 heading_->SetY(y); |
| 240 } | 221 } |
| 241 } | 222 } |
| 242 | 223 |
| 243 } // namespace | 224 } // namespace |
| 244 | 225 |
| 245 // static | 226 // static |
| 246 extensions::ExtensionUninstallDialog* | 227 extensions::ExtensionUninstallDialog* |
| 247 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 228 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
| 248 Browser* browser, | 229 gfx::NativeWindow parent, |
| 249 Delegate* delegate) { | 230 Delegate* delegate) { |
| 250 return new ExtensionUninstallDialogViews(profile, browser, delegate); | 231 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
| 251 } | 232 } |
| OLD | NEW |