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

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: Remove print 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..0e8d29b29b151d82ad24d0cc680fddd03b4c485e 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;
+ SetControlNavigations(false);
color_picker_->SetEnabled(false);
return Response::FallThrough();
}
@@ -373,6 +377,65 @@ Response PageHandler::RequestAppBanner() {
return Response::OK();
}
+Response PageHandler::SetControlNavigations(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_) {
+ pair.second->AlwaysProceed();
+ }
+ navigation_throttles_.clear();
+ 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::InvalidParams("Unknown navigation id");
+
+ if (response == kNavigationResponseProceed) {
+ it->second->Resume();
+ return Response::OK();
+ } else if (response == kNavigationResponseCancel) {
+ it->second->CancelDeferredNavigation(content::NavigationThrottle::CANCEL);
+ return Response::OK();
+ } else if (response == kNavigationResponseCancelAndIgnore) {
+ it->second->CancelDeferredNavigation(
+ content::NavigationThrottle::CANCEL_AND_IGNORE);
+ return Response::OK();
+ }
+
+ return Response::InvalidParams("Unrecognized response");
+}
+
+std::unique_ptr<PageNavigationThrottle>
+PageHandler::CreateThrottleForNavigation(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_redirect(navigation_handle->WasServerRedirect())
+ ->set_navigation_id(throttle->navigation_id())
+ ->set_url(navigation_handle->GetURL().spec()));
+}
+
WebContentsImpl* PageHandler::GetWebContents() {
return host_ ?
static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(host_)) :
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | content/browser/devtools/render_frame_devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698