OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/libgtk2ui/chrome_browser_main_extra_parts_views_gtk.
h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/chrome_browser_main.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/themes/theme_service.h" |
| 12 #include "chrome/browser/themes/theme_service_factory.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" |
| 14 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
| 15 #include "chrome/browser/ui/simple_message_box.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/grit/chromium_strings.h" |
| 20 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/prefs/pref_service.h" |
| 22 #include "ui/aura/window.h" |
| 23 #include "ui/base/ime/input_method_initializer.h" |
| 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/ui_base_switches.h" |
| 26 #include "ui/gfx/screen.h" |
| 27 #include "ui/native_theme/native_theme_aura.h" |
| 28 #include "ui/native_theme/native_theme_dark_aura.h" |
| 29 #include "ui/views/linux_ui/linux_ui.h" |
| 30 #include "ui/views/widget/desktop_aura/desktop_screen.h" |
| 31 #include "ui/views/widget/native_widget_aura.h" |
| 32 |
| 33 namespace { |
| 34 |
| 35 ui::NativeTheme* GetNativeThemeForWindow(aura::Window* window) { |
| 36 if (!window) |
| 37 return nullptr; |
| 38 |
| 39 Profile* profile = nullptr; |
| 40 // Window types not listed here (such as tooltips) will never use Chrome |
| 41 // theming. |
| 42 if (window->type() == ui::wm::WINDOW_TYPE_NORMAL || |
| 43 window->type() == ui::wm::WINDOW_TYPE_POPUP) { |
| 44 profile = reinterpret_cast<Profile*>( |
| 45 window->GetNativeWindowProperty(Profile::kProfileKey)); |
| 46 } |
| 47 |
| 48 // If using the system (GTK) theme, don't use an Aura NativeTheme at all. |
| 49 // NB: ThemeService::UsingSystemTheme() might lag behind this pref. See |
| 50 // http://crbug.com/585522 |
| 51 if (!profile || profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) |
| 52 return nullptr; |
| 53 |
| 54 // Use a dark theme for incognito browser windows that aren't |
| 55 // custom-themed. Otherwise, normal Aura theme. |
| 56 if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE && |
| 57 ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme() && |
| 58 BrowserView::GetBrowserViewForNativeWindow(window)) { |
| 59 return ui::NativeThemeDarkAura::instance(); |
| 60 } |
| 61 |
| 62 return ui::NativeThemeAura::instance(); |
| 63 } |
| 64 |
| 65 } // namespace |
| 66 |
| 67 ChromeBrowserMainExtraPartsViewsGtk::ChromeBrowserMainExtraPartsViewsGtk() { |
| 68 } |
| 69 |
| 70 ChromeBrowserMainExtraPartsViewsGtk::~ChromeBrowserMainExtraPartsViewsGtk() { |
| 71 } |
| 72 |
| 73 void ChromeBrowserMainExtraPartsViewsGtk::PreEarlyInitialization() { |
| 74 // TODO(erg): Refactor this into a dlopen call when we add a GTK3 port. |
| 75 views::LinuxUI* gtk2_ui = BuildGtk2UI(); |
| 76 gtk2_ui->SetNativeThemeOverride(base::Bind(&GetNativeThemeForWindow)); |
| 77 views::LinuxUI::SetInstance(gtk2_ui); |
| 78 } |
| 79 |
| 80 void ChromeBrowserMainExtraPartsViewsGtk::ToolkitInitialized() { |
| 81 views::LinuxUI::instance()->Initialize(); |
| 82 } |
| 83 |
| 84 void ChromeBrowserMainExtraPartsViewsGtk::PreCreateThreads() { |
| 85 ChromeBrowserMainExtraPartsViews::PreCreateThreads(); |
| 86 views::LinuxUI::instance()->UpdateDeviceScaleFactor( |
| 87 gfx::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor()); |
| 88 } |
| 89 |
| 90 void ChromeBrowserMainExtraPartsViewsGtk::PreProfileInit() { |
| 91 // On the Linux desktop, we want to prevent the user from logging in as root, |
| 92 // so that we don't destroy the profile. Now that we have some minimal ui |
| 93 // initialized, check to see if we're running as root and bail if we are. |
| 94 if (getuid() != 0) |
| 95 return; |
| 96 |
| 97 const base::CommandLine& command_line = |
| 98 *base::CommandLine::ForCurrentProcess(); |
| 99 if (command_line.HasSwitch(switches::kUserDataDir)) |
| 100 return; |
| 101 |
| 102 base::string16 title = l10n_util::GetStringFUTF16( |
| 103 IDS_REFUSE_TO_RUN_AS_ROOT, |
| 104 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 105 base::string16 message = l10n_util::GetStringFUTF16( |
| 106 IDS_REFUSE_TO_RUN_AS_ROOT_2, |
| 107 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 108 |
| 109 chrome::ShowMessageBox(NULL, |
| 110 title, |
| 111 message, |
| 112 chrome::MESSAGE_BOX_TYPE_WARNING); |
| 113 |
| 114 // Avoids gpu_process_transport_factory.cc(153)] Check failed: |
| 115 // per_compositor_data_.empty() when quit is chosen. |
| 116 base::RunLoop().RunUntilIdle(); |
| 117 |
| 118 exit(EXIT_FAILURE); |
| 119 } |
OLD | NEW |