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_ash.h" | 6 #include "win8/metro_driver/chrome_app_view_ash.h" |
7 | 7 |
8 #include <windows.foundation.h> | 8 #include <windows.foundation.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 namespace { | 59 namespace { |
60 | 60 |
61 // TODO(robertshield): Share this with chrome_app_view.cc | 61 // TODO(robertshield): Share this with chrome_app_view.cc |
62 void MetroExit() { | 62 void MetroExit() { |
63 globals.app_exit->Exit(); | 63 globals.app_exit->Exit(); |
64 globals.core_window = NULL; | 64 globals.core_window = NULL; |
65 } | 65 } |
66 | 66 |
67 class ChromeChannelListener : public IPC::Listener { | 67 class ChromeChannelListener : public IPC::Listener { |
68 public: | 68 public: |
69 ChromeChannelListener(MessageLoop* ui_loop, ChromeAppViewAsh* app_view) | |
70 : ui_proxy_(ui_loop->message_loop_proxy()), | |
71 app_view_(app_view) { | |
72 } | |
73 | |
69 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
70 DVLOG(1) << "Received ipc message " << message.type(); | 75 IPC_BEGIN_MESSAGE_MAP(ChromeChannelListener, message) |
76 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor) | |
77 IPC_MESSAGE_UNHANDLED(__debugbreak()) | |
78 IPC_END_MESSAGE_MAP() | |
71 return true; | 79 return true; |
72 } | 80 } |
73 | 81 |
74 virtual void OnChannelError() OVERRIDE { | 82 virtual void OnChannelError() OVERRIDE { |
75 DVLOG(1) << "Channel error"; | 83 DVLOG(1) << "Channel error"; |
76 MetroExit(); | 84 MetroExit(); |
77 } | 85 } |
86 | |
87 private: | |
88 void OnSetCursor(int64 cursor) { | |
89 ui_proxy_->PostTask(FROM_HERE, | |
90 base::Bind(&ChromeAppViewAsh::OnSetCursor, | |
91 base::Unretained(app_view_), | |
92 reinterpret_cast<HCURSOR>(cursor))); | |
93 } | |
94 | |
95 scoped_refptr<base::MessageLoopProxy> ui_proxy_; | |
96 ChromeAppViewAsh* app_view_; | |
78 }; | 97 }; |
79 | 98 |
80 bool WaitForChromeIPCConnection(const std::string& channel_name) { | 99 bool WaitForChromeIPCConnection(const std::string& channel_name) { |
81 int ms_elapsed = 0; | 100 int ms_elapsed = 0; |
82 while (!IPC::Channel::IsNamedServerInitialized(channel_name) && | 101 while (!IPC::Channel::IsNamedServerInitialized(channel_name) && |
83 ms_elapsed < 10000) { | 102 ms_elapsed < 10000) { |
84 ms_elapsed += 500; | 103 ms_elapsed += 500; |
85 Sleep(500); | 104 Sleep(500); |
86 } | 105 } |
87 return IPC::Channel::IsNamedServerInitialized(channel_name); | 106 return IPC::Channel::IsNamedServerInitialized(channel_name); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 // TODO(robertshield): Figure out how to receive and append the channel ID | 327 // TODO(robertshield): Figure out how to receive and append the channel ID |
309 // from the delegate_execute instance that launched the browser process. | 328 // from the delegate_execute instance that launched the browser process. |
310 // See http://crbug.com/162474 | 329 // See http://crbug.com/162474 |
311 // ipc_channel_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); | 330 // ipc_channel_name.append(IPC::Channel::GenerateUniqueRandomChannelID()); |
312 | 331 |
313 // Start up Chrome and wait for the desired IPC server connection to exist. | 332 // Start up Chrome and wait for the desired IPC server connection to exist. |
314 WaitForChromeIPCConnection(ipc_channel_name); | 333 WaitForChromeIPCConnection(ipc_channel_name); |
315 | 334 |
316 // In Aura mode we create an IPC channel to the browser, then ask it to | 335 // In Aura mode we create an IPC channel to the browser, then ask it to |
317 // connect to us. | 336 // connect to us. |
318 ChromeChannelListener ui_channel_listener; | 337 ChromeChannelListener ui_channel_listener(&msg_loop, this); |
319 IPC::ChannelProxy ui_channel(ipc_channel_name, | 338 IPC::ChannelProxy ui_channel(ipc_channel_name, |
320 IPC::Channel::MODE_NAMED_CLIENT, | 339 IPC::Channel::MODE_NAMED_CLIENT, |
321 &ui_channel_listener, | 340 &ui_channel_listener, |
322 io_thread.message_loop_proxy()); | 341 io_thread.message_loop_proxy()); |
323 ui_channel_ = &ui_channel; | 342 ui_channel_ = &ui_channel; |
324 | 343 |
325 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( | 344 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( |
326 gfx::NativeViewId(globals.core_window))); | 345 gfx::NativeViewId(globals.core_window))); |
327 DVLOG(1) << "ICoreWindow sent " << globals.core_window; | 346 DVLOG(1) << "ICoreWindow sent " << globals.core_window; |
328 | 347 |
329 // And post the task that'll do the inner Metro message pumping to it. | 348 // And post the task that'll do the inner Metro message pumping to it. |
330 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); | 349 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
331 msg_loop.Run(); | 350 msg_loop.Run(); |
332 | 351 |
333 DVLOG(0) << "ProcessEvents done, hr=" << hr; | 352 DVLOG(0) << "ProcessEvents done, hr=" << hr; |
334 return hr; | 353 return hr; |
335 } | 354 } |
336 | 355 |
337 IFACEMETHODIMP | 356 IFACEMETHODIMP |
338 ChromeAppViewAsh::Uninitialize() { | 357 ChromeAppViewAsh::Uninitialize() { |
339 DVLOG(1) << __FUNCTION__; | 358 DVLOG(1) << __FUNCTION__; |
340 window_ = nullptr; | 359 window_ = nullptr; |
341 view_ = nullptr; | 360 view_ = nullptr; |
342 return S_OK; | 361 return S_OK; |
343 } | 362 } |
344 | 363 |
364 void ChromeAppViewAsh::OnSetCursor(HCURSOR cursor) { | |
365 ::SetCursor(HCURSOR(cursor)); | |
ananta
2012/12/11 00:17:30
replace with cursor
| |
366 } | |
367 | |
345 HRESULT ChromeAppViewAsh::OnActivate( | 368 HRESULT ChromeAppViewAsh::OnActivate( |
346 winapp::Core::ICoreApplicationView*, | 369 winapp::Core::ICoreApplicationView*, |
347 winapp::Activation::IActivatedEventArgs* args) { | 370 winapp::Activation::IActivatedEventArgs* args) { |
348 DVLOG(1) << __FUNCTION__; | 371 DVLOG(1) << __FUNCTION__; |
349 | 372 |
350 args->get_PreviousExecutionState(&globals.previous_state); | 373 args->get_PreviousExecutionState(&globals.previous_state); |
351 DVLOG(1) << "Previous Execution State: " << globals.previous_state; | 374 DVLOG(1) << "Previous Execution State: " << globals.previous_state; |
352 | 375 |
353 window_->Activate(); | 376 window_->Activate(); |
354 | 377 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 537 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
515 CheckHR(core_app.As(&app_exit)); | 538 CheckHR(core_app.As(&app_exit)); |
516 globals.app_exit = app_exit.Detach(); | 539 globals.app_exit = app_exit.Detach(); |
517 } | 540 } |
518 | 541 |
519 IFACEMETHODIMP | 542 IFACEMETHODIMP |
520 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 543 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
521 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 544 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
522 return (*view) ? S_OK : E_OUTOFMEMORY; | 545 return (*view) ? S_OK : E_OUTOFMEMORY; |
523 } | 546 } |
OLD | NEW |