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

Side by Side Diff: content/browser/devtools/page_navigation_throttle.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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/devtools/page_navigation_throttle.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "content/browser/devtools/protocol/page_handler.h"
9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "content/public/browser/web_contents.h"
12
13 namespace content {
14 namespace devtools {
15
16 PageNavigationThrottle::PageNavigationThrottle(
17 base::WeakPtr<page::PageHandler> page_handler,
18 int navigation_id,
19 content::NavigationHandle* navigation_handle)
20 : content::NavigationThrottle(navigation_handle),
21 navigation_id_(navigation_id),
22 page_handler_(page_handler),
23 navigation_deferred_(false) {}
24
25 PageNavigationThrottle::~PageNavigationThrottle() {
26 if (page_handler_)
27 page_handler_->OnPageNavigationThrottleDisposed(navigation_id_);
28 }
29
30 NavigationThrottle::ThrottleCheckResult
31 PageNavigationThrottle::WillStartRequest() {
32 if (!page_handler_)
33 return ThrottleCheckResult::PROCEED;
34 navigation_deferred_ = true;
35 page_handler_->NavigationRequested(this);
36 return ThrottleCheckResult::DEFER;
37 }
38
39 NavigationThrottle::ThrottleCheckResult
40 PageNavigationThrottle::WillRedirectRequest() {
41 if (!page_handler_)
42 return ThrottleCheckResult::PROCEED;
43 navigation_deferred_ = true;
44 page_handler_->NavigationRequested(this);
45 return ThrottleCheckResult::DEFER;
46 }
47
48 void PageNavigationThrottle::AlwaysProceed() {
49 // Makes WillStartRequest and WillRedirectRequest always return
50 // ThrottleCheckResult::PROCEED.
51 page_handler_.reset();
52
53 if (navigation_deferred_)
54 Resume();
55 }
56
57 void PageNavigationThrottle::Resume() {
58 if (!navigation_deferred_)
59 return;
60 navigation_handle()->Resume();
61 navigation_deferred_ = false;
62 }
63
64 void PageNavigationThrottle::CancelDeferredNavigation(
65 NavigationThrottle::ThrottleCheckResult result) {
66 if (!navigation_deferred_)
67 return;
68 navigation_handle()->CancelDeferredNavigation(result);
69 navigation_deferred_ = false;
70 }
71
72 } // namespace devtools
73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698