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

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

Issue 2732923002: Add fromSurface optional parameter to devtools Page.CaptureScreenshot (Closed)
Patch Set: Marked fromSurface parameter as experimental Created 3 years, 9 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 8
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); 1448 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)));
1449 } 1449 }
1450 #endif 1450 #endif
1451 pending_browser_snapshots_.insert(std::make_pair(id, callback)); 1451 pending_browser_snapshots_.insert(std::make_pair(id, callback));
1452 ui::LatencyInfo latency_info; 1452 ui::LatencyInfo latency_info;
1453 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, 1453 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0,
1454 id); 1454 id);
1455 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); 1455 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info));
1456 } 1456 }
1457 1457
1458 void RenderWidgetHostImpl::GetSurfaceSnapshotFromBrowser(
1459 const GetSnapshotFromBrowserCallback& callback) {
1460 int id = next_browser_snapshot_id_++;
1461
1462 pending_surface_browser_snapshots_.insert(std::make_pair(id, callback));
1463 ui::LatencyInfo latency_info;
1464 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0,
1465 id);
1466 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info));
1467 }
1468
1458 const NativeWebKeyboardEvent* 1469 const NativeWebKeyboardEvent*
1459 RenderWidgetHostImpl::GetLastKeyboardEvent() const { 1470 RenderWidgetHostImpl::GetLastKeyboardEvent() const {
1460 return input_router_->GetLastKeyboardEvent(); 1471 return input_router_->GetLastKeyboardEvent();
1461 } 1472 }
1462 1473
1463 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, 1474 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text,
1464 uint32_t offset, 1475 uint32_t offset,
1465 const gfx::Range& range) { 1476 const gfx::Range& range) {
1466 if (view_) 1477 if (view_)
1467 view_->SelectionChanged(text, static_cast<size_t>(offset), range); 1478 view_->SelectionChanged(text, static_cast<size_t>(offset), range);
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
2355 is_running_navigation_hint_task); 2366 is_running_navigation_hint_task);
2356 } 2367 }
2357 2368
2358 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2369 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2359 view_->DidReceiveRendererFrame(); 2370 view_->DidReceiveRendererFrame();
2360 } 2371 }
2361 2372
2362 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2373 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2363 DCHECK(base::MessageLoopForUI::IsCurrent()); 2374 DCHECK(base::MessageLoopForUI::IsCurrent());
2364 2375
2376 if (!pending_surface_browser_snapshots_.empty()) {
2377 GetView()->CopyFromSurface(
2378 gfx::Rect(), gfx::Size(),
2379 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived,
2380 weak_factory_.GetWeakPtr(), snapshot_id, 0),
2381 kN32_SkColorType);
2382 }
2383
2384 if (!pending_browser_snapshots_.empty()) {
2365 #if defined(OS_ANDROID) 2385 #if defined(OS_ANDROID)
2366 // On Android, call sites should pass in the bounds with correct offset 2386 // On Android, call sites should pass in the bounds with correct offset
2367 // to capture the intended content area. 2387 // to capture the intended content area.
2368 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); 2388 gfx::Rect snapshot_bounds(GetView()->GetViewBounds());
2369 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); 2389 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y());
2370 #else 2390 #else
2371 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); 2391 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size());
2372 #endif 2392 #endif
2373 2393
2374 gfx::Image image; 2394 gfx::Image image;
2375 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, 2395 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds,
2376 &image)) { 2396 &image)) {
2377 OnSnapshotReceived(snapshot_id, image); 2397 OnSnapshotReceived(snapshot_id, image);
2398 return;
2399 }
2400
2401 ui::GrabViewSnapshotAsync(
2402 GetView()->GetNativeView(), snapshot_bounds,
2403 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived,
2404 weak_factory_.GetWeakPtr(), snapshot_id));
2405 }
2406 }
2407
2408 void RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived(
2409 int snapshot_id,
2410 int retry_count,
2411 const SkBitmap& bitmap,
2412 ReadbackResponse response) {
2413 static const int kMaxRetries = 5;
2414 if (response != READBACK_SUCCESS && retry_count < kMaxRetries) {
2415 GetView()->CopyFromSurface(
2416 gfx::Rect(), gfx::Size(),
2417 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived,
2418 weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1),
2419 kN32_SkColorType);
2378 return; 2420 return;
2379 } 2421 }
2380 2422 // Any pending snapshots with a lower ID than the one received are considered
2381 ui::GrabViewSnapshotAsync( 2423 // to be implicitly complete, and returned the same snapshot data.
2382 GetView()->GetNativeView(), snapshot_bounds, 2424 PendingSnapshotFromSurfaceMap::iterator it =
2383 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, 2425 pending_surface_browser_snapshots_.begin();
2384 weak_factory_.GetWeakPtr(), snapshot_id)); 2426 while (it != pending_surface_browser_snapshots_.end()) {
2427 if (it->first <= snapshot_id) {
2428 it->second.Run(gfx::Image::CreateFrom1xBitmap(bitmap));
Eric Seckler 2017/03/09 09:55:22 nit: create gfx::Image outside the loop. Maybe al
dvallet 2017/03/09 22:43:52 Done on outside loop image creation. Regarding emp
dvallet 2017/03/10 00:07:27 I see that GetSnapshotFromBrowser does indicate th
2429 pending_surface_browser_snapshots_.erase(it++);
2430 } else {
2431 ++it;
2432 }
2433 }
2385 } 2434 }
2386 2435
2387 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, 2436 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id,
2388 const gfx::Image& image) { 2437 const gfx::Image& image) {
2389 // Any pending snapshots with a lower ID than the one received are considered 2438 // Any pending snapshots with a lower ID than the one received are considered
2390 // to be implicitly complete, and returned the same snapshot data. 2439 // to be implicitly complete, and returned the same snapshot data.
2391 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); 2440 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2392 while (it != pending_browser_snapshots_.end()) { 2441 while (it != pending_browser_snapshots_.end()) {
2393 if (it->first <= snapshot_id) { 2442 if (it->first <= snapshot_id) {
2394 it->second.Run(image); 2443 it->second.Run(image);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 // different from the receiver's. 2565 // different from the receiver's.
2517 file_system_file.url = 2566 file_system_file.url =
2518 GURL(storage::GetIsolatedFileSystemRootURIString( 2567 GURL(storage::GetIsolatedFileSystemRootURIString(
2519 file_system_url.origin(), filesystem_id, std::string()) 2568 file_system_url.origin(), filesystem_id, std::string())
2520 .append(register_name)); 2569 .append(register_name));
2521 file_system_file.filesystem_id = filesystem_id; 2570 file_system_file.filesystem_id = filesystem_id;
2522 } 2571 }
2523 } 2572 }
2524 2573
2525 } // namespace content 2574 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698