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