[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 5 | #include "chrome/browser/browser_main_posix.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 6 | |
[email protected] | ce8c16ad | 2009-08-12 19:00:42 | [diff] [blame] | 7 | #import <Cocoa/Cocoa.h> |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 8 | |
[email protected] | 9986ee16 | 2009-11-19 16:25:04 | [diff] [blame] | 9 | #include "app/app_switches.h" |
| 10 | #include "app/l10n_util_mac.h" |
[email protected] | 885b727 | 2009-08-12 20:33:05 | [diff] [blame] | 11 | #include "app/resource_bundle.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 13 | #include "base/debug_util.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 14 | #include "base/file_path.h" |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 15 | #include "base/mac_util.h" |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 16 | #include "base/nss_util.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 17 | #include "base/path_service.h" |
[email protected] | 304a317 | 2010-05-04 05:38:44 | [diff] [blame] | 18 | #include "base/scoped_nsobject.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 19 | #include "chrome/app/breakpad_mac.h" |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 20 | #import "chrome/browser/app_controller_mac.h" |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 21 | #include "chrome/browser/browser_main_win.h" |
[email protected] | aaa47ee | 2009-11-05 21:53:01 | [diff] [blame] | 22 | #import "chrome/browser/chrome_browser_application_mac.h" |
[email protected] | eee9f55 | 2009-11-28 22:05:11 | [diff] [blame] | 23 | #import "chrome/browser/cocoa/keystone_glue.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 24 | #include "chrome/browser/metrics/metrics_service.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 25 | #include "chrome/common/chrome_paths.h" |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 26 | #include "chrome/common/chrome_switches.h" |
[email protected] | 885b727 | 2009-08-12 20:33:05 | [diff] [blame] | 27 | #include "chrome/common/main_function_params.h" |
[email protected] | 9eaf0ba | 2010-03-09 23:33:19 | [diff] [blame] | 28 | #include "chrome/common/notification_service.h" |
[email protected] | 74d1bb0 | 2009-03-03 00:41:23 | [diff] [blame] | 29 | #include "chrome/common/result_codes.h" |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 30 | #include "net/socket/ssl_client_socket_mac_factory.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 31 | |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 32 | void DidEndMainMessageLoop() { |
| 33 | AppController* appController = [NSApp delegate]; |
| 34 | [appController didEndMainMessageLoop]; |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 37 | void RecordBreakpadStatusUMA(MetricsService* metrics) { |
| 38 | metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); |
| 39 | metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged()); |
| 40 | } |
| 41 | |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 42 | void WarnAboutMinimumSystemRequirements() { |
| 43 | // Nothing to check for on Mac right now. |
| 44 | } |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 45 | |
| 46 | // From browser_main_win.h, stubs until we figure out the right thing... |
| 47 | |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 48 | int DoUninstallTasks(bool chrome_still_running) { |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 49 | return ResultCodes::NORMAL_EXIT; |
| 50 | } |
| 51 | |
[email protected] | ce8c16ad | 2009-08-12 19:00:42 | [diff] [blame] | 52 | int HandleIconsCommands(const CommandLine& parsed_command_line) { |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | bool CheckMachineLevelInstall() { |
| 57 | return false; |
| 58 | } |
| 59 | |
[email protected] | ce8c16ad | 2009-08-12 19:00:42 | [diff] [blame] | 60 | void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 61 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 62 | |
| 63 | // BrowserMainPartsMac --------------------------------------------------------- |
| 64 | |
| 65 | class BrowserMainPartsMac : public BrowserMainPartsPosix { |
| 66 | public: |
| 67 | explicit BrowserMainPartsMac(const MainFunctionParams& parameters) |
| 68 | : BrowserMainPartsPosix(parameters) {} |
| 69 | |
| 70 | protected: |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame^] | 71 | virtual void PreEarlyInitialization() { |
| 72 | BrowserMainPartsPosix::PreEarlyInitialization(); |
| 73 | |
| 74 | if (mac_util::WasLaunchedAsHiddenLoginItem()) { |
| 75 | CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); |
| 76 | singleton_command_line->AppendSwitch(switches::kNoStartupWindow); |
| 77 | } |
| 78 | } |
| 79 | |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 80 | virtual void PreMainMessageLoopStart() { |
| 81 | BrowserMainPartsPosix::PreMainMessageLoopStart(); |
| 82 | |
| 83 | // Tell Cooca to finish its initalization, which we want to do manually |
| 84 | // instead of calling NSApplicationMain(). The primary reason is that NSAM() |
| 85 | // never returns, which would leave all the objects currently on the stack |
| 86 | // in scoped_ptrs hanging and never cleaned up. We then load the main nib |
| 87 | // directly. The main event loop is run from common code using the |
| 88 | // MessageLoop API, which works out ok for us because it's a wrapper around |
| 89 | // CFRunLoop. |
| 90 | |
| 91 | // Initialize NSApplication using the custom subclass. |
| 92 | [BrowserCrApplication sharedApplication]; |
| 93 | |
| 94 | // If ui_task is not NULL, the app is actually a browser_test, so startup is |
| 95 | // handled outside of BrowserMain (which is what called this). |
| 96 | if (!parameters().ui_task) { |
| 97 | // The browser process only wants to support the language Cocoa will use, |
| 98 | // so force the app locale to be overriden with that value. |
| 99 | l10n_util::OverrideLocaleWithCocoaLocale(); |
| 100 | |
| 101 | // Before we load the nib, we need to start up the resource bundle so we |
| 102 | // have the strings avaiable for localization. |
[email protected] | ff622aa | 2010-08-04 17:07:46 | [diff] [blame] | 103 | std::string pref_locale; |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 104 | // TODO(markusheintz): Read preference pref::kApplicationLocale in order |
| 105 | // to enforce the application locale. |
| 106 | ResourceBundle::InitSharedInstance(pref_locale); |
| 107 | |
| 108 | FilePath resources_pack_path; |
| 109 | PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 110 | ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
| 111 | } |
| 112 | |
| 113 | // Now load the nib (from the right bundle). |
| 114 | scoped_nsobject<NSNib> |
| 115 | nib([[NSNib alloc] initWithNibNamed:@"MainMenu" |
| 116 | bundle:mac_util::MainAppBundle()]); |
[email protected] | 60742f1 | 2010-07-27 19:45:23 | [diff] [blame] | 117 | // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you |
| 118 | // change this, you'll probably need to change the Valgrind suppression. |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 119 | [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]; |
| 120 | // Make sure the app controller has been created. |
| 121 | DCHECK([NSApp delegate]); |
| 122 | |
| 123 | // This is a no-op if the KeystoneRegistration framework is not present. |
| 124 | // The framework is only distributed with branded Google Chrome builds. |
| 125 | [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; |
| 126 | |
| 127 | // Prevent Cocoa from turning command-line arguments into |
| 128 | // |-application:openFiles:|, since we already handle them directly. |
| 129 | [[NSUserDefaults standardUserDefaults] |
| 130 | setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; |
| 131 | } |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 132 | |
| 133 | private: |
| 134 | virtual void InitializeSSL() { |
| 135 | // Use NSS for SSL by default. |
| 136 | // The default client socket factory uses NSS for SSL by default on Mac. |
| 137 | if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { |
| 138 | net::ClientSocketFactory::SetSSLClientSocketFactory( |
| 139 | net::SSLClientSocketMacFactory); |
| 140 | } else { |
| 141 | // We want to be sure to init NSPR on the main thread. |
| 142 | base::EnsureNSPRInit(); |
| 143 | } |
| 144 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | // static |
| 148 | BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( |
| 149 | const MainFunctionParams& parameters) { |
| 150 | return new BrowserMainPartsMac(parameters); |
| 151 | } |