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

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

Issue 2548263002: [DevTools] Migrate dom, emulation, inspector, network, page and schema handlers to new generator. (Closed)
Patch Set: rebased atop of roll Created 4 years 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 22 matching lines...) Expand all
33 #include "content/public/common/referrer.h" 33 #include "content/public/common/referrer.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 34 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/base/page_transition_types.h" 35 #include "ui/base/page_transition_types.h"
36 #include "ui/gfx/codec/jpeg_codec.h" 36 #include "ui/gfx/codec/jpeg_codec.h"
37 #include "ui/gfx/codec/png_codec.h" 37 #include "ui/gfx/codec/png_codec.h"
38 #include "ui/gfx/geometry/size_conversions.h" 38 #include "ui/gfx/geometry/size_conversions.h"
39 #include "ui/snapshot/snapshot.h" 39 #include "ui/snapshot/snapshot.h"
40 #include "url/gurl.h" 40 #include "url/gurl.h"
41 41
42 namespace content { 42 namespace content {
43 namespace devtools { 43 namespace protocol {
44 namespace page {
45 44
46 namespace { 45 namespace {
47 46
48 static const char kPng[] = "png"; 47 static const char kPng[] = "png";
49 static const char kJpeg[] = "jpeg"; 48 static const char kJpeg[] = "jpeg";
50 static int kDefaultScreenshotQuality = 80; 49 static int kDefaultScreenshotQuality = 80;
51 static int kFrameRetryDelayMs = 100; 50 static int kFrameRetryDelayMs = 100;
52 static int kCaptureRetryLimit = 2; 51 static int kCaptureRetryLimit = 2;
53 static int kMaxScreencastFramesInFlight = 2; 52 static int kMaxScreencastFramesInFlight = 2;
54 53
(...skipping 28 matching lines...) Expand all
83 std::string base_64_data; 82 std::string base_64_data;
84 base::Base64Encode( 83 base::Base64Encode(
85 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()), 84 base::StringPiece(reinterpret_cast<char*>(&data[0]), data.size()),
86 &base_64_data); 85 &base_64_data);
87 86
88 return base_64_data; 87 return base_64_data;
89 } 88 }
90 89
91 } // namespace 90 } // namespace
92 91
93 typedef DevToolsProtocolClient::Response Response;
94
95 PageHandler::PageHandler() 92 PageHandler::PageHandler()
96 : enabled_(false), 93 : enabled_(false),
97 screencast_enabled_(false), 94 screencast_enabled_(false),
98 screencast_quality_(kDefaultScreenshotQuality), 95 screencast_quality_(kDefaultScreenshotQuality),
99 screencast_max_width_(-1), 96 screencast_max_width_(-1),
100 screencast_max_height_(-1), 97 screencast_max_height_(-1),
101 capture_every_nth_frame_(1), 98 capture_every_nth_frame_(1),
102 capture_retry_count_(0), 99 capture_retry_count_(0),
103 has_compositor_frame_metadata_(false), 100 has_compositor_frame_metadata_(false),
104 session_id_(0), 101 session_id_(0),
(...skipping 27 matching lines...) Expand all
132 color_picker_->SetRenderWidgetHost(widget_host); 129 color_picker_->SetRenderWidgetHost(widget_host);
133 130
134 if (widget_host) { 131 if (widget_host) {
135 registrar_.Add( 132 registrar_.Add(
136 this, 133 this,
137 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 134 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
138 content::Source<RenderWidgetHost>(widget_host)); 135 content::Source<RenderWidgetHost>(widget_host));
139 } 136 }
140 } 137 }
141 138
142 void PageHandler::SetClient(std::unique_ptr<Client> client) { 139 void PageHandler::Wire(UberDispatcher* dispatcher) {
143 client_.swap(client); 140 frontend_.reset(new Page::Frontend(dispatcher->channel()));
144 } 141 Page::Dispatcher::wire(dispatcher, this);
145
146 void PageHandler::Detached() {
147 Disable();
148 } 142 }
149 143
150 void PageHandler::OnSwapCompositorFrame( 144 void PageHandler::OnSwapCompositorFrame(
151 cc::CompositorFrameMetadata frame_metadata) { 145 cc::CompositorFrameMetadata frame_metadata) {
152 last_compositor_frame_metadata_ = std::move(frame_metadata); 146 last_compositor_frame_metadata_ = std::move(frame_metadata);
153 has_compositor_frame_metadata_ = true; 147 has_compositor_frame_metadata_ = true;
154 148
155 if (screencast_enabled_) 149 if (screencast_enabled_)
156 InnerSwapCompositorFrame(); 150 InnerSwapCompositorFrame();
157 color_picker_->OnSwapCompositorFrame(); 151 color_picker_->OnSwapCompositorFrame();
(...skipping 22 matching lines...) Expand all
180 if (!screencast_enabled_) 174 if (!screencast_enabled_)
181 return; 175 return;
182 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED); 176 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED);
183 bool visible = *Details<bool>(details).ptr(); 177 bool visible = *Details<bool>(details).ptr();
184 NotifyScreencastVisibility(visible); 178 NotifyScreencastVisibility(visible);
185 } 179 }
186 180
187 void PageHandler::DidAttachInterstitialPage() { 181 void PageHandler::DidAttachInterstitialPage() {
188 if (!enabled_) 182 if (!enabled_)
189 return; 183 return;
190 client_->InterstitialShown(InterstitialShownParams::Create()); 184 frontend_->InterstitialShown();
191 } 185 }
192 186
193 void PageHandler::DidDetachInterstitialPage() { 187 void PageHandler::DidDetachInterstitialPage() {
194 if (!enabled_) 188 if (!enabled_)
195 return; 189 return;
196 client_->InterstitialHidden(InterstitialHiddenParams::Create()); 190 frontend_->InterstitialHidden();
197 } 191 }
198 192
199 Response PageHandler::Enable() { 193 Response PageHandler::Enable() {
200 enabled_ = true; 194 enabled_ = true;
201 if (GetWebContents() && GetWebContents()->ShowingInterstitialPage()) 195 if (GetWebContents() && GetWebContents()->ShowingInterstitialPage())
202 client_->InterstitialShown(InterstitialShownParams::Create()); 196 frontend_->InterstitialShown();
203 return Response::FallThrough(); 197 return Response::FallThrough();
204 } 198 }
205 199
206 Response PageHandler::Disable() { 200 Response PageHandler::Disable() {
207 enabled_ = false; 201 enabled_ = false;
208 screencast_enabled_ = false; 202 screencast_enabled_ = false;
209 SetControlNavigations(false); 203 SetControlNavigations(false);
210 color_picker_->SetEnabled(false); 204 color_picker_->SetEnabled(false);
211 return Response::FallThrough(); 205 return Response::FallThrough();
212 } 206 }
213 207
214 Response PageHandler::Reload(const bool* bypassCache, 208 Response PageHandler::Reload(Maybe<bool> bypassCache,
215 const std::string* script_to_evaluate_on_load, 209 Maybe<std::string> script_to_evaluate_on_load) {
216 const std::string* script_preprocessor) {
217 WebContentsImpl* web_contents = GetWebContents(); 210 WebContentsImpl* web_contents = GetWebContents();
218 if (!web_contents) 211 if (!web_contents)
219 return Response::InternalError("Could not connect to view"); 212 return Response::InternalError();
220 213
221 if (web_contents->IsCrashed() || 214 if (web_contents->IsCrashed() ||
222 (web_contents->GetController().GetVisibleEntry() && 215 (web_contents->GetController().GetVisibleEntry() &&
223 web_contents->GetController().GetVisibleEntry()->IsViewSourceMode())) { 216 web_contents->GetController().GetVisibleEntry()->IsViewSourceMode())) {
224 if (bypassCache && *bypassCache) 217 if (bypassCache.fromMaybe(false))
225 web_contents->GetController().ReloadBypassingCache(false); 218 web_contents->GetController().ReloadBypassingCache(false);
226 else 219 else
227 web_contents->GetController().Reload(false); 220 web_contents->GetController().Reload(false);
228 return Response::OK(); 221 return Response::OK();
229 } else { 222 } else {
230 // Handle reload in renderer except for crashed and view source mode. 223 // Handle reload in renderer except for crashed and view source mode.
231 return Response::FallThrough(); 224 return Response::FallThrough();
232 } 225 }
233 } 226 }
234 227
235 Response PageHandler::Navigate(const std::string& url, 228 Response PageHandler::Navigate(const std::string& url,
236 FrameId* frame_id) { 229 Page::FrameId* frame_id) {
237 GURL gurl(url); 230 GURL gurl(url);
238 if (!gurl.is_valid()) 231 if (!gurl.is_valid())
239 return Response::InternalError("Cannot navigate to invalid URL"); 232 return Response::Error("Cannot navigate to invalid URL");
240 233
241 WebContentsImpl* web_contents = GetWebContents(); 234 WebContentsImpl* web_contents = GetWebContents();
242 if (!web_contents) 235 if (!web_contents)
243 return Response::InternalError("Could not connect to view"); 236 return Response::InternalError();
244 237
245 web_contents->GetController() 238 web_contents->GetController()
246 .LoadURL(gurl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 239 .LoadURL(gurl, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
247 return Response::FallThrough(); 240 return Response::FallThrough();
248 } 241 }
249 242
250 Response PageHandler::GetNavigationHistory(int* current_index, 243 Response PageHandler::GetNavigationHistory(
251 NavigationEntries* entries) { 244 int* current_index,
245 std::unique_ptr<NavigationEntries>* entries) {
252 WebContentsImpl* web_contents = GetWebContents(); 246 WebContentsImpl* web_contents = GetWebContents();
253 if (!web_contents) 247 if (!web_contents)
254 return Response::InternalError("Could not connect to view"); 248 return Response::InternalError();
255 249
256 NavigationController& controller = web_contents->GetController(); 250 NavigationController& controller = web_contents->GetController();
257 *current_index = controller.GetCurrentEntryIndex(); 251 *current_index = controller.GetCurrentEntryIndex();
252 *entries = NavigationEntries::create();
258 for (int i = 0; i != controller.GetEntryCount(); ++i) { 253 for (int i = 0; i != controller.GetEntryCount(); ++i) {
259 entries->push_back(NavigationEntry::Create() 254 (*entries)->addItem(Page::NavigationEntry::Create()
260 ->set_id(controller.GetEntryAtIndex(i)->GetUniqueID()) 255 .SetId(controller.GetEntryAtIndex(i)->GetUniqueID())
261 ->set_url(controller.GetEntryAtIndex(i)->GetURL().spec()) 256 .SetUrl(controller.GetEntryAtIndex(i)->GetURL().spec())
262 ->set_title( 257 .SetTitle(base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle()))
263 base::UTF16ToUTF8(controller.GetEntryAtIndex(i)->GetTitle()))); 258 .Build());
264 } 259 }
265 return Response::OK(); 260 return Response::OK();
266 } 261 }
267 262
268 Response PageHandler::NavigateToHistoryEntry(int entry_id) { 263 Response PageHandler::NavigateToHistoryEntry(int entry_id) {
269 WebContentsImpl* web_contents = GetWebContents(); 264 WebContentsImpl* web_contents = GetWebContents();
270 if (!web_contents) 265 if (!web_contents)
271 return Response::InternalError("Could not connect to view"); 266 return Response::InternalError();
272 267
273 NavigationController& controller = web_contents->GetController(); 268 NavigationController& controller = web_contents->GetController();
274 for (int i = 0; i != controller.GetEntryCount(); ++i) { 269 for (int i = 0; i != controller.GetEntryCount(); ++i) {
275 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) { 270 if (controller.GetEntryAtIndex(i)->GetUniqueID() == entry_id) {
276 controller.GoToIndex(i); 271 controller.GoToIndex(i);
277 return Response::OK(); 272 return Response::OK();
278 } 273 }
279 } 274 }
280 275
281 return Response::InvalidParams("No entry with passed id"); 276 return Response::InvalidParams("No entry with passed id");
282 } 277 }
283 278
284 Response PageHandler::CaptureScreenshot(DevToolsCommandId command_id) { 279 void PageHandler::CaptureScreenshot(
285 if (!host_ || !host_->GetRenderWidgetHost()) 280 std::unique_ptr<CaptureScreenshotCallback> callback) {
286 return Response::InternalError("Could not connect to view"); 281 if (!host_ || !host_->GetRenderWidgetHost()) {
282 callback->sendFailure(Response::InternalError());
283 return;
284 }
287 285
288 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser( 286 host_->GetRenderWidgetHost()->GetSnapshotFromBrowser(
289 base::Bind(&PageHandler::ScreenshotCaptured, 287 base::Bind(&PageHandler::ScreenshotCaptured,
290 weak_factory_.GetWeakPtr(), command_id)); 288 weak_factory_.GetWeakPtr(), base::Passed(std::move(callback))));
291 return Response::OK();
292 } 289 }
293 290
294 Response PageHandler::StartScreencast(const std::string* format, 291 Response PageHandler::StartScreencast(Maybe<std::string> format,
295 const int* quality, 292 Maybe<int> quality,
296 const int* max_width, 293 Maybe<int> max_width,
297 const int* max_height, 294 Maybe<int> max_height,
298 const int* every_nth_frame) { 295 Maybe<int> every_nth_frame) {
299 RenderWidgetHostImpl* widget_host = 296 RenderWidgetHostImpl* widget_host =
300 host_ ? host_->GetRenderWidgetHost() : nullptr; 297 host_ ? host_->GetRenderWidgetHost() : nullptr;
301 if (!widget_host) 298 if (!widget_host)
302 return Response::InternalError("Could not connect to view"); 299 return Response::InternalError();
303 300
304 screencast_enabled_ = true; 301 screencast_enabled_ = true;
305 screencast_format_ = format ? *format : kPng; 302 screencast_format_ = format.fromMaybe(kPng);
306 screencast_quality_ = quality ? *quality : kDefaultScreenshotQuality; 303 screencast_quality_ = quality.fromMaybe(kDefaultScreenshotQuality);
307 if (screencast_quality_ < 0 || screencast_quality_ > 100) 304 if (screencast_quality_ < 0 || screencast_quality_ > 100)
308 screencast_quality_ = kDefaultScreenshotQuality; 305 screencast_quality_ = kDefaultScreenshotQuality;
309 screencast_max_width_ = max_width ? *max_width : -1; 306 screencast_max_width_ = max_width.fromMaybe(-1);
310 screencast_max_height_ = max_height ? *max_height : -1; 307 screencast_max_height_ = max_height.fromMaybe(-1);
311 ++session_id_; 308 ++session_id_;
312 frame_counter_ = 0; 309 frame_counter_ = 0;
313 frames_in_flight_ = 0; 310 frames_in_flight_ = 0;
314 capture_every_nth_frame_ = 311 capture_every_nth_frame_ = every_nth_frame.fromMaybe(1);
315 every_nth_frame && *every_nth_frame ? *every_nth_frame : 1;
316 312
317 bool visible = !widget_host->is_hidden(); 313 bool visible = !widget_host->is_hidden();
318 NotifyScreencastVisibility(visible); 314 NotifyScreencastVisibility(visible);
319 if (visible) { 315 if (visible) {
320 if (has_compositor_frame_metadata_) { 316 if (has_compositor_frame_metadata_) {
321 InnerSwapCompositorFrame(); 317 InnerSwapCompositorFrame();
322 } else { 318 } else {
323 widget_host->Send(new ViewMsg_ForceRedraw(widget_host->GetRoutingID(), 319 widget_host->Send(new ViewMsg_ForceRedraw(widget_host->GetRoutingID(),
324 ui::LatencyInfo())); 320 ui::LatencyInfo()));
325 } 321 }
326 } 322 }
327 return Response::FallThrough(); 323 return Response::FallThrough();
328 } 324 }
329 325
330 Response PageHandler::StopScreencast() { 326 Response PageHandler::StopScreencast() {
331 screencast_enabled_ = false; 327 screencast_enabled_ = false;
332 return Response::FallThrough(); 328 return Response::FallThrough();
333 } 329 }
334 330
335 Response PageHandler::ScreencastFrameAck(int session_id) { 331 Response PageHandler::ScreencastFrameAck(int session_id) {
336 if (session_id == session_id_) 332 if (session_id == session_id_)
337 --frames_in_flight_; 333 --frames_in_flight_;
338 return Response::OK(); 334 return Response::OK();
339 } 335 }
340 336
341 Response PageHandler::HandleJavaScriptDialog(bool accept, 337 Response PageHandler::HandleJavaScriptDialog(bool accept,
342 const std::string* prompt_text) { 338 Maybe<std::string> prompt_text) {
343 base::string16 prompt_override; 339 base::string16 prompt_override;
344 if (prompt_text) 340 if (prompt_text.isJust())
345 prompt_override = base::UTF8ToUTF16(*prompt_text); 341 prompt_override = base::UTF8ToUTF16(prompt_text.fromJust());
346 342
347 WebContentsImpl* web_contents = GetWebContents(); 343 WebContentsImpl* web_contents = GetWebContents();
348 if (!web_contents) 344 if (!web_contents)
349 return Response::InternalError("Could not connect to view"); 345 return Response::InternalError();
350 346
351 JavaScriptDialogManager* manager = 347 JavaScriptDialogManager* manager =
352 web_contents->GetDelegate()->GetJavaScriptDialogManager(web_contents); 348 web_contents->GetDelegate()->GetJavaScriptDialogManager(web_contents);
353 if (manager && manager->HandleJavaScriptDialog( 349 if (manager && manager->HandleJavaScriptDialog(
354 web_contents, accept, prompt_text ? &prompt_override : nullptr)) { 350 web_contents, accept,
351 prompt_text.isJust() ? &prompt_override : nullptr)) {
355 return Response::OK(); 352 return Response::OK();
356 } 353 }
357 354
358 return Response::InternalError("Could not handle JavaScript dialog"); 355 return Response::Error("Could not handle JavaScript dialog");
359 }
360
361 Response PageHandler::QueryUsageAndQuota(DevToolsCommandId command_id,
362 const std::string& security_origin) {
363 return Response::OK();
364 } 356 }
365 357
366 Response PageHandler::SetColorPickerEnabled(bool enabled) { 358 Response PageHandler::SetColorPickerEnabled(bool enabled) {
367 if (!host_) 359 if (!host_)
368 return Response::InternalError("Could not connect to view"); 360 return Response::InternalError();
369 361
370 color_picker_->SetEnabled(enabled); 362 color_picker_->SetEnabled(enabled);
371 return Response::OK(); 363 return Response::OK();
372 } 364 }
373 365
374 Response PageHandler::RequestAppBanner() { 366 Response PageHandler::RequestAppBanner() {
375 WebContentsImpl* web_contents = GetWebContents(); 367 WebContentsImpl* web_contents = GetWebContents();
376 if (!web_contents) 368 if (!web_contents)
377 return Response::InternalError("Could not connect to view"); 369 return Response::InternalError();
378 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); 370 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents);
379 return Response::OK(); 371 return Response::OK();
380 } 372 }
381 373
382 Response PageHandler::SetControlNavigations(bool enabled) { 374 Response PageHandler::SetControlNavigations(bool enabled) {
383 navigation_throttle_enabled_ = enabled; 375 navigation_throttle_enabled_ = enabled;
384 // We don't own the page PageNavigationThrottles so we can't delete them, but 376 // We don't own the page PageNavigationThrottles so we can't delete them, but
385 // we can turn them into NOPs. 377 // we can turn them into NOPs.
386 for (auto& pair : navigation_throttles_) { 378 for (auto& pair : navigation_throttles_) {
387 pair.second->AlwaysProceed(); 379 pair.second->AlwaysProceed();
388 } 380 }
389 navigation_throttles_.clear(); 381 navigation_throttles_.clear();
390 return Response::OK(); 382 return Response::OK();
391 } 383 }
392 384
393 Response PageHandler::ProcessNavigation(const std::string& response, 385 Response PageHandler::ProcessNavigation(const std::string& response,
394 int navigation_id) { 386 int navigation_id) {
395 auto it = navigation_throttles_.find(navigation_id); 387 auto it = navigation_throttles_.find(navigation_id);
396 if (it == navigation_throttles_.end()) 388 if (it == navigation_throttles_.end())
397 return Response::InvalidParams("Unknown navigation id"); 389 return Response::InvalidParams("Unknown navigation id");
398 390
399 if (response == kNavigationResponseProceed) { 391 if (response == Page::NavigationResponseEnum::Proceed) {
400 it->second->Resume(); 392 it->second->Resume();
401 return Response::OK(); 393 return Response::OK();
402 } else if (response == kNavigationResponseCancel) { 394 } else if (response == Page::NavigationResponseEnum::Cancel) {
403 it->second->CancelDeferredNavigation(content::NavigationThrottle::CANCEL); 395 it->second->CancelDeferredNavigation(content::NavigationThrottle::CANCEL);
404 return Response::OK(); 396 return Response::OK();
405 } else if (response == kNavigationResponseCancelAndIgnore) { 397 } else if (response == Page::NavigationResponseEnum::CancelAndIgnore) {
406 it->second->CancelDeferredNavigation( 398 it->second->CancelDeferredNavigation(
407 content::NavigationThrottle::CANCEL_AND_IGNORE); 399 content::NavigationThrottle::CANCEL_AND_IGNORE);
408 return Response::OK(); 400 return Response::OK();
409 } 401 }
410 402
411 return Response::InvalidParams("Unrecognized response"); 403 return Response::InvalidParams("Unrecognized response");
412 } 404 }
413 405
414 Response PageHandler::AddScriptToEvaluateOnLoad(const std::string& source,
415 std::string* identifier) {
416 return Response::FallThrough();
417 }
418
419 Response PageHandler::RemoveScriptToEvaluateOnLoad(
420 const std::string& identifier) {
421 return Response::FallThrough();
422 }
423
424 Response PageHandler::SetAutoAttachToCreatedPages(bool auto_attach) {
425 return Response::FallThrough();
426 }
427
428 Response PageHandler::GetResourceTree(scoped_refptr<FrameResourceTree>* tree) {
429 return Response::FallThrough();
430 }
431
432 Response PageHandler::GetResourceContent(DevToolsCommandId command_id,
433 const std::string& frame_id,
434 const std::string& url) {
435 return Response::FallThrough();
436 }
437
438 Response PageHandler::SearchInResource(DevToolsCommandId command_id,
439 const std::string& frame_id,
440 const std::string& url,
441 const std::string& query,
442 bool* case_sensitive,
443 bool* is_regex) {
444 return Response::FallThrough();
445 }
446
447 Response PageHandler::SetDocumentContent(const std::string& frame_id,
448 const std::string& html) {
449 return Response::FallThrough();
450 }
451
452 Response PageHandler::ConfigureOverlay(const bool* is_suspended,
453 const std::string* message) {
454 return Response::FallThrough();
455 }
456
457 Response PageHandler::GetAppManifest(
458 std::string* url,
459 std::vector<scoped_refptr<AppManifestError>>* errors,
460 std::string* data) {
461 return Response::FallThrough();
462 }
463
464 Response PageHandler::GetLayoutMetrics(
465 scoped_refptr<LayoutViewport>* layout_viewport,
466 scoped_refptr<VisualViewport>* visual_viewport) {
467 return Response::FallThrough();
468 }
469
470 std::unique_ptr<PageNavigationThrottle> 406 std::unique_ptr<PageNavigationThrottle>
471 PageHandler::CreateThrottleForNavigation(NavigationHandle* navigation_handle) { 407 PageHandler::CreateThrottleForNavigation(NavigationHandle* navigation_handle) {
472 if (!navigation_throttle_enabled_) 408 if (!navigation_throttle_enabled_)
473 return nullptr; 409 return nullptr;
474 410
475 std::unique_ptr<PageNavigationThrottle> throttle(new PageNavigationThrottle( 411 std::unique_ptr<PageNavigationThrottle> throttle(new PageNavigationThrottle(
476 weak_factory_.GetWeakPtr(), next_navigation_id_, navigation_handle)); 412 weak_factory_.GetWeakPtr(), next_navigation_id_, navigation_handle));
477 navigation_throttles_[next_navigation_id_++] = throttle.get(); 413 navigation_throttles_[next_navigation_id_++] = throttle.get();
478 return throttle; 414 return throttle;
479 } 415 }
480 416
481 void PageHandler::OnPageNavigationThrottleDisposed(int navigation_id) { 417 void PageHandler::OnPageNavigationThrottleDisposed(int navigation_id) {
482 DCHECK(navigation_throttles_.find(navigation_id) != 418 DCHECK(navigation_throttles_.find(navigation_id) !=
483 navigation_throttles_.end()); 419 navigation_throttles_.end());
484 navigation_throttles_.erase(navigation_id); 420 navigation_throttles_.erase(navigation_id);
485 } 421 }
486 422
487 void PageHandler::NavigationRequested(const PageNavigationThrottle* throttle) { 423 void PageHandler::NavigationRequested(const PageNavigationThrottle* throttle) {
488 NavigationHandle* navigation_handle = throttle->navigation_handle(); 424 NavigationHandle* navigation_handle = throttle->navigation_handle();
489 client_->NavigationRequested( 425 frontend_->NavigationRequested(
490 NavigationRequestedParams::Create() 426 navigation_handle->IsInMainFrame(),
491 ->set_is_in_main_frame(navigation_handle->IsInMainFrame()) 427 navigation_handle->WasServerRedirect(),
492 ->set_is_redirect(navigation_handle->WasServerRedirect()) 428 throttle->navigation_id(),
493 ->set_navigation_id(throttle->navigation_id()) 429 navigation_handle->GetURL().spec());
494 ->set_url(navigation_handle->GetURL().spec()));
495 } 430 }
496 431
497 WebContentsImpl* PageHandler::GetWebContents() { 432 WebContentsImpl* PageHandler::GetWebContents() {
498 return host_ ? 433 return host_ ?
499 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : 434 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) :
500 nullptr; 435 nullptr;
501 } 436 }
502 437
503 void PageHandler::NotifyScreencastVisibility(bool visible) { 438 void PageHandler::NotifyScreencastVisibility(bool visible) {
504 if (visible) 439 if (visible)
505 capture_retry_count_ = kCaptureRetryLimit; 440 capture_retry_count_ = kCaptureRetryLimit;
506 client_->ScreencastVisibilityChanged( 441 frontend_->ScreencastVisibilityChanged(visible);
507 ScreencastVisibilityChangedParams::Create()->set_visible(visible));
508 } 442 }
509 443
510 void PageHandler::InnerSwapCompositorFrame() { 444 void PageHandler::InnerSwapCompositorFrame() {
511 if (!host_ || !host_->GetView()) 445 if (!host_ || !host_->GetView())
512 return; 446 return;
513 447
514 if (frames_in_flight_ > kMaxScreencastFramesInFlight) 448 if (frames_in_flight_ > kMaxScreencastFramesInFlight)
515 return; 449 return;
516 450
517 if (++frame_counter_ % capture_every_nth_frame_) 451 if (++frame_counter_ % capture_every_nth_frame_)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 529 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
596 host_->GetView()); 530 host_->GetView());
597 if (!view) { 531 if (!view) {
598 --frames_in_flight_; 532 --frames_in_flight_;
599 return; 533 return;
600 } 534 }
601 535
602 gfx::SizeF screen_size_dip = 536 gfx::SizeF screen_size_dip =
603 gfx::ScaleSize(gfx::SizeF(view->GetPhysicalBackingSize()), 537 gfx::ScaleSize(gfx::SizeF(view->GetPhysicalBackingSize()),
604 1 / metadata.device_scale_factor); 538 1 / metadata.device_scale_factor);
605 scoped_refptr<ScreencastFrameMetadata> param_metadata = 539 std::unique_ptr<Page::ScreencastFrameMetadata> param_metadata =
606 ScreencastFrameMetadata::Create() 540 Page::ScreencastFrameMetadata::Create()
607 ->set_page_scale_factor(metadata.page_scale_factor) 541 .SetPageScaleFactor(metadata.page_scale_factor)
608 ->set_offset_top(metadata.top_controls_height * 542 .SetOffsetTop(metadata.top_controls_height *
609 metadata.top_controls_shown_ratio) 543 metadata.top_controls_shown_ratio)
610 ->set_device_width(screen_size_dip.width()) 544 .SetDeviceWidth(screen_size_dip.width())
611 ->set_device_height(screen_size_dip.height()) 545 .SetDeviceHeight(screen_size_dip.height())
612 ->set_scroll_offset_x(metadata.root_scroll_offset.x()) 546 .SetScrollOffsetX(metadata.root_scroll_offset.x())
613 ->set_scroll_offset_y(metadata.root_scroll_offset.y()) 547 .SetScrollOffsetY(metadata.root_scroll_offset.y())
614 ->set_timestamp(timestamp.ToDoubleT()); 548 .SetTimestamp(timestamp.ToDoubleT())
615 client_->ScreencastFrame(ScreencastFrameParams::Create() 549 .Build();
616 ->set_data(data) 550 frontend_->ScreencastFrame(data, std::move(param_metadata), session_id_);
617 ->set_metadata(param_metadata)
618 ->set_session_id(session_id_));
619 } 551 }
620 552
621 void PageHandler::ScreenshotCaptured(DevToolsCommandId command_id, 553 void PageHandler::ScreenshotCaptured(
622 const unsigned char* png_data, 554 std::unique_ptr<CaptureScreenshotCallback> callback,
623 size_t png_size) { 555 const unsigned char* png_data,
556 size_t png_size) {
624 if (!png_data || !png_size) { 557 if (!png_data || !png_size) {
625 client_->SendError(command_id, 558 callback->sendFailure(Response::Error("Unable to capture screenshot"));
626 Response::InternalError("Unable to capture screenshot"));
627 return; 559 return;
628 } 560 }
629 561
630 std::string base_64_data; 562 std::string base_64_data;
631 base::Base64Encode( 563 base::Base64Encode(
632 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size), 564 base::StringPiece(reinterpret_cast<const char*>(png_data), png_size),
633 &base_64_data); 565 &base_64_data);
634 566 callback->sendSuccess(base_64_data);
635 client_->SendCaptureScreenshotResponse(command_id,
636 CaptureScreenshotResponse::Create()->set_data(base_64_data));
637 } 567 }
638 568
639 void PageHandler::OnColorPicked(int r, int g, int b, int a) { 569 void PageHandler::OnColorPicked(int r, int g, int b, int a) {
640 scoped_refptr<dom::RGBA> color = 570 frontend_->ColorPicked(
641 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); 571 DOM::RGBA::Create().SetR(r).SetG(g).SetB(b).SetA(a).Build());
642 client_->ColorPicked(ColorPickedParams::Create()->set_color(color));
643 } 572 }
644 573
645 Response PageHandler::StopLoading() { 574 Response PageHandler::StopLoading() {
646 WebContentsImpl* web_contents = GetWebContents(); 575 WebContentsImpl* web_contents = GetWebContents();
647 if (!web_contents) 576 if (!web_contents)
648 return Response::InternalError("Could not connect to view"); 577 return Response::InternalError();
649 web_contents->Stop(); 578 web_contents->Stop();
650 return Response::OK(); 579 return Response::OK();
651 } 580 }
652 581
653 } // namespace page 582 } // namespace protocol
654 } // namespace devtools
655 } // namespace content 583 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | content/browser/devtools/protocol/schema_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698