| 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..7c24c6c9e21ef49b2073c9e7d180045f602ddf8a 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,76 @@
|
| #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/views/apps/jumplist_updater_win.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 "grit/chromium_strings.h"
|
| #include "ui/aura/remote_root_window_host_win.h"
|
| +#include "ui/base/l10n/l10n_util.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);
|
| +}
|
| +
|
| +base::FilePath GetInstallIconPath() {
|
| + const wchar_t kInstallIconSubdir[] = L"icons";
|
| + const wchar_t kInstallIconFileName[] = L"star.ico";
|
| +
|
| + base::FilePath icon_path;
|
| + if (!PathService::Get(base::DIR_MODULE, &icon_path))
|
| + return base::FilePath();
|
| +
|
| + return icon_path.Append(kInstallIconSubdir).Append(kInstallIconFileName);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +NativeAppWindowViewsWin::NativeAppWindowViewsWin()
|
| + : weak_ptr_factory_(this) {
|
| }
|
|
|
| void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
|
| @@ -63,6 +124,30 @@ void NativeAppWindowViewsWin::OnBeforeWidgetInit(
|
| init_params->native_widget = new views::DesktopNativeWidgetAura(widget);
|
| }
|
|
|
| +void NativeAppWindowViewsWin::InitializeDefaultWindow(
|
| + const apps::ShellWindow::CreateParams& create_params) {
|
| + 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()));
|
| +
|
| + if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableEphemeralApps)) {
|
| + jumplist_updater_.reset(new JumpListUpdater(profile(), app_id));
|
| + UpdateAppMenu();
|
| + }
|
| +}
|
| +
|
| void NativeAppWindowViewsWin::Show() {
|
| ActivateParentDesktopIfNecessary();
|
| NativeAppWindowViews::Show();
|
| @@ -72,3 +157,48 @@ void NativeAppWindowViewsWin::Activate() {
|
| ActivateParentDesktopIfNecessary();
|
| NativeAppWindowViews::Activate();
|
| }
|
| +
|
| +void NativeAppWindowViewsWin::UpdateAppMenu() {
|
| + if (!jumplist_updater_.get())
|
| + return;
|
| +
|
| + std::vector<JumpListUpdater::ListItem> list_items;
|
| +
|
| + // Add item to install ephemeral apps.
|
| + if (extension()->is_ephemeral()) {
|
| + JumpListUpdater::ListItem install_item(
|
| + l10n_util::GetStringUTF16(IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE),
|
| + GetInstallIconPath());
|
| + JumpListUpdater::AppendArgs(switches::kInstallFromWebstore,
|
| + base::UTF8ToWide(extension()->id()),
|
| + &install_item.command_line_args);
|
| + list_items.push_back(install_item);
|
| + }
|
| +
|
| + jumplist_updater_->Update(list_items);
|
| +}
|
| +
|
| +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());
|
| +}
|
|
|