| 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/startup/startup_browser_creator_impl.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #include "chrome/common/chrome_notification_types.h" | 65 #include "chrome/common/chrome_notification_types.h" |
| 66 #include "chrome/common/chrome_paths.h" | 66 #include "chrome/common/chrome_paths.h" |
| 67 #include "chrome/common/chrome_result_codes.h" | 67 #include "chrome/common/chrome_result_codes.h" |
| 68 #include "chrome/common/chrome_switches.h" | 68 #include "chrome/common/chrome_switches.h" |
| 69 #include "chrome/common/chrome_version_info.h" | 69 #include "chrome/common/chrome_version_info.h" |
| 70 #include "chrome/common/extensions/extension_constants.h" | 70 #include "chrome/common/extensions/extension_constants.h" |
| 71 #include "chrome/common/pref_names.h" | 71 #include "chrome/common/pref_names.h" |
| 72 #include "chrome/common/url_constants.h" | 72 #include "chrome/common/url_constants.h" |
| 73 #include "chrome/installer/util/browser_distribution.h" | 73 #include "chrome/installer/util/browser_distribution.h" |
| 74 #include "content/public/browser/child_process_security_policy.h" | 74 #include "content/public/browser/child_process_security_policy.h" |
| 75 #include "content/public/browser/notification_observer.h" |
| 76 #include "content/public/browser/notification_registrar.h" |
| 75 #include "content/public/browser/web_contents.h" | 77 #include "content/public/browser/web_contents.h" |
| 76 #include "content/public/browser/web_contents_view.h" | 78 #include "content/public/browser/web_contents_view.h" |
| 77 #include "grit/locale_settings.h" | 79 #include "grit/locale_settings.h" |
| 78 #include "ui/base/l10n/l10n_util.h" | 80 #include "ui/base/l10n/l10n_util.h" |
| 79 #include "ui/base/resource/resource_bundle.h" | 81 #include "ui/base/resource/resource_bundle.h" |
| 80 | 82 |
| 81 #if defined(OS_MACOSX) | 83 #if defined(OS_MACOSX) |
| 82 #include "base/mac/mac_util.h" | 84 #include "base/mac/mac_util.h" |
| 83 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" | 85 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" |
| 84 #endif | 86 #endif |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 220 } |
| 219 } | 221 } |
| 220 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { | 222 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { |
| 221 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { | 223 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { |
| 222 AppLauncherHandler::RecordAppLaunchType( | 224 AppLauncherHandler::RecordAppLaunchType( |
| 223 extension_misc::APP_LAUNCH_AUTOLAUNCH); | 225 extension_misc::APP_LAUNCH_AUTOLAUNCH); |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 230 class WebContentsCloseObserver : public content::NotificationObserver { |
| 231 public: |
| 232 WebContentsCloseObserver() : contents_(NULL) {} |
| 233 virtual ~WebContentsCloseObserver() {} |
| 234 |
| 235 void SetContents(content::WebContents* contents) { |
| 236 DCHECK(!contents_); |
| 237 contents_ = contents; |
| 238 |
| 239 registrar_.Add(this, |
| 240 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 241 content::Source<content::WebContents>(contents_)); |
| 242 } |
| 243 |
| 244 content::WebContents* contents() { return contents_; } |
| 245 |
| 246 private: |
| 247 // content::NotificationObserver overrides: |
| 248 virtual void Observe(int type, |
| 249 const content::NotificationSource& source, |
| 250 const content::NotificationDetails& details) OVERRIDE { |
| 251 DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_DESTROYED); |
| 252 contents_ = NULL; |
| 253 } |
| 254 |
| 255 content::WebContents* contents_; |
| 256 content::NotificationRegistrar registrar_; |
| 257 |
| 258 DISALLOW_COPY_AND_ASSIGN(WebContentsCloseObserver); |
| 259 }; |
| 260 |
| 228 } // namespace | 261 } // namespace |
| 229 | 262 |
| 230 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( | 263 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( |
| 231 const FilePath& cur_dir, | 264 const FilePath& cur_dir, |
| 232 const CommandLine& command_line, | 265 const CommandLine& command_line, |
| 233 chrome::startup::IsFirstRun is_first_run) | 266 chrome::startup::IsFirstRun is_first_run) |
| 234 : cur_dir_(cur_dir), | 267 : cur_dir_(cur_dir), |
| 235 command_line_(command_line), | 268 command_line_(command_line), |
| 236 profile_(NULL), | 269 profile_(NULL), |
| 237 browser_creator_(NULL), | 270 browser_creator_(NULL), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 !browser_defaults::kAppRestoreSession) { | 334 !browser_defaults::kAppRestoreSession) { |
| 302 RecordLaunchModeHistogram(LM_AS_WEBAPP); | 335 RecordLaunchModeHistogram(LM_AS_WEBAPP); |
| 303 } else { | 336 } else { |
| 304 RecordLaunchModeHistogram(urls_to_open.empty() ? | 337 RecordLaunchModeHistogram(urls_to_open.empty() ? |
| 305 LM_TO_BE_DECIDED : LM_WITH_URLS); | 338 LM_TO_BE_DECIDED : LM_WITH_URLS); |
| 306 | 339 |
| 307 // Notify user if the Preferences backup is invalid or changes to settings | 340 // Notify user if the Preferences backup is invalid or changes to settings |
| 308 // affecting browser startup have been detected. | 341 // affecting browser startup have been detected. |
| 309 CheckPreferencesBackup(profile); | 342 CheckPreferencesBackup(profile); |
| 310 | 343 |
| 344 // Watch for |app_contents| closing since ProcessLaunchURLs might run a |
| 345 // synchronous session restore which has a nested message loop and could |
| 346 // close |app_contents|. |
| 347 WebContentsCloseObserver app_contents_observer; |
| 348 if (browser_defaults::kAppRestoreSession && app_contents) |
| 349 app_contents_observer.SetContents(app_contents); |
| 350 |
| 311 ProcessLaunchURLs(process_startup, urls_to_open); | 351 ProcessLaunchURLs(process_startup, urls_to_open); |
| 312 | 352 |
| 313 // If this is an app launch, but we didn't open an app window, it may | 353 // If this is an app launch, but we didn't open an app window, it may |
| 314 // be an app tab. | 354 // be an app tab. |
| 315 OpenApplicationTab(profile); | 355 OpenApplicationTab(profile); |
| 316 | 356 |
| 317 // In case of app mode + session restore we want to focus that app. | 357 // In case of app mode + session restore we want to focus that app. |
| 318 if (browser_defaults::kAppRestoreSession && app_contents) | 358 if (app_contents_observer.contents()) |
| 319 app_contents->GetView()->SetInitialFocus(); | 359 app_contents_observer.contents()->GetView()->SetInitialFocus(); |
| 320 | 360 |
| 321 if (process_startup) { | 361 if (process_startup) { |
| 322 if (browser_defaults::kOSSupportsOtherBrowsers && | 362 if (browser_defaults::kOSSupportsOtherBrowsers && |
| 323 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { | 363 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { |
| 324 if (!chrome::ShowAutolaunchPrompt(profile)) | 364 if (!chrome::ShowAutolaunchPrompt(profile)) |
| 325 chrome::ShowDefaultBrowserPrompt(profile); | 365 chrome::ShowDefaultBrowserPrompt(profile); |
| 326 } | 366 } |
| 327 #if defined(OS_MACOSX) | 367 #if defined(OS_MACOSX) |
| 328 // Check whether the auto-update system needs to be promoted from user | 368 // Check whether the auto-update system needs to be promoted from user |
| 329 // to system. | 369 // to system. |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 // New: | 901 // New: |
| 862 prefs->GetString(prefs::kHomePage), | 902 prefs->GetString(prefs::kHomePage), |
| 863 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), | 903 prefs->GetBoolean(prefs::kHomePageIsNewTabPage), |
| 864 prefs->GetBoolean(prefs::kShowHomeButton), | 904 prefs->GetBoolean(prefs::kShowHomeButton), |
| 865 // Backup: | 905 // Backup: |
| 866 backup_homepage, | 906 backup_homepage, |
| 867 backup_homepage_is_ntp, | 907 backup_homepage_is_ntp, |
| 868 backup_show_home_button)); | 908 backup_show_home_button)); |
| 869 } | 909 } |
| 870 } | 910 } |
| OLD | NEW |