| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/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 "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/browser/apps/per_app_settings_service.h" | 15 #include "chrome/browser/apps/per_app_settings_service.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 !base::CreateDirectory(web_app_path)) { | 61 !base::CreateDirectory(web_app_path)) { |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | 65 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
| 66 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 66 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 NativeAppWindowViewsWin::NativeAppWindowViewsWin() | 71 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() |
| 72 : weak_ptr_factory_(this) { | 72 : weak_ptr_factory_(this) {} |
| 73 } | |
| 74 | 73 |
| 75 void NativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { | 74 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| 76 if (!ash::Shell::HasInstance()) | 75 if (!ash::Shell::HasInstance()) |
| 77 return; | 76 return; |
| 78 | 77 |
| 79 views::Widget* widget = | 78 views::Widget* widget = |
| 80 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); | 79 implicit_cast<views::WidgetDelegate*>(this)->GetWidget(); |
| 81 chrome::HostDesktopType host_desktop_type = | 80 chrome::HostDesktopType host_desktop_type = |
| 82 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); | 81 chrome::GetHostDesktopTypeForNativeWindow(widget->GetNativeWindow()); |
| 83 // Only switching into Ash from Native is supported. Tearing the user out of | 82 // Only switching into Ash from Native is supported. Tearing the user out of |
| 84 // Metro mode can only be done by launching a process from Metro mode itself. | 83 // Metro mode can only be done by launching a process from Metro mode itself. |
| 85 // This is done for launching apps, but not regular activations. | 84 // This is done for launching apps, but not regular activations. |
| 86 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && | 85 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH && |
| 87 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { | 86 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 88 chrome::ActivateMetroChrome(); | 87 chrome::ActivateMetroChrome(); |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 void NativeAppWindowViewsWin::OnShortcutInfoLoaded( | 91 void ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded( |
| 93 const ShellIntegration::ShortcutInfo& shortcut_info) { | 92 const ShellIntegration::ShortcutInfo& shortcut_info) { |
| 94 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 93 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 95 | 94 |
| 96 HWND hwnd = GetNativeAppWindowHWND(); | 95 HWND hwnd = GetNativeAppWindowHWND(); |
| 97 | 96 |
| 98 // Set window's icon to the one we're about to create/update in the web app | 97 // Set window's icon to the one we're about to create/update in the web app |
| 99 // path. The icon cache will refresh on icon creation. | 98 // path. The icon cache will refresh on icon creation. |
| 100 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( | 99 base::FilePath web_app_path = web_app::GetWebAppDataDirectory( |
| 101 shortcut_info.profile_path, shortcut_info.extension_id, | 100 shortcut_info.profile_path, shortcut_info.extension_id, |
| 102 shortcut_info.url); | 101 shortcut_info.url); |
| 103 base::FilePath icon_file = web_app_path | 102 base::FilePath icon_file = web_app_path |
| 104 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) | 103 .Append(web_app::internals::GetSanitizedFileName(shortcut_info.title)) |
| 105 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); | 104 .ReplaceExtension(FILE_PATH_LITERAL(".ico")); |
| 106 | 105 |
| 107 content::BrowserThread::PostBlockingPoolTask( | 106 content::BrowserThread::PostBlockingPoolTask( |
| 108 FROM_HERE, | 107 FROM_HERE, |
| 109 base::Bind(&CreateIconAndSetRelaunchDetails, | 108 base::Bind(&CreateIconAndSetRelaunchDetails, |
| 110 web_app_path, icon_file, shortcut_info, hwnd)); | 109 web_app_path, icon_file, shortcut_info, hwnd)); |
| 111 } | 110 } |
| 112 | 111 |
| 113 HWND NativeAppWindowViewsWin::GetNativeAppWindowHWND() const { | 112 HWND ChromeNativeAppWindowViewsWin::GetNativeAppWindowHWND() const { |
| 114 return views::HWNDForWidget(window()->GetTopLevelWidget()); | 113 return views::HWNDForWidget(window()->GetTopLevelWidget()); |
| 115 } | 114 } |
| 116 | 115 |
| 117 void NativeAppWindowViewsWin::OnBeforeWidgetInit( | 116 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( |
| 118 views::Widget::InitParams* init_params, views::Widget* widget) { | 117 views::Widget::InitParams* init_params, |
| 118 views::Widget* widget) { |
| 119 content::BrowserContext* browser_context = app_window()->browser_context(); | 119 content::BrowserContext* browser_context = app_window()->browser_context(); |
| 120 const extensions::Extension* extension = app_window()->extension(); | 120 const extensions::Extension* extension = app_window()->extension(); |
| 121 // If an app has any existing windows, ensure new ones are created on the | 121 // If an app has any existing windows, ensure new ones are created on the |
| 122 // same desktop. | 122 // same desktop. |
| 123 apps::AppWindow* any_existing_window = | 123 apps::AppWindow* any_existing_window = |
| 124 apps::AppWindowRegistry::Get(browser_context) | 124 apps::AppWindowRegistry::Get(browser_context) |
| 125 ->GetCurrentAppWindowForApp(extension->id()); | 125 ->GetCurrentAppWindowForApp(extension->id()); |
| 126 chrome::HostDesktopType desktop_type; | 126 chrome::HostDesktopType desktop_type; |
| 127 if (any_existing_window) { | 127 if (any_existing_window) { |
| 128 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( | 128 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( |
| 129 any_existing_window->GetNativeWindow()); | 129 any_existing_window->GetNativeWindow()); |
| 130 } else { | 130 } else { |
| 131 PerAppSettingsService* settings = | 131 PerAppSettingsService* settings = |
| 132 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context); | 132 PerAppSettingsServiceFactory::GetForBrowserContext(browser_context); |
| 133 if (settings->HasDesktopLastLaunchedFrom(extension->id())) { | 133 if (settings->HasDesktopLastLaunchedFrom(extension->id())) { |
| 134 desktop_type = settings->GetDesktopLastLaunchedFrom(extension->id()); | 134 desktop_type = settings->GetDesktopLastLaunchedFrom(extension->id()); |
| 135 } else { | 135 } else { |
| 136 // We don't know what desktop this app was last launched from, so take our | 136 // We don't know what desktop this app was last launched from, so take our |
| 137 // best guess as to what desktop the user is on. | 137 // best guess as to what desktop the user is on. |
| 138 desktop_type = chrome::GetActiveDesktop(); | 138 desktop_type = chrome::GetActiveDesktop(); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) | 141 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) |
| 142 init_params->context = ash::Shell::GetPrimaryRootWindow(); | 142 init_params->context = ash::Shell::GetPrimaryRootWindow(); |
| 143 else | 143 else |
| 144 init_params->native_widget = new views::DesktopNativeWidgetAura(widget); | 144 init_params->native_widget = new views::DesktopNativeWidgetAura(widget); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void NativeAppWindowViewsWin::InitializeDefaultWindow( | 147 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( |
| 148 const apps::AppWindow::CreateParams& create_params) { | 148 const apps::AppWindow::CreateParams& create_params) { |
| 149 NativeAppWindowViews::InitializeDefaultWindow(create_params); | 149 ChromeNativeAppWindowViews::InitializeDefaultWindow(create_params); |
| 150 | 150 |
| 151 const extensions::Extension* extension = app_window()->extension(); | 151 const extensions::Extension* extension = app_window()->extension(); |
| 152 std::string app_name = | 152 std::string app_name = |
| 153 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 153 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 154 base::string16 app_name_wide = base::UTF8ToWide(app_name); | 154 base::string16 app_name_wide = base::UTF8ToWide(app_name); |
| 155 HWND hwnd = GetNativeAppWindowHWND(); | 155 HWND hwnd = GetNativeAppWindowHWND(); |
| 156 Profile* profile = | 156 Profile* profile = |
| 157 Profile::FromBrowserContext(app_window()->browser_context()); | 157 Profile::FromBrowserContext(app_window()->browser_context()); |
| 158 app_model_id_ = | 158 app_model_id_ = |
| 159 ShellIntegration::GetAppModelIdForProfile(app_name_wide, | 159 ShellIntegration::GetAppModelIdForProfile(app_name_wide, |
| 160 profile->GetPath()); | 160 profile->GetPath()); |
| 161 ui::win::SetAppIdForWindow(app_model_id_, hwnd); | 161 ui::win::SetAppIdForWindow(app_model_id_, hwnd); |
| 162 | 162 |
| 163 web_app::UpdateShortcutInfoAndIconForApp( | 163 web_app::UpdateShortcutInfoAndIconForApp( |
| 164 *extension, | 164 *extension, |
| 165 profile, | 165 profile, |
| 166 base::Bind(&NativeAppWindowViewsWin::OnShortcutInfoLoaded, | 166 base::Bind(&ChromeNativeAppWindowViewsWin::OnShortcutInfoLoaded, |
| 167 weak_ptr_factory_.GetWeakPtr())); | 167 weak_ptr_factory_.GetWeakPtr())); |
| 168 | 168 |
| 169 UpdateShelfMenu(); | 169 UpdateShelfMenu(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void NativeAppWindowViewsWin::Show() { | 172 void ChromeNativeAppWindowViewsWin::Show() { |
| 173 ActivateParentDesktopIfNecessary(); | 173 ActivateParentDesktopIfNecessary(); |
| 174 NativeAppWindowViews::Show(); | 174 ChromeNativeAppWindowViews::Show(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void NativeAppWindowViewsWin::Activate() { | 177 void ChromeNativeAppWindowViewsWin::Activate() { |
| 178 ActivateParentDesktopIfNecessary(); | 178 ActivateParentDesktopIfNecessary(); |
| 179 NativeAppWindowViews::Activate(); | 179 ChromeNativeAppWindowViews::Activate(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void NativeAppWindowViewsWin::UpdateShelfMenu() { | 182 void ChromeNativeAppWindowViewsWin::UpdateShelfMenu() { |
| 183 if (!JumpListUpdater::IsEnabled()) | 183 if (!JumpListUpdater::IsEnabled()) |
| 184 return; | 184 return; |
| 185 | 185 |
| 186 // Currently the only option is related to ephemeral apps, so avoid updating | 186 // Currently the only option is related to ephemeral apps, so avoid updating |
| 187 // the app's jump list when the feature is not enabled. | 187 // the app's jump list when the feature is not enabled. |
| 188 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 188 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 189 switches::kEnableEphemeralApps)) { | 189 switches::kEnableEphemeralApps)) { |
| 190 return; | 190 return; |
| 191 } | 191 } |
| 192 | 192 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, | 212 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, |
| 213 extension->id()); | 213 extension->id()); |
| 214 | 214 |
| 215 ShellLinkItemList items; | 215 ShellLinkItemList items; |
| 216 items.push_back(link); | 216 items.push_back(link); |
| 217 jumplist_updater.AddTasks(items); | 217 jumplist_updater.AddTasks(items); |
| 218 } | 218 } |
| 219 | 219 |
| 220 jumplist_updater.CommitUpdate(); | 220 jumplist_updater.CommitUpdate(); |
| 221 } | 221 } |
| OLD | NEW |