OLD | NEW |
---|---|
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.h" | 6 #include "win8/metro_driver/chrome_app_view.h" |
7 #include "win8/metro_driver/direct3d_helper.h" | |
7 | 8 |
8 #include <algorithm> | 9 #include <algorithm> |
9 #include <windows.applicationModel.datatransfer.h> | 10 #include <windows.applicationModel.datatransfer.h> |
10 #include <windows.foundation.h> | 11 #include <windows.foundation.h> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/win/metro.h" | 15 #include "base/win/metro.h" |
15 | 16 |
17 #include "base/threading/thread.h" | |
18 #include "ipc/ipc_channel.h" | |
19 #include "ipc/ipc_channel_proxy.h" | |
20 #include "ipc/ipc_sender.h" | |
21 | |
16 // This include allows to send WM_SYSCOMMANDs to chrome. | 22 // This include allows to send WM_SYSCOMMANDs to chrome. |
17 #include "chrome/app/chrome_command_ids.h" | 23 #include "chrome/app/chrome_command_ids.h" |
18 #include "win8/metro_driver/winrt_utils.h" | 24 #include "win8/metro_driver/winrt_utils.h" |
19 #include "ui/base/ui_base_switches.h" | 25 #include "ui/base/ui_base_switches.h" |
20 | 26 |
27 //============================================================================= | |
28 | |
cpu_(ooo_6.6-7.5)
2012/09/28 21:37:37
remove this 29 - 60 block.
scottmg
2012/09/28 22:14:28
moved to metro_viewer_messages.cc
| |
29 // Get basic type definitions. | |
30 #define IPC_MESSAGE_IMPL | |
31 #include "chrome/common/viewer_messages.h" | |
32 | |
33 // Generate constructors. | |
34 #include "ipc/struct_constructor_macros.h" | |
35 #include "chrome/common/viewer_messages.h" | |
36 | |
37 // Generate destructors. | |
38 #include "ipc/struct_destructor_macros.h" | |
39 #include "chrome/common/viewer_messages.h" | |
40 | |
41 // Generate param traits write methods. | |
42 #include "ipc/param_traits_write_macros.h" | |
43 namespace IPC { | |
44 #include "chrome/common/viewer_messages.h" | |
45 } // namespace IPC | |
46 | |
47 // Generate param traits read methods. | |
48 #include "ipc/param_traits_read_macros.h" | |
49 namespace IPC { | |
50 #include "chrome/common/viewer_messages.h" | |
51 } // namespace IPC | |
52 | |
53 // Generate param traits log methods. | |
54 #include "ipc/param_traits_log_macros.h" | |
55 namespace IPC { | |
56 #include "chrome/common/viewer_messages.h" | |
57 } // namespace IPC | |
58 | |
59 //============================================================================= | |
60 | |
21 typedef winfoundtn::ITypedEventHandler< | 61 typedef winfoundtn::ITypedEventHandler< |
22 winapp::Core::CoreApplicationView*, | 62 winapp::Core::CoreApplicationView*, |
23 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 63 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
24 | 64 |
25 typedef winfoundtn::ITypedEventHandler< | 65 typedef winfoundtn::ITypedEventHandler< |
26 winui::Core::CoreWindow*, | 66 winui::Core::CoreWindow*, |
27 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; | 67 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; |
28 | 68 |
29 typedef winfoundtn::ITypedEventHandler< | 69 typedef winfoundtn::ITypedEventHandler< |
30 winui::Input::EdgeGesture*, | 70 winui::Input::EdgeGesture*, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 | 303 |
264 DVLOG(1) << "Hiding current top window:" | 304 DVLOG(1) << "Hiding current top window:" |
265 << reinterpret_cast<int>(current_top_window.first); | 305 << reinterpret_cast<int>(current_top_window.first); |
266 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs, | 306 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs, |
267 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE); | 307 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE); |
268 | 308 |
269 globals.host_windows.push_back(current_top_window); | 309 globals.host_windows.push_back(current_top_window); |
270 } | 310 } |
271 } | 311 } |
272 | 312 |
313 class ChromeChannelListener : public IPC::Listener { | |
314 public: | |
315 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
316 DVLOG(1) << "Received ipc message " << message.type(); | |
317 return true; | |
318 } | |
319 | |
320 virtual void OnChannelError() OVERRIDE { | |
321 DVLOG(1) << "Channel error"; | |
322 MessageLoop::current()->Quit(); | |
323 } | |
324 | |
325 void Init(IPC::Sender* s) { | |
326 sender_ = s; | |
327 } | |
328 | |
329 private: | |
330 IPC::Sender* sender_; | |
331 }; | |
332 | |
273 } // namespace | 333 } // namespace |
274 | 334 |
275 HRESULT ChromeAppView::TileRequestCreateDone( | 335 HRESULT ChromeAppView::TileRequestCreateDone( |
276 winfoundtn::IAsyncOperation<bool>* async, | 336 winfoundtn::IAsyncOperation<bool>* async, |
277 AsyncStatus status) { | 337 AsyncStatus status) { |
278 if (status == Completed) { | 338 if (status == Completed) { |
279 unsigned char result; | 339 unsigned char result; |
280 CheckHR(async->GetResults(&result)); | 340 CheckHR(async->GetResults(&result)); |
281 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result); | 341 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result); |
282 } else { | 342 } else { |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 // chrome. Uncomment this once we figure out why they don't fire. | 756 // chrome. Uncomment this once we figure out why they don't fire. |
697 // RegisterInputPaneNotifications(); | 757 // RegisterInputPaneNotifications(); |
698 | 758 |
699 hr = winrt_utils::CreateActivationFactory( | 759 hr = winrt_utils::CreateActivationFactory( |
700 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, | 760 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, |
701 app_view_.GetAddressOf()); | 761 app_view_.GetAddressOf()); |
702 CheckHR(hr); | 762 CheckHR(hr); |
703 | 763 |
704 DVLOG(1) << "Created appview instance."; | 764 DVLOG(1) << "Created appview instance."; |
705 | 765 |
766 direct3d_helper_.Initialize(window); | |
767 | |
768 DVLOG(1) << "Initialized Direct3D."; | |
769 | |
706 hr = devices_handler_.Initialize(window); | 770 hr = devices_handler_.Initialize(window); |
707 // Don't check or return the failure here, we need to let the app | 771 // Don't check or return the failure here, we need to let the app |
708 // initialization succeed. Even if we won't be able to access devices | 772 // initialization succeed. Even if we won't be able to access devices |
709 // we still want to allow the app to start. | 773 // we still want to allow the app to start. |
710 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; | 774 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; |
711 return S_OK; | 775 return S_OK; |
712 } | 776 } |
713 | 777 |
714 IFACEMETHODIMP | 778 IFACEMETHODIMP |
715 ChromeAppView::Load(HSTRING entryPoint) { | 779 ChromeAppView::Load(HSTRING entryPoint) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 } | 829 } |
766 } | 830 } |
767 } | 831 } |
768 MessageLoop::current()->PostDelayedTask( | 832 MessageLoop::current()->PostDelayedTask( |
769 FROM_HERE, | 833 FROM_HERE, |
770 base::Bind(&ChromeAppView::CheckForOSKActivation, | 834 base::Bind(&ChromeAppView::CheckForOSKActivation, |
771 base::Unretained(this)), | 835 base::Unretained(this)), |
772 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); | 836 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
773 } | 837 } |
774 | 838 |
839 void SendHwnd(base::Thread* thread, HWND hwnd) { | |
840 ChromeChannelListener channel_listener; | |
841 IPC::ChannelProxy chan("viewer", IPC::Channel::MODE_NAMED_CLIENT, | |
cpu_(ooo_6.6-7.5)
2012/09/28 21:37:37
this is the reason the pipe closes, methinks.
scottmg
2012/09/28 22:14:28
Done.
| |
842 &channel_listener, thread->message_loop_proxy()); | |
843 channel_listener.Init(&chan); | |
844 chan.Send(new ViewerHostMsg_SetTargetSurface(uint32(hwnd))); | |
845 | |
846 DVLOG(1) << "ICoreWindow sent " << hwnd; | |
847 } | |
848 | |
775 IFACEMETHODIMP | 849 IFACEMETHODIMP |
776 ChromeAppView::Run() { | 850 ChromeAppView::Run() { |
777 DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get()); | 851 DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get()); |
778 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; | 852 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; |
779 HRESULT hr = window_->get_Dispatcher(&dispatcher); | 853 HRESULT hr = window_->get_Dispatcher(&dispatcher); |
780 CheckHR(hr, "Dispatcher failed."); | 854 CheckHR(hr, "Dispatcher failed."); |
781 | 855 |
782 hr = window_->Activate(); | 856 hr = window_->Activate(); |
783 if (SUCCEEDED(hr)) { | 857 if (SUCCEEDED(hr)) { |
784 // TODO(cpu): Draw something here. | 858 // TODO(cpu): Draw something here. |
785 } else { | 859 } else { |
786 DVLOG(1) << "Activate failed, hr=" << hr; | 860 DVLOG(1) << "Activate failed, hr=" << hr; |
787 } | 861 } |
788 | 862 |
863 // The thread needs to out-live the ChannelProxy. | |
864 base::Thread thread("metro_IO_thread"); | |
865 base::Thread::Options options; | |
866 options.message_loop_type = MessageLoop::TYPE_IO; | |
867 thread.StartWithOptions(options); | |
868 | |
cpu_(ooo_6.6-7.5)
2012/09/28 21:37:37
if we go back to my code with async message I thin
scottmg
2012/09/28 22:14:28
Done.
| |
869 thread.message_loop_proxy()->PostTask( | |
870 FROM_HERE, | |
871 base::Bind(&SendHwnd, &thread, globals.core_window)); | |
872 | |
789 // Create a message loop to allow message passing into this thread. | 873 // Create a message loop to allow message passing into this thread. |
790 MessageLoop msg_loop(MessageLoop::TYPE_UI); | 874 MessageLoop msg_loop(MessageLoop::TYPE_UI); |
791 | 875 |
792 // Announce our message loop to the world. | 876 // Announce our message loop to the world. |
793 globals.appview_msg_loop = msg_loop.message_loop_proxy(); | 877 globals.appview_msg_loop = msg_loop.message_loop_proxy(); |
794 | 878 |
795 // And post the task that'll do the inner Metro message pumping to it. | 879 // And post the task that'll do the inner Metro message pumping to it. |
796 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); | 880 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
797 | 881 |
798 // Post the recurring task which checks for OSK activation in metro chrome. | 882 // Post the recurring task which checks for OSK activation in metro chrome. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 return S_OK; | 977 return S_OK; |
894 } | 978 } |
895 | 979 |
896 do { | 980 do { |
897 ::Sleep(10); | 981 ::Sleep(10); |
898 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0); | 982 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0); |
899 } while (globals.core_window == NULL); | 983 } while (globals.core_window == NULL); |
900 | 984 |
901 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; | 985 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; |
902 | 986 |
903 if (!globals.host_thread) { | |
904 DWORD chrome_ui_thread_id = 0; | |
905 globals.host_thread = | |
906 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, | |
907 &chrome_ui_thread_id); | |
908 | 987 |
988 if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F11)) { | |
scottmg
2012/09/28 22:14:28
Made it #if !defined(USE_AURA) instead
| |
989 DVLOG(1) << "Using Shift-F11 debug hook, connecting to browser"; | |
990 } else { | |
909 if (!globals.host_thread) { | 991 if (!globals.host_thread) { |
910 NOTREACHED() << "thread creation failed."; | 992 DWORD chrome_ui_thread_id = 0; |
911 return E_UNEXPECTED; | 993 globals.host_thread = |
994 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, | |
995 &chrome_ui_thread_id); | |
996 | |
997 if (!globals.host_thread) { | |
998 NOTREACHED() << "thread creation failed."; | |
999 return E_UNEXPECTED; | |
1000 } | |
912 } | 1001 } |
913 } | 1002 } |
914 | 1003 |
915 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, | 1004 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, |
916 MOD_CONTROL, VK_F12)) { | 1005 MOD_CONTROL, VK_F12)) { |
917 DVLOG(1) << "Registered flip window hotkey."; | 1006 DVLOG(1) << "Registered flip window hotkey."; |
918 } else { | 1007 } else { |
919 VPLOG(1) << "Failed to register flip window hotkey."; | 1008 VPLOG(1) << "Failed to register flip window hotkey."; |
920 } | 1009 } |
921 HRESULT hr = settings_handler_.Initialize(); | 1010 HRESULT hr = settings_handler_.Initialize(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 CheckHR(core_app.As(&app_exit)); | 1271 CheckHR(core_app.As(&app_exit)); |
1183 globals.app_exit = app_exit.Detach(); | 1272 globals.app_exit = app_exit.Detach(); |
1184 } | 1273 } |
1185 | 1274 |
1186 IFACEMETHODIMP | 1275 IFACEMETHODIMP |
1187 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1276 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
1188 globals.view = mswr::Make<ChromeAppView>().Detach(); | 1277 globals.view = mswr::Make<ChromeAppView>().Detach(); |
1189 *view = globals.view; | 1278 *view = globals.view; |
1190 return (*view) ? S_OK : E_OUTOFMEMORY; | 1279 return (*view) ? S_OK : E_OUTOFMEMORY; |
1191 } | 1280 } |
OLD | NEW |