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

Side by Side Diff: trunk/src/content/browser/devtools/renderer_overrides_handler.cc

Issue 343033002: Revert 278472 "DevTools: Fix for Page.captureScreenshot" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/devtools/renderer_overrides_handler.h" 5 #include "content/browser/devtools/renderer_overrides_handler.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/barrier_closure.h" 10 #include "base/barrier_closure.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if (format->empty()) 256 if (format->empty())
257 *format = kPng; 257 *format = kPng;
258 if (*quality < 0 || *quality > 100) 258 if (*quality < 0 || *quality > 100)
259 *quality = kDefaultScreenshotQuality; 259 *quality = kDefaultScreenshotQuality;
260 if (*scale <= 0) 260 if (*scale <= 0)
261 *scale = 0.1; 261 *scale = 0.1;
262 if (*scale > 5) 262 if (*scale > 5)
263 *scale = 5; 263 *scale = 5;
264 } 264 }
265 265
266 base::DictionaryValue* RendererOverridesHandler::CreateScreenshotResponse(
267 const std::vector<unsigned char>& png_data) {
268 std::string base_64_data;
269 base::Base64Encode(
270 base::StringPiece(reinterpret_cast<const char*>(&png_data[0]),
271 png_data.size()),
272 &base_64_data);
273
274 base::DictionaryValue* response = new base::DictionaryValue();
275 response->SetString(
276 devtools::Page::captureScreenshot::kResponseData, base_64_data);
277 return response;
278 }
279
266 // DOM agent handlers -------------------------------------------------------- 280 // DOM agent handlers --------------------------------------------------------
267 281
268 scoped_refptr<DevToolsProtocol::Response> 282 scoped_refptr<DevToolsProtocol::Response>
269 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( 283 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles(
270 scoped_refptr<DevToolsProtocol::Command> command) { 284 scoped_refptr<DevToolsProtocol::Command> command) {
271 base::DictionaryValue* params = command->params(); 285 base::DictionaryValue* params = command->params();
272 base::ListValue* file_list = NULL; 286 base::ListValue* file_list = NULL;
273 const char* param = 287 const char* param =
274 devtools::DOM::setFileInputFiles::kParamFiles; 288 devtools::DOM::setFileInputFiles::kParamFiles;
275 if (!params || !params->GetList(param, &file_list)) 289 if (!params || !params->GetList(param, &file_list))
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 463 }
450 return command->InvalidParamResponse(param); 464 return command->InvalidParamResponse(param);
451 } 465 }
452 } 466 }
453 return command->InternalErrorResponse("No WebContents to navigate"); 467 return command->InternalErrorResponse("No WebContents to navigate");
454 } 468 }
455 469
456 scoped_refptr<DevToolsProtocol::Response> 470 scoped_refptr<DevToolsProtocol::Response>
457 RendererOverridesHandler::PageCaptureScreenshot( 471 RendererOverridesHandler::PageCaptureScreenshot(
458 scoped_refptr<DevToolsProtocol::Command> command) { 472 scoped_refptr<DevToolsProtocol::Command> command) {
459 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( 473 RenderViewHost* host = agent_->GetRenderViewHost();
460 agent_->GetRenderViewHost());
461 if (!host->GetView()) 474 if (!host->GetView())
462 return command->InternalErrorResponse("Unable to access the view"); 475 return command->InternalErrorResponse("Unable to access the view");
463 476
464 host->GetSnapshotFromBrowser( 477 gfx::Rect view_bounds = host->GetView()->GetViewBounds();
478 gfx::Rect snapshot_bounds(view_bounds.size());
479 gfx::Size snapshot_size = snapshot_bounds.size();
480
481 std::vector<unsigned char> png_data;
482 if (ui::GrabViewSnapshot(host->GetView()->GetNativeView(),
483 &png_data,
484 snapshot_bounds)) {
485 if (png_data.size())
486 return command->SuccessResponse(CreateScreenshotResponse(png_data));
487 else
488 return command->InternalErrorResponse("Unable to capture screenshot");
489 }
490
491 ui::GrabViewSnapshotAsync(
492 host->GetView()->GetNativeView(),
493 snapshot_bounds,
494 base::ThreadTaskRunnerHandle::Get(),
465 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, 495 base::Bind(&RendererOverridesHandler::ScreenshotCaptured,
466 weak_factory_.GetWeakPtr(), command)); 496 weak_factory_.GetWeakPtr(), command));
467 return command->AsyncResponsePromise(); 497 return command->AsyncResponsePromise();
468 } 498 }
469 499
470 void RendererOverridesHandler::ScreenshotCaptured( 500 void RendererOverridesHandler::ScreenshotCaptured(
471 scoped_refptr<DevToolsProtocol::Command> command, 501 scoped_refptr<DevToolsProtocol::Command> command,
472 const unsigned char* png_data, 502 scoped_refptr<base::RefCountedBytes> png_data) {
473 size_t png_size) { 503 if (png_data) {
474 if (!png_data || !png_size) { 504 SendAsyncResponse(
505 command->SuccessResponse(CreateScreenshotResponse(png_data->data())));
506 } else {
475 SendAsyncResponse( 507 SendAsyncResponse(
476 command->InternalErrorResponse("Unable to capture screenshot")); 508 command->InternalErrorResponse("Unable to capture screenshot"));
477 return;
478 } 509 }
479
480 std::string base_64_data;
481 base::Base64Encode(
482 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size),
483 &base_64_data);
484
485 base::DictionaryValue* response = new base::DictionaryValue();
486 response->SetString(devtools::Page::screencastFrame::kParamData,
487 base_64_data);
488
489 SendAsyncResponse(command->SuccessResponse(response));
490 } 510 }
491 511
492 scoped_refptr<DevToolsProtocol::Response> 512 scoped_refptr<DevToolsProtocol::Response>
493 RendererOverridesHandler::PageCanScreencast( 513 RendererOverridesHandler::PageCanScreencast(
494 scoped_refptr<DevToolsProtocol::Command> command) { 514 scoped_refptr<DevToolsProtocol::Command> command) {
495 base::DictionaryValue* result = new base::DictionaryValue(); 515 base::DictionaryValue* result = new base::DictionaryValue();
496 #if defined(OS_ANDROID) 516 #if defined(OS_ANDROID)
497 result->SetBoolean(devtools::kResult, true); 517 result->SetBoolean(devtools::kResult, true);
498 #else 518 #else
499 result->SetBoolean(devtools::kResult, false); 519 result->SetBoolean(devtools::kResult, false);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 return NULL; 998 return NULL;
979 } 999 }
980 event.data.pinchUpdate.scale = static_cast<float>(scale); 1000 event.data.pinchUpdate.scale = static_cast<float>(scale);
981 } 1001 }
982 1002
983 host->ForwardGestureEvent(event); 1003 host->ForwardGestureEvent(event);
984 return command->SuccessResponse(NULL); 1004 return command->SuccessResponse(NULL);
985 } 1005 }
986 1006
987 } // namespace content 1007 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698