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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { | 278 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { |
279 controller.GoToIndex(i); | 279 controller.GoToIndex(i); |
280 return Response::OK(); | 280 return Response::OK(); |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 return Response::InvalidParams("No entry with passed id"); | 284 return Response::InvalidParams("No entry with passed id"); |
285 } | 285 } |
286 | 286 |
287 void PageHandler::CaptureScreenshot( | 287 void PageHandler::CaptureScreenshot( |
| 288 Maybe<std::string> format, |
| 289 Maybe<int> quality, |
288 std::unique_ptr<CaptureScreenshotCallback> callback) { | 290 std::unique_ptr<CaptureScreenshotCallback> callback) { |
289 if (!host_ || !host_->GetRenderWidgetHost()) { | 291 if (!host_ || !host_->GetRenderWidgetHost()) { |
290 callback->sendFailure(Response::InternalError()); | 292 callback->sendFailure(Response::InternalError()); |
291 return; | 293 return; |
292 } | 294 } |
293 | 295 |
| 296 ui::SnapshotEncoding snapshot_encoding = format.fromMaybe(kPng) == kPng |
| 297 ? ui::SnapshotEncoding::PNG |
| 298 : ui::SnapshotEncoding::JPEG; |
| 299 ui::SnapshotQuality snapshot_quality = |
| 300 quality.fromMaybe(kDefaultScreenshotQuality); |
| 301 |
294 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser( | 302 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser( |
295 base::Bind(&PageHandler::ScreenshotCaptured, | 303 base::Bind(&PageHandler::ScreenshotCaptured, weak_factory_.GetWeakPtr(), |
296 weak_factory_.GetWeakPtr(), base::Passed(std::move(callback)))); | 304 base::Passed(std::move(callback))), |
| 305 snapshot_encoding, snapshot_quality); |
297 } | 306 } |
298 | 307 |
299 Response PageHandler::StartScreencast(Maybe<std::string> format, | 308 Response PageHandler::StartScreencast(Maybe<std::string> format, |
300 Maybe<int> quality, | 309 Maybe<int> quality, |
301 Maybe<int> max_width, | 310 Maybe<int> max_width, |
302 Maybe<int> max_height, | 311 Maybe<int> max_height, |
303 Maybe<int> every_nth_frame) { | 312 Maybe<int> every_nth_frame) { |
304 RenderWidgetHostImpl* widget_host = | 313 RenderWidgetHostImpl* widget_host = |
305 host_ ? host_->GetRenderWidgetHost() : nullptr; | 314 host_ ? host_->GetRenderWidgetHost() : nullptr; |
306 if (!widget_host) | 315 if (!widget_host) |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 .SetDeviceHeight(screen_size_dip.height()) | 562 .SetDeviceHeight(screen_size_dip.height()) |
554 .SetScrollOffsetX(metadata.root_scroll_offset.x()) | 563 .SetScrollOffsetX(metadata.root_scroll_offset.x()) |
555 .SetScrollOffsetY(metadata.root_scroll_offset.y()) | 564 .SetScrollOffsetY(metadata.root_scroll_offset.y()) |
556 .SetTimestamp(timestamp.ToDoubleT()) | 565 .SetTimestamp(timestamp.ToDoubleT()) |
557 .Build(); | 566 .Build(); |
558 frontend_->ScreencastFrame(data, std::move(param_metadata), session_id_); | 567 frontend_->ScreencastFrame(data, std::move(param_metadata), session_id_); |
559 } | 568 } |
560 | 569 |
561 void PageHandler::ScreenshotCaptured( | 570 void PageHandler::ScreenshotCaptured( |
562 std::unique_ptr<CaptureScreenshotCallback> callback, | 571 std::unique_ptr<CaptureScreenshotCallback> callback, |
563 const unsigned char* png_data, | 572 const unsigned char* image_data, |
564 size_t png_size) { | 573 size_t data_size) { |
565 if (!png_data || !png_size) { | 574 if (!image_data || !data_size) { |
566 callback->sendFailure(Response::Error("Unable to capture screenshot")); | 575 callback->sendFailure(Response::Error("Unable to capture screenshot")); |
567 return; | 576 return; |
568 } | 577 } |
569 | 578 |
570 std::string base_64_data; | 579 std::string base_64_data; |
571 base::Base64Encode( | 580 base::Base64Encode( |
572 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), | 581 base::StringPiece(reinterpret_cast<const char*>(image_data), data_size), |
573 &base_64_data); | 582 &base_64_data); |
574 callback->sendSuccess(base_64_data); | 583 callback->sendSuccess(base_64_data); |
575 } | 584 } |
576 | 585 |
577 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 586 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
578 frontend_->ColorPicked( | 587 frontend_->ColorPicked( |
579 DOM::RGBA::Create().SetR(r).SetG(g).SetB(b).SetA(a).Build()); | 588 DOM::RGBA::Create().SetR(r).SetG(g).SetB(b).SetA(a).Build()); |
580 } | 589 } |
581 | 590 |
582 Response PageHandler::StopLoading() { | 591 Response PageHandler::StopLoading() { |
583 WebContentsImpl* web_contents = GetWebContents(); | 592 WebContentsImpl* web_contents = GetWebContents(); |
584 if (!web_contents) | 593 if (!web_contents) |
585 return Response::InternalError(); | 594 return Response::InternalError(); |
586 web_contents->Stop(); | 595 web_contents->Stop(); |
587 return Response::OK(); | 596 return Response::OK(); |
588 } | 597 } |
589 | 598 |
590 } // namespace protocol | 599 } // namespace protocol |
591 } // namespace content | 600 } // namespace content |
OLD | NEW |