OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/protocol/page_handler.h" | 5 #include "content/browser/devtools/protocol/page_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" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 for (int i = 0; i != controller.GetEntryCount(); ++i) { | 265 for (int i = 0; i != controller.GetEntryCount(); ++i) { |
266 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { | 266 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { |
267 controller.GoToIndex(i); | 267 controller.GoToIndex(i); |
268 return Response::OK(); | 268 return Response::OK(); |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 return Response::InvalidParams("No entry with passed id"); | 272 return Response::InvalidParams("No entry with passed id"); |
273 } | 273 } |
274 | 274 |
275 Response PageHandler::CaptureScreenshot(DevToolsCommandId command_id) { | 275 Response PageHandler::CaptureScreenshot(int session_id, |
| 276 DevToolsCommandId command_id) { |
276 if (!host_ || !host_->GetRenderWidgetHost()) | 277 if (!host_ || !host_->GetRenderWidgetHost()) |
277 return Response::InternalError("Could not connect to view"); | 278 return Response::InternalError("Could not connect to view"); |
278 | 279 |
279 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser( | 280 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser( |
280 base::Bind(&PageHandler::ScreenshotCaptured, | 281 base::Bind(&PageHandler::ScreenshotCaptured, weak_factory_.GetWeakPtr(), |
281 weak_factory_.GetWeakPtr(), command_id)); | 282 session_id, command_id)); |
282 return Response::OK(); | 283 return Response::OK(); |
283 } | 284 } |
284 | 285 |
285 Response PageHandler::CanScreencast(bool* result) { | 286 Response PageHandler::CanScreencast(bool* result) { |
286 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
287 *result = true; | 288 *result = true; |
288 #else | 289 #else |
289 *result = false; | 290 *result = false; |
290 #endif // defined(OS_ANDROID) | 291 #endif // defined(OS_ANDROID) |
291 return Response::OK(); | 292 return Response::OK(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 ->set_device_height(screen_size_dip.height()) | 485 ->set_device_height(screen_size_dip.height()) |
485 ->set_scroll_offset_x(metadata.root_scroll_offset.x()) | 486 ->set_scroll_offset_x(metadata.root_scroll_offset.x()) |
486 ->set_scroll_offset_y(metadata.root_scroll_offset.y()) | 487 ->set_scroll_offset_y(metadata.root_scroll_offset.y()) |
487 ->set_timestamp(timestamp.ToDoubleT()); | 488 ->set_timestamp(timestamp.ToDoubleT()); |
488 client_->ScreencastFrame(ScreencastFrameParams::Create() | 489 client_->ScreencastFrame(ScreencastFrameParams::Create() |
489 ->set_data(data) | 490 ->set_data(data) |
490 ->set_metadata(param_metadata) | 491 ->set_metadata(param_metadata) |
491 ->set_frame_number(++screencast_frame_sent_)); | 492 ->set_frame_number(++screencast_frame_sent_)); |
492 } | 493 } |
493 | 494 |
494 void PageHandler::ScreenshotCaptured(DevToolsCommandId command_id, | 495 void PageHandler::ScreenshotCaptured(int session_id, |
| 496 DevToolsCommandId command_id, |
495 const unsigned char* png_data, | 497 const unsigned char* png_data, |
496 size_t png_size) { | 498 size_t png_size) { |
497 if (!png_data || !png_size) { | 499 if (!png_data || !png_size) { |
498 client_->SendError(command_id, | 500 client_->SendError(session_id, command_id, |
499 Response::InternalError("Unable to capture screenshot")); | 501 Response::InternalError("Unable to capture screenshot")); |
500 return; | 502 return; |
501 } | 503 } |
502 | 504 |
503 std::string base_64_data; | 505 std::string base_64_data; |
504 base::Base64Encode( | 506 base::Base64Encode( |
505 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), | 507 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), |
506 &base_64_data); | 508 &base_64_data); |
507 | 509 |
508 client_->SendCaptureScreenshotResponse(command_id, | 510 client_->SendCaptureScreenshotResponse( |
| 511 session_id, command_id, |
509 CaptureScreenshotResponse::Create()->set_data(base_64_data)); | 512 CaptureScreenshotResponse::Create()->set_data(base_64_data)); |
510 } | 513 } |
511 | 514 |
512 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 515 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
513 scoped_refptr<dom::RGBA> color = | 516 scoped_refptr<dom::RGBA> color = |
514 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 517 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
515 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 518 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
516 } | 519 } |
517 | 520 |
518 } // namespace page | 521 } // namespace page |
519 } // namespace devtools | 522 } // namespace devtools |
520 } // namespace content | 523 } // namespace content |
OLD | NEW |