Chromium Code Reviews| 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 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 #include "ui/base/clipboard/clipboard.h" | 84 #include "ui/base/clipboard/clipboard.h" |
| 85 #include "ui/events/blink/web_input_event_traits.h" | 85 #include "ui/events/blink/web_input_event_traits.h" |
| 86 #include "ui/events/event.h" | 86 #include "ui/events/event.h" |
| 87 #include "ui/events/keycodes/keyboard_codes.h" | 87 #include "ui/events/keycodes/keyboard_codes.h" |
| 88 #include "ui/gfx/color_space.h" | 88 #include "ui/gfx/color_space.h" |
| 89 #include "ui/gfx/geometry/size_conversions.h" | 89 #include "ui/gfx/geometry/size_conversions.h" |
| 90 #include "ui/gfx/geometry/vector2d_conversions.h" | 90 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 91 #include "ui/gfx/image/image.h" | 91 #include "ui/gfx/image/image.h" |
| 92 #include "ui/gfx/image/image_skia.h" | 92 #include "ui/gfx/image/image_skia.h" |
| 93 #include "ui/gfx/skbitmap_operations.h" | 93 #include "ui/gfx/skbitmap_operations.h" |
| 94 #include "ui/gfx/switches.h" | |
| 94 #include "ui/snapshot/snapshot.h" | 95 #include "ui/snapshot/snapshot.h" |
| 95 | 96 |
| 96 #if defined(OS_ANDROID) | 97 #if defined(OS_ANDROID) |
| 97 #include "ui/android/view_android.h" | 98 #include "ui/android/view_android.h" |
| 98 #else | 99 #else |
| 99 #include "content/browser/compositor/image_transport_factory.h" | 100 #include "content/browser/compositor/image_transport_factory.h" |
| 100 // nogncheck as dependency of "ui/compositor" is on non-Android platforms only. | 101 // nogncheck as dependency of "ui/compositor" is on non-Android platforms only. |
| 101 #include "ui/compositor/compositor.h" // nogncheck | 102 #include "ui/compositor/compositor.h" // nogncheck |
| 102 #endif | 103 #endif |
| 103 | 104 |
| (...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1443 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1444 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 1444 } | 1445 } |
| 1445 #endif | 1446 #endif |
| 1446 pending_browser_snapshots_.insert(std::make_pair(id, callback)); | 1447 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
| 1447 ui::LatencyInfo latency_info; | 1448 ui::LatencyInfo latency_info; |
| 1448 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | 1449 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, |
| 1449 id); | 1450 id); |
| 1450 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1451 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
| 1451 } | 1452 } |
| 1452 | 1453 |
| 1454 void RenderWidgetHostImpl::GetBitmapSnapshotFromBrowser( | |
| 1455 const GetBitmapSnapshotFromBrowserCallback& callback) { | |
| 1456 int id = next_browser_snapshot_id_++; | |
| 1457 | |
| 1458 pending_bitmap_browser_snapshots_.insert(std::make_pair(id, callback)); | |
| 1459 ui::LatencyInfo latency_info; | |
| 1460 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | |
| 1461 id); | |
| 1462 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | |
| 1463 } | |
| 1464 | |
| 1453 const NativeWebKeyboardEvent* | 1465 const NativeWebKeyboardEvent* |
| 1454 RenderWidgetHostImpl::GetLastKeyboardEvent() const { | 1466 RenderWidgetHostImpl::GetLastKeyboardEvent() const { |
| 1455 return input_router_->GetLastKeyboardEvent(); | 1467 return input_router_->GetLastKeyboardEvent(); |
| 1456 } | 1468 } |
| 1457 | 1469 |
| 1458 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, | 1470 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, |
| 1459 uint32_t offset, | 1471 uint32_t offset, |
| 1460 const gfx::Range& range) { | 1472 const gfx::Range& range) { |
| 1461 if (view_) | 1473 if (view_) |
| 1462 view_->SelectionChanged(text, static_cast<size_t>(offset), range); | 1474 view_->SelectionChanged(text, static_cast<size_t>(offset), range); |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2344 is_running_navigation_hint_task); | 2356 is_running_navigation_hint_task); |
| 2345 } | 2357 } |
| 2346 | 2358 |
| 2347 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2359 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2348 view_->DidReceiveRendererFrame(); | 2360 view_->DidReceiveRendererFrame(); |
| 2349 } | 2361 } |
| 2350 | 2362 |
| 2351 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2363 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
| 2352 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2364 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 2353 | 2365 |
| 2366 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) { | |
|
Eric Seckler
2017/03/06 07:32:53
If we use the headless switch to determine how we
dgozman
2017/03/06 18:45:34
We should not special-case headless here.
dvallet
2017/03/08 02:26:14
Done.
dvallet
2017/03/08 02:26:14
Done. I opted to check both.
| |
| 2367 // In headless mode, we capture the whole view. | |
| 2368 GetView()->CopyFromSurface( | |
| 2369 gfx::Rect(), gfx::Size(), | |
| 2370 base::Bind(&RenderWidgetHostImpl::OnBitmapSnapshotReceived, | |
| 2371 weak_factory_.GetWeakPtr(), snapshot_id, 0), | |
| 2372 kN32_SkColorType); | |
| 2373 return; | |
| 2374 } | |
| 2375 | |
| 2354 #if defined(OS_ANDROID) | 2376 #if defined(OS_ANDROID) |
| 2355 // On Android, call sites should pass in the bounds with correct offset | 2377 // On Android, call sites should pass in the bounds with correct offset |
| 2356 // to capture the intended content area. | 2378 // to capture the intended content area. |
| 2357 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); | 2379 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); |
| 2358 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); | 2380 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); |
| 2359 #else | 2381 #else |
| 2360 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); | 2382 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); |
| 2361 #endif | 2383 #endif |
| 2362 | 2384 |
| 2363 gfx::Image image; | 2385 gfx::Image image; |
| 2364 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, | 2386 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, |
| 2365 &image)) { | 2387 &image)) { |
| 2366 OnSnapshotReceived(snapshot_id, image); | 2388 OnSnapshotReceived(snapshot_id, image); |
| 2367 return; | 2389 return; |
| 2368 } | 2390 } |
| 2369 | 2391 |
| 2370 ui::GrabViewSnapshotAsync( | 2392 ui::GrabViewSnapshotAsync( |
| 2371 GetView()->GetNativeView(), snapshot_bounds, | 2393 GetView()->GetNativeView(), snapshot_bounds, |
| 2372 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, | 2394 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, |
| 2373 weak_factory_.GetWeakPtr(), snapshot_id)); | 2395 weak_factory_.GetWeakPtr(), snapshot_id)); |
| 2374 } | 2396 } |
| 2375 | 2397 |
| 2398 void RenderWidgetHostImpl::OnBitmapSnapshotReceived(int snapshot_id, | |
| 2399 int retry_count, | |
| 2400 const SkBitmap& bitmap, | |
| 2401 ReadbackResponse response) { | |
| 2402 static const int kMaxRetries = 5; | |
| 2403 if (response != READBACK_SUCCESS && retry_count < kMaxRetries) { | |
| 2404 GetView()->CopyFromSurface( | |
| 2405 gfx::Rect(), gfx::Size(), | |
| 2406 base::Bind(&RenderWidgetHostImpl::OnBitmapSnapshotReceived, | |
| 2407 weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1), | |
| 2408 kN32_SkColorType); | |
| 2409 return; | |
| 2410 } | |
| 2411 // Any pending snapshots with a lower ID than the one received are considered | |
| 2412 // to be implicitly complete, and returned the same snapshot data. | |
| 2413 PendingBitmapSnapshotMap::iterator it = | |
| 2414 pending_bitmap_browser_snapshots_.begin(); | |
| 2415 while (it != pending_bitmap_browser_snapshots_.end()) { | |
| 2416 if (it->first <= snapshot_id) { | |
| 2417 it->second.Run(bitmap); | |
| 2418 pending_bitmap_browser_snapshots_.erase(it++); | |
| 2419 } else { | |
| 2420 ++it; | |
| 2421 } | |
| 2422 } | |
| 2423 } | |
| 2424 | |
| 2376 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, | 2425 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, |
| 2377 const gfx::Image& image) { | 2426 const gfx::Image& image) { |
| 2378 // Any pending snapshots with a lower ID than the one received are considered | 2427 // Any pending snapshots with a lower ID than the one received are considered |
| 2379 // to be implicitly complete, and returned the same snapshot data. | 2428 // to be implicitly complete, and returned the same snapshot data. |
| 2380 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); | 2429 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
| 2381 while (it != pending_browser_snapshots_.end()) { | 2430 while (it != pending_browser_snapshots_.end()) { |
| 2382 if (it->first <= snapshot_id) { | 2431 if (it->first <= snapshot_id) { |
| 2383 it->second.Run(image); | 2432 it->second.Run(image); |
| 2384 pending_browser_snapshots_.erase(it++); | 2433 pending_browser_snapshots_.erase(it++); |
| 2385 } else { | 2434 } else { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2505 // different from the receiver's. | 2554 // different from the receiver's. |
| 2506 file_system_file.url = | 2555 file_system_file.url = |
| 2507 GURL(storage::GetIsolatedFileSystemRootURIString( | 2556 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 2508 file_system_url.origin(), filesystem_id, std::string()) | 2557 file_system_url.origin(), filesystem_id, std::string()) |
| 2509 .append(register_name)); | 2558 .append(register_name)); |
| 2510 file_system_file.filesystem_id = filesystem_id; | 2559 file_system_file.filesystem_id = filesystem_id; |
| 2511 } | 2560 } |
| 2512 } | 2561 } |
| 2513 | 2562 |
| 2514 } // namespace content | 2563 } // namespace content |
| OLD | NEW |