| 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/ui/views/app_window_frame_view.h" | 7 #include "apps/ui/views/app_window_frame_view.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "extensions/browser/app_window/app_window.h" | 28 #include "extensions/browser/app_window/app_window.h" |
| 29 #include "extensions/browser/app_window/app_window_registry.h" | 29 #include "extensions/browser/app_window/app_window_registry.h" |
| 30 #include "extensions/browser/extension_util.h" | 30 #include "extensions/browser/extension_util.h" |
| 31 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 32 #include "ui/aura/remote_window_tree_host_win.h" | 32 #include "ui/aura/remote_window_tree_host_win.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/win/shell.h" | 34 #include "ui/base/win/shell.h" |
| 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 36 #include "ui/views/win/hwnd_util.h" | 36 #include "ui/views/win/hwnd_util.h" |
| 37 | 37 |
| 38 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin() | 38 ChromeNativeAppWindowViewsWin::ChromeNativeAppWindowViewsWin( |
| 39 : glass_frame_view_(NULL), weak_ptr_factory_(this) { | 39 extensions::AppWindow* app_window) |
| 40 : ChromeNativeAppWindowViews(app_window), |
| 41 glass_frame_view_(NULL), |
| 42 weak_ptr_factory_(this) { |
| 40 } | 43 } |
| 41 | 44 |
| 42 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { | 45 void ChromeNativeAppWindowViewsWin::ActivateParentDesktopIfNecessary() { |
| 43 // Only switching into Ash from Native is supported. Tearing the user out of | 46 // Only switching into Ash from Native is supported. Tearing the user out of |
| 44 // Metro mode can only be done by launching a process from Metro mode itself. | 47 // Metro mode can only be done by launching a process from Metro mode itself. |
| 45 // This is done for launching apps, but not regular activations. | 48 // This is done for launching apps, but not regular activations. |
| 46 if (IsRunningInAsh() && | 49 if (IsRunningInAsh() && |
| 47 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { | 50 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 48 chrome::ActivateMetroChrome(); | 51 chrome::ActivateMetroChrome(); |
| 49 } | 52 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 // The default views / Aura implementation will remove this if we are using | 72 // The default views / Aura implementation will remove this if we are using |
| 70 // frameless or colored windows, so we put it back here. | 73 // frameless or colored windows, so we put it back here. |
| 71 HWND hwnd = GetNativeAppWindowHWND(); | 74 HWND hwnd = GetNativeAppWindowHWND(); |
| 72 int current_style = ::GetWindowLong(hwnd, GWL_STYLE); | 75 int current_style = ::GetWindowLong(hwnd, GWL_STYLE); |
| 73 ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION); | 76 ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION); |
| 74 } | 77 } |
| 75 | 78 |
| 76 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( | 79 void ChromeNativeAppWindowViewsWin::OnBeforeWidgetInit( |
| 77 views::Widget::InitParams* init_params, | 80 views::Widget::InitParams* init_params, |
| 78 views::Widget* widget) { | 81 views::Widget* widget) { |
| 79 content::BrowserContext* browser_context = app_window()->browser_context(); | 82 content::BrowserContext* browser_context = app_window()->GetBrowserContext(); |
| 80 std::string extension_id = app_window()->extension_id(); | 83 std::string extension_id = extension_app_window()->extension_id(); |
| 81 // If an app has any existing windows, ensure new ones are created on the | 84 // If an app has any existing windows, ensure new ones are created on the |
| 82 // same desktop. | 85 // same desktop. |
| 83 extensions::AppWindow* any_existing_window = | 86 extensions::AppWindow* any_existing_window = |
| 84 extensions::AppWindowRegistry::Get(browser_context) | 87 extensions::AppWindowRegistry::Get(browser_context) |
| 85 ->GetCurrentAppWindowForApp(extension_id); | 88 ->GetCurrentAppWindowForApp(extension_id); |
| 86 chrome::HostDesktopType desktop_type; | 89 chrome::HostDesktopType desktop_type; |
| 87 if (any_existing_window) { | 90 if (any_existing_window) { |
| 88 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( | 91 desktop_type = chrome::GetHostDesktopTypeForNativeWindow( |
| 89 any_existing_window->GetNativeWindow()); | 92 any_existing_window->GetNativeWindow()); |
| 90 } else { | 93 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 | 109 |
| 107 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( | 110 void ChromeNativeAppWindowViewsWin::InitializeDefaultWindow( |
| 108 const extensions::AppWindow::CreateParams& create_params) { | 111 const extensions::AppWindow::CreateParams& create_params) { |
| 109 ChromeNativeAppWindowViews::InitializeDefaultWindow(create_params); | 112 ChromeNativeAppWindowViews::InitializeDefaultWindow(create_params); |
| 110 | 113 |
| 111 // Remaining initialization is for Windows shell integration, which doesn't | 114 // Remaining initialization is for Windows shell integration, which doesn't |
| 112 // apply to app windows in Ash. | 115 // apply to app windows in Ash. |
| 113 if (IsRunningInAsh()) | 116 if (IsRunningInAsh()) |
| 114 return; | 117 return; |
| 115 | 118 |
| 116 const extensions::Extension* extension = app_window()->GetExtension(); | 119 const extensions::Extension* extension = |
| 120 extension_app_window()->GetExtension(); |
| 117 if (!extension) | 121 if (!extension) |
| 118 return; | 122 return; |
| 119 | 123 |
| 120 std::string app_name = | 124 std::string app_name = |
| 121 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | 125 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 122 base::string16 app_name_wide = base::UTF8ToWide(app_name); | 126 base::string16 app_name_wide = base::UTF8ToWide(app_name); |
| 123 HWND hwnd = GetNativeAppWindowHWND(); | 127 HWND hwnd = GetNativeAppWindowHWND(); |
| 124 Profile* profile = | 128 Profile* profile = |
| 125 Profile::FromBrowserContext(app_window()->browser_context()); | 129 Profile::FromBrowserContext(app_window()->GetBrowserContext()); |
| 126 app_model_id_ = | 130 app_model_id_ = |
| 127 ShellIntegration::GetAppModelIdForProfile(app_name_wide, | 131 ShellIntegration::GetAppModelIdForProfile(app_name_wide, |
| 128 profile->GetPath()); | 132 profile->GetPath()); |
| 129 ui::win::SetAppIdForWindow(app_model_id_, hwnd); | 133 ui::win::SetAppIdForWindow(app_model_id_, hwnd); |
| 130 web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd); | 134 web_app::UpdateRelaunchDetailsForApp(profile, extension, hwnd); |
| 131 | 135 |
| 132 if (!create_params.alpha_enabled) | 136 if (!create_params.alpha_enabled) |
| 133 EnsureCaptionStyleSet(); | 137 EnsureCaptionStyleSet(); |
| 134 UpdateShelfMenu(); | 138 UpdateShelfMenu(); |
| 135 } | 139 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 158 if (!JumpListUpdater::IsEnabled() || IsRunningInAsh()) | 162 if (!JumpListUpdater::IsEnabled() || IsRunningInAsh()) |
| 159 return; | 163 return; |
| 160 | 164 |
| 161 // Currently the only option is related to ephemeral apps, so avoid updating | 165 // Currently the only option is related to ephemeral apps, so avoid updating |
| 162 // the app's jump list when the feature is not enabled. | 166 // the app's jump list when the feature is not enabled. |
| 163 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 167 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 164 switches::kEnableEphemeralApps)) { | 168 switches::kEnableEphemeralApps)) { |
| 165 return; | 169 return; |
| 166 } | 170 } |
| 167 | 171 |
| 168 const extensions::Extension* extension = app_window()->GetExtension(); | 172 const extensions::Extension* extension = |
| 173 extension_app_window()->GetExtension(); |
| 169 if (!extension) | 174 if (!extension) |
| 170 return; | 175 return; |
| 171 | 176 |
| 172 // For the icon resources. | 177 // For the icon resources. |
| 173 base::FilePath chrome_path; | 178 base::FilePath chrome_path; |
| 174 if (!PathService::Get(base::FILE_EXE, &chrome_path)) | 179 if (!PathService::Get(base::FILE_EXE, &chrome_path)) |
| 175 return; | 180 return; |
| 176 | 181 |
| 177 DCHECK(!app_model_id_.empty()); | 182 DCHECK(!app_model_id_.empty()); |
| 178 | 183 |
| 179 JumpListUpdater jumplist_updater(app_model_id_); | 184 JumpListUpdater jumplist_updater(app_model_id_); |
| 180 if (!jumplist_updater.BeginUpdate()) | 185 if (!jumplist_updater.BeginUpdate()) |
| 181 return; | 186 return; |
| 182 | 187 |
| 183 // Add item to install ephemeral apps. | 188 // Add item to install ephemeral apps. |
| 184 if (extensions::util::IsEphemeralApp(extension->id(), | 189 if (extensions::util::IsEphemeralApp(extension->id(), |
| 185 app_window()->browser_context())) { | 190 app_window()->GetBrowserContext())) { |
| 186 scoped_refptr<ShellLinkItem> link(new ShellLinkItem()); | 191 scoped_refptr<ShellLinkItem> link(new ShellLinkItem()); |
| 187 link->set_title(l10n_util::GetStringUTF16(IDS_APP_INSTALL_TITLE)); | 192 link->set_title(l10n_util::GetStringUTF16(IDS_APP_INSTALL_TITLE)); |
| 188 link->set_icon(chrome_path.value(), | 193 link->set_icon(chrome_path.value(), |
| 189 icon_resources::kInstallPackagedAppIndex); | 194 icon_resources::kInstallPackagedAppIndex); |
| 190 ShellIntegration::AppendProfileArgs( | 195 ShellIntegration::AppendProfileArgs( |
| 191 app_window()->browser_context()->GetPath(), link->GetCommandLine()); | 196 app_window()->GetBrowserContext()->GetPath(), link->GetCommandLine()); |
| 192 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, | 197 link->GetCommandLine()->AppendSwitchASCII(switches::kInstallFromWebstore, |
| 193 extension->id()); | 198 extension->id()); |
| 194 | 199 |
| 195 ShellLinkItemList items; | 200 ShellLinkItemList items; |
| 196 items.push_back(link); | 201 items.push_back(link); |
| 197 jumplist_updater.AddTasks(items); | 202 jumplist_updater.AddTasks(items); |
| 198 } | 203 } |
| 199 | 204 |
| 200 // Note that an empty jumplist must still be committed to clear all items. | 205 // Note that an empty jumplist must still be committed to clear all items. |
| 201 jumplist_updater.CommitUpdate(); | 206 jumplist_updater.CommitUpdate(); |
| 202 } | 207 } |
| OLD | NEW |