1 // Copyright 2014 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_SUPERVISED_USER_SUPERVISED_USER_NAVIGATION_THROTTLE_H_ 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_NAVIGATION_THROTTLE_H_ 7 8 #include <memory> 9 10 #include "base/compiler_specific.h" 11 #include "base/macros.h" 12 #include "base/memory/weak_ptr.h" 13 #include "chrome/browser/supervised_user/supervised_user_error_page/supervised_user_error_page.h" 14 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" 15 #include "chrome/browser/supervised_user/supervised_users.h" 16 #include "content/public/browser/navigation_throttle.h" 17 18 class SupervisedUserNavigationThrottle : public content::NavigationThrottle { 19 public: 20 enum CallbackActions { kCancelNavigation = 0, kCancelWithInterstitial }; 21 22 // Returns a new throttle for the given navigation, or nullptr if no 23 // throttling is required. 24 static std::unique_ptr<SupervisedUserNavigationThrottle> 25 MaybeCreateThrottleFor(content::NavigationHandle* navigation_handle); 26 27 ~SupervisedUserNavigationThrottle() override; 28 29 // content::NavigationThrottle implementation: 30 ThrottleCheckResult WillStartRequest() override; 31 ThrottleCheckResult WillRedirectRequest() override; 32 const char* GetNameForLogging() override; 33 34 private: 35 SupervisedUserNavigationThrottle( 36 content::NavigationHandle* navigation_handle); 37 38 // Checks the current URL for the navigation. If called from 39 // WillRedirectRequest, checks the URL being redirected to, not the original 40 // URL. 41 ThrottleCheckResult CheckURL(); 42 43 void ShowInterstitial( 44 const GURL& url, 45 supervised_user_error_page::FilteringBehaviorReason reason); 46 47 void ShowInterstitialAsync( 48 supervised_user_error_page::FilteringBehaviorReason reason); 49 50 void OnCheckDone(const GURL& url, 51 SupervisedUserURLFilter::FilteringBehavior behavior, 52 supervised_user_error_page::FilteringBehaviorReason reason, 53 bool uncertain); 54 55 void OnInterstitialResult(CallbackActions continue_request, 56 bool already_requested_permission, 57 bool is_main_frame); 58 59 const SupervisedUserURLFilter* url_filter_; 60 bool deferred_; 61 supervised_user_error_page::FilteringBehaviorReason reason_; 62 SupervisedUserURLFilter::FilteringBehavior behavior_; 63 base::WeakPtrFactory<SupervisedUserNavigationThrottle> weak_ptr_factory_{ 64 this}; 65 66 DISALLOW_COPY_AND_ASSIGN(SupervisedUserNavigationThrottle); 67 }; 68 69 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_NAVIGATION_THROTTLE_H_ 70