blob: 493f8eab88e6fcb6ee563a3ba471311d0d50e89c [file] [log] [blame]
[email protected]71c0eb92012-01-03 17:57:301// Copyright (c) 2012 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]e6b5bc22011-09-08 22:01:565#include "chrome/browser/chrome_browser_main_mac.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]2f1804c2012-01-19 14:59:0712#include "base/mac/bundle_locations.h"
[email protected]0378bf42011-01-01 18:20:1413#include "base/mac/mac_util.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_nsobject.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]aaa47ee2009-11-05 21:53:0118#import "chrome/browser/chrome_browser_application_mac.h"
[email protected]5950f5712011-06-20 22:15:5219#import "chrome/browser/mac/keystone_glue.h"
[email protected]1152b7e2009-09-14 03:26:0320#include "chrome/browser/metrics/metrics_service.h"
[email protected]e1cb0e92010-06-15 07:23:5921#include "chrome/common/chrome_paths.h"
[email protected]d7dbe28c2010-07-29 04:33:4722#include "chrome/common/chrome_switches.h"
[email protected]4573fbd2011-10-31 20:25:1823#include "content/public/common/main_function_params.h"
[email protected]b39ef1cb2011-10-25 04:46:5524#include "content/public/common/result_codes.h"
[email protected]c051a1b2011-01-21 23:30:1725#include "ui/base/l10n/l10n_util_mac.h"
[email protected]42ce29d2011-01-20 23:19:4626#include "ui/base/resource/resource_bundle.h"
[email protected]5c9587c2008-12-09 21:20:1627
[email protected]1152b7e2009-09-14 03:26:0328void RecordBreakpadStatusUMA(MetricsService* metrics) {
29 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
[email protected]58580352010-10-26 04:07:5030 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged());
[email protected]1152b7e2009-09-14 03:26:0331}
32
[email protected]45d72762011-04-15 18:58:2033void RecordBrowserStartupTime() {
34 // Not implemented on Mac for now.
35}
36
[email protected]34f73fb2010-03-24 20:50:3437void WarnAboutMinimumSystemRequirements() {
38 // Nothing to check for on Mac right now.
39}
[email protected]1bcdb532009-01-16 17:47:5740
41// From browser_main_win.h, stubs until we figure out the right thing...
42
[email protected]53c38d232009-02-13 20:52:1843int DoUninstallTasks(bool chrome_still_running) {
[email protected]1fcfb202011-07-19 19:53:1444 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]1bcdb532009-01-16 17:47:5745}
46
[email protected]e6b5bc22011-09-08 22:01:5647// ChromeBrowserMainPartsMac ---------------------------------------------------
[email protected]1fec64352010-07-27 13:55:2148
[email protected]e6b5bc22011-09-08 22:01:5649ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac(
[email protected]4573fbd2011-10-31 20:25:1850 const content::MainFunctionParams& parameters)
[email protected]e6b5bc22011-09-08 22:01:5651 : ChromeBrowserMainPartsPosix(parameters) {
[email protected]f967b722011-09-07 00:58:0452}
[email protected]1fec64352010-07-27 13:55:2153
[email protected]e6b5bc22011-09-08 22:01:5654void ChromeBrowserMainPartsMac::PreEarlyInitialization() {
[email protected]37c722b2011-09-08 22:18:4655 ChromeBrowserMainPartsPosix::PreEarlyInitialization();
[email protected]91484af2010-08-27 17:55:5456
[email protected]f967b722011-09-07 00:58:0457 if (base::mac::WasLaunchedAsHiddenLoginItem()) {
58 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
59 singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
60 }
61}
62
[email protected]e6b5bc22011-09-08 22:01:5663void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() {
[email protected]37c722b2011-09-08 22:18:4664 ChromeBrowserMainPartsPosix::PreMainMessageLoopStart();
[email protected]f967b722011-09-07 00:58:0465
66 // Tell Cooca to finish its initialization, which we want to do manually
67 // instead of calling NSApplicationMain(). The primary reason is that NSAM()
68 // never returns, which would leave all the objects currently on the stack
69 // in scoped_ptrs hanging and never cleaned up. We then load the main nib
70 // directly. The main event loop is run from common code using the
71 // MessageLoop API, which works out ok for us because it's a wrapper around
72 // CFRunLoop.
73
74 // Initialize NSApplication using the custom subclass.
[email protected]d7de57872011-12-06 23:32:4375 chrome_browser_application_mac::RegisterBrowserCrApp();
[email protected]f967b722011-09-07 00:58:0476
77 // If ui_task is not NULL, the app is actually a browser_test, so startup is
78 // handled outside of BrowserMain (which is what called this).
[email protected]716476c2011-12-29 00:07:0379 if (!parameters().ui_task) {
[email protected]f967b722011-09-07 00:58:0480 // The browser process only wants to support the language Cocoa will use,
81 // so force the app locale to be overriden with that value.
82 l10n_util::OverrideLocaleWithCocoaLocale();
83
84 // Before we load the nib, we need to start up the resource bundle so we
85 // have the strings avaiable for localization.
86 // TODO(markusheintz): Read preference pref::kApplicationLocale in order
87 // to enforce the application locale.
88 const std::string loaded_locale =
[email protected]70f9df12012-01-28 02:30:0489 ResourceBundle::InitSharedInstanceWithLocale(std::string());
[email protected]f967b722011-09-07 00:58:0490 CHECK(!loaded_locale.empty()) << "Default locale could not be found";
91
92 FilePath resources_pack_path;
93 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
94 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
[email protected]91484af2010-08-27 17:55:5495 }
96
[email protected]f967b722011-09-07 00:58:0497 // Now load the nib (from the right bundle).
98 scoped_nsobject<NSNib>
99 nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
[email protected]2f1804c2012-01-19 14:59:07100 bundle:base::mac::FrameworkBundle()]);
[email protected]f967b722011-09-07 00:58:04101 // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you
102 // change this, you'll probably need to change the Valgrind suppression.
103 [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
104 // Make sure the app controller has been created.
105 DCHECK([NSApp delegate]);
[email protected]1fec64352010-07-27 13:55:21106
[email protected]5bb15df2012-03-24 09:27:28107 // This is a no-op if the KeystoneRegistration framework is not present.
108 // The framework is only distributed with branded Google Chrome builds.
109 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
110
[email protected]f967b722011-09-07 00:58:04111 // Prevent Cocoa from turning command-line arguments into
112 // |-application:openFiles:|, since we already handle them directly.
113 [[NSUserDefaults standardUserDefaults]
114 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
115}
[email protected]03d8d3e92011-09-20 06:07:11116
[email protected]03d8d3e92011-09-20 06:07:11117void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() {
118 AppController* appController = [NSApp delegate];
119 [appController didEndMainMessageLoop];
120}