blob: 806c6e7e48dc336cbe7cd3a7416ec415c3600712 [file] [log] [blame]
[email protected]f7752782011-03-21 13:17:451// Copyright (c) 2011 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]5c9587c2008-12-09 21:20:169#include "base/command_line.h"
[email protected]58580352010-10-26 04:07:5010#include "base/debug/debugger.h"
[email protected]e1cb0e92010-06-15 07:23:5911#include "base/file_path.h"
[email protected]0378bf42011-01-01 18:20:1412#include "base/mac/mac_util.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_nsobject.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]1152b7e2009-09-14 03:26:0316#include "chrome/app/breakpad_mac.h"
[email protected]3b6aa8b62009-09-15 21:36:1117#import "chrome/browser/app_controller_mac.h"
[email protected]1bcdb532009-01-16 17:47:5718#include "chrome/browser/browser_main_win.h"
[email protected]aaa47ee2009-11-05 21:53:0119#import "chrome/browser/chrome_browser_application_mac.h"
[email protected]2b78be32011-02-11 00:18:0820#import "chrome/browser/cocoa/keystone_glue.h"
[email protected]1152b7e2009-09-14 03:26:0321#include "chrome/browser/metrics/metrics_service.h"
[email protected]e1cb0e92010-06-15 07:23:5922#include "chrome/common/chrome_paths.h"
[email protected]d7dbe28c2010-07-29 04:33:4723#include "chrome/common/chrome_switches.h"
[email protected]415c2cd2011-03-11 21:56:1124#include "content/common/main_function_params.h"
[email protected]4dd57932011-03-17 06:06:1225#include "content/common/result_codes.h"
[email protected]2380f372011-02-23 21:35:1926#include "net/socket/client_socket_factory.h"
[email protected]c051a1b2011-01-21 23:30:1727#include "ui/base/l10n/l10n_util_mac.h"
[email protected]42ce29d2011-01-20 23:19:4628#include "ui/base/resource/resource_bundle.h"
[email protected]5c9587c2008-12-09 21:20:1629
[email protected]3b6aa8b62009-09-15 21:36:1130void DidEndMainMessageLoop() {
31 AppController* appController = [NSApp delegate];
32 [appController didEndMainMessageLoop];
[email protected]1bcdb532009-01-16 17:47:5733}
34
[email protected]1152b7e2009-09-14 03:26:0335void RecordBreakpadStatusUMA(MetricsService* metrics) {
36 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
[email protected]58580352010-10-26 04:07:5037 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged());
[email protected]1152b7e2009-09-14 03:26:0338}
39
[email protected]34f73fb2010-03-24 20:50:3440void WarnAboutMinimumSystemRequirements() {
41 // Nothing to check for on Mac right now.
42}
[email protected]1bcdb532009-01-16 17:47:5743
44// From browser_main_win.h, stubs until we figure out the right thing...
45
[email protected]53c38d232009-02-13 20:52:1846int DoUninstallTasks(bool chrome_still_running) {
[email protected]1bcdb532009-01-16 17:47:5747 return ResultCodes::NORMAL_EXIT;
48}
49
[email protected]ce8c16ad2009-08-12 19:00:4250int HandleIconsCommands(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5751 return 0;
52}
53
54bool CheckMachineLevelInstall() {
55 return false;
56}
57
[email protected]ce8c16ad2009-08-12 19:00:4258void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) {
[email protected]1bcdb532009-01-16 17:47:5759}
[email protected]1fec64352010-07-27 13:55:2160
61// BrowserMainPartsMac ---------------------------------------------------------
62
63class BrowserMainPartsMac : public BrowserMainPartsPosix {
64 public:
65 explicit BrowserMainPartsMac(const MainFunctionParams& parameters)
66 : BrowserMainPartsPosix(parameters) {}
67
68 protected:
[email protected]91484af2010-08-27 17:55:5469 virtual void PreEarlyInitialization() {
70 BrowserMainPartsPosix::PreEarlyInitialization();
71
[email protected]0378bf42011-01-01 18:20:1472 if (base::mac::WasLaunchedAsHiddenLoginItem()) {
[email protected]91484af2010-08-27 17:55:5473 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
74 singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
75 }
76 }
77
[email protected]1fec64352010-07-27 13:55:2178 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]1fec64352010-07-27 13:55:21101 // TODO(markusheintz): Read preference pref::kApplicationLocale in order
102 // to enforce the application locale.
[email protected]455ee192010-12-22 16:05:57103 const std::string loaded_locale =
104 ResourceBundle::InitSharedInstance(std::string());
105 CHECK(!loaded_locale.empty()) << "Default locale could not be found";
[email protected]1fec64352010-07-27 13:55:21106
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]0378bf42011-01-01 18:20:14115 bundle:base::mac::MainAppBundle()]);
[email protected]60742f12010-07-27 19:45:23116 // 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]1fec64352010-07-27 13:55:21118 [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]d7dbe28c2010-07-29 04:33:47131
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]2380f372011-02-23 21:35:19137 net::ClientSocketFactory::UseSystemSSL();
[email protected]d7dbe28c2010-07-29 04:33:47138 } else {
139 // We want to be sure to init NSPR on the main thread.
140 base::EnsureNSPRInit();
141 }
142 }
[email protected]1fec64352010-07-27 13:55:21143};
144
145// static
146BrowserMainParts* BrowserMainParts::CreateBrowserMainParts(
147 const MainFunctionParams& parameters) {
148 return new BrowserMainPartsMac(parameters);
149}