| 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.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
| 13 #include "chrome/browser/favicon/favicon_tab_helper.h" | 13 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 15 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 16 #include "chrome/browser/ui/views/extensions/shell_window_frame_view.h" | 16 #include "chrome/browser/ui/views/extensions/shell_window_frame_view.h" |
| 17 #include "chrome/browser/web_applications/web_app.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/render_widget_host_view.h" | 22 #include "content/public/browser/render_widget_host_view.h" |
| 22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
| 24 #include "extensions/common/draggable_region.h" | 25 #include "extensions/common/draggable_region.h" |
| 25 #include "ui/views/controls/webview/webview.h" | 26 #include "ui/views/controls/webview/webview.h" |
| 26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/window/non_client_view.h" | 28 #include "ui/views/window/non_client_view.h" |
| 28 | 29 |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 #include "base/strings/utf_string_conversions.h" | 31 #include "base/strings/utf_string_conversions.h" |
| 31 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 32 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
| 32 #include "chrome/browser/web_applications/web_app.h" | |
| 33 #include "chrome/browser/web_applications/web_app_win.h" | 33 #include "chrome/browser/web_applications/web_app_win.h" |
| 34 #include "ui/base/win/shell.h" | 34 #include "ui/base/win/shell.h" |
| 35 #include "ui/views/win/hwnd_util.h" | 35 #include "ui/views/win/hwnd_util.h" |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(OS_LINUX) |
| 39 #include "chrome/browser/shell_integration_linux.h" |
| 40 #endif |
| 41 |
| 38 #if defined(USE_ASH) | 42 #if defined(USE_ASH) |
| 39 #include "ash/screen_ash.h" | 43 #include "ash/screen_ash.h" |
| 40 #include "ash/shell.h" | 44 #include "ash/shell.h" |
| 41 #include "ash/wm/custom_frame_view_ash.h" | 45 #include "ash/wm/custom_frame_view_ash.h" |
| 42 #include "ash/wm/panels/panel_frame_view.h" | 46 #include "ash/wm/panels/panel_frame_view.h" |
| 43 #include "ash/wm/window_properties.h" | 47 #include "ash/wm/window_properties.h" |
| 44 #include "chrome/browser/ui/ash/ash_util.h" | 48 #include "chrome/browser/ui/ash/ash_util.h" |
| 45 #include "ui/aura/client/aura_constants.h" | 49 #include "ui/aura/client/aura_constants.h" |
| 46 #include "ui/aura/root_window.h" | 50 #include "ui/aura/root_window.h" |
| 47 #include "ui/aura/window.h" | 51 #include "ui/aura/window.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 OnViewWasResized(); | 153 OnViewWasResized(); |
| 150 window_->AddObserver(this); | 154 window_->AddObserver(this); |
| 151 } | 155 } |
| 152 | 156 |
| 153 NativeAppWindowViews::~NativeAppWindowViews() { | 157 NativeAppWindowViews::~NativeAppWindowViews() { |
| 154 web_view_->SetWebContents(NULL); | 158 web_view_->SetWebContents(NULL); |
| 155 } | 159 } |
| 156 | 160 |
| 157 void NativeAppWindowViews::InitializeDefaultWindow( | 161 void NativeAppWindowViews::InitializeDefaultWindow( |
| 158 const ShellWindow::CreateParams& create_params) { | 162 const ShellWindow::CreateParams& create_params) { |
| 163 std::string app_name = |
| 164 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); |
| 165 |
| 159 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 166 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 160 init_params.delegate = this; | 167 init_params.delegate = this; |
| 161 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); | 168 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); |
| 162 init_params.use_system_default_icon = true; | 169 init_params.use_system_default_icon = true; |
| 163 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 170 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
| 164 // could plumb context through to here in some cases. | 171 // could plumb context through to here in some cases. |
| 165 init_params.top_level = true; | 172 init_params.top_level = true; |
| 166 gfx::Rect window_bounds = create_params.bounds; | 173 gfx::Rect window_bounds = create_params.bounds; |
| 167 bool position_specified = | 174 bool position_specified = |
| 168 window_bounds.x() != INT_MIN && window_bounds.y() != INT_MIN; | 175 window_bounds.x() != INT_MIN && window_bounds.y() != INT_MIN; |
| 169 if (position_specified && !window_bounds.IsEmpty()) | 176 if (position_specified && !window_bounds.IsEmpty()) |
| 170 init_params.bounds = window_bounds; | 177 init_params.bounds = window_bounds; |
| 178 |
| 179 #if defined(OS_LINUX) |
| 180 // Set up a custom WM_CLASS for app windows. This allows task switchers in |
| 181 // X11 environments to distinguish them from main browser windows. |
| 182 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); |
| 183 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); |
| 184 #endif |
| 185 |
| 171 window_->Init(init_params); | 186 window_->Init(init_params); |
| 172 | 187 |
| 173 gfx::Rect adjusted_bounds = window_bounds; | 188 gfx::Rect adjusted_bounds = window_bounds; |
| 174 adjusted_bounds.Inset(-GetFrameInsets()); | 189 adjusted_bounds.Inset(-GetFrameInsets()); |
| 175 // Center window if no position was specified. | 190 // Center window if no position was specified. |
| 176 if (!position_specified) | 191 if (!position_specified) |
| 177 window_->CenterWindow(adjusted_bounds.size()); | 192 window_->CenterWindow(adjusted_bounds.size()); |
| 178 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | 193 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) |
| 179 window_->SetBounds(adjusted_bounds); | 194 window_->SetBounds(adjusted_bounds); |
| 180 | 195 |
| 181 // Register accelarators supported by app windows. | 196 // Register accelarators supported by app windows. |
| 182 // TODO(jeremya/stevenjb): should these be registered for panels too? | 197 // TODO(jeremya/stevenjb): should these be registered for panels too? |
| 183 views::FocusManager* focus_manager = GetFocusManager(); | 198 views::FocusManager* focus_manager = GetFocusManager(); |
| 184 const std::map<ui::Accelerator, int>& accelerator_table = | 199 const std::map<ui::Accelerator, int>& accelerator_table = |
| 185 GetAcceleratorTable(); | 200 GetAcceleratorTable(); |
| 186 for (std::map<ui::Accelerator, int>::const_iterator iter = | 201 for (std::map<ui::Accelerator, int>::const_iterator iter = |
| 187 accelerator_table.begin(); | 202 accelerator_table.begin(); |
| 188 iter != accelerator_table.end(); ++iter) { | 203 iter != accelerator_table.end(); ++iter) { |
| 189 focus_manager->RegisterAccelerator( | 204 focus_manager->RegisterAccelerator( |
| 190 iter->first, ui::AcceleratorManager::kNormalPriority, this); | 205 iter->first, ui::AcceleratorManager::kNormalPriority, this); |
| 191 } | 206 } |
| 192 | 207 |
| 193 #if defined(OS_WIN) | 208 #if defined(OS_WIN) |
| 194 string16 app_name = UTF8ToWide( | 209 string16 app_name_wide = UTF8ToWide(app_name); |
| 195 web_app::GenerateApplicationNameFromExtensionId(extension()->id())); | |
| 196 HWND hwnd = GetNativeAppWindowHWND(); | 210 HWND hwnd = GetNativeAppWindowHWND(); |
| 197 ui::win::SetAppIdForWindow(ShellIntegration::GetAppModelIdForProfile( | 211 ui::win::SetAppIdForWindow(ShellIntegration::GetAppModelIdForProfile( |
| 198 app_name, profile()->GetPath()), hwnd); | 212 app_name_wide, profile()->GetPath()), hwnd); |
| 199 | 213 |
| 200 web_app::UpdateShortcutInfoAndIconForApp( | 214 web_app::UpdateShortcutInfoAndIconForApp( |
| 201 *extension(), profile(), | 215 *extension(), profile(), |
| 202 base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded, | 216 base::Bind(&NativeAppWindowViews::OnShortcutInfoLoaded, |
| 203 weak_ptr_factory_.GetWeakPtr())); | 217 weak_ptr_factory_.GetWeakPtr())); |
| 204 #endif | 218 #endif |
| 205 } | 219 } |
| 206 | 220 |
| 207 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
| 208 void NativeAppWindowViews::OnShortcutInfoLoaded( | 222 void NativeAppWindowViews::OnShortcutInfoLoaded( |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 780 |
| 767 void NativeAppWindowViews::HandleKeyboardEvent( | 781 void NativeAppWindowViews::HandleKeyboardEvent( |
| 768 const content::NativeWebKeyboardEvent& event) { | 782 const content::NativeWebKeyboardEvent& event) { |
| 769 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 783 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 770 GetFocusManager()); | 784 GetFocusManager()); |
| 771 } | 785 } |
| 772 | 786 |
| 773 void NativeAppWindowViews::RenderViewHostChanged() { | 787 void NativeAppWindowViews::RenderViewHostChanged() { |
| 774 OnViewWasResized(); | 788 OnViewWasResized(); |
| 775 } | 789 } |
| OLD | NEW |