OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_install_ui.h" | 5 #include "chrome/browser/extensions/extension_install_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/extensions/extension_install_dialog.h" | 15 #include "chrome/browser/extensions/extension_install_dialog.h" |
16 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 16 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
17 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/tabs/tab_strip_model.h" | 19 #include "chrome/browser/tabs/tab_strip_model.h" |
20 #include "chrome/browser/themes/theme_service.h" | 20 #include "chrome/browser/themes/theme_service.h" |
21 #include "chrome/browser/themes/theme_service_factory.h" | 21 #include "chrome/browser/themes/theme_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
| 28 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
29 #include "chrome/common/extensions/extension_icon_set.h" | 30 #include "chrome/common/extensions/extension_icon_set.h" |
30 #include "chrome/common/extensions/extension_resource.h" | 31 #include "chrome/common/extensions/extension_resource.h" |
31 #include "chrome/common/extensions/url_pattern.h" | 32 #include "chrome/common/extensions/url_pattern.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "content/common/notification_service.h" | 34 #include "content/common/notification_service.h" |
34 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
35 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
36 #include "grit/theme_resources.h" | 37 #include "grit/theme_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // automatically show the install animation for any new apps. | 82 // automatically show the install animation for any new apps. |
82 for (int i = 0; i < browser->tab_count(); ++i) { | 83 for (int i = 0; i < browser->tab_count(); ++i) { |
83 GURL url = browser->GetTabContentsAt(i)->GetURL(); | 84 GURL url = browser->GetTabContentsAt(i)->GetURL(); |
84 if (url.SchemeIs(chrome::kChromeUIScheme) && | 85 if (url.SchemeIs(chrome::kChromeUIScheme) && |
85 url.host() == chrome::kChromeUINewTabHost) { | 86 url.host() == chrome::kChromeUINewTabHost) { |
86 browser->ActivateTabAt(i, false); | 87 browser->ActivateTabAt(i, false); |
87 return; | 88 return; |
88 } | 89 } |
89 } | 90 } |
90 | 91 |
91 // If there isn't an NTP, open one and pass it the ID of the installed app. | 92 // If there isn't an NTP, open one. |
92 std::string url = base::StringPrintf( | 93 ExtensionInstallUI::OpenAppInstalledNTP(browser, app_id); |
93 "%s#app-id=%s", chrome::kChromeUINewTabURL, app_id.c_str()); | |
94 browser->AddSelectedTabWithURL(GURL(url), PageTransition::TYPED); | |
95 } | 94 } |
96 | 95 |
97 } // namespace | 96 } // namespace |
98 | 97 |
99 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 98 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
100 : profile_(profile), | 99 : profile_(profile), |
101 ui_loop_(MessageLoop::current()), | 100 ui_loop_(MessageLoop::current()), |
102 previous_using_native_theme_(false), | 101 previous_using_native_theme_(false), |
103 extension_(NULL), | 102 extension_(NULL), |
104 delegate_(NULL), | 103 delegate_(NULL), |
105 prompt_type_(NUM_PROMPT_TYPES), | 104 prompt_type_(NUM_PROMPT_TYPES), |
106 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 105 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| 106 use_app_installed_bubble_(false) { |
107 // Remember the current theme in case the user presses undo. | 107 // Remember the current theme in case the user presses undo. |
108 if (profile_) { | 108 if (profile_) { |
109 const Extension* previous_theme = | 109 const Extension* previous_theme = |
110 ThemeServiceFactory::GetThemeForProfile(profile_); | 110 ThemeServiceFactory::GetThemeForProfile(profile_); |
111 if (previous_theme) | 111 if (previous_theme) |
112 previous_theme_id_ = previous_theme->id(); | 112 previous_theme_id_ = previous_theme->id(); |
113 previous_using_native_theme_ = | 113 previous_using_native_theme_ = |
114 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme(); | 114 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme(); |
115 } | 115 } |
116 } | 116 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 170 } |
171 | 171 |
172 // Extensions aren't enabled by default in incognito so we confirm | 172 // Extensions aren't enabled by default in incognito so we confirm |
173 // the install in a normal window. | 173 // the install in a normal window. |
174 Profile* profile = profile_->GetOriginalProfile(); | 174 Profile* profile = profile_->GetOriginalProfile(); |
175 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); | 175 Browser* browser = Browser::GetOrCreateTabbedBrowser(profile); |
176 if (browser->tab_count() == 0) | 176 if (browser->tab_count() == 0) |
177 browser->AddBlankTab(true); | 177 browser->AddBlankTab(true); |
178 browser->window()->Show(); | 178 browser->window()->Show(); |
179 | 179 |
180 if (extension->GetFullLaunchURL().is_valid()) { | 180 bool use_bubble_for_apps = false; |
| 181 |
| 182 #if defined(TOOLKIT_VIEWS) |
| 183 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 184 use_bubble_for_apps = (use_app_installed_bubble_ || |
| 185 cmdline->HasSwitch(switches::kAppsNewInstallBubble)); |
| 186 #endif |
| 187 |
| 188 if (extension->is_app() && !use_bubble_for_apps) { |
181 ShowAppInstalledAnimation(browser, extension->id()); | 189 ShowAppInstalledAnimation(browser, extension->id()); |
182 return; | 190 return; |
183 } | 191 } |
184 | 192 |
185 browser::ShowExtensionInstalledBubble(extension, browser, icon_, profile); | 193 browser::ShowExtensionInstalledBubble(extension, browser, icon_, profile); |
186 } | 194 } |
187 | 195 |
188 namespace { | 196 namespace { |
189 | 197 |
190 bool disable_failure_ui_for_tests = false; | 198 bool disable_failure_ui_for_tests = false; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 profile_, delegate_, extension_, &icon_, warnings, prompt_type_); | 241 profile_, delegate_, extension_, &icon_, warnings, prompt_type_); |
234 break; | 242 break; |
235 } | 243 } |
236 default: | 244 default: |
237 NOTREACHED() << "Unknown message"; | 245 NOTREACHED() << "Unknown message"; |
238 break; | 246 break; |
239 } | 247 } |
240 } | 248 } |
241 | 249 |
242 // static | 250 // static |
| 251 void ExtensionInstallUI::OpenAppInstalledNTP(Browser* browser, |
| 252 const std::string& app_id) { |
| 253 std::string url = base::StringPrintf( |
| 254 "%s#app-id=%s", chrome::kChromeUINewTabURL, app_id.c_str()); |
| 255 browser->AddSelectedTabWithURL(GURL(url), PageTransition::TYPED); |
| 256 } |
| 257 |
| 258 // static |
243 void ExtensionInstallUI::DisableFailureUIForTests() { | 259 void ExtensionInstallUI::DisableFailureUIForTests() { |
244 disable_failure_ui_for_tests = true; | 260 disable_failure_ui_for_tests = true; |
245 } | 261 } |
246 | 262 |
247 void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, | 263 void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, |
248 bool previous_using_native_theme, | 264 bool previous_using_native_theme, |
249 const Extension* new_theme, | 265 const Extension* new_theme, |
250 Profile* profile) { | 266 Profile* profile) { |
251 if (!new_theme->is_theme()) | 267 if (!new_theme->is_theme()) |
252 return; | 268 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 317 |
302 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 318 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
303 TabContents* tab_contents, | 319 TabContents* tab_contents, |
304 const Extension* new_theme, | 320 const Extension* new_theme, |
305 const std::string& previous_theme_id, | 321 const std::string& previous_theme_id, |
306 bool previous_using_native_theme) { | 322 bool previous_using_native_theme) { |
307 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 323 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
308 previous_theme_id, | 324 previous_theme_id, |
309 previous_using_native_theme); | 325 previous_using_native_theme); |
310 } | 326 } |
OLD | NEW |