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 |
26 TestMetroViewerProcessHost::TestMetroViewerProcessHost( | 36 TestMetroViewerProcessHost::TestMetroViewerProcessHost( |
27 const std::string& ipc_channel_name, | 37 const std::string& ipc_channel_name) |
28 base::SingleThreadTaskRunner* ipc_task_runner) | 38 : ipc_thread_("test_metro_viewer_ipc_thread"), |
29 : MetroViewerProcessHost(ipc_channel_name, ipc_task_runner) { | 39 channel_connected_event_(false, false), |
| 40 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)); |
30 } | 53 } |
31 | 54 |
32 TestMetroViewerProcessHost::~TestMetroViewerProcessHost() { | 55 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); |
33 } | 101 } |
34 | 102 |
35 void TestMetroViewerProcessHost::OnChannelError() { | 103 void TestMetroViewerProcessHost::OnChannelError() { |
36 closed_unexpectedly_ = true; | 104 closed_unexpectedly_ = true; |
37 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); | 105 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); |
38 } | 106 } |
39 | 107 |
40 void TestMetroViewerProcessHost::OnSetTargetSurface( | 108 void TestMetroViewerProcessHost::OnSetTargetSurface( |
41 gfx::NativeViewId target_surface) { | 109 gfx::NativeViewId target_surface) { |
42 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; | 110 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; |
43 HWND hwnd = reinterpret_cast<HWND>(target_surface); | 111 HWND hwnd = reinterpret_cast<HWND>(target_surface); |
44 | 112 |
45 backing_surface.reset(new AcceleratedSurface(hwnd)); | 113 backing_surface.reset(new AcceleratedSurface(hwnd)); |
46 | 114 |
47 scoped_refptr<AcceleratedPresenter> any_window = | 115 scoped_refptr<AcceleratedPresenter> any_window = |
48 AcceleratedPresenter::GetForWindow(NULL); | 116 AcceleratedPresenter::GetForWindow(NULL); |
49 any_window->SetNewTargetWindow(hwnd); | 117 any_window->SetNewTargetWindow(hwnd); |
50 aura::RemoteRootWindowHostWin::Instance()->Connected(this); | 118 aura::RemoteRootWindowHostWin::Instance()->Connected(this); |
51 } | 119 } |
52 | 120 |
53 } // namespace test | 121 } // namespace test |
54 } // namespace ash | 122 } // namespace ash |
OLD | NEW |