Chromium Code Reviews| Index: content/browser/devtools/page_navigation_throttle.cc |
| diff --git a/content/browser/devtools/page_navigation_throttle.cc b/content/browser/devtools/page_navigation_throttle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1dabe622f4418d90c95706ebf20cfabb91d61a94 |
| --- /dev/null |
| +++ b/content/browser/devtools/page_navigation_throttle.cc |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/devtools/page_navigation_throttle.h" |
| + |
| +#include "base/strings/stringprintf.h" |
| +#include "content/browser/devtools/protocol/page_handler.h" |
| +#include "content/public/browser/navigation_handle.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace content { |
| +namespace devtools { |
| + |
| +PageNavigationThrottle::PageNavigationThrottle( |
| + base::WeakPtr<page::PageHandler> page_handler, |
| + int navigation_id, |
| + content::NavigationHandle* navigation_handle) |
| + : content::NavigationThrottle(navigation_handle), |
| + navigation_id_(navigation_id), |
| + page_handler_(page_handler), |
| + response_pending_(false) {} |
| + |
| +PageNavigationThrottle::~PageNavigationThrottle() { |
| + if (page_handler_) |
| + page_handler_->OnPageNavigationThrottleDisposed(navigation_id_); |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +PageNavigationThrottle::WillStartRequest() { |
| + if (!page_handler_) |
| + return ThrottleCheckResult::PROCEED; |
| + response_pending_ = true; |
| + page_handler_->NavigationRequested(this); |
| + return ThrottleCheckResult::DEFER; |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +PageNavigationThrottle::WillRedirectRequest() { |
| + if (!page_handler_) |
| + return ThrottleCheckResult::PROCEED; |
| + response_pending_ = true; |
| + page_handler_->RedirectRequested(this); |
| + return ThrottleCheckResult::DEFER; |
| +} |
| + |
| +NavigationThrottle::ThrottleCheckResult |
| +PageNavigationThrottle::WillProcessResponse() { |
| + return ThrottleCheckResult::PROCEED; |
| +} |
| + |
| +std::string PageNavigationThrottle::GetFrameId() const { |
| + WebContents* web_contents = navigation_handle()->GetWebContents(); |
| + // NOTE keep in sync with BlinkPlatformImpl::getUniqueIdForProcess. |
| + return base::StringPrintf( |
| + "%d.%d", |
| + base::GetProcId(web_contents->GetRenderProcessHost()->GetHandle()), |
|
clamy
2016/07/08 15:47:33
Does it work for cross-process navigations?
alex clarke (OOO till 29th)
2016/07/08 17:15:40
It appeared to, although I didn't test it thorough
|
| + navigation_handle()->GetFrameTreeNodeId()); |
| +} |
| + |
| +void PageNavigationThrottle::AlwaysProceed() { |
| + // Makes WillStartRequest and WillRedirectRequest always return |
| + // ThrottleCheckResult::PROCEED. |
| + page_handler_.reset(); |
| + |
| + if (response_pending_) |
| + Resume(); |
| +} |
| + |
| +void PageNavigationThrottle::Resume() { |
| + if (!response_pending_) |
| + return; |
| + navigation_handle()->Resume(); |
| + response_pending_ = false; |
| +} |
| + |
| +void PageNavigationThrottle::CancelDeferredNavigation( |
| + NavigationThrottle::ThrottleCheckResult result) { |
| + if (!response_pending_) |
| + return; |
| + navigation_handle()->CancelDeferredNavigation(result); |
| + response_pending_ = false; |
| +} |
| + |
| +} // namespace devtools |
| +} // namespace content |