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