Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "cc/output/compositor_frame_metadata.h" | |
| 15 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
| 16 #include "content/browser/devtools/devtools_protocol_constants.h" | 17 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 17 #include "content/browser/devtools/devtools_tracing_handler.h" | 18 #include "content/browser/devtools/devtools_tracing_handler.h" |
| 18 #include "content/browser/renderer_host/dip_util.h" | 19 #include "content/browser/renderer_host/dip_util.h" |
| 19 #include "content/browser/renderer_host/render_view_host_delegate.h" | 20 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 20 #include "content/browser/renderer_host/render_view_host_impl.h" | 21 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 21 #include "content/port/browser/render_widget_host_view_port.h" | 22 #include "content/port/browser/render_widget_host_view_port.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/devtools_agent_host.h" | 24 #include "content/public/browser/devtools_agent_host.h" |
| 24 #include "content/public/browser/javascript_dialog_manager.h" | 25 #include "content/public/browser/javascript_dialog_manager.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 164 |
| 164 gfx::Rect view_bounds = host->GetView()->GetViewBounds(); | 165 gfx::Rect view_bounds = host->GetView()->GetViewBounds(); |
| 165 gfx::Size snapshot_size = gfx::ToFlooredSize( | 166 gfx::Size snapshot_size = gfx::ToFlooredSize( |
| 166 gfx::ScaleSize(view_bounds.size(), scale)); | 167 gfx::ScaleSize(view_bounds.size(), scale)); |
| 167 | 168 |
| 168 view_port->CopyFromCompositingSurface( | 169 view_port->CopyFromCompositingSurface( |
| 169 view_bounds, snapshot_size, | 170 view_bounds, snapshot_size, |
| 170 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, | 171 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
| 171 weak_factory_.GetWeakPtr(), | 172 weak_factory_.GetWeakPtr(), |
| 172 scoped_refptr<DevToolsProtocol::Command>(), format, quality, | 173 scoped_refptr<DevToolsProtocol::Command>(), format, quality, |
| 173 scale)); | 174 view_port->GetCompositorFrameMetadata())); |
| 174 } | 175 } |
| 175 | 176 |
| 176 | 177 |
| 177 // DOM agent handlers -------------------------------------------------------- | 178 // DOM agent handlers -------------------------------------------------------- |
| 178 | 179 |
| 179 scoped_refptr<DevToolsProtocol::Response> | 180 scoped_refptr<DevToolsProtocol::Response> |
| 180 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( | 181 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| 181 scoped_refptr<DevToolsProtocol::Command> command) { | 182 scoped_refptr<DevToolsProtocol::Command> command) { |
| 182 base::DictionaryValue* params = command->params(); | 183 base::DictionaryValue* params = command->params(); |
| 183 base::ListValue* file_list = NULL; | 184 base::ListValue* file_list = NULL; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 bool is_unscaled_png = scale == 1 && format == kPng; | 283 bool is_unscaled_png = scale == 1 && format == kPng; |
| 283 if (is_unscaled_png && ui::GrabViewSnapshot(host->GetView()->GetNativeView(), | 284 if (is_unscaled_png && ui::GrabViewSnapshot(host->GetView()->GetNativeView(), |
| 284 &png, view_bounds)) { | 285 &png, view_bounds)) { |
| 285 std::string base64_data; | 286 std::string base64_data; |
| 286 bool success = base::Base64Encode( | 287 bool success = base::Base64Encode( |
| 287 base::StringPiece(reinterpret_cast<char*>(&*png.begin()), png.size()), | 288 base::StringPiece(reinterpret_cast<char*>(&*png.begin()), png.size()), |
| 288 &base64_data); | 289 &base64_data); |
| 289 if (success) { | 290 if (success) { |
| 290 base::DictionaryValue* result = new base::DictionaryValue(); | 291 base::DictionaryValue* result = new base::DictionaryValue(); |
| 291 result->SetString( | 292 result->SetString( |
| 292 devtools::Page::captureScreenshot::kResponseData, base64_data); | 293 devtools::Page::kData, base64_data); |
| 293 return command->SuccessResponse(result); | 294 return command->SuccessResponse(result); |
| 294 } | 295 } |
| 295 return command->InternalErrorResponse("Unable to base64encode screenshot"); | 296 return command->InternalErrorResponse("Unable to base64encode screenshot"); |
| 296 } | 297 } |
| 297 | 298 |
| 298 // Fallback to copying from compositing surface. | 299 // Fallback to copying from compositing surface. |
| 299 RenderWidgetHostViewPort* view_port = | 300 RenderWidgetHostViewPort* view_port = |
| 300 RenderWidgetHostViewPort::FromRWHV(host->GetView()); | 301 RenderWidgetHostViewPort::FromRWHV(host->GetView()); |
| 301 | 302 |
| 302 gfx::Size snapshot_size = gfx::ToFlooredSize( | 303 gfx::Size snapshot_size = gfx::ToFlooredSize( |
| 303 gfx::ScaleSize(view_bounds.size(), scale)); | 304 gfx::ScaleSize(view_bounds.size(), scale)); |
| 304 view_port->CopyFromCompositingSurface( | 305 view_port->CopyFromCompositingSurface( |
| 305 view_bounds, snapshot_size, | 306 view_bounds, snapshot_size, |
| 306 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, | 307 base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
| 307 weak_factory_.GetWeakPtr(), command, format, quality, scale)); | 308 weak_factory_.GetWeakPtr(), command, format, quality, |
| 309 view_port->GetCompositorFrameMetadata())); | |
|
Sami
2013/08/28 15:42:50
I think reading the screenshot and the frame metad
| |
| 308 return command->AsyncResponsePromise(); | 310 return command->AsyncResponsePromise(); |
| 309 } | 311 } |
| 310 | 312 |
| 311 scoped_refptr<DevToolsProtocol::Response> | 313 scoped_refptr<DevToolsProtocol::Response> |
| 312 RendererOverridesHandler::PageStartScreencast( | 314 RendererOverridesHandler::PageStartScreencast( |
| 313 scoped_refptr<DevToolsProtocol::Command> command) { | 315 scoped_refptr<DevToolsProtocol::Command> command) { |
| 314 screencast_command_ = command; | 316 screencast_command_ = command; |
| 315 OnSwapCompositorFrame(); | 317 OnSwapCompositorFrame(); |
| 316 return command->SuccessResponse(NULL); | 318 return command->SuccessResponse(NULL); |
| 317 } | 319 } |
| 318 | 320 |
| 319 scoped_refptr<DevToolsProtocol::Response> | 321 scoped_refptr<DevToolsProtocol::Response> |
| 320 RendererOverridesHandler::PageStopScreencast( | 322 RendererOverridesHandler::PageStopScreencast( |
| 321 scoped_refptr<DevToolsProtocol::Command> command) { | 323 scoped_refptr<DevToolsProtocol::Command> command) { |
| 322 screencast_command_ = NULL; | 324 screencast_command_ = NULL; |
| 323 return command->SuccessResponse(NULL); | 325 return command->SuccessResponse(NULL); |
| 324 } | 326 } |
| 325 | 327 |
| 326 void RendererOverridesHandler::ScreenshotCaptured( | 328 void RendererOverridesHandler::ScreenshotCaptured( |
| 327 scoped_refptr<DevToolsProtocol::Command> command, | 329 scoped_refptr<DevToolsProtocol::Command> command, |
| 328 const std::string& format, | 330 const std::string& format, |
| 329 int quality, | 331 int quality, |
| 330 double scale, | 332 const cc::CompositorFrameMetadata& metadata, |
| 331 bool success, | 333 bool success, |
| 332 const SkBitmap& bitmap) { | 334 const SkBitmap& bitmap) { |
| 333 if (!success) { | 335 if (!success) { |
| 334 if (command) { | 336 if (command) { |
| 335 SendAsyncResponse( | 337 SendAsyncResponse( |
| 336 command->InternalErrorResponse("Unable to capture screenshot")); | 338 command->InternalErrorResponse("Unable to capture screenshot")); |
| 337 } | 339 } |
| 338 return; | 340 return; |
| 339 } | 341 } |
| 340 | 342 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 reinterpret_cast<char*>(&data[0]), | 375 reinterpret_cast<char*>(&data[0]), |
| 374 data.size()), | 376 data.size()), |
| 375 &base_64_data)) { | 377 &base_64_data)) { |
| 376 if (command) { | 378 if (command) { |
| 377 SendAsyncResponse( | 379 SendAsyncResponse( |
| 378 command->InternalErrorResponse("Unable to base64 encode")); | 380 command->InternalErrorResponse("Unable to base64 encode")); |
| 379 } | 381 } |
| 380 return; | 382 return; |
| 381 } | 383 } |
| 382 | 384 |
| 385 base::DictionaryValue* viewport = new base::DictionaryValue(); | |
| 386 viewport->SetDouble(devtools::Page::kDeviceScaleFactor, | |
| 387 metadata.device_scale_factor); | |
| 388 viewport->SetDouble(devtools::Page::kPageScaleFactor, | |
| 389 metadata.page_scale_factor); | |
| 390 viewport->SetDouble(devtools::Page::kScrollLeft, | |
| 391 metadata.root_scroll_offset.x()); | |
| 392 viewport->SetDouble(devtools::Page::kScrollTop, | |
| 393 metadata.root_scroll_offset.y()); | |
| 394 viewport->SetDouble(devtools::Page::kViewportWidth, | |
| 395 metadata.viewport_size.width()); | |
| 396 viewport->SetDouble(devtools::Page::kViewportHeight, | |
| 397 metadata.viewport_size.height()); | |
| 398 | |
| 383 base::DictionaryValue* response = new base::DictionaryValue(); | 399 base::DictionaryValue* response = new base::DictionaryValue(); |
| 400 response->SetString(devtools::Page::kData, base_64_data); | |
| 401 response->Set(devtools::Page::kViewport, viewport); | |
| 402 | |
| 384 if (command) { | 403 if (command) { |
| 385 response->SetString( | |
| 386 devtools::Page::captureScreenshot::kResponseData, base_64_data); | |
| 387 SendAsyncResponse(command->SuccessResponse(response)); | 404 SendAsyncResponse(command->SuccessResponse(response)); |
| 388 } else { | 405 } else { |
| 389 response->SetString( | |
| 390 devtools::Page::screencastFrame::kResponseData, base_64_data); | |
| 391 SendNotification(devtools::Page::screencastFrame::kName, response); | 406 SendNotification(devtools::Page::screencastFrame::kName, response); |
| 392 } | 407 } |
| 393 } | 408 } |
| 394 | 409 |
| 395 | 410 |
| 396 // Input agent handlers ------------------------------------------------------ | 411 // Input agent handlers ------------------------------------------------------ |
| 397 | 412 |
| 398 scoped_refptr<DevToolsProtocol::Response> | 413 scoped_refptr<DevToolsProtocol::Response> |
| 399 RendererOverridesHandler::InputDispatchMouseEvent( | 414 RendererOverridesHandler::InputDispatchMouseEvent( |
| 400 scoped_refptr<DevToolsProtocol::Command> command) { | 415 scoped_refptr<DevToolsProtocol::Command> command) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 return NULL; | 559 return NULL; |
| 545 } | 560 } |
| 546 event.data.pinchUpdate.scale = static_cast<float>(scale); | 561 event.data.pinchUpdate.scale = static_cast<float>(scale); |
| 547 } | 562 } |
| 548 | 563 |
| 549 host->ForwardGestureEvent(event); | 564 host->ForwardGestureEvent(event); |
| 550 return command->SuccessResponse(NULL); | 565 return command->SuccessResponse(NULL); |
| 551 } | 566 } |
| 552 | 567 |
| 553 } // namespace content | 568 } // namespace content |
| OLD | NEW |