OLD | NEW |
---|---|
(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 response_pending_(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 response_pending_ = 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 response_pending_ = true; | |
44 page_handler_->RedirectRequested(this); | |
45 return ThrottleCheckResult::DEFER; | |
46 } | |
47 | |
48 NavigationThrottle::ThrottleCheckResult | |
49 PageNavigationThrottle::WillProcessResponse() { | |
50 return ThrottleCheckResult::PROCEED; | |
51 } | |
52 | |
53 std::string PageNavigationThrottle::GetFrameId() const { | |
54 WebContents* web_contents = navigation_handle()->GetWebContents(); | |
55 // NOTE keep in sync with BlinkPlatformImpl::getUniqueIdForProcess. | |
56 return base::StringPrintf( | |
57 "%d.%d", | |
58 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
| |
59 navigation_handle()->GetFrameTreeNodeId()); | |
60 } | |
61 | |
62 void PageNavigationThrottle::AlwaysProceed() { | |
63 // Makes WillStartRequest and WillRedirectRequest always return | |
64 // ThrottleCheckResult::PROCEED. | |
65 page_handler_.reset(); | |
66 | |
67 if (response_pending_) | |
68 Resume(); | |
69 } | |
70 | |
71 void PageNavigationThrottle::Resume() { | |
72 if (!response_pending_) | |
73 return; | |
74 navigation_handle()->Resume(); | |
75 response_pending_ = false; | |
76 } | |
77 | |
78 void PageNavigationThrottle::CancelDeferredNavigation( | |
79 NavigationThrottle::ThrottleCheckResult result) { | |
80 if (!response_pending_) | |
81 return; | |
82 navigation_handle()->CancelDeferredNavigation(result); | |
83 response_pending_ = false; | |
84 } | |
85 | |
86 } // namespace devtools | |
87 } // namespace content | |
OLD | NEW |