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

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: Created 6 years, 3 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
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 static const wchar_t kChromeAppViewAshInstanceProp[] =
92 L"ChromeAppViewAshInstance";
93 static const wchar_t kChromeChannelListenerProp[] =
94 L"ChromeChannelListenerProp";
95
90 // Helper function to send keystrokes via the SendInput function. 96 // Helper function to send keystrokes via the SendInput function.
91 // mnemonic_char: The keystroke to be sent. 97 // mnemonic_char: The keystroke to be sent.
92 // modifiers: Combination with Alt, Ctrl, Shift, etc. 98 // modifiers: Combination with Alt, Ctrl, Shift, etc.
93 void SendKeySequence( 99 void SendKeySequence(
94 WORD mnemonic_char, KeyModifier modifiers) { 100 WORD mnemonic_char, KeyModifier modifiers) {
95 INPUT keys[4] = {0}; // Keyboard events 101 INPUT keys[4] = {0}; // Keyboard events
96 int key_count = 0; // Number of generated events 102 int key_count = 0; // Number of generated events
97 103
98 if (modifiers & SHIFT) { 104 if (modifiers & SHIFT) {
99 keys[key_count].type = INPUT_KEYBOARD; 105 keys[key_count].type = INPUT_KEYBOARD;
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 677 }
672 678
673 IFACEMETHODIMP 679 IFACEMETHODIMP
674 ChromeAppViewAsh::Run() { 680 ChromeAppViewAsh::Run() {
675 DVLOG(1) << __FUNCTION__; 681 DVLOG(1) << __FUNCTION__;
676 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; 682 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher;
677 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf()); 683 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf());
678 CheckHR(hr, "Dispatcher failed."); 684 CheckHR(hr, "Dispatcher failed.");
679 685
680 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy. 686 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy.
681 base::Thread io_thread("metro_IO_thread"); 687 io_thread_.reset(new base::Thread("metro_IO_thread"));
682 base::Thread::Options options; 688 base::Thread::Options options;
683 options.message_loop_type = base::MessageLoop::TYPE_IO; 689 options.message_loop_type = base::MessageLoop::TYPE_IO;
684 io_thread.StartWithOptions(options); 690 io_thread_->StartWithOptions(options);
685 691
686 // Start up Chrome and wait for the desired IPC server connection to exist. 692 ChromeChannelListener ui_channel_listener(&ui_loop_, this);
687 WaitForChromeIPCConnection(win8::kMetroViewerIPCChannelName);
688 693
689 // In Aura mode we create an IPC channel to the browser, then ask it to 694 // We can't do anything until the Chrome browser IPC channel is initialized.
690 // connect to us. 695 // Lazy initialization in a timer.
691 ChromeChannelListener ui_channel_listener(&ui_loop_, this); 696 ::SetProp(core_window_hwnd_, kChromeAppViewAshInstanceProp, this);
692 scoped_ptr<IPC::ChannelProxy> channel = 697 ::SetProp(core_window_hwnd_, kChromeChannelListenerProp,
693 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName, 698 &ui_channel_listener);
694 IPC::Channel::MODE_NAMED_CLIENT,
695 &ui_channel_listener,
696 io_thread.message_loop_proxy());
697 ui_channel_ = channel.get();
698 699
699 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the 700 UINT_PTR channel_setup_timer_id =
700 // browser will use D3D from the browser process to present to our Window. 701 ::SetTimer(core_window_hwnd_,
701 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( 702 kChromeChannelPollTimerId,
702 gfx::NativeViewId(core_window_hwnd_), win32_dpi_scale_)); 703 kChromeChannelPollTimerMs,
703 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; 704 &ChromeAppViewAsh::StartChromeOSMode);
704 705
705 // Send an initial size message so that the Ash root window host gets sized 706 // 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())); 707 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get()));
725 ui_loop_.Run(); 708 ui_loop_.Run();
726 709
710 io_thread_.reset(NULL);
711 ui_channel_.reset(NULL);
712
727 DVLOG(0) << "ProcessEvents done, hr=" << hr; 713 DVLOG(0) << "ProcessEvents done, hr=" << hr;
728 return hr; 714 return hr;
729 } 715 }
730 716
731 IFACEMETHODIMP 717 IFACEMETHODIMP
732 ChromeAppViewAsh::Uninitialize() { 718 ChromeAppViewAsh::Uninitialize() {
733 DVLOG(1) << __FUNCTION__; 719 DVLOG(1) << __FUNCTION__;
734 metro_driver::RemoveImePopupObserver(this); 720 metro_driver::RemoveImePopupObserver(this);
735 input_source_.reset(); 721 input_source_.reset();
736 text_service_.reset(); 722 text_service_.reset();
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 // in turn launches the chrome browser process in desktop mode via 1054 // in turn launches the chrome browser process in desktop mode via
1069 // ShellExecute. If we call ICoreWindow::Activate before this, then 1055 // ShellExecute. If we call ICoreWindow::Activate before this, then
1070 // Windows kills the metro chrome process when it calls ShellExecute. Seems 1056 // Windows kills the metro chrome process when it calls ShellExecute. Seems
1071 // to be a bug. 1057 // to be a bug.
1072 window_->Activate(); 1058 window_->Activate();
1073 return S_OK; 1059 return S_OK;
1074 } 1060 }
1075 1061
1076 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender, 1062 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender,
1077 winui::Core::IPointerEventArgs* args) { 1063 winui::Core::IPointerEventArgs* args) {
1064 if (!ui_channel_)
1065 return S_OK;
1066
1078 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1067 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1079 HRESULT hr = pointer.Init(args); 1068 HRESULT hr = pointer.Init(args);
1080 if (FAILED(hr)) 1069 if (FAILED(hr))
1081 return hr; 1070 return hr;
1082 1071
1083 if (pointer.IsMouse()) { 1072 if (pointer.IsMouse()) {
1084 // If the mouse was moved towards the charms or the OS specific section, 1073 // 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. 1074 // the cursor may change from what the browser last set. Restore it here.
1086 if (::GetCursor() != last_cursor_) 1075 if (::GetCursor() != last_cursor_)
1087 SetCursor(last_cursor_); 1076 SetCursor(last_cursor_);
(...skipping 15 matching lines...) Expand all
1103 1092
1104 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed 1093 // 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 1094 // event for the first button pressed and the last button released in a sequence
1106 // of mouse events. 1095 // of mouse events.
1107 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results 1096 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results
1108 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary 1097 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary
1109 // presses and releases are tracked in OnPointMoved(). 1098 // presses and releases are tracked in OnPointMoved().
1110 HRESULT ChromeAppViewAsh::OnPointerPressed( 1099 HRESULT ChromeAppViewAsh::OnPointerPressed(
1111 winui::Core::ICoreWindow* sender, 1100 winui::Core::ICoreWindow* sender,
1112 winui::Core::IPointerEventArgs* args) { 1101 winui::Core::IPointerEventArgs* args) {
1102 if (!ui_channel_)
1103 return S_OK;
1104
1113 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1105 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1114 HRESULT hr = pointer.Init(args); 1106 HRESULT hr = pointer.Init(args);
1115 if (FAILED(hr)) 1107 if (FAILED(hr))
1116 return hr; 1108 return hr;
1117 1109
1118 if (pointer.IsMouse()) { 1110 if (pointer.IsMouse()) {
1119 mouse_down_flags_ = pointer.mouse_down_flags(); 1111 mouse_down_flags_ = pointer.mouse_down_flags();
1120 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, 1112 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED,
1121 mouse_down_flags_ | GetKeyboardEventFlags(), 1113 mouse_down_flags_ | GetKeyboardEventFlags(),
1122 pointer.changed_button(), pointer.is_horizontal_wheel()); 1114 pointer.changed_button(), pointer.is_horizontal_wheel());
1123 } else { 1115 } else {
1124 DCHECK(pointer.IsTouch()); 1116 DCHECK(pointer.IsTouch());
1125 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), 1117 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(),
1126 pointer.y(), 1118 pointer.y(),
1127 pointer.timestamp(), 1119 pointer.timestamp(),
1128 pointer.pointer_id())); 1120 pointer.pointer_id()));
1129 } 1121 }
1130 return S_OK; 1122 return S_OK;
1131 } 1123 }
1132 1124
1133 HRESULT ChromeAppViewAsh::OnPointerReleased( 1125 HRESULT ChromeAppViewAsh::OnPointerReleased(
1134 winui::Core::ICoreWindow* sender, 1126 winui::Core::ICoreWindow* sender,
1135 winui::Core::IPointerEventArgs* args) { 1127 winui::Core::IPointerEventArgs* args) {
1128 if (!ui_channel_)
1129 return S_OK;
1130
1136 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1131 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1137 HRESULT hr = pointer.Init(args); 1132 HRESULT hr = pointer.Init(args);
1138 if (FAILED(hr)) 1133 if (FAILED(hr))
1139 return hr; 1134 return hr;
1140 1135
1141 if (pointer.IsMouse()) { 1136 if (pointer.IsMouse()) {
1142 mouse_down_flags_ = ui::EF_NONE; 1137 mouse_down_flags_ = ui::EF_NONE;
1143 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, 1138 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED,
1144 static_cast<uint32>(pointer.changed_button()) | 1139 static_cast<uint32>(pointer.changed_button()) |
1145 GetKeyboardEventFlags(), 1140 GetKeyboardEventFlags(),
1146 pointer.changed_button(), 1141 pointer.changed_button(),
1147 pointer.is_horizontal_wheel()); 1142 pointer.is_horizontal_wheel());
1148 } else { 1143 } else {
1149 DCHECK(pointer.IsTouch()); 1144 DCHECK(pointer.IsTouch());
1150 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), 1145 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(),
1151 pointer.y(), 1146 pointer.y(),
1152 pointer.timestamp(), 1147 pointer.timestamp(),
1153 pointer.pointer_id())); 1148 pointer.pointer_id()));
1154 } 1149 }
1155 return S_OK; 1150 return S_OK;
1156 } 1151 }
1157 1152
1158 HRESULT ChromeAppViewAsh::OnWheel( 1153 HRESULT ChromeAppViewAsh::OnWheel(
1159 winui::Core::ICoreWindow* sender, 1154 winui::Core::ICoreWindow* sender,
1160 winui::Core::IPointerEventArgs* args) { 1155 winui::Core::IPointerEventArgs* args) {
1156 if (!ui_channel_)
1157 return S_OK;
1158
1161 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); 1159 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_);
1162 HRESULT hr = pointer.Init(args); 1160 HRESULT hr = pointer.Init(args);
1163 if (FAILED(hr)) 1161 if (FAILED(hr))
1164 return hr; 1162 return hr;
1165 DCHECK(pointer.IsMouse()); 1163 DCHECK(pointer.IsMouse());
1166 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), 1164 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(),
1167 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE, 1165 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE,
1168 pointer.is_horizontal_wheel()); 1166 pointer.is_horizontal_wheel());
1169 return S_OK; 1167 return S_OK;
1170 } 1168 }
1171 1169
1172 HRESULT ChromeAppViewAsh::OnKeyDown( 1170 HRESULT ChromeAppViewAsh::OnKeyDown(
1173 winui::Core::ICoreWindow* sender, 1171 winui::Core::ICoreWindow* sender,
1174 winui::Core::IKeyEventArgs* args) { 1172 winui::Core::IKeyEventArgs* args) {
1173 if (!ui_channel_)
1174 return S_OK;
1175
1175 winsys::VirtualKey virtual_key; 1176 winsys::VirtualKey virtual_key;
1176 HRESULT hr = args->get_VirtualKey(&virtual_key); 1177 HRESULT hr = args->get_VirtualKey(&virtual_key);
1177 if (FAILED(hr)) 1178 if (FAILED(hr))
1178 return hr; 1179 return hr;
1179 winui::Core::CorePhysicalKeyStatus status; 1180 winui::Core::CorePhysicalKeyStatus status;
1180 hr = args->get_KeyStatus(&status); 1181 hr = args->get_KeyStatus(&status);
1181 if (FAILED(hr)) 1182 if (FAILED(hr))
1182 return hr; 1183 return hr;
1183 1184
1184 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key, 1185 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key,
1185 status.RepeatCount, 1186 status.RepeatCount,
1186 status.ScanCode, 1187 status.ScanCode,
1187 GetKeyboardEventFlags())); 1188 GetKeyboardEventFlags()));
1188 return S_OK; 1189 return S_OK;
1189 } 1190 }
1190 1191
1191 HRESULT ChromeAppViewAsh::OnKeyUp( 1192 HRESULT ChromeAppViewAsh::OnKeyUp(
1192 winui::Core::ICoreWindow* sender, 1193 winui::Core::ICoreWindow* sender,
1193 winui::Core::IKeyEventArgs* args) { 1194 winui::Core::IKeyEventArgs* args) {
1195 if (!ui_channel_)
1196 return S_OK;
1197
1194 winsys::VirtualKey virtual_key; 1198 winsys::VirtualKey virtual_key;
1195 HRESULT hr = args->get_VirtualKey(&virtual_key); 1199 HRESULT hr = args->get_VirtualKey(&virtual_key);
1196 if (FAILED(hr)) 1200 if (FAILED(hr))
1197 return hr; 1201 return hr;
1198 winui::Core::CorePhysicalKeyStatus status; 1202 winui::Core::CorePhysicalKeyStatus status;
1199 hr = args->get_KeyStatus(&status); 1203 hr = args->get_KeyStatus(&status);
1200 if (FAILED(hr)) 1204 if (FAILED(hr))
1201 return hr; 1205 return hr;
1202 1206
1203 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key, 1207 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key,
1204 status.RepeatCount, 1208 status.RepeatCount,
1205 status.ScanCode, 1209 status.ScanCode,
1206 GetKeyboardEventFlags())); 1210 GetKeyboardEventFlags()));
1207 return S_OK; 1211 return S_OK;
1208 } 1212 }
1209 1213
1210 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown( 1214 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown(
1211 winui::Core::ICoreDispatcher* sender, 1215 winui::Core::ICoreDispatcher* sender,
1212 winui::Core::IAcceleratorKeyEventArgs* args) { 1216 winui::Core::IAcceleratorKeyEventArgs* args) {
1217 if (!ui_channel_)
1218 return S_OK;
1219
1213 winsys::VirtualKey virtual_key; 1220 winsys::VirtualKey virtual_key;
1214 HRESULT hr = args->get_VirtualKey(&virtual_key); 1221 HRESULT hr = args->get_VirtualKey(&virtual_key);
1215 if (FAILED(hr)) 1222 if (FAILED(hr))
1216 return hr; 1223 return hr;
1217 winui::Core::CorePhysicalKeyStatus status; 1224 winui::Core::CorePhysicalKeyStatus status;
1218 hr = args->get_KeyStatus(&status); 1225 hr = args->get_KeyStatus(&status);
1219 if (FAILED(hr)) 1226 if (FAILED(hr))
1220 return hr; 1227 return hr;
1221 1228
1222 winui::Core::CoreAcceleratorKeyEventType event_type; 1229 winui::Core::CoreAcceleratorKeyEventType event_type;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1264
1258 default: 1265 default:
1259 break; 1266 break;
1260 } 1267 }
1261 return S_OK; 1268 return S_OK;
1262 } 1269 }
1263 1270
1264 HRESULT ChromeAppViewAsh::OnCharacterReceived( 1271 HRESULT ChromeAppViewAsh::OnCharacterReceived(
1265 winui::Core::ICoreWindow* sender, 1272 winui::Core::ICoreWindow* sender,
1266 winui::Core::ICharacterReceivedEventArgs* args) { 1273 winui::Core::ICharacterReceivedEventArgs* args) {
1274 if (!ui_channel_)
1275 return S_OK;
1276
1267 unsigned int char_code = 0; 1277 unsigned int char_code = 0;
1268 HRESULT hr = args->get_KeyCode(&char_code); 1278 HRESULT hr = args->get_KeyCode(&char_code);
1269 if (FAILED(hr)) 1279 if (FAILED(hr))
1270 return hr; 1280 return hr;
1271 1281
1272 winui::Core::CorePhysicalKeyStatus status; 1282 winui::Core::CorePhysicalKeyStatus status;
1273 hr = args->get_KeyStatus(&status); 1283 hr = args->get_KeyStatus(&status);
1274 if (FAILED(hr)) 1284 if (FAILED(hr))
1275 return hr; 1285 return hr;
1276 1286
1277 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code, 1287 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code,
1278 status.RepeatCount, 1288 status.RepeatCount,
1279 status.ScanCode, 1289 status.ScanCode,
1280 GetKeyboardEventFlags())); 1290 GetKeyboardEventFlags()));
1281 return S_OK; 1291 return S_OK;
1282 } 1292 }
1283 1293
1284 HRESULT ChromeAppViewAsh::OnWindowActivated( 1294 HRESULT ChromeAppViewAsh::OnWindowActivated(
1285 winui::Core::ICoreWindow* sender, 1295 winui::Core::ICoreWindow* sender,
1286 winui::Core::IWindowActivatedEventArgs* args) { 1296 winui::Core::IWindowActivatedEventArgs* args) {
1297 if (!ui_channel_)
1298 return S_OK;
1299
1287 if (args) { 1300 if (args) {
1288 winui::Core::CoreWindowActivationState state; 1301 winui::Core::CoreWindowActivationState state;
1289 HRESULT hr = args->get_WindowActivationState(&state); 1302 HRESULT hr = args->get_WindowActivationState(&state);
1290 if (FAILED(hr)) 1303 if (FAILED(hr))
1291 return hr; 1304 return hr;
1292 1305
1293 // Treat both full activation (Ash was reopened from the Start Screen or 1306 // Treat both full activation (Ash was reopened from the Start Screen or
1294 // from any other Metro entry point in Windows) and pointer activation 1307 // from any other Metro entry point in Windows) and pointer activation
1295 // (user clicked back in Ash after using another app on another monitor) 1308 // (user clicked back in Ash after using another app on another monitor)
1296 // the same. 1309 // the same.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 ::GetWindowRect(core_window_hwnd_, &rect); 1398 ::GetWindowRect(core_window_hwnd_, &rect);
1386 1399
1387 uint32 cx = static_cast<uint32>(rect.right - rect.left); 1400 uint32 cx = static_cast<uint32>(rect.right - rect.left);
1388 uint32 cy = static_cast<uint32>(rect.bottom - rect.top); 1401 uint32 cy = static_cast<uint32>(rect.bottom - rect.top);
1389 1402
1390 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy; 1403 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy;
1391 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy)); 1404 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy));
1392 return S_OK; 1405 return S_OK;
1393 } 1406 }
1394 1407
1408 // static
1409 void CALLBACK ChromeAppViewAsh::StartChromeOSMode(HWND core_window,
1410 UINT message,
1411 UINT_PTR timer_id,
1412 DWORD time) {
1413 static int ms_elapsed = 0;
1414 if (!IPC::Channel::IsNamedServerInitialized(
scottmg 2014/09/24 02:40:32 WaitForChromeIPCConnection isn't used any more, sh
ananta 2014/09/24 18:22:33 Done.
1415 win8::kMetroViewerIPCChannelName) && ms_elapsed < 10000) {
1416 ms_elapsed += 100;
1417 return;
1418 }
1419
1420 if (!IPC::Channel::IsNamedServerInitialized(
1421 win8::kMetroViewerIPCChannelName)) {
1422 DVLOG(1) << "Failed to connect to chrome channel : "
1423 << win8::kMetroViewerIPCChannelName;
1424 DVLOG(1) << "Exiting...";
1425 PostMessage(core_window, WM_CLOSE, 0, 0);
1426 ::RemoveProp(core_window, kChromeAppViewAshInstanceProp);
scottmg 2014/09/24 02:40:32 why do we need window props instead of plain globa
ananta 2014/09/24 18:22:33 Good point. Done.
1427 ::RemoveProp(core_window, kChromeChannelListenerProp);
1428 ::KillTimer(core_window, kChromeChannelPollTimerId);
scottmg 2014/09/24 02:40:32 killtimer here and below can move out above the if
ananta 2014/09/24 18:22:33 Done.
1429 return;
1430 }
1431
1432 ::KillTimer(core_window, kChromeChannelPollTimerId);
1433
1434 DVLOG(1) << "Found channel : " << win8::kMetroViewerIPCChannelName;
1435
1436 ChromeAppViewAsh* instance = reinterpret_cast<ChromeAppViewAsh*>(
1437 ::GetProp(core_window, kChromeAppViewAshInstanceProp));
1438 DCHECK(instance);
1439
1440 ChromeChannelListener* listener = reinterpret_cast<ChromeChannelListener*>(
1441 ::GetProp(core_window, kChromeChannelListenerProp));
1442 DCHECK(listener);
1443
1444 // In Aura mode we create an IPC channel to the browser, then ask it to
1445 // connect to us.
1446 instance->ui_channel_ =
1447 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName,
1448 IPC::Channel::MODE_NAMED_CLIENT,
1449 listener,
1450 instance->io_thread_->message_loop_proxy());
1451 DVLOG(1) << "Created channel proxy";
1452
1453 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the
1454 // browser will use D3D from the browser process to present to our Window.
1455 instance->ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface(
1456 gfx::NativeViewId(core_window),
1457 instance->win32_dpi_scale_));
1458 DVLOG(1) << "ICoreWindow sent " << core_window;
1459
1460 // Send an initial size message so that the Ash root window host gets sized
1461 // correctly.
1462 RECT rect = {0};
1463 ::GetWindowRect(core_window, &rect);
1464 instance->ui_channel_->Send(
1465 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left,
1466 rect.bottom - rect.top));
1467
1468 instance->input_source_ = metro_driver::InputSource::Create();
1469 if (instance->input_source_) {
1470 instance->input_source_->AddObserver(instance);
1471 // Send an initial input source.
1472 instance->OnInputSourceChanged();
1473 }
1474
1475 // Start receiving IME popup window notifications.
1476 metro_driver::AddImePopupObserver(instance);
1477
1478 ::RemoveProp(core_window, kChromeAppViewAshInstanceProp);
1479 ::RemoveProp(core_window, kChromeChannelListenerProp);
1480
1481 DVLOG(1) << "Channel setup complete";
1482 }
1483
1395 /////////////////////////////////////////////////////////////////////////////// 1484 ///////////////////////////////////////////////////////////////////////////////
1396 1485
1397 ChromeAppViewFactory::ChromeAppViewFactory( 1486 ChromeAppViewFactory::ChromeAppViewFactory(
1398 winapp::Core::ICoreApplication* icore_app) { 1487 winapp::Core::ICoreApplication* icore_app) {
1399 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); 1488 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app);
1400 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; 1489 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit;
1401 CheckHR(core_app.As(&app_exit)); 1490 CheckHR(core_app.As(&app_exit));
1402 globals.app_exit = app_exit.Detach(); 1491 globals.app_exit = app_exit.Detach();
1403 } 1492 }
1404 1493
1405 IFACEMETHODIMP 1494 IFACEMETHODIMP
1406 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { 1495 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) {
1407 *view = mswr::Make<ChromeAppViewAsh>().Detach(); 1496 *view = mswr::Make<ChromeAppViewAsh>().Detach();
1408 return (*view) ? S_OK : E_OUTOFMEMORY; 1497 return (*view) ? S_OK : E_OUTOFMEMORY;
1409 } 1498 }
OLDNEW
« win8/metro_driver/chrome_app_view_ash.h ('K') | « 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