Chromium Code Reviews| Index: chrome/browser/ui/views/apps/native_app_window_views_win.cc |
| diff --git a/chrome/browser/ui/views/apps/native_app_window_views_win.cc b/chrome/browser/ui/views/apps/native_app_window_views_win.cc |
| index 5bdf99938fd28f921e5deb0612d547902bc5703b..3f67f3f99d63057cb6acf977b6ad1bbfef38cf3c 100644 |
| --- a/chrome/browser/ui/views/apps/native_app_window_views_win.cc |
| +++ b/chrome/browser/ui/views/apps/native_app_window_views_win.cc |
| @@ -7,15 +7,63 @@ |
| #include "apps/shell_window.h" |
| #include "apps/shell_window_registry.h" |
| #include "ash/shell.h" |
| +#include "base/command_line.h" |
| +#include "base/file_util.h" |
| +#include "base/path_service.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/apps/per_app_settings_service.h" |
| #include "chrome/browser/apps/per_app_settings_service_factory.h" |
| #include "chrome/browser/metro_utils/metro_chrome_win.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/web_applications/web_app_ui.h" |
| +#include "chrome/browser/web_applications/web_app.h" |
| +#include "chrome/browser/web_applications/web_app_win.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "extensions/common/extension.h" |
| #include "ui/aura/remote_root_window_host_win.h" |
| +#include "ui/base/win/shell.h" |
| #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| +#include "ui/views/win/hwnd_util.h" |
| -NativeAppWindowViewsWin::NativeAppWindowViewsWin() { |
| +namespace { |
| + |
| +void CreateIconAndSetRelaunchDetails( |
| + const base::FilePath& web_app_path, |
| + const base::FilePath& icon_file, |
| + const ShellIntegration::ShortcutInfo& shortcut_info, |
| + const HWND hwnd) { |
| + DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| + |
| + // Set the relaunch data so "Pin this program to taskbar" has the app's |
| + // information. |
| + CommandLine command_line = ShellIntegration::CommandLineArgsForLauncher( |
| + shortcut_info.url, |
| + shortcut_info.extension_id, |
| + shortcut_info.profile_path); |
| + |
| + base::FilePath chrome_exe; |
| + if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + command_line.SetProgram(chrome_exe); |
| + ui::win::SetRelaunchDetailsForWindow(command_line.GetCommandLineString(), |
| + shortcut_info.title, hwnd); |
| + |
| + if (!base::PathExists(web_app_path) && |
| + !base::CreateDirectory(web_app_path)) { |
| + return; |
| + } |
| + |
| + ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
| + web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
| +} |
| + |
| +} // namespace |
| + |
| +NativeAppWindowViewsWin::NativeAppWindowViewsWin() |
| + : weak_ptr_factory_(this) { |
| } |
| void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| @@ -35,6 +83,31 @@ void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| } |
| } |
| +void NativeAppWindowViewsWin::OnShortcutInfoLoaded( |
| + const ShellIntegration::ShortcutInfo& shortcut_info) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + HWND hwnd = GetNativeAppWindowHWND(); |
| + |
| + // Set window's icon to the one we're about to create/update in the web app |
| + // path. The icon cache will refresh on icon creation. |
| + base::FilePath web_app_path = web_app::GetWebAppDataDirectory( |
| + shortcut_info.profile_path, shortcut_info.extension_id, |
| + shortcut_info.url); |
| + base::FilePath icon_file = web_app_path |
| + .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) |
| + .ReplaceExtension(FILE_PATH_LITERAL(".ico")); |
| + |
| + content::BrowserThread::PostBlockingPoolTask( |
| + FROM_HERE, |
| + base::Bind(&CreateIconAndSetRelaunchDetails, |
| + web_app_path, icon_file, shortcut_info, hwnd)); |
| +} |
| + |
| +HWND NativeAppWindowViewsWin::GetNativeAppWindowHWND() const { |
| + return views::HWNDForWidget(window()->GetTopLevelWidget()); |
| +} |
| + |
| void NativeAppWindowViewsWin::OnBeforeWidgetInit( |
| views::Widget::InitParams* init_params, views::Widget* widget) { |
| // If an app has any existing windows, ensure new ones are created on the |
| @@ -63,6 +136,24 @@ void NativeAppWindowViewsWin::OnBeforeWidgetInit( |
| init_params->native_widget = new views::DesktopNativeWidgetAura(widget); |
| } |
| +void NativeAppWindowViewsWin::InitializeDefaultWindow( |
| + const apps::ShellWindow::CreateParams& create_params) { |
|
tapted
2014/02/12 23:00:03
nit: indented two spaced too much
|
| + NativeAppWindowViews::InitializeDefaultWindow(create_params); |
| + |
| + std::string app_name = |
| + web_app::GenerateApplicationNameFromExtensionId(extension()->id()); |
| + base::string16 app_name_wide = base::UTF8ToWide(app_name); |
| + HWND hwnd = GetNativeAppWindowHWND(); |
| + base::string16 app_id = ShellIntegration::GetAppModelIdForProfile( |
| + app_name_wide, profile()->GetPath()); |
| + ui::win::SetAppIdForWindow(app_id, hwnd); |
| + |
| + web_app::UpdateShortcutInfoAndIconForApp( |
| + *extension(), profile(), |
| + base::Bind(&NativeAppWindowViewsWin::OnShortcutInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| void NativeAppWindowViewsWin::Show() { |
| ActivateParentDesktopIfNecessary(); |
| NativeAppWindowViews::Show(); |