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

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

Issue 171523005: BACKUP: NativeAppWindowView - before splitting CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/app_window_registry.h" 8 #include "apps/app_window_registry.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 !base::CreateDirectory(web_app_path)) { 56 !base::CreateDirectory(web_app_path)) {
57 return; 57 return;
58 } 58 }
59 59
60 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); 60 ui::win::SetAppIconForWindow(icon_file.value(), hwnd);
61 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); 61 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
62 } 62 }
63 63
64 } // namespace 64 } // namespace
65 65
66 NativeAppWindowViewsWin::NativeAppWindowViewsWin() 66 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin()
67 : weak_ptr_factory_(this) { 67 : weak_ptr_factory_(this) {
68 } 68 }
69 69
70 void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { 70 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
71 if (!ash::Shell::HasInstance()) 71 if (!ash::Shell::HasInstance())
72 return; 72 return;
73 73
74 views::Widget* widget = 74 views::Widget* widget =
75 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); 75 implicit_cast<views::WidgetDelegate*>(this)->GetWidget();
76 chrome::HostDesktopType host_desktop_type = 76 chrome::HostDesktopType host_desktop_type =
77 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); 77 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow());
78 // Only switching into Ash from Native is supported. Tearing the user out of 78 // Only switching into Ash from Native is supported. Tearing the user out of
79 // Metro mode can only be done by launching a process from Metro mode itself. 79 // Metro mode can only be done by launching a process from Metro mode itself.
80 // This is done for launching apps, but not regular activations. 80 // This is done for launching apps, but not regular activations.
81 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && 81 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH &&
82 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { 82 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
83 chrome::ActivateMetroChrome(); 83 chrome::ActivateMetroChrome();
84 } 84 }
85 } 85 }
86 86
87 void NativeAppWindowViewsWin::OnShortcutInfoLoaded( 87 void ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded(
88 const ShellIntegration::ShortcutInfo& shortcut_info) { 88 const ShellIntegration::ShortcutInfo& shortcut_info) {
89 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 89 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
90 90
91 HWND hwnd = GetNativeAppWindowHWND(); 91 HWND hwnd = GetNativeAppWindowHWND();
92 92
93 // Set window's icon to the one we're about to create/update in the web app 93 // Set window's icon to the one we're about to create/update in the web app
94 // path. The icon cache will refresh on icon creation. 94 // path. The icon cache will refresh on icon creation.
95 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( 95 base::FilePath web_app_path = web_app::GetWebAppDataDirectory(
96 shortcut_info.profile_path, shortcut_info.extension_id, 96 shortcut_info.profile_path, shortcut_info.extension_id,
97 shortcut_info.url); 97 shortcut_info.url);
98 base::FilePath icon_file = web_app_path 98 base::FilePath icon_file = web_app_path
99 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) 99 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title))
100 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); 100 .ReplaceExtension(FILE_PATH_LITERAL(".ico"));
101 101
102 content::BrowserThread::PostBlockingPoolTask( 102 content::BrowserThread::PostBlockingPoolTask(
103 FROM_HERE, 103 FROM_HERE,
104 base::Bind(&CreateIconAndSetRelaunchDetails, 104 base::Bind(&CreateIconAndSetRelaunchDetails,
105 web_app_path, icon_file, shortcut_info, hwnd)); 105 web_app_path, icon_file, shortcut_info, hwnd));
106 } 106 }
107 107
108 HWND NativeAppWindowViewsWin::GetNativeAppWindowHWND() const { 108 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const {
109 return views::HWNDForWidget(window()->GetTopLevelWidget()); 109 return views::HWNDForWidget(window()->GetTopLevelWidget());
110 } 110 }
111 111
112 void NativeAppWindowViewsWin::OnBeforeWidgetInit( 112 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit(
113 views::Widget::InitParams* init_params, views::Widget* widget) { 113 views::Widget::InitParams* init_params, views::Widget* widget) {
114 // If an app has any existing windows, ensure new ones are created on the 114 // If an app has any existing windows, ensure new ones are created on the
115 // same desktop. 115 // same desktop.
116 apps::AppWindow* any_existing_window = 116 apps::AppWindow* any_existing_window =
117 apps::AppWindowRegistry::Get(browser_context()) 117 apps::AppWindowRegistry::Get(browser_context())
118 ->GetCurrentAppWindowForApp(extension()->id()); 118 ->GetCurrentAppWindowForApp(extension()->id());
119 chrome::HostDesktopType desktop_type; 119 chrome::HostDesktopType desktop_type;
120 if (any_existing_window) { 120 if (any_existing_window) {
121 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( 121 desktop_type = chrome::GetHostDesktopTypeForNativeWindow(
122 any_existing_window->GetNativeWindow()); 122 any_existing_window->GetNativeWindow());
123 } else { 123 } else {
124 PerAppSettingsService* settings = 124 PerAppSettingsService* settings =
125 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context()); 125 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context());
126 if (settings->HasDesktopLastLaunchedFrom(extension()->id())) { 126 if (settings->HasDesktopLastLaunchedFrom(extension()->id())) {
127 desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id()); 127 desktop_type = settings->GetDesktopLastLaunchedFrom(extension()->id());
128 } else { 128 } else {
129 // We don't know what desktop this app was last launched from, so take our 129 // We don't know what desktop this app was last launched from, so take our
130 // best guess as to what desktop the user is on. 130 // best guess as to what desktop the user is on.
131 desktop_type = chrome::GetActiveDesktop(); 131 desktop_type = chrome::GetActiveDesktop();
132 } 132 }
133 } 133 }
134 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) 134 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
135 init_params->context = ash::Shell::GetPrimaryRootWindow(); 135 init_params->context = ash::Shell::GetPrimaryRootWindow();
136 else 136 else
137 init_params->native_widget = new views::DesktopNativeWidgetAura(widget); 137 init_params->native_widget = new views::DesktopNativeWidgetAura(widget);
138 } 138 }
139 139
140 void NativeAppWindowViewsWin::InitializeDefaultWindow( 140 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow(
141 const apps::AppWindow::CreateParams& create_params) { 141 const apps::AppWindow::CreateParams& create_params) {
142 NativeAppWindowViews::InitializeDefaultWindow(create_params); 142 NativeAppWindowViews::InitializeDefaultWindow(create_params);
143 143
144 std::string app_name = 144 std::string app_name =
145 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); 145 web_app::GenerateApplicationNameFromExtensionId(extension()->id());
146 base::string16 app_name_wide = base::UTF8ToWide(app_name); 146 base::string16 app_name_wide = base::UTF8ToWide(app_name);
147 HWND hwnd = GetNativeAppWindowHWND(); 147 HWND hwnd = GetNativeAppWindowHWND();
148 ui::win::SetAppIdForWindow( 148 ui::win::SetAppIdForWindow(
149 ShellIntegration::GetAppModelIdForProfile( 149 ShellIntegration::GetAppModelIdForProfile(
150 app_name_wide, 150 app_name_wide,
151 Profile::FromBrowserContext(browser_context())->GetPath()), 151 Profile::FromBrowserContext(browser_context())->GetPath()),
152 hwnd); 152 hwnd);
153 153
154 web_app::UpdateShortcutInfoAndIconForApp( 154 web_app::UpdateShortcutInfoAndIconForApp(
155 *extension(), 155 *extension(),
156 Profile::FromBrowserContext(browser_context()), 156 Profile::FromBrowserContext(browser_context()),
157 base::Bind(&NativeAppWindowViewsWin::OnShortcutInfoLoaded, 157 base::Bind(&NativeAppWindowViewsWin::OnShortcutInfoLoaded,
158 weak_ptr_factory_.GetWeakPtr())); 158 weak_ptr_factory_.GetWeakPtr()));
159 } 159 }
160 160
161 void NativeAppWindowViewsWin::Show() { 161 void ChromeNativeAppWindowViewsWin::Show() {
162 ActivateParentDesktopIfNecessary(); 162 ActivateParentDesktopIfNecessary();
163 NativeAppWindowViews::Show(); 163 NativeAppWindowViews::Show();
164 } 164 }
165 165
166 void NativeAppWindowViewsWin::Activate() { 166 void ChromeNativeAppWindowViewsWin::Activate() {
167 ActivateParentDesktopIfNecessary(); 167 ActivateParentDesktopIfNecessary();
168 NativeAppWindowViews::Activate(); 168 NativeAppWindowViews::Activate();
169 } 169 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/native_app_window_views_win.h ('k') | chrome/browser/ui/views/apps/shaped_app_window_targeter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698