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/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/simple_message_box.h" | 18 #include "chrome/browser/simple_message_box.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_navigator.h" |
25 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
30 #include "chrome/common/extensions/extension_icon_set.h" | 31 #include "chrome/common/extensions/extension_icon_set.h" |
31 #include "chrome/common/extensions/extension_resource.h" | 32 #include "chrome/common/extensions/extension_resource.h" |
32 #include "chrome/common/extensions/url_pattern.h" | 33 #include "chrome/common/extensions/url_pattern.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "content/common/notification_service.h" | 35 #include "content/common/notification_service.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, | 67 IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO, |
67 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, | 68 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO, |
68 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, | 69 IDS_EXTENSION_PROMPT_WANTS_ACCESS_TO, |
69 }; | 70 }; |
70 | 71 |
71 namespace { | 72 namespace { |
72 | 73 |
73 // Size of extension icon in top left of dialog. | 74 // Size of extension icon in top left of dialog. |
74 const int kIconSize = 69; | 75 const int kIconSize = 69; |
75 | 76 |
76 // Shows the application install animation on the new tab page for the app | |
77 // with |app_id|. If a NTP already exists on the active |browser|, this will | |
78 // select that tab and show the animation there. Otherwise, it will create | |
79 // a new NTP. | |
80 void ShowAppInstalledAnimation(Browser* browser, const std::string& app_id) { | |
81 // Select an already open NTP, if there is one. Existing NTPs will | |
82 // automatically show the install animation for any new apps. | |
83 for (int i = 0; i < browser->tab_count(); ++i) { | |
84 GURL url = browser->GetTabContentsAt(i)->GetURL(); | |
85 if (url.SchemeIs(chrome::kChromeUIScheme) && | |
86 url.host() == chrome::kChromeUINewTabHost) { | |
87 browser->ActivateTabAt(i, false); | |
88 return; | |
89 } | |
90 } | |
91 | |
92 // If there isn't an NTP, open one. | |
93 ExtensionInstallUI::OpenAppInstalledNTP(browser, app_id); | |
94 } | |
95 | |
96 } // namespace | 77 } // namespace |
97 | 78 |
98 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 79 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
99 : profile_(profile), | 80 : profile_(profile), |
100 ui_loop_(MessageLoop::current()), | 81 ui_loop_(MessageLoop::current()), |
101 previous_using_native_theme_(false), | 82 previous_using_native_theme_(false), |
102 extension_(NULL), | 83 extension_(NULL), |
103 delegate_(NULL), | 84 delegate_(NULL), |
104 prompt_type_(NUM_PROMPT_TYPES), | 85 prompt_type_(NUM_PROMPT_TYPES), |
105 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 86 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 160 |
180 bool use_bubble_for_apps = false; | 161 bool use_bubble_for_apps = false; |
181 | 162 |
182 #if defined(TOOLKIT_VIEWS) | 163 #if defined(TOOLKIT_VIEWS) |
183 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 164 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
184 use_bubble_for_apps = (use_app_installed_bubble_ || | 165 use_bubble_for_apps = (use_app_installed_bubble_ || |
185 cmdline->HasSwitch(switches::kAppsNewInstallBubble)); | 166 cmdline->HasSwitch(switches::kAppsNewInstallBubble)); |
186 #endif | 167 #endif |
187 | 168 |
188 if (extension->is_app() && !use_bubble_for_apps) { | 169 if (extension->is_app() && !use_bubble_for_apps) { |
189 ShowAppInstalledAnimation(browser, extension->id()); | 170 ExtensionInstallUI::OpenAppInstalledNTP(browser, extension->id()); |
190 return; | 171 return; |
191 } | 172 } |
192 | 173 |
193 browser::ShowExtensionInstalledBubble(extension, browser, icon_, profile); | 174 browser::ShowExtensionInstalledBubble(extension, browser, icon_, profile); |
194 } | 175 } |
195 | 176 |
196 namespace { | 177 namespace { |
197 | 178 |
198 bool disable_failure_ui_for_tests = false; | 179 bool disable_failure_ui_for_tests = false; |
199 | 180 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 NOTREACHED() << "Unknown message"; | 226 NOTREACHED() << "Unknown message"; |
246 break; | 227 break; |
247 } | 228 } |
248 } | 229 } |
249 | 230 |
250 // static | 231 // static |
251 void ExtensionInstallUI::OpenAppInstalledNTP(Browser* browser, | 232 void ExtensionInstallUI::OpenAppInstalledNTP(Browser* browser, |
252 const std::string& app_id) { | 233 const std::string& app_id) { |
253 std::string url = base::StringPrintf( | 234 std::string url = base::StringPrintf( |
254 "%s#app-id=%s", chrome::kChromeUINewTabURL, app_id.c_str()); | 235 "%s#app-id=%s", chrome::kChromeUINewTabURL, app_id.c_str()); |
255 browser->AddSelectedTabWithURL(GURL(url), PageTransition::TYPED); | 236 browser::NavigateParams params = |
| 237 browser->GetSingletonTabNavigateParams(GURL(url)); |
| 238 params.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE; |
| 239 browser::Navigate(¶ms); |
256 } | 240 } |
257 | 241 |
258 // static | 242 // static |
259 void ExtensionInstallUI::DisableFailureUIForTests() { | 243 void ExtensionInstallUI::DisableFailureUIForTests() { |
260 disable_failure_ui_for_tests = true; | 244 disable_failure_ui_for_tests = true; |
261 } | 245 } |
262 | 246 |
263 void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, | 247 void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, |
264 bool previous_using_native_theme, | 248 bool previous_using_native_theme, |
265 const Extension* new_theme, | 249 const Extension* new_theme, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 301 |
318 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 302 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
319 TabContents* tab_contents, | 303 TabContents* tab_contents, |
320 const Extension* new_theme, | 304 const Extension* new_theme, |
321 const std::string& previous_theme_id, | 305 const std::string& previous_theme_id, |
322 bool previous_using_native_theme) { | 306 bool previous_using_native_theme) { |
323 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, | 307 return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme, |
324 previous_theme_id, | 308 previous_theme_id, |
325 previous_using_native_theme); | 309 previous_using_native_theme); |
326 } | 310 } |
OLD | NEW |