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

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

Issue 158643002: Add option to install an ephemeral app to the Windows jump list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added notimplemented 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
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.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/extensions/extension_host.h" 12 #include "chrome/browser/extensions/extension_host.h"
15 #include "chrome/browser/favicon/favicon_tab_helper.h" 13 #include "chrome/browser/favicon/favicon_tab_helper.h"
16 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" 15 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
18 #include "chrome/browser/ui/host_desktop.h" 16 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" 17 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h"
20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 18 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
21 #include "chrome/browser/web_applications/web_app.h" 19 #include "chrome/browser/web_applications/web_app.h"
22 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
23 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 23 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
28 #include "extensions/common/draggable_region.h" 26 #include "extensions/common/draggable_region.h"
29 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
30 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
31 #include "ui/base/models/simple_menu_model.h" 29 #include "ui/base/models/simple_menu_model.h"
32 #include "ui/views/controls/menu/menu_runner.h" 30 #include "ui/views/controls/menu/menu_runner.h"
33 #include "ui/views/controls/webview/webview.h" 31 #include "ui/views/controls/webview/webview.h"
34 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
35 #include "ui/views/window/non_client_view.h" 33 #include "ui/views/window/non_client_view.h"
36 34
37 #if defined(OS_WIN)
38 #include "base/strings/utf_string_conversions.h"
39 #include "chrome/browser/ui/web_applications/web_app_ui.h"
40 #include "chrome/browser/web_applications/web_app_win.h"
41 #include "ui/base/win/shell.h"
42 #include "ui/views/win/hwnd_util.h"
43 #endif
44
45 #if defined(OS_LINUX) 35 #if defined(OS_LINUX)
46 #include "chrome/browser/shell_integration_linux.h" 36 #include "chrome/browser/shell_integration_linux.h"
47 #endif 37 #endif
48 38
49 #if defined(USE_ASH) 39 #if defined(USE_ASH)
50 #include "ash/ash_constants.h" 40 #include "ash/ash_constants.h"
51 #include "ash/ash_switches.h" 41 #include "ash/ash_switches.h"
52 #include "ash/screen_util.h" 42 #include "ash/screen_util.h"
53 #include "ash/shell.h" 43 #include "ash/shell.h"
54 #include "ash/wm/custom_frame_view_ash.h" 44 #include "ash/wm/custom_frame_view_ash.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (accelerators.empty()) { 86 if (accelerators.empty()) {
97 for (size_t i = 0; i < arraysize(kAppWindowAcceleratorMap); ++i) { 87 for (size_t i = 0; i < arraysize(kAppWindowAcceleratorMap); ++i) {
98 ui::Accelerator accelerator(kAppWindowAcceleratorMap[i].keycode, 88 ui::Accelerator accelerator(kAppWindowAcceleratorMap[i].keycode,
99 kAppWindowAcceleratorMap[i].modifiers); 89 kAppWindowAcceleratorMap[i].modifiers);
100 accelerators[accelerator] = kAppWindowAcceleratorMap[i].command_id; 90 accelerators[accelerator] = kAppWindowAcceleratorMap[i].command_id;
101 } 91 }
102 } 92 }
103 return accelerators; 93 return accelerators;
104 } 94 }
105 95
106 #if defined(OS_WIN)
107 void CreateIconAndSetRelaunchDetails(
108 const base::FilePath web_app_path,
109 const base::FilePath icon_file,
110 const ShellIntegration::ShortcutInfo& shortcut_info,
111 const HWND hwnd) {
112 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
113
114 // Set the relaunch data so "Pin this program to taskbar" has the app's
115 // information.
116 CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher(
117 shortcut_info.url,
118 shortcut_info.extension_id,
119 shortcut_info.profile_path);
120
121 base::FilePath chrome_exe;
122 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
123 NOTREACHED();
124 return;
125 }
126 command_line.SetProgram(chrome_exe);
127 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(),
128 shortcut_info.title, hwnd);
129
130 if (!base::PathExists(web_app_path) &&
131 !base::CreateDirectory(web_app_path))
132 return;
133
134 ui::win::SetAppIconForWindow(icon_file.value(), hwnd);
135 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
136 }
137 #endif
138
139 #if defined(USE_ASH) 96 #if defined(USE_ASH)
140 // This class handles a user's fullscreen request (Shift+F4/F4). 97 // This class handles a user's fullscreen request (Shift+F4/F4).
141 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, 98 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate,
142 public ash::wm::WindowStateObserver, 99 public ash::wm::WindowStateObserver,
143 public aura::WindowObserver { 100 public aura::WindowObserver {
144 public: 101 public:
145 NativeAppWindowStateDelegate(ShellWindow* shell_window, 102 NativeAppWindowStateDelegate(ShellWindow* shell_window,
146 apps::NativeAppWindow* native_app_window) 103 apps::NativeAppWindow* native_app_window)
147 : shell_window_(shell_window), 104 : shell_window_(shell_window),
148 window_state_( 105 window_state_(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // TODO(jeremya/stevenjb): should these be registered for panels too? 257 // TODO(jeremya/stevenjb): should these be registered for panels too?
301 views::FocusManager* focus_manager = GetFocusManager(); 258 views::FocusManager* focus_manager = GetFocusManager();
302 const std::map<ui::Accelerator, int>& accelerator_table = 259 const std::map<ui::Accelerator, int>& accelerator_table =
303 GetAcceleratorTable(); 260 GetAcceleratorTable();
304 for (std::map<ui::Accelerator, int>::const_iterator iter = 261 for (std::map<ui::Accelerator, int>::const_iterator iter =
305 accelerator_table.begin(); 262 accelerator_table.begin();
306 iter != accelerator_table.end(); ++iter) { 263 iter != accelerator_table.end(); ++iter) {
307 focus_manager->RegisterAccelerator( 264 focus_manager->RegisterAccelerator(
308 iter->first, ui::AcceleratorManager::kNormalPriority, this); 265 iter->first, ui::AcceleratorManager::kNormalPriority, this);
309 } 266 }
310
311 #if defined(OS_WIN)
312 base::string16 app_name_wide = base::UTF8ToWide(app_name);
313 HWND hwnd = GetNativeAppWindowHWND();
314 ui::win::SetAppIdForWindow(ShellIntegration::GetAppModelIdForProfile(
315 app_name_wide, profile()->GetPath()), hwnd);
316
317 web_app::UpdateShortcutInfoAndIconForApp(
318 *extension(), profile(),
319 base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded,
320 weak_ptr_factory_.GetWeakPtr()));
321 #endif
322 } 267 }
323 268
324 #if defined(OS_WIN)
325 void NativeAppWindowViews::OnShortcutInfoLoaded(
326 const ShellIntegration::ShortcutInfo& shortcut_info) {
327 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
328
329 HWND hwnd = GetNativeAppWindowHWND();
330
331 // Set window's icon to the one we're about to create/update in the web app
332 // path. The icon cache will refresh on icon creation.
333 base::FilePath web_app_path = web_app::GetWebAppDataDirectory(
334 shortcut_info.profile_path, shortcut_info.extension_id,
335 shortcut_info.url);
336 base::FilePath icon_file = web_app_path
337 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title))
338 .ReplaceExtension(FILE_PATH_LITERAL(".ico"));
339
340 content::BrowserThread::PostBlockingPoolTask(
341 FROM_HERE,
342 base::Bind(&CreateIconAndSetRelaunchDetails,
343 web_app_path, icon_file, shortcut_info, hwnd));
344 }
345
346 HWND NativeAppWindowViews::GetNativeAppWindowHWND() const {
347 return views::HWNDForWidget(window_->GetTopLevelWidget());
348 }
349 #endif
350
351 void NativeAppWindowViews::InitializePanelWindow( 269 void NativeAppWindowViews::InitializePanelWindow(
352 const ShellWindow::CreateParams& create_params) { 270 const ShellWindow::CreateParams& create_params) {
353 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); 271 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL);
354 params.delegate = this; 272 params.delegate = this;
355 273
356 preferred_size_ = gfx::Size(create_params.bounds.width(), 274 preferred_size_ = gfx::Size(create_params.bounds.width(),
357 create_params.bounds.height()); 275 create_params.bounds.height());
358 if (preferred_size_.width() == 0) 276 if (preferred_size_.width() == 0)
359 preferred_size_.set_width(kDefaultPanelWidth); 277 preferred_size_.set_width(kDefaultPanelWidth);
360 else if (preferred_size_.width() < kMinPanelWidth) 278 else if (preferred_size_.width() < kMinPanelWidth)
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 gfx::Rect client_bounds = gfx::Rect(1000, 1000); 891 gfx::Rect client_bounds = gfx::Rect(1000, 1000);
974 gfx::Rect window_bounds = 892 gfx::Rect window_bounds =
975 window_->non_client_view()->GetWindowBoundsForClientBounds( 893 window_->non_client_view()->GetWindowBoundsForClientBounds(
976 client_bounds); 894 client_bounds);
977 return window_bounds.InsetsFrom(client_bounds); 895 return window_bounds.InsetsFrom(client_bounds);
978 } 896 }
979 897
980 void NativeAppWindowViews::HideWithApp() {} 898 void NativeAppWindowViews::HideWithApp() {}
981 void NativeAppWindowViews::ShowWithApp() {} 899 void NativeAppWindowViews::ShowWithApp() {}
982 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} 900 void NativeAppWindowViews::UpdateWindowMinMaxSize() {}
901 void NativeAppWindowViews::UpdateAppMenu() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698