[email protected] | 71c0eb9 | 2012-01-03 17:57:30 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 5 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 6 | |
[email protected] | ce8c16ad | 2009-08-12 19:00:42 | [diff] [blame] | 7 | #import <Cocoa/Cocoa.h> |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 8 | |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 10 | #include "base/debug/debugger.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 11 | #include "base/file_path.h" |
[email protected] | 2f1804c | 2012-01-19 14:59:07 | [diff] [blame] | 12 | #include "base/mac/bundle_locations.h" |
[email protected] | 0378bf4 | 2011-01-01 18:20:14 | [diff] [blame] | 13 | #include "base/mac/mac_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/scoped_nsobject.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 15 | #include "base/path_service.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 16 | #include "chrome/app/breakpad_mac.h" |
[email protected] | 3b6aa8b6 | 2009-09-15 21:36:11 | [diff] [blame] | 17 | #import "chrome/browser/app_controller_mac.h" |
[email protected] | aaa47ee | 2009-11-05 21:53:01 | [diff] [blame] | 18 | #import "chrome/browser/chrome_browser_application_mac.h" |
[email protected] | 5950f571 | 2011-06-20 22:15:52 | [diff] [blame] | 19 | #import "chrome/browser/mac/keystone_glue.h" |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 20 | #include "chrome/browser/metrics/metrics_service.h" |
[email protected] | e1cb0e9 | 2010-06-15 07:23:59 | [diff] [blame] | 21 | #include "chrome/common/chrome_paths.h" |
[email protected] | d7dbe28c | 2010-07-29 04:33:47 | [diff] [blame] | 22 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 23 | #include "content/public/common/main_function_params.h" |
[email protected] | b39ef1cb | 2011-10-25 04:46:55 | [diff] [blame] | 24 | #include "content/public/common/result_codes.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 25 | #include "ui/base/l10n/l10n_util_mac.h" |
[email protected] | 42ce29d | 2011-01-20 23:19:46 | [diff] [blame] | 26 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 5c9587c | 2008-12-09 21:20:16 | [diff] [blame] | 27 | |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 28 | void RecordBreakpadStatusUMA(MetricsService* metrics) { |
| 29 | metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 30 | metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); |
[email protected] | 1152b7e | 2009-09-14 03:26:03 | [diff] [blame] | 31 | } |
| 32 | |
[email protected] | 45d7276 | 2011-04-15 18:58:20 | [diff] [blame] | 33 | void RecordBrowserStartupTime() { |
| 34 | // Not implemented on Mac for now. |
| 35 | } |
| 36 | |
[email protected] | 34f73fb | 2010-03-24 20:50:34 | [diff] [blame] | 37 | void WarnAboutMinimumSystemRequirements() { |
| 38 | // Nothing to check for on Mac right now. |
| 39 | } |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 40 | |
| 41 | // From browser_main_win.h, stubs until we figure out the right thing... |
| 42 | |
[email protected] | 53c38d23 | 2009-02-13 20:52:18 | [diff] [blame] | 43 | int DoUninstallTasks(bool chrome_still_running) { |
[email protected] | 1fcfb20 | 2011-07-19 19:53:14 | [diff] [blame] | 44 | return content::RESULT_CODE_NORMAL_EXIT; |
[email protected] | 1bcdb53 | 2009-01-16 17:47:57 | [diff] [blame] | 45 | } |
| 46 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 47 | // ChromeBrowserMainPartsMac --------------------------------------------------- |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 48 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 49 | ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac( |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 50 | const content::MainFunctionParams& parameters) |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 51 | : ChromeBrowserMainPartsPosix(parameters) { |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 52 | } |
[email protected] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 53 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 54 | void ChromeBrowserMainPartsMac::PreEarlyInitialization() { |
[email protected] | 37c722b | 2011-09-08 22:18:46 | [diff] [blame] | 55 | ChromeBrowserMainPartsPosix::PreEarlyInitialization(); |
[email protected] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 56 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 57 | if (base::mac::WasLaunchedAsHiddenLoginItem()) { |
| 58 | CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); |
| 59 | singleton_command_line->AppendSwitch(switches::kNoStartupWindow); |
| 60 | } |
| 61 | } |
| 62 | |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 63 | void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() { |
[email protected] | 37c722b | 2011-09-08 22:18:46 | [diff] [blame] | 64 | ChromeBrowserMainPartsPosix::PreMainMessageLoopStart(); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 65 | |
| 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] | d7de5787 | 2011-12-06 23:32:43 | [diff] [blame] | 75 | chrome_browser_application_mac::RegisterBrowserCrApp(); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 76 | |
| 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] | 716476c | 2011-12-29 00:07:03 | [diff] [blame] | 79 | if (!parameters().ui_task) { |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 80 | // 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] | 70f9df1 | 2012-01-28 02:30:04 | [diff] [blame] | 89 | ResourceBundle::InitSharedInstanceWithLocale(std::string()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 90 | 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] | 91484af | 2010-08-27 17:55:54 | [diff] [blame] | 95 | } |
| 96 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 97 | // Now load the nib (from the right bundle). |
| 98 | scoped_nsobject<NSNib> |
| 99 | nib([[NSNib alloc] initWithNibNamed:@"MainMenu" |
[email protected] | 2f1804c | 2012-01-19 14:59:07 | [diff] [blame] | 100 | bundle:base::mac::FrameworkBundle()]); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 101 | // 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] | 1fec6435 | 2010-07-27 13:55:21 | [diff] [blame] | 106 | |
[email protected] | 5bb15df | 2012-03-24 09:27:28 | [diff] [blame] | 107 | // 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] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 111 | // 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] | 03d8d3e9 | 2011-09-20 06:07:11 | [diff] [blame] | 116 | |
[email protected] | 03d8d3e9 | 2011-09-20 06:07:11 | [diff] [blame] | 117 | void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() { |
| 118 | AppController* appController = [NSApp delegate]; |
| 119 | [appController didEndMainMessageLoop]; |
| 120 | } |