Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / navigation_interception / intercept_navigation_delegate.h
blob57858fdc92dd905f119295a9c947b6283db4d969
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.
5 #ifndef COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
6 #define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
8 #include "base/android/jni_weak_ref.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/supports_user_data.h"
12 class GURL;
14 namespace content {
15 class NavigationHandle;
16 class NavigationThrottle;
17 class WebContents;
20 namespace net {
21 class URLRequest;
24 namespace navigation_interception {
26 class NavigationParams;
28 // Native side of the InterceptNavigationDelegate Java interface.
29 // This is used to create a InterceptNavigationResourceThrottle that calls the
30 // Java interface method to determine whether a navigation should be ignored or
31 // not.
32 // To us this class:
33 // 1) the Java-side interface implementation must be associated (via the
34 // Associate method) with a WebContents for which URLRequests are to be
35 // intercepted,
36 // 2) the NavigationThrottle obtained via CreateThrottleFor must be associated
37 // with the NavigationHandle in the ContentBrowserClient implementation.
38 class InterceptNavigationDelegate : public base::SupportsUserData::Data {
39 public:
40 InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate);
41 ~InterceptNavigationDelegate() override;
43 // Associates the InterceptNavigationDelegate with a WebContents using the
44 // SupportsUserData mechanism.
45 // As implied by the use of scoped_ptr, the WebContents will assume ownership
46 // of |delegate|.
47 static void Associate(content::WebContents* web_contents,
48 scoped_ptr<InterceptNavigationDelegate> delegate);
49 // Gets the InterceptNavigationDelegate associated with the WebContents,
50 // can be null.
51 static InterceptNavigationDelegate* Get(content::WebContents* web_contents);
53 // Creates a InterceptNavigationThrottle that will direct all callbacks to
54 // the InterceptNavigationDelegate.
55 static scoped_ptr<content::NavigationThrottle> CreateThrottleFor(
56 content::NavigationHandle* handle);
58 // Updates information to determine whether to have user gesture carryover or
59 // not.
60 static void UpdateUserGestureCarryoverInfo(net::URLRequest* request);
62 virtual bool ShouldIgnoreNavigation(
63 const NavigationParams& navigation_params);
65 // Updates |last_user_gesture_carryover_timestamp_| when user gesture is
66 // carried over.
67 void UpdateLastUserGestureCarryoverTimestamp();
69 private:
70 JavaObjectWeakGlobalRef weak_jdelegate_;
71 base::TimeTicks last_user_gesture_carryover_timestamp_;
73 DISALLOW_COPY_AND_ASSIGN(InterceptNavigationDelegate);
76 bool RegisterInterceptNavigationDelegate(JNIEnv* env);
78 } // namespace navigation_interception
80 #endif // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_