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 #include "ui/gfx/native_widget_types.h" |
| 22 #include "ui/metro_viewer/metro_viewer_messages.h" |
| 23 |
16 // This include allows to send WM_SYSCOMMANDs to chrome. | 24 // This include allows to send WM_SYSCOMMANDs to chrome. |
17 #include "chrome/app/chrome_command_ids.h" | 25 #include "chrome/app/chrome_command_ids.h" |
18 #include "win8/metro_driver/winrt_utils.h" | 26 #include "win8/metro_driver/winrt_utils.h" |
19 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
20 | 28 |
| 29 |
21 typedef winfoundtn::ITypedEventHandler< | 30 typedef winfoundtn::ITypedEventHandler< |
22 winapp::Core::CoreApplicationView*, | 31 winapp::Core::CoreApplicationView*, |
23 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; | 32 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
24 | 33 |
25 typedef winfoundtn::ITypedEventHandler< | 34 typedef winfoundtn::ITypedEventHandler< |
26 winui::Core::CoreWindow*, | 35 winui::Core::CoreWindow*, |
27 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; | 36 winui::Core::WindowSizeChangedEventArgs*> SizeChangedHandler; |
28 | 37 |
29 typedef winfoundtn::ITypedEventHandler< | 38 typedef winfoundtn::ITypedEventHandler< |
30 winui::Input::EdgeGesture*, | 39 winui::Input::EdgeGesture*, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 272 |
264 DVLOG(1) << "Hiding current top window:" | 273 DVLOG(1) << "Hiding current top window:" |
265 << reinterpret_cast<int>(current_top_window.first); | 274 << reinterpret_cast<int>(current_top_window.first); |
266 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs, | 275 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs, |
267 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE); | 276 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE); |
268 | 277 |
269 globals.host_windows.push_back(current_top_window); | 278 globals.host_windows.push_back(current_top_window); |
270 } | 279 } |
271 } | 280 } |
272 | 281 |
| 282 class ChromeChannelListener : public IPC::Listener { |
| 283 public: |
| 284 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 285 DVLOG(1) << "Received ipc message " << message.type(); |
| 286 return true; |
| 287 } |
| 288 |
| 289 virtual void OnChannelError() OVERRIDE { |
| 290 DVLOG(1) << "Channel error"; |
| 291 MessageLoop::current()->Quit(); |
| 292 } |
| 293 |
| 294 void Init(IPC::Sender* s) { |
| 295 sender_ = s; |
| 296 } |
| 297 |
| 298 private: |
| 299 IPC::Sender* sender_; |
| 300 }; |
| 301 |
273 } // namespace | 302 } // namespace |
274 | 303 |
275 HRESULT ChromeAppView::TileRequestCreateDone( | 304 HRESULT ChromeAppView::TileRequestCreateDone( |
276 winfoundtn::IAsyncOperation<bool>* async, | 305 winfoundtn::IAsyncOperation<bool>* async, |
277 AsyncStatus status) { | 306 AsyncStatus status) { |
278 if (status == Completed) { | 307 if (status == Completed) { |
279 unsigned char result; | 308 unsigned char result; |
280 CheckHR(async->GetResults(&result)); | 309 CheckHR(async->GetResults(&result)); |
281 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result); | 310 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result); |
282 } else { | 311 } 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. | 725 // chrome. Uncomment this once we figure out why they don't fire. |
697 // RegisterInputPaneNotifications(); | 726 // RegisterInputPaneNotifications(); |
698 | 727 |
699 hr = winrt_utils::CreateActivationFactory( | 728 hr = winrt_utils::CreateActivationFactory( |
700 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, | 729 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, |
701 app_view_.GetAddressOf()); | 730 app_view_.GetAddressOf()); |
702 CheckHR(hr); | 731 CheckHR(hr); |
703 | 732 |
704 DVLOG(1) << "Created appview instance."; | 733 DVLOG(1) << "Created appview instance."; |
705 | 734 |
| 735 direct3d_helper_.Initialize(window); |
| 736 |
| 737 DVLOG(1) << "Initialized Direct3D."; |
| 738 |
706 hr = devices_handler_.Initialize(window); | 739 hr = devices_handler_.Initialize(window); |
707 // Don't check or return the failure here, we need to let the app | 740 // 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 | 741 // initialization succeed. Even if we won't be able to access devices |
709 // we still want to allow the app to start. | 742 // we still want to allow the app to start. |
710 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; | 743 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; |
711 return S_OK; | 744 return S_OK; |
712 } | 745 } |
713 | 746 |
714 IFACEMETHODIMP | 747 IFACEMETHODIMP |
715 ChromeAppView::Load(HSTRING entryPoint) { | 748 ChromeAppView::Load(HSTRING entryPoint) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 } | 800 } |
768 MessageLoop::current()->PostDelayedTask( | 801 MessageLoop::current()->PostDelayedTask( |
769 FROM_HERE, | 802 FROM_HERE, |
770 base::Bind(&ChromeAppView::CheckForOSKActivation, | 803 base::Bind(&ChromeAppView::CheckForOSKActivation, |
771 base::Unretained(this)), | 804 base::Unretained(this)), |
772 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); | 805 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
773 } | 806 } |
774 | 807 |
775 IFACEMETHODIMP | 808 IFACEMETHODIMP |
776 ChromeAppView::Run() { | 809 ChromeAppView::Run() { |
777 DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get()); | 810 DVLOG(1) << __FUNCTION__; |
778 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; | 811 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; |
779 HRESULT hr = window_->get_Dispatcher(&dispatcher); | 812 HRESULT hr = window_->get_Dispatcher(&dispatcher); |
780 CheckHR(hr, "Dispatcher failed."); | 813 CheckHR(hr, "Dispatcher failed."); |
781 | 814 |
782 hr = window_->Activate(); | 815 hr = window_->Activate(); |
783 if (SUCCEEDED(hr)) { | 816 if (SUCCEEDED(hr)) { |
784 // TODO(cpu): Draw something here. | 817 // TODO(cpu): Draw something here. |
785 } else { | 818 } else { |
786 DVLOG(1) << "Activate failed, hr=" << hr; | 819 DVLOG(1) << "Activate failed, hr=" << hr; |
787 } | 820 } |
788 | 821 |
789 // Create a message loop to allow message passing into this thread. | 822 // Create a message loop to allow message passing into this thread. |
790 MessageLoop msg_loop(MessageLoop::TYPE_UI); | 823 MessageLoop msg_loop(MessageLoop::TYPE_UI); |
791 | 824 |
792 // Announce our message loop to the world. | 825 // Announce our message loop to the world. |
793 globals.appview_msg_loop = msg_loop.message_loop_proxy(); | 826 globals.appview_msg_loop = msg_loop.message_loop_proxy(); |
794 | 827 |
| 828 // The thread needs to out-live the ChannelProxy. |
| 829 base::Thread thread("metro_IO_thread"); |
| 830 base::Thread::Options options; |
| 831 options.message_loop_type = MessageLoop::TYPE_IO; |
| 832 thread.StartWithOptions(options); |
| 833 |
| 834 ChromeChannelListener channel_listener; |
| 835 IPC::ChannelProxy chan("viewer", IPC::Channel::MODE_NAMED_CLIENT, |
| 836 &channel_listener, thread.message_loop_proxy()); |
| 837 channel_listener.Init(&chan); |
| 838 chan.Send(new MetroViewerHostMsg_SetTargetSurface( |
| 839 gfx::NativeViewId(globals.core_window))); |
| 840 |
| 841 DVLOG(1) << "ICoreWindow sent " << globals.core_window; |
| 842 |
795 // And post the task that'll do the inner Metro message pumping to it. | 843 // 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())); | 844 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
797 | 845 |
798 // Post the recurring task which checks for OSK activation in metro chrome. | 846 // Post the recurring task which checks for OSK activation in metro chrome. |
799 // Please refer to the comments in the CheckForOSKActivation function for why | 847 // Please refer to the comments in the CheckForOSKActivation function for why |
800 // this is needed. | 848 // this is needed. |
801 // TODO(ananta) | 849 // TODO(ananta) |
802 // Take this out when the documented OSK notifications start working. | 850 // Take this out when the documented OSK notifications start working. |
803 msg_loop.PostDelayedTask( | 851 msg_loop.PostDelayedTask( |
804 FROM_HERE, | 852 FROM_HERE, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 return S_OK; | 941 return S_OK; |
894 } | 942 } |
895 | 943 |
896 do { | 944 do { |
897 ::Sleep(10); | 945 ::Sleep(10); |
898 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0); | 946 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0); |
899 } while (globals.core_window == NULL); | 947 } while (globals.core_window == NULL); |
900 | 948 |
901 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; | 949 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; |
902 | 950 |
| 951 |
| 952 #if !defined(USE_AURA) |
903 if (!globals.host_thread) { | 953 if (!globals.host_thread) { |
904 DWORD chrome_ui_thread_id = 0; | 954 DWORD chrome_ui_thread_id = 0; |
905 globals.host_thread = | 955 globals.host_thread = |
906 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, | 956 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, |
907 &chrome_ui_thread_id); | 957 &chrome_ui_thread_id); |
908 | 958 |
909 if (!globals.host_thread) { | 959 if (!globals.host_thread) { |
910 NOTREACHED() << "thread creation failed."; | 960 NOTREACHED() << "thread creation failed."; |
911 return E_UNEXPECTED; | 961 return E_UNEXPECTED; |
912 } | 962 } |
913 } | 963 } |
| 964 #endif |
914 | 965 |
915 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, | 966 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, |
916 MOD_CONTROL, VK_F12)) { | 967 MOD_CONTROL, VK_F12)) { |
917 DVLOG(1) << "Registered flip window hotkey."; | 968 DVLOG(1) << "Registered flip window hotkey."; |
918 } else { | 969 } else { |
919 VPLOG(1) << "Failed to register flip window hotkey."; | 970 VPLOG(1) << "Failed to register flip window hotkey."; |
920 } | 971 } |
921 HRESULT hr = settings_handler_.Initialize(); | 972 HRESULT hr = settings_handler_.Initialize(); |
922 CheckHR(hr,"Failed to initialize settings handler."); | 973 CheckHR(hr,"Failed to initialize settings handler."); |
923 return hr; | 974 return hr; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 CheckHR(core_app.As(&app_exit)); | 1233 CheckHR(core_app.As(&app_exit)); |
1183 globals.app_exit = app_exit.Detach(); | 1234 globals.app_exit = app_exit.Detach(); |
1184 } | 1235 } |
1185 | 1236 |
1186 IFACEMETHODIMP | 1237 IFACEMETHODIMP |
1187 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1238 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
1188 globals.view = mswr::Make<ChromeAppView>().Detach(); | 1239 globals.view = mswr::Make<ChromeAppView>().Detach(); |
1189 *view = globals.view; | 1240 *view = globals.view; |
1190 return (*view) ? S_OK : E_OUTOFMEMORY; | 1241 return (*view) ? S_OK : E_OUTOFMEMORY; |
1191 } | 1242 } |
OLD | NEW |