1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
7 #include "base/command_line.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/chrome_browser_main.h"
10 #include "chrome/browser/ui/aura/active_desktop_monitor.h"
11 #include "chrome/browser/ui/host_desktop.h"
12 #include "chrome/browser/ui/simple_message_box.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h"
16 #include "ui/aura/env.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/gfx/screen.h"
19 #include "ui/views/widget/desktop_aura/desktop_screen.h"
20 #include "ui/views/widget/native_widget_aura.h"
23 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h"
24 #include "ui/views/linux_ui/linux_ui.h"
29 #include "chrome/browser/ui/ash/ash_init.h"
31 #include "base/command_line.h"
32 #include "chrome/common/chrome_switches.h"
33 #endif // defined(OS_WIN)
34 #endif // defined(USE_ASH)
38 #if !defined(OS_CHROMEOS) && defined(USE_ASH)
39 // Returns the desktop this process was initially launched in.
40 chrome::HostDesktopType
GetInitialDesktop() {
41 #if defined(OS_WIN) && defined(USE_ASH)
42 const CommandLine
* command_line
= CommandLine::ForCurrentProcess();
43 if (command_line
->HasSwitch(switches::kViewerConnect
) ||
44 command_line
->HasSwitch(switches::kViewerLaunchViaAppId
)) {
45 return chrome::HOST_DESKTOP_TYPE_ASH
;
48 return chrome::HOST_DESKTOP_TYPE_NATIVE
;
50 #endif // !defined(OS_CHROMEOS) && defined(USE_ASH)
54 ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() {
57 ChromeBrowserMainExtraPartsAura::~ChromeBrowserMainExtraPartsAura() {
60 void ChromeBrowserMainExtraPartsAura::PreEarlyInitialization() {
61 #if !defined(USE_ASH) && defined(OS_LINUX) && defined(USE_X11)
62 // TODO(erg): Refactor this into a dlopen call when we add a GTK3 port.
63 views::LinuxUI::SetInstance(BuildGtk2UI());
67 void ChromeBrowserMainExtraPartsAura::ToolkitInitialized() {
68 #if !defined(OS_CHROMEOS)
70 aura::Env::CreateInstance();
71 active_desktop_monitor_
.reset(new ActiveDesktopMonitor(GetInitialDesktop()));
75 #if !defined(USE_ASH) && defined(OS_LINUX) && defined(USE_X11)
76 views::LinuxUI::instance()->Initialize();
80 void ChromeBrowserMainExtraPartsAura::PreCreateThreads() {
81 #if !defined(OS_CHROMEOS)
83 if (!chrome::ShouldOpenAshOnStartup())
86 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE
,
87 views::CreateDesktopScreen());
92 void ChromeBrowserMainExtraPartsAura::PreProfileInit() {
93 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
94 // Now that we have some minimal ui initialized, check to see if we're
95 // running as root and bail if we are.
96 DetectRunningAsRoot();
100 void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() {
101 active_desktop_monitor_
.reset();
103 // aura::Env instance is deleted in BrowserProcessImpl::StartTearDown
104 // after the metrics service is deleted.
107 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
108 void ChromeBrowserMainExtraPartsAura::DetectRunningAsRoot() {
110 const CommandLine
& command_line
= *CommandLine::ForCurrentProcess();
111 if (command_line
.HasSwitch(switches::kUserDataDir
))
114 base::string16 title
= l10n_util::GetStringFUTF16(
115 IDS_REFUSE_TO_RUN_AS_ROOT
,
116 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
117 base::string16 message
= l10n_util::GetStringFUTF16(
118 IDS_REFUSE_TO_RUN_AS_ROOT_2
,
119 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
121 chrome::ShowMessageBox(NULL
,
124 chrome::MESSAGE_BOX_TYPE_WARNING
);
126 // Avoids gpu_process_transport_factory.cc(153)] Check failed:
127 // per_compositor_data_.empty() when quit is chosen.
128 base::RunLoop().RunUntilIdle();