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

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

Issue 10984007: in-chrome viewer for metro (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debug code Created 8 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 | Annotate | Revision Log
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.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
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 305
266 DVLOG(1) << "Hiding current top window:" 306 DVLOG(1) << "Hiding current top window:"
267 << reinterpret_cast<int>(current_top_window.first); 307 << reinterpret_cast<int>(current_top_window.first);
268 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs, 308 AnimateWindow(current_top_window.first, kAnimateWindowTimeoutMs,
269 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE); 309 AW_HIDE | AW_HOR_POSITIVE | AW_SLIDE);
270 310
271 globals.host_windows.push_back(current_top_window); 311 globals.host_windows.push_back(current_top_window);
272 } 312 }
273 } 313 }
274 314
315 class ChromeChannelListener : public IPC::Listener {
316 public:
317 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
318 DVLOG(1) << "Received ipc message " << message.type();
319 return true;
320 }
321
322 virtual void OnChannelError() OVERRIDE {
323 DVLOG(1) << "Channel error";
324 MessageLoop::current()->Quit();
325 }
326
327 void Init(IPC::Sender* s) {
328 sender_ = s;
329 }
330
331 private:
332 IPC::Sender* sender_;
333 };
334
275 } // namespace 335 } // namespace
276 336
277 HRESULT ChromeAppView::TileRequestCreateDone( 337 HRESULT ChromeAppView::TileRequestCreateDone(
278 winfoundtn::IAsyncOperation<bool>* async, 338 winfoundtn::IAsyncOperation<bool>* async,
279 AsyncStatus status) { 339 AsyncStatus status) {
280 if (status == Completed) { 340 if (status == Completed) {
281 unsigned char result; 341 unsigned char result;
282 CheckHR(async->GetResults(&result)); 342 CheckHR(async->GetResults(&result));
283 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result); 343 DVLOG(1) << __FUNCTION__ << " result " << static_cast<int>(result);
284 } else { 344 } else {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // chrome. Uncomment this once we figure out why they don't fire. 758 // chrome. Uncomment this once we figure out why they don't fire.
699 // RegisterInputPaneNotifications(); 759 // RegisterInputPaneNotifications();
700 760
701 hr = winrt_utils::CreateActivationFactory( 761 hr = winrt_utils::CreateActivationFactory(
702 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, 762 RuntimeClass_Windows_UI_ViewManagement_ApplicationView,
703 app_view_.GetAddressOf()); 763 app_view_.GetAddressOf());
704 CheckHR(hr); 764 CheckHR(hr);
705 765
706 DVLOG(1) << "Created appview instance."; 766 DVLOG(1) << "Created appview instance.";
707 767
768 direct3d_helper_.Initialize(window);
769
770 DVLOG(1) << "Initialized Direct3D.";
771
708 hr = devices_handler_.Initialize(window); 772 hr = devices_handler_.Initialize(window);
709 // Don't check or return the failure here, we need to let the app 773 // Don't check or return the failure here, we need to let the app
710 // initialization succeed. Even if we won't be able to access devices 774 // initialization succeed. Even if we won't be able to access devices
711 // we still want to allow the app to start. 775 // we still want to allow the app to start.
712 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; 776 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler.";
713 return S_OK; 777 return S_OK;
714 } 778 }
715 779
716 IFACEMETHODIMP 780 IFACEMETHODIMP
717 ChromeAppView::Load(HSTRING entryPoint) { 781 ChromeAppView::Load(HSTRING entryPoint) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 } 831 }
768 } 832 }
769 } 833 }
770 MessageLoop::current()->PostDelayedTask( 834 MessageLoop::current()->PostDelayedTask(
771 FROM_HERE, 835 FROM_HERE,
772 base::Bind(&ChromeAppView::CheckForOSKActivation, 836 base::Bind(&ChromeAppView::CheckForOSKActivation,
773 base::Unretained(this)), 837 base::Unretained(this)),
774 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); 838 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs));
775 } 839 }
776 840
841 void SendHwnd(base::Thread* thread, HWND hwnd) {
842 ChromeChannelListener channel_listener;
843 IPC::ChannelProxy chan("viewer", IPC::Channel::MODE_NAMED_CLIENT,
844 &channel_listener, thread->message_loop_proxy());
845 DVLOG(1) << __FUNCTION__ << ", wee6";
846 channel_listener.Init(&chan);
847 DVLOG(1) << __FUNCTION__ << ", wee7";
848 chan.Send(new ViewerHostMsg_SetTargetSurface(uint32(hwnd)));
849 DVLOG(1) << __FUNCTION__ << ", wee8";
850
851 DVLOG(1) << "corewindow sent " << hwnd;
852 }
853
777 IFACEMETHODIMP 854 IFACEMETHODIMP
778 ChromeAppView::Run() { 855 ChromeAppView::Run() {
779 DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get()); 856 DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get());
780 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; 857 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher;
858 DVLOG(1) << __FUNCTION__ << ", wee0";
781 HRESULT hr = window_->get_Dispatcher(&dispatcher); 859 HRESULT hr = window_->get_Dispatcher(&dispatcher);
860 DVLOG(1) << __FUNCTION__ << ", wee1";
782 CheckHR(hr, "Dispatcher failed."); 861 CheckHR(hr, "Dispatcher failed.");
783 862
784 hr = window_->Activate(); 863 hr = window_->Activate();
864 DVLOG(1) << __FUNCTION__ << ", wee2";
785 if (SUCCEEDED(hr)) { 865 if (SUCCEEDED(hr)) {
786 // TODO(cpu): Draw something here. 866 // TODO(cpu): Draw something here.
787 } else { 867 } else {
788 DVLOG(1) << "Activate failed, hr=" << hr; 868 DVLOG(1) << "Activate failed, hr=" << hr;
789 } 869 }
870 DVLOG(1) << __FUNCTION__ << ", wee3";
871
872 // The thread needs to out-live the ChannelProxy.
873 base::Thread thread("metro_IO_thread");
874 base::Thread::Options options;
875 DVLOG(1) << __FUNCTION__ << ", wee4";
876 options.message_loop_type = MessageLoop::TYPE_IO;
877 thread.StartWithOptions(options);
878 DVLOG(1) << __FUNCTION__ << ", wee5";
879 DVLOG(1) << __FUNCTION__ << "message_loop: " << thread.message_loop();
880
881 thread.message_loop_proxy()->PostTask(
882 FROM_HERE,
883 base::Bind(&SendHwnd, &thread, globals.core_window));
790 884
791 // Create a message loop to allow message passing into this thread. 885 // Create a message loop to allow message passing into this thread.
792 MessageLoop msg_loop(MessageLoop::TYPE_UI); 886 MessageLoop msg_loop(MessageLoop::TYPE_UI);
793 887
794 // Announce our message loop to the world. 888 // Announce our message loop to the world.
795 globals.appview_msg_loop = msg_loop.message_loop_proxy(); 889 globals.appview_msg_loop = msg_loop.message_loop_proxy();
796 890
797 // And post the task that'll do the inner Metro message pumping to it. 891 // And post the task that'll do the inner Metro message pumping to it.
798 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); 892 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get()));
799 893
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 return S_OK; 989 return S_OK;
896 } 990 }
897 991
898 do { 992 do {
899 ::Sleep(10); 993 ::Sleep(10);
900 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0); 994 ::EnumThreadWindows(globals.main_thread_id, &CoreWindowFinder, 0);
901 } while (globals.core_window == NULL); 995 } while (globals.core_window == NULL);
902 996
903 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; 997 DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window;
904 998
999 #if 0
905 if (!globals.host_thread) { 1000 if (!globals.host_thread) {
906 DWORD chrome_ui_thread_id = 0; 1001 DWORD chrome_ui_thread_id = 0;
907 globals.host_thread = 1002 globals.host_thread =
908 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, 1003 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0,
909 &chrome_ui_thread_id); 1004 &chrome_ui_thread_id);
910 1005
911 if (!globals.host_thread) { 1006 if (!globals.host_thread) {
912 NOTREACHED() << "thread creation failed."; 1007 NOTREACHED() << "thread creation failed.";
913 return E_UNEXPECTED; 1008 return E_UNEXPECTED;
914 } 1009 }
915 1010
916 ::AttachThreadInput(chrome_ui_thread_id, globals.main_thread_id, TRUE); 1011 ::AttachThreadInput(chrome_ui_thread_id, globals.main_thread_id, TRUE);
917 } 1012 }
1013 #endif
918 1014
919 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, 1015 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId,
920 MOD_CONTROL, VK_F12)) { 1016 MOD_CONTROL, VK_F12)) {
921 DVLOG(1) << "Registered flip window hotkey."; 1017 DVLOG(1) << "Registered flip window hotkey.";
922 } else { 1018 } else {
923 VPLOG(1) << "Failed to register flip window hotkey."; 1019 VPLOG(1) << "Failed to register flip window hotkey.";
924 } 1020 }
925 HRESULT hr = settings_handler_.Initialize(); 1021 HRESULT hr = settings_handler_.Initialize();
926 CheckHR(hr,"Failed to initialize settings handler."); 1022 CheckHR(hr,"Failed to initialize settings handler.");
927 return hr; 1023 return hr;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 CheckHR(core_app.As(&app_exit)); 1282 CheckHR(core_app.As(&app_exit));
1187 globals.app_exit = app_exit.Detach(); 1283 globals.app_exit = app_exit.Detach();
1188 } 1284 }
1189 1285
1190 IFACEMETHODIMP 1286 IFACEMETHODIMP
1191 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { 1287 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) {
1192 globals.view = mswr::Make<ChromeAppView>().Detach(); 1288 globals.view = mswr::Make<ChromeAppView>().Detach();
1193 *view = globals.view; 1289 *view = globals.view;
1194 return (*view) ? S_OK : E_OUTOFMEMORY; 1290 return (*view) ? S_OK : E_OUTOFMEMORY;
1195 } 1291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698