OLD | NEW |
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 463 } |
464 return command->InvalidParamResponse(param); | 464 return command->InvalidParamResponse(param); |
465 } | 465 } |
466 } | 466 } |
467 return command->InternalErrorResponse("No WebContents to navigate"); | 467 return command->InternalErrorResponse("No WebContents to navigate"); |
468 } | 468 } |
469 | 469 |
470 scoped_refptr<DevToolsProtocol::Response> | 470 scoped_refptr<DevToolsProtocol::Response> |
471 RendererOverridesHandler::PageCaptureScreenshot( | 471 RendererOverridesHandler::PageCaptureScreenshot( |
472 scoped_refptr<DevToolsProtocol::Command> command) { | 472 scoped_refptr<DevToolsProtocol::Command> command) { |
473 RenderViewHost* host = agent_->GetRenderViewHost(); | 473 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( |
| 474 agent_->GetRenderViewHost()); |
474 if (!host->GetView()) | 475 if (!host->GetView()) |
475 return command->InternalErrorResponse("Unable to access the view"); | 476 return command->InternalErrorResponse("Unable to access the view"); |
476 | 477 |
477 gfx::Rect view_bounds = host->GetView()->GetViewBounds(); | 478 host->GetSnapshotFromBrowser( |
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(), | |
495 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, | 479 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
496 weak_factory_.GetWeakPtr(), command)); | 480 weak_factory_.GetWeakPtr(), command)); |
497 return command->AsyncResponsePromise(); | 481 return command->AsyncResponsePromise(); |
498 } | 482 } |
499 | 483 |
500 void RendererOverridesHandler::ScreenshotCaptured( | 484 void RendererOverridesHandler::ScreenshotCaptured( |
501 scoped_refptr<DevToolsProtocol::Command> command, | 485 scoped_refptr<DevToolsProtocol::Command> command, |
502 scoped_refptr<base::RefCountedBytes> png_data) { | 486 const unsigned char* png_data, |
503 if (png_data) { | 487 size_t png_size) { |
504 SendAsyncResponse( | 488 if (!png_data || !png_size) { |
505 command->SuccessResponse(CreateScreenshotResponse(png_data->data()))); | |
506 } else { | |
507 SendAsyncResponse( | 489 SendAsyncResponse( |
508 command->InternalErrorResponse("Unable to capture screenshot")); | 490 command->InternalErrorResponse("Unable to capture screenshot")); |
| 491 return; |
509 } | 492 } |
| 493 |
| 494 std::string base_64_data; |
| 495 base::Base64Encode( |
| 496 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), |
| 497 &base_64_data); |
| 498 |
| 499 base::DictionaryValue* response = new base::DictionaryValue(); |
| 500 response->SetString(devtools::Page::screencastFrame::kParamData, |
| 501 base_64_data); |
| 502 |
| 503 SendAsyncResponse(command->SuccessResponse(response)); |
510 } | 504 } |
511 | 505 |
512 scoped_refptr<DevToolsProtocol::Response> | 506 scoped_refptr<DevToolsProtocol::Response> |
513 RendererOverridesHandler::PageCanScreencast( | 507 RendererOverridesHandler::PageCanScreencast( |
514 scoped_refptr<DevToolsProtocol::Command> command) { | 508 scoped_refptr<DevToolsProtocol::Command> command) { |
515 base::DictionaryValue* result = new base::DictionaryValue(); | 509 base::DictionaryValue* result = new base::DictionaryValue(); |
516 #if defined(OS_ANDROID) | 510 #if defined(OS_ANDROID) |
517 result->SetBoolean(devtools::kResult, true); | 511 result->SetBoolean(devtools::kResult, true); |
518 #else | 512 #else |
519 result->SetBoolean(devtools::kResult, false); | 513 result->SetBoolean(devtools::kResult, false); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 return NULL; | 992 return NULL; |
999 } | 993 } |
1000 event.data.pinchUpdate.scale = static_cast<float>(scale); | 994 event.data.pinchUpdate.scale = static_cast<float>(scale); |
1001 } | 995 } |
1002 | 996 |
1003 host->ForwardGestureEvent(event); | 997 host->ForwardGestureEvent(event); |
1004 return command->SuccessResponse(NULL); | 998 return command->SuccessResponse(NULL); |
1005 } | 999 } |
1006 | 1000 |
1007 } // namespace content | 1001 } // namespace content |
OLD | NEW |