| 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/ui/extensions/extension_install_ui_default.h" | 5 #include "chrome/browser/ui/extensions/extension_install_ui_default.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 content::OpenURLParams( | 132 content::OpenURLParams( |
| 133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), | 133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), |
| 134 content::Referrer(), | 134 content::Referrer(), |
| 135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 136 ui::PAGE_TRANSITION_LINK, false)); | 136 ui::PAGE_TRANSITION_LINK, false)); |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace | 140 } // namespace |
| 141 | 141 |
| 142 | |
| 143 // ExtensionInstallUI --------------------------------------------------------- | |
| 144 | |
| 145 // static | |
| 146 ExtensionInstallUI* ExtensionInstallUI::Create(Profile* profile) { | |
| 147 return new ExtensionInstallUIDefault(profile); | |
| 148 } | |
| 149 | |
| 150 // static | |
| 151 void ExtensionInstallUI::OpenAppInstalledUI(Profile* profile, | |
| 152 const std::string& app_id) { | |
| 153 #if defined(OS_CHROMEOS) | |
| 154 // App Launcher always enabled on ChromeOS, so always handled in | |
| 155 // OnInstallSuccess. | |
| 156 NOTREACHED(); | |
| 157 #else | |
| 158 Browser* browser = FindOrCreateVisibleBrowser(profile); | |
| 159 if (browser) { | |
| 160 GURL url(chrome::IsInstantExtendedAPIEnabled() ? | |
| 161 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); | |
| 162 chrome::NavigateParams params( | |
| 163 chrome::GetSingletonTabNavigateParams(browser, url)); | |
| 164 chrome::Navigate(¶ms); | |
| 165 | |
| 166 content::NotificationService::current()->Notify( | |
| 167 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, | |
| 168 content::Source<WebContents>(params.target_contents), | |
| 169 content::Details<const std::string>(&app_id)); | |
| 170 } | |
| 171 #endif | |
| 172 } | |
| 173 | |
| 174 // static | |
| 175 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithBrowser( | |
| 176 Browser* browser) { | |
| 177 content::WebContents* web_contents = NULL; | |
| 178 if (browser) | |
| 179 web_contents = browser->tab_strip_model()->GetActiveWebContents(); | |
| 180 return new ExtensionInstallPrompt(web_contents); | |
| 181 } | |
| 182 | |
| 183 // static | |
| 184 ExtensionInstallPrompt* ExtensionInstallUI::CreateInstallPromptWithProfile( | |
| 185 Profile* profile) { | |
| 186 Browser* browser = chrome::FindLastActiveWithProfile(profile, | |
| 187 chrome::GetActiveDesktop()); | |
| 188 if (browser) | |
| 189 return CreateInstallPromptWithBrowser(browser); | |
| 190 // No browser window is open yet. Create a free-standing dialog associated | |
| 191 // with |profile|. | |
| 192 return new ExtensionInstallPrompt(profile, NULL, NULL); | |
| 193 } | |
| 194 | |
| 195 | |
| 196 // ExtensionInstallUIDefault -------------------------------------------------- | 142 // ExtensionInstallUIDefault -------------------------------------------------- |
| 197 | 143 |
| 198 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile) | 144 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile) |
| 199 : ExtensionInstallUI(profile), | 145 : ExtensionInstallUI(profile), |
| 200 previous_using_system_theme_(false), | 146 previous_using_system_theme_(false), |
| 201 use_app_installed_bubble_(false) { | 147 use_app_installed_bubble_(false) { |
| 202 // |profile| can be NULL during tests. | 148 // |profile| can be NULL during tests. |
| 203 if (profile) { | 149 if (profile) { |
| 204 // Remember the current theme in case the user presses undo. | 150 // Remember the current theme in case the user presses undo. |
| 205 const Extension* previous_theme = | 151 const Extension* previous_theme = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 AppListService::Get(chrome::GetActiveDesktop()) | 193 AppListService::Get(chrome::GetActiveDesktop()) |
| 248 ->ShowForAppInstall(current_profile, extension->id(), false); | 194 ->ShowForAppInstall(current_profile, extension->id(), false); |
| 249 return; | 195 return; |
| 250 } | 196 } |
| 251 | 197 |
| 252 if (use_bubble) { | 198 if (use_bubble) { |
| 253 ShowExtensionInstalledBubble(extension, current_profile, *icon); | 199 ShowExtensionInstalledBubble(extension, current_profile, *icon); |
| 254 return; | 200 return; |
| 255 } | 201 } |
| 256 | 202 |
| 257 ExtensionInstallUI::OpenAppInstalledUI(current_profile, extension->id()); | 203 OpenAppInstalledUI(extension->id()); |
| 258 return; | 204 return; |
| 259 } | 205 } |
| 260 | 206 |
| 261 ShowExtensionInstalledBubble(extension, current_profile, *icon); | 207 ShowExtensionInstalledBubble(extension, current_profile, *icon); |
| 262 } | 208 } |
| 263 | 209 |
| 264 void ExtensionInstallUIDefault::OnInstallFailure( | 210 void ExtensionInstallUIDefault::OnInstallFailure( |
| 265 const extensions::CrxInstallerError& error) { | 211 const extensions::CrxInstallerError& error) { |
| 266 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 212 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 267 if (disable_failure_ui_for_tests() || skip_post_install_ui()) | 213 if (disable_failure_ui_for_tests() || skip_post_install_ui()) |
| 268 return; | 214 return; |
| 269 | 215 |
| 270 Browser* browser = | 216 Browser* browser = |
| 271 chrome::FindLastActiveWithProfile(profile(), chrome::GetActiveDesktop()); | 217 chrome::FindLastActiveWithProfile(profile(), chrome::GetActiveDesktop()); |
| 272 if (!browser) // Can be NULL in unittests. | 218 if (!browser) // Can be NULL in unittests. |
| 273 return; | 219 return; |
| 274 WebContents* web_contents = | 220 WebContents* web_contents = |
| 275 browser->tab_strip_model()->GetActiveWebContents(); | 221 browser->tab_strip_model()->GetActiveWebContents(); |
| 276 if (!web_contents) | 222 if (!web_contents) |
| 277 return; | 223 return; |
| 278 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), | 224 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), |
| 279 error); | 225 error); |
| 280 } | 226 } |
| 281 | 227 |
| 228 void ExtensionInstallUIDefault::OpenAppInstalledUI(const std::string& app_id) { |
| 229 #if defined(OS_CHROMEOS) |
| 230 // App Launcher always enabled on ChromeOS, so always handled in |
| 231 // OnInstallSuccess. |
| 232 NOTREACHED(); |
| 233 #else |
| 234 Browser* browser = FindOrCreateVisibleBrowser(profile); |
| 235 if (browser) { |
| 236 GURL url(chrome::IsInstantExtendedAPIEnabled() ? |
| 237 chrome::kChromeUIAppsURL : chrome::kChromeUINewTabURL); |
| 238 chrome::NavigateParams params( |
| 239 chrome::GetSingletonTabNavigateParams(browser, url)); |
| 240 chrome::Navigate(¶ms); |
| 241 |
| 242 content::NotificationService::current()->Notify( |
| 243 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
| 244 content::Source<WebContents>(params.target_contents), |
| 245 content::Details<const std::string>(&app_id)); |
| 246 } |
| 247 #endif |
| 248 } |
| 249 |
| 250 ExtensionInstallPrompt* ExtensionInstallUIDefault::CreateInstallPrompt() { |
| 251 Browser* browser = chrome::FindLastActiveWithProfile(profile(), |
| 252 chrome::GetActiveDesktop()); |
| 253 if (browser) { |
| 254 content::WebContents* web_contents = |
| 255 browser->tab_strip_model()->GetActiveWebContents(); |
| 256 return new ExtensionInstallPrompt(web_contents); |
| 257 } |
| 258 // No browser window is open yet. Create a free-standing dialog associated |
| 259 // with |profile|. |
| 260 return new ExtensionInstallPrompt(profile(), NULL, NULL); |
| 261 } |
| 262 |
| 282 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { | 263 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { |
| 283 use_app_installed_bubble_ = use_bubble; | 264 use_app_installed_bubble_ = use_bubble; |
| 284 } | 265 } |
| OLD | NEW |