Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / ui / host_desktop.cc
blobf7f7c6539f670b519b77a26880a062b9463b6aca
1 // Copyright 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.
5 #include "chrome/browser/ui/host_desktop.h"
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #endif
11 #include "ash/shell.h"
12 #include "chrome/browser/ui/ash/ash_util.h"
13 #include "chrome/browser/ui/aura/active_desktop_monitor.h"
14 #include "chrome/browser/ui/browser_list_impl.h"
16 namespace chrome {
18 namespace {
20 bool g_force_ = false;
21 HostDesktopType g_force_type_ = HOST_DESKTOP_TYPE_COUNT;
23 } // namespace
25 ScopedForceDesktopType::ScopedForceDesktopType(HostDesktopType type)
26 : previous_type_(g_force_type_),
27 previous_force_(g_force_) {
28 g_force_type_ = type;
29 g_force_ = true;
32 ScopedForceDesktopType::~ScopedForceDesktopType() {
33 g_force_type_ = previous_type_;
34 g_force_ = previous_force_;
37 HostDesktopType GetHostDesktopTypeForNativeView(gfx::NativeView native_view) {
38 if (g_force_)
39 return g_force_type_;
40 #if defined(USE_ASH)
41 return IsNativeViewInAsh(native_view) ?
42 HOST_DESKTOP_TYPE_ASH :
43 HOST_DESKTOP_TYPE_NATIVE;
44 #else
45 return HOST_DESKTOP_TYPE_NATIVE;
46 #endif
49 HostDesktopType GetHostDesktopTypeForNativeWindow(
50 gfx::NativeWindow native_window) {
51 if (g_force_)
52 return g_force_type_;
53 #if defined(USE_ASH)
54 return IsNativeWindowInAsh(native_window) ?
55 HOST_DESKTOP_TYPE_ASH :
56 HOST_DESKTOP_TYPE_NATIVE;
57 #else
58 return HOST_DESKTOP_TYPE_NATIVE;
59 #endif
62 HostDesktopType GetHostDesktopTypeForBrowser(const Browser* browser) {
63 if (g_force_)
64 return g_force_type_;
65 for (HostDesktopType type = HOST_DESKTOP_TYPE_FIRST;
66 type < HOST_DESKTOP_TYPE_COUNT;
67 type = static_cast<HostDesktopType>(type + 1)) {
68 BrowserListImpl::const_iterator begin =
69 BrowserListImpl::GetInstance(type)->begin();
70 BrowserListImpl::const_iterator end =
71 BrowserListImpl::GetInstance(type)->end();
72 if (std::find(begin, end, browser) != end)
73 return type;
75 return HOST_DESKTOP_TYPE_NATIVE;
78 HostDesktopType GetActiveDesktop() {
79 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
80 // The Ash desktop is considered active if a non-desktop RootWindow was last
81 // activated and the Ash desktop is still open. As it is, the Ash desktop
82 // will be considered the last active if a user switches from metro Chrome to
83 // the Windows desktop but doesn't activate any Chrome windows there (e.g.,
84 // by clicking on one or otherwise giving one focus). Consider finding a way
85 // to detect that the Windows desktop has been activated so that the native
86 // desktop can be considered active once the user switches to it if its
87 // BrowserList isn't empty.
88 if ((ActiveDesktopMonitor::GetLastActivatedDesktopType() ==
89 chrome::HOST_DESKTOP_TYPE_ASH) &&
90 ash::Shell::HasInstance()) {
91 return HOST_DESKTOP_TYPE_ASH;
93 #endif
94 return HOST_DESKTOP_TYPE_NATIVE;
97 } // namespace chrome