Chromium Code Reviews| 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 std::wstring message; | |
| 930 // TODO we probably shouldn't add instances of ToWStringHack() -- what's the | |
| 931 // right thing to do? | |
|
Elliot Glaysher
2010/08/05 23:58:57
nit: Format is "TODO(ldap): "
Matt Perry
2010/08/06 00:03:55
also, for consistency, don't indent the text in th
| |
| 932 // TODO this code is redundant with the code in extensions_ui.cc -- would it | |
| 933 // make sense to push the logic down into PackExtensionJob? | |
| 934 if (output_private_key_path.empty()) { | |
| 935 message = l10n_util::GetStringF( | |
| 936 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_UPDATE, | |
| 937 crx_path.ToWStringHack(), | |
| 938 output_private_key_path.ToWStringHack()); | |
| 939 } else { | |
| 940 message = l10n_util::GetStringF( | |
| 941 IDS_EXTENSION_PACK_DIALOG_SUCCESS_BODY_NEW, | |
| 942 crx_path.ToWStringHack(), | |
| 943 output_private_key_path.ToWStringHack()); | |
| 944 } | |
| 945 ShowPackExtensionMessage(L"Extension Packaging Success", message); | |
| 946 } | |
| 947 | |
| 948 void PackExtensionLogger::OnPackFailure(const std::string& error_message) { | |
| 949 ShowPackExtensionMessage(L"Extension Packaging Error", | |
| 950 UTF8ToWide(error_message)); | |
| 951 } | |
| 952 | |
| 953 void PackExtensionLogger::ShowPackExtensionMessage(const std::wstring& caption, | |
| 954 const std::wstring& message) { | |
| 955 #if defined(OS_WIN) | |
| 956 win_util::MessageBox(NULL, message, caption, MB_OK | MB_SETFOREGROUND); | |
| 957 #else | |
| 958 // Just send caption & text to stdout on mac & linux. | |
| 959 std::string out_text = WideToASCII(caption); | |
| 960 out_text.append("\n\n"); | |
| 961 out_text.append(WideToASCII(message)); | |
| 962 out_text.append("\n"); | |
| 963 printf("%s", out_text.c_str()); | |
| 964 #endif | |
| 965 | |
| 966 // We got the notification and processed it; we don't expect any further tasks | |
| 967 // to be posted to the current thread, so we should stop blocking and exit. | |
| 968 MessageLoop::current()->Quit(); | |
|
Matt Perry
2010/08/05 23:56:09
add a note saying that this matches the Run() in P
| |
| 969 } | |
| 970 | |
| 926 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, | 971 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, |
| 927 const FilePath& cur_dir, | 972 const FilePath& cur_dir, |
| 928 bool process_startup, | 973 bool process_startup, |
| 929 Profile* profile, | 974 Profile* profile, |
| 930 int* return_code, | 975 int* return_code, |
| 931 BrowserInit* browser_init) { | 976 BrowserInit* browser_init) { |
| 932 DCHECK(profile); | 977 DCHECK(profile); |
| 933 if (process_startup) { | 978 if (process_startup) { |
| 934 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 979 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 935 NavigationController::DisablePromptOnRepost(); | 980 NavigationController::DisablePromptOnRepost(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 960 if (command_line.HasSwitch(switches::kPackExtension)) { | 1005 if (command_line.HasSwitch(switches::kPackExtension)) { |
| 961 // Input Paths. | 1006 // Input Paths. |
| 962 FilePath src_dir = command_line.GetSwitchValuePath( | 1007 FilePath src_dir = command_line.GetSwitchValuePath( |
| 963 switches::kPackExtension); | 1008 switches::kPackExtension); |
| 964 FilePath private_key_path; | 1009 FilePath private_key_path; |
| 965 if (command_line.HasSwitch(switches::kPackExtensionKey)) { | 1010 if (command_line.HasSwitch(switches::kPackExtensionKey)) { |
| 966 private_key_path = command_line.GetSwitchValuePath( | 1011 private_key_path = command_line.GetSwitchValuePath( |
| 967 switches::kPackExtensionKey); | 1012 switches::kPackExtensionKey); |
| 968 } | 1013 } |
| 969 | 1014 |
| 970 // Output Paths. | 1015 // Launch a job to perform the packing on the file thread. |
| 971 FilePath output(src_dir.DirName().Append(src_dir.BaseName().value())); | 1016 scoped_ptr<PackExtensionLogger> pack_client(new PackExtensionLogger); |
| 972 FilePath crx_path(output); | 1017 scoped_refptr<PackExtensionJob> pack_job = |
| 973 crx_path = crx_path.ReplaceExtension(chrome::kExtensionFileExtension); | 1018 new PackExtensionJob(pack_client.get(), src_dir, private_key_path); |
| 974 FilePath output_private_key_path; | 1019 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 | 1020 |
| 981 // TODO(port): Creation & running is removed from mac & linux because | 1021 // The job will post a notification task to the current thread's message |
| 982 // ExtensionCreator depends on base/crypto/rsa_private_key and | 1022 // loop when it is finished. We manually run the loop here to catch this |
| 983 // base/crypto/signature_creator, both of which only have windows | 1023 // notification -- otherwise, we won't be able to report success or |
| 984 // implementations. | 1024 // failure back to the user. |
|
Matt Perry
2010/08/05 23:56:09
this comment is not quite accurate. The main point
| |
| 985 scoped_ptr<ExtensionCreator> creator(new ExtensionCreator()); | 1025 MessageLoop::current()->Run(); |
|
Matt Perry
2010/08/05 23:56:09
add a note saying that this is matched by the Quit
| |
| 986 if (creator->Run(src_dir, crx_path, private_key_path, | 1026 |
| 987 output_private_key_path)) { | |
| 988 std::wstring message; | |
| 989 if (private_key_path.value().empty()) { | |
| 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; | 1027 return false; |
| 1009 } | 1028 } |
| 1010 } | 1029 } |
| 1011 | 1030 |
| 1012 bool silent_launch = false; | 1031 bool silent_launch = false; |
| 1013 | 1032 |
| 1014 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 1033 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
| 1015 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 1034 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
| 1016 switches::kAutomationClientChannelID); | 1035 switches::kAutomationClientChannelID); |
| 1017 // If there are any extra parameters, we expect each one to generate a | 1036 // 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 = | 1079 scoped_refptr<AutomationProviderClass> automation = |
| 1061 new AutomationProviderClass(profile); | 1080 new AutomationProviderClass(profile); |
| 1062 automation->ConnectToChannel(channel_id); | 1081 automation->ConnectToChannel(channel_id); |
| 1063 automation->SetExpectedTabCount(expected_tabs); | 1082 automation->SetExpectedTabCount(expected_tabs); |
| 1064 | 1083 |
| 1065 AutomationProviderList* list = | 1084 AutomationProviderList* list = |
| 1066 g_browser_process->InitAutomationProviderList(); | 1085 g_browser_process->InitAutomationProviderList(); |
| 1067 DCHECK(list); | 1086 DCHECK(list); |
| 1068 list->AddProvider(automation); | 1087 list->AddProvider(automation); |
| 1069 } | 1088 } |
| OLD | NEW |