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

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

Issue 258243002: Support "Pin to taskbar" for hosted app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test for XP Created 6 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/browser_window_property_manager_browsertest_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "apps/ui/views/app_window_frame_view.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 17 matching lines...) Expand all
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "extensions/browser/extension_util.h" 29 #include "extensions/browser/extension_util.h"
30 #include "extensions/common/extension.h" 30 #include "extensions/common/extension.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "ui/aura/remote_window_tree_host_win.h" 32 #include "ui/aura/remote_window_tree_host_win.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/win/shell.h" 34 #include "ui/base/win/shell.h"
35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
36 #include "ui/views/win/hwnd_util.h" 36 #include "ui/views/win/hwnd_util.h"
37 37
38 namespace {
39
40 void CreateIconAndSetRelaunchDetails(
41 const base::FilePath& web_app_path,
42 const base::FilePath& icon_file,
43 const web_app::ShortcutInfo& shortcut_info,
44 const HWND hwnd) {
45 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
46
47 // Set the relaunch data so "Pin this program to taskbar" has the app's
48 // information.
49 CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher(
50 shortcut_info.url,
51 shortcut_info.extension_id,
52 shortcut_info.profile_path);
53
54 base::FilePath chrome_exe;
55 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
56 NOTREACHED();
57 return;
58 }
59 command_line.SetProgram(chrome_exe);
60 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(),
61 shortcut_info.title, hwnd);
62
63 if (!base::PathExists(web_app_path) &&
64 !base::CreateDirectory(web_app_path)) {
65 return;
66 }
67
68 ui::win::SetAppIconForWindow(icon_file.value(), hwnd);
69 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon);
70 }
71
72 } // namespace
73
74 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() 38 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin()
75 : weak_ptr_factory_(this), glass_frame_view_(NULL) { 39 : weak_ptr_factory_(this), glass_frame_view_(NULL) {
76 } 40 }
77 41
78 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { 42 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
79 if (!ash::Shell::HasInstance()) 43 if (!ash::Shell::HasInstance())
80 return; 44 return;
81 45
82 views::Widget* widget = 46 views::Widget* widget =
83 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); 47 implicit_cast<views::WidgetDelegate*>(this)->GetWidget();
84 chrome::HostDesktopType host_desktop_type = 48 chrome::HostDesktopType host_desktop_type =
85 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); 49 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow());
86 // Only switching into Ash from Native is supported. Tearing the user out of 50 // Only switching into Ash from Native is supported. Tearing the user out of
87 // Metro mode can only be done by launching a process from Metro mode itself. 51 // Metro mode can only be done by launching a process from Metro mode itself.
88 // This is done for launching apps, but not regular activations. 52 // This is done for launching apps, but not regular activations.
89 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && 53 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH &&
90 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { 54 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
91 chrome::ActivateMetroChrome(); 55 chrome::ActivateMetroChrome();
92 } 56 }
93 } 57 }
94 58
95 void ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded(
96 const web_app::ShortcutInfo& shortcut_info) {
97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
98
99 HWND hwnd = GetNativeAppWindowHWND();
100
101 // Set window's icon to the one we're about to create/update in the web app
102 // path. The icon cache will refresh on icon creation.
103 base::FilePath web_app_path = web_app::GetWebAppDataDirectory(
104 shortcut_info.profile_path, shortcut_info.extension_id,
105 shortcut_info.url);
106 base::FilePath icon_file = web_app_path
107 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title))
108 .ReplaceExtension(FILE_PATH_LITERAL(".ico"));
109
110 content::BrowserThread::PostBlockingPoolTask(
111 FROM_HERE,
112 base::Bind(&CreateIconAndSetRelaunchDetails,
113 web_app_path, icon_file, shortcut_info, hwnd));
114 }
115
116 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { 59 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const {
117 return views::HWNDForWidget(widget()->GetTopLevelWidget()); 60 return views::HWNDForWidget(widget()->GetTopLevelWidget());
118 } 61 }
119 62
120 void ChromeNativeAppWindowViewsWin::EnsureCaptionStyleSet() { 63 void ChromeNativeAppWindowViewsWin::EnsureCaptionStyleSet() {
121 // Windows seems to have issues maximizing windows without WS_CAPTION. 64 // Windows seems to have issues maximizing windows without WS_CAPTION.
122 // The default views / Aura implementation will remove this if we are using 65 // The default views / Aura implementation will remove this if we are using
123 // frameless or colored windows, so we put it back here. 66 // frameless or colored windows, so we put it back here.
124 HWND hwnd = GetNativeAppWindowHWND(); 67 HWND hwnd = GetNativeAppWindowHWND();
125 int current_style = ::GetWindowLong(hwnd, GWL_STYLE); 68 int current_style = ::GetWindowLong(hwnd, GWL_STYLE);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 web_app::GenerateApplicationNameFromExtensionId(extension->id()); 112 web_app::GenerateApplicationNameFromExtensionId(extension->id());
170 base::string16 app_name_wide = base::UTF8ToWide(app_name); 113 base::string16 app_name_wide = base::UTF8ToWide(app_name);
171 HWND hwnd = GetNativeAppWindowHWND(); 114 HWND hwnd = GetNativeAppWindowHWND();
172 Profile* profile = 115 Profile* profile =
173 Profile::FromBrowserContext(app_window()->browser_context()); 116 Profile::FromBrowserContext(app_window()->browser_context());
174 app_model_id_ = 117 app_model_id_ =
175 ShellIntegration::GetAppModelIdForProfile(app_name_wide, 118 ShellIntegration::GetAppModelIdForProfile(app_name_wide,
176 profile->GetPath()); 119 profile->GetPath());
177 ui::win::SetAppIdForWindow(app_model_id_, hwnd); 120 ui::win::SetAppIdForWindow(app_model_id_, hwnd);
178 121
179 web_app::UpdateShortcutInfoAndIconForApp( 122 web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd);
180 extension,
181 profile,
182 base::Bind(&ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded,
183 weak_ptr_factory_.GetWeakPtr()));
184 123
185 if (!create_params.transparent_background) 124 if (!create_params.transparent_background)
186 EnsureCaptionStyleSet(); 125 EnsureCaptionStyleSet();
187 UpdateShelfMenu(); 126 UpdateShelfMenu();
188 } 127 }
189 128
190 views::NonClientFrameView* 129 views::NonClientFrameView*
191 ChromeNativeAppWindowViewsWin::CreateStandardDesktopAppFrame() { 130 ChromeNativeAppWindowViewsWin::CreateStandardDesktopAppFrame() {
192 glass_frame_view_ = NULL; 131 glass_frame_view_ = NULL;
193 if (ui::win::IsAeroGlassEnabled()) { 132 if (ui::win::IsAeroGlassEnabled()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 extension->id()); 183 extension->id());
245 184
246 ShellLinkItemList items; 185 ShellLinkItemList items;
247 items.push_back(link); 186 items.push_back(link);
248 jumplist_updater.AddTasks(items); 187 jumplist_updater.AddTasks(items);
249 } 188 }
250 189
251 // Note that an empty jumplist must still be committed to clear all items. 190 // Note that an empty jumplist must still be committed to clear all items.
252 jumplist_updater.CommitUpdate(); 191 jumplist_updater.CommitUpdate();
253 } 192 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/browser_window_property_manager_browsertest_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698