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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 const gfx::ImageSkia& image = | 38 const gfx::ImageSkia& image = |
39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); | 39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); |
40 return image.GetRepresentation( | 40 return image.GetRepresentation( |
41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
42 } | 42 } |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 ExtensionUninstallDialog::ExtensionUninstallDialog( | 46 ExtensionUninstallDialog::ExtensionUninstallDialog( |
47 Profile* profile, | 47 Profile* profile, |
48 Browser* browser, | 48 gfx::NativeWindow parent, |
49 ExtensionUninstallDialog::Delegate* delegate) | 49 ExtensionUninstallDialog::Delegate* delegate) |
50 : profile_(profile), | 50 : profile_(profile), |
51 browser_(browser), | 51 parent_(parent), |
52 delegate_(delegate), | 52 delegate_(delegate), |
53 extension_(NULL), | 53 extension_(NULL), |
54 triggering_extension_(NULL), | 54 triggering_extension_(NULL), |
55 state_(kImageIsLoading), | 55 state_(kImageIsLoading), |
56 ui_loop_(base::MessageLoop::current()) { | 56 ui_loop_(base::MessageLoop::current()) { |
57 if (browser) { | 57 } |
58 registrar_.Add(this, | 58 |
59 chrome::NOTIFICATION_BROWSER_CLOSED, | 59 void ExtensionUninstallDialog::RegisterObserver(Browser* browser) { |
sashab
2014/07/21 02:50:30
We can actually remove the need for the Browser ob
| |
60 content::Source<Browser>(browser)); | 60 // Close the dialog if the browser is closed while the dialog is open. |
61 } | 61 registrar_.Add(this, |
62 chrome::NOTIFICATION_BROWSER_CLOSED, | |
63 content::Source<Browser>(browser)); | |
64 | |
65 // If there are no open browser windows, close the dialog immediately. | |
66 if (!browser->window()) | |
67 delegate_->ExtensionUninstallCanceled(); | |
62 } | 68 } |
63 | 69 |
64 ExtensionUninstallDialog::~ExtensionUninstallDialog() { | 70 ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
65 } | 71 } |
66 | 72 |
67 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( | 73 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( |
68 const Extension* extension, | 74 const Extension* extension, |
69 const Extension* triggering_extension) { | 75 const Extension* triggering_extension) { |
70 triggering_extension_ = triggering_extension; | 76 triggering_extension_ = triggering_extension; |
71 ConfirmUninstall(extension); | 77 ConfirmUninstall(extension); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 Show(); | 138 Show(); |
133 } | 139 } |
134 } | 140 } |
135 | 141 |
136 void ExtensionUninstallDialog::Observe( | 142 void ExtensionUninstallDialog::Observe( |
137 int type, | 143 int type, |
138 const content::NotificationSource& source, | 144 const content::NotificationSource& source, |
139 const content::NotificationDetails& details) { | 145 const content::NotificationDetails& details) { |
140 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); | 146 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); |
141 | 147 |
142 browser_ = NULL; | |
143 // If the browser is closed while waiting for the image, we need to send a | 148 // If the browser is closed while waiting for the image, we need to send a |
144 // "cancel" event here, because there will not be another opportunity to | 149 // "cancel" event here, because there will not be another opportunity to |
145 // notify the delegate of the cancellation as we won't open the dialog. | 150 // notify the delegate of the cancellation as we won't open the dialog. |
146 if (state_ == kImageIsLoading) { | 151 if (state_ == kImageIsLoading) { |
147 state_ = kBrowserIsClosing; | 152 state_ = kBrowserIsClosing; |
148 delegate_->ExtensionUninstallCanceled(); | 153 delegate_->ExtensionUninstallCanceled(); |
149 } | 154 } |
150 } | 155 } |
151 | 156 |
152 std::string ExtensionUninstallDialog::GetHeadingText() { | 157 std::string ExtensionUninstallDialog::GetHeadingText() { |
153 if (triggering_extension_) { | 158 if (triggering_extension_) { |
154 return l10n_util::GetStringFUTF8( | 159 return l10n_util::GetStringFUTF8( |
155 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, | 160 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, |
156 base::UTF8ToUTF16(triggering_extension_->name()), | 161 base::UTF8ToUTF16(triggering_extension_->name()), |
157 base::UTF8ToUTF16(extension_->name())); | 162 base::UTF8ToUTF16(extension_->name())); |
158 } | 163 } |
159 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, | 164 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
160 base::UTF8ToUTF16(extension_->name())); | 165 base::UTF8ToUTF16(extension_->name())); |
161 } | 166 } |
162 | 167 |
163 } // namespace extensions | 168 } // namespace extensions |
OLD | NEW |