Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: win8/metro_driver/chrome_app_view_ash.cc

Issue 593353003: The metro_driver should not block the UI thread while waiting for the Chrome browser IPC channel to… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « win8/metro_driver/chrome_app_view_ash.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "win8/metro_driver/stdafx.h" 5 #include "win8/metro_driver/stdafx.h"
6 #include "win8/metro_driver/chrome_app_view_ash.h" 6 #include "win8/metro_driver/chrome_app_view_ash.h"
7 7
8 #include <corewindow.h> 8 #include <corewindow.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <windows.foundation.h> 10 #include <windows.foundation.h>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/threading/thread.h"
18 #include "base/win/metro.h" 17 #include "base/win/metro.h"
19 #include "base/win/win_util.h" 18 #include "base/win/win_util.h"
20 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
21 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
22 #include "ipc/ipc_channel.h" 21 #include "ipc/ipc_channel.h"
23 #include "ipc/ipc_channel_proxy.h" 22 #include "ipc/ipc_channel_proxy.h"
24 #include "ipc/ipc_sender.h" 23 #include "ipc/ipc_sender.h"
25 #include "ui/events/gesture_detection/motion_event.h" 24 #include "ui/events/gesture_detection/motion_event.h"
26 #include "ui/gfx/geometry/point_conversions.h" 25 #include "ui/gfx/geometry/point_conversions.h"
27 #include "ui/gfx/win/dpi.h" 26 #include "ui/gfx/win/dpi.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 79
81 namespace { 80 namespace {
82 81
83 enum KeyModifier { 82 enum KeyModifier {
84 NONE, 83 NONE,
85 SHIFT = 1, 84 SHIFT = 1,
86 CONTROL = 2, 85 CONTROL = 2,
87 ALT = 4 86 ALT = 4
88 }; 87 };
89 88
89 const int kChromeChannelPollTimerMs = 100;
90 const UINT_PTR kChromeChannelPollTimerId = 0xdeadbabe;
91
90 // Helper function to send keystrokes via the SendInput function. 92 // Helper function to send keystrokes via the SendInput function.
91 // mnemonic_char: The keystroke to be sent. 93 // mnemonic_char: The keystroke to be sent.
92 // modifiers: Combination with Alt, Ctrl, Shift, etc. 94 // modifiers: Combination with Alt, Ctrl, Shift, etc.
93 void SendKeySequence( 95 void SendKeySequence(
94 WORD mnemonic_char, KeyModifier modifiers) { 96 WORD mnemonic_char, KeyModifier modifiers) {
95 INPUT keys[4] = {0}; // Keyboard events 97 INPUT keys[4] = {0}; // Keyboard events
96 int key_count = 0; // Number of generated events 98 int key_count = 0; // Number of generated events
97 99
98 if (modifiers & SHIFT) { 100 if (modifiers & SHIFT) {
99 keys[key_count].type = INPUT_KEYBOARD; 101 keys[key_count].type = INPUT_KEYBOARD;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient, 268 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient,
267 base::Unretained(app_view_), 269 base::Unretained(app_view_),
268 input_scopes, 270 input_scopes,
269 character_bounds)); 271 character_bounds));
270 } 272 }
271 273
272 scoped_refptr<base::MessageLoopProxy> ui_proxy_; 274 scoped_refptr<base::MessageLoopProxy> ui_proxy_;
273 ChromeAppViewAsh* app_view_; 275 ChromeAppViewAsh* app_view_;
274 }; 276 };
275 277
276 bool WaitForChromeIPCConnection(const std::string& channel_name) {
277 int ms_elapsed = 0;
278 while (!IPC::Channel::IsNamedServerInitialized(channel_name) &&
279 ms_elapsed < 10000) {
280 ms_elapsed += 100;
281 Sleep(100);
282 }
283 return IPC::Channel::IsNamedServerInitialized(channel_name);
284 }
285
286 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { 278 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) {
287 // We're entering a nested message loop, let's allow dispatching 279 // We're entering a nested message loop, let's allow dispatching
288 // tasks while we're in there. 280 // tasks while we're in there.
289 base::MessageLoop::current()->SetNestableTasksAllowed(true); 281 base::MessageLoop::current()->SetNestableTasksAllowed(true);
290 282
291 // Enter main core message loop. There are several ways to exit it 283 // Enter main core message loop. There are several ways to exit it
292 // Nicely: 284 // Nicely:
293 // 1 - User action like ALT-F4. 285 // 1 - User action like ALT-F4.
294 // 2 - Calling ICoreApplicationExit::Exit(). 286 // 2 - Calling ICoreApplicationExit::Exit().
295 // 3- Posting WM_CLOSE to the core window. 287 // 3- Posting WM_CLOSE to the core window.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 510
519 // The metro device scale factor as reported by the winrt interfaces. 511 // The metro device scale factor as reported by the winrt interfaces.
520 float metro_dpi_scale_; 512 float metro_dpi_scale_;
521 // The win32 dpi scale which is queried via GetDeviceCaps. Please refer to 513 // The win32 dpi scale which is queried via GetDeviceCaps. Please refer to
522 // ui/gfx/win/dpi.cc for more information. 514 // ui/gfx/win/dpi.cc for more information.
523 float win32_dpi_scale_; 515 float win32_dpi_scale_;
524 516
525 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler); 517 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler);
526 }; 518 };
527 519
520 ChromeAppViewAsh* ChromeAppViewAsh::g_instance_ = NULL;
521
528 ChromeAppViewAsh::ChromeAppViewAsh() 522 ChromeAppViewAsh::ChromeAppViewAsh()
529 : mouse_down_flags_(ui::EF_NONE), 523 : mouse_down_flags_(ui::EF_NONE),
530 ui_channel_(nullptr), 524 ui_channel_(nullptr),
531 core_window_hwnd_(NULL), 525 core_window_hwnd_(NULL),
532 metro_dpi_scale_(0), 526 metro_dpi_scale_(0),
533 win32_dpi_scale_(0), 527 win32_dpi_scale_(0),
534 last_cursor_(NULL) { 528 last_cursor_(NULL),
529 channel_listener_(NULL) {
535 DVLOG(1) << __FUNCTION__; 530 DVLOG(1) << __FUNCTION__;
536 globals.previous_state = 531 globals.previous_state =
537 winapp::Activation::ApplicationExecutionState_NotRunning; 532 winapp::Activation::ApplicationExecutionState_NotRunning;
533 DCHECK(!g_instance_);
534
535 g_instance_ = this;
538 } 536 }
539 537
540 ChromeAppViewAsh::~ChromeAppViewAsh() { 538 ChromeAppViewAsh::~ChromeAppViewAsh() {
541 DVLOG(1) << __FUNCTION__; 539 DVLOG(1) << __FUNCTION__;
542 } 540 }
543 541
544 IFACEMETHODIMP 542 IFACEMETHODIMP
545 ChromeAppViewAsh::Initialize(winapp::Core::ICoreApplicationView* view) { 543 ChromeAppViewAsh::Initialize(winapp::Core::ICoreApplicationView* view) {
546 view_ = view; 544 view_ = view;
547 DVLOG(1) << __FUNCTION__; 545 DVLOG(1) << __FUNCTION__;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 669 }
672 670
673 IFACEMETHODIMP 671 IFACEMETHODIMP
674 ChromeAppViewAsh::Run() { 672 ChromeAppViewAsh::Run() {
675 DVLOG(1) << __FUNCTION__; 673 DVLOG(1) << __FUNCTION__;
676 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; 674 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher;
677 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf()); 675 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf());
678 CheckHR(hr, "Dispatcher failed."); 676 CheckHR(hr, "Dispatcher failed.");
679 677
680 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy. 678 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy.
681 base::Thread io_thread("metro_IO_thread"); 679 io_thread_.reset(new base::Thread("metro_IO_thread"));
682 base::Thread::Options options; 680 base::Thread::Options options;
683 options.message_loop_type = base::MessageLoop::TYPE_IO; 681 options.message_loop_type = base::MessageLoop::TYPE_IO;
684 io_thread.StartWithOptions(options); 682 io_thread_->StartWithOptions(options);
685 683
686 // Start up Chrome and wait for the desired IPC server connection to exist. 684 ChromeChannelListener ui_channel_listener(&ui_loop_, this);
687 WaitForChromeIPCConnection(win8::kMetroViewerIPCChannelName); 685 channel_listener_ = &ui_channel_listener;
688 686
689 // In Aura mode we create an IPC channel to the browser, then ask it to 687 // We can't do anything until the Chrome browser IPC channel is initialized.
690 // connect to us. 688 // Lazy initialization in a timer.
691 ChromeChannelListener ui_channel_listener(&ui_loop_, this);
692 scoped_ptr<IPC::ChannelProxy> channel =
693 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName,
694 IPC::Channel::MODE_NAMED_CLIENT,
695 &ui_channel_listener,
696 io_thread.message_loop_proxy());
697 ui_channel_ = channel.get();
698 689
699 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the 690 UINT_PTR channel_setup_timer_id =
cpu_(ooo_6.6-7.5) 2014/09/25 23:00:08 change to base::timer, since in line 698 we run ou
ananta 2014/09/26 02:29:01 Good point. Done.
700 // browser will use D3D from the browser process to present to our Window. 691 ::SetTimer(core_window_hwnd_,
701 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( 692 kChromeChannelPollTimerId,
702 gfx::NativeViewId(core_window_hwnd_), win32_dpi_scale_)); 693 kChromeChannelPollTimerMs,
703 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; 694 &ChromeAppViewAsh::StartChromeOSMode);
704 695
705 // Send an initial size message so that the Ash root window host gets sized 696 // Post the task that'll do the inner Metro message pumping to it.
706 // correctly.
707 RECT rect = {0};
708 ::GetWindowRect(core_window_hwnd_, &rect);
709 ui_channel_->Send(
710 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left,
711 rect.bottom - rect.top));
712
713 input_source_ = metro_driver::InputSource::Create();
714 if (input_source_) {
715 input_source_->AddObserver(this);
716 // Send an initial input source.
717 OnInputSourceChanged();
718 }
719
720 // Start receiving IME popup window notifications.
721 metro_driver::AddImePopupObserver(this);
722
723 // And post the task that'll do the inner Metro message pumping to it.
724 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); 697 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get()));
725 ui_loop_.Run(); 698 ui_loop_.Run();
726 699
700 io_thread_.reset(NULL);
701 ui_channel_.reset(NULL);
702 channel_listener_ = NULL;
703
727 DVLOG(0) << "ProcessEvents done, hr=" << hr; 704 DVLOG(0) << "ProcessEvents done, hr=" << hr;
728 return hr; 705 return hr;
729 } 706 }
730 707
731 IFACEMETHODIMP 708 IFACEMETHODIMP
732 ChromeAppViewAsh::Uninitialize() { 709 ChromeAppViewAsh::Uninitialize() {
733 DVLOG(1) << __FUNCTION__; 710 DVLOG(1) << __FUNCTION__;
734 metro_driver::RemoveImePopupObserver(this); 711 metro_driver::RemoveImePopupObserver(this);
735 input_source_.reset(); 712 input_source_.reset();
736 text_service_.reset(); 713 text_service_.reset();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 ::PostMessage(core_window, WM_CLOSE, 0, 0); 946 ::PostMessage(core_window, WM_CLOSE, 0, 0);
970 947
971 globals.app_exit->Exit(); 948 globals.app_exit->Exit();
972 } 949 }
973 } 950 }
974 951
975 void ChromeAppViewAsh::OnInputSourceChanged() { 952 void ChromeAppViewAsh::OnInputSourceChanged() {
976 if (!input_source_) 953 if (!input_source_)
977 return; 954 return;
978 955
956 DCHECK(ui_channel_);
957
979 LANGID langid = 0; 958 LANGID langid = 0;
980 bool is_ime = false; 959 bool is_ime = false;
981 if (!input_source_->GetActiveSource(&langid, &is_ime)) { 960 if (!input_source_->GetActiveSource(&langid, &is_ime)) {
982 LOG(ERROR) << "GetActiveSource failed"; 961 LOG(ERROR) << "GetActiveSource failed";
983 return; 962 return;
984 } 963 }
985 ui_channel_->Send(new MetroViewerHostMsg_ImeInputSourceChanged(langid, 964 ui_channel_->Send(new MetroViewerHostMsg_ImeInputSourceChanged(langid,
986 is_ime)); 965 is_ime));
987 } 966 }
988 967
(...skipping 10 matching lines...) Expand all
999 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text)); 978 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text));
1000 } 979 }
1001 980
1002 void ChromeAppViewAsh::SendMouseButton(int x, 981 void ChromeAppViewAsh::SendMouseButton(int x,
1003 int y, 982 int y,
1004 int extra, 983 int extra,
1005 ui::EventType event_type, 984 ui::EventType event_type,
1006 uint32 flags, 985 uint32 flags,
1007 ui::EventFlags changed_button, 986 ui::EventFlags changed_button,
1008 bool is_horizontal_wheel) { 987 bool is_horizontal_wheel) {
988 if (!ui_channel_)
989 return;
1009 MetroViewerHostMsg_MouseButtonParams params; 990 MetroViewerHostMsg_MouseButtonParams params;
1010 params.x = static_cast<int32>(x); 991 params.x = static_cast<int32>(x);
1011 params.y = static_cast<int32>(y); 992 params.y = static_cast<int32>(y);
1012 params.extra = static_cast<int32>(extra); 993 params.extra = static_cast<int32>(extra);
1013 params.event_type = event_type; 994 params.event_type = event_type;
1014 params.flags = static_cast<int32>(flags); 995 params.flags = static_cast<int32>(flags);
1015 params.changed_button = changed_button; 996 params.changed_button = changed_button;
1016 params.is_horizontal_wheel = is_horizontal_wheel; 997 params.is_horizontal_wheel = is_horizontal_wheel;
1017 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params)); 998 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params));
1018 } 999 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // in turn launches the chrome browser process in desktop mode via 1049 // in turn launches the chrome browser process in desktop mode via
1069 // ShellExecute. If we call ICoreWindow::Activate before this, then 1050 // ShellExecute. If we call ICoreWindow::Activate before this, then
1070 // Windows kills the metro chrome process when it calls ShellExecute. Seems 1051 // Windows kills the metro chrome process when it calls ShellExecute. Seems
1071 // to be a bug. 1052 // to be a bug.
1072 window_->Activate(); 1053 window_->Activate();
1073 return S_OK; 1054 return S_OK;
1074 } 1055 }
1075 1056
1076 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender, 1057 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender,
1077 winui::Core::IPointerEventArgs* args) { 1058 winui::Core::IPointerEventArgs* args) {
1059 if (!ui_channel_)
1060 return S_OK;
1061
1078 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1062 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1079 HRESULT hr = pointer.Init(args); 1063 HRESULT hr = pointer.Init(args);
1080 if (FAILED(hr)) 1064 if (FAILED(hr))
1081 return hr; 1065 return hr;
1082 1066
1083 if (pointer.IsMouse()) { 1067 if (pointer.IsMouse()) {
1084 // If the mouse was moved towards the charms or the OS specific section, 1068 // If the mouse was moved towards the charms or the OS specific section,
1085 // the cursor may change from what the browser last set. Restore it here. 1069 // the cursor may change from what the browser last set. Restore it here.
1086 if (::GetCursor() != last_cursor_) 1070 if (::GetCursor() != last_cursor_)
1087 SetCursor(last_cursor_); 1071 SetCursor(last_cursor_);
(...skipping 15 matching lines...) Expand all
1103 1087
1104 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed 1088 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed
1105 // event for the first button pressed and the last button released in a sequence 1089 // event for the first button pressed and the last button released in a sequence
1106 // of mouse events. 1090 // of mouse events.
1107 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results 1091 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results
1108 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary 1092 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary
1109 // presses and releases are tracked in OnPointMoved(). 1093 // presses and releases are tracked in OnPointMoved().
1110 HRESULT ChromeAppViewAsh::OnPointerPressed( 1094 HRESULT ChromeAppViewAsh::OnPointerPressed(
1111 winui::Core::ICoreWindow* sender, 1095 winui::Core::ICoreWindow* sender,
1112 winui::Core::IPointerEventArgs* args) { 1096 winui::Core::IPointerEventArgs* args) {
1097 if (!ui_channel_)
1098 return S_OK;
1099
1113 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1100 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1114 HRESULT hr = pointer.Init(args); 1101 HRESULT hr = pointer.Init(args);
1115 if (FAILED(hr)) 1102 if (FAILED(hr))
1116 return hr; 1103 return hr;
1117 1104
1118 if (pointer.IsMouse()) { 1105 if (pointer.IsMouse()) {
1119 mouse_down_flags_ = pointer.mouse_down_flags(); 1106 mouse_down_flags_ = pointer.mouse_down_flags();
1120 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, 1107 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED,
1121 mouse_down_flags_ | GetKeyboardEventFlags(), 1108 mouse_down_flags_ | GetKeyboardEventFlags(),
1122 pointer.changed_button(), pointer.is_horizontal_wheel()); 1109 pointer.changed_button(), pointer.is_horizontal_wheel());
1123 } else { 1110 } else {
1124 DCHECK(pointer.IsTouch()); 1111 DCHECK(pointer.IsTouch());
1125 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), 1112 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(),
1126 pointer.y(), 1113 pointer.y(),
1127 pointer.timestamp(), 1114 pointer.timestamp(),
1128 pointer.pointer_id())); 1115 pointer.pointer_id()));
1129 } 1116 }
1130 return S_OK; 1117 return S_OK;
1131 } 1118 }
1132 1119
1133 HRESULT ChromeAppViewAsh::OnPointerReleased( 1120 HRESULT ChromeAppViewAsh::OnPointerReleased(
1134 winui::Core::ICoreWindow* sender, 1121 winui::Core::ICoreWindow* sender,
1135 winui::Core::IPointerEventArgs* args) { 1122 winui::Core::IPointerEventArgs* args) {
1123 if (!ui_channel_)
1124 return S_OK;
1125
1136 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1126 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1137 HRESULT hr = pointer.Init(args); 1127 HRESULT hr = pointer.Init(args);
1138 if (FAILED(hr)) 1128 if (FAILED(hr))
1139 return hr; 1129 return hr;
1140 1130
1141 if (pointer.IsMouse()) { 1131 if (pointer.IsMouse()) {
1142 mouse_down_flags_ = ui::EF_NONE; 1132 mouse_down_flags_ = ui::EF_NONE;
1143 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, 1133 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED,
1144 static_cast<uint32>(pointer.changed_button()) | 1134 static_cast<uint32>(pointer.changed_button()) |
1145 GetKeyboardEventFlags(), 1135 GetKeyboardEventFlags(),
1146 pointer.changed_button(), 1136 pointer.changed_button(),
1147 pointer.is_horizontal_wheel()); 1137 pointer.is_horizontal_wheel());
1148 } else { 1138 } else {
1149 DCHECK(pointer.IsTouch()); 1139 DCHECK(pointer.IsTouch());
1150 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), 1140 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(),
1151 pointer.y(), 1141 pointer.y(),
1152 pointer.timestamp(), 1142 pointer.timestamp(),
1153 pointer.pointer_id())); 1143 pointer.pointer_id()));
1154 } 1144 }
1155 return S_OK; 1145 return S_OK;
1156 } 1146 }
1157 1147
1158 HRESULT ChromeAppViewAsh::OnWheel( 1148 HRESULT ChromeAppViewAsh::OnWheel(
1159 winui::Core::ICoreWindow* sender, 1149 winui::Core::ICoreWindow* sender,
1160 winui::Core::IPointerEventArgs* args) { 1150 winui::Core::IPointerEventArgs* args) {
1151 if (!ui_channel_)
1152 return S_OK;
1153
1161 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1154 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1162 HRESULT hr = pointer.Init(args); 1155 HRESULT hr = pointer.Init(args);
1163 if (FAILED(hr)) 1156 if (FAILED(hr))
1164 return hr; 1157 return hr;
1165 DCHECK(pointer.IsMouse()); 1158 DCHECK(pointer.IsMouse());
1166 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), 1159 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(),
1167 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE, 1160 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE,
1168 pointer.is_horizontal_wheel()); 1161 pointer.is_horizontal_wheel());
1169 return S_OK; 1162 return S_OK;
1170 } 1163 }
1171 1164
1172 HRESULT ChromeAppViewAsh::OnKeyDown( 1165 HRESULT ChromeAppViewAsh::OnKeyDown(
1173 winui::Core::ICoreWindow* sender, 1166 winui::Core::ICoreWindow* sender,
1174 winui::Core::IKeyEventArgs* args) { 1167 winui::Core::IKeyEventArgs* args) {
1168 if (!ui_channel_)
1169 return S_OK;
1170
1175 winsys::VirtualKey virtual_key; 1171 winsys::VirtualKey virtual_key;
1176 HRESULT hr = args->get_VirtualKey(&virtual_key); 1172 HRESULT hr = args->get_VirtualKey(&virtual_key);
1177 if (FAILED(hr)) 1173 if (FAILED(hr))
1178 return hr; 1174 return hr;
1179 winui::Core::CorePhysicalKeyStatus status; 1175 winui::Core::CorePhysicalKeyStatus status;
1180 hr = args->get_KeyStatus(&status); 1176 hr = args->get_KeyStatus(&status);
1181 if (FAILED(hr)) 1177 if (FAILED(hr))
1182 return hr; 1178 return hr;
1183 1179
1184 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key, 1180 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key,
1185 status.RepeatCount, 1181 status.RepeatCount,
1186 status.ScanCode, 1182 status.ScanCode,
1187 GetKeyboardEventFlags())); 1183 GetKeyboardEventFlags()));
1188 return S_OK; 1184 return S_OK;
1189 } 1185 }
1190 1186
1191 HRESULT ChromeAppViewAsh::OnKeyUp( 1187 HRESULT ChromeAppViewAsh::OnKeyUp(
1192 winui::Core::ICoreWindow* sender, 1188 winui::Core::ICoreWindow* sender,
1193 winui::Core::IKeyEventArgs* args) { 1189 winui::Core::IKeyEventArgs* args) {
1190 if (!ui_channel_)
1191 return S_OK;
1192
1194 winsys::VirtualKey virtual_key; 1193 winsys::VirtualKey virtual_key;
1195 HRESULT hr = args->get_VirtualKey(&virtual_key); 1194 HRESULT hr = args->get_VirtualKey(&virtual_key);
1196 if (FAILED(hr)) 1195 if (FAILED(hr))
1197 return hr; 1196 return hr;
1198 winui::Core::CorePhysicalKeyStatus status; 1197 winui::Core::CorePhysicalKeyStatus status;
1199 hr = args->get_KeyStatus(&status); 1198 hr = args->get_KeyStatus(&status);
1200 if (FAILED(hr)) 1199 if (FAILED(hr))
1201 return hr; 1200 return hr;
1202 1201
1203 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key, 1202 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key,
1204 status.RepeatCount, 1203 status.RepeatCount,
1205 status.ScanCode, 1204 status.ScanCode,
1206 GetKeyboardEventFlags())); 1205 GetKeyboardEventFlags()));
1207 return S_OK; 1206 return S_OK;
1208 } 1207 }
1209 1208
1210 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown( 1209 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown(
1211 winui::Core::ICoreDispatcher* sender, 1210 winui::Core::ICoreDispatcher* sender,
1212 winui::Core::IAcceleratorKeyEventArgs* args) { 1211 winui::Core::IAcceleratorKeyEventArgs* args) {
1212 if (!ui_channel_)
1213 return S_OK;
1214
1213 winsys::VirtualKey virtual_key; 1215 winsys::VirtualKey virtual_key;
1214 HRESULT hr = args->get_VirtualKey(&virtual_key); 1216 HRESULT hr = args->get_VirtualKey(&virtual_key);
1215 if (FAILED(hr)) 1217 if (FAILED(hr))
1216 return hr; 1218 return hr;
1217 winui::Core::CorePhysicalKeyStatus status; 1219 winui::Core::CorePhysicalKeyStatus status;
1218 hr = args->get_KeyStatus(&status); 1220 hr = args->get_KeyStatus(&status);
1219 if (FAILED(hr)) 1221 if (FAILED(hr))
1220 return hr; 1222 return hr;
1221 1223
1222 winui::Core::CoreAcceleratorKeyEventType event_type; 1224 winui::Core::CoreAcceleratorKeyEventType event_type;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1259
1258 default: 1260 default:
1259 break; 1261 break;
1260 } 1262 }
1261 return S_OK; 1263 return S_OK;
1262 } 1264 }
1263 1265
1264 HRESULT ChromeAppViewAsh::OnCharacterReceived( 1266 HRESULT ChromeAppViewAsh::OnCharacterReceived(
1265 winui::Core::ICoreWindow* sender, 1267 winui::Core::ICoreWindow* sender,
1266 winui::Core::ICharacterReceivedEventArgs* args) { 1268 winui::Core::ICharacterReceivedEventArgs* args) {
1269 if (!ui_channel_)
1270 return S_OK;
1271
1267 unsigned int char_code = 0; 1272 unsigned int char_code = 0;
1268 HRESULT hr = args->get_KeyCode(&char_code); 1273 HRESULT hr = args->get_KeyCode(&char_code);
1269 if (FAILED(hr)) 1274 if (FAILED(hr))
1270 return hr; 1275 return hr;
1271 1276
1272 winui::Core::CorePhysicalKeyStatus status; 1277 winui::Core::CorePhysicalKeyStatus status;
1273 hr = args->get_KeyStatus(&status); 1278 hr = args->get_KeyStatus(&status);
1274 if (FAILED(hr)) 1279 if (FAILED(hr))
1275 return hr; 1280 return hr;
1276 1281
1277 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code, 1282 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code,
1278 status.RepeatCount, 1283 status.RepeatCount,
1279 status.ScanCode, 1284 status.ScanCode,
1280 GetKeyboardEventFlags())); 1285 GetKeyboardEventFlags()));
1281 return S_OK; 1286 return S_OK;
1282 } 1287 }
1283 1288
1284 HRESULT ChromeAppViewAsh::OnWindowActivated( 1289 HRESULT ChromeAppViewAsh::OnWindowActivated(
1285 winui::Core::ICoreWindow* sender, 1290 winui::Core::ICoreWindow* sender,
1286 winui::Core::IWindowActivatedEventArgs* args) { 1291 winui::Core::IWindowActivatedEventArgs* args) {
1292 if (!ui_channel_)
1293 return S_OK;
1294
1287 if (args) { 1295 if (args) {
1288 winui::Core::CoreWindowActivationState state; 1296 winui::Core::CoreWindowActivationState state;
1289 HRESULT hr = args->get_WindowActivationState(&state); 1297 HRESULT hr = args->get_WindowActivationState(&state);
1290 if (FAILED(hr)) 1298 if (FAILED(hr))
1291 return hr; 1299 return hr;
1292 1300
1293 // Treat both full activation (Ash was reopened from the Start Screen or 1301 // Treat both full activation (Ash was reopened from the Start Screen or
1294 // from any other Metro entry point in Windows) and pointer activation 1302 // from any other Metro entry point in Windows) and pointer activation
1295 // (user clicked back in Ash after using another app on another monitor) 1303 // (user clicked back in Ash after using another app on another monitor)
1296 // the same. 1304 // the same.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 ui_loop_.PostTask(FROM_HERE, 1359 ui_loop_.PostTask(FROM_HERE,
1352 base::Bind(&ChromeAppViewAsh::OnNavigateToUrl, 1360 base::Bind(&ChromeAppViewAsh::OnNavigateToUrl,
1353 base::Unretained(this), 1361 base::Unretained(this),
1354 actual_url)); 1362 actual_url));
1355 return S_OK; 1363 return S_OK;
1356 } 1364 }
1357 1365
1358 HRESULT ChromeAppViewAsh::OnEdgeGestureCompleted( 1366 HRESULT ChromeAppViewAsh::OnEdgeGestureCompleted(
1359 winui::Input::IEdgeGesture* gesture, 1367 winui::Input::IEdgeGesture* gesture,
1360 winui::Input::IEdgeGestureEventArgs* args) { 1368 winui::Input::IEdgeGestureEventArgs* args) {
1361 ui_channel_->Send(new MetroViewerHostMsg_EdgeGesture()); 1369 if (ui_channel_)
1370 ui_channel_->Send(new MetroViewerHostMsg_EdgeGesture());
1362 return S_OK; 1371 return S_OK;
1363 } 1372 }
1364 1373
1365 void ChromeAppViewAsh::OnSearchRequest(const base::string16& search_string) { 1374 void ChromeAppViewAsh::OnSearchRequest(const base::string16& search_string) {
1366 DCHECK(ui_channel_); 1375 if (ui_channel_)
1367 ui_channel_->Send(new MetroViewerHostMsg_SearchRequest(search_string)); 1376 ui_channel_->Send(new MetroViewerHostMsg_SearchRequest(search_string));
1368 } 1377 }
1369 1378
1370 void ChromeAppViewAsh::OnNavigateToUrl(const base::string16& url) { 1379 void ChromeAppViewAsh::OnNavigateToUrl(const base::string16& url) {
1371 DCHECK(ui_channel_); 1380 if (ui_channel_)
1372 ui_channel_->Send(new MetroViewerHostMsg_OpenURL(url)); 1381 ui_channel_->Send(new MetroViewerHostMsg_OpenURL(url));
1373 } 1382 }
1374 1383
1375 HRESULT ChromeAppViewAsh::OnSizeChanged(winui::Core::ICoreWindow* sender, 1384 HRESULT ChromeAppViewAsh::OnSizeChanged(winui::Core::ICoreWindow* sender,
1376 winui::Core::IWindowSizeChangedEventArgs* args) { 1385 winui::Core::IWindowSizeChangedEventArgs* args) {
1377 if (!window_) { 1386 if (!window_) {
1378 return S_OK; 1387 return S_OK;
1379 } 1388 }
1380 1389
1381 // winui::Core::IWindowSizeChangedEventArgs args->Size appears to return 1390 // winui::Core::IWindowSizeChangedEventArgs args->Size appears to return
1382 // scaled values under HiDPI. We will instead use GetWindowRect() which 1391 // scaled values under HiDPI. We will instead use GetWindowRect() which
1383 // should always return values in Pixels. 1392 // should always return values in Pixels.
1384 RECT rect = {0}; 1393 RECT rect = {0};
1385 ::GetWindowRect(core_window_hwnd_, &rect); 1394 ::GetWindowRect(core_window_hwnd_, &rect);
1386 1395
1387 uint32 cx = static_cast<uint32>(rect.right - rect.left); 1396 uint32 cx = static_cast<uint32>(rect.right - rect.left);
1388 uint32 cy = static_cast<uint32>(rect.bottom - rect.top); 1397 uint32 cy = static_cast<uint32>(rect.bottom - rect.top);
1389 1398
1390 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy; 1399 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy;
1391 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy)); 1400 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy));
1392 return S_OK; 1401 return S_OK;
1393 } 1402 }
1394 1403
1404 // static
1405 void CALLBACK ChromeAppViewAsh::StartChromeOSMode(HWND core_window,
1406 UINT message,
1407 UINT_PTR timer_id,
1408 DWORD time) {
1409 static int ms_elapsed = 0;
1410 if (!IPC::Channel::IsNamedServerInitialized(
1411 win8::kMetroViewerIPCChannelName) && ms_elapsed < 10000) {
1412 ms_elapsed += 100;
1413 return;
1414 }
1415
1416 ::KillTimer(core_window, kChromeChannelPollTimerId);
1417
1418 if (!IPC::Channel::IsNamedServerInitialized(
1419 win8::kMetroViewerIPCChannelName)) {
1420 DVLOG(1) << "Failed to connect to chrome channel : "
1421 << win8::kMetroViewerIPCChannelName;
1422 DVLOG(1) << "Exiting. Elapsed time :" << ms_elapsed;
1423 PostMessage(core_window, WM_CLOSE, 0, 0);
1424 return;
1425 }
1426
1427 DVLOG(1) << "Found channel : " << win8::kMetroViewerIPCChannelName;
1428
1429 DCHECK(g_instance_);
1430 DCHECK(g_instance_->channel_listener_);
1431
1432 // In Aura mode we create an IPC channel to the browser, then ask it to
1433 // connect to us.
1434 g_instance_->ui_channel_ =
1435 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName,
1436 IPC::Channel::MODE_NAMED_CLIENT,
1437 g_instance_->channel_listener_,
1438 g_instance_->io_thread_->message_loop_proxy());
1439 DVLOG(1) << "Created channel proxy";
1440
1441 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the
1442 // browser will use D3D from the browser process to present to our Window.
1443 g_instance_->ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface(
1444 gfx::NativeViewId(core_window),
1445 g_instance_->win32_dpi_scale_));
1446 DVLOG(1) << "ICoreWindow sent " << core_window;
1447
1448 // Send an initial size message so that the Ash root window host gets sized
1449 // correctly.
1450 RECT rect = {0};
1451 ::GetWindowRect(core_window, &rect);
1452 g_instance_->ui_channel_->Send(
1453 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left,
1454 rect.bottom - rect.top));
1455
1456 g_instance_->input_source_ = metro_driver::InputSource::Create();
1457 if (g_instance_->input_source_) {
1458 g_instance_->input_source_->AddObserver(g_instance_);
1459 // Send an initial input source.
1460 g_instance_->OnInputSourceChanged();
1461 }
1462
1463 // Start receiving IME popup window notifications.
1464 metro_driver::AddImePopupObserver(g_instance_);
1465
1466 DVLOG(1) << "Channel setup complete";
1467 }
1468
1395 /////////////////////////////////////////////////////////////////////////////// 1469 ///////////////////////////////////////////////////////////////////////////////
1396 1470
1397 ChromeAppViewFactory::ChromeAppViewFactory( 1471 ChromeAppViewFactory::ChromeAppViewFactory(
1398 winapp::Core::ICoreApplication* icore_app) { 1472 winapp::Core::ICoreApplication* icore_app) {
1399 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); 1473 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app);
1400 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; 1474 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit;
1401 CheckHR(core_app.As(&app_exit)); 1475 CheckHR(core_app.As(&app_exit));
1402 globals.app_exit = app_exit.Detach(); 1476 globals.app_exit = app_exit.Detach();
1403 } 1477 }
1404 1478
1405 IFACEMETHODIMP 1479 IFACEMETHODIMP
1406 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { 1480 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) {
1407 *view = mswr::Make<ChromeAppViewAsh>().Detach(); 1481 *view = mswr::Make<ChromeAppViewAsh>().Detach();
1408 return (*view) ? S_OK : E_OUTOFMEMORY; 1482 return (*view) ? S_OK : E_OUTOFMEMORY;
1409 } 1483 }
OLDNEW
« no previous file with comments | « win8/metro_driver/chrome_app_view_ash.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698