| Index: trunk/src/content/browser/devtools/renderer_overrides_handler.cc
|
| ===================================================================
|
| --- trunk/src/content/browser/devtools/renderer_overrides_handler.cc (revision 278497)
|
| +++ trunk/src/content/browser/devtools/renderer_overrides_handler.cc (working copy)
|
| @@ -263,6 +263,20 @@
|
| *scale = 5;
|
| }
|
|
|
| +base::DictionaryValue* RendererOverridesHandler::CreateScreenshotResponse(
|
| + const std::vector<unsigned char>& png_data) {
|
| + std::string base_64_data;
|
| + base::Base64Encode(
|
| + base::StringPiece(reinterpret_cast<const char*>(&png_data[0]),
|
| + png_data.size()),
|
| + &base_64_data);
|
| +
|
| + base::DictionaryValue* response = new base::DictionaryValue();
|
| + response->SetString(
|
| + devtools::Page::captureScreenshot::kResponseData, base_64_data);
|
| + return response;
|
| +}
|
| +
|
| // DOM agent handlers --------------------------------------------------------
|
|
|
| scoped_refptr<DevToolsProtocol::Response>
|
| @@ -456,37 +470,43 @@
|
| scoped_refptr<DevToolsProtocol::Response>
|
| RendererOverridesHandler::PageCaptureScreenshot(
|
| scoped_refptr<DevToolsProtocol::Command> command) {
|
| - RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>(
|
| - agent_->GetRenderViewHost());
|
| + RenderViewHost* host = agent_->GetRenderViewHost();
|
| if (!host->GetView())
|
| return command->InternalErrorResponse("Unable to access the view");
|
|
|
| - host->GetSnapshotFromBrowser(
|
| + gfx::Rect view_bounds = host->GetView()->GetViewBounds();
|
| + gfx::Rect snapshot_bounds(view_bounds.size());
|
| + gfx::Size snapshot_size = snapshot_bounds.size();
|
| +
|
| + std::vector<unsigned char> png_data;
|
| + if (ui::GrabViewSnapshot(host->GetView()->GetNativeView(),
|
| + &png_data,
|
| + snapshot_bounds)) {
|
| + if (png_data.size())
|
| + return command->SuccessResponse(CreateScreenshotResponse(png_data));
|
| + else
|
| + return command->InternalErrorResponse("Unable to capture screenshot");
|
| + }
|
| +
|
| + ui::GrabViewSnapshotAsync(
|
| + host->GetView()->GetNativeView(),
|
| + snapshot_bounds,
|
| + base::ThreadTaskRunnerHandle::Get(),
|
| base::Bind(&RendererOverridesHandler::ScreenshotCaptured,
|
| - weak_factory_.GetWeakPtr(), command));
|
| + weak_factory_.GetWeakPtr(), command));
|
| return command->AsyncResponsePromise();
|
| }
|
|
|
| void RendererOverridesHandler::ScreenshotCaptured(
|
| scoped_refptr<DevToolsProtocol::Command> command,
|
| - const unsigned char* png_data,
|
| - size_t png_size) {
|
| - if (!png_data || !png_size) {
|
| + scoped_refptr<base::RefCountedBytes> png_data) {
|
| + if (png_data) {
|
| SendAsyncResponse(
|
| + command->SuccessResponse(CreateScreenshotResponse(png_data->data())));
|
| + } else {
|
| + SendAsyncResponse(
|
| command->InternalErrorResponse("Unable to capture screenshot"));
|
| - return;
|
| }
|
| -
|
| - std::string base_64_data;
|
| - base::Base64Encode(
|
| - base::StringPiece(reinterpret_cast<const char*>(png_data), png_size),
|
| - &base_64_data);
|
| -
|
| - base::DictionaryValue* response = new base::DictionaryValue();
|
| - response->SetString(devtools::Page::screencastFrame::kParamData,
|
| - base_64_data);
|
| -
|
| - SendAsyncResponse(command->SuccessResponse(response));
|
| }
|
|
|
| scoped_refptr<DevToolsProtocol::Response>
|
|
|