| 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" | |
| 12 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/app_mode/app_mode_utils.h" | 12 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 15 #include "chrome/browser/chrome_page_zoom.h" | 13 #include "chrome/browser/chrome_page_zoom.h" |
| 16 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 17 #include "chrome/browser/favicon/favicon_tab_helper.h" | 15 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | 17 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" |
| 20 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
| 21 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | 19 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
| 22 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 23 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | 21 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" |
| 24 #include "chrome/browser/web_applications/web_app.h" | 22 #include "chrome/browser/web_applications/web_app.h" |
| 25 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 26 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
| 29 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 30 #include "content/public/browser/web_contents_view.h" | 28 #include "content/public/browser/web_contents_view.h" |
| 31 #include "extensions/common/draggable_region.h" | 29 #include "extensions/common/draggable_region.h" |
| 32 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 33 #include "ui/base/hit_test.h" | 31 #include "ui/base/hit_test.h" |
| 34 #include "ui/base/models/simple_menu_model.h" | 32 #include "ui/base/models/simple_menu_model.h" |
| 35 #include "ui/views/controls/menu/menu_runner.h" | 33 #include "ui/views/controls/menu/menu_runner.h" |
| 36 #include "ui/views/controls/webview/webview.h" | 34 #include "ui/views/controls/webview/webview.h" |
| 37 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 38 #include "ui/views/window/non_client_view.h" | 36 #include "ui/views/window/non_client_view.h" |
| 39 | 37 |
| 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 | |
| 48 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
| 49 #include "chrome/browser/shell_integration_linux.h" | 39 #include "chrome/browser/shell_integration_linux.h" |
| 50 #endif | 40 #endif |
| 51 | 41 |
| 52 #if defined(USE_ASH) | 42 #if defined(USE_ASH) |
| 53 #include "ash/ash_constants.h" | 43 #include "ash/ash_constants.h" |
| 54 #include "ash/ash_switches.h" | 44 #include "ash/ash_switches.h" |
| 55 #include "ash/screen_util.h" | 45 #include "ash/screen_util.h" |
| 56 #include "ash/shell.h" | 46 #include "ash/shell.h" |
| 57 #include "ash/wm/custom_frame_view_ash.h" | 47 #include "ash/wm/custom_frame_view_ash.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (chrome::IsRunningInForcedAppMode()) { | 122 if (chrome::IsRunningInForcedAppMode()) { |
| 133 AddAcceleratorsFromMapping( | 123 AddAcceleratorsFromMapping( |
| 134 kAppWindowKioskAppModeAcceleratorMap, | 124 kAppWindowKioskAppModeAcceleratorMap, |
| 135 arraysize(kAppWindowKioskAppModeAcceleratorMap), | 125 arraysize(kAppWindowKioskAppModeAcceleratorMap), |
| 136 &accelerators); | 126 &accelerators); |
| 137 } | 127 } |
| 138 } | 128 } |
| 139 return accelerators; | 129 return accelerators; |
| 140 } | 130 } |
| 141 | 131 |
| 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 | |
| 175 #if defined(USE_ASH) | 132 #if defined(USE_ASH) |
| 176 // This class handles a user's fullscreen request (Shift+F4/F4). | 133 // This class handles a user's fullscreen request (Shift+F4/F4). |
| 177 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, | 134 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, |
| 178 public ash::wm::WindowStateObserver, | 135 public ash::wm::WindowStateObserver, |
| 179 public aura::WindowObserver { | 136 public aura::WindowObserver { |
| 180 public: | 137 public: |
| 181 NativeAppWindowStateDelegate(ShellWindow* shell_window, | 138 NativeAppWindowStateDelegate(ShellWindow* shell_window, |
| 182 apps::NativeAppWindow* native_app_window) | 139 apps::NativeAppWindow* native_app_window) |
| 183 : shell_window_(shell_window), | 140 : shell_window_(shell_window), |
| 184 window_state_( | 141 window_state_( |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 307 |
| 351 for (std::map<ui::Accelerator, int>::const_iterator iter = | 308 for (std::map<ui::Accelerator, int>::const_iterator iter = |
| 352 accelerator_table.begin(); | 309 accelerator_table.begin(); |
| 353 iter != accelerator_table.end(); ++iter) { | 310 iter != accelerator_table.end(); ++iter) { |
| 354 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | 311 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) |
| 355 continue; | 312 continue; |
| 356 | 313 |
| 357 focus_manager->RegisterAccelerator( | 314 focus_manager->RegisterAccelerator( |
| 358 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 315 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
| 359 } | 316 } |
| 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 | |
| 376 } | 317 } |
| 377 | 318 |
| 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 | |
| 405 void NativeAppWindowViews::InitializePanelWindow( | 319 void NativeAppWindowViews::InitializePanelWindow( |
| 406 const ShellWindow::CreateParams& create_params) { | 320 const ShellWindow::CreateParams& create_params) { |
| 407 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | 321 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); |
| 408 params.delegate = this; | 322 params.delegate = this; |
| 409 | 323 |
| 410 preferred_size_ = gfx::Size(create_params.bounds.width(), | 324 preferred_size_ = gfx::Size(create_params.bounds.width(), |
| 411 create_params.bounds.height()); | 325 create_params.bounds.height()); |
| 412 if (preferred_size_.width() == 0) | 326 if (preferred_size_.width() == 0) |
| 413 preferred_size_.set_width(kDefaultPanelWidth); | 327 preferred_size_.set_width(kDefaultPanelWidth); |
| 414 else if (preferred_size_.width() < kMinPanelWidth) | 328 else if (preferred_size_.width() < kMinPanelWidth) |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 969 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 1056 gfx::Rect window_bounds = | 970 gfx::Rect window_bounds = |
| 1057 window_->non_client_view()->GetWindowBoundsForClientBounds( | 971 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 1058 client_bounds); | 972 client_bounds); |
| 1059 return window_bounds.InsetsFrom(client_bounds); | 973 return window_bounds.InsetsFrom(client_bounds); |
| 1060 } | 974 } |
| 1061 | 975 |
| 1062 void NativeAppWindowViews::HideWithApp() {} | 976 void NativeAppWindowViews::HideWithApp() {} |
| 1063 void NativeAppWindowViews::ShowWithApp() {} | 977 void NativeAppWindowViews::ShowWithApp() {} |
| 1064 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 978 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |