Home | History | Annotate | Download | only in navigation_interception
      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 
      5 #ifndef COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
      6 #define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
      7 
      8 #include "base/android/jni_helper.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/supports_user_data.h"
     11 #include "content/public/common/page_transition_types.h"
     12 
     13 class GURL;
     14 
     15 namespace content {
     16 class ResourceThrottle;
     17 class WebContents;
     18 }
     19 
     20 namespace net {
     21 class URLRequest;
     22 }
     23 
     24 namespace navigation_interception {
     25 
     26 class NavigationParams;
     27 
     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 ResourceThrottle obtained via CreateThrottleFor must be associated
     37 //    with the URLRequests in the ResourceDispatcherHostDelegate
     38 //    implementation.
     39 class InterceptNavigationDelegate : public base::SupportsUserData::Data {
     40  public:
     41   InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate);
     42   virtual ~InterceptNavigationDelegate();
     43 
     44   // Associates the InterceptNavigationDelegate with a WebContents using the
     45   // SupportsUserData mechanism.
     46   // As implied by the use of scoped_ptr, the WebContents will assume ownership
     47   // of |delegate|.
     48   static void Associate(content::WebContents* web_contents,
     49                         scoped_ptr<InterceptNavigationDelegate> delegate);
     50   // Gets the InterceptNavigationDelegate associated with the WebContents,
     51   // can be null.
     52   static InterceptNavigationDelegate* Get(content::WebContents* web_contents);
     53 
     54   // Creates a InterceptNavigationResourceThrottle that will direct all
     55   // callbacks to the InterceptNavigationDelegate.
     56   static content::ResourceThrottle* CreateThrottleFor(
     57       net::URLRequest* request);
     58 
     59   virtual bool ShouldIgnoreNavigation(
     60       const NavigationParams& navigation_params);
     61  private:
     62   JavaObjectWeakGlobalRef weak_jdelegate_;
     63 };
     64 
     65 bool RegisterInterceptNavigationDelegate(JNIEnv* env);
     66 
     67 }  // namespace navigation_interception
     68 
     69 #endif  // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_
     70