Index: chrome/browser/ui/views/native_widget_factory.cc |
diff --git a/chrome/browser/ui/views/native_widget_factory.cc b/chrome/browser/ui/views/native_widget_factory.cc |
index b4ad4ae84ba0cb0241fca4acccdc4170cf2e5883..b72680b466e558c24b8b922c900b9d97c2119267 100644 |
--- a/chrome/browser/ui/views/native_widget_factory.cc |
+++ b/chrome/browser/ui/views/native_widget_factory.cc |
@@ -5,6 +5,7 @@ |
#include "chrome/browser/ui/views/native_widget_factory.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/views/theme_profile_key.h" |
#include "ui/aura/window.h" |
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
#include "ui/views/widget/native_widget_aura.h" |
@@ -18,30 +19,36 @@ views::NativeWidget* CreateNativeWidget( |
// it's possible that there is no contextual state that we can use. |
gfx::NativeWindow parent_or_context = |
params->parent ? params->parent : params->context; |
- // Set the profile key based on the profile of |parent_or_context| |
- // so that the widget will be styled with the apropriate |
- // NativeTheme. For browser windows, BrowserView will reset the |
- // profile key to profile of the corresponding Browser. |
Profile* profile = nullptr; |
- if (parent_or_context) { |
- profile = reinterpret_cast<Profile*>( |
- parent_or_context->GetNativeWindowProperty(Profile::kProfileKey)); |
- } |
- // Use the original profile because |window| may outlive the profile |
- // of the context window. This can happen with incognito profiles. |
- // However, the original profile will stick around until shutdown. |
- if (profile) |
- profile = profile->GetOriginalProfile(); |
+ if (parent_or_context) |
+ profile = GetThemeProfileForWindow(parent_or_context); |
+ views::NativeWidget* native_widget = nullptr; |
+ aura::Window* window = nullptr; |
if (type == NativeWidgetType::DESKTOP_NATIVE_WIDGET_AURA || |
(!params->parent && !params->context && !params->child)) { |
+ // In the desktop case, do not always set the profile window |
+ // property from the parent since there are windows (like the task |
+ // manager) that are not associated with a specific profile. |
views::DesktopNativeWidgetAura* desktop_native_widget = |
new views::DesktopNativeWidgetAura(delegate); |
- desktop_native_widget->SetNativeWindowProperty(Profile::kProfileKey, |
- profile); |
- return desktop_native_widget; |
+ window = desktop_native_widget->GetNativeWindow(); |
+ native_widget = desktop_native_widget; |
+ } else { |
+ views::NativeWidgetAura* native_widget_aura = |
+ new views::NativeWidgetAura(delegate); |
+ if (params->parent) { |
+ Profile* parent_profile = reinterpret_cast<Profile*>( |
+ params->parent->GetNativeWindowProperty(Profile::kProfileKey)); |
+ native_widget_aura->SetNativeWindowProperty(Profile::kProfileKey, |
+ parent_profile); |
+ } |
+ window = native_widget_aura->GetNativeWindow(); |
+ native_widget = native_widget_aura; |
} |
- views::NativeWidgetAura* native_widget_aura = |
- new views::NativeWidgetAura(delegate); |
- native_widget_aura->SetNativeWindowProperty(Profile::kProfileKey, profile); |
- return native_widget_aura; |
+ // Use the original profile because |window| may outlive the profile |
+ // of the context window. This can happen with incognito profiles. |
+ // However, the original profile will stick around until shutdown. |
+ SetThemeProfileForWindow(window, |
+ profile ? profile->GetOriginalProfile() : nullptr); |
+ return native_widget; |
} |