Index: chrome/browser/ui/host_desktop.cc |
diff --git a/chrome/browser/ui/host_desktop.cc b/chrome/browser/ui/host_desktop.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ca7b7076fa76a8a8d3c9bd7e18ff0e0a6416b63f |
--- /dev/null |
+++ b/chrome/browser/ui/host_desktop.cc |
@@ -0,0 +1,64 @@ |
+// Copyright 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/host_desktop.h" |
+ |
+#include "chrome/browser/ui/ash/ash_util.h" |
+#include "chrome/browser/ui/browser_list_impl.h" |
+ |
+namespace chrome { |
+ |
+namespace { |
+ |
+bool force_ = false; |
+HostDesktopType force_type_ = HOST_DESKTOP_TYPE_COUNT; |
+ |
+} // namespace |
+ |
+ScopedForceDesktopType::ScopedForceDesktopType(HostDesktopType type) |
+ : previous_type_(force_type_), |
+ previous_force_(force_) { |
+ force_type_ = type; |
+ force_ = true; |
+} |
+ |
+ScopedForceDesktopType::~ScopedForceDesktopType() { |
+ force_type_ = previous_type_; |
+ force_ = previous_force_; |
+} |
+ |
+HostDesktopType GetHostDesktopTypeForNativeView(gfx::NativeView native_view) { |
+ if (force_) |
+ return force_type_; |
+ return IsNativeViewInAsh(native_view) ? |
+ HOST_DESKTOP_TYPE_ASH : |
+ HOST_DESKTOP_TYPE_NATIVE; |
+} |
+ |
+HostDesktopType GetHostDesktopTypeForNativeWindow( |
+ gfx::NativeWindow native_window) { |
+ if (force_) |
+ return force_type_; |
+ return IsNativeWindowInAsh(native_window) ? |
+ HOST_DESKTOP_TYPE_ASH : |
+ HOST_DESKTOP_TYPE_NATIVE; |
+} |
+ |
+HostDesktopType GetHostDesktopTypeForBrowser(const Browser* browser) { |
+ if (force_) |
+ return force_type_; |
+ for (HostDesktopType type = HOST_DESKTOP_TYPE_FIRST; |
+ type < HOST_DESKTOP_TYPE_COUNT; |
+ type = static_cast<HostDesktopType>(type + 1)) { |
+ BrowserListImpl::const_iterator begin = |
+ BrowserListImpl::GetInstance(type)->begin(); |
+ BrowserListImpl::const_iterator end = |
+ BrowserListImpl::GetInstance(type)->end(); |
+ if (find(begin, end, browser) != end) |
+ return type; |
+ } |
+ return HOST_DESKTOP_TYPE_NATIVE; |
+} |
+ |
+} |