| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 static const char kPng[] = "png"; | 46 static const char kPng[] = "png"; |
| 47 static const char kJpeg[] = "jpeg"; | 47 static const char kJpeg[] = "jpeg"; |
| 48 static int kDefaultScreenshotQuality = 80; | 48 static int kDefaultScreenshotQuality = 80; |
| 49 static int kFrameRetryDelayMs = 100; | 49 static int kFrameRetryDelayMs = 100; |
| 50 static int kCaptureRetryLimit = 2; | 50 static int kCaptureRetryLimit = 2; |
| 51 static int kMaxScreencastFramesInFlight = 2; | 51 static int kMaxScreencastFramesInFlight = 2; |
| 52 | 52 |
| 53 ui::GestureProviderConfigType TouchEmulationConfigurationToType( |
| 54 const std::string& protocol_value) { |
| 55 ui::GestureProviderConfigType result = |
| 56 ui::GestureProviderConfigType::CURRENT_PLATFORM; |
| 57 if (protocol_value == |
| 58 set_touch_emulation_enabled::kConfigurationMobile) { |
| 59 result = ui::GestureProviderConfigType::GENERIC_MOBILE; |
| 60 } |
| 61 if (protocol_value == |
| 62 set_touch_emulation_enabled::kConfigurationDesktop) { |
| 63 result = ui::GestureProviderConfigType::GENERIC_DESKTOP; |
| 64 } |
| 65 return result; |
| 66 } |
| 67 |
| 53 void QueryUsageAndQuotaCompletedOnIOThread( | 68 void QueryUsageAndQuotaCompletedOnIOThread( |
| 54 const UsageAndQuotaQuery::Callback& callback, | 69 const UsageAndQuotaQuery::Callback& callback, |
| 55 scoped_refptr<QueryUsageAndQuotaResponse> response) { | 70 scoped_refptr<QueryUsageAndQuotaResponse> response) { |
| 56 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 57 base::Bind(callback, response)); | 72 base::Bind(callback, response)); |
| 58 } | 73 } |
| 59 | 74 |
| 60 void QueryUsageAndQuotaOnIOThread( | 75 void QueryUsageAndQuotaOnIOThread( |
| 61 scoped_refptr<storage::QuotaManager> quota_manager, | 76 scoped_refptr<storage::QuotaManager> quota_manager, |
| 62 const GURL& security_origin, | 77 const GURL& security_origin, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 WebContents::FromRenderViewHost(host_)); | 321 WebContents::FromRenderViewHost(host_)); |
| 307 if (!web_contents) | 322 if (!web_contents) |
| 308 return Response::InternalError("No WebContents to override"); | 323 return Response::InternalError("No WebContents to override"); |
| 309 | 324 |
| 310 GeolocationServiceContext* geolocation_context = | 325 GeolocationServiceContext* geolocation_context = |
| 311 web_contents->GetGeolocationServiceContext(); | 326 web_contents->GetGeolocationServiceContext(); |
| 312 geolocation_context->ClearOverride(); | 327 geolocation_context->ClearOverride(); |
| 313 return Response::OK(); | 328 return Response::OK(); |
| 314 } | 329 } |
| 315 | 330 |
| 316 Response PageHandler::SetTouchEmulationEnabled(bool enabled) { | |
| 317 touch_emulation_enabled_ = enabled; | |
| 318 UpdateTouchEventEmulationState(); | |
| 319 return Response::FallThrough(); | |
| 320 } | |
| 321 | |
| 322 Response PageHandler::SetTouchEmulationEnabled( | 331 Response PageHandler::SetTouchEmulationEnabled( |
| 323 bool enabled, const std::string* configuration) { | 332 bool enabled, const std::string* configuration) { |
| 324 touch_emulation_enabled_ = enabled; | 333 touch_emulation_enabled_ = enabled; |
| 325 touch_emulation_configuration_ = | 334 touch_emulation_configuration_ = |
| 326 configuration ? *configuration : std::string(); | 335 configuration ? *configuration : std::string(); |
| 327 UpdateTouchEventEmulationState(); | 336 UpdateTouchEventEmulationState(); |
| 328 return Response::FallThrough(); | 337 return Response::FallThrough(); |
| 329 } | 338 } |
| 330 | 339 |
| 331 Response PageHandler::CaptureScreenshot(DevToolsCommandId command_id) { | 340 Response PageHandler::CaptureScreenshot(DevToolsCommandId command_id) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 return Response::InternalError("Could not connect to view"); | 468 return Response::InternalError("Could not connect to view"); |
| 460 | 469 |
| 461 color_picker_->SetEnabled(enabled); | 470 color_picker_->SetEnabled(enabled); |
| 462 return Response::OK(); | 471 return Response::OK(); |
| 463 } | 472 } |
| 464 | 473 |
| 465 void PageHandler::UpdateTouchEventEmulationState() { | 474 void PageHandler::UpdateTouchEventEmulationState() { |
| 466 if (!host_) | 475 if (!host_) |
| 467 return; | 476 return; |
| 468 bool enabled = touch_emulation_enabled_ || screencast_enabled_; | 477 bool enabled = touch_emulation_enabled_ || screencast_enabled_; |
| 469 // TODO(dgozman): pass |touch_emulation_configuration_| once supported. | 478 ui::GestureProviderConfigType config_type = |
| 470 host_->SetTouchEventEmulationEnabled(enabled); | 479 TouchEmulationConfigurationToType(touch_emulation_configuration_); |
| 480 host_->SetTouchEventEmulationEnabled(enabled, config_type); |
| 471 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 481 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 472 WebContents::FromRenderViewHost(host_)); | 482 WebContents::FromRenderViewHost(host_)); |
| 473 if (web_contents) | 483 if (web_contents) |
| 474 web_contents->SetForceDisableOverscrollContent(enabled); | 484 web_contents->SetForceDisableOverscrollContent(enabled); |
| 475 } | 485 } |
| 476 | 486 |
| 477 void PageHandler::NotifyScreencastVisibility(bool visible) { | 487 void PageHandler::NotifyScreencastVisibility(bool visible) { |
| 478 if (visible) | 488 if (visible) |
| 479 capture_retry_count_ = kCaptureRetryLimit; | 489 capture_retry_count_ = kCaptureRetryLimit; |
| 480 client_->ScreencastVisibilityChanged( | 490 client_->ScreencastVisibilityChanged( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 | 632 |
| 623 void PageHandler::QueryUsageAndQuotaCompleted( | 633 void PageHandler::QueryUsageAndQuotaCompleted( |
| 624 DevToolsCommandId command_id, | 634 DevToolsCommandId command_id, |
| 625 scoped_refptr<QueryUsageAndQuotaResponse> response_data) { | 635 scoped_refptr<QueryUsageAndQuotaResponse> response_data) { |
| 626 client_->SendQueryUsageAndQuotaResponse(command_id, response_data); | 636 client_->SendQueryUsageAndQuotaResponse(command_id, response_data); |
| 627 } | 637 } |
| 628 | 638 |
| 629 } // namespace page | 639 } // namespace page |
| 630 } // namespace devtools | 640 } // namespace devtools |
| 631 } // namespace content | 641 } // namespace content |
| OLD | NEW |