blob: 8264490f95d4f6a90852f3f845230bfca4953d0d [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]c4d501e2012-03-27 20:08:0219#include "chrome/browser/mac/install_from_dmg.h"
[email protected]5950f5712011-06-20 22:15:5220#import "chrome/browser/mac/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]4573fbd2011-10-31 20:25:1824#include "content/public/common/main_function_params.h"
[email protected]b39ef1cb2011-10-25 04:46:5525#include "content/public/common/result_codes.h"
[email protected]c051a1b2011-01-21 23:30:1726#include "ui/base/l10n/l10n_util_mac.h"
[email protected]42ce29d2011-01-20 23:19:4627#include "ui/base/resource/resource_bundle.h"
[email protected]5c9587c2008-12-09 21:20:1628
[email protected]1152b7e2009-09-14 03:26:0329void RecordBreakpadStatusUMA(MetricsService* metrics) {
30 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled());
[email protected]58580352010-10-26 04:07:5031 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged());
[email protected]1152b7e2009-09-14 03:26:0332}
33
[email protected]45d72762011-04-15 18:58:2034void RecordBrowserStartupTime() {
35 // Not implemented on Mac for now.
36}
37
[email protected]34f73fb2010-03-24 20:50:3438void WarnAboutMinimumSystemRequirements() {
39 // Nothing to check for on Mac right now.
40}
[email protected]1bcdb532009-01-16 17:47:5741
42// From browser_main_win.h, stubs until we figure out the right thing...
43
[email protected]53c38d232009-02-13 20:52:1844int DoUninstallTasks(bool chrome_still_running) {
[email protected]1fcfb202011-07-19 19:53:1445 return content::RESULT_CODE_NORMAL_EXIT;
[email protected]1bcdb532009-01-16 17:47:5746}
47
[email protected]e6b5bc22011-09-08 22:01:5648// ChromeBrowserMainPartsMac ---------------------------------------------------
[email protected]1fec64352010-07-27 13:55:2149
[email protected]e6b5bc22011-09-08 22:01:5650ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac(
[email protected]4573fbd2011-10-31 20:25:1851 const content::MainFunctionParams& parameters)
[email protected]e6b5bc22011-09-08 22:01:5652 : ChromeBrowserMainPartsPosix(parameters) {
[email protected]f967b722011-09-07 00:58:0453}
[email protected]1fec64352010-07-27 13:55:2154
[email protected]e6b5bc22011-09-08 22:01:5655void ChromeBrowserMainPartsMac::PreEarlyInitialization() {
[email protected]37c722b2011-09-08 22:18:4656 ChromeBrowserMainPartsPosix::PreEarlyInitialization();
[email protected]91484af2010-08-27 17:55:5457
[email protected]f967b722011-09-07 00:58:0458 if (base::mac::WasLaunchedAsHiddenLoginItem()) {
59 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
60 singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
61 }
62}
63
[email protected]e6b5bc22011-09-08 22:01:5664void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() {
[email protected]37c722b2011-09-08 22:18:4665 ChromeBrowserMainPartsPosix::PreMainMessageLoopStart();
[email protected]f967b722011-09-07 00:58:0466
67 // Tell Cooca to finish its initialization, which we want to do manually
68 // instead of calling NSApplicationMain(). The primary reason is that NSAM()
69 // never returns, which would leave all the objects currently on the stack
70 // in scoped_ptrs hanging and never cleaned up. We then load the main nib
71 // directly. The main event loop is run from common code using the
72 // MessageLoop API, which works out ok for us because it's a wrapper around
73 // CFRunLoop.
74
75 // Initialize NSApplication using the custom subclass.
[email protected]d7de57872011-12-06 23:32:4376 chrome_browser_application_mac::RegisterBrowserCrApp();
[email protected]f967b722011-09-07 00:58:0477
78 // If ui_task is not NULL, the app is actually a browser_test, so startup is
79 // handled outside of BrowserMain (which is what called this).
[email protected]716476c2011-12-29 00:07:0380 if (!parameters().ui_task) {
[email protected]f967b722011-09-07 00:58:0481 // The browser process only wants to support the language Cocoa will use,
82 // so force the app locale to be overriden with that value.
83 l10n_util::OverrideLocaleWithCocoaLocale();
84
85 // Before we load the nib, we need to start up the resource bundle so we
86 // have the strings avaiable for localization.
87 // TODO(markusheintz): Read preference pref::kApplicationLocale in order
88 // to enforce the application locale.
89 const std::string loaded_locale =
[email protected]70f9df12012-01-28 02:30:0490 ResourceBundle::InitSharedInstanceWithLocale(std::string());
[email protected]f967b722011-09-07 00:58:0491 CHECK(!loaded_locale.empty()) << "Default locale could not be found";
92
93 FilePath resources_pack_path;
94 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
95 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path);
[email protected]91484af2010-08-27 17:55:5496 }
97
[email protected]c4d501e2012-03-27 20:08:0298 // This is a no-op if the KeystoneRegistration framework is not present.
99 // The framework is only distributed with branded Google Chrome builds.
100 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone];
101
102 // Disk image installation is sort of a first-run task, so it shares the
103 // kNoFirstRun switch.
104 //
105 // This needs to be done after the resource bundle is initialized (for
106 // access to localizations in the UI) and after Keystone is initialized
107 // (because the installation may need to promote Keystone) but before the
108 // app controller is set up (and thus before MainMenu.nib is loaded, because
109 // the app controller assumes that a browser has been set up and will crash
110 // upon receipt of certain notifications if no browser exists), before
111 // anyone tries doing anything silly like firing off an import job, and
112 // before anything creating preferences like Local State in order for the
113 // relaunched installed application to still consider itself as first-run.
114 if (!parsed_command_line().HasSwitch(switches::kNoFirstRun)) {
115 if (MaybeInstallFromDiskImage()) {
116 // The application was installed and the installed copy has been
117 // launched. This process is now obsolete. Exit.
118 exit(0);
119 }
120 }
121
[email protected]f967b722011-09-07 00:58:04122 // Now load the nib (from the right bundle).
123 scoped_nsobject<NSNib>
124 nib([[NSNib alloc] initWithNibNamed:@"MainMenu"
[email protected]2f1804c2012-01-19 14:59:07125 bundle:base::mac::FrameworkBundle()]);
[email protected]f967b722011-09-07 00:58:04126 // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you
127 // change this, you'll probably need to change the Valgrind suppression.
128 [nib instantiateNibWithOwner:NSApp topLevelObjects:nil];
129 // Make sure the app controller has been created.
130 DCHECK([NSApp delegate]);
[email protected]1fec64352010-07-27 13:55:21131
[email protected]f967b722011-09-07 00:58:04132 // Prevent Cocoa from turning command-line arguments into
133 // |-application:openFiles:|, since we already handle them directly.
134 [[NSUserDefaults standardUserDefaults]
135 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"];
136}
[email protected]03d8d3e92011-09-20 06:07:11137
[email protected]03d8d3e92011-09-20 06:07:11138void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() {
139 AppController* appController = [NSApp delegate];
140 [appController didEndMainMessageLoop];
141}