summaryrefslogtreecommitdiffstats
path: root/components/navigation_interception/intercept_navigation_delegate.h
blob: 66a2518d7a0f92c91946cf49a5181699996cb7c3 (plain)
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
// Copyright (c) 2012 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 COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
#define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_

#include "base/android/jni_helper.h"
#include "base/memory/scoped_ptr.h"
#include "base/supports_user_data.h"
#include "content/public/common/page_transition_types.h"

class GURL;

namespace content {
class ResourceThrottle;
class WebContents;
}

namespace net {
class URLRequest;
}

namespace components {

// Native side of the InterceptNavigationDelegate Java interface.
// This is used to create a InterceptNavigationResourceThrottle that calls the
// Java interface method to determine whether a navigation should be ignored or
// not.
// To us this class:
// 1) the Java-side interface implementation must be associated (via the
//    Associate method) with a WebContents for which URLRequests are to be
//    intercepted,
// 2) the ResourceThrottle obtained via CreateThrottleFor must be associated
//    with the URLRequests in the ResourceDispatcherHostDelegate
//    implementation.
class InterceptNavigationDelegate : public base::SupportsUserData::Data {
 public:
  InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate);
  virtual ~InterceptNavigationDelegate();

  // Associates the InterceptNavigationDelegate with a WebContents using the
  // SupportsUserData mechanism.
  // As implied by the use of scoped_ptr, the WebContents will assume ownership
  // of |delegate|.
  static void Associate(content::WebContents* web_contents,
                        scoped_ptr<InterceptNavigationDelegate> delegate);
  // Gets the InterceptNavigationDelegate associated with the WebContents,
  // can be null.
  static InterceptNavigationDelegate* Get(content::WebContents* web_contents);

  // Creates a InterceptNavigationResourceThrottle that will direct all
  // callbacks to the InterceptNavigationDelegate.
  static content::ResourceThrottle* CreateThrottleFor(
      net::URLRequest* request);

  virtual bool ShouldIgnoreNavigation(const GURL& url,
                                      bool is_post,
                                      bool has_user_gesture,
                                      content::PageTransition transition_type);
 private:
  JavaObjectWeakGlobalRef weak_jdelegate_;
};

bool RegisterInterceptNavigationDelegate(JNIEnv* env);

}  // namespace components

#endif  // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_