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), | |
| 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; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 197 } |
| 195 | 198 |
| 196 Response PageHandler::Enable() { | 199 Response PageHandler::Enable() { |
| 197 enabled_ = true; | 200 enabled_ = true; |
| 198 return Response::FallThrough(); | 201 return Response::FallThrough(); |
| 199 } | 202 } |
| 200 | 203 |
| 201 Response PageHandler::Disable() { | 204 Response PageHandler::Disable() { |
| 202 enabled_ = false; | 205 enabled_ = false; |
| 203 screencast_enabled_ = false; | 206 screencast_enabled_ = false; |
| 207 SetNavigationThrottleEnabled(false); | |
| 204 color_picker_->SetEnabled(false); | 208 color_picker_->SetEnabled(false); |
| 205 return Response::FallThrough(); | 209 return Response::FallThrough(); |
| 206 } | 210 } |
| 207 | 211 |
| 208 Response PageHandler::Reload(const bool* bypassCache, | 212 Response PageHandler::Reload(const bool* bypassCache, |
| 209 const std::string* script_to_evaluate_on_load, | 213 const std::string* script_to_evaluate_on_load, |
| 210 const std::string* script_preprocessor) { | 214 const std::string* script_preprocessor) { |
| 211 WebContentsImpl* web_contents = GetWebContents(); | 215 WebContentsImpl* web_contents = GetWebContents(); |
| 212 if (!web_contents) | 216 if (!web_contents) |
| 213 return Response::InternalError("Could not connect to view"); | 217 return Response::InternalError("Could not connect to view"); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } | 370 } |
| 367 | 371 |
| 368 Response PageHandler::RequestAppBanner() { | 372 Response PageHandler::RequestAppBanner() { |
| 369 WebContentsImpl* web_contents = GetWebContents(); | 373 WebContentsImpl* web_contents = GetWebContents(); |
| 370 if (!web_contents) | 374 if (!web_contents) |
| 371 return Response::InternalError("Could not connect to view"); | 375 return Response::InternalError("Could not connect to view"); |
| 372 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); | 376 web_contents->GetDelegate()->RequestAppBannerFromDevTools(web_contents); |
| 373 return Response::OK(); | 377 return Response::OK(); |
| 374 } | 378 } |
| 375 | 379 |
| 380 Response PageHandler::SetNavigationThrottleEnabled(bool enabled) { | |
| 381 navigation_throttle_enabled_ = enabled; | |
| 382 // We don't own the page PageNavigationThrottles so we can't delete them, but | |
| 383 // we can turn them into NOPs. | |
| 384 for (auto& pair : navigation_throttles_) { | |
|
dgozman
2016/07/08 19:19:59
Clear navigation_throttles_ after this.
alex clarke (OOO till 29th)
2016/07/08 20:55:37
Done.
| |
| 385 pair.second->AlwaysProceed(); | |
| 386 } | |
| 387 return Response::OK(); | |
| 388 } | |
| 389 | |
| 390 Response PageHandler::ProcessNavigation(const std::string& response, | |
| 391 int navigation_id) { | |
| 392 auto it = navigation_throttles_.find(navigation_id); | |
| 393 if (it == navigation_throttles_.end()) | |
| 394 return Response::InternalError("Unknown navigation"); | |
|
dgozman
2016/07/08 19:20:00
Response::InvalidParams("Unknown navigation id")
alex clarke (OOO till 29th)
2016/07/08 20:55:37
Done.
| |
| 395 | |
| 396 if (response == kNavigationThrottleResponseProceed) { | |
| 397 it->second->Resume(); | |
| 398 return Response::OK(); | |
| 399 } else if (response == kNavigationThrottleResponseCancel) { | |
| 400 it->second->CancelDeferredNavigation(content::NavigationThrottle::CANCEL); | |
| 401 return Response::OK(); | |
| 402 } else if (response == kNavigationThrottleResponseCancelAndIgnore) { | |
| 403 it->second->CancelDeferredNavigation( | |
| 404 content::NavigationThrottle::CANCEL_AND_IGNORE); | |
| 405 return Response::OK(); | |
| 406 } | |
| 407 | |
| 408 return Response::InternalError("Unrecognized response"); | |
|
dgozman
2016/07/08 19:19:59
Response::InvalidParams("Unrecognized response")
alex clarke (OOO till 29th)
2016/07/08 20:55:37
Done.
| |
| 409 } | |
| 410 | |
| 411 std::unique_ptr<PageNavigationThrottle> PageHandler::GetThrottleForNavigation( | |
| 412 NavigationHandle* navigation_handle) { | |
| 413 if (!navigation_throttle_enabled_) | |
| 414 return nullptr; | |
| 415 | |
| 416 std::unique_ptr<PageNavigationThrottle> throttle(new PageNavigationThrottle( | |
| 417 weak_factory_.GetWeakPtr(), next_navigation_id_, navigation_handle)); | |
| 418 navigation_throttles_[next_navigation_id_++] = throttle.get(); | |
| 419 return throttle; | |
| 420 } | |
| 421 | |
| 422 void PageHandler::OnPageNavigationThrottleDisposed(int navigation_id) { | |
| 423 DCHECK(navigation_throttles_.find(navigation_id) != | |
| 424 navigation_throttles_.end()); | |
| 425 navigation_throttles_.erase(navigation_id); | |
| 426 } | |
| 427 | |
| 428 void PageHandler::NavigationRequested(const PageNavigationThrottle* throttle) { | |
| 429 NavigationHandle* navigation_handle = throttle->navigation_handle(); | |
| 430 client_->NavigationRequested( | |
| 431 NavigationRequestedParams::Create() | |
| 432 ->set_is_in_main_frame(navigation_handle->IsInMainFrame()) | |
| 433 ->set_is_parent_main_frame(navigation_handle->IsParentMainFrame()) | |
| 434 ->set_navigation_id(throttle->navigation_id()) | |
| 435 ->set_url(navigation_handle->GetURL().spec()) | |
| 436 ->set_renderer_initiated(navigation_handle->IsRendererInitiated())); | |
| 437 } | |
| 438 | |
| 439 void PageHandler::RedirectRequested(const PageNavigationThrottle* throttle) { | |
| 440 NavigationHandle* navigation_handle = throttle->navigation_handle(); | |
| 441 client_->RedirectRequested( | |
| 442 RedirectRequestedParams::Create() | |
| 443 ->set_is_in_main_frame(navigation_handle->IsInMainFrame()) | |
| 444 ->set_is_parent_main_frame(navigation_handle->IsParentMainFrame()) | |
| 445 ->set_navigation_id(throttle->navigation_id()) | |
| 446 ->set_url(navigation_handle->GetURL().spec()) | |
| 447 ->set_renderer_initiated(navigation_handle->IsRendererInitiated())); | |
| 448 } | |
| 449 | |
| 376 WebContentsImpl* PageHandler::GetWebContents() { | 450 WebContentsImpl* PageHandler::GetWebContents() { |
| 377 return host_ ? | 451 return host_ ? |
| 378 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : | 452 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) : |
| 379 nullptr; | 453 nullptr; |
| 380 } | 454 } |
| 381 | 455 |
| 382 void PageHandler::NotifyScreencastVisibility(bool visible) { | 456 void PageHandler::NotifyScreencastVisibility(bool visible) { |
| 383 if (visible) | 457 if (visible) |
| 384 capture_retry_count_ = kCaptureRetryLimit; | 458 capture_retry_count_ = kCaptureRetryLimit; |
| 385 client_->ScreencastVisibilityChanged( | 459 client_->ScreencastVisibilityChanged( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 | 590 |
| 517 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 591 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
| 518 scoped_refptr<dom::RGBA> color = | 592 scoped_refptr<dom::RGBA> color = |
| 519 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 593 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
| 520 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 594 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
| 521 } | 595 } |
| 522 | 596 |
| 523 } // namespace page | 597 } // namespace page |
| 524 } // namespace devtools | 598 } // namespace devtools |
| 525 } // namespace content | 599 } // namespace content |
| OLD | NEW |