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