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_gtk.h" | 5 #include "chrome/browser/browser_main_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/debugger.h" | 13 #include "base/debug/debugger.h" |
14 #include "chrome/browser/browser_main_win.h" | 14 #include "chrome/browser/browser_main_win.h" |
15 #include "chrome/browser/metrics/metrics_service.h" | 15 #include "chrome/browser/metrics/metrics_service.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/chrome_result_codes.h" | 18 #include "chrome/common/chrome_result_codes.h" |
19 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | |
20 #include "content/browser/zygote_host_linux.h" | |
21 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
22 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/base/x/x11_util.h" | 23 #include "ui/base/x/x11_util.h" |
26 #include "ui/base/x/x11_util_internal.h" | 24 #include "ui/base/x/x11_util_internal.h" |
27 #include "ui/gfx/gtk_util.h" | 25 #include "ui/gfx/gtk_util.h" |
28 | 26 |
29 #if defined(USE_NSS) | |
30 #include "crypto/nss_util.h" | |
31 #endif | |
32 | |
33 #if defined(USE_LINUX_BREAKPAD) | 27 #if defined(USE_LINUX_BREAKPAD) |
34 #include "chrome/app/breakpad_linux.h" | 28 #include "chrome/app/breakpad_linux.h" |
35 #endif | 29 #endif |
36 | 30 |
37 namespace { | 31 namespace { |
38 | 32 |
39 // Indicates that we're currently responding to an IO error (by shutting down). | 33 // Indicates that we're currently responding to an IO error (by shutting down). |
40 bool g_in_x11_io_error_handler = false; | 34 bool g_in_x11_io_error_handler = false; |
41 | 35 |
42 // Number of seconds to wait for UI thread to get an IO error if we get it on | 36 // Number of seconds to wait for UI thread to get an IO error if we get it on |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } // namespace | 76 } // namespace |
83 | 77 |
84 BrowserMainPartsGtk::BrowserMainPartsGtk(const MainFunctionParams& parameters) | 78 BrowserMainPartsGtk::BrowserMainPartsGtk(const MainFunctionParams& parameters) |
85 : BrowserMainPartsPosix(parameters) { | 79 : BrowserMainPartsPosix(parameters) { |
86 } | 80 } |
87 | 81 |
88 void BrowserMainPartsGtk::PreEarlyInitialization() { | 82 void BrowserMainPartsGtk::PreEarlyInitialization() { |
89 DetectRunningAsRoot(); | 83 DetectRunningAsRoot(); |
90 | 84 |
91 BrowserMainPartsPosix::PreEarlyInitialization(); | 85 BrowserMainPartsPosix::PreEarlyInitialization(); |
92 | |
93 SetupSandbox(); | |
94 | |
95 #if defined(USE_NSS) | |
96 // We want to be sure to init NSPR on the main thread. | |
97 crypto::EnsureNSPRInit(); | |
98 #endif | |
99 } | 86 } |
100 | 87 |
101 void BrowserMainPartsGtk::DetectRunningAsRoot() { | 88 void BrowserMainPartsGtk::DetectRunningAsRoot() { |
102 if (geteuid() == 0) { | 89 if (geteuid() == 0) { |
103 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 90 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
104 if (parsed_command_line().HasSwitch(switches::kUserDataDir)) | 91 if (parsed_command_line().HasSwitch(switches::kUserDataDir)) |
105 return; | 92 return; |
106 | 93 |
107 gfx::GtkInitFromCommandLine(command_line); | 94 gfx::GtkInitFromCommandLine(command_line); |
108 | 95 |
(...skipping 23 matching lines...) Expand all Loading... |
132 | 119 |
133 message = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); | 120 message = l10n_util::GetStringUTF8(IDS_PRODUCT_NAME); |
134 gtk_window_set_title(GTK_WINDOW(dialog), message.c_str()); | 121 gtk_window_set_title(GTK_WINDOW(dialog), message.c_str()); |
135 | 122 |
136 gtk_dialog_run(GTK_DIALOG(dialog)); | 123 gtk_dialog_run(GTK_DIALOG(dialog)); |
137 gtk_widget_destroy(dialog); | 124 gtk_widget_destroy(dialog); |
138 exit(EXIT_FAILURE); | 125 exit(EXIT_FAILURE); |
139 } | 126 } |
140 } | 127 } |
141 | 128 |
142 void BrowserMainPartsGtk::SetupSandbox() { | |
143 // TODO(evanm): move this into SandboxWrapper; I'm just trying to move this | |
144 // code en masse out of chrome_main for now. | |
145 const char* sandbox_binary = NULL; | |
146 struct stat st; | |
147 | |
148 // In Chromium branded builds, developers can set an environment variable to | |
149 // use the development sandbox. See | |
150 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment | |
151 if (stat("/proc/self/exe", &st) == 0 && st.st_uid == getuid()) | |
152 sandbox_binary = getenv("CHROME_DEVEL_SANDBOX"); | |
153 | |
154 #if defined(LINUX_SANDBOX_PATH) | |
155 if (!sandbox_binary) | |
156 sandbox_binary = LINUX_SANDBOX_PATH; | |
157 #endif | |
158 | |
159 std::string sandbox_cmd; | |
160 if (sandbox_binary && !parsed_command_line().HasSwitch(switches::kNoSandbox)) | |
161 sandbox_cmd = sandbox_binary; | |
162 | |
163 // Tickle the sandbox host and zygote host so they fork now. | |
164 RenderSandboxHostLinux* shost = RenderSandboxHostLinux::GetInstance(); | |
165 shost->Init(sandbox_cmd); | |
166 ZygoteHost* zhost = ZygoteHost::GetInstance(); | |
167 zhost->Init(sandbox_cmd); | |
168 } | |
169 | |
170 namespace content { | 129 namespace content { |
171 | 130 |
172 void DidEndMainMessageLoop() { | 131 void DidEndMainMessageLoop() { |
173 } | 132 } |
174 | 133 |
175 } | 134 } |
176 | 135 |
177 void RecordBreakpadStatusUMA(MetricsService* metrics) { | 136 void RecordBreakpadStatusUMA(MetricsService* metrics) { |
178 #if defined(USE_LINUX_BREAKPAD) | 137 #if defined(USE_LINUX_BREAKPAD) |
179 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); | 138 metrics->RecordBreakpadRegistration(IsCrashReporterEnabled()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 181 } |
223 | 182 |
224 void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { | 183 void PrepareRestartOnCrashEnviroment(const CommandLine &parsed_command_line) { |
225 } | 184 } |
226 | 185 |
227 void SetBrowserX11ErrorHandlers() { | 186 void SetBrowserX11ErrorHandlers() { |
228 // Set up error handlers to make sure profile gets written if X server | 187 // Set up error handlers to make sure profile gets written if X server |
229 // goes away. | 188 // goes away. |
230 ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); | 189 ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); |
231 } | 190 } |
OLD | NEW |