blob: cd359a9986ccf55a3e37be3a96259d47bfb70327 [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"
[email protected]5c9587c2008-12-09 21:20:1610#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5011#include "base/debug/debugger.h"
[email protected]e1cb0e92010-06-15 07:23:5912#include "base/file_path.h"
[email protected]0378bf42011-01-01 18:20:1413#include "base/mac/mac_util.h"
[email protected]d7dbe28c2010-07-29 04:33:4714#include "base/nss_util.h"
[email protected]e1cb0e92010-06-15 07:23:5915#include "base/path_service.h"
[email protected]304a3172010-05-04 05:38:4416#include "base/scoped_nsobject.h"
[email protected]1152b7e2009-09-14 03:26:0317#include "chrome/app/breakpad_mac.h"
[email protected]3b6aa8b62009-09-15 21:36:1118#import "chrome/browser/app_controller_mac.h"
[email protected]1bcdb532009-01-16 17:47:5719#include "chrome/browser/browser_main_win.h"
[email protected]aaa47ee2009-11-05 21:53:0120#import "chrome/browser/chrome_browser_application_mac.h"
[email protected]7d791652010-12-01 16:34:4921#import "chrome/browser/ui/cocoa/keystone_glue.h"
[email protected]1152b7e2009-09-14 03:26:0322#include "chrome/browser/metrics/metrics_service.h"
[email protected]e1cb0e92010-06-15 07:23:5923#include "chrome/common/chrome_paths.h"
[email protected]d7dbe28c2010-07-29 04:33:4724#include "chrome/common/chrome_switches.h"
[email protected]885b7272009-08-12 20:33:0525#include "chrome/common/main_function_params.h"
[email protected]74d1bb02009-03-03 00:41:2326#include "chrome/common/result_codes.h"
[email protected]d7dbe28c2010-07-29 04:33:4727#include "net/socket/ssl_client_socket_mac_factory.h"
[email protected]c051a1b2011-01-21 23:30:1728#include "ui/base/l10n/l10n_util_mac.h"
[email protected]42ce29d2011-01-20 23:19:4629#include "ui/base/resource/resource_bundle.h"
[email protected]5c9587c2008-12-09 21:20:1630
[email protected]3b6aa8b62009-09-15 21:36:1131void DidEndMainMessageLoop() {
32 AppController* appController = [NSApp delegate];
33 [appController didEndMainMessageLoop];
[email protected]1bcdb532009-01-16 17:47:5734}
35
[email protected]1152b7e2009-09-14 03:26:0336void RecordBreakpadStatusUMA(MetricsService* metrics) {
37 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
[email protected]58580352010-10-26 04:07:5038 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged());
[email protected]1152b7e2009-09-14 03:26:0339}
40
[email protected]34f73fb2010-03-24 20:50:3441void WarnAboutMinimumSystemRequirements() {
42 // Nothing to check for on Mac right now.
43}
[email protected]1bcdb532009-01-16 17:47:5744
45// From browser_main_win.h, stubs until we figure out the right thing...
46
[email protected]53c38d232009-02-13 20:52:1847int DoUninstallTasks(bool chrome_still_running) {
[email protected]1bcdb532009-01-16 17:47:5748 return ResultCodes::NORMAL_EXIT;
49}
50
[email protected]ce8c16ad2009-08-12 19:00:4251int HandleIconsCommands(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5752 return 0;
53}
54
55bool CheckMachineLevelInstall() {
56 return false;
57}
58
[email protected]ce8c16ad2009-08-12 19:00:4259void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5760}
[email protected]1fec64352010-07-27 13:55:2161
62// BrowserMainPartsMac ---------------------------------------------------------
63
64class BrowserMainPartsMac : public BrowserMainPartsPosix {
65 public:
66 explicit BrowserMainPartsMac(const MainFunctionParams& parameters)
67 : BrowserMainPartsPosix(parameters) {}
68
69 protected:
[email protected]91484af2010-08-27 17:55:5470 virtual void PreEarlyInitialization() {
71 BrowserMainPartsPosix::PreEarlyInitialization();
72
[email protected]0378bf42011-01-01 18:20:1473 if (base::mac::WasLaunchedAsHiddenLoginItem()) {
[email protected]91484af2010-08-27 17:55:5474 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
75 singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
76 }
77 }
78
[email protected]1fec64352010-07-27 13:55:2179 virtual void PreMainMessageLoopStart() {
80 BrowserMainPartsPosix::PreMainMessageLoopStart();
81
82 // Tell Cooca to finish its initalization, which we want to do manually
83 // instead of calling NSApplicationMain(). The primary reason is that NSAM()
84 // never returns, which would leave all the objects currently on the stack
85 // in scoped_ptrs hanging and never cleaned up. We then load the main nib
86 // directly. The main event loop is run from common code using the
87 // MessageLoop API, which works out ok for us because it's a wrapper around
88 // CFRunLoop.
89
90 // Initialize NSApplication using the custom subclass.
91 [BrowserCrApplication sharedApplication];
92
93 // If ui_task is not NULL, the app is actually a browser_test, so startup is
94 // handled outside of BrowserMain (which is what called this).
95 if (!parameters().ui_task) {
96 // The browser process only wants to support the language Cocoa will use,
97 // so force the app locale to be overriden with that value.
98 l10n_util::OverrideLocaleWithCocoaLocale();
99
100 // Before we load the nib, we need to start up the resource bundle so we
101 // have the strings avaiable for localization.
[email protected]1fec64352010-07-27 13:55:21102 // TODO(markusheintz): Read preference pref::kApplicationLocale in order
103 // to enforce the application locale.
[email protected]455ee192010-12-22 16:05:57104 const std::string loaded_locale =
105 ResourceBundle::InitSharedInstance(std::string());
106 CHECK(!loaded_locale.empty()) << "Default locale could not be found";
[email protected]1fec64352010-07-27 13:55:21107
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"
[email protected]0378bf42011-01-01 18:20:14116 bundle:base::mac::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}