| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/environment.h" | 11 #include "base/environment.h" |
| 12 #include "base/event_recorder.h" | 12 #include "base/event_recorder.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/histogram.h" | 14 #include "base/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/automation/automation_provider.h" | 19 #include "chrome/browser/automation/automation_provider.h" |
| 20 #include "chrome/browser/automation/automation_provider_list.h" | 20 #include "chrome/browser/automation/automation_provider_list.h" |
| 21 #include "chrome/browser/automation/chrome_frame_automation_provider.h" | 21 #include "chrome/browser/automation/chrome_frame_automation_provider.h" |
| 22 #include "chrome/browser/browser_list.h" | 22 #include "chrome/browser/browser_list.h" |
| 23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/browser_window.h" | 24 #include "chrome/browser/browser_window.h" |
| 25 #include "chrome/browser/child_process_security_policy.h" | 25 #include "chrome/browser/child_process_security_policy.h" |
| 26 #include "chrome/browser/chrome_thread.h" | 26 #include "chrome/browser/chrome_thread.h" |
| 27 #include "chrome/browser/defaults.h" | 27 #include "chrome/browser/defaults.h" |
| 28 #include "chrome/browser/extensions/extension_creator.h" | 28 #include "chrome/browser/extensions/extension_creator.h" |
| 29 #include "chrome/browser/extensions/extensions_service.h" | 29 #include "chrome/browser/extensions/extensions_service.h" |
| 30 #include "chrome/browser/extensions/pack_extension_job.h" |
| 30 #include "chrome/browser/first_run/first_run.h" | 31 #include "chrome/browser/first_run/first_run.h" |
| 31 #include "chrome/browser/net/predictor_api.h" | 32 #include "chrome/browser/net/predictor_api.h" |
| 32 #include "chrome/browser/net/url_fixer_upper.h" | 33 #include "chrome/browser/net/url_fixer_upper.h" |
| 33 #include "chrome/browser/notifications/desktop_notification_service.h" | 34 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 34 #include "chrome/browser/pref_service.h" | 35 #include "chrome/browser/pref_service.h" |
| 35 #include "chrome/browser/profile.h" | 36 #include "chrome/browser/profile.h" |
| 36 #include "chrome/browser/renderer_host/render_process_host.h" | 37 #include "chrome/browser/renderer_host/render_process_host.h" |
| 37 #include "chrome/browser/search_engines/template_url_model.h" | 38 #include "chrome/browser/search_engines/template_url_model.h" |
| 38 #include "chrome/browser/session_startup_pref.h" | 39 #include "chrome/browser/session_startup_pref.h" |
| 39 #include "chrome/browser/sessions/session_restore.h" | 40 #include "chrome/browser/sessions/session_restore.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 UMA_HISTOGRAM_COUNTS_100("Launch.Modes", bucket); | 339 UMA_HISTOGRAM_COUNTS_100("Launch.Modes", bucket); |
| 339 } | 340 } |
| 340 | 341 |
| 341 static bool in_startup = false; | 342 static bool in_startup = false; |
| 342 | 343 |
| 343 GURL GetWelcomePageURL() { | 344 GURL GetWelcomePageURL() { |
| 344 std::string welcome_url = l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL); | 345 std::string welcome_url = l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL); |
| 345 return GURL(welcome_url); | 346 return GURL(welcome_url); |
| 346 } | 347 } |
| 347 | 348 |
| 348 void ShowPackExtensionMessage(const std::wstring caption, | |
| 349 const std::wstring message) { | |
| 350 #if defined(OS_WIN) | |
| 351 win_util::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); | |
| 352 #else | |
| 353 // Just send caption & text to stdout on mac & linux. | |
| 354 std::string out_text = WideToASCII(caption); | |
| 355 out_text.append("\n\n"); | |
| 356 out_text.append(WideToASCII(message)); | |
| 357 out_text.append("\n"); | |
| 358 printf("%s", out_text.c_str()); | |
| 359 #endif | |
| 360 } | |
| 361 | |
| 362 void UrlsToTabs(const std::vector<GURL>& urls, | 349 void UrlsToTabs(const std::vector<GURL>& urls, |
| 363 std::vector<BrowserInit::LaunchWithProfile::Tab>* tabs) { | 350 std::vector<BrowserInit::LaunchWithProfile::Tab>* tabs) { |
| 364 for (size_t i = 0; i < urls.size(); ++i) { | 351 for (size_t i = 0; i < urls.size(); ++i) { |
| 365 BrowserInit::LaunchWithProfile::Tab tab; | 352 BrowserInit::LaunchWithProfile::Tab tab; |
| 366 tab.is_pinned = false; | 353 tab.is_pinned = false; |
| 367 tab.url = urls[i]; | 354 tab.url = urls[i]; |
| 368 tabs->push_back(tab); | 355 tabs->push_back(tab); |
| 369 } | 356 } |
| 370 } | 357 } |
| 371 | 358 |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 // - the user said "don't ask me again" on the infobar earlier. | 903 // - the user said "don't ask me again" on the infobar earlier. |
| 917 // - this is the first launch after the first run flow. | 904 // - this is the first launch after the first run flow. |
| 918 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || | 905 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || |
| 919 FirstRun::IsChromeFirstRun()) { | 906 FirstRun::IsChromeFirstRun()) { |
| 920 return; | 907 return; |
| 921 } | 908 } |
| 922 ChromeThread::PostTask( | 909 ChromeThread::PostTask( |
| 923 ChromeThread::FILE, FROM_HERE, new CheckDefaultBrowserTask()); | 910 ChromeThread::FILE, FROM_HERE, new CheckDefaultBrowserTask()); |
| 924 } | 911 } |
| 925 | 912 |
| 913 class PackExtensionLogger : public PackExtensionJob::Client { |
| 914 public: |
| 915 PackExtensionLogger() {} |
| 916 virtual void OnPackSuccess(const FilePath& crx_path, |
| 917 const FilePath& output_private_key_path); |
| 918 virtual void OnPackFailure(const std::string& error_message); |
| 919 |
| 920 private: |
| 921 void ShowPackExtensionMessage(const std::wstring& caption, |
| 922 const std::wstring& message); |
| 923 |
| 924 DISALLOW_COPY_AND_ASSIGN(PackExtensionLogger); |
| 925 }; |
| 926 |
| 927 void PackExtensionLogger::OnPackSuccess(const FilePath& crx_path, |
| 928 const FilePath& output_private_key_path) |
| 929 { |
| 930 ShowPackExtensionMessage(L"Extension Packaging Success", |
| 931 PackExtensionJob::StandardSuccessMessage( |
| 932 crx_path, output_private_key_path)); |
| 933 } |
| 934 |
| 935 void PackExtensionLogger::OnPackFailure(const std::string& error_message) { |
| 936 ShowPackExtensionMessage(L"Extension Packaging Error", |
| 937 UTF8ToWide(error_message)); |
| 938 } |
| 939 |
| 940 void PackExtensionLogger::ShowPackExtensionMessage(const std::wstring& caption, |
| 941 const std::wstring& message) |
| 942 { |
| 943 #if defined(OS_WIN) |
| 944 win_util::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); |
| 945 #else |
| 946 // Just send caption & text to stdout on mac & linux. |
| 947 std::string out_text = WideToASCII(caption); |
| 948 out_text.append("\n\n"); |
| 949 out_text.append(WideToASCII(message)); |
| 950 out_text.append("\n"); |
| 951 printf("%s", out_text.c_str()); |
| 952 #endif |
| 953 |
| 954 // We got the notification and processed it; we don't expect any further tasks |
| 955 // to be posted to the current thread, so we should stop blocking and exit. |
| 956 // This call to |Quit()| matches the call to |Run()| in |
| 957 // |ProcessCmdLineImpl()|. |
| 958 MessageLoop::current()->Quit(); |
| 959 } |
| 960 |
| 926 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, | 961 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, |
| 927 const FilePath& cur_dir, | 962 const FilePath& cur_dir, |
| 928 bool process_startup, | 963 bool process_startup, |
| 929 Profile* profile, | 964 Profile* profile, |
| 930 int* return_code, | 965 int* return_code, |
| 931 BrowserInit* browser_init) { | 966 BrowserInit* browser_init) { |
| 932 DCHECK(profile); | 967 DCHECK(profile); |
| 933 if (process_startup) { | 968 if (process_startup) { |
| 934 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 969 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 935 NavigationController::DisablePromptOnRepost(); | 970 NavigationController::DisablePromptOnRepost(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 960 if (command_line.HasSwitch(switches::kPackExtension)) { | 995 if (command_line.HasSwitch(switches::kPackExtension)) { |
| 961 // Input Paths. | 996 // Input Paths. |
| 962 FilePath src_dir = command_line.GetSwitchValuePath( | 997 FilePath src_dir = command_line.GetSwitchValuePath( |
| 963 switches::kPackExtension); | 998 switches::kPackExtension); |
| 964 FilePath private_key_path; | 999 FilePath private_key_path; |
| 965 if (command_line.HasSwitch(switches::kPackExtensionKey)) { | 1000 if (command_line.HasSwitch(switches::kPackExtensionKey)) { |
| 966 private_key_path = command_line.GetSwitchValuePath( | 1001 private_key_path = command_line.GetSwitchValuePath( |
| 967 switches::kPackExtensionKey); | 1002 switches::kPackExtensionKey); |
| 968 } | 1003 } |
| 969 | 1004 |
| 970 // Output Paths. | 1005 // Launch a job to perform the packing on the file thread. |
| 971 FilePath output(src_dir.DirName().Append(src_dir.BaseName().value())); | 1006 PackExtensionLogger pack_client; |
| 972 FilePath crx_path(output); | 1007 scoped_refptr<PackExtensionJob> pack_job = |
| 973 crx_path = crx_path.ReplaceExtension(chrome::kExtensionFileExtension); | 1008 new PackExtensionJob(&pack_client, src_dir, private_key_path); |
| 974 FilePath output_private_key_path; | 1009 pack_job->Start(); |
| 975 if (private_key_path.empty()) { | |
| 976 output_private_key_path = FilePath(output); | |
| 977 output_private_key_path = | |
| 978 output_private_key_path.ReplaceExtension(FILE_PATH_LITERAL("pem")); | |
| 979 } | |
| 980 | 1010 |
| 981 // TODO(port): Creation & running is removed from mac & linux because | 1011 // The job will post a notification task to the current thread's message |
| 982 // ExtensionCreator depends on base/crypto/rsa_private_key and | 1012 // loop when it is finished. We manually run the loop here so that we |
| 983 // base/crypto/signature_creator, both of which only have windows | 1013 // block and catch the notification. Otherwise, the process would exit; |
| 984 // implementations. | 1014 // in particular, this would mean that |pack_client| would be destroyed |
| 985 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 1015 // and we wouldn't be able to report success or failure back to the user. |
| 986 if (creator->Run(src_dir, crx_path, private_key_path, | 1016 // This call to |Run()| is matched by a call to |Quit()| in the |
| 987 output_private_key_path)) { | 1017 // |PackExtensionLogger|'s notification handling code. |
| 988 std::wstring message; | 1018 MessageLoop::current()->Run(); |
| 989 if (private_key_path.value().empty()) { | 1019 |
| 990 message = StringPrintf( | |
| 991 L"Created the following files:\n\n" | |
| 992 L"Extension: %ls\n" | |
| 993 L"Key File: %ls\n\n" | |
| 994 L"Keep your key file in a safe place. You will need it to create " | |
| 995 L"new versions of your extension.", | |
| 996 crx_path.ToWStringHack().c_str(), | |
| 997 output_private_key_path.ToWStringHack().c_str()); | |
| 998 } else { | |
| 999 message = StringPrintf(L"Created the extension:\n\n%ls", | |
| 1000 crx_path.ToWStringHack().c_str()); | |
| 1001 } | |
| 1002 ShowPackExtensionMessage(L"Extension Packaging Success", message); | |
| 1003 } else { | |
| 1004 ShowPackExtensionMessage(L"Extension Packaging Error", | |
| 1005 UTF8ToWide(creator->error_message())); | |
| 1006 return false; | |
| 1007 } | |
| 1008 return false; | 1020 return false; |
| 1009 } | 1021 } |
| 1010 } | 1022 } |
| 1011 | 1023 |
| 1012 bool silent_launch = false; | 1024 bool silent_launch = false; |
| 1013 | 1025 |
| 1014 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 1026 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
| 1015 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 1027 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
| 1016 switches::kAutomationClientChannelID); | 1028 switches::kAutomationClientChannelID); |
| 1017 // If there are any extra parameters, we expect each one to generate a | 1029 // If there are any extra parameters, we expect each one to generate a |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 scoped_refptr<AutomationProviderClass> automation = | 1072 scoped_refptr<AutomationProviderClass> automation = |
| 1061 new AutomationProviderClass(profile); | 1073 new AutomationProviderClass(profile); |
| 1062 automation->ConnectToChannel(channel_id); | 1074 automation->ConnectToChannel(channel_id); |
| 1063 automation->SetExpectedTabCount(expected_tabs); | 1075 automation->SetExpectedTabCount(expected_tabs); |
| 1064 | 1076 |
| 1065 AutomationProviderList* list = | 1077 AutomationProviderList* list = |
| 1066 g_browser_process->InitAutomationProviderList(); | 1078 g_browser_process->InitAutomationProviderList(); |
| 1067 DCHECK(list); | 1079 DCHECK(list); |
| 1068 list->AddProvider(automation); | 1080 list->AddProvider(automation); |
| 1069 } | 1081 } |
| OLD | NEW |