OLD | NEW |
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.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
6 | 6 |
7 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
8 #include "apps/ui/views/shell_window_frame_view.h" | 8 #include "apps/ui/views/shell_window_frame_view.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
13 #include "chrome/browser/chrome_page_zoom.h" | 15 #include "chrome/browser/chrome_page_zoom.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 16 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/browser/favicon/favicon_tab_helper.h" | 17 #include "chrome/browser/favicon/favicon_tab_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | 19 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
18 #include "chrome/browser/ui/host_desktop.h" | 20 #include "chrome/browser/ui/host_desktop.h" |
19 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | 21 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 22 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
21 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 23 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
22 #include "chrome/browser/web_applications/web_app.h" | 24 #include "chrome/browser/web_applications/web_app.h" |
23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 28 #include "content/public/browser/render_widget_host_view.h" |
27 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
29 #include "extensions/common/draggable_region.h" | 31 #include "extensions/common/draggable_region.h" |
30 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
31 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
32 #include "ui/base/models/simple_menu_model.h" | 34 #include "ui/base/models/simple_menu_model.h" |
33 #include "ui/views/controls/menu/menu_runner.h" | 35 #include "ui/views/controls/menu/menu_runner.h" |
34 #include "ui/views/controls/webview/webview.h" | 36 #include "ui/views/controls/webview/webview.h" |
35 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
36 #include "ui/views/window/non_client_view.h" | 38 #include "ui/views/window/non_client_view.h" |
37 | 39 |
| 40 #if defined(OS_WIN) |
| 41 #include "base/strings/utf_string_conversions.h" |
| 42 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 43 #include "chrome/browser/web_applications/web_app_win.h" |
| 44 #include "ui/base/win/shell.h" |
| 45 #include "ui/views/win/hwnd_util.h" |
| 46 #endif |
| 47 |
38 #if defined(OS_LINUX) | 48 #if defined(OS_LINUX) |
39 #include "chrome/browser/shell_integration_linux.h" | 49 #include "chrome/browser/shell_integration_linux.h" |
40 #endif | 50 #endif |
41 | 51 |
42 #if defined(USE_ASH) | 52 #if defined(USE_ASH) |
43 #include "ash/ash_constants.h" | 53 #include "ash/ash_constants.h" |
44 #include "ash/ash_switches.h" | 54 #include "ash/ash_switches.h" |
45 #include "ash/screen_util.h" | 55 #include "ash/screen_util.h" |
46 #include "ash/shell.h" | 56 #include "ash/shell.h" |
47 #include "ash/wm/custom_frame_view_ash.h" | 57 #include "ash/wm/custom_frame_view_ash.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (chrome::IsRunningInForcedAppMode()) { | 132 if (chrome::IsRunningInForcedAppMode()) { |
123 AddAcceleratorsFromMapping( | 133 AddAcceleratorsFromMapping( |
124 kAppWindowKioskAppModeAcceleratorMap, | 134 kAppWindowKioskAppModeAcceleratorMap, |
125 arraysize(kAppWindowKioskAppModeAcceleratorMap), | 135 arraysize(kAppWindowKioskAppModeAcceleratorMap), |
126 &accelerators); | 136 &accelerators); |
127 } | 137 } |
128 } | 138 } |
129 return accelerators; | 139 return accelerators; |
130 } | 140 } |
131 | 141 |
| 142 #if defined(OS_WIN) |
| 143 void CreateIconAndSetRelaunchDetails( |
| 144 const base::FilePath web_app_path, |
| 145 const base::FilePath icon_file, |
| 146 const ShellIntegration::ShortcutInfo& shortcut_info, |
| 147 const HWND hwnd) { |
| 148 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 149 |
| 150 // Set the relaunch data so "Pin this program to taskbar" has the app's |
| 151 // information. |
| 152 CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher( |
| 153 shortcut_info.url, |
| 154 shortcut_info.extension_id, |
| 155 shortcut_info.profile_path); |
| 156 |
| 157 base::FilePath chrome_exe; |
| 158 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 159 NOTREACHED(); |
| 160 return; |
| 161 } |
| 162 command_line.SetProgram(chrome_exe); |
| 163 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), |
| 164 shortcut_info.title, hwnd); |
| 165 |
| 166 if (!base::PathExists(web_app_path) && |
| 167 !base::CreateDirectory(web_app_path)) |
| 168 return; |
| 169 |
| 170 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
| 171 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
| 172 } |
| 173 #endif |
| 174 |
132 #if defined(USE_ASH) | 175 #if defined(USE_ASH) |
133 // This class handles a user's fullscreen request (Shift+F4/F4). | 176 // This class handles a user's fullscreen request (Shift+F4/F4). |
134 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, | 177 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, |
135 public ash::wm::WindowStateObserver, | 178 public ash::wm::WindowStateObserver, |
136 public aura::WindowObserver { | 179 public aura::WindowObserver { |
137 public: | 180 public: |
138 NativeAppWindowStateDelegate(ShellWindow* shell_window, | 181 NativeAppWindowStateDelegate(ShellWindow* shell_window, |
139 apps::NativeAppWindow* native_app_window) | 182 apps::NativeAppWindow* native_app_window) |
140 : shell_window_(shell_window), | 183 : shell_window_(shell_window), |
141 window_state_( | 184 window_state_( |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 350 |
308 for (std::map<ui::Accelerator, int>::const_iterator iter = | 351 for (std::map<ui::Accelerator, int>::const_iterator iter = |
309 accelerator_table.begin(); | 352 accelerator_table.begin(); |
310 iter != accelerator_table.end(); ++iter) { | 353 iter != accelerator_table.end(); ++iter) { |
311 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | 354 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) |
312 continue; | 355 continue; |
313 | 356 |
314 focus_manager->RegisterAccelerator( | 357 focus_manager->RegisterAccelerator( |
315 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 358 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
316 } | 359 } |
| 360 |
| 361 #if defined(OS_WIN) |
| 362 base::string16 app_name_wide = base::UTF8ToWide(app_name); |
| 363 HWND hwnd = GetNativeAppWindowHWND(); |
| 364 ui::win::SetAppIdForWindow( |
| 365 ShellIntegration::GetAppModelIdForProfile( |
| 366 app_name_wide, |
| 367 Profile::FromBrowserContext(browser_context())->GetPath()), |
| 368 hwnd); |
| 369 |
| 370 web_app::UpdateShortcutInfoAndIconForApp( |
| 371 *extension(), |
| 372 Profile::FromBrowserContext(browser_context()), |
| 373 base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded, |
| 374 weak_ptr_factory_.GetWeakPtr())); |
| 375 #endif |
317 } | 376 } |
318 | 377 |
| 378 #if defined(OS_WIN) |
| 379 void NativeAppWindowViews::OnShortcutInfoLoaded( |
| 380 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 381 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 382 |
| 383 HWND hwnd = GetNativeAppWindowHWND(); |
| 384 |
| 385 // Set window's icon to the one we're about to create/update in the web app |
| 386 // path. The icon cache will refresh on icon creation. |
| 387 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( |
| 388 shortcut_info.profile_path, shortcut_info.extension_id, |
| 389 shortcut_info.url); |
| 390 base::FilePath icon_file = web_app_path |
| 391 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) |
| 392 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); |
| 393 |
| 394 content::BrowserThread::PostBlockingPoolTask( |
| 395 FROM_HERE, |
| 396 base::Bind(&CreateIconAndSetRelaunchDetails, |
| 397 web_app_path, icon_file, shortcut_info, hwnd)); |
| 398 } |
| 399 |
| 400 HWND NativeAppWindowViews::GetNativeAppWindowHWND() const { |
| 401 return views::HWNDForWidget(window_->GetTopLevelWidget()); |
| 402 } |
| 403 #endif |
| 404 |
319 void NativeAppWindowViews::InitializePanelWindow( | 405 void NativeAppWindowViews::InitializePanelWindow( |
320 const ShellWindow::CreateParams& create_params) { | 406 const ShellWindow::CreateParams& create_params) { |
321 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 407 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
322 params.delegate = this; | 408 params.delegate = this; |
323 | 409 |
324 preferred_size_ = gfx::Size(create_params.bounds.width(), | 410 preferred_size_ = gfx::Size(create_params.bounds.width(), |
325 create_params.bounds.height()); | 411 create_params.bounds.height()); |
326 if (preferred_size_.width() == 0) | 412 if (preferred_size_.width() == 0) |
327 preferred_size_.set_width(kDefaultPanelWidth); | 413 preferred_size_.set_width(kDefaultPanelWidth); |
328 else if (preferred_size_.width() < kMinPanelWidth) | 414 else if (preferred_size_.width() < kMinPanelWidth) |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 1055 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
970 gfx::Rect window_bounds = | 1056 gfx::Rect window_bounds = |
971 window_->non_client_view()->GetWindowBoundsForClientBounds( | 1057 window_->non_client_view()->GetWindowBoundsForClientBounds( |
972 client_bounds); | 1058 client_bounds); |
973 return window_bounds.InsetsFrom(client_bounds); | 1059 return window_bounds.InsetsFrom(client_bounds); |
974 } | 1060 } |
975 | 1061 |
976 void NativeAppWindowViews::HideWithApp() {} | 1062 void NativeAppWindowViews::HideWithApp() {} |
977 void NativeAppWindowViews::ShowWithApp() {} | 1063 void NativeAppWindowViews::ShowWithApp() {} |
978 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 1064 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
OLD | NEW |