Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/browser/devtools/protocol/page_handler.cc

Issue 1003113003: [DevTools] Handle emulation in embedder, call into web API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/threading/worker_pool.h" 14 #include "base/threading/worker_pool.h"
14 #include "content/browser/devtools/protocol/color_picker.h" 15 #include "content/browser/devtools/protocol/color_picker.h"
15 #include "content/browser/devtools/protocol/frame_recorder.h" 16 #include "content/browser/devtools/protocol/frame_recorder.h"
16 #include "content/browser/geolocation/geolocation_service_context.h" 17 #include "content/browser/geolocation/geolocation_service_context.h"
17 #include "content/browser/renderer_host/render_view_host_impl.h" 18 #include "content/browser/renderer_host/render_view_host_impl.h"
18 #include "content/browser/renderer_host/render_widget_host_view_base.h" 19 #include "content/browser/renderer_host/render_widget_host_view_base.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 20 #include "content/browser/web_contents/web_contents_impl.h"
21 #include "content/common/devtools_messages.h"
20 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
21 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/javascript_dialog_manager.h" 24 #include "content/public/browser/javascript_dialog_manager.h"
23 #include "content/public/browser/navigation_controller.h" 25 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
26 #include "content/public/browser/web_contents_delegate.h" 28 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/common/referrer.h" 29 #include "content/public/common/referrer.h"
28 #include "content/public/common/url_constants.h" 30 #include "content/public/common/url_constants.h"
29 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 31 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return base_64_data; 101 return base_64_data;
100 } 102 }
101 103
102 } // namespace 104 } // namespace
103 105
104 typedef DevToolsProtocolClient::Response Response; 106 typedef DevToolsProtocolClient::Response Response;
105 107
106 PageHandler::PageHandler() 108 PageHandler::PageHandler()
107 : enabled_(false), 109 : enabled_(false),
108 touch_emulation_enabled_(false), 110 touch_emulation_enabled_(false),
111 device_emulation_enabled_(false),
109 screencast_enabled_(false), 112 screencast_enabled_(false),
110 screencast_quality_(kDefaultScreenshotQuality), 113 screencast_quality_(kDefaultScreenshotQuality),
111 screencast_max_width_(-1), 114 screencast_max_width_(-1),
112 screencast_max_height_(-1), 115 screencast_max_height_(-1),
113 capture_retry_count_(0), 116 capture_retry_count_(0),
114 has_compositor_frame_metadata_(false), 117 has_compositor_frame_metadata_(false),
115 screencast_frame_sent_(0), 118 screencast_frame_sent_(0),
116 screencast_frame_acked_(0), 119 screencast_frame_acked_(0),
117 processing_screencast_frame_(false), 120 processing_screencast_frame_(false),
118 color_picker_(new ColorPicker(base::Bind( 121 color_picker_(new ColorPicker(base::Bind(
119 &PageHandler::OnColorPicked, base::Unretained(this)))), 122 &PageHandler::OnColorPicked, base::Unretained(this)))),
120 frame_recorder_(new FrameRecorder()), 123 frame_recorder_(new FrameRecorder()),
121 host_(nullptr), 124 host_(nullptr),
122 weak_factory_(this) { 125 weak_factory_(this) {
123 } 126 }
124 127
125 PageHandler::~PageHandler() { 128 PageHandler::~PageHandler() {
126 } 129 }
127 130
128 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { 131 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) {
129 if (host_ == host) 132 if (host_ == host)
130 return; 133 return;
131 134
132 color_picker_->SetRenderViewHost(host); 135 color_picker_->SetRenderViewHost(host);
133 frame_recorder_->SetRenderViewHost(host); 136 frame_recorder_->SetRenderViewHost(host);
134 host_ = host; 137 host_ = host;
135 UpdateTouchEventEmulationState(); 138 UpdateTouchEventEmulationState();
139 UpdateDeviceEmulationState();
136 } 140 }
137 141
138 void PageHandler::SetClient(scoped_ptr<Client> client) { 142 void PageHandler::SetClient(scoped_ptr<Client> client) {
139 client_.swap(client); 143 client_.swap(client);
140 } 144 }
141 145
142 void PageHandler::Detached() { 146 void PageHandler::Detached() {
143 Disable(); 147 Disable();
144 } 148 }
145 149
(...skipping 30 matching lines...) Expand all
176 180
177 Response PageHandler::Enable() { 181 Response PageHandler::Enable() {
178 enabled_ = true; 182 enabled_ = true;
179 return Response::FallThrough(); 183 return Response::FallThrough();
180 } 184 }
181 185
182 Response PageHandler::Disable() { 186 Response PageHandler::Disable() {
183 enabled_ = false; 187 enabled_ = false;
184 touch_emulation_enabled_ = false; 188 touch_emulation_enabled_ = false;
185 screencast_enabled_ = false; 189 screencast_enabled_ = false;
190 device_emulation_enabled_ = false;
186 UpdateTouchEventEmulationState(); 191 UpdateTouchEventEmulationState();
192 UpdateDeviceEmulationState();
187 color_picker_->SetEnabled(false); 193 color_picker_->SetEnabled(false);
188 return Response::FallThrough(); 194 return Response::FallThrough();
189 } 195 }
190 196
191 Response PageHandler::Reload(const bool* ignoreCache, 197 Response PageHandler::Reload(const bool* ignoreCache,
192 const std::string* script_to_evaluate_on_load, 198 const std::string* script_to_evaluate_on_load,
193 const std::string* script_preprocessor) { 199 const std::string* script_preprocessor) {
194 if (!host_) 200 if (!host_)
195 return Response::InternalError("Could not connect to view"); 201 return Response::InternalError("Could not connect to view");
196 202
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 #endif // defined(OS_ANDROID) 341 #endif // defined(OS_ANDROID)
336 return Response::OK(); 342 return Response::OK();
337 } 343 }
338 344
339 Response PageHandler::CanEmulate(bool* result) { 345 Response PageHandler::CanEmulate(bool* result) {
340 #if defined(OS_ANDROID) 346 #if defined(OS_ANDROID)
341 *result = false; 347 *result = false;
342 #else 348 #else
343 if (host_) { 349 if (host_) {
344 if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) { 350 if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) {
345 *result = !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme); 351 *result =
352 !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme) &&
pfeldman 2015/03/13 13:00:17 DEBUG_DEVTOOLS ?
dgozman 2015/03/13 15:57:27 Done.
353 web_contents->GetMainFrame()->GetRenderViewHost() == host_;
346 } else { 354 } else {
347 *result = true; 355 *result = true;
348 } 356 }
349 } else { 357 } else {
350 *result = true; 358 *result = true;
351 } 359 }
352 #endif // defined(OS_ANDROID) 360 #endif // defined(OS_ANDROID)
353 return Response::OK(); 361 return Response::OK();
354 } 362 }
355 363
364 Response PageHandler::SetDeviceMetricsOverride(
365 int width, int height, double device_scale_factor, bool mobile,
366 bool fit_window, const double* optional_scale,
367 const double* optional_offset_x, const double* optional_offset_y) {
368 const static int max_size = 10000000;
369 const static double max_scale = 10;
370
371 if (!host_)
372 return Response::InternalError("Could not connect to view");
373
374 if (width < 0 || height < 0 || width > max_size || height > max_size) {
375 return Response::InvalidParams(
376 "Width and height values must be positive, not greater than " +
377 base::IntToString(max_size));
378 }
379
380 if (device_scale_factor < 0)
381 return Response::InvalidParams("deviceScaleFactor must be non-negative");
382
383 if (optional_scale && (*optional_scale <= 0 || *optional_scale > max_scale)) {
384 return Response::InvalidParams(
385 "scale must be positive, not greater than " +
386 base::IntToString(max_scale));
387 }
388
389 blink::WebDeviceEmulationParams params;
390 params.screenPosition = mobile ? blink::WebDeviceEmulationParams::Mobile :
391 blink::WebDeviceEmulationParams::Desktop;
392 params.deviceScaleFactor = device_scale_factor;
393 params.viewSize = blink::WebSize(width, height);
394 params.fitToView = fit_window;
395 params.scale = optional_scale ? *optional_scale : 1;
396 params.offset = blink::WebFloatPoint(
397 optional_offset_x ? *optional_offset_x : 0.f,
398 optional_offset_y ? *optional_offset_y : 0.f);
399
400 if (device_emulation_enabled_ && params == device_emulation_params_)
401 return Response::OK();
402
403 device_emulation_enabled_ = true;
404 device_emulation_params_ = params;
405 UpdateDeviceEmulationState();
406 return Response::OK();
407 }
408
409 Response PageHandler::ClearDeviceMetricsOverride() {
410 if (!device_emulation_enabled_)
411 return Response::OK();
412
413 device_emulation_enabled_ = false;
414 UpdateDeviceEmulationState();
415 return Response::OK();
416 }
417
356 Response PageHandler::StartScreencast(const std::string* format, 418 Response PageHandler::StartScreencast(const std::string* format,
357 const int* quality, 419 const int* quality,
358 const int* max_width, 420 const int* max_width,
359 const int* max_height) { 421 const int* max_height) {
360 if (!host_) 422 if (!host_)
361 return Response::InternalError("Could not connect to view"); 423 return Response::InternalError("Could not connect to view");
362 424
363 screencast_enabled_ = true; 425 screencast_enabled_ = true;
364 screencast_format_ = format ? *format : kPng; 426 screencast_format_ = format ? *format : kPng;
365 screencast_quality_ = quality ? *quality : kDefaultScreenshotQuality; 427 screencast_quality_ = quality ? *quality : kDefaultScreenshotQuality;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 bool enabled = touch_emulation_enabled_ || screencast_enabled_; 508 bool enabled = touch_emulation_enabled_ || screencast_enabled_;
447 ui::GestureProviderConfigType config_type = 509 ui::GestureProviderConfigType config_type =
448 TouchEmulationConfigurationToType(touch_emulation_configuration_); 510 TouchEmulationConfigurationToType(touch_emulation_configuration_);
449 host_->SetTouchEventEmulationEnabled(enabled, config_type); 511 host_->SetTouchEventEmulationEnabled(enabled, config_type);
450 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 512 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
451 WebContents::FromRenderViewHost(host_)); 513 WebContents::FromRenderViewHost(host_));
452 if (web_contents) 514 if (web_contents)
453 web_contents->SetForceDisableOverscrollContent(enabled); 515 web_contents->SetForceDisableOverscrollContent(enabled);
454 } 516 }
455 517
518 void PageHandler::UpdateDeviceEmulationState() {
519 if (!host_)
520 return;
521 if (device_emulation_enabled_) {
522 host_->GetMainFrame()->Send(new DevToolsMsg_EnableDeviceEmulation(
523 host_->GetMainFrame()->GetRoutingID(), device_emulation_params_));
524 } else {
525 host_->GetMainFrame()->Send(new DevToolsMsg_DisableDeviceEmulation(
526 host_->GetMainFrame()->GetRoutingID()));
527 }
528 }
529
456 void PageHandler::NotifyScreencastVisibility(bool visible) { 530 void PageHandler::NotifyScreencastVisibility(bool visible) {
457 if (visible) 531 if (visible)
458 capture_retry_count_ = kCaptureRetryLimit; 532 capture_retry_count_ = kCaptureRetryLimit;
459 client_->ScreencastVisibilityChanged( 533 client_->ScreencastVisibilityChanged(
460 ScreencastVisibilityChangedParams::Create()->set_visible(visible)); 534 ScreencastVisibilityChangedParams::Create()->set_visible(visible));
461 } 535 }
462 536
463 void PageHandler::InnerSwapCompositorFrame() { 537 void PageHandler::InnerSwapCompositorFrame() {
464 if (screencast_frame_sent_ - screencast_frame_acked_ > 538 if (screencast_frame_sent_ - screencast_frame_acked_ >
465 kMaxScreencastFramesInFlight || processing_screencast_frame_) { 539 kMaxScreencastFramesInFlight || processing_screencast_frame_) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 669
596 void PageHandler::OnFramesRecorded( 670 void PageHandler::OnFramesRecorded(
597 DevToolsCommandId command_id, 671 DevToolsCommandId command_id,
598 scoped_refptr<StopRecordingFramesResponse> response_data) { 672 scoped_refptr<StopRecordingFramesResponse> response_data) {
599 client_->SendStopRecordingFramesResponse(command_id, response_data); 673 client_->SendStopRecordingFramesResponse(command_id, response_data);
600 } 674 }
601 675
602 } // namespace page 676 } // namespace page
603 } // namespace devtools 677 } // namespace devtools
604 } // namespace content 678 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698