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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/threading/worker_pool.h" | 16 #include "base/threading/worker_pool.h" |
| 17 #include "content/browser/devtools/page_navigation_throttle.h" | |
| 17 #include "content/browser/devtools/protocol/color_picker.h" | 18 #include "content/browser/devtools/protocol/color_picker.h" |
| 18 #include "content/browser/renderer_host/render_widget_host_impl.h" | 19 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/javascript_dialog_manager.h" | 24 #include "content/public/browser/javascript_dialog_manager.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/navigation_handle.h" | |
| 26 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 29 #include "content/public/browser/web_contents_delegate.h" | 31 #include "content/public/browser/web_contents_delegate.h" |
| 30 #include "content/public/common/referrer.h" | 32 #include "content/public/common/referrer.h" |
| 31 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 33 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 32 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 33 #include "ui/base/page_transition_types.h" | 35 #include "ui/base/page_transition_types.h" |
| 34 #include "ui/gfx/codec/jpeg_codec.h" | 36 #include "ui/gfx/codec/jpeg_codec.h" |
| 35 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 screencast_enabled_(false), | 97 screencast_enabled_(false), |
| 96 screencast_quality_(kDefaultScreenshotQuality), | 98 screencast_quality_(kDefaultScreenshotQuality), |
| 97 screencast_max_width_(-1), | 99 screencast_max_width_(-1), |
| 98 screencast_max_height_(-1), | 100 screencast_max_height_(-1), |
| 99 capture_every_nth_frame_(1), | 101 capture_every_nth_frame_(1), |
| 100 capture_retry_count_(0), | 102 capture_retry_count_(0), |
| 101 has_compositor_frame_metadata_(false), | 103 has_compositor_frame_metadata_(false), |
| 102 session_id_(0), | 104 session_id_(0), |
| 103 frame_counter_(0), | 105 frame_counter_(0), |
| 104 frames_in_flight_(0), | 106 frames_in_flight_(0), |
| 105 color_picker_(new ColorPicker(base::Bind( | 107 color_picker_(new ColorPicker( |
| 106 &PageHandler::OnColorPicked, base::Unretained(this)))), | 108 base::Bind(&PageHandler::OnColorPicked, base::Unretained(this)))), |
| 109 navigation_throttle_enabled_(false), | |
|
dgozman
2016/07/07 19:25:58
We should resume and remove any throttles we curre
alex clarke (OOO till 29th)
2016/07/08 10:37:57
Good point! Done.
| |
| 110 next_navigation_id_(0), | |
| 107 host_(nullptr), | 111 host_(nullptr), |
| 108 weak_factory_(this) { | 112 weak_factory_(this) {} |
| 109 } | |
| 110 | 113 |
| 111 PageHandler::~PageHandler() { | 114 PageHandler::~PageHandler() { |
| 112 } | 115 } |
| 113 | 116 |
| 114 void PageHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { | 117 void PageHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { |
| 115 if (host_ == host) | 118 if (host_ == host) |
| 116 return; | 119 return; |
| 117 | 120 |
| 118 RenderWidgetHostImpl* widget_host = | 121 RenderWidgetHostImpl* widget_host = |
| 119 host_ ? host_->GetRenderWidgetHost() : nullptr; | 122 host_ ? host_->GetRenderWidgetHost() : nullptr; |
| 120 if (widget_host) { | 123 if (widget_host) { |
| 121 registrar_.Remove( | 124 registrar_.Remove( |
| 122 this, | 125 this, |
| 123 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 126 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 124 content::Source<RenderWidgetHost>(widget_host)); | 127 content::Source<RenderWidgetHost>(widget_host)); |
| 125 } | 128 } |
| 126 | 129 |
| 127 host_ = host; | 130 host_ = host; |
|
dgozman
2016/07/07 19:25:58
I was about to say that we should clean up everyth
alex clarke (OOO till 29th)
2016/07/08 10:37:57
Acknowledged. I'll have to think about that.
| |
| 128 widget_host = host_ ? host_->GetRenderWidgetHost() : nullptr; | 131 widget_host = host_ ? host_->GetRenderWidgetHost() : nullptr; |
| 129 color_picker_->SetRenderWidgetHost(widget_host); | 132 color_picker_->SetRenderWidgetHost(widget_host); |
| 130 | 133 |
| 131 if (widget_host) { | 134 if (widget_host) { |
| 132 registrar_.Add( | 135 registrar_.Add( |
| 133 this, | 136 this, |
| 134 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 137 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 135 content::Source<RenderWidgetHost>(widget_host)); | 138 content::Source<RenderWidgetHost>(widget_host)); |
| 136 } | 139 } |
| 137 } | 140 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } | 369 } |
| 367 | 370 |
| 368 Response PageHandler::RequestAppBanner() { | 371 Response PageHandler::RequestAppBanner() { |
| 369 WebContentsImpl* web_contents = GetWebContents(); | 372 WebContentsImpl* web_contents = GetWebContents(); |
| 370 if (!web_contents) | 373 if (!web_contents) |
| 371 return Response::InternalError("Could not connect to view"); | 374 return Response::InternalError("Could not connect to view"); |
| 372 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); | 375 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); |
| 373 return Response::OK(); | 376 return Response::OK(); |
| 374 } | 377 } |
| 375 | 378 |
| 379 Response PageHandler::SetNavigationThrottleEnabled(bool enabled) { | |
| 380 navigation_throttle_enabled_ = enabled; | |
|
dgozman
2016/07/07 19:25:58
Even better, clean up existing throttles here and
alex clarke (OOO till 29th)
2016/07/08 10:37:57
Done.
| |
| 381 return Response::OK(); | |
| 382 } | |
| 383 | |
| 384 Response PageHandler::NavigationThrottleResponse(const std::string& response, | |
| 385 int navigation_id) { | |
| 386 auto it = navigation_throttles_.find(navigation_id); | |
| 387 if (it == navigation_throttles_.end()) | |
| 388 return Response::InternalError("Unknown navigation"); | |
| 389 | |
| 390 if (response == kNavigationThrottleResponseProceed) { | |
| 391 it->second->navigation_handle()->Resume(); | |
| 392 return Response::OK(); | |
| 393 } else if (response == kNavigationThrottleResponseCancel) { | |
| 394 it->second->navigation_handle()->CancelDeferredNavigation( | |
| 395 content::NavigationThrottle::CANCEL); | |
| 396 return Response::OK(); | |
| 397 } else if (response == kNavigationThrottleResponseCancelAndIgnore) { | |
| 398 it->second->navigation_handle()->CancelDeferredNavigation( | |
| 399 content::NavigationThrottle::CANCEL_AND_IGNORE); | |
| 400 return Response::OK(); | |
| 401 } | |
| 402 | |
| 403 return Response::InternalError("Unrecognized response"); | |
| 404 } | |
| 405 | |
| 406 std::unique_ptr<PageNavigationThrottle> PageHandler::GetThrottleForNavigation( | |
| 407 NavigationHandle* navigation_handle) { | |
| 408 if (!navigation_throttle_enabled_) | |
| 409 return nullptr; | |
| 410 | |
| 411 std::unique_ptr<PageNavigationThrottle> throttle(new PageNavigationThrottle( | |
| 412 weak_factory_.GetWeakPtr(), next_navigation_id_, navigation_handle)); | |
| 413 navigation_throttles_[next_navigation_id_++] = throttle.get(); | |
| 414 return throttle; | |
| 415 } | |
| 416 | |
| 417 void PageHandler::OnPageNavigationThrottleDisposed(int navigation_id) { | |
| 418 DCHECK(navigation_throttles_.find(navigation_id) != | |
| 419 navigation_throttles_.end()); | |
| 420 navigation_throttles_.erase(navigation_id); | |
| 421 } | |
| 422 | |
| 423 void PageHandler::ShouldAllowNavigation( | |
| 424 const PageNavigationThrottle* throttle) { | |
| 425 NavigationHandle* navigation_handle = throttle->navigation_handle(); | |
| 426 client_->ShouldAllowNavigation( | |
| 427 ShouldAllowNavigationParams::Create() | |
| 428 ->set_frame_id(throttle->GetFrameId()) | |
| 429 ->set_navigation_id(throttle->navigation_id()) | |
| 430 ->set_url(navigation_handle->GetURL().spec()) | |
| 431 ->set_renderer_initiated(navigation_handle->IsRendererInitiated())); | |
| 432 } | |
| 433 | |
| 434 void PageHandler::ShouldAllowRedirect(const PageNavigationThrottle* throttle) { | |
| 435 NavigationHandle* navigation_handle = throttle->navigation_handle(); | |
| 436 client_->ShouldAllowRedirect( | |
| 437 ShouldAllowRedirectParams::Create() | |
| 438 ->set_frame_id(throttle->GetFrameId()) | |
| 439 ->set_navigation_id(throttle->navigation_id()) | |
| 440 ->set_url(navigation_handle->GetURL().spec()) | |
| 441 ->set_renderer_initiated(navigation_handle->IsRendererInitiated())); | |
| 442 } | |
| 443 | |
| 376 WebContentsImpl* PageHandler::GetWebContents() { | 444 WebContentsImpl* PageHandler::GetWebContents() { |
| 377 return host_ ? | 445 return host_ ? |
| 378 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : | 446 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : |
| 379 nullptr; | 447 nullptr; |
| 380 } | 448 } |
| 381 | 449 |
| 382 void PageHandler::NotifyScreencastVisibility(bool visible) { | 450 void PageHandler::NotifyScreencastVisibility(bool visible) { |
| 383 if (visible) | 451 if (visible) |
| 384 capture_retry_count_ = kCaptureRetryLimit; | 452 capture_retry_count_ = kCaptureRetryLimit; |
| 385 client_->ScreencastVisibilityChanged( | 453 client_->ScreencastVisibilityChanged( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 | 584 |
| 517 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 585 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
| 518 scoped_refptr<dom::RGBA> color = | 586 scoped_refptr<dom::RGBA> color = |
| 519 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 587 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
| 520 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 588 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
| 521 } | 589 } |
| 522 | 590 |
| 523 } // namespace page | 591 } // namespace page |
| 524 } // namespace devtools | 592 } // namespace devtools |
| 525 } // namespace content | 593 } // namespace content |
| OLD | NEW |