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