OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ |
6 #define CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ |
7 | 7 |
8 #include "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 class NavigationHandle; | 11 class NavigationHandle; |
12 | 12 |
13 // A NavigationThrottle tracks and allows interaction with a navigation on the | 13 // A NavigationThrottle tracks and allows interaction with a navigation on the |
14 // UI thread. | 14 // UI thread. |
15 class CONTENT_EXPORT NavigationThrottle { | 15 class CONTENT_EXPORT NavigationThrottle { |
16 public: | 16 public: |
17 // This is returned to the NavigationHandle to allow the navigation to | 17 // This is returned to the NavigationHandle to allow the navigation to |
18 // proceed, or to cancel it. | 18 // proceed, or to cancel it. |
19 enum ThrottleCheckResult { | 19 enum ThrottleCheckResult { |
| 20 // The navigation proceeds uninterrupted. |
20 PROCEED, | 21 PROCEED, |
| 22 |
| 23 // Defers the navigation until the NavigationThrottle calls |
| 24 // NavigationHandle::Resume or NavigationHandle::CancelDeferredRequest. |
| 25 // If the NavigationHandle is destroyed while the navigation is deferred, |
| 26 // the navigation will be canceled in the network stack. |
21 DEFER, | 27 DEFER, |
| 28 |
| 29 // Cancels the navigation. |
| 30 CANCEL, |
| 31 |
| 32 // Cancels the navigation and makes the requester of the navigation acts |
| 33 // like the request was never made. |
22 CANCEL_AND_IGNORE, | 34 CANCEL_AND_IGNORE, |
23 }; | 35 }; |
24 | 36 |
25 NavigationThrottle(NavigationHandle* navigation_handle); | 37 NavigationThrottle(NavigationHandle* navigation_handle); |
26 virtual ~NavigationThrottle(); | 38 virtual ~NavigationThrottle(); |
27 | 39 |
28 // Called when a network request is about to be made for this navigation. | 40 // Called when a network request is about to be made for this navigation. |
| 41 // |
| 42 // The implementer is responsible for ensuring that the WebContents this |
| 43 // throttle is associated with remain alive during the duration of this |
| 44 // method. Failing to do so will result in use-after-free bugs. Should the |
| 45 // implementer need to destroy the WebContents, it should return CANCEL, |
| 46 // CANCEL_AND_IGNORE or DEFER and perform the destruction asynchronously. |
29 virtual ThrottleCheckResult WillStartRequest(); | 47 virtual ThrottleCheckResult WillStartRequest(); |
30 | 48 |
31 // Called when a server redirect is received by the navigation. | 49 // Called when a server redirect is received by the navigation. |
| 50 // |
| 51 // The implementer is responsible for ensuring that the WebContents this |
| 52 // throttle is associated with remain alive during the duration of this |
| 53 // method. Failing to do so will result in use-after-free bugs. Should the |
| 54 // implementer need to destroy the WebContents, it should return CANCEL, |
| 55 // CANCEL_AND_IGNORE or DEFER and perform the destruction asynchronously. |
32 virtual ThrottleCheckResult WillRedirectRequest(); | 56 virtual ThrottleCheckResult WillRedirectRequest(); |
33 | 57 |
34 // The NavigationHandle that is tracking the information related to this | 58 // The NavigationHandle that is tracking the information related to this |
35 // navigation. | 59 // navigation. |
36 NavigationHandle* navigation_handle() const { return navigation_handle_; } | 60 NavigationHandle* navigation_handle() const { return navigation_handle_; } |
37 | 61 |
38 private: | 62 private: |
39 NavigationHandle* navigation_handle_; | 63 NavigationHandle* navigation_handle_; |
40 }; | 64 }; |
41 | 65 |
42 } // namespace content | 66 } // namespace content |
43 | 67 |
44 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ | 68 #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_ |
OLD | NEW |