OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/run_loop.h" | |
9 #include "build/build_config.h" | |
10 #include "chrome/browser/chrome_browser_main.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 "chrome/grit/chromium_strings.h" | |
15 #include "chrome/grit/generated_resources.h" | |
16 #include "ui/aura/env.h" | |
17 #include "ui/base/l10n/l10n_util.h" | |
18 #include "ui/base/ui_base_switches.h" | |
19 #include "ui/gfx/screen.h" | |
20 #include "ui/views/widget/native_widget_aura.h" | |
21 | |
22 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
23 #include "chrome/browser/profiles/profile.h" | |
24 #include "chrome/browser/themes/theme_service.h" | |
25 #include "chrome/browser/themes/theme_service_factory.h" | |
26 #include "chrome/browser/ui/views/frame/browser_view.h" | |
27 #include "chrome/common/pref_names.h" | |
28 #include "components/prefs/pref_service.h" | |
29 #include "ui/aura/window.h" | |
30 #include "ui/native_theme/native_theme_aura.h" | |
31 #include "ui/native_theme/native_theme_dark_aura.h" | |
32 #include "ui/views/linux_ui/linux_ui.h" | |
33 #endif | |
34 | |
35 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
36 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" | |
37 #endif | |
38 | |
39 #if defined(USE_ASH) | |
40 #include "chrome/browser/ui/ash/ash_util.h" | |
41 #endif // defined(USE_ASH) | |
42 | |
43 #if !defined(OS_CHROMEOS) | |
44 #include "ui/views/widget/desktop_aura/desktop_screen.h" | |
45 #endif | |
46 | |
47 namespace { | |
48 | |
49 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
50 ui::NativeTheme* GetNativeThemeForWindow(aura::Window* window) { | |
51 if (!window) | |
52 return nullptr; | |
53 | |
54 Profile* profile = nullptr; | |
55 // Window types not listed here (such as tooltips) will never use Chrome | |
56 // theming. | |
57 if (window->type() == ui::wm::WINDOW_TYPE_NORMAL || | |
58 window->type() == ui::wm::WINDOW_TYPE_POPUP) { | |
59 profile = reinterpret_cast<Profile*>( | |
60 window->GetNativeWindowProperty(Profile::kProfileKey)); | |
61 } | |
62 | |
63 // If using the system (GTK) theme, don't use an Aura NativeTheme at all. | |
64 // NB: ThemeService::UsingSystemTheme() might lag behind this pref. See | |
65 // http://crbug.com/585522 | |
66 if (!profile || profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) | |
67 return nullptr; | |
68 | |
69 // Use a dark theme for incognito browser windows that aren't | |
70 // custom-themed. Otherwise, normal Aura theme. | |
71 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE && | |
72 ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme() && | |
73 BrowserView::GetBrowserViewForNativeWindow(window)) { | |
74 return ui::NativeThemeDarkAura::instance(); | |
75 } | |
76 | |
77 return ui::NativeThemeAura::instance(); | |
78 } | |
79 #endif | |
80 | |
81 } // namespace | |
82 | |
83 ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() { | |
84 } | |
85 | |
86 ChromeBrowserMainExtraPartsAura::~ChromeBrowserMainExtraPartsAura() { | |
87 } | |
88 | |
89 void ChromeBrowserMainExtraPartsAura::PreEarlyInitialization() { | |
90 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
91 // TODO(erg): Refactor this into a dlopen call when we add a GTK3 port. | |
92 views::LinuxUI* gtk2_ui = BuildGtk2UI(); | |
93 gtk2_ui->SetNativeThemeOverride(base::Bind(&GetNativeThemeForWindow)); | |
94 views::LinuxUI::SetInstance(gtk2_ui); | |
95 #endif | |
96 } | |
97 | |
98 void ChromeBrowserMainExtraPartsAura::ToolkitInitialized() { | |
99 #if defined(USE_X11) && !defined(OS_CHROMEOS) | |
100 views::LinuxUI::instance()->Initialize(); | |
101 #endif | |
102 } | |
103 | |
104 void ChromeBrowserMainExtraPartsAura::PreCreateThreads() { | |
105 #if !defined(OS_CHROMEOS) | |
106 #if defined(USE_ASH) | |
107 bool should_open_ash = chrome::ShouldOpenAshOnStartup(); | |
108 #else | |
109 bool should_open_ash = false; | |
110 #endif | |
111 if (!should_open_ash) { | |
112 gfx::Screen* screen = views::CreateDesktopScreen(); | |
113 gfx::Screen::SetScreenInstance(screen); | |
114 #if defined(USE_X11) | |
115 views::LinuxUI::instance()->UpdateDeviceScaleFactor( | |
116 screen->GetPrimaryDisplay().device_scale_factor()); | |
117 #endif | |
118 } | |
119 #endif | |
120 } | |
121 | |
122 void ChromeBrowserMainExtraPartsAura::PreProfileInit() { | |
123 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
124 // Now that we have some minimal ui initialized, check to see if we're | |
125 // running as root and bail if we are. | |
126 DetectRunningAsRoot(); | |
127 #endif | |
128 } | |
129 | |
130 void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() { | |
131 // aura::Env instance is deleted in BrowserProcessImpl::StartTearDown | |
132 // after the metrics service is deleted. | |
133 } | |
134 | |
135 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
136 void ChromeBrowserMainExtraPartsAura::DetectRunningAsRoot() { | |
137 if (getuid() == 0) { | |
138 const base::CommandLine& command_line = | |
139 *base::CommandLine::ForCurrentProcess(); | |
140 if (command_line.HasSwitch(switches::kUserDataDir)) | |
141 return; | |
142 | |
143 base::string16 title = l10n_util::GetStringFUTF16( | |
144 IDS_REFUSE_TO_RUN_AS_ROOT, | |
145 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
146 base::string16 message = l10n_util::GetStringFUTF16( | |
147 IDS_REFUSE_TO_RUN_AS_ROOT_2, | |
148 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
149 | |
150 chrome::ShowMessageBox(NULL, | |
151 title, | |
152 message, | |
153 chrome::MESSAGE_BOX_TYPE_WARNING); | |
154 | |
155 // Avoids gpu_process_transport_factory.cc(153)] Check failed: | |
156 // per_compositor_data_.empty() when quit is chosen. | |
157 base::RunLoop().RunUntilIdle(); | |
158 | |
159 exit(EXIT_FAILURE); | |
160 } | |
161 } | |
162 #endif | |
OLD | NEW |