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()); |
dgozman
2014/11/06 14:20:42
nit: indentation
vkuzkokov
2014/11/06 16:30:12
Done.
| |
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; |
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 ScreencastFrameMetadata param_metadata = ScreencastFrameMetadata::Create() |
544 metadata.location_bar_content_translation.y()); | 537 .set_device_scale_factor(metadata.device_scale_factor) |
545 param_metadata.set_offset_bottom(screen_size_dip.height() - | 538 .set_page_scale_factor(metadata.page_scale_factor) |
546 metadata.location_bar_content_translation.y() - | 539 .set_page_scale_factor_min(metadata.min_page_scale_factor) |
547 viewport_size_dip.height()); | 540 .set_page_scale_factor_max(metadata.max_page_scale_factor) |
548 param_metadata.set_device_width(screen_size_dip.width()); | 541 .set_offset_top(metadata.location_bar_content_translation.y()) |
549 param_metadata.set_device_height(screen_size_dip.height()); | 542 .set_offset_bottom(screen_size_dip.height() - |
550 param_metadata.set_scroll_offset_x(metadata.root_scroll_offset.x()); | 543 metadata.location_bar_content_translation.y() - |
551 param_metadata.set_scroll_offset_y(metadata.root_scroll_offset.y()); | 544 viewport_size_dip.height()) |
552 | 545 .set_device_width(screen_size_dip.width()) |
553 devtools::dom::Rect viewport; | 546 .set_device_height(screen_size_dip.height()) |
554 viewport.set_x(metadata.root_scroll_offset.x()); | 547 .set_scroll_offset_x(metadata.root_scroll_offset.x()) |
555 viewport.set_y(metadata.root_scroll_offset.y()); | 548 .set_scroll_offset_y(metadata.root_scroll_offset.y()) |
556 viewport.set_width(metadata.scrollable_viewport_size.width()); | 549 .set_viewport(dom::Rect::Create() |
557 viewport.set_height(metadata.scrollable_viewport_size.height()); | 550 .set_x(metadata.root_scroll_offset.x()) |
558 param_metadata.set_viewport(viewport); | 551 .set_y(metadata.root_scroll_offset.y()) |
559 } | 552 .set_width(metadata.scrollable_viewport_size.width()) |
560 | 553 .set_height(metadata.scrollable_viewport_size.height()) |
561 ScreencastFrameParams params; | 554 .Pass()) |
562 params.set_data(base_64_data); | 555 .Pass(); |
563 params.set_metadata(param_metadata); | 556 client_->ScreencastFrame(ScreencastFrameParams::Create() |
564 client_->ScreencastFrame(params); | 557 .set_data(base_64_data) |
558 .set_metadata(param_metadata.Pass()) | |
559 .Pass()); | |
565 } | 560 } |
566 | 561 |
567 void PageHandler::ScreenshotCaptured( | 562 void PageHandler::ScreenshotCaptured( |
568 scoped_refptr<DevToolsProtocol::Command> command, | 563 scoped_refptr<DevToolsProtocol::Command> command, |
569 const unsigned char* png_data, | 564 const unsigned char* png_data, |
570 size_t png_size) { | 565 size_t png_size) { |
571 if (!png_data || !png_size) { | 566 if (!png_data || !png_size) { |
572 client_->SendInternalErrorResponse(command, | 567 client_->SendInternalErrorResponse(command, |
573 "Unable to capture screenshot"); | 568 "Unable to capture screenshot"); |
574 return; | 569 return; |
575 } | 570 } |
576 | 571 |
577 std::string base_64_data; | 572 std::string base_64_data; |
578 base::Base64Encode( | 573 base::Base64Encode( |
579 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), | 574 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), |
580 &base_64_data); | 575 &base_64_data); |
581 | 576 |
582 CaptureScreenshotResponse response; | 577 client_->SendCaptureScreenshotResponse(command, |
583 response.set_data(base_64_data); | 578 CaptureScreenshotResponse::Create().set_data(base_64_data).Pass()); |
584 client_->SendCaptureScreenshotResponse(command, response); | |
585 } | 579 } |
586 | 580 |
587 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 581 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
588 dom::RGBA color; | 582 dom::RGBA color = |
589 color.set_r(r); | 583 dom::RGBA::Create().set_r(r).set_g(g).set_b(b).set_a(a).Pass(); |
590 color.set_g(g); | 584 client_->ColorPicked( |
591 color.set_b(b); | 585 ColorPickedParams::Create().set_color(color.Pass()).Pass()); |
592 color.set_a(a); | |
593 ColorPickedParams params; | |
594 params.set_color(color); | |
595 client_->ColorPicked(params); | |
596 } | 586 } |
597 | 587 |
598 void PageHandler::QueryUsageAndQuotaCompleted( | 588 void PageHandler::QueryUsageAndQuotaCompleted( |
599 scoped_refptr<DevToolsProtocol::Command> command, | 589 scoped_refptr<DevToolsProtocol::Command> command, |
600 scoped_ptr<QueryUsageAndQuotaResponse> response_data) { | 590 QueryUsageAndQuotaResponse response_data) { |
601 client_->SendQueryUsageAndQuotaResponse(command, *response_data); | 591 client_->SendQueryUsageAndQuotaResponse(command, response_data.Pass()); |
602 } | 592 } |
603 | 593 |
604 } // namespace page | 594 } // namespace page |
605 } // namespace devtools | 595 } // namespace devtools |
606 } // namespace content | 596 } // namespace content |
OLD | NEW |