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

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

Issue 642263004: [DevTools] Make generated protocol structs wrappers around DictionaryValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(nullptr);
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(nullptr);
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
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 scoped_ptr<NavigationEntry> entry;
dgozman 2014/10/17 10:51:57 I think, default constructor of scoped_ptr will ha
vkuzkokov 2014/10/17 11:41:26 Not every method.
201 entry.set_id(controller.GetEntryAtIndex(i)->GetUniqueID()); 199 entry->set_id(controller.GetEntryAtIndex(i)->GetUniqueID());
202 entry.set_url(controller.GetEntryAtIndex(i)->GetURL().spec()); 200 entry->set_url(controller.GetEntryAtIndex(i)->GetURL().spec());
203 entry.set_title( 201 entry->set_title(
204 base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle())); 202 base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle()));
205 entries->push_back(entry); 203 entries->push_back(entry.Pass());
206 } 204 }
207 return Response::OK(); 205 return Response::OK();
208 } 206 }
209 207
210 Response PageHandler::NavigateToHistoryEntry(int entry_id) { 208 Response PageHandler::NavigateToHistoryEntry(int entry_id) {
211 if (!host_) 209 if (!host_)
212 return Response::InternalError("Could not connect to view"); 210 return Response::InternalError("Could not connect to view");
213 211
214 WebContents* web_contents = WebContents::FromRenderViewHost(host_); 212 WebContents* web_contents = WebContents::FromRenderViewHost(host_);
215 if (!web_contents) 213 if (!web_contents)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 host_->SetTouchEventEmulationEnabled(enabled); 406 host_->SetTouchEventEmulationEnabled(enabled);
409 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 407 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
410 WebContents::FromRenderViewHost(host_)); 408 WebContents::FromRenderViewHost(host_));
411 if (web_contents) 409 if (web_contents)
412 web_contents->SetForceDisableOverscrollContent(enabled); 410 web_contents->SetForceDisableOverscrollContent(enabled);
413 } 411 }
414 412
415 void PageHandler::NotifyScreencastVisibility(bool visible) { 413 void PageHandler::NotifyScreencastVisibility(bool visible) {
416 if (visible) 414 if (visible)
417 capture_retry_count_ = kCaptureRetryLimit; 415 capture_retry_count_ = kCaptureRetryLimit;
418 ScreencastVisibilityChangedParams params; 416 scoped_ptr<ScreencastVisibilityChangedParams> params;
419 params.set_visible(visible); 417 params->set_visible(visible);
420 client_->ScreencastVisibilityChanged(params); 418 client_->ScreencastVisibilityChanged(params.Pass());
421 } 419 }
422 420
423 void PageHandler::InnerSwapCompositorFrame() { 421 void PageHandler::InnerSwapCompositorFrame() {
424 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() < 422 if ((base::TimeTicks::Now() - last_frame_time_).InMilliseconds() <
425 kFrameRateThresholdMs) { 423 kFrameRateThresholdMs) {
426 return; 424 return;
427 } 425 }
428 426
429 if (!host_ || !host_->GetView()) 427 if (!host_ || !host_->GetView())
430 return; 428 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 514 }
517 515
518 if (!encoded) 516 if (!encoded)
519 return; 517 return;
520 518
521 std::string base_64_data; 519 std::string base_64_data;
522 base::Base64Encode( 520 base::Base64Encode(
523 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), 521 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()),
524 &base_64_data); 522 &base_64_data);
525 523
526 ScreencastFrameMetadata param_metadata; 524 scoped_ptr<ScreencastFrameMetadata> param_metadata;
527 // Consider metadata empty in case it has no device scale factor. 525 // Consider metadata empty in case it has no device scale factor.
528 if (metadata.device_scale_factor != 0 && host_) { 526 if (metadata.device_scale_factor != 0 && host_) {
529 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 527 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
530 host_->GetView()); 528 host_->GetView());
531 if (!view) 529 if (!view)
532 return; 530 return;
533 531
534 gfx::SizeF viewport_size_dip = gfx::ScaleSize( 532 gfx::SizeF viewport_size_dip = gfx::ScaleSize(
535 metadata.scrollable_viewport_size, metadata.page_scale_factor); 533 metadata.scrollable_viewport_size, metadata.page_scale_factor);
536 gfx::SizeF screen_size_dip = gfx::ScaleSize( 534 gfx::SizeF screen_size_dip = gfx::ScaleSize(
537 view->GetPhysicalBackingSize(), 1 / metadata.device_scale_factor); 535 view->GetPhysicalBackingSize(), 1 / metadata.device_scale_factor);
538 536
539 param_metadata.set_device_scale_factor(metadata.device_scale_factor); 537 param_metadata->set_device_scale_factor(metadata.device_scale_factor);
540 param_metadata.set_page_scale_factor(metadata.page_scale_factor); 538 param_metadata->set_page_scale_factor(metadata.page_scale_factor);
541 param_metadata.set_page_scale_factor_min(metadata.min_page_scale_factor); 539 param_metadata->set_page_scale_factor_min(metadata.min_page_scale_factor);
542 param_metadata.set_page_scale_factor_max(metadata.max_page_scale_factor); 540 param_metadata->set_page_scale_factor_max(metadata.max_page_scale_factor);
543 param_metadata.set_offset_top( 541 param_metadata->set_offset_top(
544 metadata.location_bar_content_translation.y()); 542 metadata.location_bar_content_translation.y());
545 param_metadata.set_offset_bottom(screen_size_dip.height() - 543 param_metadata->set_offset_bottom(screen_size_dip.height() -
546 metadata.location_bar_content_translation.y() - 544 metadata.location_bar_content_translation.y() -
547 viewport_size_dip.height()); 545 viewport_size_dip.height());
548 param_metadata.set_device_width(screen_size_dip.width()); 546 param_metadata->set_device_width(screen_size_dip.width());
549 param_metadata.set_device_height(screen_size_dip.height()); 547 param_metadata->set_device_height(screen_size_dip.height());
550 param_metadata.set_scroll_offset_x(metadata.root_scroll_offset.x()); 548 param_metadata->set_scroll_offset_x(metadata.root_scroll_offset.x());
551 param_metadata.set_scroll_offset_y(metadata.root_scroll_offset.y()); 549 param_metadata->set_scroll_offset_y(metadata.root_scroll_offset.y());
552 550
553 devtools::dom::Rect viewport; 551 scoped_ptr<devtools::dom::Rect> viewport;
554 viewport.set_x(metadata.root_scroll_offset.x()); 552 viewport->set_x(metadata.root_scroll_offset.x());
555 viewport.set_y(metadata.root_scroll_offset.y()); 553 viewport->set_y(metadata.root_scroll_offset.y());
556 viewport.set_width(metadata.scrollable_viewport_size.width()); 554 viewport->set_width(metadata.scrollable_viewport_size.width());
557 viewport.set_height(metadata.scrollable_viewport_size.height()); 555 viewport->set_height(metadata.scrollable_viewport_size.height());
558 param_metadata.set_viewport(viewport); 556 param_metadata->set_viewport(viewport.Pass());
559 } 557 }
560 558
561 ScreencastFrameParams params; 559 scoped_ptr<ScreencastFrameParams> params;
562 params.set_data(base_64_data); 560 params->set_data(base_64_data);
563 params.set_metadata(param_metadata); 561 params->set_metadata(param_metadata.Pass());
564 client_->ScreencastFrame(params); 562 client_->ScreencastFrame(params.Pass());
565 } 563 }
566 564
567 void PageHandler::ScreenshotCaptured( 565 void PageHandler::ScreenshotCaptured(
568 scoped_refptr<DevToolsProtocol::Command> command, 566 scoped_refptr<DevToolsProtocol::Command> command,
569 const unsigned char* png_data, 567 const unsigned char* png_data,
570 size_t png_size) { 568 size_t png_size) {
571 if (!png_data || !png_size) { 569 if (!png_data || !png_size) {
572 client_->SendInternalErrorResponse(command, 570 client_->SendInternalErrorResponse(command,
573 "Unable to capture screenshot"); 571 "Unable to capture screenshot");
574 return; 572 return;
575 } 573 }
576 574
577 std::string base_64_data; 575 std::string base_64_data;
578 base::Base64Encode( 576 base::Base64Encode(
579 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), 577 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size),
580 &base_64_data); 578 &base_64_data);
581 579
582 CaptureScreenshotResponse response; 580 scoped_ptr<CaptureScreenshotResponse> response;
583 response.set_data(base_64_data); 581 response->set_data(base_64_data);
584 client_->SendCaptureScreenshotResponse(command, response); 582 client_->SendCaptureScreenshotResponse(command, response.Pass());
585 } 583 }
586 584
587 void PageHandler::OnColorPicked(int r, int g, int b, int a) { 585 void PageHandler::OnColorPicked(int r, int g, int b, int a) {
588 dom::RGBA color; 586 scoped_ptr<dom::RGBA> color;
589 color.set_r(r); 587 color->set_r(r);
590 color.set_g(g); 588 color->set_g(g);
591 color.set_b(b); 589 color->set_b(b);
592 color.set_a(a); 590 color->set_a(a);
593 ColorPickedParams params; 591 scoped_ptr<ColorPickedParams> params;
594 params.set_color(color); 592 params->set_color(color.Pass());
595 client_->ColorPicked(params); 593 client_->ColorPicked(params.Pass());
596 } 594 }
597 595
598 void PageHandler::QueryUsageAndQuotaCompleted( 596 void PageHandler::QueryUsageAndQuotaCompleted(
599 scoped_refptr<DevToolsProtocol::Command> command, 597 scoped_refptr<DevToolsProtocol::Command> command,
600 scoped_ptr<QueryUsageAndQuotaResponse> response_data) { 598 scoped_ptr<QueryUsageAndQuotaResponse> response_data) {
601 client_->SendQueryUsageAndQuotaResponse(command, *response_data); 599 client_->SendQueryUsageAndQuotaResponse(command, response_data.Pass());
602 } 600 }
603 601
604 } // namespace page 602 } // namespace page
605 } // namespace devtools 603 } // namespace devtools
606 } // namespace content 604 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698