blob: accf14ef08057b0601aaeabba6f4f95597abd33d [file] [log] [blame]
[email protected]b27a5842012-11-09 10:06:131// 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]62885ab2013-01-23 03:55:165#ifndef COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
6#define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
[email protected]b27a5842012-11-09 10:06:137
dcheng84c358e2016-04-26 07:05:538#include <memory>
9
[email protected]6a718ab2014-04-23 20:01:2010#include "base/android/jni_weak_ref.h"
avif57136c12015-12-25 23:27:4511#include "base/macros.h"
[email protected]b27a5842012-11-09 10:06:1312#include "base/supports_user_data.h"
Charlie Harrison3286ab72019-02-13 20:13:3013#include "components/navigation_interception/intercept_navigation_throttle.h"
[email protected]b27a5842012-11-09 10:06:1314
[email protected]b27a5842012-11-09 10:06:1315namespace content {
clamy40c9e142015-09-29 11:18:4716class NavigationHandle;
17class NavigationThrottle;
[email protected]b27a5842012-11-09 10:06:1318class WebContents;
19}
20
[email protected]8812e3d02013-05-22 12:38:5321namespace navigation_interception {
[email protected]b27a5842012-11-09 10:06:1322
[email protected]c0d243a2013-01-31 21:20:1623class NavigationParams;
24
[email protected]b27a5842012-11-09 10:06:1325// 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 Bokan2a48f7bb2021-07-09 13:21:3633// 2) the NavigationThrottle obtained via MaybeCreateThrottleFor must be
34// associated with the NavigationHandle in the ContentBrowserClient
35// implementation.
[email protected]b27a5842012-11-09 10:06:1336class InterceptNavigationDelegate : public base::SupportsUserData::Data {
37 public:
Colin Blundell4695e8142020-03-16 11:13:1238 // 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);
dchenge27b1ef2015-02-04 23:34:1144 ~InterceptNavigationDelegate() override;
[email protected]b27a5842012-11-09 10:06:1345
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,
dcheng84c358e2016-04-26 07:05:5351 std::unique_ptr<InterceptNavigationDelegate> delegate);
[email protected]b27a5842012-11-09 10:06:1352 // Gets the InterceptNavigationDelegate associated with the WebContents,
53 // can be null.
54 static InterceptNavigationDelegate* Get(content::WebContents* web_contents);
55
clamy40c9e142015-09-29 11:18:4756 // Creates a InterceptNavigationThrottle that will direct all callbacks to
57 // the InterceptNavigationDelegate.
David Bokan2a48f7bb2021-07-09 13:21:3658 static std::unique_ptr<content::NavigationThrottle> MaybeCreateThrottleFor(
Charlie Harrison3286ab72019-02-13 20:13:3059 content::NavigationHandle* handle,
60 navigation_interception::SynchronyMode mode);
[email protected]b27a5842012-11-09 10:06:1361
[email protected]c0d243a2013-01-31 21:20:1662 virtual bool ShouldIgnoreNavigation(
63 const NavigationParams& navigation_params);
jaekyun038903192015-03-31 14:15:5964
65 // Updates |last_user_gesture_carryover_timestamp_| when user gesture is
66 // carried over.
67 void UpdateLastUserGestureCarryoverTimestamp();
68
[email protected]b27a5842012-11-09 10:06:1369 private:
70 JavaObjectWeakGlobalRef weak_jdelegate_;
jaekyun038903192015-03-31 14:15:5971 base::TimeTicks last_user_gesture_carryover_timestamp_;
Colin Blundell4695e8142020-03-16 11:13:1272 bool escape_external_handler_value_ = false;
jaekyun038903192015-03-31 14:15:5973
74 DISALLOW_COPY_AND_ASSIGN(InterceptNavigationDelegate);
[email protected]b27a5842012-11-09 10:06:1375};
76
[email protected]8812e3d02013-05-22 12:38:5377} // namespace navigation_interception
[email protected]b27a5842012-11-09 10:06:1378
[email protected]62885ab2013-01-23 03:55:1679#endif // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_