| 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" | |
| 11 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 10 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 12 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/themes/theme_service.h" | 14 #include "chrome/browser/themes/theme_service.h" |
| 16 #include "chrome/browser/themes/theme_service_factory.h" | 15 #include "chrome/browser/themes/theme_service_factory.h" |
| 17 #include "chrome/browser/ui/app_list/app_list_service.h" | 16 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 18 #include "chrome/browser/ui/app_list/app_list_util.h" | 17 #include "chrome/browser/ui/app_list/app_list_util.h" |
| 19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_dialogs.h" | 19 #include "chrome/browser/ui/browser_dialogs.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_navigator.h" | 21 #include "chrome/browser/ui/browser_navigator.h" |
| 23 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/browser/ui/host_desktop.h" | 24 #include "chrome/browser/ui/host_desktop.h" |
| 26 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 25 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 27 #include "chrome/browser/ui/simple_message_box.h" | 26 #include "chrome/browser/ui/simple_message_box.h" |
| 28 #include "chrome/browser/ui/singleton_tabs.h" | 27 #include "chrome/browser/ui/singleton_tabs.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 32 #include "components/infobars/core/confirm_infobar_delegate.h" | 31 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 33 #include "components/infobars/core/infobar.h" | 32 #include "components/infobars/core/infobar.h" |
| 34 #include "components/search/search.h" | 33 #include "components/search/search.h" |
| 35 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "extensions/browser/install/crx_installer_error.h" |
| 38 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
| 39 #include "grit/components_strings.h" | 39 #include "grit/components_strings.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 | 41 |
| 42 #if defined(USE_ASH) | 42 #if defined(USE_ASH) |
| 43 #include "ash/shell.h" | 43 #include "ash/shell.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 using content::BrowserThread; | 46 using content::BrowserThread; |
| 47 using content::WebContents; | 47 using content::WebContents; |
| 48 using extensions::Extension; | 48 using extensions::Extension; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 // Helpers -------------------------------------------------------------------- | |
| 53 | |
| 54 Browser* FindOrCreateVisibleBrowser(Profile* profile) { | 52 Browser* FindOrCreateVisibleBrowser(Profile* profile) { |
| 55 // TODO(mpcomplete): remove this workaround for http://crbug.com/244246 | 53 // TODO(mpcomplete): remove this workaround for http://crbug.com/244246 |
| 56 // after fixing http://crbug.com/38676. | 54 // after fixing http://crbug.com/38676. |
| 57 if (!IncognitoModePrefs::CanOpenBrowser(profile)) | 55 if (!IncognitoModePrefs::CanOpenBrowser(profile)) |
| 58 return NULL; | 56 return NULL; |
| 59 chrome::ScopedTabbedBrowserDisplayer displayer( | 57 chrome::ScopedTabbedBrowserDisplayer displayer( |
| 60 profile, chrome::GetActiveDesktop()); | 58 profile, chrome::GetActiveDesktop()); |
| 61 Browser* browser = displayer.browser(); | 59 Browser* browser = displayer.browser(); |
| 62 if (browser->tab_strip_model()->count() == 0) | 60 if (browser->tab_strip_model()->count() == 0) |
| 63 chrome::AddTabAt(browser, GURL(), -1, true); | 61 chrome::AddTabAt(browser, GURL(), -1, true); |
| 64 return browser; | 62 return browser; |
| 65 } | 63 } |
| 66 | 64 |
| 67 void ShowExtensionInstalledBubble(const extensions::Extension* extension, | 65 void ShowExtensionInstalledBubble(const extensions::Extension* extension, |
| 68 Profile* profile, | 66 Profile* profile, |
| 69 const SkBitmap& icon) { | 67 const SkBitmap& icon) { |
| 70 Browser* browser = FindOrCreateVisibleBrowser(profile); | 68 Browser* browser = FindOrCreateVisibleBrowser(profile); |
| 71 if (browser) | 69 if (browser) |
| 72 chrome::ShowExtensionInstalledBubble(extension, browser, icon); | 70 chrome::ShowExtensionInstalledBubble(extension, browser, icon); |
| 73 } | 71 } |
| 74 | 72 |
| 75 | |
| 76 // ErrorInfoBarDelegate ------------------------------------------------------- | |
| 77 | |
| 78 // Helper class to put up an infobar when installation fails. | 73 // Helper class to put up an infobar when installation fails. |
| 79 class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { | 74 class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 80 public: | 75 public: |
| 81 // Creates an error infobar and delegate and adds the infobar to | 76 // Creates an error infobar and delegate and adds the infobar to |
| 82 // |infobar_service|. | 77 // |infobar_service|. |
| 83 static void Create(InfoBarService* infobar_service, | 78 static void Create(InfoBarService* infobar_service, |
| 84 const extensions::CrxInstallerError& error); | 79 const extensions::CrxInstallerError& error); |
| 85 | 80 |
| 86 private: | 81 private: |
| 87 explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error); | 82 explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 content::OpenURLParams( | 127 content::OpenURLParams( |
| 133 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), | 128 GURL("http://support.google.com/chrome_webstore/?p=crx_warning"), |
| 134 content::Referrer(), | 129 content::Referrer(), |
| 135 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 130 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 136 ui::PAGE_TRANSITION_LINK, false)); | 131 ui::PAGE_TRANSITION_LINK, false)); |
| 137 return false; | 132 return false; |
| 138 } | 133 } |
| 139 | 134 |
| 140 } // namespace | 135 } // namespace |
| 141 | 136 |
| 142 | 137 ExtensionInstallUIDefault::ExtensionInstallUIDefault( |
| 143 // ExtensionInstallUI --------------------------------------------------------- | 138 content::BrowserContext* context) |
| 144 | 139 : profile_(Profile::FromBrowserContext(context)), |
| 145 // static | 140 skip_post_install_ui_(false), |
| 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 -------------------------------------------------- | |
| 197 | |
| 198 ExtensionInstallUIDefault::ExtensionInstallUIDefault(Profile* profile) | |
| 199 : ExtensionInstallUI(profile), | |
| 200 previous_using_system_theme_(false), | 141 previous_using_system_theme_(false), |
| 201 use_app_installed_bubble_(false) { | 142 use_app_installed_bubble_(false) { |
| 202 // |profile| can be NULL during tests. | 143 // |profile| can be NULL during tests. |
| 203 if (profile) { | 144 if (profile_) { |
| 204 // Remember the current theme in case the user presses undo. | 145 // Remember the current theme in case the user presses undo. |
| 205 const Extension* previous_theme = | 146 const Extension* previous_theme = |
| 206 ThemeServiceFactory::GetThemeForProfile(profile); | 147 ThemeServiceFactory::GetThemeForProfile(profile_); |
| 207 if (previous_theme) | 148 if (previous_theme) |
| 208 previous_theme_id_ = previous_theme->id(); | 149 previous_theme_id_ = previous_theme->id(); |
| 209 previous_using_system_theme_ = | 150 previous_using_system_theme_ = |
| 210 ThemeServiceFactory::GetForProfile(profile)->UsingSystemTheme(); | 151 ThemeServiceFactory::GetForProfile(profile_)->UsingSystemTheme(); |
| 211 } | 152 } |
| 212 } | 153 } |
| 213 | 154 |
| 214 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {} | 155 ExtensionInstallUIDefault::~ExtensionInstallUIDefault() {} |
| 215 | 156 |
| 216 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension, | 157 void ExtensionInstallUIDefault::OnInstallSuccess(const Extension* extension, |
| 217 const SkBitmap* icon) { | 158 const SkBitmap* icon) { |
| 218 if (skip_post_install_ui()) | 159 if (skip_post_install_ui_) |
| 219 return; | 160 return; |
| 220 | 161 |
| 221 if (!profile()) { | 162 if (!profile_) { |
| 222 // TODO(zelidrag): Figure out what exact conditions cause crash | 163 // TODO(zelidrag): Figure out what exact conditions cause crash |
| 223 // http://crbug.com/159437 and write browser test to cover it. | 164 // http://crbug.com/159437 and write browser test to cover it. |
| 224 NOTREACHED(); | 165 NOTREACHED(); |
| 225 return; | 166 return; |
| 226 } | 167 } |
| 227 | 168 |
| 228 if (extension->is_theme()) { | 169 if (extension->is_theme()) { |
| 229 ThemeInstalledInfoBarDelegate::Create( | 170 ThemeInstalledInfoBarDelegate::Create( |
| 230 extension, profile(), previous_theme_id_, previous_using_system_theme_); | 171 extension, profile_, previous_theme_id_, previous_using_system_theme_); |
| 231 return; | 172 return; |
| 232 } | 173 } |
| 233 | 174 |
| 234 // Extensions aren't enabled by default in incognito so we confirm | 175 // Extensions aren't enabled by default in incognito so we confirm |
| 235 // the install in a normal window. | 176 // the install in a normal window. |
| 236 Profile* current_profile = profile()->GetOriginalProfile(); | 177 Profile* current_profile = profile_->GetOriginalProfile(); |
| 237 if (extension->is_app()) { | 178 if (extension->is_app()) { |
| 238 bool use_bubble = false; | 179 bool use_bubble = false; |
| 239 | 180 |
| 240 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) | 181 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) |
| 241 use_bubble = use_app_installed_bubble_; | 182 use_bubble = use_app_installed_bubble_; |
| 242 #endif | 183 #endif |
| 243 | 184 |
| 244 if (IsAppLauncherEnabled()) { | 185 if (IsAppLauncherEnabled()) { |
| 245 // TODO(tapted): ExtensionInstallUI should retain the desktop type from | 186 // TODO(tapted): ExtensionInstallUI should retain the desktop type from |
| 246 // the browser used to initiate the flow. http://crbug.com/308360. | 187 // the browser used to initiate the flow. http://crbug.com/308360. |
| 247 AppListService::Get(chrome::GetActiveDesktop()) | 188 AppListService::Get(chrome::GetActiveDesktop()) |
| 248 ->ShowForAppInstall(current_profile, extension->id(), false); | 189 ->ShowForAppInstall(current_profile, extension->id(), false); |
| 249 return; | 190 return; |
| 250 } | 191 } |
| 251 | 192 |
| 252 if (use_bubble) { | 193 if (use_bubble) { |
| 253 ShowExtensionInstalledBubble(extension, current_profile, *icon); | 194 ShowExtensionInstalledBubble(extension, current_profile, *icon); |
| 254 return; | 195 return; |
| 255 } | 196 } |
| 256 | 197 |
| 257 ExtensionInstallUI::OpenAppInstalledUI(current_profile, extension->id()); | 198 OpenAppInstalledUI(extension->id()); |
| 258 return; | 199 return; |
| 259 } | 200 } |
| 260 | 201 |
| 261 ShowExtensionInstalledBubble(extension, current_profile, *icon); | 202 ShowExtensionInstalledBubble(extension, current_profile, *icon); |
| 262 } | 203 } |
| 263 | 204 |
| 264 void ExtensionInstallUIDefault::OnInstallFailure( | 205 void ExtensionInstallUIDefault::OnInstallFailure( |
| 265 const extensions::CrxInstallerError& error) { | 206 const extensions::CrxInstallerError& error) { |
| 266 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 207 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 267 if (disable_failure_ui_for_tests() || skip_post_install_ui()) | 208 if (disable_failure_ui_for_tests() || skip_post_install_ui_) |
| 268 return; | 209 return; |
| 269 | 210 |
| 270 Browser* browser = | 211 Browser* browser = |
| 271 chrome::FindLastActiveWithProfile(profile(), chrome::GetActiveDesktop()); | 212 chrome::FindLastActiveWithProfile(profile_, chrome::GetActiveDesktop()); |
| 272 if (!browser) // Can be NULL in unittests. | 213 if (!browser) // Can be NULL in unittests. |
| 273 return; | 214 return; |
| 274 WebContents* web_contents = | 215 WebContents* web_contents = |
| 275 browser->tab_strip_model()->GetActiveWebContents(); | 216 browser->tab_strip_model()->GetActiveWebContents(); |
| 276 if (!web_contents) | 217 if (!web_contents) |
| 277 return; | 218 return; |
| 278 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), | 219 ErrorInfoBarDelegate::Create(InfoBarService::FromWebContents(web_contents), |
| 279 error); | 220 error); |
| 280 } | 221 } |
| 281 | 222 |
| 223 void ExtensionInstallUIDefault::OpenAppInstalledUI(const std::string& app_id) { |
| 224 #if defined(OS_CHROMEOS) |
| 225 // App Launcher always enabled on ChromeOS, so always handled in |
| 226 // OnInstallSuccess. |
| 227 NOTREACHED(); |
| 228 #else |
| 229 Profile* current_profile = profile_->GetOriginalProfile(); |
| 230 Browser* browser = FindOrCreateVisibleBrowser(current_profile); |
| 231 if (browser) { |
| 232 GURL url(chrome::IsInstantExtendedAPIEnabled() |
| 233 ? chrome::kChromeUIAppsURL |
| 234 : chrome::kChromeUINewTabURL); |
| 235 chrome::NavigateParams params( |
| 236 chrome::GetSingletonTabNavigateParams(browser, url)); |
| 237 chrome::Navigate(¶ms); |
| 238 |
| 239 content::NotificationService::current()->Notify( |
| 240 chrome::NOTIFICATION_APP_INSTALLED_TO_NTP, |
| 241 content::Source<WebContents>(params.target_contents), |
| 242 content::Details<const std::string>(&app_id)); |
| 243 } |
| 244 #endif |
| 245 } |
| 246 |
| 282 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { | 247 void ExtensionInstallUIDefault::SetUseAppInstalledBubble(bool use_bubble) { |
| 283 use_app_installed_bubble_ = use_bubble; | 248 use_app_installed_bubble_ = use_bubble; |
| 284 } | 249 } |
| 250 |
| 251 void ExtensionInstallUIDefault::SetSkipPostInstallUI(bool skip_ui) { |
| 252 skip_post_install_ui_ = skip_ui; |
| 253 } |
| 254 |
| 255 gfx::NativeWindow ExtensionInstallUIDefault::GetDefaultInstallDialogParent() { |
| 256 Browser* browser = |
| 257 chrome::FindLastActiveWithProfile(profile_, chrome::GetActiveDesktop()); |
| 258 if (browser) { |
| 259 content::WebContents* contents = |
| 260 browser->tab_strip_model()->GetActiveWebContents(); |
| 261 return contents->GetTopLevelNativeWindow(); |
| 262 } |
| 263 return NULL; |
| 264 } |
| OLD | NEW |