15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 80529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/android/jni_weak_ref.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceThrottle; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequest; 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace navigation_interception { 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class NavigationParams; 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Native side of the InterceptNavigationDelegate Java interface. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is used to create a InterceptNavigationResourceThrottle that calls the 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Java interface method to determine whether a navigation should be ignored or 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// not. 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// To us this class: 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1) the Java-side interface implementation must be associated (via the 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Associate method) with a WebContents for which URLRequests are to be 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// intercepted, 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2) the ResourceThrottle obtained via CreateThrottleFor must be associated 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// with the URLRequests in the ResourceDispatcherHostDelegate 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// implementation. 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterceptNavigationDelegate : public base::SupportsUserData::Data { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) InterceptNavigationDelegate(JNIEnv* env, jobject jdelegate); 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~InterceptNavigationDelegate(); 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Associates the InterceptNavigationDelegate with a WebContents using the 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SupportsUserData mechanism. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // As implied by the use of scoped_ptr, the WebContents will assume ownership 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of |delegate|. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void Associate(content::WebContents* web_contents, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<InterceptNavigationDelegate> delegate); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets the InterceptNavigationDelegate associated with the WebContents, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // can be null. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static InterceptNavigationDelegate* Get(content::WebContents* web_contents); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates a InterceptNavigationResourceThrottle that will direct all 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callbacks to the InterceptNavigationDelegate. 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static content::ResourceThrottle* CreateThrottleFor( 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) net::URLRequest* request); 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool ShouldIgnoreNavigation( 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const NavigationParams& navigation_params); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) JavaObjectWeakGlobalRef weak_jdelegate_; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RegisterInterceptNavigationDelegate(JNIEnv* env); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace navigation_interception 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // COMPONENTS_NAVIGATION_INTERCEPTION_INTERCEPT_NAVIGATION_DELEGATE_H_ 69