diff options
| author | estade <estade@chromium.org> | 2016-02-17 14:55:21 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 22:56:09 +0000 |
| commit | d3aa0e87b3342365ba4eded7e3d0f1eb2de50f6d (patch) | |
| tree | 96768e0ed7180857ae34b3795e6f9d22ad011043 | |
| parent | 54d1294f337c5d7fe0bc474e9ae34d38913dc1f3 (diff) | |
| download | chromium_src-d3aa0e87b3342365ba4eded7e3d0f1eb2de50f6d.zip chromium_src-d3aa0e87b3342365ba4eded7e3d0f1eb2de50f6d.tar.gz chromium_src-d3aa0e87b3342365ba4eded7e3d0f1eb2de50f6d.tar.bz2 | |
Move gtk-specific browser main parts stuff to its own file.
BUG=none
Review URL: https://codereview.chromium.org/1680033004
Cr-Commit-Position: refs/heads/master@{#376017}
10 files changed, 166 insertions, 209 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index e2e64e8..8334c7c 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -71,6 +71,7 @@ include_rules = [ "-chrome/browser/ui/views", "+chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h", + "+chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h", "+chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h", # Explicitly disallow using SyncMessageFilter to prevent browser from diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 819c6d7..f6efaed 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -221,12 +221,12 @@ #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" #endif -#if defined(USE_ASH) -#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) +#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" #endif -#if defined(USE_AURA) -#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" +#if defined(USE_ASH) +#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" #endif #if defined(USE_X11) @@ -780,8 +780,12 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( // Construct additional browser parts. Stages are called in the order in // which they are added. #if defined(TOOLKIT_VIEWS) +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) + main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux()); +#else main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); #endif +#endif // TODO(oshima): Athena on chrome currently requires USE_ASH to build. // We should reduce the dependency as much as possible. @@ -789,10 +793,6 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); #endif -#if defined(USE_AURA) - main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); -#endif - #if defined(USE_X11) main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); #endif diff --git a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc deleted file mode 100644 index 10673a3..0000000 --- a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" - -#include "base/command_line.h" -#include "base/run_loop.h" -#include "build/build_config.h" -#include "chrome/browser/chrome_browser_main.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/simple_message_box.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/grit/chromium_strings.h" -#include "chrome/grit/generated_resources.h" -#include "ui/aura/env.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/ui_base_switches.h" -#include "ui/gfx/screen.h" -#include "ui/views/widget/native_widget_aura.h" - -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/themes/theme_service.h" -#include "chrome/browser/themes/theme_service_factory.h" -#include "chrome/browser/ui/views/frame/browser_view.h" -#include "chrome/common/pref_names.h" -#include "components/prefs/pref_service.h" -#include "ui/aura/window.h" -#include "ui/native_theme/native_theme_aura.h" -#include "ui/native_theme/native_theme_dark_aura.h" -#include "ui/views/linux_ui/linux_ui.h" -#endif - -#if defined(USE_X11) && !defined(OS_CHROMEOS) -#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" -#endif - -#if defined(USE_ASH) -#include "chrome/browser/ui/ash/ash_util.h" -#endif // defined(USE_ASH) - -#if !defined(OS_CHROMEOS) -#include "ui/views/widget/desktop_aura/desktop_screen.h" -#endif - -namespace { - -#if defined(USE_X11) && !defined(OS_CHROMEOS) -ui::NativeTheme* GetNativeThemeForWindow(aura::Window* window) { - if (!window) - return nullptr; - - Profile* profile = nullptr; - // Window types not listed here (such as tooltips) will never use Chrome - // theming. - if (window->type() == ui::wm::WINDOW_TYPE_NORMAL || - window->type() == ui::wm::WINDOW_TYPE_POPUP) { - profile = reinterpret_cast<Profile*>( - window->GetNativeWindowProperty(Profile::kProfileKey)); - } - - // If using the system (GTK) theme, don't use an Aura NativeTheme at all. - // NB: ThemeService::UsingSystemTheme() might lag behind this pref. See - // http://crbug.com/585522 - if (!profile || profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) - return nullptr; - - // Use a dark theme for incognito browser windows that aren't - // custom-themed. Otherwise, normal Aura theme. - if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE && - ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme() && - BrowserView::GetBrowserViewForNativeWindow(window)) { - return ui::NativeThemeDarkAura::instance(); - } - - return ui::NativeThemeAura::instance(); -} -#endif - -} // namespace - -ChromeBrowserMainExtraPartsAura::ChromeBrowserMainExtraPartsAura() { -} - -ChromeBrowserMainExtraPartsAura::~ChromeBrowserMainExtraPartsAura() { -} - -void ChromeBrowserMainExtraPartsAura::PreEarlyInitialization() { -#if defined(USE_X11) && !defined(OS_CHROMEOS) - // TODO(erg): Refactor this into a dlopen call when we add a GTK3 port. - views::LinuxUI* gtk2_ui = BuildGtk2UI(); - gtk2_ui->SetNativeThemeOverride(base::Bind(&GetNativeThemeForWindow)); - views::LinuxUI::SetInstance(gtk2_ui); -#endif -} - -void ChromeBrowserMainExtraPartsAura::ToolkitInitialized() { -#if defined(USE_X11) && !defined(OS_CHROMEOS) - views::LinuxUI::instance()->Initialize(); -#endif -} - -void ChromeBrowserMainExtraPartsAura::PreCreateThreads() { -#if !defined(OS_CHROMEOS) -#if defined(USE_ASH) - bool should_open_ash = chrome::ShouldOpenAshOnStartup(); -#else - bool should_open_ash = false; -#endif - if (!should_open_ash) { - gfx::Screen* screen = views::CreateDesktopScreen(); - gfx::Screen::SetScreenInstance(screen); -#if defined(USE_X11) - views::LinuxUI::instance()->UpdateDeviceScaleFactor( - screen->GetPrimaryDisplay().device_scale_factor()); -#endif - } -#endif -} - -void ChromeBrowserMainExtraPartsAura::PreProfileInit() { -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) - // Now that we have some minimal ui initialized, check to see if we're - // running as root and bail if we are. - DetectRunningAsRoot(); -#endif -} - -void ChromeBrowserMainExtraPartsAura::PostMainMessageLoopRun() { - // aura::Env instance is deleted in BrowserProcessImpl::StartTearDown - // after the metrics service is deleted. -} - -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) -void ChromeBrowserMainExtraPartsAura::DetectRunningAsRoot() { - if (getuid() == 0) { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(switches::kUserDataDir)) - return; - - base::string16 title = l10n_util::GetStringFUTF16( - IDS_REFUSE_TO_RUN_AS_ROOT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - base::string16 message = l10n_util::GetStringFUTF16( - IDS_REFUSE_TO_RUN_AS_ROOT_2, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - - chrome::ShowMessageBox(NULL, - title, - message, - chrome::MESSAGE_BOX_TYPE_WARNING); - - // Avoids gpu_process_transport_factory.cc(153)] Check failed: - // per_compositor_data_.empty() when quit is chosen. - base::RunLoop().RunUntilIdle(); - - exit(EXIT_FAILURE); - } -} -#endif diff --git a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h b/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h deleted file mode 100644 index 9162381..0000000 --- a/chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_AURA_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ -#define CHROME_BROWSER_UI_AURA_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" -#include "build/build_config.h" -#include "chrome/browser/chrome_browser_main_extra_parts.h" - -class ChromeBrowserMainExtraPartsAura : public ChromeBrowserMainExtraParts { - public: - ChromeBrowserMainExtraPartsAura(); - ~ChromeBrowserMainExtraPartsAura() override; - - // Overridden from ChromeBrowserMainExtraParts: - void PreEarlyInitialization() override; - void ToolkitInitialized() override; - void PreCreateThreads() override; - void PreProfileInit() override; - void PostMainMessageLoopRun() override; - - private: -#if defined(OS_LINUX) && !defined(OS_CHROMEOS) - // On the Linux desktop, we want to prevent the user from logging in as root, - // so that we don't destroy the profile. - void DetectRunningAsRoot(); -#endif - - DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAura); -}; - -#endif // CHROME_BROWSER_UI_AURA_CHROME_BROWSER_MAIN_EXTRA_PARTS_AURA_H_ diff --git a/chrome/browser/ui/views/DEPS b/chrome/browser/ui/views/DEPS index 9f12b1b..b81ef82 100644 --- a/chrome/browser/ui/views/DEPS +++ b/chrome/browser/ui/views/DEPS @@ -1,5 +1,4 @@ include_rules = [ - "-chrome/browser/ui/libgtk2ui", "+content/app/resources/grit/content_resources.h", "+chrome/browser/ui/views", "+components/constrained_window", diff --git a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.cc b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.cc index f10252d..3206b65 100644 --- a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.cc +++ b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.cc @@ -9,6 +9,8 @@ #include "components/constrained_window/constrained_window_views.h" #if defined(USE_AURA) +#include "ui/gfx/screen.h" +#include "ui/views/widget/desktop_aura/desktop_screen.h" #include "ui/wm/core/wm_state.h" #endif @@ -31,3 +33,9 @@ void ChromeBrowserMainExtraPartsViews::ToolkitInitialized() { wm_state_.reset(new wm::WMState); #endif } + +void ChromeBrowserMainExtraPartsViews::PreCreateThreads() { +#if defined(USE_AURA) && !defined(OS_CHROMEOS) + gfx::Screen::SetScreenInstance(views::CreateDesktopScreen()); +#endif +} diff --git a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h index bd9afcc..ce714f2 100644 --- a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h +++ b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h @@ -26,6 +26,7 @@ class ChromeBrowserMainExtraPartsViews : public ChromeBrowserMainExtraParts { // Overridden from ChromeBrowserMainExtraParts: void ToolkitInitialized() override; + void PreCreateThreads() override; private: scoped_ptr<views::ViewsDelegate> views_delegate_; diff --git a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc new file mode 100644 index 0000000..9a36f1a --- /dev/null +++ b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc @@ -0,0 +1,116 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" + +#include "base/command_line.h" +#include "base/run_loop.h" +#include "chrome/browser/chrome_browser_main.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/themes/theme_service.h" +#include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/ui/host_desktop.h" +#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" +#include "chrome/browser/ui/simple_message_box.h" +#include "chrome/browser/ui/views/frame/browser_view.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/pref_names.h" +#include "chrome/grit/chromium_strings.h" +#include "chrome/grit/generated_resources.h" +#include "components/prefs/pref_service.h" +#include "ui/aura/window.h" +#include "ui/base/ime/input_method_initializer.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/ui_base_switches.h" +#include "ui/gfx/screen.h" +#include "ui/native_theme/native_theme_aura.h" +#include "ui/native_theme/native_theme_dark_aura.h" +#include "ui/views/linux_ui/linux_ui.h" +#include "ui/views/widget/desktop_aura/desktop_screen.h" +#include "ui/views/widget/native_widget_aura.h" + +namespace { + +ui::NativeTheme* GetNativeThemeForWindow(aura::Window* window) { + if (!window) + return nullptr; + + Profile* profile = nullptr; + // Window types not listed here (such as tooltips) will never use Chrome + // theming. + if (window->type() == ui::wm::WINDOW_TYPE_NORMAL || + window->type() == ui::wm::WINDOW_TYPE_POPUP) { + profile = reinterpret_cast<Profile*>( + window->GetNativeWindowProperty(Profile::kProfileKey)); + } + + // If using the system (GTK) theme, don't use an Aura NativeTheme at all. + // NB: ThemeService::UsingSystemTheme() might lag behind this pref. See + // http://crbug.com/585522 + if (!profile || profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) + return nullptr; + + // Use a dark theme for incognito browser windows that aren't + // custom-themed. Otherwise, normal Aura theme. + if (profile->GetProfileType() == Profile::INCOGNITO_PROFILE && + ThemeServiceFactory::GetForProfile(profile)->UsingDefaultTheme() && + BrowserView::GetBrowserViewForNativeWindow(window)) { + return ui::NativeThemeDarkAura::instance(); + } + + return ui::NativeThemeAura::instance(); +} + +} // namespace + +ChromeBrowserMainExtraPartsViewsLinux::ChromeBrowserMainExtraPartsViewsLinux() { +} + +ChromeBrowserMainExtraPartsViewsLinux:: + ~ChromeBrowserMainExtraPartsViewsLinux() {} + +void ChromeBrowserMainExtraPartsViewsLinux::PreEarlyInitialization() { + // TODO(erg): Refactor this into a dlopen call when we add a GTK3 port. + views::LinuxUI* gtk2_ui = BuildGtk2UI(); + gtk2_ui->SetNativeThemeOverride(base::Bind(&GetNativeThemeForWindow)); + views::LinuxUI::SetInstance(gtk2_ui); +} + +void ChromeBrowserMainExtraPartsViewsLinux::ToolkitInitialized() { + ChromeBrowserMainExtraPartsViews::ToolkitInitialized(); + views::LinuxUI::instance()->Initialize(); +} + +void ChromeBrowserMainExtraPartsViewsLinux::PreCreateThreads() { + ChromeBrowserMainExtraPartsViews::PreCreateThreads(); + views::LinuxUI::instance()->UpdateDeviceScaleFactor( + gfx::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor()); +} + +void ChromeBrowserMainExtraPartsViewsLinux::PreProfileInit() { + // On the Linux desktop, we want to prevent the user from logging in as root, + // so that we don't destroy the profile. Now that we have some minimal ui + // initialized, check to see if we're running as root and bail if we are. + if (getuid() != 0) + return; + + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kUserDataDir)) + return; + + base::string16 title = l10n_util::GetStringFUTF16( + IDS_REFUSE_TO_RUN_AS_ROOT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + base::string16 message = l10n_util::GetStringFUTF16( + IDS_REFUSE_TO_RUN_AS_ROOT_2, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + + chrome::ShowMessageBox(NULL, title, message, + chrome::MESSAGE_BOX_TYPE_WARNING); + + // Avoids gpu_process_transport_factory.cc(153)] Check failed: + // per_compositor_data_.empty() when quit is chosen. + base::RunLoop().RunUntilIdle(); + + exit(EXIT_FAILURE); +} diff --git a/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h new file mode 100644 index 0000000..422a59a --- /dev/null +++ b/chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h @@ -0,0 +1,30 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ +#define CHROME_BROWSER_UI_VIEWS_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "build/build_config.h" +#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" + +class ChromeBrowserMainExtraPartsViewsLinux + : public ChromeBrowserMainExtraPartsViews { + public: + ChromeBrowserMainExtraPartsViewsLinux(); + ~ChromeBrowserMainExtraPartsViewsLinux() override; + + // Overridden from ChromeBrowserMainExtraParts: + void PreEarlyInitialization() override; + void ToolkitInitialized() override; + void PreCreateThreads() override; + void PreProfileInit() override; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsViewsLinux); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_CHROME_BROWSER_MAIN_EXTRA_PARTS_VIEWS_LINUX_H_ diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 66374d9..94d354a 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -654,8 +654,6 @@ 'browser/ui/aura/accessibility/ax_root_obj_wrapper.h', 'browser/ui/aura/accessibility/ax_tree_source_aura.cc', 'browser/ui/aura/accessibility/ax_tree_source_aura.h', - 'browser/ui/aura/chrome_browser_main_extra_parts_aura.cc', - 'browser/ui/aura/chrome_browser_main_extra_parts_aura.h', 'browser/ui/aura/native_window_tracker_aura.cc', 'browser/ui/aura/native_window_tracker_aura.h', 'browser/ui/aura/tab_contents/web_drag_bookmark_handler_aura.cc', @@ -2123,6 +2121,8 @@ 'chrome_browser_ui_views_non_chromeos_sources': [ 'browser/ui/external_protocol_dialog_delegate.cc', 'browser/ui/external_protocol_dialog_delegate.h', + 'browser/ui/views/chrome_browser_main_extra_parts_views_linux.cc', + 'browser/ui/views/chrome_browser_main_extra_parts_views_linux.h', 'browser/ui/views/external_protocol_dialog.cc', 'browser/ui/views/external_protocol_dialog.h', 'browser/ui/views/frame/opaque_browser_frame_view.cc', |
