blob: a00c47bd0aa3c6c0a6f7f0a4235e9de645b2e0e5 [file] [log] [blame]
[email protected]34f73fb2010-03-24 20:50:341// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]5c9587c2008-12-09 21:20:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1fec64352010-07-27 13:55:215#include "chrome/browser/browser_main_posix.h"
[email protected]1152b7e2009-09-14 03:26:036
[email protected]ce8c16ad2009-08-12 19:00:427#import <Cocoa/Cocoa.h>
[email protected]1152b7e2009-09-14 03:26:038
[email protected]9986ee162009-11-19 16:25:049#include "app/app_switches.h"
10#include "app/l10n_util_mac.h"
[email protected]885b7272009-08-12 20:33:0511#include "app/resource_bundle.h"
[email protected]5c9587c2008-12-09 21:20:1612#include "base/command_line.h"
[email protected]1152b7e2009-09-14 03:26:0313#include "base/debug_util.h"
[email protected]e1cb0e92010-06-15 07:23:5914#include "base/file_path.h"
[email protected]304a3172010-05-04 05:38:4415#include "base/mac_util.h"
[email protected]d7dbe28c2010-07-29 04:33:4716#include "base/nss_util.h"
[email protected]e1cb0e92010-06-15 07:23:5917#include "base/path_service.h"
[email protected]304a3172010-05-04 05:38:4418#include "base/scoped_nsobject.h"
[email protected]1152b7e2009-09-14 03:26:0319#include "chrome/app/breakpad_mac.h"
[email protected]3b6aa8b62009-09-15 21:36:1120#import "chrome/browser/app_controller_mac.h"
[email protected]1bcdb532009-01-16 17:47:5721#include "chrome/browser/browser_main_win.h"
[email protected]aaa47ee2009-11-05 21:53:0122#import "chrome/browser/chrome_browser_application_mac.h"
[email protected]eee9f552009-11-28 22:05:1123#import "chrome/browser/cocoa/keystone_glue.h"
[email protected]1152b7e2009-09-14 03:26:0324#include "chrome/browser/metrics/metrics_service.h"
[email protected]e1cb0e92010-06-15 07:23:5925#include "chrome/common/chrome_paths.h"
[email protected]d7dbe28c2010-07-29 04:33:4726#include "chrome/common/chrome_switches.h"
[email protected]885b7272009-08-12 20:33:0527#include "chrome/common/main_function_params.h"
[email protected]9eaf0ba2010-03-09 23:33:1928#include "chrome/common/notification_service.h"
[email protected]74d1bb02009-03-03 00:41:2329#include "chrome/common/result_codes.h"
[email protected]d7dbe28c2010-07-29 04:33:4730#include "net/socket/ssl_client_socket_mac_factory.h"
[email protected]5c9587c2008-12-09 21:20:1631
[email protected]3b6aa8b62009-09-15 21:36:1132void DidEndMainMessageLoop() {
33 AppController* appController = [NSApp delegate];
34 [appController didEndMainMessageLoop];
[email protected]1bcdb532009-01-16 17:47:5735}
36
[email protected]1152b7e2009-09-14 03:26:0337void RecordBreakpadStatusUMA(MetricsService* metrics) {
38 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
39 metrics->RecordBreakpadHasDebugger(DebugUtil::BeingDebugged());
40}
41
[email protected]34f73fb2010-03-24 20:50:3442void WarnAboutMinimumSystemRequirements() {
43 // Nothing to check for on Mac right now.
44}
[email protected]1bcdb532009-01-16 17:47:5745
46// From browser_main_win.h, stubs until we figure out the right thing...
47
[email protected]53c38d232009-02-13 20:52:1848int DoUninstallTasks(bool chrome_still_running) {
[email protected]1bcdb532009-01-16 17:47:5749 return ResultCodes::NORMAL_EXIT;
50}
51
[email protected]ce8c16ad2009-08-12 19:00:4252int HandleIconsCommands(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5753 return 0;
54}
55
56bool CheckMachineLevelInstall() {
57 return false;
58}
59
[email protected]ce8c16ad2009-08-12 19:00:4260void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5761}
[email protected]1fec64352010-07-27 13:55:2162
63// BrowserMainPartsMac ---------------------------------------------------------
64
65class BrowserMainPartsMac : public BrowserMainPartsPosix {
66 public:
67 explicit BrowserMainPartsMac(const MainFunctionParams& parameters)
68 : BrowserMainPartsPosix(parameters) {}
69
70 protected:
[email protected]91484af2010-08-27 17:55:5471 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]1fec64352010-07-27 13:55:2180 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]ff622aa2010-08-04 17:07:46103 std::string pref_locale;
[email protected]1fec64352010-07-27 13:55:21104 // 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]60742f12010-07-27 19:45:23117 // 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]1fec64352010-07-27 13:55:21119 [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]d7dbe28c2010-07-29 04:33:47132
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]1fec64352010-07-27 13:55:21145};
146
147// static
148BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
149 const MainFunctionParams& parameters) {
150 return new BrowserMainPartsMac(parameters);
151}