NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / apps / native_app_window_views_win.cc
bloba6d0fbabb88823ffa8a0ce591ecf31a88e16f5f7
1 // Copyright 2013 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/apps/native_app_window_views_win.h"
7 #include "apps/app_window.h"
8 #include "apps/app_window_registry.h"
9 #include "ash/shell.h"
10 #include "chrome/browser/apps/per_app_settings_service.h"
11 #include "chrome/browser/apps/per_app_settings_service_factory.h"
12 #include "chrome/browser/metro_utils/metro_chrome_win.h"
13 #include "extensions/common/extension.h"
14 #include "ui/aura/remote_window_tree_host_win.h"
15 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
17 NativeAppWindowViewsWin::NativeAppWindowViewsWin() {
20 void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
21 if (!ash::Shell::HasInstance())
22 return;
24 views::Widget* widget =
25 implicit_cast<views::WidgetDelegate*>(this)->GetWidget();
26 chrome::HostDesktopType host_desktop_type =
27 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow());
28 // Only switching into Ash from Native is supported. Tearing the user out of
29 // Metro mode can only be done by launching a process from Metro mode itself.
30 // This is done for launching apps, but not regular activations.
31 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH &&
32 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
33 chrome::ActivateMetroChrome();
37 void NativeAppWindowViewsWin::OnBeforeWidgetInit(
38 views::Widget::InitParams* init_params, views::Widget* widget) {
39 // If an app has any existing windows, ensure new ones are created on the
40 // same desktop.
41 apps::AppWindow* any_existing_window =
42 apps::AppWindowRegistry::Get(browser_context())
43 ->GetCurrentAppWindowForApp(extension()->id());
44 chrome::HostDesktopType desktop_type;
45 if (any_existing_window) {
46 desktop_type = chrome::GetHostDesktopTypeForNativeWindow(
47 any_existing_window->GetNativeWindow());
48 } else {
49 PerAppSettingsService* settings =
50 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context());
51 if (settings->HasDesktopLastLaunchedFrom(extension()->id())) {
52 desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id());
53 } else {
54 // We don't know what desktop this app was last launched from, so take our
55 // best guess as to what desktop the user is on.
56 desktop_type = chrome::GetActiveDesktop();
59 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
60 init_params->context = ash::Shell::GetPrimaryRootWindow();
61 else
62 init_params->native_widget = new views::DesktopNativeWidgetAura(widget);
65 void NativeAppWindowViewsWin::Show() {
66 ActivateParentDesktopIfNecessary();
67 NativeAppWindowViews::Show();
70 void NativeAppWindowViewsWin::Activate() {
71 ActivateParentDesktopIfNecessary();
72 NativeAppWindowViews::Activate();