| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser_main_posix.h" | 5 #include "chrome/browser/browser_main_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "base/memory/scoped_nsobject.h" | 13 #include "base/memory/scoped_nsobject.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "crypto/nss_util.h" | 15 #include "crypto/nss_util.h" |
| 16 #include "chrome/app/breakpad_mac.h" | 16 #include "chrome/app/breakpad_mac.h" |
| 17 #import "chrome/browser/app_controller_mac.h" | 17 #import "chrome/browser/app_controller_mac.h" |
| 18 #include "chrome/browser/browser_main_win.h" | 18 #include "chrome/browser/browser_main_win.h" |
| 19 #import "chrome/browser/chrome_browser_application_mac.h" | 19 #import "chrome/browser/chrome_browser_application_mac.h" |
| 20 #import "chrome/browser/mac/keystone_glue.h" | 20 #import "chrome/browser/mac/keystone_glue.h" |
| 21 #include "chrome/browser/metrics/metrics_service.h" | 21 #include "chrome/browser/metrics/metrics_service.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "content/common/main_function_params.h" | 24 #include "content/common/main_function_params.h" |
| 25 #include "content/common/result_codes.h" | 25 #include "content/common/result_codes.h" |
| 26 #include "net/socket/client_socket_factory.h" | 26 #include "net/socket/client_socket_factory.h" |
| 27 #include "ui/base/l10n/l10n_util_mac.h" | 27 #include "ui/base/l10n/l10n_util_mac.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 | 29 |
| 30 namespace content { |
| 31 |
| 30 void DidEndMainMessageLoop() { | 32 void DidEndMainMessageLoop() { |
| 31 AppController* appController = [NSApp delegate]; | 33 AppController* appController = [NSApp delegate]; |
| 32 [appController didEndMainMessageLoop]; | 34 [appController didEndMainMessageLoop]; |
| 33 } | 35 } |
| 34 | 36 |
| 37 } |
| 38 |
| 35 void RecordBreakpadStatusUMA(MetricsService* metrics) { | 39 void RecordBreakpadStatusUMA(MetricsService* metrics) { |
| 36 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); | 40 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); |
| 37 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); | 41 metrics->RecordBreakpadHasDebugger(base::debug::BeingDebugged()); |
| 38 } | 42 } |
| 39 | 43 |
| 40 void RecordBrowserStartupTime() { | 44 void RecordBrowserStartupTime() { |
| 41 // Not implemented on Mac for now. | 45 // Not implemented on Mac for now. |
| 42 } | 46 } |
| 43 | 47 |
| 44 void WarnAboutMinimumSystemRequirements() { | 48 void WarnAboutMinimumSystemRequirements() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 | 65 |
| 62 bool CheckMachineLevelInstall() { | 66 bool CheckMachineLevelInstall() { |
| 63 return false; | 67 return false; |
| 64 } | 68 } |
| 65 | 69 |
| 66 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { | 70 void PrepareRestartOnCrashEnviroment(const CommandLine& parsed_command_line) { |
| 67 } | 71 } |
| 68 | 72 |
| 69 // BrowserMainPartsMac --------------------------------------------------------- | 73 // BrowserMainPartsMac --------------------------------------------------------- |
| 70 | 74 |
| 71 class BrowserMainPartsMac : public BrowserMainPartsPosix { | 75 BrowserMainPartsMac::BrowserMainPartsMac(const MainFunctionParams& parameters) |
| 72 public: | 76 : BrowserMainPartsPosix(parameters) { |
| 73 explicit BrowserMainPartsMac(const MainFunctionParams& parameters) | 77 } |
| 74 : BrowserMainPartsPosix(parameters) {} | |
| 75 | 78 |
| 76 protected: | 79 void BrowserMainPartsMac::PreEarlyInitialization() { |
| 77 virtual void PreEarlyInitialization() { | 80 BrowserMainPartsPosix::PreEarlyInitialization(); |
| 78 BrowserMainPartsPosix::PreEarlyInitialization(); | |
| 79 | 81 |
| 80 if (base::mac::WasLaunchedAsHiddenLoginItem()) { | 82 if (base::mac::WasLaunchedAsHiddenLoginItem()) { |
| 81 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); | 83 CommandLine* singleton_command_line = CommandLine::ForCurrentProcess(); |
| 82 singleton_command_line->AppendSwitch(switches::kNoStartupWindow); | 84 singleton_command_line->AppendSwitch(switches::kNoStartupWindow); |
| 83 } | 85 } |
| 86 } |
| 87 |
| 88 void BrowserMainPartsMac::PreMainMessageLoopStart() { |
| 89 BrowserMainPartsPosix::PreMainMessageLoopStart(); |
| 90 |
| 91 // Tell Cooca to finish its initialization, which we want to do manually |
| 92 // instead of calling NSApplicationMain(). The primary reason is that NSAM() |
| 93 // never returns, which would leave all the objects currently on the stack |
| 94 // in scoped_ptrs hanging and never cleaned up. We then load the main nib |
| 95 // directly. The main event loop is run from common code using the |
| 96 // MessageLoop API, which works out ok for us because it's a wrapper around |
| 97 // CFRunLoop. |
| 98 |
| 99 // Initialize NSApplication using the custom subclass. |
| 100 [BrowserCrApplication sharedApplication]; |
| 101 |
| 102 // If ui_task is not NULL, the app is actually a browser_test, so startup is |
| 103 // handled outside of BrowserMain (which is what called this). |
| 104 if (!parameters().ui_task) { |
| 105 // The browser process only wants to support the language Cocoa will use, |
| 106 // so force the app locale to be overriden with that value. |
| 107 l10n_util::OverrideLocaleWithCocoaLocale(); |
| 108 |
| 109 // Before we load the nib, we need to start up the resource bundle so we |
| 110 // have the strings avaiable for localization. |
| 111 // TODO(markusheintz): Read preference pref::kApplicationLocale in order |
| 112 // to enforce the application locale. |
| 113 const std::string loaded_locale = |
| 114 ResourceBundle::InitSharedInstance(std::string()); |
| 115 CHECK(!loaded_locale.empty()) << "Default locale could not be found"; |
| 116 |
| 117 FilePath resources_pack_path; |
| 118 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 119 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
| 84 } | 120 } |
| 85 | 121 |
| 86 virtual void PreMainMessageLoopStart() { | 122 // Now load the nib (from the right bundle). |
| 87 BrowserMainPartsPosix::PreMainMessageLoopStart(); | 123 scoped_nsobject<NSNib> |
| 124 nib([[NSNib alloc] initWithNibNamed:@"MainMenu" |
| 125 bundle:base::mac::MainAppBundle()]); |
| 126 // 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]); |
| 88 | 131 |
| 89 // Tell Cooca to finish its initalization, which we want to do manually | 132 // This is a no-op if the KeystoneRegistration framework is not present. |
| 90 // instead of calling NSApplicationMain(). The primary reason is that NSAM() | 133 // The framework is only distributed with branded Google Chrome builds. |
| 91 // never returns, which would leave all the objects currently on the stack | 134 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; |
| 92 // in scoped_ptrs hanging and never cleaned up. We then load the main nib | |
| 93 // directly. The main event loop is run from common code using the | |
| 94 // MessageLoop API, which works out ok for us because it's a wrapper around | |
| 95 // CFRunLoop. | |
| 96 | 135 |
| 97 // Initialize NSApplication using the custom subclass. | 136 // Prevent Cocoa from turning command-line arguments into |
| 98 [BrowserCrApplication sharedApplication]; | 137 // |-application:openFiles:|, since we already handle them directly. |
| 138 [[NSUserDefaults standardUserDefaults] |
| 139 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; |
| 140 } |
| 99 | 141 |
| 100 // If ui_task is not NULL, the app is actually a browser_test, so startup is | 142 void BrowserMainPartsMac::InitializeSSL() { |
| 101 // handled outside of BrowserMain (which is what called this). | 143 // Use NSS for SSL by default. |
| 102 if (!parameters().ui_task) { | 144 // The default client socket factory uses NSS for SSL by default on Mac. |
| 103 // The browser process only wants to support the language Cocoa will use, | 145 if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { |
| 104 // so force the app locale to be overriden with that value. | 146 net::ClientSocketFactory::UseSystemSSL(); |
| 105 l10n_util::OverrideLocaleWithCocoaLocale(); | 147 } else { |
| 106 | 148 // We want to be sure to init NSPR on the main thread. |
| 107 // Before we load the nib, we need to start up the resource bundle so we | 149 crypto::EnsureNSPRInit(); |
| 108 // have the strings avaiable for localization. | |
| 109 // TODO(markusheintz): Read preference pref::kApplicationLocale in order | |
| 110 // to enforce the application locale. | |
| 111 const std::string loaded_locale = | |
| 112 ResourceBundle::InitSharedInstance(std::string()); | |
| 113 CHECK(!loaded_locale.empty()) << "Default locale could not be found"; | |
| 114 | |
| 115 FilePath resources_pack_path; | |
| 116 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | |
| 117 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | |
| 118 } | |
| 119 | |
| 120 // Now load the nib (from the right bundle). | |
| 121 scoped_nsobject<NSNib> | |
| 122 nib([[NSNib alloc] initWithNibNamed:@"MainMenu" | |
| 123 bundle:base::mac::MainAppBundle()]); | |
| 124 // TODO(viettrungluu): crbug.com/20504 - This currently leaks, so if you | |
| 125 // change this, you'll probably need to change the Valgrind suppression. | |
| 126 [nib instantiateNibWithOwner:NSApp topLevelObjects:nil]; | |
| 127 // Make sure the app controller has been created. | |
| 128 DCHECK([NSApp delegate]); | |
| 129 | |
| 130 // This is a no-op if the KeystoneRegistration framework is not present. | |
| 131 // The framework is only distributed with branded Google Chrome builds. | |
| 132 [[KeystoneGlue defaultKeystoneGlue] registerWithKeystone]; | |
| 133 | |
| 134 // Prevent Cocoa from turning command-line arguments into | |
| 135 // |-application:openFiles:|, since we already handle them directly. | |
| 136 [[NSUserDefaults standardUserDefaults] | |
| 137 setObject:@"NO" forKey:@"NSTreatUnknownArgumentsAsOpen"]; | |
| 138 } | 150 } |
| 139 | |
| 140 private: | |
| 141 virtual void InitializeSSL() { | |
| 142 // Use NSS for SSL by default. | |
| 143 // The default client socket factory uses NSS for SSL by default on Mac. | |
| 144 if (parsed_command_line().HasSwitch(switches::kUseSystemSSL)) { | |
| 145 net::ClientSocketFactory::UseSystemSSL(); | |
| 146 } else { | |
| 147 // We want to be sure to init NSPR on the main thread. | |
| 148 crypto::EnsureNSPRInit(); | |
| 149 } | |
| 150 } | |
| 151 }; | |
| 152 | |
| 153 // static | |
| 154 BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( | |
| 155 const MainFunctionParams& parameters) { | |
| 156 return new BrowserMainPartsMac(parameters); | |
| 157 } | 151 } |
| OLD | NEW |