OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser_init.h" | 5 #include "chrome/browser/browser_init.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/event_recorder.h" | 9 #include "base/event_recorder.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 if (command_line_.HasSwitch(switches::kDnsLogDetails)) | 400 if (command_line_.HasSwitch(switches::kDnsLogDetails)) |
401 chrome_browser_net::EnableDnsDetailedLog(true); | 401 chrome_browser_net::EnableDnsDetailedLog(true); |
402 if (command_line_.HasSwitch(switches::kDnsPrefetchDisable)) | 402 if (command_line_.HasSwitch(switches::kDnsPrefetchDisable)) |
403 chrome_browser_net::EnableDnsPrefetch(false); | 403 chrome_browser_net::EnableDnsPrefetch(false); |
404 | 404 |
405 if (command_line_.HasSwitch(switches::kDumpHistogramsOnExit)) | 405 if (command_line_.HasSwitch(switches::kDumpHistogramsOnExit)) |
406 StatisticsRecorder::set_dump_on_exit(true); | 406 StatisticsRecorder::set_dump_on_exit(true); |
407 | 407 |
408 if (command_line_.HasSwitch(switches::kRemoteShellPort)) { | 408 if (command_line_.HasSwitch(switches::kRemoteShellPort)) { |
409 if (!RenderProcessHost::run_renderer_in_process()) { | 409 if (!RenderProcessHost::run_renderer_in_process()) { |
410 std::wstring port_str = | 410 std::string port_str = |
411 command_line_.GetSwitchValue(switches::kRemoteShellPort); | 411 command_line_.GetSwitchValueASCII(switches::kRemoteShellPort); |
412 int64 port = StringToInt64(WideToUTF16Hack(port_str)); | 412 int64 port = StringToInt64(port_str); |
413 if (port > 0 && port < 65535) { | 413 if (port > 0 && port < 65535) { |
414 g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); | 414 g_browser_process->InitDebuggerWrapper(static_cast<int>(port)); |
415 } else { | 415 } else { |
416 DLOG(WARNING) << "Invalid port number " << port; | 416 DLOG(WARNING) << "Invalid port number " << port; |
417 } | 417 } |
418 } | 418 } |
419 } | 419 } |
420 | 420 |
421 if (command_line_.HasSwitch(switches::kUserAgent)) { | 421 if (command_line_.HasSwitch(switches::kUserAgent)) { |
422 webkit_glue::SetUserAgent(WideToUTF8( | 422 webkit_glue::SetUserAgent(command_line_.GetSwitchValueASCII( |
423 command_line_.GetSwitchValue(switches::kUserAgent))); | 423 switches::kUserAgent)); |
424 } | 424 } |
425 | 425 |
426 // Open the required browser windows and tabs. | 426 // Open the required browser windows and tabs. |
427 // First, see if we're being run as a web application (thin frame window). | 427 // First, see if we're being run as a web application (thin frame window). |
428 if (!OpenApplicationURL(profile)) { | 428 if (!OpenApplicationURL(profile)) { |
429 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); | 429 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); |
430 RecordLaunchModeHistogram(urls_to_open.empty()? | 430 RecordLaunchModeHistogram(urls_to_open.empty()? |
431 LM_TO_BE_DECIDED : LM_WITH_URLS); | 431 LM_TO_BE_DECIDED : LM_WITH_URLS); |
432 // Always attempt to restore the last session. OpenStartupURLs only opens | 432 // Always attempt to restore the last session. OpenStartupURLs only opens |
433 // the home pages if no additional URLs were passed on the command line. | 433 // the home pages if no additional URLs were passed on the command line. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 base::EventRecorder::current()->StartPlayback(script_path); | 472 base::EventRecorder::current()->StartPlayback(script_path); |
473 } | 473 } |
474 | 474 |
475 return true; | 475 return true; |
476 } | 476 } |
477 | 477 |
478 bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { | 478 bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { |
479 if (!command_line_.HasSwitch(switches::kApp)) | 479 if (!command_line_.HasSwitch(switches::kApp)) |
480 return false; | 480 return false; |
481 | 481 |
482 GURL url(WideToUTF8(command_line_.GetSwitchValue(switches::kApp))); | 482 GURL url(command_line_.GetSwitchValueASCII(switches::kApp)); |
483 if (!url.is_empty() && url.is_valid()) { | 483 if (!url.is_empty() && url.is_valid()) { |
484 Browser::OpenApplicationWindow(profile, url); | 484 Browser::OpenApplicationWindow(profile, url); |
485 return true; | 485 return true; |
486 } | 486 } |
487 return false; | 487 return false; |
488 } | 488 } |
489 | 489 |
490 bool BrowserInit::LaunchWithProfile::OpenStartupURLs( | 490 bool BrowserInit::LaunchWithProfile::OpenStartupURLs( |
491 bool is_process_startup, | 491 bool is_process_startup, |
492 const std::vector<GURL>& urls_to_open) { | 492 const std::vector<GURL>& urls_to_open) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 const std::vector<GURL>& urls) { | 544 const std::vector<GURL>& urls) { |
545 DCHECK(!urls.empty()); | 545 DCHECK(!urls.empty()); |
546 // If we don't yet have a profile, try to use the one we're given from | 546 // If we don't yet have a profile, try to use the one we're given from |
547 // |browser|. While we may not end up actually using |browser| (since it | 547 // |browser|. While we may not end up actually using |browser| (since it |
548 // could be a popup window), we can at least use the profile. | 548 // could be a popup window), we can at least use the profile. |
549 if (!profile_ && browser) | 549 if (!profile_ && browser) |
550 profile_ = browser->profile(); | 550 profile_ = browser->profile(); |
551 | 551 |
552 int pin_count = 0; | 552 int pin_count = 0; |
553 if (!browser) { | 553 if (!browser) { |
554 std::wstring pin_count_string = | 554 std::string pin_count_string = |
555 command_line_.GetSwitchValue(switches::kPinnedTabCount); | 555 command_line_.GetSwitchValueASCII(switches::kPinnedTabCount); |
556 if (!pin_count_string.empty()) | 556 if (!pin_count_string.empty()) |
557 pin_count = StringToInt(WideToUTF16Hack(pin_count_string)); | 557 pin_count = StringToInt(pin_count_string); |
558 } | 558 } |
559 if (!browser || browser->type() != Browser::TYPE_NORMAL) | 559 if (!browser || browser->type() != Browser::TYPE_NORMAL) |
560 browser = Browser::Create(profile_); | 560 browser = Browser::Create(profile_); |
561 | 561 |
562 for (size_t i = 0; i < urls.size(); ++i) { | 562 for (size_t i = 0; i < urls.size(); ++i) { |
563 // We skip URLs that we'd have to launch an external protocol handler for. | 563 // We skip URLs that we'd have to launch an external protocol handler for. |
564 // This avoids us getting into an infinite loop asking ourselves to open | 564 // This avoids us getting into an infinite loop asking ourselves to open |
565 // a URL, should the handler be (incorrectly) configured to be us. Anyone | 565 // a URL, should the handler be (incorrectly) configured to be us. Anyone |
566 // asking us to open such a URL should really ask the handler directly. | 566 // asking us to open such a URL should really ask the handler directly. |
567 if (!process_startup && !URLRequest::IsHandledURL(urls[i])) | 567 if (!process_startup && !URLRequest::IsHandledURL(urls[i])) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 } | 680 } |
681 | 681 |
682 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, | 682 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, |
683 const std::wstring& cur_dir, | 683 const std::wstring& cur_dir, |
684 bool process_startup, | 684 bool process_startup, |
685 Profile* profile, | 685 Profile* profile, |
686 int* return_code, | 686 int* return_code, |
687 BrowserInit* browser_init) { | 687 BrowserInit* browser_init) { |
688 DCHECK(profile); | 688 DCHECK(profile); |
689 if (process_startup) { | 689 if (process_startup) { |
690 const std::wstring popup_count_string = | 690 const std::string popup_count_string = |
691 command_line.GetSwitchValue(switches::kOmniBoxPopupCount); | 691 command_line.GetSwitchValueASCII(switches::kOmniBoxPopupCount); |
692 if (!popup_count_string.empty()) { | 692 if (!popup_count_string.empty()) { |
693 int count = 0; | 693 int count = 0; |
694 if (StringToInt(WideToUTF16Hack(popup_count_string), &count)) { | 694 if (StringToInt(popup_count_string, &count)) { |
695 const int popup_count = std::max(0, count); | 695 const int popup_count = std::max(0, count); |
696 AutocompleteResult::set_max_matches(popup_count); | 696 AutocompleteResult::set_max_matches(popup_count); |
697 AutocompleteProvider::set_max_matches(popup_count / 2); | 697 AutocompleteProvider::set_max_matches(popup_count / 2); |
698 } | 698 } |
699 } | 699 } |
700 | 700 |
701 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 701 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
702 NavigationController::DisablePromptOnRepost(); | 702 NavigationController::DisablePromptOnRepost(); |
703 | 703 |
704 const std::wstring tab_count_string = | 704 const std::string tab_count_string = command_line.GetSwitchValueASCII( |
705 command_line.GetSwitchValue(switches::kTabCountToLoadOnSessionRestore); | 705 switches::kTabCountToLoadOnSessionRestore); |
706 if (!tab_count_string.empty()) { | 706 if (!tab_count_string.empty()) { |
707 int count = 0; | 707 int count = 0; |
708 if (StringToInt(WideToUTF16Hack(tab_count_string), &count)) { | 708 if (StringToInt(tab_count_string, &count)) { |
709 const int tab_count = std::max(0, count); | 709 const int tab_count = std::max(0, count); |
710 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); | 710 SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); |
711 } | 711 } |
712 } | 712 } |
713 | 713 |
714 // Look for the testing channel ID ONLY during process startup | 714 // Look for the testing channel ID ONLY during process startup |
715 if (command_line.HasSwitch(switches::kTestingChannelID)) { | 715 if (command_line.HasSwitch(switches::kTestingChannelID)) { |
716 std::string testing_channel_id = WideToASCII( | 716 std::string testing_channel_id = command_line.GetSwitchValueASCII( |
717 command_line.GetSwitchValue(switches::kTestingChannelID)); | 717 switches::kTestingChannelID); |
718 // TODO(sanjeevr) Check if we need to make this a singleton for | 718 // TODO(sanjeevr) Check if we need to make this a singleton for |
719 // compatibility with the old testing code | 719 // compatibility with the old testing code |
720 // If there are any loose parameters, we expect each one to generate a | 720 // If there are any loose parameters, we expect each one to generate a |
721 // new tab; if there are none then we get one homepage tab. | 721 // new tab; if there are none then we get one homepage tab. |
722 int expected_tab_count = 1; | 722 int expected_tab_count = 1; |
723 if (command_line.HasSwitch(switches::kRestoreLastSession)) { | 723 if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
724 std::wstring restore_session_value( | 724 std::string restore_session_value( |
725 command_line.GetSwitchValue(switches::kRestoreLastSession)); | 725 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
726 StringToInt(WideToUTF16Hack(restore_session_value), | 726 StringToInt(restore_session_value, &expected_tab_count); |
727 &expected_tab_count); | |
728 } else { | 727 } else { |
729 expected_tab_count = | 728 expected_tab_count = |
730 std::max(1, static_cast<int>(command_line.GetLooseValues().size())); | 729 std::max(1, static_cast<int>(command_line.GetLooseValues().size())); |
731 } | 730 } |
732 CreateAutomationProvider<TestingAutomationProvider>( | 731 CreateAutomationProvider<TestingAutomationProvider>( |
733 testing_channel_id, | 732 testing_channel_id, |
734 profile, | 733 profile, |
735 static_cast<size_t>(expected_tab_count)); | 734 static_cast<size_t>(expected_tab_count)); |
736 } | 735 } |
737 | 736 |
738 if (command_line.HasSwitch(switches::kPackExtension)) { | 737 if (command_line.HasSwitch(switches::kPackExtension)) { |
739 // Input Paths. | 738 // Input Paths. |
740 FilePath src_dir = FilePath::FromWStringHack(command_line.GetSwitchValue( | 739 FilePath src_dir = FilePath::FromWStringHack(command_line.GetSwitchValue( |
741 switches::kPackExtension)); | 740 switches::kPackExtension)); |
742 FilePath private_key_path; | 741 FilePath private_key_path; |
743 if (command_line.HasSwitch(switches::kPackExtensionKey)) { | 742 if (command_line.HasSwitch(switches::kPackExtensionKey)) { |
744 private_key_path = FilePath::FromWStringHack( | 743 private_key_path = command_line.GetSwitchValuePath( |
745 command_line.GetSwitchValue(switches::kPackExtensionKey)); | 744 switches::kPackExtensionKey); |
746 } | 745 } |
747 | 746 |
748 // Output Paths. | 747 // Output Paths. |
749 FilePath output(src_dir.DirName().Append(src_dir.BaseName().value())); | 748 FilePath output(src_dir.DirName().Append(src_dir.BaseName().value())); |
750 FilePath crx_path(output); | 749 FilePath crx_path(output); |
751 crx_path = crx_path.ReplaceExtension(chrome::kExtensionFileExtension); | 750 crx_path = crx_path.ReplaceExtension(chrome::kExtensionFileExtension); |
752 FilePath output_private_key_path; | 751 FilePath output_private_key_path; |
753 if (private_key_path.empty()) { | 752 if (private_key_path.empty()) { |
754 output_private_key_path = FilePath(output); | 753 output_private_key_path = FilePath(output); |
755 output_private_key_path = | 754 output_private_key_path = |
(...skipping 29 matching lines...) Expand all Loading... |
785 } | 784 } |
786 return false; | 785 return false; |
787 } | 786 } |
788 } | 787 } |
789 | 788 |
790 // Allow the command line to override the persisted setting of home page. | 789 // Allow the command line to override the persisted setting of home page. |
791 SetOverrideHomePage(command_line, profile->GetPrefs()); | 790 SetOverrideHomePage(command_line, profile->GetPrefs()); |
792 | 791 |
793 bool silent_launch = false; | 792 bool silent_launch = false; |
794 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 793 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
795 std::string automation_channel_id = WideToASCII( | 794 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
796 command_line.GetSwitchValue(switches::kAutomationClientChannelID)); | 795 switches::kAutomationClientChannelID); |
797 // If there are any loose parameters, we expect each one to generate a | 796 // If there are any loose parameters, we expect each one to generate a |
798 // new tab; if there are none then we have no tabs | 797 // new tab; if there are none then we have no tabs |
799 size_t expected_tabs = | 798 size_t expected_tabs = |
800 std::max(static_cast<int>(command_line.GetLooseValues().size()), | 799 std::max(static_cast<int>(command_line.GetLooseValues().size()), |
801 0); | 800 0); |
802 if (expected_tabs == 0) | 801 if (expected_tabs == 0) |
803 silent_launch = true; | 802 silent_launch = true; |
804 CreateAutomationProvider<AutomationProvider>(automation_channel_id, | 803 CreateAutomationProvider<AutomationProvider>(automation_channel_id, |
805 profile, expected_tabs); | 804 profile, expected_tabs); |
806 } | 805 } |
(...skipping 26 matching lines...) Expand all Loading... |
833 scoped_refptr<AutomationProviderClass> automation = | 832 scoped_refptr<AutomationProviderClass> automation = |
834 new AutomationProviderClass(profile); | 833 new AutomationProviderClass(profile); |
835 automation->ConnectToChannel(channel_id); | 834 automation->ConnectToChannel(channel_id); |
836 automation->SetExpectedTabCount(expected_tabs); | 835 automation->SetExpectedTabCount(expected_tabs); |
837 | 836 |
838 AutomationProviderList* list = | 837 AutomationProviderList* list = |
839 g_browser_process->InitAutomationProviderList(); | 838 g_browser_process->InitAutomationProviderList(); |
840 DCHECK(list); | 839 DCHECK(list); |
841 list->AddProvider(automation); | 840 list->AddProvider(automation); |
842 } | 841 } |
OLD | NEW |