Chromium Code Reviews| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 static const char kPng[] = "png"; | 44 static const char kPng[] = "png"; |
| 45 static const char kJpeg[] = "jpeg"; | 45 static const char kJpeg[] = "jpeg"; |
| 46 static int kDefaultScreenshotQuality = 80; | 46 static int kDefaultScreenshotQuality = 80; |
| 47 static int kFrameRateThresholdMs = 100; | 47 static int kFrameRateThresholdMs = 100; |
| 48 static int kCaptureRetryLimit = 2; | 48 static int kCaptureRetryLimit = 2; |
| 49 | 49 |
| 50 void QueryUsageAndQuotaCompletedOnIOThread( | 50 void QueryUsageAndQuotaCompletedOnIOThread( |
| 51 const UsageAndQuotaQuery::Callback& callback, | 51 const UsageAndQuotaQuery::Callback& callback, |
| 52 scoped_ptr<QueryUsageAndQuotaResponse> response) { | 52 QueryUsageAndQuotaResponse response) { |
| 53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 53 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 54 base::Bind(callback, base::Passed(&response))); | 54 base::Bind(callback, base::Passed(&response))); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void QueryUsageAndQuotaOnIOThread( | 57 void QueryUsageAndQuotaOnIOThread( |
| 58 scoped_refptr<storage::QuotaManager> quota_manager, | 58 scoped_refptr<storage::QuotaManager> quota_manager, |
| 59 const GURL& security_origin, | 59 const GURL& security_origin, |
| 60 const UsageAndQuotaQuery::Callback& callback) { | 60 const UsageAndQuotaQuery::Callback& callback) { |
| 61 new UsageAndQuotaQuery( | 61 new UsageAndQuotaQuery( |
| 62 quota_manager, | 62 quota_manager, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 116 |
| 117 void PageHandler::OnVisibilityChanged(bool visible) { | 117 void PageHandler::OnVisibilityChanged(bool visible) { |
| 118 if (!screencast_enabled_) | 118 if (!screencast_enabled_) |
| 119 return; | 119 return; |
| 120 NotifyScreencastVisibility(visible); | 120 NotifyScreencastVisibility(visible); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void PageHandler::DidAttachInterstitialPage() { | 123 void PageHandler::DidAttachInterstitialPage() { |
| 124 if (!enabled_) | 124 if (!enabled_) |
| 125 return; | 125 return; |
| 126 InterstitialShownParams params; | 126 client_->InterstitialShown(InterstitialShownParams::Create().Pass()); |
| 127 client_->InterstitialShown(params); | |
| 128 } | 127 } |
| 129 | 128 |
| 130 void PageHandler::DidDetachInterstitialPage() { | 129 void PageHandler::DidDetachInterstitialPage() { |
| 131 if (!enabled_) | 130 if (!enabled_) |
| 132 return; | 131 return; |
| 133 InterstitialHiddenParams params; | 132 client_->InterstitialHidden(InterstitialHiddenParams::Create().Pass()); |
| 134 client_->InterstitialHidden(params); | |
| 135 } | 133 } |
| 136 | 134 |
| 137 Response PageHandler::Enable() { | 135 Response PageHandler::Enable() { |
| 138 enabled_ = true; | 136 enabled_ = true; |
| 139 return Response::FallThrough(); | 137 return Response::FallThrough(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 Response PageHandler::Disable() { | 140 Response PageHandler::Disable() { |
| 143 enabled_ = false; | 141 enabled_ = false; |
| 144 touch_emulation_enabled_ = false; | 142 touch_emulation_enabled_ = false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 if (!web_contents) | 177 if (!web_contents) |
| 180 return Response::InternalError("No WebContents to navigate"); | 178 return Response::InternalError("No WebContents to navigate"); |
| 181 | 179 |
| 182 web_contents->GetController() | 180 web_contents->GetController() |
| 183 .LoadURL(gurl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 181 .LoadURL(gurl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 184 return Response::FallThrough(); | 182 return Response::FallThrough(); |
| 185 } | 183 } |
| 186 | 184 |
| 187 Response PageHandler::GetNavigationHistory( | 185 Response PageHandler::GetNavigationHistory( |
| 188 int* current_index, | 186 int* current_index, |
| 189 std::vector<NavigationEntry>* entries) { | 187 ListBuilder<NavigationEntry>* entries) { |
| 190 if (!host_) | 188 if (!host_) |
| 191 return Response::InternalError("Could not connect to view"); | 189 return Response::InternalError("Could not connect to view"); |
| 192 | 190 |
| 193 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | 191 WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| 194 if (!web_contents) | 192 if (!web_contents) |
| 195 return Response::InternalError("No WebContents to navigate"); | 193 return Response::InternalError("No WebContents to navigate"); |
| 196 | 194 |
| 197 NavigationController& controller = web_contents->GetController(); | 195 NavigationController& controller = web_contents->GetController(); |
| 198 *current_index = controller.GetCurrentEntryIndex(); | 196 *current_index = controller.GetCurrentEntryIndex(); |
| 199 for (int i = 0; i != controller.GetEntryCount(); ++i) { | 197 for (int i = 0; i != controller.GetEntryCount(); ++i) { |
| 200 NavigationEntry entry; | 198 entries->push_back(NavigationEntry::Create() |
| 201 entry.set_id(controller.GetEntryAtIndex(i)->GetUniqueID()); | 199 .set_id(controller.GetEntryAtIndex(i)->GetUniqueID()) |
| 202 entry.set_url(controller.GetEntryAtIndex(i)->GetURL().spec()); | 200 .set_url(controller.GetEntryAtIndex(i)->GetURL().spec()) |
| 203 entry.set_title( | 201 .set_title(base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle())) |
| 204 base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle())); | 202 .Pass()); |
| 205 entries->push_back(entry); | |
| 206 } | 203 } |
| 207 return Response::OK(); | 204 return Response::OK(); |
| 208 } | 205 } |
| 209 | 206 |
| 210 Response PageHandler::NavigateToHistoryEntry(int entry_id) { | 207 Response PageHandler::NavigateToHistoryEntry(int entry_id) { |
| 211 if (!host_) | 208 if (!host_) |
| 212 return Response::InternalError("Could not connect to view"); | 209 return Response::InternalError("Could not connect to view"); |
| 213 | 210 |
| 214 WebContents* web_contents = WebContents::FromRenderViewHost(host_); | 211 WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| 215 if (!web_contents) | 212 if (!web_contents) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 host_->SetTouchEventEmulationEnabled(enabled); | 405 host_->SetTouchEventEmulationEnabled(enabled); |
| 409 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 406 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 410 WebContents::FromRenderViewHost(host_)); | 407 WebContents::FromRenderViewHost(host_)); |
| 411 if (web_contents) | 408 if (web_contents) |
| 412 web_contents->SetForceDisableOverscrollContent(enabled); | 409 web_contents->SetForceDisableOverscrollContent(enabled); |
| 413 } | 410 } |
| 414 | 411 |
| 415 void PageHandler::NotifyScreencastVisibility(bool visible) { | 412 void PageHandler::NotifyScreencastVisibility(bool visible) { |
| 416 if (visible) | 413 if (visible) |
| 417 capture_retry_count_ = kCaptureRetryLimit; | 414 capture_retry_count_ = kCaptureRetryLimit; |
| 418 ScreencastVisibilityChangedParams params; | 415 client_->ScreencastVisibilityChanged( |
| 419 params.set_visible(visible); | 416 ScreencastVisibilityChangedParams::Create() |
| 420 client_->ScreencastVisibilityChanged(params); | 417 .set_visible(visible).Pass()); |
| 421 } | 418 } |
| 422 | 419 |
| 423 void PageHandler::InnerSwapCompositorFrame() { | 420 void PageHandler::InnerSwapCompositorFrame() { |
| 424 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() < | 421 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() < |
| 425 kFrameRateThresholdMs) { | 422 kFrameRateThresholdMs) { |
| 426 return; | 423 return; |
| 427 } | 424 } |
| 428 | 425 |
| 429 if (!host_ || !host_->GetView()) | 426 if (!host_ || !host_->GetView()) |
| 430 return; | 427 return; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 } | 513 } |
| 517 | 514 |
| 518 if (!encoded) | 515 if (!encoded) |
| 519 return; | 516 return; |
| 520 | 517 |
| 521 std::string base_64_data; | 518 std::string base_64_data; |
| 522 base::Base64Encode( | 519 base::Base64Encode( |
| 523 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), | 520 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), |
| 524 &base_64_data); | 521 &base_64_data); |
| 525 | 522 |
| 526 ScreencastFrameMetadata param_metadata; | |
| 527 // Consider metadata empty in case it has no device scale factor. | 523 // Consider metadata empty in case it has no device scale factor. |
| 528 if (metadata.device_scale_factor != 0 && host_) { | 524 if (metadata.device_scale_factor == 0 || !host_) |
| 529 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 525 return; |
|
dgozman
2014/10/29 13:27:45
This changes the semantics - we used to send frame
vkuzkokov
2014/10/29 17:42:02
Not exactly: empty ScreencaseFrameMetadata failed
| |
| 530 host_->GetView()); | |
| 531 if (!view) | |
| 532 return; | |
| 533 | 526 |
| 534 gfx::SizeF viewport_size_dip = gfx::ScaleSize( | 527 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 535 metadata.scrollable_viewport_size, metadata.page_scale_factor); | 528 host_->GetView()); |
| 536 gfx::SizeF screen_size_dip = gfx::ScaleSize( | 529 if (!view) |
| 537 view->GetPhysicalBackingSize(), 1 / metadata.device_scale_factor); | 530 return; |
| 538 | 531 |
| 539 param_metadata.set_device_scale_factor(metadata.device_scale_factor); | 532 gfx::SizeF viewport_size_dip = gfx::ScaleSize( |
| 540 param_metadata.set_page_scale_factor(metadata.page_scale_factor); | 533 metadata.scrollable_viewport_size, metadata.page_scale_factor); |
| 541 param_metadata.set_page_scale_factor_min(metadata.min_page_scale_factor); | 534 gfx::SizeF screen_size_dip = gfx::ScaleSize( |
| 542 param_metadata.set_page_scale_factor_max(metadata.max_page_scale_factor); | 535 view->GetPhysicalBackingSize(), 1 / metadata.device_scale_factor); |
| 543 param_metadata.set_offset_top( | 536 client_->ScreencastFrame(ScreencastFrameParams::Create() |
| 544 metadata.location_bar_content_translation.y()); | 537 .set_data(base_64_data) |
| 545 param_metadata.set_offset_bottom(screen_size_dip.height() - | 538 .set_metadata(ScreencastFrameMetadata::Create() |
|
dgozman
2014/10/29 13:27:45
I'd extract metadata to a separate statement for r
vkuzkokov
2014/10/29 17:42:02
Done.
| |
| 546 metadata.location_bar_content_translation.y() - | 539 .set_device_scale_factor(metadata.device_scale_factor) |
| 547 viewport_size_dip.height()); | 540 .set_page_scale_factor(metadata.page_scale_factor) |
| 548 param_metadata.set_device_width(screen_size_dip.width()); | 541 .set_page_scale_factor_min(metadata.min_page_scale_factor) |
| 549 param_metadata.set_device_height(screen_size_dip.height()); | 542 .set_page_scale_factor_max(metadata.max_page_scale_factor) |
| 550 param_metadata.set_scroll_offset_x(metadata.root_scroll_offset.x()); | 543 .set_offset_top(metadata.location_bar_content_translation.y()) |
| 551 param_metadata.set_scroll_offset_y(metadata.root_scroll_offset.y()); | 544 .set_offset_bottom(screen_size_dip.height() - |
| 552 | 545 metadata.location_bar_content_translation.y() - |
| 553 devtools::dom::Rect viewport; | 546 viewport_size_dip.height()) |
| 554 viewport.set_x(metadata.root_scroll_offset.x()); | 547 .set_device_width(screen_size_dip.width()) |
| 555 viewport.set_y(metadata.root_scroll_offset.y()); | 548 .set_device_height(screen_size_dip.height()) |
| 556 viewport.set_width(metadata.scrollable_viewport_size.width()); | 549 .set_scroll_offset_x(metadata.root_scroll_offset.x()) |
| 557 viewport.set_height(metadata.scrollable_viewport_size.height()); | 550 .set_scroll_offset_y(metadata.root_scroll_offset.y()) |
| 558 param_metadata.set_viewport(viewport); | 551 .set_viewport(dom::Rect::Create() |
| 559 } | 552 .set_x(metadata.root_scroll_offset.x()) |
| 560 | 553 .set_y(metadata.root_scroll_offset.y()) |
| 561 ScreencastFrameParams params; | 554 .set_width(metadata.scrollable_viewport_size.width()) |
| 562 params.set_data(base_64_data); | 555 .set_height(metadata.scrollable_viewport_size.height()) |
| 563 params.set_metadata(param_metadata); | 556 .Pass()) |
| 564 client_->ScreencastFrame(params); | 557 .Pass()) |
| 558 .Pass()); | |
| 565 } | 559 } |
| 566 | 560 |
| 567 void PageHandler::ScreenshotCaptured( | 561 void PageHandler::ScreenshotCaptured( |
| 568 scoped_refptr<DevToolsProtocol::Command> command, | 562 scoped_refptr<DevToolsProtocol::Command> command, |
| 569 const unsigned char* png_data, | 563 const unsigned char* png_data, |
| 570 size_t png_size) { | 564 size_t png_size) { |
| 571 if (!png_data || !png_size) { | 565 if (!png_data || !png_size) { |
| 572 client_->SendInternalErrorResponse(command, | 566 client_->SendInternalErrorResponse(command, |
| 573 "Unable to capture screenshot"); | 567 "Unable to capture screenshot"); |
| 574 return; | 568 return; |
| 575 } | 569 } |
| 576 | 570 |
| 577 std::string base_64_data; | 571 std::string base_64_data; |
| 578 base::Base64Encode( | 572 base::Base64Encode( |
| 579 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), | 573 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), |
| 580 &base_64_data); | 574 &base_64_data); |
| 581 | 575 |
| 582 CaptureScreenshotResponse response; | 576 client_->SendCaptureScreenshotResponse(command, |
| 583 response.set_data(base_64_data); | 577 CaptureScreenshotResponse::Create().set_data(base_64_data).Pass()); |
| 584 client_->SendCaptureScreenshotResponse(command, response); | |
| 585 } | 578 } |
| 586 | 579 |
| 587 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 580 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
| 588 dom::RGBA color; | 581 client_->ColorPicked(ColorPickedParams::Create() |
| 589 color.set_r(r); | 582 .set_color(dom::RGBA::Create().set_r(r).set_g(g).set_b(b).set_a(a).Pass()) |
|
dgozman
2014/10/29 13:27:45
Please extract color into a separate variable.
vkuzkokov
2014/10/29 17:42:03
Done.
| |
| 590 color.set_g(g); | 583 .Pass()); |
| 591 color.set_b(b); | |
| 592 color.set_a(a); | |
| 593 ColorPickedParams params; | |
| 594 params.set_color(color); | |
| 595 client_->ColorPicked(params); | |
| 596 } | 584 } |
| 597 | 585 |
| 598 void PageHandler::QueryUsageAndQuotaCompleted( | 586 void PageHandler::QueryUsageAndQuotaCompleted( |
| 599 scoped_refptr<DevToolsProtocol::Command> command, | 587 scoped_refptr<DevToolsProtocol::Command> command, |
| 600 scoped_ptr<QueryUsageAndQuotaResponse> response_data) { | 588 QueryUsageAndQuotaResponse response_data) { |
| 601 client_->SendQueryUsageAndQuotaResponse(command, *response_data); | 589 client_->SendQueryUsageAndQuotaResponse(command, response_data.Pass()); |
| 602 } | 590 } |
| 603 | 591 |
| 604 } // namespace page | 592 } // namespace page |
| 605 } // namespace devtools | 593 } // namespace devtools |
| 606 } // namespace content | 594 } // namespace content |
| OLD | NEW |