Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 311313003: DevTools: Fix for Page.captureScreenshot (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ignore_input_events_(false), 185 ignore_input_events_(false),
186 input_method_active_(false), 186 input_method_active_(false),
187 text_direction_updated_(false), 187 text_direction_updated_(false),
188 text_direction_(blink::WebTextDirectionLeftToRight), 188 text_direction_(blink::WebTextDirectionLeftToRight),
189 text_direction_canceled_(false), 189 text_direction_canceled_(false),
190 suppress_next_char_events_(false), 190 suppress_next_char_events_(false),
191 pending_mouse_lock_request_(false), 191 pending_mouse_lock_request_(false),
192 allow_privileged_mouse_lock_(false), 192 allow_privileged_mouse_lock_(false),
193 has_touch_handler_(false), 193 has_touch_handler_(false),
194 weak_factory_(this), 194 weak_factory_(this),
195 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { 195 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32),
196 next_browser_snapshot_id_(0) {
196 CHECK(delegate_); 197 CHECK(delegate_);
197 if (routing_id_ == MSG_ROUTING_NONE) { 198 if (routing_id_ == MSG_ROUTING_NONE) {
198 routing_id_ = process_->GetNextRoutingID(); 199 routing_id_ = process_->GetNextRoutingID();
199 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( 200 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
200 process_->GetID(), 201 process_->GetID(),
201 routing_id_); 202 routing_id_);
202 } else { 203 } else {
203 // TODO(piman): This is a O(N) lookup, where we could forward the 204 // TODO(piman): This is a O(N) lookup, where we could forward the
204 // information from the RenderWidgetHelper. The problem is that doing so 205 // information from the RenderWidgetHelper. The problem is that doing so
205 // currently leaks outside of content all the way to chrome classes, and 206 // currently leaks outside of content all the way to chrome classes, and
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // factor). 1156 // factor).
1156 InvalidateScreenInfo(); 1157 InvalidateScreenInfo();
1157 WasResized(); 1158 WasResized();
1158 } 1159 }
1159 1160
1160 void RenderWidgetHostImpl::InvalidateScreenInfo() { 1161 void RenderWidgetHostImpl::InvalidateScreenInfo() {
1161 screen_info_out_of_date_ = true; 1162 screen_info_out_of_date_ = true;
1162 screen_info_.reset(); 1163 screen_info_.reset();
1163 } 1164 }
1164 1165
1166 void RenderWidgetHostImpl::GetSnapshotFromBrowser(
1167 const base::Callback<void(const unsigned char*,size_t)> callback) {
1168 int id = next_browser_snapshot_id_++;
1169 pending_browser_snapshots_.insert(std::make_pair(id, callback));
1170 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id));
1171 }
1172
1165 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, 1173 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text,
1166 size_t offset, 1174 size_t offset,
1167 const gfx::Range& range) { 1175 const gfx::Range& range) {
1168 if (view_) 1176 if (view_)
1169 view_->SelectionChanged(text, offset, range); 1177 view_->SelectionChanged(text, offset, range);
1170 } 1178 }
1171 1179
1172 void RenderWidgetHostImpl::OnSelectionBoundsChanged( 1180 void RenderWidgetHostImpl::OnSelectionBoundsChanged(
1173 const ViewHostMsg_SelectionBounds_Params& params) { 1181 const ViewHostMsg_SelectionBounds_Params& params) {
1174 if (view_) { 1182 if (view_) {
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 "Event.Latency.Browser.TouchAcked", 2157 "Event.Latency.Browser.TouchAcked",
2150 acked_delta.InMicroseconds(), 2158 acked_delta.InMicroseconds(),
2151 1, 2159 1,
2152 1000000, 2160 1000000,
2153 100); 2161 100);
2154 } 2162 }
2155 } 2163 }
2156 2164
2157 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2165 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2158 ui::LatencyInfo::LatencyComponent window_snapshot_component; 2166 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2167 if (latency_info.FindLatency(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2168 GetLatencyComponentId(),
2169 &window_snapshot_component)) {
2170 WindowOldSnapshotReachedScreen(
2171 static_cast<int>(window_snapshot_component.sequence_number));
2172 }
2159 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 2173 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2160 GetLatencyComponentId(), 2174 GetLatencyComponentId(),
2161 &window_snapshot_component)) { 2175 &window_snapshot_component)) {
2162 WindowSnapshotReachedScreen( 2176 WindowSnapshotReachedScreen(
2163 static_cast<int>(window_snapshot_component.sequence_number)); 2177 static_cast<int>(window_snapshot_component.sequence_number));
2164 } 2178 }
2165 2179
2166 ui::LatencyInfo::LatencyComponent rwh_component; 2180 ui::LatencyInfo::LatencyComponent rwh_component;
2167 ui::LatencyInfo::LatencyComponent swap_component; 2181 ui::LatencyInfo::LatencyComponent swap_component;
2168 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 2182 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 std::vector<unsigned char> png_vector; 2222 std::vector<unsigned char> png_vector;
2209 Send(new ViewMsg_WindowSnapshotCompleted( 2223 Send(new ViewMsg_WindowSnapshotCompleted(
2210 routing_id, snapshot_id, gfx::Size(), png_vector)); 2224 routing_id, snapshot_id, gfx::Size(), png_vector));
2211 return; 2225 return;
2212 } 2226 }
2213 2227
2214 Send(new ViewMsg_WindowSnapshotCompleted( 2228 Send(new ViewMsg_WindowSnapshotCompleted(
2215 routing_id, snapshot_id, snapshot_size, png_data->data())); 2229 routing_id, snapshot_id, snapshot_size, png_data->data()));
2216 } 2230 }
2217 2231
2218 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2232 void RenderWidgetHostImpl::WindowOldSnapshotReachedScreen(int snapshot_id) {
2219 DCHECK(base::MessageLoopForUI::IsCurrent()); 2233 DCHECK(base::MessageLoopForUI::IsCurrent());
2220 2234
2221 std::vector<unsigned char> png; 2235 std::vector<unsigned char> png;
2222 2236
2223 // This feature is behind the kEnableGpuBenchmarking command line switch 2237 // This feature is behind the kEnableGpuBenchmarking command line switch
2224 // because it poses security concerns and should only be used for testing. 2238 // because it poses security concerns and should only be used for testing.
2225 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2239 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2226 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { 2240 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) {
2227 Send(new ViewMsg_WindowSnapshotCompleted( 2241 Send(new ViewMsg_WindowSnapshotCompleted(
2228 GetRoutingID(), snapshot_id, gfx::Size(), png)); 2242 GetRoutingID(), snapshot_id, gfx::Size(), png));
(...skipping 15 matching lines...) Expand all
2244 GetView()->GetNativeView(), 2258 GetView()->GetNativeView(),
2245 snapshot_bounds, 2259 snapshot_bounds,
2246 base::ThreadTaskRunnerHandle::Get(), 2260 base::ThreadTaskRunnerHandle::Get(),
2247 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, 2261 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback,
2248 weak_factory_.GetWeakPtr(), 2262 weak_factory_.GetWeakPtr(),
2249 GetRoutingID(), 2263 GetRoutingID(),
2250 snapshot_id, 2264 snapshot_id,
2251 snapshot_size)); 2265 snapshot_size));
2252 } 2266 }
2253 2267
2268 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2269 DCHECK(base::MessageLoopForUI::IsCurrent());
2270
2271 gfx::Rect view_bounds = GetView()->GetViewBounds();
2272 gfx::Rect snapshot_bounds(view_bounds.size());
2273
2274 std::vector<unsigned char> png;
2275 if (ui::GrabViewSnapshot(
2276 GetView()->GetNativeView(), &png, snapshot_bounds)) {
2277 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size());
2278 return;
2279 }
2280
2281 ui::GrabViewSnapshotAsync(
2282 GetView()->GetNativeView(),
2283 snapshot_bounds,
2284 base::ThreadTaskRunnerHandle::Get(),
2285 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync,
2286 weak_factory_.GetWeakPtr(),
2287 snapshot_id));
2288 }
2289
2290 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
2291 const unsigned char* data,
2292 size_t size) {
2293 // Any pending snapshots with a lower ID than the one received are considered
2294 // to be implicitly complete, and returned the same snapshot data.
2295 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2296 while(it != pending_browser_snapshots_.end()) {
2297 if (it->first <= snapshot_id) {
2298 it->second.Run(data, size);
2299 pending_browser_snapshots_.erase(it++);
2300 } else {
2301 ++it;
2302 }
2303 }
2304 }
2305
2306 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
2307 int snapshot_id,
2308 scoped_refptr<base::RefCountedBytes> png_data) {
2309 if (png_data)
2310 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size());
2311 else
2312 OnSnapshotDataReceived(snapshot_id, NULL, 0);
2313 }
2314
2254 // static 2315 // static
2255 void RenderWidgetHostImpl::CompositorFrameDrawn( 2316 void RenderWidgetHostImpl::CompositorFrameDrawn(
2256 const std::vector<ui::LatencyInfo>& latency_info) { 2317 const std::vector<ui::LatencyInfo>& latency_info) {
2257 for (size_t i = 0; i < latency_info.size(); i++) { 2318 for (size_t i = 0; i < latency_info.size(); i++) {
2258 std::set<RenderWidgetHostImpl*> rwhi_set; 2319 std::set<RenderWidgetHostImpl*> rwhi_set;
2259 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2320 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2260 latency_info[i].latency_components.begin(); 2321 latency_info[i].latency_components.begin();
2261 b != latency_info[i].latency_components.end(); 2322 b != latency_info[i].latency_components.end();
2262 ++b) { 2323 ++b) {
2263 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || 2324 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT ||
2264 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) { 2325 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT ||
2326 b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2265 // Matches with GetLatencyComponentId 2327 // Matches with GetLatencyComponentId
2266 int routing_id = b->first.second & 0xffffffff; 2328 int routing_id = b->first.second & 0xffffffff;
2267 int process_id = (b->first.second >> 32) & 0xffffffff; 2329 int process_id = (b->first.second >> 32) & 0xffffffff;
2268 RenderWidgetHost* rwh = 2330 RenderWidgetHost* rwh =
2269 RenderWidgetHost::FromID(process_id, routing_id); 2331 RenderWidgetHost::FromID(process_id, routing_id);
2270 if (!rwh) { 2332 if (!rwh) {
2271 continue; 2333 continue;
2272 } 2334 }
2273 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 2335 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2274 if (rwhi_set.insert(rwhi).second) 2336 if (rwhi_set.insert(rwhi).second)
(...skipping 29 matching lines...) Expand all
2304 } 2366 }
2305 } 2367 }
2306 2368
2307 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() { 2369 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() {
2308 if (view_) 2370 if (view_)
2309 return view_->PreferredReadbackFormat(); 2371 return view_->PreferredReadbackFormat();
2310 return SkBitmap::kARGB_8888_Config; 2372 return SkBitmap::kARGB_8888_Config;
2311 } 2373 }
2312 2374
2313 } // namespace content 2375 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698