Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc

Issue 1680033004: Move gtk-specific browser main parts stuff to its own file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, fix ToolkitInitialized() Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/views/chrome_browser_main_extra_parts_views_linux.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 ChromeBrowserMainExtraPartsViewsLinux::ChromeBrowserMainExtraPartsViewsLinux() {
68 }
69
70 ChromeBrowserMainExtraPartsViewsLinux::
71 ~ChromeBrowserMainExtraPartsViewsLinux() {}
72
73 void ChromeBrowserMainExtraPartsViewsLinux::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 ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() {
81 ChromeBrowserMainExtraPartsViews::ToolkitInitialized();
82 views::LinuxUI::instance()->Initialize();
83 }
84
85 void ChromeBrowserMainExtraPartsViewsLinux::PreCreateThreads() {
86 ChromeBrowserMainExtraPartsViews::PreCreateThreads();
87 views::LinuxUI::instance()->UpdateDeviceScaleFactor(
88 gfx::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
89 }
90
91 void ChromeBrowserMainExtraPartsViewsLinux::PreProfileInit() {
92 // On the Linux desktop, we want to prevent the user from logging in as root,
93 // so that we don't destroy the profile. Now that we have some minimal ui
94 // initialized, check to see if we're running as root and bail if we are.
95 if (getuid() != 0)
96 return;
97
98 const base::CommandLine& command_line =
99 *base::CommandLine::ForCurrentProcess();
100 if (command_line.HasSwitch(switches::kUserDataDir))
101 return;
102
103 base::string16 title = l10n_util::GetStringFUTF16(
104 IDS_REFUSE_TO_RUN_AS_ROOT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
105 base::string16 message = l10n_util::GetStringFUTF16(
106 IDS_REFUSE_TO_RUN_AS_ROOT_2, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
107
108 chrome::ShowMessageBox(NULL, title, message,
109 chrome::MESSAGE_BOX_TYPE_WARNING);
110
111 // Avoids gpu_process_transport_factory.cc(153)] Check failed:
112 // per_compositor_data_.empty() when quit is chosen.
113 base::RunLoop().RunUntilIdle();
114
115 exit(EXIT_FAILURE);
116 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698