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