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

Unified Diff: content/browser/devtools/protocol/page_handler.cc

Issue 2132673002: Adding Navigation Throttles to DevTools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing files Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/page_handler.cc
diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc
index d5a9244dc95b4123fe0e2ad4e5d1248ac2ba873a..40117ef5aad9720c76ecc5977f4327079e245616 100644
--- a/content/browser/devtools/protocol/page_handler.cc
+++ b/content/browser/devtools/protocol/page_handler.cc
@@ -14,6 +14,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
+#include "content/browser/devtools/page_navigation_throttle.h"
#include "content/browser/devtools/protocol/color_picker.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_base.h"
@@ -23,6 +24,7 @@
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/storage_partition.h"
@@ -102,11 +104,12 @@ PageHandler::PageHandler()
session_id_(0),
frame_counter_(0),
frames_in_flight_(0),
- color_picker_(new ColorPicker(base::Bind(
- &PageHandler::OnColorPicked, base::Unretained(this)))),
+ color_picker_(new ColorPicker(
+ base::Bind(&PageHandler::OnColorPicked, base::Unretained(this)))),
+ 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.
+ next_navigation_id_(0),
host_(nullptr),
- weak_factory_(this) {
-}
+ weak_factory_(this) {}
PageHandler::~PageHandler() {
}
@@ -373,6 +376,71 @@ Response PageHandler::RequestAppBanner() {
return Response::OK();
}
+Response PageHandler::SetNavigationThrottleEnabled(bool enabled) {
+ 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.
+ return Response::OK();
+}
+
+Response PageHandler::NavigationThrottleResponse(const std::string& response,
+ int navigation_id) {
+ auto it = navigation_throttles_.find(navigation_id);
+ if (it == navigation_throttles_.end())
+ return Response::InternalError("Unknown navigation");
+
+ if (response == kNavigationThrottleResponseProceed) {
+ it->second->navigation_handle()->Resume();
+ return Response::OK();
+ } else if (response == kNavigationThrottleResponseCancel) {
+ it->second->navigation_handle()->CancelDeferredNavigation(
+ content::NavigationThrottle::CANCEL);
+ return Response::OK();
+ } else if (response == kNavigationThrottleResponseCancelAndIgnore) {
+ it->second->navigation_handle()->CancelDeferredNavigation(
+ content::NavigationThrottle::CANCEL_AND_IGNORE);
+ return Response::OK();
+ }
+
+ return Response::InternalError("Unrecognized response");
+}
+
+std::unique_ptr<PageNavigationThrottle> PageHandler::GetThrottleForNavigation(
+ NavigationHandle* navigation_handle) {
+ if (!navigation_throttle_enabled_)
+ return nullptr;
+
+ std::unique_ptr<PageNavigationThrottle> throttle(new PageNavigationThrottle(
+ weak_factory_.GetWeakPtr(), next_navigation_id_, navigation_handle));
+ navigation_throttles_[next_navigation_id_++] = throttle.get();
+ return throttle;
+}
+
+void PageHandler::OnPageNavigationThrottleDisposed(int navigation_id) {
+ DCHECK(navigation_throttles_.find(navigation_id) !=
+ navigation_throttles_.end());
+ navigation_throttles_.erase(navigation_id);
+}
+
+void PageHandler::ShouldAllowNavigation(
+ const PageNavigationThrottle* throttle) {
+ NavigationHandle* navigation_handle = throttle->navigation_handle();
+ client_->ShouldAllowNavigation(
+ ShouldAllowNavigationParams::Create()
+ ->set_frame_id(throttle->GetFrameId())
+ ->set_navigation_id(throttle->navigation_id())
+ ->set_url(navigation_handle->GetURL().spec())
+ ->set_renderer_initiated(navigation_handle->IsRendererInitiated()));
+}
+
+void PageHandler::ShouldAllowRedirect(const PageNavigationThrottle* throttle) {
+ NavigationHandle* navigation_handle = throttle->navigation_handle();
+ client_->ShouldAllowRedirect(
+ ShouldAllowRedirectParams::Create()
+ ->set_frame_id(throttle->GetFrameId())
+ ->set_navigation_id(throttle->navigation_id())
+ ->set_url(navigation_handle->GetURL().spec())
+ ->set_renderer_initiated(navigation_handle->IsRendererInitiated()));
+}
+
WebContentsImpl* PageHandler::GetWebContents() {
return host_ ?
static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) :

Powered by Google App Engine
This is Rietveld 408576698