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

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: Fix tests and mac popups compilation 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"
20 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return base_64_data; 100 return base_64_data;
100 } 101 }
101 102
102 } // namespace 103 } // namespace
103 104
104 typedef DevToolsProtocolClient::Response Response; 105 typedef DevToolsProtocolClient::Response Response;
105 106
106 PageHandler::PageHandler() 107 PageHandler::PageHandler()
107 : enabled_(false), 108 : enabled_(false),
108 touch_emulation_enabled_(false), 109 touch_emulation_enabled_(false),
110 device_emulation_enabled_(false),
109 screencast_enabled_(false), 111 screencast_enabled_(false),
110 screencast_quality_(kDefaultScreenshotQuality), 112 screencast_quality_(kDefaultScreenshotQuality),
111 screencast_max_width_(-1), 113 screencast_max_width_(-1),
112 screencast_max_height_(-1), 114 screencast_max_height_(-1),
113 capture_retry_count_(0), 115 capture_retry_count_(0),
114 has_compositor_frame_metadata_(false), 116 has_compositor_frame_metadata_(false),
115 screencast_frame_sent_(0), 117 screencast_frame_sent_(0),
116 screencast_frame_acked_(0), 118 screencast_frame_acked_(0),
117 processing_screencast_frame_(false), 119 processing_screencast_frame_(false),
118 color_picker_(new ColorPicker(base::Bind( 120 color_picker_(new ColorPicker(base::Bind(
119 &PageHandler::OnColorPicked, base::Unretained(this)))), 121 &PageHandler::OnColorPicked, base::Unretained(this)))),
120 frame_recorder_(new FrameRecorder()), 122 frame_recorder_(new FrameRecorder()),
121 host_(nullptr), 123 host_(nullptr),
122 weak_factory_(this) { 124 weak_factory_(this) {
123 } 125 }
124 126
125 PageHandler::~PageHandler() { 127 PageHandler::~PageHandler() {
126 } 128 }
127 129
128 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) { 130 void PageHandler::SetRenderViewHost(RenderViewHostImpl* host) {
129 if (host_ == host) 131 if (host_ == host)
130 return; 132 return;
131 133
132 color_picker_->SetRenderViewHost(host); 134 color_picker_->SetRenderViewHost(host);
133 frame_recorder_->SetRenderViewHost(host); 135 frame_recorder_->SetRenderViewHost(host);
134 host_ = host; 136 host_ = host;
135 UpdateTouchEventEmulationState(); 137 UpdateTouchEventEmulationState();
138 UpdateDeviceEmulationState();
136 } 139 }
137 140
138 void PageHandler::SetClient(scoped_ptr<Client> client) { 141 void PageHandler::SetClient(scoped_ptr<Client> client) {
139 client_.swap(client); 142 client_.swap(client);
140 } 143 }
141 144
142 void PageHandler::Detached() { 145 void PageHandler::Detached() {
143 Disable(); 146 Disable();
144 } 147 }
145 148
(...skipping 30 matching lines...) Expand all
176 179
177 Response PageHandler::Enable() { 180 Response PageHandler::Enable() {
178 enabled_ = true; 181 enabled_ = true;
179 return Response::FallThrough(); 182 return Response::FallThrough();
180 } 183 }
181 184
182 Response PageHandler::Disable() { 185 Response PageHandler::Disable() {
183 enabled_ = false; 186 enabled_ = false;
184 touch_emulation_enabled_ = false; 187 touch_emulation_enabled_ = false;
185 screencast_enabled_ = false; 188 screencast_enabled_ = false;
189 device_emulation_enabled_ = false;
186 UpdateTouchEventEmulationState(); 190 UpdateTouchEventEmulationState();
191 UpdateDeviceEmulationState();
187 color_picker_->SetEnabled(false); 192 color_picker_->SetEnabled(false);
188 return Response::FallThrough(); 193 return Response::FallThrough();
189 } 194 }
190 195
191 Response PageHandler::Reload(const bool* ignoreCache, 196 Response PageHandler::Reload(const bool* ignoreCache,
192 const std::string* script_to_evaluate_on_load, 197 const std::string* script_to_evaluate_on_load,
193 const std::string* script_preprocessor) { 198 const std::string* script_preprocessor) {
194 if (!host_) 199 if (!host_)
195 return Response::InternalError("Could not connect to view"); 200 return Response::InternalError("Could not connect to view");
196 201
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 #endif // defined(OS_ANDROID) 340 #endif // defined(OS_ANDROID)
336 return Response::OK(); 341 return Response::OK();
337 } 342 }
338 343
339 Response PageHandler::CanEmulate(bool* result) { 344 Response PageHandler::CanEmulate(bool* result) {
340 #if defined(OS_ANDROID) 345 #if defined(OS_ANDROID)
341 *result = false; 346 *result = false;
342 #else 347 #else
343 if (host_) { 348 if (host_) {
344 if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) { 349 if (WebContents* web_contents = WebContents::FromRenderViewHost(host_)) {
345 *result = !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme); 350 *result = web_contents->GetMainFrame()->GetRenderViewHost() == host_;
351 #if defined(DEBUG_DEVTOOLS)
352 *result &= !web_contents->GetVisibleURL().SchemeIs(kChromeDevToolsScheme);
353 #endif // defined(DEBUG_DEVTOOLS)
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
356 Response PageHandler::SetDeviceMetricsOverride( 364 Response PageHandler::SetDeviceMetricsOverride(
357 int width, int height, double device_scale_factor, bool mobile, 365 int width, int height, double device_scale_factor, bool mobile,
358 bool fit_window, const double* optional_scale, 366 bool fit_window, const double* optional_scale,
359 const double* optional_offset_x, const double* optional_offset_y) { 367 const double* optional_offset_x, const double* optional_offset_y) {
360 return Response::FallThrough(); 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();
361 } 407 }
362 408
363 Response PageHandler::ClearDeviceMetricsOverride() { 409 Response PageHandler::ClearDeviceMetricsOverride() {
364 return Response::FallThrough(); 410 if (!device_emulation_enabled_)
411 return Response::OK();
412
413 device_emulation_enabled_ = false;
414 UpdateDeviceEmulationState();
415 return Response::OK();
365 } 416 }
366 417
367 Response PageHandler::StartScreencast(const std::string* format, 418 Response PageHandler::StartScreencast(const std::string* format,
368 const int* quality, 419 const int* quality,
369 const int* max_width, 420 const int* max_width,
370 const int* max_height) { 421 const int* max_height) {
371 if (!host_) 422 if (!host_)
372 return Response::InternalError("Could not connect to view"); 423 return Response::InternalError("Could not connect to view");
373 424
374 screencast_enabled_ = true; 425 screencast_enabled_ = true;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 bool enabled = touch_emulation_enabled_ || screencast_enabled_; 508 bool enabled = touch_emulation_enabled_ || screencast_enabled_;
458 ui::GestureProviderConfigType config_type = 509 ui::GestureProviderConfigType config_type =
459 TouchEmulationConfigurationToType(touch_emulation_configuration_); 510 TouchEmulationConfigurationToType(touch_emulation_configuration_);
460 host_->SetTouchEventEmulationEnabled(enabled, config_type); 511 host_->SetTouchEventEmulationEnabled(enabled, config_type);
461 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 512 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
462 WebContents::FromRenderViewHost(host_)); 513 WebContents::FromRenderViewHost(host_));
463 if (web_contents) 514 if (web_contents)
464 web_contents->SetForceDisableOverscrollContent(enabled); 515 web_contents->SetForceDisableOverscrollContent(enabled);
465 } 516 }
466 517
518 void PageHandler::UpdateDeviceEmulationState() {
519 if (!host_)
520 return;
521 if (device_emulation_enabled_) {
522 host_->Send(new ViewMsg_EnableDeviceEmulation(
523 host_->GetRoutingID(), device_emulation_params_));
524 } else {
525 host_->Send(new ViewMsg_DisableDeviceEmulation(host_->GetRoutingID()));
526 }
527 }
528
467 void PageHandler::NotifyScreencastVisibility(bool visible) { 529 void PageHandler::NotifyScreencastVisibility(bool visible) {
468 if (visible) 530 if (visible)
469 capture_retry_count_ = kCaptureRetryLimit; 531 capture_retry_count_ = kCaptureRetryLimit;
470 client_->ScreencastVisibilityChanged( 532 client_->ScreencastVisibilityChanged(
471 ScreencastVisibilityChangedParams::Create()->set_visible(visible)); 533 ScreencastVisibilityChangedParams::Create()->set_visible(visible));
472 } 534 }
473 535
474 void PageHandler::InnerSwapCompositorFrame() { 536 void PageHandler::InnerSwapCompositorFrame() {
475 if (screencast_frame_sent_ - screencast_frame_acked_ > 537 if (screencast_frame_sent_ - screencast_frame_acked_ >
476 kMaxScreencastFramesInFlight || processing_screencast_frame_) { 538 kMaxScreencastFramesInFlight || processing_screencast_frame_) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 668
607 void PageHandler::OnFramesRecorded( 669 void PageHandler::OnFramesRecorded(
608 DevToolsCommandId command_id, 670 DevToolsCommandId command_id,
609 scoped_refptr<StopRecordingFramesResponse> response_data) { 671 scoped_refptr<StopRecordingFramesResponse> response_data) {
610 client_->SendStopRecordingFramesResponse(command_id, response_data); 672 client_->SendStopRecordingFramesResponse(command_id, response_data);
611 } 673 }
612 674
613 } // namespace page 675 } // namespace page
614 } // namespace devtools 676 } // namespace devtools
615 } // namespace content 677 } // 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