| 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 26 matching lines...) Expand all Loading... |
| 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 ExtensionUninstallDialogViews( | 45 ExtensionUninstallDialogViews( |
| 46 Profile* profile, | 46 Profile* profile, |
| 47 Browser* browser, | 47 gfx::NativeWindow parent, |
| 48 extensions::ExtensionUninstallDialog::Delegate* delegate); | 48 extensions::ExtensionUninstallDialog::Delegate* delegate); |
| 49 virtual ~ExtensionUninstallDialogViews(); | 49 virtual ~ExtensionUninstallDialogViews(); |
| 50 | 50 |
| 51 // Forwards the accept and cancels to the delegate. | 51 // Forwards the accept and cancels to the delegate. |
| 52 void ExtensionUninstallAccepted(); | 52 void ExtensionUninstallAccepted(); |
| 53 void ExtensionUninstallCanceled(); | 53 void ExtensionUninstallCanceled(); |
| 54 | 54 |
| 55 ExtensionUninstallDialogDelegateView* view() { return view_; } | 55 ExtensionUninstallDialogDelegateView* view() { return view_; } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 virtual void Show() OVERRIDE; | 58 virtual void Show() OVERRIDE; |
| 59 | 59 |
| 60 ExtensionUninstallDialogDelegateView* view_; | 60 ExtensionUninstallDialogDelegateView* view_; |
| 61 bool show_in_app_list_; | |
| 62 | 61 |
| 63 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); | 62 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogViews); |
| 64 }; | 63 }; |
| 65 | 64 |
| 66 // The dialog's view, owned by the views framework. | 65 // The dialog's view, owned by the views framework. |
| 67 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { | 66 class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { |
| 68 public: | 67 public: |
| 69 ExtensionUninstallDialogDelegateView( | 68 ExtensionUninstallDialogDelegateView( |
| 70 ExtensionUninstallDialogViews* dialog_view, | 69 ExtensionUninstallDialogViews* dialog_view, |
| 71 const extensions::Extension* extension, | 70 const extensions::Extension* extension, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 103 |
| 105 views::ImageView* icon_; | 104 views::ImageView* icon_; |
| 106 views::Label* heading_; | 105 views::Label* heading_; |
| 107 bool triggered_by_extension_; | 106 bool triggered_by_extension_; |
| 108 | 107 |
| 109 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); | 108 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialogDelegateView); |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( | 111 ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( |
| 113 Profile* profile, | 112 Profile* profile, |
| 114 Browser* browser, | 113 gfx::NativeWindow parent, |
| 115 extensions::ExtensionUninstallDialog::Delegate* delegate) | 114 extensions::ExtensionUninstallDialog::Delegate* delegate) |
| 116 : extensions::ExtensionUninstallDialog(profile, browser, delegate), | 115 : extensions::ExtensionUninstallDialog(profile, parent, delegate), |
| 117 view_(NULL), | 116 view_(NULL) { |
| 118 show_in_app_list_(!browser) { | |
| 119 } | 117 } |
| 120 | 118 |
| 121 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { | 119 ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { |
| 122 // Close the widget (the views framework will delete view_). | 120 // Close the widget (the views framework will delete view_). |
| 123 if (view_) { | 121 if (view_) { |
| 124 view_->DialogDestroyed(); | 122 view_->DialogDestroyed(); |
| 125 view_->GetWidget()->CloseNow(); | 123 view_->GetWidget()->CloseNow(); |
| 126 } | 124 } |
| 127 } | 125 } |
| 128 | 126 |
| 129 void ExtensionUninstallDialogViews::Show() { | 127 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( | 128 view_ = new ExtensionUninstallDialogDelegateView( |
| 141 this, extension_, triggering_extension_, &icon_); | 129 this, extension_, triggering_extension_, &icon_); |
| 142 CreateBrowserModalDialogViews(view_, parent)->Show(); | 130 CreateBrowserModalDialogViews(view_, parent_)->Show(); |
| 143 } | 131 } |
| 144 | 132 |
| 145 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { | 133 void ExtensionUninstallDialogViews::ExtensionUninstallAccepted() { |
| 146 // The widget gets destroyed when the dialog is accepted. | 134 // The widget gets destroyed when the dialog is accepted. |
| 147 view_ = NULL; | 135 view_ = NULL; |
| 148 delegate_->ExtensionUninstallAccepted(); | 136 delegate_->ExtensionUninstallAccepted(); |
| 149 } | 137 } |
| 150 | 138 |
| 151 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { | 139 void ExtensionUninstallDialogViews::ExtensionUninstallCanceled() { |
| 152 // The widget gets destroyed when the dialog is canceled. | 140 // The widget gets destroyed when the dialog is canceled. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 228 } |
| 241 } | 229 } |
| 242 | 230 |
| 243 } // namespace | 231 } // namespace |
| 244 | 232 |
| 245 // static | 233 // static |
| 246 extensions::ExtensionUninstallDialog* | 234 extensions::ExtensionUninstallDialog* |
| 247 extensions::ExtensionUninstallDialog::Create(Profile* profile, | 235 extensions::ExtensionUninstallDialog::Create(Profile* profile, |
| 248 Browser* browser, | 236 Browser* browser, |
| 249 Delegate* delegate) { | 237 Delegate* delegate) { |
| 250 return new ExtensionUninstallDialogViews(profile, browser, delegate); | 238 // If no browser window can be found, GetParent(browser) will be NULL, which |
| 239 // will display this dialog as a standalone window (rather than a modal). |
| 240 ExtensionUninstallDialogViews* dialog = |
| 241 new ExtensionUninstallDialogViews(profile, GetParent(browser), delegate); |
| 242 dialog->RegisterObserver(browser); |
| 243 return dialog; |
| 251 } | 244 } |
| 245 |
| 246 // static |
| 247 extensions::ExtensionUninstallDialog* |
| 248 extensions::ExtensionUninstallDialog::CreateModal(Profile* profile, |
| 249 gfx::NativeWindow parent, |
| 250 Delegate* delegate) { |
| 251 return new ExtensionUninstallDialogViews(profile, parent, delegate); |
| 252 } |
| OLD | NEW |