Commit 9518c8c7 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Move Windows-specific code into NativeAppWindowViewsWin

NativeAppWindowViews has Windows-specific code in #ifdefs. Move this
into derived class NativeAppWindowViewsWin.

BUG=None

Review URL: https://codereview.chromium.org/161753002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251029 0039d316-1c4b-4281-b951-d872f2087c98
parent 01430824
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include "apps/shell_window.h" #include "apps/shell_window.h"
#include "apps/ui/views/shell_window_frame_view.h" #include "apps/ui/views/shell_window_frame_view.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/app_mode/app_mode_utils.h"
...@@ -37,14 +35,6 @@ ...@@ -37,14 +35,6 @@
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h" #include "ui/views/window/non_client_view.h"
#if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
#include "chrome/browser/web_applications/web_app_win.h"
#include "ui/base/win/shell.h"
#include "ui/views/win/hwnd_util.h"
#endif
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "chrome/browser/shell_integration_linux.h" #include "chrome/browser/shell_integration_linux.h"
#endif #endif
...@@ -139,39 +129,6 @@ const std::map<ui::Accelerator, int>& GetAcceleratorTable() { ...@@ -139,39 +129,6 @@ const std::map<ui::Accelerator, int>& GetAcceleratorTable() {
return accelerators; return accelerators;
} }
#if defined(OS_WIN)
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);
}
#endif
#if defined(USE_ASH) #if defined(USE_ASH)
// This class handles a user's fullscreen request (Shift+F4/F4). // This class handles a user's fullscreen request (Shift+F4/F4).
class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate,
...@@ -357,51 +314,8 @@ void NativeAppWindowViews::InitializeDefaultWindow( ...@@ -357,51 +314,8 @@ void NativeAppWindowViews::InitializeDefaultWindow(
focus_manager->RegisterAccelerator( focus_manager->RegisterAccelerator(
iter->first, ui::AcceleratorManager::kNormalPriority, this); iter->first, ui::AcceleratorManager::kNormalPriority, this);
} }
#if defined(OS_WIN)
base::string16 app_name_wide = base::UTF8ToWide(app_name);
HWND hwnd = GetNativeAppWindowHWND();
ui::win::SetAppIdForWindow(
ShellIntegration::GetAppModelIdForProfile(
app_name_wide,
Profile::FromBrowserContext(browser_context())->GetPath()),
hwnd);
web_app::UpdateShortcutInfoAndIconForApp(
*extension(),
Profile::FromBrowserContext(browser_context()),
base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded,
weak_ptr_factory_.GetWeakPtr()));
#endif
}
#if defined(OS_WIN)
void NativeAppWindowViews::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 NativeAppWindowViews::GetNativeAppWindowHWND() const {
return views::HWNDForWidget(window_->GetTopLevelWidget());
}
#endif
void NativeAppWindowViews::InitializePanelWindow( void NativeAppWindowViews::InitializePanelWindow(
const ShellWindow::CreateParams& create_params) { const ShellWindow::CreateParams& create_params) {
views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL);
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
#if defined(OS_WIN)
#include "chrome/browser/shell_integration.h"
#endif
#if defined(USE_ASH) #if defined(USE_ASH)
namespace ash { namespace ash {
class ImmersiveFullscreenController; class ImmersiveFullscreenController;
...@@ -83,14 +79,16 @@ class NativeAppWindowViews : public apps::NativeAppWindow, ...@@ -83,14 +79,16 @@ class NativeAppWindowViews : public apps::NativeAppWindow,
const extensions::Extension* extension() { const extensions::Extension* extension() {
return shell_window_->extension(); return shell_window_->extension();
} }
const views::Widget* window() const { return window_; }
virtual void InitializeDefaultWindow(
const apps::ShellWindow::CreateParams& create_params);
virtual void InitializePanelWindow(
const apps::ShellWindow::CreateParams& create_params);
private: private:
friend class ShapedAppWindowTargeterTest; friend class ShapedAppWindowTargeterTest;
void InitializeDefaultWindow(
const apps::ShellWindow::CreateParams& create_params);
void InitializePanelWindow(
const apps::ShellWindow::CreateParams& create_params);
void OnViewWasResized(); void OnViewWasResized();
bool ShouldUseChromeStyleFrame() const; bool ShouldUseChromeStyleFrame() const;
...@@ -98,12 +96,6 @@ class NativeAppWindowViews : public apps::NativeAppWindow, ...@@ -98,12 +96,6 @@ class NativeAppWindowViews : public apps::NativeAppWindow,
// Caller owns the returned object. // Caller owns the returned object.
apps::ShellWindowFrameView* CreateShellWindowFrameView(); apps::ShellWindowFrameView* CreateShellWindowFrameView();
#if defined(OS_WIN)
void OnShortcutInfoLoaded(
const ShellIntegration::ShortcutInfo& shortcut_info);
HWND GetNativeAppWindowHWND() const;
#endif
// ui::BaseWindow implementation. // ui::BaseWindow implementation.
virtual bool IsActive() const OVERRIDE; virtual bool IsActive() const OVERRIDE;
virtual bool IsMaximized() const OVERRIDE; virtual bool IsMaximized() const OVERRIDE;
......
...@@ -7,14 +7,63 @@ ...@@ -7,14 +7,63 @@
#include "apps/shell_window.h" #include "apps/shell_window.h"
#include "apps/shell_window_registry.h" #include "apps/shell_window_registry.h"
#include "ash/shell.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.h"
#include "chrome/browser/apps/per_app_settings_service_factory.h" #include "chrome/browser/apps/per_app_settings_service_factory.h"
#include "chrome/browser/metro_utils/metro_chrome_win.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 "extensions/common/extension.h"
#include "ui/aura/remote_root_window_host_win.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/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() { void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() {
...@@ -34,6 +83,31 @@ void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { ...@@ -34,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( void NativeAppWindowViewsWin::OnBeforeWidgetInit(
views::Widget::InitParams* init_params, views::Widget* widget) { views::Widget::InitParams* init_params, views::Widget* widget) {
// If an app has any existing windows, ensure new ones are created on the // If an app has any existing windows, ensure new ones are created on the
...@@ -62,6 +136,27 @@ void NativeAppWindowViewsWin::OnBeforeWidgetInit( ...@@ -62,6 +136,27 @@ void NativeAppWindowViewsWin::OnBeforeWidgetInit(
init_params->native_widget = new views::DesktopNativeWidgetAura(widget); 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();
ui::win::SetAppIdForWindow(
ShellIntegration::GetAppModelIdForProfile(
app_name_wide,
Profile::FromBrowserContext(browser_context())->GetPath()),
hwnd);
web_app::UpdateShortcutInfoAndIconForApp(
*extension(),
Profile::FromBrowserContext(browser_context()),
base::Bind(&NativeAppWindowViewsWin::OnShortcutInfoLoaded,
weak_ptr_factory_.GetWeakPtr()));
}
void NativeAppWindowViewsWin::Show() { void NativeAppWindowViewsWin::Show() {
ActivateParentDesktopIfNecessary(); ActivateParentDesktopIfNecessary();
NativeAppWindowViews::Show(); NativeAppWindowViews::Show();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_WIN_H_ #ifndef CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_WIN_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_WIN_H_ #define CHROME_BROWSER_UI_VIEWS_APPS_NATIVE_APP_WINDOW_VIEWS_WIN_H_
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/views/apps/native_app_window_views.h" #include "chrome/browser/ui/views/apps/native_app_window_views.h"
// Windows-specific parts of the views-backed native shell window implementation // Windows-specific parts of the views-backed native shell window implementation
...@@ -16,14 +17,23 @@ class NativeAppWindowViewsWin : public NativeAppWindowViews { ...@@ -16,14 +17,23 @@ class NativeAppWindowViewsWin : public NativeAppWindowViews {
private: private:
void ActivateParentDesktopIfNecessary(); void ActivateParentDesktopIfNecessary();
void OnShortcutInfoLoaded(
const ShellIntegration::ShortcutInfo& shortcut_info);
HWND GetNativeAppWindowHWND() const;
// Overridden from NativeAppWindowViews: // Overridden from NativeAppWindowViews:
virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params, virtual void OnBeforeWidgetInit(views::Widget::InitParams* init_params,
views::Widget* widget) OVERRIDE; views::Widget* widget) OVERRIDE;
virtual void InitializeDefaultWindow(
const apps::ShellWindow::CreateParams& create_params) OVERRIDE;
// Overridden from ui::BaseWindow: // Overridden from ui::BaseWindow:
virtual void Show() OVERRIDE; virtual void Show() OVERRIDE;
virtual void Activate() OVERRIDE; virtual void Activate() OVERRIDE;
base::WeakPtrFactory<NativeAppWindowViewsWin> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViewsWin); DISALLOW_COPY_AND_ASSIGN(NativeAppWindowViewsWin);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment