| 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 21 matching lines...) Expand all Loading... |
| 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 #include "ui/wm/core/easy_resize_window_targeter.h" | 36 #include "ui/wm/core/easy_resize_window_targeter.h" |
| 37 | 37 |
| 38 #if defined(USE_ASH) | 38 #if defined(USE_ASH) |
| 39 #include "chrome/browser/ui/ash/ash_util.h" | 39 #include "chrome/browser/ui/ash/ash_util.h" |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 namespace { | |
| 43 | |
| 44 void CreateIconAndSetRelaunchDetails( | |
| 45 const base::FilePath& web_app_path, | |
| 46 const base::FilePath& icon_file, | |
| 47 const ShellIntegration::ShortcutInfo& shortcut_info, | |
| 48 const HWND hwnd) { | |
| 49 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
| 50 | |
| 51 // Set the relaunch data so "Pin this program to taskbar" has the app's | |
| 52 // information. | |
| 53 CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher( | |
| 54 shortcut_info.url, | |
| 55 shortcut_info.extension_id, | |
| 56 shortcut_info.profile_path); | |
| 57 | |
| 58 base::FilePath chrome_exe; | |
| 59 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | |
| 60 NOTREACHED(); | |
| 61 return; | |
| 62 } | |
| 63 command_line.SetProgram(chrome_exe); | |
| 64 ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), | |
| 65 shortcut_info.title, hwnd); | |
| 66 | |
| 67 if (!base::PathExists(web_app_path) && | |
| 68 !base::CreateDirectory(web_app_path)) { | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | |
| 73 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | |
| 74 } | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() | 42 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() |
| 79 : weak_ptr_factory_(this), glass_frame_view_(NULL) {} | 43 : weak_ptr_factory_(this), glass_frame_view_(NULL) {} |
| 80 | 44 |
| 81 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { | 45 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| 82 if (!ash::Shell::HasInstance()) | 46 if (!ash::Shell::HasInstance()) |
| 83 return; | 47 return; |
| 84 | 48 |
| 85 views::Widget* widget = | 49 views::Widget* widget = |
| 86 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); | 50 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); |
| 87 chrome::HostDesktopType host_desktop_type = | 51 chrome::HostDesktopType host_desktop_type = |
| 88 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); | 52 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); |
| 89 // Only switching into Ash from Native is supported. Tearing the user out of | 53 // Only switching into Ash from Native is supported. Tearing the user out of |
| 90 // Metro mode can only be done by launching a process from Metro mode itself. | 54 // Metro mode can only be done by launching a process from Metro mode itself. |
| 91 // This is done for launching apps, but not regular activations. | 55 // This is done for launching apps, but not regular activations. |
| 92 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && | 56 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && |
| 93 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { | 57 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 94 chrome::ActivateMetroChrome(); | 58 chrome::ActivateMetroChrome(); |
| 95 } | 59 } |
| 96 } | 60 } |
| 97 | 61 |
| 98 void ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded( | |
| 99 const ShellIntegration::ShortcutInfo& shortcut_info) { | |
| 100 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 101 | |
| 102 HWND hwnd = GetNativeAppWindowHWND(); | |
| 103 | |
| 104 // Set window's icon to the one we're about to create/update in the web app | |
| 105 // path. The icon cache will refresh on icon creation. | |
| 106 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( | |
| 107 shortcut_info.profile_path, shortcut_info.extension_id, | |
| 108 shortcut_info.url); | |
| 109 base::FilePath icon_file = web_app_path | |
| 110 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) | |
| 111 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); | |
| 112 | |
| 113 content::BrowserThread::PostBlockingPoolTask( | |
| 114 FROM_HERE, | |
| 115 base::Bind(&CreateIconAndSetRelaunchDetails, | |
| 116 web_app_path, icon_file, shortcut_info, hwnd)); | |
| 117 } | |
| 118 | |
| 119 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { | 62 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { |
| 120 return views::HWNDForWidget(widget()->GetTopLevelWidget()); | 63 return views::HWNDForWidget(widget()->GetTopLevelWidget()); |
| 121 } | 64 } |
| 122 | 65 |
| 123 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( | 66 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( |
| 124 views::Widget::InitParams* init_params, | 67 views::Widget::InitParams* init_params, |
| 125 views::Widget* widget) { | 68 views::Widget* widget) { |
| 126 content::BrowserContext* browser_context = app_window()->browser_context(); | 69 content::BrowserContext* browser_context = app_window()->browser_context(); |
| 127 const extensions::Extension* extension = app_window()->extension(); | 70 const extensions::Extension* extension = app_window()->extension(); |
| 128 // If an app has any existing windows, ensure new ones are created on the | 71 // If an app has any existing windows, ensure new ones are created on the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 103 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 161 base::string16 app_name_wide = base::UTF8ToWide(app_name); | 104 base::string16 app_name_wide = base::UTF8ToWide(app_name); |
| 162 HWND hwnd = GetNativeAppWindowHWND(); | 105 HWND hwnd = GetNativeAppWindowHWND(); |
| 163 Profile* profile = | 106 Profile* profile = |
| 164 Profile::FromBrowserContext(app_window()->browser_context()); | 107 Profile::FromBrowserContext(app_window()->browser_context()); |
| 165 app_model_id_ = | 108 app_model_id_ = |
| 166 ShellIntegration::GetAppModelIdForProfile(app_name_wide, | 109 ShellIntegration::GetAppModelIdForProfile(app_name_wide, |
| 167 profile->GetPath()); | 110 profile->GetPath()); |
| 168 ui::win::SetAppIdForWindow(app_model_id_, hwnd); | 111 ui::win::SetAppIdForWindow(app_model_id_, hwnd); |
| 169 | 112 |
| 170 web_app::UpdateShortcutInfoAndIconForApp( | 113 web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd); |
| 171 extension, | |
| 172 profile, | |
| 173 base::Bind(&ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded, | |
| 174 weak_ptr_factory_.GetWeakPtr())); | |
| 175 | 114 |
| 176 UpdateShelfMenu(); | 115 UpdateShelfMenu(); |
| 177 } | 116 } |
| 178 | 117 |
| 179 views::NonClientFrameView* | 118 views::NonClientFrameView* |
| 180 ChromeNativeAppWindowViewsWin::CreateStandardDesktopAppFrame() { | 119 ChromeNativeAppWindowViewsWin::CreateStandardDesktopAppFrame() { |
| 181 glass_frame_view_ = NULL; | 120 glass_frame_view_ = NULL; |
| 182 if (ui::win::IsAeroGlassEnabled()) { | 121 if (ui::win::IsAeroGlassEnabled()) { |
| 183 glass_frame_view_ = new GlassAppWindowFrameViewWin(this, widget()); | 122 glass_frame_view_ = new GlassAppWindowFrameViewWin(this, widget()); |
| 184 return glass_frame_view_; | 123 return glass_frame_view_; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, | 185 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, |
| 247 extension->id()); | 186 extension->id()); |
| 248 | 187 |
| 249 ShellLinkItemList items; | 188 ShellLinkItemList items; |
| 250 items.push_back(link); | 189 items.push_back(link); |
| 251 jumplist_updater.AddTasks(items); | 190 jumplist_updater.AddTasks(items); |
| 252 } | 191 } |
| 253 | 192 |
| 254 jumplist_updater.CommitUpdate(); | 193 jumplist_updater.CommitUpdate(); |
| 255 } | 194 } |
| OLD | NEW |