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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 #include "skia/ext/platform_canvas.h" | 80 #include "skia/ext/platform_canvas.h" |
81 #include "storage/browser/fileapi/isolated_context.h" | 81 #include "storage/browser/fileapi/isolated_context.h" |
82 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 82 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
83 #include "ui/base/clipboard/clipboard.h" | 83 #include "ui/base/clipboard/clipboard.h" |
84 #include "ui/events/blink/web_input_event_traits.h" | 84 #include "ui/events/blink/web_input_event_traits.h" |
85 #include "ui/events/event.h" | 85 #include "ui/events/event.h" |
86 #include "ui/events/keycodes/keyboard_codes.h" | 86 #include "ui/events/keycodes/keyboard_codes.h" |
87 #include "ui/gfx/color_space.h" | 87 #include "ui/gfx/color_space.h" |
88 #include "ui/gfx/geometry/size_conversions.h" | 88 #include "ui/gfx/geometry/size_conversions.h" |
89 #include "ui/gfx/geometry/vector2d_conversions.h" | 89 #include "ui/gfx/geometry/vector2d_conversions.h" |
90 #include "ui/gfx/image/image.h" | |
91 #include "ui/gfx/image/image_skia.h" | 90 #include "ui/gfx/image/image_skia.h" |
92 #include "ui/gfx/skbitmap_operations.h" | 91 #include "ui/gfx/skbitmap_operations.h" |
93 #include "ui/snapshot/snapshot.h" | 92 #include "ui/snapshot/snapshot.h" |
94 | 93 |
95 #if defined(OS_ANDROID) | 94 #if defined(OS_ANDROID) |
96 #include "ui/android/view_android.h" | 95 #include "ui/android/view_android.h" |
97 #endif | 96 #endif |
98 | 97 |
99 #if defined(OS_MACOSX) | 98 #if defined(OS_MACOSX) |
100 #include "device/power_save_blocker/power_save_blocker.h" | 99 #include "device/power_save_blocker/power_save_blocker.h" |
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 | 2361 |
2363 #if defined(OS_ANDROID) | 2362 #if defined(OS_ANDROID) |
2364 // On Android, call sites should pass in the bounds with correct offset | 2363 // On Android, call sites should pass in the bounds with correct offset |
2365 // to capture the intended content area. | 2364 // to capture the intended content area. |
2366 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); | 2365 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); |
2367 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); | 2366 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); |
2368 #else | 2367 #else |
2369 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); | 2368 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); |
2370 #endif | 2369 #endif |
2371 | 2370 |
2372 gfx::Image image; | 2371 std::vector<unsigned char> png; |
2373 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, | 2372 if (ui::GrabViewSnapshot( |
2374 &image)) { | 2373 GetView()->GetNativeView(), &png, snapshot_bounds)) { |
2375 OnSnapshotReceived(snapshot_id, image); | 2374 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
2376 return; | 2375 return; |
2377 } | 2376 } |
2378 | 2377 |
2379 ui::GrabViewSnapshotAsync( | 2378 ui::GrabViewSnapshotAsync( |
2380 GetView()->GetNativeView(), snapshot_bounds, | 2379 GetView()->GetNativeView(), |
2381 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, | 2380 snapshot_bounds, |
2382 weak_factory_.GetWeakPtr(), snapshot_id)); | 2381 base::ThreadTaskRunnerHandle::Get(), |
| 2382 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
| 2383 weak_factory_.GetWeakPtr(), |
| 2384 snapshot_id)); |
2383 } | 2385 } |
2384 | 2386 |
2385 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, | 2387 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
2386 const gfx::Image& image) { | 2388 const unsigned char* data, |
| 2389 size_t size) { |
2387 // Any pending snapshots with a lower ID than the one received are considered | 2390 // Any pending snapshots with a lower ID than the one received are considered |
2388 // to be implicitly complete, and returned the same snapshot data. | 2391 // to be implicitly complete, and returned the same snapshot data. |
2389 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); | 2392 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
2390 while (it != pending_browser_snapshots_.end()) { | 2393 while (it != pending_browser_snapshots_.end()) { |
2391 if (it->first <= snapshot_id) { | 2394 if (it->first <= snapshot_id) { |
2392 it->second.Run(image); | 2395 it->second.Run(data, size); |
2393 pending_browser_snapshots_.erase(it++); | 2396 pending_browser_snapshots_.erase(it++); |
2394 } else { | 2397 } else { |
2395 ++it; | 2398 ++it; |
2396 } | 2399 } |
2397 } | 2400 } |
2398 #if defined(OS_MACOSX) | 2401 #if defined(OS_MACOSX) |
2399 if (pending_browser_snapshots_.empty()) | 2402 if (pending_browser_snapshots_.empty()) |
2400 power_save_blocker_.reset(); | 2403 power_save_blocker_.reset(); |
2401 #endif | 2404 #endif |
2402 } | 2405 } |
2403 | 2406 |
| 2407 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
| 2408 int snapshot_id, |
| 2409 scoped_refptr<base::RefCountedBytes> png_data) { |
| 2410 if (png_data.get()) |
| 2411 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
| 2412 else |
| 2413 OnSnapshotDataReceived(snapshot_id, NULL, 0); |
| 2414 } |
| 2415 |
2404 // static | 2416 // static |
2405 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2417 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2406 const std::vector<ui::LatencyInfo>& latency_info) { | 2418 const std::vector<ui::LatencyInfo>& latency_info) { |
2407 for (size_t i = 0; i < latency_info.size(); i++) { | 2419 for (size_t i = 0; i < latency_info.size(); i++) { |
2408 std::set<RenderWidgetHostImpl*> rwhi_set; | 2420 std::set<RenderWidgetHostImpl*> rwhi_set; |
2409 for (const auto& lc : latency_info[i].latency_components()) { | 2421 for (const auto& lc : latency_info[i].latency_components()) { |
2410 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2422 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
2411 lc.first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || | 2423 lc.first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
2412 lc.first.first == ui::TAB_SHOW_COMPONENT) { | 2424 lc.first.first == ui::TAB_SHOW_COMPONENT) { |
2413 // Matches with GetLatencyComponentId | 2425 // Matches with GetLatencyComponentId |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2514 // different from the receiver's. | 2526 // different from the receiver's. |
2515 file_system_file.url = | 2527 file_system_file.url = |
2516 GURL(storage::GetIsolatedFileSystemRootURIString( | 2528 GURL(storage::GetIsolatedFileSystemRootURIString( |
2517 file_system_url.origin(), filesystem_id, std::string()) | 2529 file_system_url.origin(), filesystem_id, std::string()) |
2518 .append(register_name)); | 2530 .append(register_name)); |
2519 file_system_file.filesystem_id = filesystem_id; | 2531 file_system_file.filesystem_id = filesystem_id; |
2520 } | 2532 } |
2521 } | 2533 } |
2522 | 2534 |
2523 } // namespace content | 2535 } // namespace content |
OLD | NEW |