[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |||||
[email protected] | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 5 | #ifndef COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ |
6 | #define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ | ||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 7 | |
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 8 | #include <memory> |
9 | |||||
[email protected] | 6a718ab | 2014-04-23 20:01:20 | [diff] [blame] | 10 | #include "base/android/jni_weak_ref.h" |
avi | f57136c1 | 2015-12-25 23:27:45 | [diff] [blame] | 11 | #include "base/macros.h" |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 12 | #include "base/supports_user_data.h" |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 13 | #include "components/navigation_interception/intercept_navigation_throttle.h" |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 14 | |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 15 | namespace content { |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 16 | class NavigationHandle; |
17 | class NavigationThrottle; | ||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 18 | class WebContents; |
19 | } | ||||
20 | |||||
[email protected] | 8812e3d0 | 2013-05-22 12:38:53 | [diff] [blame] | 21 | namespace navigation_interception { |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 22 | |
[email protected] | c0d243a | 2013-01-31 21:20:16 | [diff] [blame] | 23 | class NavigationParams; |
24 | |||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 25 | // Native side of the InterceptNavigationDelegate Java interface. |
26 | // This is used to create a InterceptNavigationResourceThrottle that calls the | ||||
27 | // Java interface method to determine whether a navigation should be ignored or | ||||
28 | // not. | ||||
29 | // To us this class: | ||||
30 | // 1) the Java-side interface implementation must be associated (via the | ||||
31 | // Associate method) with a WebContents for which URLRequests are to be | ||||
32 | // intercepted, | ||||
David Bokan | 2a48f7bb | 2021-07-09 13:21:36 | [diff] [blame] | 33 | // 2) the NavigationThrottle obtained via MaybeCreateThrottleFor must be |
34 | // associated with the NavigationHandle in the ContentBrowserClient | ||||
35 | // implementation. | ||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 36 | class InterceptNavigationDelegate : public base::SupportsUserData::Data { |
37 | public: | ||||
Colin Blundell | 4695e814 | 2020-03-16 11:13:12 | [diff] [blame] | 38 | // Pass true for |escape_external_handler_value| to have |
39 | // net::EscapeExternalHandlerValue() invoked on URLs passed to | ||||
40 | // ShouldIgnoreNavigation() before the navigation is processed. | ||||
41 | InterceptNavigationDelegate(JNIEnv* env, | ||||
42 | jobject jdelegate, | ||||
43 | bool escape_external_handler_value = false); | ||||
dcheng | e27b1ef | 2015-02-04 23:34:11 | [diff] [blame] | 44 | ~InterceptNavigationDelegate() override; |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 45 | |
46 | // Associates the InterceptNavigationDelegate with a WebContents using the | ||||
47 | // SupportsUserData mechanism. | ||||
48 | // As implied by the use of scoped_ptr, the WebContents will assume ownership | ||||
49 | // of |delegate|. | ||||
50 | static void Associate(content::WebContents* web_contents, | ||||
dcheng | 84c358e | 2016-04-26 07:05:53 | [diff] [blame] | 51 | std::unique_ptr<InterceptNavigationDelegate> delegate); |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 52 | // Gets the InterceptNavigationDelegate associated with the WebContents, |
53 | // can be null. | ||||
54 | static InterceptNavigationDelegate* Get(content::WebContents* web_contents); | ||||
55 | |||||
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 56 | // Creates a InterceptNavigationThrottle that will direct all callbacks to |
57 | // the InterceptNavigationDelegate. | ||||
David Bokan | 2a48f7bb | 2021-07-09 13:21:36 | [diff] [blame] | 58 | static std::unique_ptr<content::NavigationThrottle> MaybeCreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 59 | content::NavigationHandle* handle, |
60 | navigation_interception::SynchronyMode mode); | ||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 61 | |
[email protected] | c0d243a | 2013-01-31 21:20:16 | [diff] [blame] | 62 | virtual bool ShouldIgnoreNavigation( |
63 | const NavigationParams& navigation_params); | ||||
jaekyun | 03890319 | 2015-03-31 14:15:59 | [diff] [blame] | 64 | |
65 | // Updates |last_user_gesture_carryover_timestamp_| when user gesture is | ||||
66 | // carried over. | ||||
67 | void UpdateLastUserGestureCarryoverTimestamp(); | ||||
68 | |||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 69 | private: |
70 | JavaObjectWeakGlobalRef weak_jdelegate_; | ||||
jaekyun | 03890319 | 2015-03-31 14:15:59 | [diff] [blame] | 71 | base::TimeTicks last_user_gesture_carryover_timestamp_; |
Colin Blundell | 4695e814 | 2020-03-16 11:13:12 | [diff] [blame] | 72 | bool escape_external_handler_value_ = false; |
jaekyun | 03890319 | 2015-03-31 14:15:59 | [diff] [blame] | 73 | |
74 | DISALLOW_COPY_AND_ASSIGN(InterceptNavigationDelegate); | ||||
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 75 | }; |
76 | |||||
[email protected] | 8812e3d0 | 2013-05-22 12:38:53 | [diff] [blame] | 77 | } // namespace navigation_interception |
[email protected] | b27a584 | 2012-11-09 10:06:13 | [diff] [blame] | 78 | |
[email protected] | 62885ab | 2013-01-23 03:55:16 | [diff] [blame] | 79 | #endif // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ |