Chromium Code Reviews| Index: win8/metro_driver/chrome_app_view.cc |
| diff --git a/win8/metro_driver/chrome_app_view.cc b/win8/metro_driver/chrome_app_view.cc |
| index f926f286f08310e08655d31d6a97c4c3a999a119..6b34c85047918aa9f67d884f97696b335efaa5c1 100644 |
| --- a/win8/metro_driver/chrome_app_view.cc |
| +++ b/win8/metro_driver/chrome_app_view.cc |
| @@ -4,6 +4,7 @@ |
| #include "win8/metro_driver/stdafx.h" |
| #include "win8/metro_driver/chrome_app_view.h" |
| +#include "win8/metro_driver/direct3d_helper.h" |
| #include <algorithm> |
| #include <windows.applicationModel.datatransfer.h> |
| @@ -13,11 +14,50 @@ |
| #include "base/message_loop.h" |
| #include "base/win/metro.h" |
| +#include "base/threading/thread.h" |
| +#include "ipc/ipc_channel.h" |
| +#include "ipc/ipc_channel_proxy.h" |
| +#include "ipc/ipc_sender.h" |
| + |
| // This include allows to send WM_SYSCOMMANDs to chrome. |
| #include "chrome/app/chrome_command_ids.h" |
| #include "win8/metro_driver/winrt_utils.h" |
| #include "ui/base/ui_base_switches.h" |
| +//============================================================================= |
| + |
|
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
|
| +// Get basic type definitions. |
| +#define IPC_MESSAGE_IMPL |
| +#include "chrome/common/viewer_messages.h" |
| + |
| +// Generate constructors. |
| +#include "ipc/struct_constructor_macros.h" |
| +#include "chrome/common/viewer_messages.h" |
| + |
| +// Generate destructors. |
| +#include "ipc/struct_destructor_macros.h" |
| +#include "chrome/common/viewer_messages.h" |
| + |
| +// Generate param traits write methods. |
| +#include "ipc/param_traits_write_macros.h" |
| +namespace IPC { |
| +#include "chrome/common/viewer_messages.h" |
| +} // namespace IPC |
| + |
| +// Generate param traits read methods. |
| +#include "ipc/param_traits_read_macros.h" |
| +namespace IPC { |
| +#include "chrome/common/viewer_messages.h" |
| +} // namespace IPC |
| + |
| +// Generate param traits log methods. |
| +#include "ipc/param_traits_log_macros.h" |
| +namespace IPC { |
| +#include "chrome/common/viewer_messages.h" |
| +} // namespace IPC |
| + |
| +//============================================================================= |
| + |
| typedef winfoundtn::ITypedEventHandler< |
| winapp::Core::CoreApplicationView*, |
| winapp::Activation::IActivatedEventArgs*> ActivatedHandler; |
| @@ -270,6 +310,26 @@ void FlipFrameWindowsInternal() { |
| } |
| } |
| +class ChromeChannelListener : public IPC::Listener { |
| + public: |
| + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| + DVLOG(1) << "Received ipc message " << message.type(); |
| + return true; |
| + } |
| + |
| + virtual void OnChannelError() OVERRIDE { |
| + DVLOG(1) << "Channel error"; |
| + MessageLoop::current()->Quit(); |
| + } |
| + |
| + void Init(IPC::Sender* s) { |
| + sender_ = s; |
| + } |
| + |
| + private: |
| + IPC::Sender* sender_; |
| +}; |
| + |
| } // namespace |
| HRESULT ChromeAppView::TileRequestCreateDone( |
| @@ -703,6 +763,10 @@ ChromeAppView::SetWindow(winui::Core::ICoreWindow* window) { |
| DVLOG(1) << "Created appview instance."; |
| + direct3d_helper_.Initialize(window); |
| + |
| + DVLOG(1) << "Initialized Direct3D."; |
| + |
| hr = devices_handler_.Initialize(window); |
| // Don't check or return the failure here, we need to let the app |
| // initialization succeed. Even if we won't be able to access devices |
| @@ -772,6 +836,16 @@ void ChromeAppView::CheckForOSKActivation() { |
| base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
| } |
| +void SendHwnd(base::Thread* thread, HWND hwnd) { |
| + ChromeChannelListener channel_listener; |
| + 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.
|
| + &channel_listener, thread->message_loop_proxy()); |
| + channel_listener.Init(&chan); |
| + chan.Send(new ViewerHostMsg_SetTargetSurface(uint32(hwnd))); |
| + |
| + DVLOG(1) << "ICoreWindow sent " << hwnd; |
| +} |
| + |
| IFACEMETHODIMP |
| ChromeAppView::Run() { |
| DVLOG(1) << __FUNCTION__ << ", hwnd=" << LONG_PTR(window_.Get()); |
| @@ -786,6 +860,16 @@ ChromeAppView::Run() { |
| DVLOG(1) << "Activate failed, hr=" << hr; |
| } |
| + // The thread needs to out-live the ChannelProxy. |
| + base::Thread thread("metro_IO_thread"); |
| + base::Thread::Options options; |
| + options.message_loop_type = MessageLoop::TYPE_IO; |
| + thread.StartWithOptions(options); |
| + |
|
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.
|
| + thread.message_loop_proxy()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&SendHwnd, &thread, globals.core_window)); |
| + |
| // Create a message loop to allow message passing into this thread. |
| MessageLoop msg_loop(MessageLoop::TYPE_UI); |
| @@ -900,15 +984,20 @@ HRESULT ChromeAppView::OnActivate(winapp::Core::ICoreApplicationView*, |
| DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window; |
| - if (!globals.host_thread) { |
| - DWORD chrome_ui_thread_id = 0; |
| - globals.host_thread = |
| - ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, |
| - &chrome_ui_thread_id); |
| + if (GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState(VK_F11)) { |
|
scottmg
2012/09/28 22:14:28
Made it #if !defined(USE_AURA) instead
|
| + DVLOG(1) << "Using Shift-F11 debug hook, connecting to browser"; |
| + } else { |
| if (!globals.host_thread) { |
| - NOTREACHED() << "thread creation failed."; |
| - return E_UNEXPECTED; |
| + DWORD chrome_ui_thread_id = 0; |
| + globals.host_thread = |
| + ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, |
| + &chrome_ui_thread_id); |
| + |
| + if (!globals.host_thread) { |
| + NOTREACHED() << "thread creation failed."; |
| + return E_UNEXPECTED; |
| + } |
| } |
| } |