OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_init.h" | 5 #include "chrome/browser/ui/browser_init.h" |
6 | 6 |
7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 #include "chrome/browser/sessions/session_service_factory.h" | 51 #include "chrome/browser/sessions/session_service_factory.h" |
52 #include "chrome/browser/shell_integration.h" | 52 #include "chrome/browser/shell_integration.h" |
53 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 53 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
54 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 54 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
55 #include "chrome/browser/tabs/pinned_tab_codec.h" | 55 #include "chrome/browser/tabs/pinned_tab_codec.h" |
56 #include "chrome/browser/tabs/tab_strip_model.h" | 56 #include "chrome/browser/tabs/tab_strip_model.h" |
57 #include "chrome/browser/ui/browser_list.h" | 57 #include "chrome/browser/ui/browser_list.h" |
58 #include "chrome/browser/ui/browser_navigator.h" | 58 #include "chrome/browser/ui/browser_navigator.h" |
59 #include "chrome/browser/ui/browser_window.h" | 59 #include "chrome/browser/ui/browser_window.h" |
60 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 60 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
61 #include "chrome/browser/ui/webui/sync_promo_ui.h" | |
61 #include "chrome/common/chrome_constants.h" | 62 #include "chrome/common/chrome_constants.h" |
62 #include "chrome/common/chrome_paths.h" | 63 #include "chrome/common/chrome_paths.h" |
63 #include "chrome/common/chrome_result_codes.h" | 64 #include "chrome/common/chrome_result_codes.h" |
64 #include "chrome/common/chrome_switches.h" | 65 #include "chrome/common/chrome_switches.h" |
65 #include "chrome/common/extensions/extension_constants.h" | 66 #include "chrome/common/extensions/extension_constants.h" |
66 #include "chrome/common/pref_names.h" | 67 #include "chrome/common/pref_names.h" |
67 #include "chrome/common/url_constants.h" | 68 #include "chrome/common/url_constants.h" |
68 #include "chrome/installer/util/browser_distribution.h" | 69 #include "chrome/installer/util/browser_distribution.h" |
69 #include "content/browser/browser_thread.h" | 70 #include "content/browser/browser_thread.h" |
70 #include "content/browser/child_process_security_policy.h" | 71 #include "content/browser/child_process_security_policy.h" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 } | 554 } |
554 | 555 |
555 // static | 556 // static |
556 bool BrowserInit::InProcessStartup() { | 557 bool BrowserInit::InProcessStartup() { |
557 return in_startup; | 558 return in_startup; |
558 } | 559 } |
559 | 560 |
560 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, | 561 bool BrowserInit::LaunchBrowser(const CommandLine& command_line, |
561 Profile* profile, | 562 Profile* profile, |
562 const FilePath& cur_dir, | 563 const FilePath& cur_dir, |
563 bool process_startup, | 564 IsProcessStartup process_startup, |
565 IsFirstRun is_first_run, | |
564 int* return_code) { | 566 int* return_code) { |
565 in_startup = process_startup; | 567 in_startup = process_startup == IS_PROCESS_STARTUP; |
566 DCHECK(profile); | 568 DCHECK(profile); |
567 | 569 |
568 // Continue with the incognito profile from here on if Incognito mode | 570 // Continue with the incognito profile from here on if Incognito mode |
569 // is forced. | 571 // is forced. |
570 if (IncognitoIsForced(command_line, profile->GetPrefs())) { | 572 if (IncognitoIsForced(command_line, profile->GetPrefs())) { |
571 profile = profile->GetOffTheRecordProfile(); | 573 profile = profile->GetOffTheRecordProfile(); |
572 } else if (command_line.HasSwitch(switches::kIncognito)) { | 574 } else if (command_line.HasSwitch(switches::kIncognito)) { |
573 LOG(WARNING) << "Incognito mode disabled by policy, launching a normal " | 575 LOG(WARNING) << "Incognito mode disabled by policy, launching a normal " |
574 << "browser session."; | 576 << "browser session."; |
575 } | 577 } |
576 | 578 |
577 BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, this); | 579 BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, this, is_first_run); |
578 std::vector<GURL> urls_to_launch = BrowserInit::GetURLsFromCommandLine( | 580 std::vector<GURL> urls_to_launch = BrowserInit::GetURLsFromCommandLine( |
579 command_line, cur_dir, profile); | 581 command_line, cur_dir, profile); |
580 bool launched = lwp.Launch(profile, urls_to_launch, process_startup); | 582 bool launched = lwp.Launch(profile, urls_to_launch, process_startup); |
581 in_startup = false; | 583 in_startup = false; |
582 | 584 |
583 if (!launched) { | 585 if (!launched) { |
584 LOG(ERROR) << "launch error"; | 586 LOG(ERROR) << "launch error"; |
585 if (return_code) | 587 if (return_code) |
586 *return_code = chrome::RESULT_CODE_INVALID_CMDLINE_URL; | 588 *return_code = chrome::RESULT_CODE_INVALID_CMDLINE_URL; |
587 return false; | 589 return false; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 | 639 |
638 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} | 640 BrowserInit::LaunchWithProfile::Tab::Tab() : is_app(false), is_pinned(true) {} |
639 | 641 |
640 BrowserInit::LaunchWithProfile::Tab::~Tab() {} | 642 BrowserInit::LaunchWithProfile::Tab::~Tab() {} |
641 | 643 |
642 | 644 |
643 // BrowserInit::LaunchWithProfile --------------------------------------------- | 645 // BrowserInit::LaunchWithProfile --------------------------------------------- |
644 | 646 |
645 BrowserInit::LaunchWithProfile::LaunchWithProfile( | 647 BrowserInit::LaunchWithProfile::LaunchWithProfile( |
646 const FilePath& cur_dir, | 648 const FilePath& cur_dir, |
647 const CommandLine& command_line) | 649 const CommandLine& command_line, |
650 IsFirstRun is_first_run) | |
648 : cur_dir_(cur_dir), | 651 : cur_dir_(cur_dir), |
649 command_line_(command_line), | 652 command_line_(command_line), |
650 profile_(NULL), | 653 profile_(NULL), |
651 browser_init_(NULL) { | 654 browser_init_(NULL), |
655 is_first_run_(is_first_run) { | |
652 } | 656 } |
653 | 657 |
654 BrowserInit::LaunchWithProfile::LaunchWithProfile( | 658 BrowserInit::LaunchWithProfile::LaunchWithProfile( |
655 const FilePath& cur_dir, | 659 const FilePath& cur_dir, |
656 const CommandLine& command_line, | 660 const CommandLine& command_line, |
657 BrowserInit* browser_init) | 661 BrowserInit* browser_init, |
662 IsFirstRun is_first_run) | |
658 : cur_dir_(cur_dir), | 663 : cur_dir_(cur_dir), |
659 command_line_(command_line), | 664 command_line_(command_line), |
660 profile_(NULL), | 665 profile_(NULL), |
661 browser_init_(browser_init) { | 666 browser_init_(browser_init), |
667 is_first_run_(is_first_run) { | |
662 } | 668 } |
663 | 669 |
664 BrowserInit::LaunchWithProfile::~LaunchWithProfile() { | 670 BrowserInit::LaunchWithProfile::~LaunchWithProfile() { |
665 } | 671 } |
666 | 672 |
667 bool BrowserInit::LaunchWithProfile::Launch( | 673 bool BrowserInit::LaunchWithProfile::Launch( |
668 Profile* profile, | 674 Profile* profile, |
669 const std::vector<GURL>& urls_to_open, | 675 const std::vector<GURL>& urls_to_open, |
670 bool process_startup) { | 676 bool process_startup) { |
671 DCHECK(profile); | 677 DCHECK(profile); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1234 } | 1240 } |
1235 #endif | 1241 #endif |
1236 } | 1242 } |
1237 | 1243 |
1238 void BrowserInit::LaunchWithProfile::AddStartupURLs( | 1244 void BrowserInit::LaunchWithProfile::AddStartupURLs( |
1239 std::vector<GURL>* startup_urls) const { | 1245 std::vector<GURL>* startup_urls) const { |
1240 // If we have urls specified beforehand (i.e. from command line) use them | 1246 // If we have urls specified beforehand (i.e. from command line) use them |
1241 // and nothing else. | 1247 // and nothing else. |
1242 if (!startup_urls->empty()) | 1248 if (!startup_urls->empty()) |
1243 return; | 1249 return; |
1250 | |
1244 // If we have urls specified by the first run master preferences use them | 1251 // If we have urls specified by the first run master preferences use them |
1245 // and nothing else. | 1252 // and nothing else. |
1246 if (browser_init_) { | 1253 if (browser_init_) { |
1247 if (!browser_init_->first_run_tabs_.empty()) { | 1254 if (!browser_init_->first_run_tabs_.empty()) { |
1248 std::vector<GURL>::iterator it = browser_init_->first_run_tabs_.begin(); | 1255 std::vector<GURL>::iterator it = browser_init_->first_run_tabs_.begin(); |
1249 while (it != browser_init_->first_run_tabs_.end()) { | 1256 while (it != browser_init_->first_run_tabs_.end()) { |
1250 // Replace magic names for the actual urls. | 1257 // Replace magic names for the actual urls. |
1251 if (it->host() == "new_tab_page") { | 1258 if (it->host() == "new_tab_page") { |
1252 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | 1259 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, |
1260 is_first_run_ == IS_FIRST_RUN)) { | |
1261 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); | |
1262 startup_urls->push_back(GURL(chrome::kChromeUISyncPromoURL)); | |
1263 } else { | |
1264 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); | |
1265 } | |
1253 } else if (it->host() == "welcome_page") { | 1266 } else if (it->host() == "welcome_page") { |
1254 startup_urls->push_back(GetWelcomePageURL()); | 1267 startup_urls->push_back(GetWelcomePageURL()); |
1255 } else { | 1268 } else { |
1256 startup_urls->push_back(*it); | 1269 startup_urls->push_back(*it); |
1257 } | 1270 } |
1258 ++it; | 1271 ++it; |
1259 } | 1272 } |
1260 browser_init_->first_run_tabs_.clear(); | 1273 browser_init_->first_run_tabs_.clear(); |
1261 return; | 1274 return; |
1262 } | 1275 } |
1263 } | 1276 } |
1264 | 1277 |
1265 // Otherwise open at least the new tab page (and the welcome page, if this | 1278 // Otherwise open at least the new tab page (and the welcome page, if this |
1266 // is the first time the browser is being started), or the set of URLs | 1279 // is the first time the browser is being started), or the set of URLs |
1267 // specified on the command line. | 1280 // specified on the command line. |
1268 startup_urls->push_back(GURL()); // New tab page. | 1281 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, |
1282 is_first_run_ == IS_FIRST_RUN)) { | |
1283 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); | |
1284 startup_urls->push_back(GURL(chrome::kChromeUISyncPromoURL)); | |
1285 } else { | |
1286 startup_urls->push_back(GURL()); // New tab page. | |
1287 } | |
1269 PrefService* prefs = g_browser_process->local_state(); | 1288 PrefService* prefs = g_browser_process->local_state(); |
1270 if (prefs->FindPreference(prefs::kShouldShowWelcomePage) && | 1289 if (prefs->FindPreference(prefs::kShouldShowWelcomePage) && |
1271 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { | 1290 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { |
1272 // Reset the preference so we don't show the welcome page next time. | 1291 // Reset the preference so we don't show the welcome page next time. |
1292 startup_urls->push_back(GURL()); // New tab page. | |
sky
2011/10/04 20:13:23
Might 1286 have already added this?
sail
2011/10/04 20:56:24
Ouch, good catch. Don't know how that line got the
| |
1273 prefs->ClearPref(prefs::kShouldShowWelcomePage); | 1293 prefs->ClearPref(prefs::kShouldShowWelcomePage); |
1274 startup_urls->push_back(GetWelcomePageURL()); | 1294 startup_urls->push_back(GetWelcomePageURL()); |
1275 } | 1295 } |
1276 } | 1296 } |
1277 | 1297 |
1278 void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { | 1298 void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { |
1279 // We do not check if we are the default browser if: | 1299 // We do not check if we are the default browser if: |
1280 // - the user said "don't ask me again" on the infobar earlier. | 1300 // - the user said "don't ask me again" on the infobar earlier. |
1281 // - this is the first launch after the first run flow. | 1301 // - this is the first launch after the first run flow. |
1282 // - There is a policy in control of this setting. | 1302 // - There is a policy in control of this setting. |
1283 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || | 1303 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || |
1284 FirstRun::IsChromeFirstRun()) { | 1304 is_first_run_ == IS_FIRST_RUN) { |
1285 return; | 1305 return; |
1286 } | 1306 } |
1287 if (g_browser_process->local_state()->IsManagedPreference( | 1307 if (g_browser_process->local_state()->IsManagedPreference( |
1288 prefs::kDefaultBrowserSettingEnabled)) { | 1308 prefs::kDefaultBrowserSettingEnabled)) { |
1289 if (g_browser_process->local_state()->GetBoolean( | 1309 if (g_browser_process->local_state()->GetBoolean( |
1290 prefs::kDefaultBrowserSettingEnabled)) { | 1310 prefs::kDefaultBrowserSettingEnabled)) { |
1291 BrowserThread::PostTask( | 1311 BrowserThread::PostTask( |
1292 BrowserThread::FILE, FROM_HERE, NewRunnableFunction( | 1312 BrowserThread::FILE, FROM_HERE, NewRunnableFunction( |
1293 &ShellIntegration::SetAsDefaultBrowser)); | 1313 &ShellIntegration::SetAsDefaultBrowser)); |
1294 } else { | 1314 } else { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 DLOG(WARNING) << "Invalid touch-device id: " << *iter; | 1500 DLOG(WARNING) << "Invalid touch-device id: " << *iter; |
1481 } | 1501 } |
1482 } | 1502 } |
1483 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 1503 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
1484 } | 1504 } |
1485 #endif | 1505 #endif |
1486 | 1506 |
1487 // If we don't want to launch a new browser window or tab (in the case | 1507 // If we don't want to launch a new browser window or tab (in the case |
1488 // of an automation request), we are done here. | 1508 // of an automation request), we are done here. |
1489 if (!silent_launch) { | 1509 if (!silent_launch) { |
1490 return browser_init->LaunchBrowser( | 1510 IsProcessStartup is_process_startup = process_startup ? |
1491 command_line, profile, cur_dir, process_startup, return_code); | 1511 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; |
1512 IsFirstRun is_first_run = FirstRun::IsChromeFirstRun() ? | |
1513 IS_FIRST_RUN : IS_NOT_FIRST_RUN; | |
1514 return browser_init->LaunchBrowser(command_line, profile, cur_dir, | |
1515 is_process_startup, is_first_run, return_code); | |
1492 } | 1516 } |
1493 return true; | 1517 return true; |
1494 } | 1518 } |
1495 | 1519 |
1496 template <class AutomationProviderClass> | 1520 template <class AutomationProviderClass> |
1497 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1521 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
1498 Profile* profile, | 1522 Profile* profile, |
1499 size_t expected_tabs) { | 1523 size_t expected_tabs) { |
1500 scoped_refptr<AutomationProviderClass> automation = | 1524 scoped_refptr<AutomationProviderClass> automation = |
1501 new AutomationProviderClass(profile); | 1525 new AutomationProviderClass(profile); |
1502 | 1526 |
1503 if (!automation->InitializeChannel(channel_id)) | 1527 if (!automation->InitializeChannel(channel_id)) |
1504 return false; | 1528 return false; |
1505 automation->SetExpectedTabCount(expected_tabs); | 1529 automation->SetExpectedTabCount(expected_tabs); |
1506 | 1530 |
1507 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 1531 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
1508 DCHECK(list); | 1532 DCHECK(list); |
1509 list->AddProvider(automation); | 1533 list->AddProvider(automation); |
1510 | 1534 |
1511 return true; | 1535 return true; |
1512 } | 1536 } |
OLD | NEW |