1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// Copyright 2015 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.
#ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_
#define CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_
#include "content/common/content_export.h"
namespace content {
class NavigationHandle;
// A NavigationThrottle tracks and allows interaction with a navigation on the
// UI thread.
class CONTENT_EXPORT NavigationThrottle {
public:
// This is returned to the NavigationHandle to allow the navigation to
// proceed, or to cancel it.
enum ThrottleCheckResult {
// The navigation proceeds uninterrupted.
PROCEED,
// Defers the navigation until the NavigationThrottle calls
// NavigationHandle::Resume or NavigationHandle::CancelDeferredRequest.
// If the NavigationHandle is destroyed while the navigation is deferred,
// the navigation will be canceled in the network stack.
DEFER,
// Cancels the navigation.
CANCEL,
// Cancels the navigation and makes the requester of the navigation acts
// like the request was never made.
CANCEL_AND_IGNORE,
// Blocks a navigation due to rules asserted before the request is made.
// This can only be returned from WillStartRequest and also from
// WillRedirectRequest when PlzNavigate is enabled. This will result in an
// error page for net::ERR_BLOCKED_BY_CLIENT being loaded in the frame that
// is navigated.
BLOCK_REQUEST,
// Blocks a navigation taking place in a subframe, and collapses the frame
// owner element in the parent document (i.e. removes it from the layout).
// This can only be returned from WillStartRequest, and also from
// WillRedirectRequest when PlzNavigate is enabled.
BLOCK_REQUEST_AND_COLLAPSE,
// Blocks a navigation due to rules asserted by a response (for instance,
// embedding restrictions like 'X-Frame-Options'). This result will only
// be returned from WillProcessResponse.
BLOCK_RESPONSE,
};
NavigationThrottle(NavigationHandle* navigation_handle);
virtual ~NavigationThrottle();
// Called when a network request is about to be made for this navigation.
//
// The implementer is responsible for ensuring that the WebContents this
// throttle is associated with remain alive during the duration of this
// method. Failing to do so will result in use-after-free bugs. Should the
// implementer need to destroy the WebContents, it should return CANCEL,
// CANCEL_AND_IGNORE or DEFER and perform the destruction asynchronously.
virtual ThrottleCheckResult WillStartRequest();
// Called when a server redirect is received by the navigation.
//
// The implementer is responsible for ensuring that the WebContents this
// throttle is associated with remain alive during the duration of this
// method. Failing to do so will result in use-after-free bugs. Should the
// implementer need to destroy the WebContents, it should return CANCEL,
// CANCEL_AND_IGNORE or DEFER and perform the destruction asynchronously.
virtual ThrottleCheckResult WillRedirectRequest();
// Called when a response's headers and metadata are available.
//
// The implementer is responsible for ensuring that the WebContents this
// throttle is associated with remain alive during the duration of this
// method. Failing to do so will result in use-after-free bugs. Should the
// implementer need to destroy the WebContents, it should return CANCEL,
// CANCEL_AND_IGNORE, or BLOCK_RESPONSE and perform the destruction
// asynchronously.
virtual ThrottleCheckResult WillProcessResponse();
// Returns the name of the throttle for logging purposes. It must not return
// nullptr.
virtual const char* GetNameForLogging() = 0;
// The NavigationHandle that is tracking the information related to this
// navigation.
NavigationHandle* navigation_handle() const { return navigation_handle_; }
private:
NavigationHandle* navigation_handle_;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_THROTTLE_H_
|