| 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" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
| 14 #include "content/browser/devtools/protocol/color_picker.h" | 14 #include "content/browser/devtools/protocol/color_picker.h" |
| 15 #include "content/browser/devtools/protocol/frame_recorder.h" | |
| 16 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 16 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 19 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/javascript_dialog_manager.h" | 20 #include "content/public/browser/javascript_dialog_manager.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 25 #include "content/public/browser/web_contents_delegate.h" | 24 #include "content/public/browser/web_contents_delegate.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 screencast_quality_(kDefaultScreenshotQuality), | 91 screencast_quality_(kDefaultScreenshotQuality), |
| 93 screencast_max_width_(-1), | 92 screencast_max_width_(-1), |
| 94 screencast_max_height_(-1), | 93 screencast_max_height_(-1), |
| 95 capture_retry_count_(0), | 94 capture_retry_count_(0), |
| 96 has_compositor_frame_metadata_(false), | 95 has_compositor_frame_metadata_(false), |
| 97 screencast_frame_sent_(0), | 96 screencast_frame_sent_(0), |
| 98 screencast_frame_acked_(0), | 97 screencast_frame_acked_(0), |
| 99 processing_screencast_frame_(false), | 98 processing_screencast_frame_(false), |
| 100 color_picker_(new ColorPicker(base::Bind( | 99 color_picker_(new ColorPicker(base::Bind( |
| 101 &PageHandler::OnColorPicked, base::Unretained(this)))), | 100 &PageHandler::OnColorPicked, base::Unretained(this)))), |
| 102 frame_recorder_(new FrameRecorder()), | |
| 103 host_(nullptr), | 101 host_(nullptr), |
| 104 screencast_listener_(nullptr), | 102 screencast_listener_(nullptr), |
| 105 weak_factory_(this) { | 103 weak_factory_(this) { |
| 106 } | 104 } |
| 107 | 105 |
| 108 PageHandler::~PageHandler() { | 106 PageHandler::~PageHandler() { |
| 109 } | 107 } |
| 110 | 108 |
| 111 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { | 109 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { |
| 112 if (host_ == host) | 110 if (host_ == host) |
| 113 return; | 111 return; |
| 114 | 112 |
| 115 color_picker_->SetRenderViewHost(host); | 113 color_picker_->SetRenderViewHost(host); |
| 116 frame_recorder_->SetRenderViewHost(host); | |
| 117 host_ = host; | 114 host_ = host; |
| 118 } | 115 } |
| 119 | 116 |
| 120 void PageHandler::SetClient(scoped_ptr<Client> client) { | 117 void PageHandler::SetClient(scoped_ptr<Client> client) { |
| 121 client_.swap(client); | 118 client_.swap(client); |
| 122 } | 119 } |
| 123 | 120 |
| 124 void PageHandler::Detached() { | 121 void PageHandler::Detached() { |
| 125 Disable(); | 122 Disable(); |
| 126 } | 123 } |
| 127 | 124 |
| 128 void PageHandler::OnSwapCompositorFrame( | 125 void PageHandler::OnSwapCompositorFrame( |
| 129 const cc::CompositorFrameMetadata& frame_metadata) { | 126 const cc::CompositorFrameMetadata& frame_metadata) { |
| 130 last_compositor_frame_metadata_ = has_compositor_frame_metadata_ ? | 127 last_compositor_frame_metadata_ = has_compositor_frame_metadata_ ? |
| 131 next_compositor_frame_metadata_ : frame_metadata; | 128 next_compositor_frame_metadata_ : frame_metadata; |
| 132 next_compositor_frame_metadata_ = frame_metadata; | 129 next_compositor_frame_metadata_ = frame_metadata; |
| 133 has_compositor_frame_metadata_ = true; | 130 has_compositor_frame_metadata_ = true; |
| 134 | 131 |
| 135 if (screencast_enabled_) | 132 if (screencast_enabled_) |
| 136 InnerSwapCompositorFrame(); | 133 InnerSwapCompositorFrame(); |
| 137 color_picker_->OnSwapCompositorFrame(); | 134 color_picker_->OnSwapCompositorFrame(); |
| 138 frame_recorder_->OnSwapCompositorFrame(); | |
| 139 } | 135 } |
| 140 | 136 |
| 141 void PageHandler::OnVisibilityChanged(bool visible) { | 137 void PageHandler::OnVisibilityChanged(bool visible) { |
| 142 if (!screencast_enabled_) | 138 if (!screencast_enabled_) |
| 143 return; | 139 return; |
| 144 NotifyScreencastVisibility(visible); | 140 NotifyScreencastVisibility(visible); |
| 145 } | 141 } |
| 146 | 142 |
| 147 void PageHandler::DidAttachInterstitialPage() { | 143 void PageHandler::DidAttachInterstitialPage() { |
| 148 if (!enabled_) | 144 if (!enabled_) |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 294 } |
| 299 | 295 |
| 300 Response PageHandler::StopScreencast() { | 296 Response PageHandler::StopScreencast() { |
| 301 screencast_enabled_ = false; | 297 screencast_enabled_ = false; |
| 302 if (screencast_listener_) | 298 if (screencast_listener_) |
| 303 screencast_listener_->ScreencastEnabledChanged(); | 299 screencast_listener_->ScreencastEnabledChanged(); |
| 304 return Response::FallThrough(); | 300 return Response::FallThrough(); |
| 305 } | 301 } |
| 306 | 302 |
| 307 Response PageHandler::StartRecordingFrames(int max_frame_count) { | 303 Response PageHandler::StartRecordingFrames(int max_frame_count) { |
| 308 return frame_recorder_->StartRecordingFrames(max_frame_count); | 304 return Response::OK(); |
| 309 } | 305 } |
| 310 | 306 |
| 311 Response PageHandler::StopRecordingFrames(DevToolsCommandId command_id) { | 307 Response PageHandler::StopRecordingFrames(DevToolsCommandId command_id) { |
| 312 return frame_recorder_->StopRecordingFrames(base::Bind( | 308 return Response::OK(); |
| 313 &PageHandler::OnFramesRecorded, base::Unretained(this), command_id)); | |
| 314 } | |
| 315 | |
| 316 Response PageHandler::CancelRecordingFrames() { | |
| 317 return frame_recorder_->CancelRecordingFrames(); | |
| 318 } | 309 } |
| 319 | 310 |
| 320 Response PageHandler::ScreencastFrameAck(int frame_number) { | 311 Response PageHandler::ScreencastFrameAck(int frame_number) { |
| 321 screencast_frame_acked_ = frame_number; | 312 screencast_frame_acked_ = frame_number; |
| 322 return Response::OK(); | 313 return Response::OK(); |
| 323 } | 314 } |
| 324 | 315 |
| 325 Response PageHandler::HandleJavaScriptDialog(bool accept, | 316 Response PageHandler::HandleJavaScriptDialog(bool accept, |
| 326 const std::string* prompt_text) { | 317 const std::string* prompt_text) { |
| 327 base::string16 prompt_override; | 318 base::string16 prompt_override; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 client_->SendCaptureScreenshotResponse(command_id, | 482 client_->SendCaptureScreenshotResponse(command_id, |
| 492 CaptureScreenshotResponse::Create()->set_data(base_64_data)); | 483 CaptureScreenshotResponse::Create()->set_data(base_64_data)); |
| 493 } | 484 } |
| 494 | 485 |
| 495 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 486 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
| 496 scoped_refptr<dom::RGBA> color = | 487 scoped_refptr<dom::RGBA> color = |
| 497 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 488 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
| 498 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 489 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
| 499 } | 490 } |
| 500 | 491 |
| 501 void PageHandler::OnFramesRecorded( | |
| 502 DevToolsCommandId command_id, | |
| 503 scoped_refptr<StopRecordingFramesResponse> response_data) { | |
| 504 client_->SendStopRecordingFramesResponse(command_id, response_data); | |
| 505 } | |
| 506 | |
| 507 } // namespace page | 492 } // namespace page |
| 508 } // namespace devtools | 493 } // namespace devtools |
| 509 } // namespace content | 494 } // namespace content |
| OLD | NEW |