OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/native_widget_factory.h" | 5 #include "chrome/browser/ui/views/native_widget_factory.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/views/theme_profile_key.h" |
8 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
9 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 10 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
10 #include "ui/views/widget/native_widget_aura.h" | 11 #include "ui/views/widget/native_widget_aura.h" |
11 | 12 |
12 views::NativeWidget* CreateNativeWidget( | 13 views::NativeWidget* CreateNativeWidget( |
13 NativeWidgetType type, | 14 NativeWidgetType type, |
14 views::Widget::InitParams* params, | 15 views::Widget::InitParams* params, |
15 views::internal::NativeWidgetDelegate* delegate) { | 16 views::internal::NativeWidgetDelegate* delegate) { |
16 // While the majority of the time, context wasn't plumbed through due to the | 17 // While the majority of the time, context wasn't plumbed through due to the |
17 // existence of a global WindowParentingClient, if this window is toplevel, | 18 // existence of a global WindowParentingClient, if this window is toplevel, |
18 // it's possible that there is no contextual state that we can use. | 19 // it's possible that there is no contextual state that we can use. |
19 gfx::NativeWindow parent_or_context = | 20 gfx::NativeWindow parent_or_context = |
20 params->parent ? params->parent : params->context; | 21 params->parent ? params->parent : params->context; |
21 // Set the profile key based on the profile of |parent_or_context| | |
22 // so that the widget will be styled with the apropriate | |
23 // NativeTheme. For browser windows, BrowserView will reset the | |
24 // profile key to profile of the corresponding Browser. | |
25 Profile* profile = nullptr; | 22 Profile* profile = nullptr; |
26 if (parent_or_context) { | 23 if (parent_or_context) |
27 profile = reinterpret_cast<Profile*>( | 24 profile = GetThemeProfileForWindow(parent_or_context); |
28 parent_or_context->GetNativeWindowProperty(Profile::kProfileKey)); | 25 views::NativeWidget* native_widget = nullptr; |
| 26 aura::Window* window = nullptr; |
| 27 if (type == NativeWidgetType::DESKTOP_NATIVE_WIDGET_AURA || |
| 28 (!params->parent && !params->context && !params->child)) { |
| 29 // In the desktop case, do not always set the profile window |
| 30 // property from the parent since there are windows (like the task |
| 31 // manager) that are not associated with a specific profile. |
| 32 views::DesktopNativeWidgetAura* desktop_native_widget = |
| 33 new views::DesktopNativeWidgetAura(delegate); |
| 34 window = desktop_native_widget->GetNativeWindow(); |
| 35 native_widget = desktop_native_widget; |
| 36 } else { |
| 37 views::NativeWidgetAura* native_widget_aura = |
| 38 new views::NativeWidgetAura(delegate); |
| 39 if (params->parent) { |
| 40 Profile* parent_profile = reinterpret_cast<Profile*>( |
| 41 params->parent->GetNativeWindowProperty(Profile::kProfileKey)); |
| 42 native_widget_aura->SetNativeWindowProperty(Profile::kProfileKey, |
| 43 parent_profile); |
| 44 } |
| 45 window = native_widget_aura->GetNativeWindow(); |
| 46 native_widget = native_widget_aura; |
29 } | 47 } |
30 // Use the original profile because |window| may outlive the profile | 48 // Use the original profile because |window| may outlive the profile |
31 // of the context window. This can happen with incognito profiles. | 49 // of the context window. This can happen with incognito profiles. |
32 // However, the original profile will stick around until shutdown. | 50 // However, the original profile will stick around until shutdown. |
33 if (profile) | 51 SetThemeProfileForWindow(window, |
34 profile = profile->GetOriginalProfile(); | 52 profile ? profile->GetOriginalProfile() : nullptr); |
35 if (type == NativeWidgetType::DESKTOP_NATIVE_WIDGET_AURA || | 53 return native_widget; |
36 (!params->parent && !params->context && !params->child)) { | |
37 views::DesktopNativeWidgetAura* desktop_native_widget = | |
38 new views::DesktopNativeWidgetAura(delegate); | |
39 desktop_native_widget->SetNativeWindowProperty(Profile::kProfileKey, | |
40 profile); | |
41 return desktop_native_widget; | |
42 } | |
43 views::NativeWidgetAura* native_widget_aura = | |
44 new views::NativeWidgetAura(delegate); | |
45 native_widget_aura->SetNativeWindowProperty(Profile::kProfileKey, profile); | |
46 return native_widget_aura; | |
47 } | 54 } |
OLD | NEW |