| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool IsNewTabURL(Profile* profile, const GURL& url) { | 269 bool IsNewTabURL(Profile* profile, const GURL& url) { |
| 270 GURL ntp_url(chrome::kChromeUINewTabURL); | 270 GURL ntp_url(chrome::kChromeUINewTabURL); |
| 271 return url == ntp_url || | 271 return url == ntp_url || |
| 272 (url.is_empty() && profile->GetHomePage() == ntp_url); | 272 (url.is_empty() && profile->GetHomePage() == ntp_url); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void AddSyncPromoTab(Profile* profile, StartupTabs* tabs) { | |
| 276 SyncPromoUI::DidShowSyncPromoAtStartup(profile); | |
| 277 | |
| 278 StartupTab sync_promo_tab; | |
| 279 sync_promo_tab.url = SyncPromoUI::GetSyncPromoURL( | |
| 280 SyncPromoUI::SOURCE_START_PAGE, false); | |
| 281 sync_promo_tab.is_pinned = false; | |
| 282 | |
| 283 // No need to add if the sync promo is already in the startup list. | |
| 284 for (StartupTabs::const_iterator it = tabs->begin(); it != tabs->end(); | |
| 285 ++it) { | |
| 286 if (it->url == sync_promo_tab.url) | |
| 287 return; | |
| 288 } | |
| 289 | |
| 290 tabs->insert(tabs->begin(), sync_promo_tab); | |
| 291 | |
| 292 // If the next URL is the NTP then remove it, effectively replacing the NTP | |
| 293 // with the sync promo. This behavior is desired because completing or | |
| 294 // skipping the sync promo causes a redirect to the NTP. | |
| 295 if (tabs->size() > 1 && IsNewTabURL(profile, tabs->at(1).url)) | |
| 296 tabs->erase(tabs->begin() + 1); | |
| 297 } | |
| 298 | |
| 299 class WebContentsCloseObserver : public content::NotificationObserver { | 275 class WebContentsCloseObserver : public content::NotificationObserver { |
| 300 public: | 276 public: |
| 301 WebContentsCloseObserver() : contents_(NULL) {} | 277 WebContentsCloseObserver() : contents_(NULL) {} |
| 302 virtual ~WebContentsCloseObserver() {} | 278 virtual ~WebContentsCloseObserver() {} |
| 303 | 279 |
| 304 void SetContents(content::WebContents* contents) { | 280 void SetContents(content::WebContents* contents) { |
| 305 DCHECK(!contents_); | 281 DCHECK(!contents_); |
| 306 contents_ = contents; | 282 contents_ = contents; |
| 307 | 283 |
| 308 registrar_.Add(this, | 284 registrar_.Add(this, |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 // Only use the set of urls specified in preferences if nothing was | 732 // Only use the set of urls specified in preferences if nothing was |
| 757 // specified on the command line. Filter out any urls that are to be | 733 // specified on the command line. Filter out any urls that are to be |
| 758 // restored by virtue of having been previously pinned. | 734 // restored by virtue of having been previously pinned. |
| 759 AddUniqueURLs(pref.urls, &tabs); | 735 AddUniqueURLs(pref.urls, &tabs); |
| 760 } else if (pref.type == SessionStartupPref::HOMEPAGE) { | 736 } else if (pref.type == SessionStartupPref::HOMEPAGE) { |
| 761 // If 'homepage' selected, either by the user or by a policy, we should | 737 // If 'homepage' selected, either by the user or by a policy, we should |
| 762 // have migrated them to another value. | 738 // have migrated them to another value. |
| 763 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; | 739 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; |
| 764 } | 740 } |
| 765 | 741 |
| 766 if (pref.type != SessionStartupPref::LAST && | |
| 767 SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) { | |
| 768 AddSyncPromoTab(profile_, &tabs); | |
| 769 } | |
| 770 | |
| 771 if (tabs.empty()) | 742 if (tabs.empty()) |
| 772 return NULL; | 743 return NULL; |
| 773 | 744 |
| 774 Browser* browser = OpenTabsInBrowser(NULL, true, tabs, desktop_type); | 745 Browser* browser = OpenTabsInBrowser(NULL, true, tabs, desktop_type); |
| 775 return browser; | 746 return browser; |
| 776 } | 747 } |
| 777 | 748 |
| 778 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, | 749 void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, |
| 779 StartupTabs* tabs) { | 750 StartupTabs* tabs) { |
| 780 size_t num_existing_tabs = tabs->size(); | 751 size_t num_existing_tabs = tabs->size(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 (browser_creator_ && | 894 (browser_creator_ && |
| 924 browser_creator_->is_default_browser_dialog_suppressed())) && | 895 browser_creator_->is_default_browser_dialog_suppressed())) && |
| 925 !chrome::ShowAutolaunchPrompt(browser)) { | 896 !chrome::ShowAutolaunchPrompt(browser)) { |
| 926 chrome::ShowDefaultBrowserPrompt(profile_, | 897 chrome::ShowDefaultBrowserPrompt(profile_, |
| 927 browser->host_desktop_type()); | 898 browser->host_desktop_type()); |
| 928 } | 899 } |
| 929 } | 900 } |
| 930 } | 901 } |
| 931 } | 902 } |
| 932 | 903 |
| 933 | |
| 934 void StartupBrowserCreatorImpl::AddStartupURLs( | 904 void StartupBrowserCreatorImpl::AddStartupURLs( |
| 935 std::vector<GURL>* startup_urls) const { | 905 std::vector<GURL>* startup_urls) const { |
| 906 // TODO(atwilson): Simplify the logic that decides which tabs to open on |
| 907 // start-up and make it more consistent. http://crbug.com/248883 |
| 908 |
| 936 // If we have urls specified by the first run master preferences use them | 909 // If we have urls specified by the first run master preferences use them |
| 937 // and nothing else. | 910 // and nothing else. |
| 938 if (browser_creator_ && startup_urls->empty()) { | 911 if (browser_creator_ && startup_urls->empty()) { |
| 939 if (!browser_creator_->first_run_tabs_.empty()) { | 912 if (!browser_creator_->first_run_tabs_.empty()) { |
| 940 std::vector<GURL>::iterator it = | 913 std::vector<GURL>::iterator it = |
| 941 browser_creator_->first_run_tabs_.begin(); | 914 browser_creator_->first_run_tabs_.begin(); |
| 942 while (it != browser_creator_->first_run_tabs_.end()) { | 915 while (it != browser_creator_->first_run_tabs_.end()) { |
| 943 // Replace magic names for the actual urls. | 916 // Replace magic names for the actual urls. |
| 944 if (it->host() == "new_tab_page") { | 917 if (it->host() == "new_tab_page") { |
| 945 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 918 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
| 946 } else if (it->host() == "welcome_page") { | 919 } else if (it->host() == "welcome_page") { |
| 947 startup_urls->push_back(internals::GetWelcomePageURL()); | 920 startup_urls->push_back(internals::GetWelcomePageURL()); |
| 948 } else { | 921 } else { |
| 949 startup_urls->push_back(*it); | 922 startup_urls->push_back(*it); |
| 950 } | 923 } |
| 951 ++it; | 924 ++it; |
| 952 } | 925 } |
| 953 browser_creator_->first_run_tabs_.clear(); | 926 browser_creator_->first_run_tabs_.clear(); |
| 954 } | 927 } |
| 955 } | 928 } |
| 956 | 929 |
| 957 // Otherwise open at least the new tab page (and the welcome page, if this | 930 // Otherwise open at least the new tab page (and the welcome page, if this |
| 958 // is the first time the browser is being started), or the set of URLs | 931 // is the first time the browser is being started), or the set of URLs |
| 959 // specified on the command line. | 932 // specified on the command line. |
| 960 if (startup_urls->empty()) { | 933 if (startup_urls->empty()) { |
| 961 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 934 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); |
| 962 if (first_run::ShouldShowWelcomePage()) | 935 if (first_run::ShouldShowWelcomePage()) |
| 963 startup_urls->push_back(internals::GetWelcomePageURL()); | 936 startup_urls->push_back(internals::GetWelcomePageURL()); |
| 964 } | 937 } |
| 938 |
| 939 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) { |
| 940 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); |
| 941 |
| 942 const GURL sync_promo_url = SyncPromoUI::GetSyncPromoURL( |
| 943 SyncPromoUI::SOURCE_START_PAGE, false); |
| 944 |
| 945 // No need to add if the sync promo is already in the startup list. |
| 946 bool add_promo = true; |
| 947 for (std::vector<GURL>::const_iterator it = startup_urls->begin(); |
| 948 it != startup_urls->end(); ++it) { |
| 949 if (*it == sync_promo_url) { |
| 950 add_promo = false; |
| 951 break; |
| 952 } |
| 953 } |
| 954 |
| 955 if (add_promo) { |
| 956 // If the first URL is the NTP, replace it with the sync promo. This |
| 957 // behavior is desired because completing or skipping the sync promo |
| 958 // causes a redirect to the NTP. |
| 959 if (!startup_urls->empty() && IsNewTabURL(profile_, startup_urls->at(0))) |
| 960 startup_urls->at(0) = sync_promo_url; |
| 961 else |
| 962 startup_urls->insert(startup_urls->begin(), sync_promo_url); |
| 963 } |
| 964 } |
| 965 } | 965 } |
| 966 | 966 |
| 967 #if !defined(OS_WIN) | 967 #if !defined(OS_WIN) |
| 968 // static | 968 // static |
| 969 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( | 969 bool StartupBrowserCreatorImpl::OpenStartupURLsInExistingBrowser( |
| 970 Profile* profile, | 970 Profile* profile, |
| 971 const std::vector<GURL>& startup_urls) { | 971 const std::vector<GURL>& startup_urls) { |
| 972 return false; | 972 return false; |
| 973 } | 973 } |
| 974 #endif | 974 #endif |
| OLD | NEW |