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/browser/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ignore_input_events_(false), | 186 ignore_input_events_(false), |
187 input_method_active_(false), | 187 input_method_active_(false), |
188 text_direction_updated_(false), | 188 text_direction_updated_(false), |
189 text_direction_(blink::WebTextDirectionLeftToRight), | 189 text_direction_(blink::WebTextDirectionLeftToRight), |
190 text_direction_canceled_(false), | 190 text_direction_canceled_(false), |
191 suppress_next_char_events_(false), | 191 suppress_next_char_events_(false), |
192 pending_mouse_lock_request_(false), | 192 pending_mouse_lock_request_(false), |
193 allow_privileged_mouse_lock_(false), | 193 allow_privileged_mouse_lock_(false), |
194 has_touch_handler_(false), | 194 has_touch_handler_(false), |
195 weak_factory_(this), | 195 weak_factory_(this), |
196 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { | 196 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
| 197 next_browser_snapshot_id_(0) { |
197 CHECK(delegate_); | 198 CHECK(delegate_); |
198 if (routing_id_ == MSG_ROUTING_NONE) { | 199 if (routing_id_ == MSG_ROUTING_NONE) { |
199 routing_id_ = process_->GetNextRoutingID(); | 200 routing_id_ = process_->GetNextRoutingID(); |
200 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 201 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
201 process_->GetID(), | 202 process_->GetID(), |
202 routing_id_); | 203 routing_id_); |
203 } else { | 204 } else { |
204 // TODO(piman): This is a O(N) lookup, where we could forward the | 205 // TODO(piman): This is a O(N) lookup, where we could forward the |
205 // information from the RenderWidgetHelper. The problem is that doing so | 206 // information from the RenderWidgetHelper. The problem is that doing so |
206 // currently leaks outside of content all the way to chrome classes, and | 207 // currently leaks outside of content all the way to chrome classes, and |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 // factor). | 1174 // factor). |
1174 InvalidateScreenInfo(); | 1175 InvalidateScreenInfo(); |
1175 WasResized(); | 1176 WasResized(); |
1176 } | 1177 } |
1177 | 1178 |
1178 void RenderWidgetHostImpl::InvalidateScreenInfo() { | 1179 void RenderWidgetHostImpl::InvalidateScreenInfo() { |
1179 screen_info_out_of_date_ = true; | 1180 screen_info_out_of_date_ = true; |
1180 screen_info_.reset(); | 1181 screen_info_.reset(); |
1181 } | 1182 } |
1182 | 1183 |
| 1184 void RenderWidgetHostImpl::GetSnapshotFromBrowser( |
| 1185 const base::Callback<void(const unsigned char*,size_t)> callback) { |
| 1186 int id = next_browser_snapshot_id_++; |
| 1187 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
| 1188 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); |
| 1189 } |
| 1190 |
1183 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, | 1191 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, |
1184 size_t offset, | 1192 size_t offset, |
1185 const gfx::Range& range) { | 1193 const gfx::Range& range) { |
1186 if (view_) | 1194 if (view_) |
1187 view_->SelectionChanged(text, offset, range); | 1195 view_->SelectionChanged(text, offset, range); |
1188 } | 1196 } |
1189 | 1197 |
1190 void RenderWidgetHostImpl::OnSelectionBoundsChanged( | 1198 void RenderWidgetHostImpl::OnSelectionBoundsChanged( |
1191 const ViewHostMsg_SelectionBounds_Params& params) { | 1199 const ViewHostMsg_SelectionBounds_Params& params) { |
1192 if (view_) { | 1200 if (view_) { |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2215 1000000, | 2223 1000000, |
2216 100); | 2224 100); |
2217 } | 2225 } |
2218 } | 2226 } |
2219 } | 2227 } |
2220 | 2228 |
2221 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2229 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2222 view_->DidReceiveRendererFrame(); | 2230 view_->DidReceiveRendererFrame(); |
2223 } | 2231 } |
2224 | 2232 |
2225 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( | |
2226 int routing_id, | |
2227 int snapshot_id, | |
2228 gfx::Size snapshot_size, | |
2229 scoped_refptr<base::RefCountedBytes> png_data) { | |
2230 if (!png_data) { | |
2231 std::vector<unsigned char> png_vector; | |
2232 Send(new ViewMsg_WindowSnapshotCompleted( | |
2233 routing_id, snapshot_id, gfx::Size(), png_vector)); | |
2234 return; | |
2235 } | |
2236 | |
2237 Send(new ViewMsg_WindowSnapshotCompleted( | |
2238 routing_id, snapshot_id, snapshot_size, png_data->data())); | |
2239 } | |
2240 | |
2241 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2233 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
2242 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2234 DCHECK(base::MessageLoopForUI::IsCurrent()); |
2243 | 2235 |
| 2236 gfx::Rect view_bounds = GetView()->GetViewBounds(); |
| 2237 gfx::Rect snapshot_bounds(view_bounds.size()); |
| 2238 |
2244 std::vector<unsigned char> png; | 2239 std::vector<unsigned char> png; |
2245 | 2240 if (ui::GrabViewSnapshot( |
2246 // This feature is behind the kEnableGpuBenchmarking command line switch | 2241 GetView()->GetNativeView(), &png, snapshot_bounds)) { |
2247 // because it poses security concerns and should only be used for testing. | 2242 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
2248 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
2249 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { | |
2250 Send(new ViewMsg_WindowSnapshotCompleted( | |
2251 GetRoutingID(), snapshot_id, gfx::Size(), png)); | |
2252 return; | 2243 return; |
2253 } | 2244 } |
2254 | 2245 |
2255 gfx::Rect view_bounds = GetView()->GetViewBounds(); | |
2256 gfx::Rect snapshot_bounds(view_bounds.size()); | |
2257 gfx::Size snapshot_size = snapshot_bounds.size(); | |
2258 | |
2259 if (ui::GrabViewSnapshot( | |
2260 GetView()->GetNativeView(), &png, snapshot_bounds)) { | |
2261 Send(new ViewMsg_WindowSnapshotCompleted( | |
2262 GetRoutingID(), snapshot_id, snapshot_size, png)); | |
2263 return; | |
2264 } | |
2265 | |
2266 ui::GrabViewSnapshotAsync( | 2246 ui::GrabViewSnapshotAsync( |
2267 GetView()->GetNativeView(), | 2247 GetView()->GetNativeView(), |
2268 snapshot_bounds, | 2248 snapshot_bounds, |
2269 base::ThreadTaskRunnerHandle::Get(), | 2249 base::ThreadTaskRunnerHandle::Get(), |
2270 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, | 2250 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
2271 weak_factory_.GetWeakPtr(), | 2251 weak_factory_.GetWeakPtr(), |
2272 GetRoutingID(), | 2252 snapshot_id)); |
2273 snapshot_id, | 2253 } |
2274 snapshot_size)); | 2254 |
| 2255 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
| 2256 const unsigned char* data, |
| 2257 size_t size) { |
| 2258 // Any pending snapshots with a lower ID than the one received are considered |
| 2259 // to be implicitly complete, and returned the same snapshot data. |
| 2260 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
| 2261 while(it != pending_browser_snapshots_.end()) { |
| 2262 if (it->first <= snapshot_id) { |
| 2263 it->second.Run(data, size); |
| 2264 pending_browser_snapshots_.erase(it++); |
| 2265 } else { |
| 2266 ++it; |
| 2267 } |
| 2268 } |
| 2269 } |
| 2270 |
| 2271 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
| 2272 int snapshot_id, |
| 2273 scoped_refptr<base::RefCountedBytes> png_data) { |
| 2274 if (png_data) |
| 2275 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
| 2276 else |
| 2277 OnSnapshotDataReceived(snapshot_id, NULL, 0); |
2275 } | 2278 } |
2276 | 2279 |
2277 // static | 2280 // static |
2278 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2281 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2279 const std::vector<ui::LatencyInfo>& latency_info) { | 2282 const std::vector<ui::LatencyInfo>& latency_info) { |
2280 for (size_t i = 0; i < latency_info.size(); i++) { | 2283 for (size_t i = 0; i < latency_info.size(); i++) { |
2281 std::set<RenderWidgetHostImpl*> rwhi_set; | 2284 std::set<RenderWidgetHostImpl*> rwhi_set; |
2282 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2285 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2283 latency_info[i].latency_components.begin(); | 2286 latency_info[i].latency_components.begin(); |
2284 b != latency_info[i].latency_components.end(); | 2287 b != latency_info[i].latency_components.end(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 } | 2330 } |
2328 } | 2331 } |
2329 | 2332 |
2330 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() { | 2333 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() { |
2331 if (view_) | 2334 if (view_) |
2332 return view_->PreferredReadbackFormat(); | 2335 return view_->PreferredReadbackFormat(); |
2333 return SkBitmap::kARGB_8888_Config; | 2336 return SkBitmap::kARGB_8888_Config; |
2334 } | 2337 } |
2335 | 2338 |
2336 } // namespace content | 2339 } // namespace content |
OLD | NEW |