Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "apps/app_restore_service.h" | 10 #include "apps/app_restore_service.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { | 246 for (size_t i = 0; i < autolaunch_tabs.size(); ++i) { |
| 247 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { | 247 if (extension_service->IsInstalledApp(autolaunch_tabs.at(i).url)) { |
| 248 AppLauncherHandler::RecordAppLaunchType( | 248 AppLauncherHandler::RecordAppLaunchType( |
| 249 extension_misc::APP_LAUNCH_AUTOLAUNCH); | 249 extension_misc::APP_LAUNCH_AUTOLAUNCH); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool IsNewTabURL(const GURL& url, Profile* profile) { | |
|
sky
2013/03/08 16:04:19
IsNewTabOrHomePage()
sail
2013/03/08 20:06:43
The "OrHomePage()" part isn't true. It's only if t
| |
| 255 GURL ntp_url(chrome::kChromeUINewTabURL); | |
| 256 return url == ntp_url || | |
| 257 (url.is_empty() && profile->GetHomePage() == ntp_url); | |
| 258 } | |
| 259 | |
| 260 void AddSyncPromoTab(StartupTabs* tabs, Profile* profile) { | |
|
sky
2013/03/08 16:04:19
out params should be last, so profile first then t
sail
2013/03/08 20:06:43
Done.
| |
| 261 SyncPromoUI::DidShowSyncPromoAtStartup(profile); | |
| 262 | |
| 263 StartupTab sync_promo_tab; | |
| 264 GURL continue_url; | |
| 265 if (!SyncPromoUI::UseWebBasedSigninFlow()) | |
| 266 continue_url = GURL(chrome::kChromeUINewTabURL); | |
| 267 sync_promo_tab.url = SyncPromoUI::GetSyncPromoURL( | |
| 268 continue_url, SyncPromoUI::SOURCE_START_PAGE, false); | |
| 269 sync_promo_tab.is_pinned = false; | |
| 270 tabs->insert(tabs->begin(), sync_promo_tab); | |
| 271 | |
| 272 // If the next URL is the NTP then remove it, effectively replacing the NTP | |
| 273 // with the sync promo. | |
| 274 if (tabs->size() > 1 && IsNewTabURL(tabs->at(1).url, profile)) | |
| 275 tabs->erase(tabs->begin() + 1); | |
|
gab
2013/03/08 14:39:32
This will remove the NTP even if it was intentiona
sail
2013/03/08 20:06:43
This behavior is intentional. When the sync promo
| |
| 276 } | |
| 277 | |
| 254 class WebContentsCloseObserver : public content::NotificationObserver { | 278 class WebContentsCloseObserver : public content::NotificationObserver { |
| 255 public: | 279 public: |
| 256 WebContentsCloseObserver() : contents_(NULL) {} | 280 WebContentsCloseObserver() : contents_(NULL) {} |
| 257 virtual ~WebContentsCloseObserver() {} | 281 virtual ~WebContentsCloseObserver() {} |
| 258 | 282 |
| 259 void SetContents(content::WebContents* contents) { | 283 void SetContents(content::WebContents* contents) { |
| 260 DCHECK(!contents_); | 284 DCHECK(!contents_); |
| 261 contents_ = contents; | 285 contents_ = contents; |
| 262 | 286 |
| 263 registrar_.Add(this, | 287 registrar_.Add(this, |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 // Only use the set of urls specified in preferences if nothing was | 723 // Only use the set of urls specified in preferences if nothing was |
| 700 // specified on the command line. Filter out any urls that are to be | 724 // specified on the command line. Filter out any urls that are to be |
| 701 // restored by virtue of having been previously pinned. | 725 // restored by virtue of having been previously pinned. |
| 702 AddUniqueURLs(pref.urls, &tabs); | 726 AddUniqueURLs(pref.urls, &tabs); |
| 703 } else if (pref.type == SessionStartupPref::HOMEPAGE) { | 727 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
| 704 // If 'homepage' selected, either by the user or by a policy, we should | 728 // If 'homepage' selected, either by the user or by a policy, we should |
| 705 // have migrated them to another value. | 729 // have migrated them to another value. |
| 706 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; | 730 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; |
| 707 } | 731 } |
| 708 | 732 |
| 733 if (pref.type != SessionStartupPref::LAST && | |
| 734 SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) { | |
| 735 AddSyncPromoTab(&tabs, profile_); | |
| 736 } | |
| 737 | |
| 709 if (tabs.empty()) | 738 if (tabs.empty()) |
| 710 return NULL; | 739 return NULL; |
| 711 | 740 |
| 712 Browser* browser = OpenTabsInBrowser(NULL, true, tabs); | 741 Browser* browser = OpenTabsInBrowser(NULL, true, tabs); |
| 713 return browser; | 742 return browser; |
| 714 } | 743 } |
| 715 | 744 |
| 716 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, | 745 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, |
| 717 StartupTabs* tabs) { | 746 StartupTabs* tabs) { |
| 718 size_t num_existing_tabs = tabs->size(); | 747 size_t num_existing_tabs = tabs->size(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 902 command_line_.HasSwitch(switches::kResetLocalPassphrase); | 931 command_line_.HasSwitch(switches::kResetLocalPassphrase); |
| 903 if ((is_first_run_ || has_reset_local_passphrase_switch) && | 932 if ((is_first_run_ || has_reset_local_passphrase_switch) && |
| 904 prefs->GetBoolean(prefs::kProfileIsManaged)) { | 933 prefs->GetBoolean(prefs::kProfileIsManaged)) { |
| 905 startup_urls->insert(startup_urls->begin(), | 934 startup_urls->insert(startup_urls->begin(), |
| 906 GURL(std::string(chrome::kChromeUISettingsURL) + | 935 GURL(std::string(chrome::kChromeUISettingsURL) + |
| 907 chrome::kManagedUserSettingsSubPage)); | 936 chrome::kManagedUserSettingsSubPage)); |
| 908 if (has_reset_local_passphrase_switch) { | 937 if (has_reset_local_passphrase_switch) { |
| 909 prefs->SetString(prefs::kManagedModeLocalPassphrase, ""); | 938 prefs->SetString(prefs::kManagedModeLocalPassphrase, ""); |
| 910 prefs->SetString(prefs::kManagedModeLocalSalt, ""); | 939 prefs->SetString(prefs::kManagedModeLocalSalt, ""); |
| 911 } | 940 } |
| 912 } else if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, | |
| 913 is_first_run_)) { | |
| 914 // If the sync promo page is going to be displayed then insert it at the | |
| 915 // front of the list. | |
| 916 GURL continue_url; | |
| 917 if (!SyncPromoUI::UseWebBasedSigninFlow()) { | |
| 918 continue_url = GURL(chrome::kChromeUINewTabURL); | |
| 919 } | |
| 920 | |
| 921 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); | |
| 922 GURL old_url = (*startup_urls)[0]; | |
| 923 (*startup_urls)[0] = | |
| 924 SyncPromoUI::GetSyncPromoURL(continue_url, | |
| 925 SyncPromoUI::SOURCE_START_PAGE, | |
| 926 false); | |
| 927 | |
| 928 // An empty URL means to go to the home page. | |
| 929 if (old_url.is_empty() && | |
| 930 profile_->GetHomePage() == GURL(chrome::kChromeUINewTabURL)) { | |
| 931 old_url = GURL(chrome::kChromeUINewTabURL); | |
| 932 } | |
| 933 | |
| 934 // If the old URL is not the NTP then insert it right after the sync promo. | |
| 935 if (old_url != GURL(chrome::kChromeUINewTabURL)) | |
| 936 startup_urls->insert(startup_urls->begin() + 1, old_url); | |
| 937 } | 941 } |
| 938 } | 942 } |
| 939 | 943 |
| 940 #if !defined(OS_WIN) || defined(USE_AURA) | 944 #if !defined(OS_WIN) || defined(USE_AURA) |
| 941 // static | 945 // static |
| 942 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( | 946 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( |
| 943 Profile* profile, | 947 Profile* profile, |
| 944 const std::vector<GURL>& startup_urls) { | 948 const std::vector<GURL>& startup_urls) { |
| 945 return false; | 949 return false; |
| 946 } | 950 } |
| 947 #endif | 951 #endif |
| OLD | NEW |