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

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: Removed frameID 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..8b0231c475ad297feff2b7b1363c2ac4c541c751 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),
+ next_navigation_id_(0),
host_(nullptr),
- weak_factory_(this) {
-}
+ weak_factory_(this) {}
PageHandler::~PageHandler() {
}
@@ -201,6 +204,7 @@ Response PageHandler::Enable() {
Response PageHandler::Disable() {
enabled_ = false;
screencast_enabled_ = false;
+ SetNavigationThrottleEnabled(false);
color_picker_->SetEnabled(false);
return Response::FallThrough();
}
@@ -373,6 +377,76 @@ Response PageHandler::RequestAppBanner() {
return Response::OK();
}
+Response PageHandler::SetNavigationThrottleEnabled(bool enabled) {
+ navigation_throttle_enabled_ = enabled;
+ // We don't own the page PageNavigationThrottles so we can't delete them, but
+ // we can turn them into NOPs.
+ 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.
+ pair.second->AlwaysProceed();
+ }
+ return Response::OK();
+}
+
+Response PageHandler::ProcessNavigation(const std::string& response,
+ int navigation_id) {
+ auto it = navigation_throttles_.find(navigation_id);
+ if (it == navigation_throttles_.end())
+ 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.
+
+ if (response == kNavigationThrottleResponseProceed) {
+ it->second->Resume();
+ return Response::OK();
+ } else if (response == kNavigationThrottleResponseCancel) {
+ it->second->CancelDeferredNavigation(content::NavigationThrottle::CANCEL);
+ return Response::OK();
+ } else if (response == kNavigationThrottleResponseCancelAndIgnore) {
+ it->second->CancelDeferredNavigation(
+ content::NavigationThrottle::CANCEL_AND_IGNORE);
+ return Response::OK();
+ }
+
+ 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.
+}
+
+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::NavigationRequested(const PageNavigationThrottle* throttle) {
+ NavigationHandle* navigation_handle = throttle->navigation_handle();
+ client_->NavigationRequested(
+ NavigationRequestedParams::Create()
+ ->set_is_in_main_frame(navigation_handle->IsInMainFrame())
+ ->set_is_parent_main_frame(navigation_handle->IsParentMainFrame())
+ ->set_navigation_id(throttle->navigation_id())
+ ->set_url(navigation_handle->GetURL().spec())
+ ->set_renderer_initiated(navigation_handle->IsRendererInitiated()));
+}
+
+void PageHandler::RedirectRequested(const PageNavigationThrottle* throttle) {
+ NavigationHandle* navigation_handle = throttle->navigation_handle();
+ client_->RedirectRequested(
+ RedirectRequestedParams::Create()
+ ->set_is_in_main_frame(navigation_handle->IsInMainFrame())
+ ->set_is_parent_main_frame(navigation_handle->IsParentMainFrame())
+ ->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