Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / desktop_browser_frame_auralinux.cc
blobce1c651c139369dcda31a1689f58d61f4f87d3a9
1 // Copyright 2015 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.
5 #include "chrome/browser/ui/views/frame/desktop_browser_frame_auralinux.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/shell_integration_linux.h"
9 #include "chrome/browser/ui/views/frame/browser_frame.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "ui/views/widget/widget.h"
15 DesktopBrowserFrameAuraLinux::DesktopBrowserFrameAuraLinux(
16 BrowserFrame* browser_frame,
17 BrowserView* browser_view)
18 : DesktopBrowserFrameAura(browser_frame, browser_view) {
19 use_custom_frame_pref_.Init(
20 prefs::kUseCustomChromeFrame,
21 browser_view->browser()->profile()->GetPrefs(),
22 base::Bind(&DesktopBrowserFrameAuraLinux::OnUseCustomChromeFrameChanged,
23 base::Unretained(this)));
26 DesktopBrowserFrameAuraLinux::~DesktopBrowserFrameAuraLinux() {
29 views::Widget::InitParams DesktopBrowserFrameAuraLinux::GetWidgetParams() {
30 views::Widget::InitParams params;
31 params.native_widget = this;
33 // Set up a custom WM_CLASS for some sorts of window types. This allows
34 // task switchers in X11 environments to distinguish between main browser
35 // windows and e.g app windows.
36 const base::CommandLine& command_line =
37 *base::CommandLine::ForCurrentProcess();
38 const Browser& browser = *browser_view()->browser();
39 params.wm_class_class = shell_integration_linux::GetProgramClassName();
40 params.wm_class_name = params.wm_class_class;
41 if (browser.is_app() && !browser.is_devtools()) {
42 // This window is a hosted app or v1 packaged app.
43 // NOTE: v2 packaged app windows are created by ChromeNativeAppWindowViews.
44 params.wm_class_name = web_app::GetWMClassFromAppName(browser.app_name());
45 } else if (command_line.HasSwitch(switches::kUserDataDir)) {
46 // Set the class name to e.g. "Chrome (/tmp/my-user-data)". The
47 // class name will show up in the alt-tab list in gnome-shell if
48 // you're running a binary that doesn't have a matching .desktop
49 // file.
50 const std::string user_data_dir =
51 command_line.GetSwitchValueNative(switches::kUserDataDir);
52 params.wm_class_name += " (" + user_data_dir + ")";
54 const char kX11WindowRoleBrowser[] = "browser";
55 const char kX11WindowRolePopup[] = "pop-up";
56 params.wm_role_name = browser_view()->browser()->is_type_tabbed() ?
57 std::string(kX11WindowRoleBrowser) : std::string(kX11WindowRolePopup);
58 params.remove_standard_frame = UseCustomFrame();
60 return params;
63 bool DesktopBrowserFrameAuraLinux::UseCustomFrame() const {
64 return use_custom_frame_pref_.GetValue() &&
65 browser_view()->IsBrowserTypeNormal();
68 void DesktopBrowserFrameAuraLinux::OnUseCustomChromeFrameChanged() {
69 // Tell the window manager to add or remove system borders.
70 browser_frame()->set_frame_type(
71 UseCustomFrame() ? views::Widget::FRAME_TYPE_FORCE_CUSTOM
72 : views::Widget::FRAME_TYPE_FORCE_NATIVE);
73 browser_frame()->FrameTypeChanged();