Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: chrome/browser/ui/views/apps/native_app_window_views_win.cc

Issue 157813007: Remove Profile dependency from apps::ShellWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/apps/native_app_window_views_win.h" 5 #include "chrome/browser/ui/views/apps/native_app_window_views_win.h"
6 6
7 #include "apps/shell_window.h" 7 #include "apps/shell_window.h"
8 #include "apps/shell_window_registry.h" 8 #include "apps/shell_window_registry.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "chrome/browser/apps/per_app_settings_service.h" 10 #include "chrome/browser/apps/per_app_settings_service.h"
11 #include "chrome/browser/apps/per_app_settings_service_factory.h" 11 #include "chrome/browser/apps/per_app_settings_service_factory.h"
12 #include "chrome/browser/metro_utils/metro_chrome_win.h" 12 #include "chrome/browser/metro_utils/metro_chrome_win.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "extensions/common/extension.h" 13 #include "extensions/common/extension.h"
15 #include "ui/aura/remote_root_window_host_win.h" 14 #include "ui/aura/remote_root_window_host_win.h"
16 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 15 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
17 16
18 NativeAppWindowViewsWin::NativeAppWindowViewsWin() { 17 NativeAppWindowViewsWin::NativeAppWindowViewsWin() {
19 } 18 }
20 19
21 void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { 20 void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
22 if (!ash::Shell::HasInstance()) 21 if (!ash::Shell::HasInstance())
23 return; 22 return;
24 23
25 views::Widget* widget = 24 views::Widget* widget =
26 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); 25 implicit_cast<views::WidgetDelegate*>(this)->GetWidget();
27 chrome::HostDesktopType host_desktop_type = 26 chrome::HostDesktopType host_desktop_type =
28 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); 27 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow());
29 // Only switching into Ash from Native is supported. Tearing the user out of 28 // Only switching into Ash from Native is supported. Tearing the user out of
30 // Metro mode can only be done by launching a process from Metro mode itself. 29 // Metro mode can only be done by launching a process from Metro mode itself.
31 // This is done for launching apps, but not regular activations. 30 // This is done for launching apps, but not regular activations.
32 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && 31 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH &&
33 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { 32 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
34 chrome::ActivateMetroChrome(); 33 chrome::ActivateMetroChrome();
35 } 34 }
36 } 35 }
37 36
38 void NativeAppWindowViewsWin::OnBeforeWidgetInit( 37 void NativeAppWindowViewsWin::OnBeforeWidgetInit(
39 views::Widget::InitParams* init_params, views::Widget* widget) { 38 views::Widget::InitParams* init_params, views::Widget* widget) {
40 // If an app has any existing windows, ensure new ones are created on the 39 // If an app has any existing windows, ensure new ones are created on the
41 // same desktop. 40 // same desktop.
42 apps::ShellWindow* any_existing_window = 41 apps::ShellWindow* any_existing_window =
43 apps::ShellWindowRegistry::Get(profile())-> 42 apps::ShellWindowRegistry::Get(browser_context())
44 GetCurrentShellWindowForApp(extension()->id()); 43 ->GetCurrentShellWindowForApp(extension()->id());
45 chrome::HostDesktopType desktop_type; 44 chrome::HostDesktopType desktop_type;
46 if (any_existing_window) { 45 if (any_existing_window) {
47 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( 46 desktop_type = chrome::GetHostDesktopTypeForNativeWindow(
48 any_existing_window->GetNativeWindow()); 47 any_existing_window->GetNativeWindow());
49 } else { 48 } else {
50 PerAppSettingsService* settings = 49 PerAppSettingsService* settings =
51 PerAppSettingsServiceFactory::GetForBrowserContext(profile()); 50 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context());
52 if (settings->HasDesktopLastLaunchedFrom(extension()->id())) { 51 if (settings->HasDesktopLastLaunchedFrom(extension()->id())) {
53 desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id()); 52 desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id());
54 } else { 53 } else {
55 // We don't know what desktop this app was last launched from, so take our 54 // We don't know what desktop this app was last launched from, so take our
56 // best guess as to what desktop the user is on. 55 // best guess as to what desktop the user is on.
57 desktop_type = chrome::GetActiveDesktop(); 56 desktop_type = chrome::GetActiveDesktop();
58 } 57 }
59 } 58 }
60 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) 59 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
61 init_params->context = ash::Shell::GetPrimaryRootWindow(); 60 init_params->context = ash::Shell::GetPrimaryRootWindow();
62 else 61 else
63 init_params->native_widget = new views::DesktopNativeWidgetAura(widget); 62 init_params->native_widget = new views::DesktopNativeWidgetAura(widget);
64 } 63 }
65 64
66 void NativeAppWindowViewsWin::Show() { 65 void NativeAppWindowViewsWin::Show() {
67 ActivateParentDesktopIfNecessary(); 66 ActivateParentDesktopIfNecessary();
68 NativeAppWindowViews::Show(); 67 NativeAppWindowViews::Show();
69 } 68 }
70 69
71 void NativeAppWindowViewsWin::Activate() { 70 void NativeAppWindowViewsWin::Activate() {
72 ActivateParentDesktopIfNecessary(); 71 ActivateParentDesktopIfNecessary();
73 NativeAppWindowViews::Activate(); 72 NativeAppWindowViews::Activate();
74 } 73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698