OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chrome_native_app_window_views_win.h" | 5 #include "chrome/browser/ui/views/apps/chrome_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 "apps/ui/views/app_window_frame_view.h" | |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
15 #include "chrome/browser/apps/per_app_settings_service.h" | 16 #include "chrome/browser/apps/per_app_settings_service.h" |
16 #include "chrome/browser/apps/per_app_settings_service_factory.h" | 17 #include "chrome/browser/apps/per_app_settings_service_factory.h" |
17 #include "chrome/browser/jumplist_updater_win.h" | 18 #include "chrome/browser/jumplist_updater_win.h" |
18 #include "chrome/browser/metro_utils/metro_chrome_win.h" | 19 #include "chrome/browser/metro_utils/metro_chrome_win.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/shell_integration.h" | 21 #include "chrome/browser/shell_integration.h" |
22 #include "chrome/browser/ui/views/apps/app_window_desktop_native_widget_aura_win .h" | |
23 #include "chrome/browser/ui/views/apps/glass_app_window_frame_view.h" | |
21 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 24 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
22 #include "chrome/browser/web_applications/web_app.h" | 25 #include "chrome/browser/web_applications/web_app.h" |
23 #include "chrome/browser/web_applications/web_app_win.h" | 26 #include "chrome/browser/web_applications/web_app_win.h" |
24 #include "chrome/common/chrome_icon_resources_win.h" | 27 #include "chrome/common/chrome_icon_resources_win.h" |
25 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
26 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
27 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
28 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
29 #include "ui/aura/remote_window_tree_host_win.h" | 32 #include "ui/aura/remote_window_tree_host_win.h" |
30 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/win/shell.h" | 34 #include "ui/base/win/shell.h" |
32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
33 #include "ui/views/win/hwnd_util.h" | 36 #include "ui/views/win/hwnd_util.h" |
37 #include "ui/wm/core/easy_resize_window_targeter.h" | |
38 | |
39 #if defined(USE_ASH) | |
40 #include "chrome/browser/ui/ash/ash_util.h" | |
41 #endif | |
34 | 42 |
35 namespace { | 43 namespace { |
36 | 44 |
37 void CreateIconAndSetRelaunchDetails( | 45 void CreateIconAndSetRelaunchDetails( |
38 const base::FilePath& web_app_path, | 46 const base::FilePath& web_app_path, |
39 const base::FilePath& icon_file, | 47 const base::FilePath& icon_file, |
40 const ShellIntegration::ShortcutInfo& shortcut_info, | 48 const ShellIntegration::ShortcutInfo& shortcut_info, |
41 const HWND hwnd) { | 49 const HWND hwnd) { |
42 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 50 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
43 | 51 |
(...skipping 18 matching lines...) Expand all Loading... | |
62 return; | 70 return; |
63 } | 71 } |
64 | 72 |
65 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | 73 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
66 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 74 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
67 } | 75 } |
68 | 76 |
69 } // namespace | 77 } // namespace |
70 | 78 |
71 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() | 79 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() |
72 : weak_ptr_factory_(this) {} | 80 : weak_ptr_factory_(this), glass_frame_view_(NULL) {} |
73 | 81 |
74 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { | 82 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
75 if (!ash::Shell::HasInstance()) | 83 if (!ash::Shell::HasInstance()) |
76 return; | 84 return; |
77 | 85 |
78 views::Widget* widget = | 86 views::Widget* widget = |
79 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); | 87 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); |
80 chrome::HostDesktopType host_desktop_type = | 88 chrome::HostDesktopType host_desktop_type = |
81 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); | 89 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); |
82 // Only switching into Ash from Native is supported. Tearing the user out of | 90 // Only switching into Ash from Native is supported. Tearing the user out of |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 desktop_type = settings->GetDesktopLastLaunchedFrom(extension->id()); | 142 desktop_type = settings->GetDesktopLastLaunchedFrom(extension->id()); |
135 } else { | 143 } else { |
136 // We don't know what desktop this app was last launched from, so take our | 144 // We don't know what desktop this app was last launched from, so take our |
137 // best guess as to what desktop the user is on. | 145 // best guess as to what desktop the user is on. |
138 desktop_type = chrome::GetActiveDesktop(); | 146 desktop_type = chrome::GetActiveDesktop(); |
139 } | 147 } |
140 } | 148 } |
141 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) | 149 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) |
142 init_params->context = ash::Shell::GetPrimaryRootWindow(); | 150 init_params->context = ash::Shell::GetPrimaryRootWindow(); |
143 else | 151 else |
144 init_params->native_widget = new views::DesktopNativeWidgetAura(widget); | 152 init_params->native_widget = new AppWindowDesktopNativeWidgetAuraWin(this); |
145 } | 153 } |
146 | 154 |
147 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( | 155 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( |
148 const apps::AppWindow::CreateParams& create_params) { | 156 const apps::AppWindow::CreateParams& create_params) { |
149 ChromeNativeAppWindowViews::InitializeDefaultWindow(create_params); | 157 ChromeNativeAppWindowViews::InitializeDefaultWindow(create_params); |
150 | 158 |
151 const extensions::Extension* extension = app_window()->extension(); | 159 const extensions::Extension* extension = app_window()->extension(); |
152 std::string app_name = | 160 std::string app_name = |
153 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 161 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
154 base::string16 app_name_wide = base::UTF8ToWide(app_name); | 162 base::string16 app_name_wide = base::UTF8ToWide(app_name); |
155 HWND hwnd = GetNativeAppWindowHWND(); | 163 HWND hwnd = GetNativeAppWindowHWND(); |
156 Profile* profile = | 164 Profile* profile = |
157 Profile::FromBrowserContext(app_window()->browser_context()); | 165 Profile::FromBrowserContext(app_window()->browser_context()); |
158 app_model_id_ = | 166 app_model_id_ = |
159 ShellIntegration::GetAppModelIdForProfile(app_name_wide, | 167 ShellIntegration::GetAppModelIdForProfile(app_name_wide, |
160 profile->GetPath()); | 168 profile->GetPath()); |
161 ui::win::SetAppIdForWindow(app_model_id_, hwnd); | 169 ui::win::SetAppIdForWindow(app_model_id_, hwnd); |
162 | 170 |
163 web_app::UpdateShortcutInfoAndIconForApp( | 171 web_app::UpdateShortcutInfoAndIconForApp( |
164 extension, | 172 extension, |
165 profile, | 173 profile, |
166 base::Bind(&ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded, | 174 base::Bind(&ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded, |
167 weak_ptr_factory_.GetWeakPtr())); | 175 weak_ptr_factory_.GetWeakPtr())); |
168 | 176 |
169 UpdateShelfMenu(); | 177 UpdateShelfMenu(); |
170 } | 178 } |
171 | 179 |
180 views::NonClientFrameView* | |
181 ChromeNativeAppWindowViewsWin::CreateStandardAppWindowFrame() { | |
182 glass_frame_view_ = NULL; | |
183 if (ui::win::IsAeroGlassEnabled()) { | |
tapted
2014/04/03 19:40:24
Does this need an IsNativeWindowInAsh check as wel
benwells
2014/04/04 06:50:43
This doesn't get called in that case. See ChromeNa
| |
184 glass_frame_view_ = new apps::GlassAppWindowFrameView(this, widget()); | |
185 return glass_frame_view_; | |
186 } | |
187 return ChromeNativeAppWindowViews::CreateStandardAppWindowFrame(); | |
188 } | |
189 | |
190 apps::AppWindowFrameView* | |
191 ChromeNativeAppWindowViewsWin::CreateNonStandardAppWindowFrame() { | |
192 apps::AppWindowFrameView* frame = | |
193 ChromeNativeAppWindowViews::CreateNonStandardAppWindowFrame(); | |
194 | |
195 if (!chrome::IsNativeWindowInAsh(widget()->GetNativeWindow())) { | |
196 aura::Window* root_window = widget()->GetNativeWindow()->GetRootWindow(); | |
197 int resize_inside = frame->resize_inside_bounds_size(); | |
198 gfx::Insets inset( | |
199 resize_inside, resize_inside, resize_inside, resize_inside); | |
200 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
201 new wm::EasyResizeWindowTargeter(root_window, inset, inset))); | |
202 } | |
203 | |
204 return frame; | |
205 } | |
206 | |
172 void ChromeNativeAppWindowViewsWin::Show() { | 207 void ChromeNativeAppWindowViewsWin::Show() { |
173 ActivateParentDesktopIfNecessary(); | 208 ActivateParentDesktopIfNecessary(); |
174 ChromeNativeAppWindowViews::Show(); | 209 ChromeNativeAppWindowViews::Show(); |
175 } | 210 } |
176 | 211 |
177 void ChromeNativeAppWindowViewsWin::Activate() { | 212 void ChromeNativeAppWindowViewsWin::Activate() { |
178 ActivateParentDesktopIfNecessary(); | 213 ActivateParentDesktopIfNecessary(); |
179 ChromeNativeAppWindowViews::Activate(); | 214 ChromeNativeAppWindowViews::Activate(); |
180 } | 215 } |
181 | 216 |
(...skipping 30 matching lines...) Expand all Loading... | |
212 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, | 247 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, |
213 extension->id()); | 248 extension->id()); |
214 | 249 |
215 ShellLinkItemList items; | 250 ShellLinkItemList items; |
216 items.push_back(link); | 251 items.push_back(link); |
217 jumplist_updater.AddTasks(items); | 252 jumplist_updater.AddTasks(items); |
218 } | 253 } |
219 | 254 |
220 jumplist_updater.CommitUpdate(); | 255 jumplist_updater.CommitUpdate(); |
221 } | 256 } |
OLD | NEW |