| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/test/test_metro_viewer_process_host.h" | 5 #include "ash/test/test_metro_viewer_process_host.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/win/scoped_com_initializer.h" | 15 #include "base/win/scoped_com_initializer.h" |
| 16 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.h" |
| 17 #include "ipc/ipc_channel_proxy.h" | 17 #include "ipc/ipc_channel_proxy.h" |
| 18 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
| 19 #include "ui/aura/remote_root_window_host_win.h" | 19 #include "ui/aura/remote_root_window_host_win.h" |
| 20 #include "ui/metro_viewer/metro_viewer_messages.h" | 20 #include "ui/metro_viewer/metro_viewer_messages.h" |
| 21 #include "ui/surface/accelerated_surface_win.h" | 21 #include "ui/surface/accelerated_surface_win.h" |
| 22 | 22 |
| 23 namespace ash { | 23 namespace ash { |
| 24 namespace test { | 24 namespace test { |
| 25 | 25 |
| 26 TestMetroViewerProcessHost::InternalMessageFilter::InternalMessageFilter( | |
| 27 TestMetroViewerProcessHost* owner) | |
| 28 : owner_(owner) { | |
| 29 } | |
| 30 | |
| 31 void TestMetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( | |
| 32 int32 peer_pid) { | |
| 33 owner_->NotifyChannelConnected(); | |
| 34 } | |
| 35 | |
| 36 TestMetroViewerProcessHost::TestMetroViewerProcessHost( | 26 TestMetroViewerProcessHost::TestMetroViewerProcessHost( |
| 37 const std::string& ipc_channel_name) | 27 const std::string& ipc_channel_name, |
| 38 : ipc_thread_("test_metro_viewer_ipc_thread"), | 28 base::SingleThreadTaskRunner* ipc_task_runner) |
| 39 channel_connected_event_(false, false), | 29 : MetroViewerProcessHost(ipc_channel_name, ipc_task_runner), |
| 40 closed_unexpectedly_(false) { | 30 closed_unexpectedly_(false) { |
| 41 | |
| 42 base::Thread::Options options; | |
| 43 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
| 44 ipc_thread_.StartWithOptions(options); | |
| 45 | |
| 46 channel_.reset(new IPC::ChannelProxy( | |
| 47 ipc_channel_name.c_str(), | |
| 48 IPC::Channel::MODE_NAMED_SERVER, | |
| 49 this, | |
| 50 ipc_thread_.message_loop_proxy())); | |
| 51 | |
| 52 channel_->AddFilter(new InternalMessageFilter(this)); | |
| 53 } | 31 } |
| 54 | 32 |
| 55 TestMetroViewerProcessHost::~TestMetroViewerProcessHost() { | 33 TestMetroViewerProcessHost::~TestMetroViewerProcessHost() { |
| 56 channel_.reset(); | |
| 57 ipc_thread_.Stop(); | |
| 58 } | |
| 59 | |
| 60 void TestMetroViewerProcessHost::NotifyChannelConnected() { | |
| 61 channel_connected_event_.Signal(); | |
| 62 } | |
| 63 | |
| 64 bool TestMetroViewerProcessHost::LaunchViewerAndWaitForConnection( | |
| 65 const base::string16& app_user_model_id) { | |
| 66 // Activate the viewer process. NOTE: This assumes that the viewer process is | |
| 67 // registered as the default browser using the provided |app_user_model_id|. | |
| 68 | |
| 69 // TODO(robertshield): Initialize COM at test suite startup. | |
| 70 base::win::ScopedCOMInitializer com_initializer; | |
| 71 | |
| 72 base::win::ScopedComPtr<IApplicationActivationManager> activator; | |
| 73 HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); | |
| 74 if (SUCCEEDED(hr)) { | |
| 75 DWORD pid = 0; | |
| 76 hr = activator->ActivateApplication( | |
| 77 app_user_model_id.c_str(), L"open", AO_NONE, &pid); | |
| 78 } | |
| 79 | |
| 80 LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " | |
| 81 << "hr=" << std::hex << hr; | |
| 82 | |
| 83 // Having launched the viewer process, now we wait for it to connect. | |
| 84 return channel_connected_event_.TimedWait(base::TimeDelta::FromSeconds(60)); | |
| 85 } | |
| 86 | |
| 87 bool TestMetroViewerProcessHost::Send(IPC::Message* msg) { | |
| 88 return channel_->Send(msg); | |
| 89 } | |
| 90 | |
| 91 bool TestMetroViewerProcessHost::OnMessageReceived( | |
| 92 const IPC::Message& message) { | |
| 93 DCHECK(CalledOnValidThread()); | |
| 94 bool handled = true; | |
| 95 IPC_BEGIN_MESSAGE_MAP(TestMetroViewerProcessHost, message) | |
| 96 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) | |
| 97 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 98 IPC_END_MESSAGE_MAP() | |
| 99 return handled ? true : | |
| 100 aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message); | |
| 101 } | 34 } |
| 102 | 35 |
| 103 void TestMetroViewerProcessHost::OnChannelError() { | 36 void TestMetroViewerProcessHost::OnChannelError() { |
| 104 closed_unexpectedly_ = true; | 37 closed_unexpectedly_ = true; |
| 105 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); | 38 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); |
| 106 } | 39 } |
| 107 | 40 |
| 108 void TestMetroViewerProcessHost::OnSetTargetSurface( | 41 void TestMetroViewerProcessHost::OnSetTargetSurface( |
| 109 gfx::NativeViewId target_surface) { | 42 gfx::NativeViewId target_surface) { |
| 110 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; | 43 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; |
| 111 HWND hwnd = reinterpret_cast<HWND>(target_surface); | 44 HWND hwnd = reinterpret_cast<HWND>(target_surface); |
| 112 | 45 |
| 113 backing_surface.reset(new AcceleratedSurface(hwnd)); | 46 backing_surface.reset(new AcceleratedSurface(hwnd)); |
| 114 | 47 |
| 115 scoped_refptr<AcceleratedPresenter> any_window = | 48 scoped_refptr<AcceleratedPresenter> any_window = |
| 116 AcceleratedPresenter::GetForWindow(NULL); | 49 AcceleratedPresenter::GetForWindow(NULL); |
| 117 any_window->SetNewTargetWindow(hwnd); | 50 any_window->SetNewTargetWindow(hwnd); |
| 118 aura::RemoteRootWindowHostWin::Instance()->Connected(this); | 51 aura::RemoteRootWindowHostWin::Instance()->Connected(this); |
| 119 } | 52 } |
| 120 | 53 |
| 121 } // namespace test | 54 } // namespace test |
| 122 } // namespace ash | 55 } // namespace ash |
| OLD | NEW |