Index: content/browser/renderer_host/render_widget_host_impl.cc |
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc |
index 5afb35d3ee61214ba6724785ebde7a2d0158b34e..064248bb85401680075b02e1f31745ffdf872cd8 100644 |
--- a/content/browser/renderer_host/render_widget_host_impl.cc |
+++ b/content/browser/renderer_host/render_widget_host_impl.cc |
@@ -193,7 +193,8 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
allow_privileged_mouse_lock_(false), |
has_touch_handler_(false), |
weak_factory_(this), |
- last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { |
+ last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
+ next_browser_snapshot_id_(0) { |
CHECK(delegate_); |
if (routing_id_ == MSG_ROUTING_NONE) { |
routing_id_ = process_->GetNextRoutingID(); |
@@ -1180,6 +1181,13 @@ void RenderWidgetHostImpl::InvalidateScreenInfo() { |
screen_info_.reset(); |
} |
+void RenderWidgetHostImpl::GetSnapshotFromBrowser( |
+ const base::Callback<void(const unsigned char*,size_t)> callback) { |
+ int id = next_browser_snapshot_id_++; |
+ pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
+ Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); |
+} |
+ |
void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, |
size_t offset, |
const gfx::Range& range) { |
@@ -2222,44 +2230,16 @@ void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
view_->DidReceiveRendererFrame(); |
} |
-void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
- int routing_id, |
- int snapshot_id, |
- gfx::Size snapshot_size, |
- scoped_refptr<base::RefCountedBytes> png_data) { |
- if (!png_data) { |
- std::vector<unsigned char> png_vector; |
- Send(new ViewMsg_WindowSnapshotCompleted( |
- routing_id, snapshot_id, gfx::Size(), png_vector)); |
- return; |
- } |
- |
- Send(new ViewMsg_WindowSnapshotCompleted( |
- routing_id, snapshot_id, snapshot_size, png_data->data())); |
-} |
- |
void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
DCHECK(base::MessageLoopForUI::IsCurrent()); |
- std::vector<unsigned char> png; |
- |
- // This feature is behind the kEnableGpuBenchmarking command line switch |
- // because it poses security concerns and should only be used for testing. |
- const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
- if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { |
- Send(new ViewMsg_WindowSnapshotCompleted( |
- GetRoutingID(), snapshot_id, gfx::Size(), png)); |
- return; |
- } |
- |
gfx::Rect view_bounds = GetView()->GetViewBounds(); |
gfx::Rect snapshot_bounds(view_bounds.size()); |
- gfx::Size snapshot_size = snapshot_bounds.size(); |
+ std::vector<unsigned char> png; |
if (ui::GrabViewSnapshot( |
- GetView()->GetNativeView(), &png, snapshot_bounds)) { |
- Send(new ViewMsg_WindowSnapshotCompleted( |
- GetRoutingID(), snapshot_id, snapshot_size, png)); |
+ GetView()->GetNativeView(), &png, snapshot_bounds)) { |
+ OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
return; |
} |
@@ -2267,11 +2247,34 @@ void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
GetView()->GetNativeView(), |
snapshot_bounds, |
base::ThreadTaskRunnerHandle::Get(), |
- base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, |
+ base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
weak_factory_.GetWeakPtr(), |
- GetRoutingID(), |
- snapshot_id, |
- snapshot_size)); |
+ snapshot_id)); |
+} |
+ |
+void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
+ const unsigned char* data, |
+ size_t size) { |
+ // Any pending snapshots with a lower ID than the one received are considered |
+ // to be implicitly complete, and returned the same snapshot data. |
+ PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
+ while(it != pending_browser_snapshots_.end()) { |
+ if (it->first <= snapshot_id) { |
+ it->second.Run(data, size); |
+ pending_browser_snapshots_.erase(it++); |
+ } else { |
+ ++it; |
+ } |
+ } |
+} |
+ |
+void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
+ int snapshot_id, |
+ scoped_refptr<base::RefCountedBytes> png_data) { |
+ if (png_data) |
+ OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
+ else |
+ OnSnapshotDataReceived(snapshot_id, NULL, 0); |
} |
// static |