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 "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
16 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
21 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "content/browser/renderer_host/render_widget_host_impl.h" | 24 #include "content/browser/renderer_host/render_widget_host_impl.h" |
25 #include "content/browser/web_contents/web_contents_impl.h" | 25 #include "content/browser/web_contents/web_contents_impl.h" |
26 #include "content/browser/web_contents/web_contents_view.h" | 26 #include "content/browser/web_contents/web_contents_view.h" |
27 #include "content/common/input/synthetic_web_input_event_builders.h" | 27 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 28 #include "content/common/input_messages.h" |
28 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
29 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/histogram_fetcher.h" | 31 #include "content/public/browser/histogram_fetcher.h" |
31 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
34 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
35 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
36 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
37 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 ->ScheduleComposite(); | 1067 ->ScheduleComposite(); |
1067 } | 1068 } |
1068 | 1069 |
1069 FrameWatcher::FrameWatcher() | 1070 FrameWatcher::FrameWatcher() |
1070 : BrowserMessageFilter(ViewMsgStart), frames_to_wait_(0) { | 1071 : BrowserMessageFilter(ViewMsgStart), frames_to_wait_(0) { |
1071 } | 1072 } |
1072 | 1073 |
1073 FrameWatcher::~FrameWatcher() { | 1074 FrameWatcher::~FrameWatcher() { |
1074 } | 1075 } |
1075 | 1076 |
1076 void FrameWatcher::ReceivedFrameSwap() { | 1077 void FrameWatcher::ReceivedFrameSwap(cc::CompositorFrameMetadata metadata) { |
1077 --frames_to_wait_; | 1078 --frames_to_wait_; |
| 1079 last_metadata_ = metadata; |
1078 if (frames_to_wait_ == 0) | 1080 if (frames_to_wait_ == 0) |
1079 quit_.Run(); | 1081 quit_.Run(); |
1080 } | 1082 } |
1081 | 1083 |
1082 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { | 1084 bool FrameWatcher::OnMessageReceived(const IPC::Message& message) { |
1083 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { | 1085 if (message.type() == ViewHostMsg_SwapCompositorFrame::ID) { |
1084 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1086 ViewHostMsg_SwapCompositorFrame::Param param; |
1085 base::Bind(&FrameWatcher::ReceivedFrameSwap, this)); | 1087 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1088 return false; |
| 1089 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 1090 base::get<1>(param).AssignTo(frame.get()); |
| 1091 |
| 1092 BrowserThread::PostTask( |
| 1093 BrowserThread::UI, FROM_HERE, |
| 1094 base::Bind(&FrameWatcher::ReceivedFrameSwap, this, frame->metadata)); |
1086 } | 1095 } |
1087 return false; | 1096 return false; |
1088 } | 1097 } |
1089 | 1098 |
1090 void FrameWatcher::AttachTo(WebContents* web_contents) { | 1099 void FrameWatcher::AttachTo(WebContents* web_contents) { |
1091 DCHECK(web_contents); | 1100 DCHECK(web_contents); |
1092 RenderWidgetHostImpl* widget_host = RenderWidgetHostImpl::From( | 1101 RenderWidgetHostImpl* widget_host = RenderWidgetHostImpl::From( |
1093 web_contents->GetRenderViewHost()->GetWidget()); | 1102 web_contents->GetRenderViewHost()->GetWidget()); |
1094 widget_host->GetProcess()->AddFilter(this); | 1103 widget_host->GetProcess()->AddFilter(this); |
1095 } | 1104 } |
1096 | 1105 |
1097 void FrameWatcher::WaitFrames(int frames_to_wait) { | 1106 void FrameWatcher::WaitFrames(int frames_to_wait) { |
1098 if (frames_to_wait <= 0) | 1107 if (frames_to_wait <= 0) |
1099 return; | 1108 return; |
1100 base::RunLoop run_loop; | 1109 base::RunLoop run_loop; |
1101 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1110 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1102 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); | 1111 base::AutoReset<int> reset_frames_to_wait(&frames_to_wait_, frames_to_wait); |
1103 run_loop.Run(); | 1112 run_loop.Run(); |
1104 } | 1113 } |
1105 | 1114 |
| 1115 const cc::CompositorFrameMetadata& FrameWatcher::LastMetadata() { |
| 1116 return last_metadata_; |
| 1117 } |
| 1118 |
1106 MainThreadFrameObserver::MainThreadFrameObserver( | 1119 MainThreadFrameObserver::MainThreadFrameObserver( |
1107 RenderWidgetHost* render_widget_host) | 1120 RenderWidgetHost* render_widget_host) |
1108 : render_widget_host_(render_widget_host), | 1121 : render_widget_host_(render_widget_host), |
1109 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) { | 1122 routing_id_(render_widget_host_->GetProcess()->GetNextRoutingID()) { |
1110 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost | 1123 // TODO(lfg): We should look into adding a way to observe RenderWidgetHost |
1111 // messages similarly to what WebContentsObserver can do with RFH and RVW. | 1124 // messages similarly to what WebContentsObserver can do with RFH and RVW. |
1112 render_widget_host_->GetProcess()->AddRoute(routing_id_, this); | 1125 render_widget_host_->GetProcess()->AddRoute(routing_id_, this); |
1113 } | 1126 } |
1114 | 1127 |
1115 MainThreadFrameObserver::~MainThreadFrameObserver() { | 1128 MainThreadFrameObserver::~MainThreadFrameObserver() { |
(...skipping 17 matching lines...) Expand all Loading... |
1133 bool MainThreadFrameObserver::OnMessageReceived(const IPC::Message& msg) { | 1146 bool MainThreadFrameObserver::OnMessageReceived(const IPC::Message& msg) { |
1134 if (msg.type() == ViewHostMsg_WaitForNextFrameForTests_ACK::ID && | 1147 if (msg.type() == ViewHostMsg_WaitForNextFrameForTests_ACK::ID && |
1135 msg.routing_id() == routing_id_) { | 1148 msg.routing_id() == routing_id_) { |
1136 BrowserThread::PostTask( | 1149 BrowserThread::PostTask( |
1137 BrowserThread::UI, FROM_HERE, | 1150 BrowserThread::UI, FROM_HERE, |
1138 base::Bind(&MainThreadFrameObserver::Quit, base::Unretained(this))); | 1151 base::Bind(&MainThreadFrameObserver::Quit, base::Unretained(this))); |
1139 } | 1152 } |
1140 return true; | 1153 return true; |
1141 } | 1154 } |
1142 | 1155 |
| 1156 InputMsgWatcher::InputMsgWatcher(RenderWidgetHost* render_widget_host, |
| 1157 blink::WebInputEvent::Type type) |
| 1158 : BrowserMessageFilter(InputMsgStart), |
| 1159 wait_for_type_(type), |
| 1160 ack_result_(INPUT_EVENT_ACK_STATE_UNKNOWN) { |
| 1161 render_widget_host->GetProcess()->AddFilter(this); |
| 1162 } |
| 1163 |
| 1164 InputMsgWatcher::~InputMsgWatcher() {} |
| 1165 |
| 1166 void InputMsgWatcher::ReceivedAck(blink::WebInputEvent::Type ack_type, |
| 1167 uint32_t ack_state) { |
| 1168 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1169 if (wait_for_type_ == ack_type) { |
| 1170 ack_result_ = ack_state; |
| 1171 if (!quit_.is_null()) |
| 1172 quit_.Run(); |
| 1173 } |
| 1174 } |
| 1175 |
| 1176 bool InputMsgWatcher::OnMessageReceived(const IPC::Message& message) { |
| 1177 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1178 if (message.type() == InputHostMsg_HandleInputEvent_ACK::ID) { |
| 1179 InputHostMsg_HandleInputEvent_ACK::Param params; |
| 1180 InputHostMsg_HandleInputEvent_ACK::Read(&message, ¶ms); |
| 1181 blink::WebInputEvent::Type ack_type = base::get<0>(params).type; |
| 1182 InputEventAckState ack_state = base::get<0>(params).state; |
| 1183 BrowserThread::PostTask( |
| 1184 BrowserThread::UI, FROM_HERE, |
| 1185 base::Bind(&InputMsgWatcher::ReceivedAck, this, ack_type, ack_state)); |
| 1186 } |
| 1187 return false; |
| 1188 } |
| 1189 |
| 1190 uint32_t InputMsgWatcher::WaitForAck() { |
| 1191 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1192 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
| 1193 return ack_result_; |
| 1194 base::RunLoop run_loop; |
| 1195 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
| 1196 run_loop.Run(); |
| 1197 return ack_result_; |
| 1198 } |
| 1199 |
1143 } // namespace content | 1200 } // namespace content |
OLD | NEW |