| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DE
LEGATE_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DE
LEGATE_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DE
LEGATE_H_ | 6 #define CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DE
LEGATE_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_helper.h" | 8 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/supports_user_data.h" | |
| 11 | 9 |
| 12 class GURL; | 10 // TODO(jknotten): Remove this header once external dependencies are using the |
| 13 | 11 // header at the above new location. |
| 14 namespace content { | |
| 15 class ResourceThrottle; | |
| 16 class WebContents; | |
| 17 } | |
| 18 | |
| 19 namespace net { | |
| 20 class URLRequest; | |
| 21 } | |
| 22 | 12 |
| 23 namespace navigation_interception { | 13 namespace navigation_interception { |
| 24 | 14 |
| 25 // Native side of the InterceptNavigationDelegate Java interface. | 15 using content::InterceptNavigationDelegate; |
| 26 // This is used to create a InterceptNavigationResourceThrottle that calls the | 16 using content::RegisterInterceptNavigationDelegate; |
| 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 | 17 |
| 64 } // namespace navigation_interception | 18 } // namespace navigation_interception |
| 65 | 19 |
| 66 #endif // CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION
_DELEGATE_H_ | 20 #endif // CHROME_BROWSER_COMPONENT_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION
_DELEGATE_H_ |
| OLD | NEW |