Chromium Code Reviews| 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_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "content/public/browser/notification_observer.h" | |
| 13 #include "content/public/browser/notification_registrar.h" | |
| 11 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/browser/web_contents_user_data.h" | 15 #include "content/public/browser/web_contents_user_data.h" |
| 13 | 16 |
| 14 class InfoBarDelegate; | 17 class InfoBarDelegate; |
| 15 class ManagedModeURLFilter; | 18 class ManagedModeURLFilter; |
| 16 class ManagedUserService; | 19 class ManagedUserService; |
| 17 | 20 |
| 18 class ManagedModeNavigationObserver | 21 class ManagedModeNavigationObserver |
| 19 : public content::WebContentsObserver, | 22 : public content::WebContentsUserData<ManagedModeNavigationObserver>, |
| 20 public content::WebContentsUserData<ManagedModeNavigationObserver> { | 23 public content::WebContentsObserver, |
| 24 public content::NotificationObserver { | |
| 21 public: | 25 public: |
| 22 virtual ~ManagedModeNavigationObserver(); | 26 virtual ~ManagedModeNavigationObserver(); |
| 23 | 27 |
| 28 // Called when a network request was blocked. The passed in |callback| is | |
| 29 // called with the result of the interstitial, i.e. whether we should proceed | |
| 30 // with the request or not. | |
| 31 static void DidBlockRequest(int render_process_id, | |
| 32 int render_view_id, | |
| 33 const GURL& url, | |
| 34 const base::Callback<void(bool)>& callback); | |
|
Adrian Kuegel
2013/03/28 14:28:34
nit: You could use a typedef for this kind of call
Bernhard Bauer
2013/03/28 15:03:30
Done.
| |
| 35 | |
| 24 // Sets the specific infobar as dismissed. | 36 // Sets the specific infobar as dismissed. |
| 25 void WarnInfobarDismissed(); | 37 void WarnInfobarDismissed(); |
| 26 void PreviewInfobarDismissed(); | 38 void PreviewInfobarDismissed(); |
| 27 | 39 |
| 28 // Sets the state of the Observer from the outside. | |
| 29 void SetStateToRecordingAfterPreview(); | |
| 30 | |
| 31 // Returns whether the user should be allowed to navigate to this URL after | 40 // Returns whether the user should be allowed to navigate to this URL after |
| 32 // he has clicked "Preview" on the interstitial. | 41 // he has clicked "Preview" on the interstitial. |
| 33 bool CanTemporarilyNavigateHost(const GURL& url); | 42 bool CanTemporarilyNavigateHost(const GURL& url); |
| 34 | 43 |
| 35 // Clears the state recorded in the observer. | 44 // Clears the state recorded in the observer. |
| 36 void ClearObserverState(); | 45 void ClearObserverState(); |
| 37 | 46 |
| 38 // Whitelists exact URLs for redirects and host patterns for the final URL. | 47 // Whitelists exact URLs for redirects and host patterns for the final URL. |
| 39 // If the URL uses HTTPS, whitelists only the host on HTTPS. Clears the | 48 // If the URL uses HTTPS, whitelists only the host on HTTPS. Clears the |
| 40 // observer state after adding the URLs. | 49 // observer state after adding the URLs. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 58 // called). | 67 // called). |
| 59 enum ObserverState { | 68 enum ObserverState { |
| 60 RECORDING_URLS_BEFORE_PREVIEW, | 69 RECORDING_URLS_BEFORE_PREVIEW, |
| 61 RECORDING_URLS_AFTER_PREVIEW, | 70 RECORDING_URLS_AFTER_PREVIEW, |
| 62 }; | 71 }; |
| 63 | 72 |
| 64 friend class content::WebContentsUserData<ManagedModeNavigationObserver>; | 73 friend class content::WebContentsUserData<ManagedModeNavigationObserver>; |
| 65 | 74 |
| 66 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); | 75 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); |
| 67 | 76 |
| 77 // Shows the blocking interstitial if it is not already shown. | |
| 78 void ShowInterstitial(const GURL& url); | |
| 79 | |
| 80 // Queues up a callback to be called with the result of the interstitial. | |
| 81 void AddInterstitialCallback(const GURL& url, | |
| 82 const base::Callback<void(bool)>& callback); | |
| 83 | |
| 84 // Dispatches the result of the interstitial to all pending callbacks. | |
| 85 void OnInterstitialResult(bool result); | |
| 86 | |
| 68 // Adding the temporary exception stops the ResourceThrottle from showing | 87 // Adding the temporary exception stops the ResourceThrottle from showing |
| 69 // an interstitial for this RenderView. This allows the user to navigate | 88 // an interstitial for this RenderView. This allows the user to navigate |
| 70 // around on the website after clicking preview. | 89 // around on the website after clicking preview. |
| 71 void AddTemporaryException(); | 90 void AddTemporaryException(); |
| 72 // Updates the ResourceThrottle with the latest user navigation status. | 91 // Updates the ResourceThrottle with the latest user navigation status. |
| 73 void UpdateExceptionNavigationStatus(); | 92 void UpdateExceptionNavigationStatus(); |
| 74 void RemoveTemporaryException(); | 93 void RemoveTemporaryException(); |
| 75 | 94 |
| 76 void AddURLToPatternList(const GURL& url); | 95 void AddURLToPatternList(const GURL& url); |
| 77 | 96 |
| 97 // Returns whether the user would stay in elevated state if he visits this | |
| 98 // URL. | |
| 99 bool ShouldStayElevatedForURL(const GURL& url); | |
| 100 | |
| 78 // content::WebContentsObserver implementation. | 101 // content::WebContentsObserver implementation. |
| 79 // An example regarding the order in which these events take place for | 102 // An example regarding the order in which these events take place for |
| 80 // google.com in our case is as follows: | 103 // google.com in our case is as follows: |
| 81 // 1. User types in google.com and clicks enter. | 104 // 1. User types in google.com and clicks enter. |
| 82 // -> NavigateToPendingEntry: http://google.com | 105 // -> NavigateToPendingEntry: http://google.com |
| 83 // -> DidStartProvisionalLoadForFrame http://google.com | 106 // -> DidStartProvisionalLoadForFrame http://google.com |
| 84 // -> ProvisionalChangeToMainFrameUrl http://google.com | 107 // -> ProvisionalChangeToMainFrameUrl http://google.com |
| 85 // 2. Interstitial is shown to the user. User clicks "Preview". | 108 // 2. Interstitial is shown to the user. User clicks "Preview". |
| 86 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) | 109 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) |
| 87 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) | 110 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) |
| 88 // -> DidNavigateMainFrame http://www.google.com | 111 // -> DidNavigateMainFrame http://www.google.com |
| 89 // 3. Page is shown. | 112 // 3. Page is shown. |
| 90 virtual void NavigateToPendingEntry( | 113 virtual void NavigateToPendingEntry( |
| 91 const GURL& url, | 114 const GURL& url, |
| 92 content::NavigationController::ReloadType reload_type) OVERRIDE; | 115 content::NavigationController::ReloadType reload_type) OVERRIDE; |
| 93 virtual void DidNavigateMainFrame( | |
| 94 const content::LoadCommittedDetails& details, | |
| 95 const content::FrameNavigateParams& params) OVERRIDE; | |
| 96 virtual void ProvisionalChangeToMainFrameUrl( | 116 virtual void ProvisionalChangeToMainFrameUrl( |
| 97 const GURL& url, | 117 const GURL& url, |
| 98 content::RenderViewHost* render_view_host) OVERRIDE; | 118 content::RenderViewHost* render_view_host) OVERRIDE; |
| 99 virtual void DidCommitProvisionalLoadForFrame( | 119 virtual void DidCommitProvisionalLoadForFrame( |
| 100 int64 frame_id, | 120 int64 frame_id, |
| 101 bool is_main_frame, | 121 bool is_main_frame, |
| 102 const GURL& url, | 122 const GURL& url, |
| 103 content::PageTransition transition_type, | 123 content::PageTransition transition_type, |
| 104 content::RenderViewHost* render_view_host) OVERRIDE; | 124 content::RenderViewHost* render_view_host) OVERRIDE; |
| 125 virtual void DidNavigateMainFrame( | |
| 126 const content::LoadCommittedDetails& details, | |
| 127 const content::FrameNavigateParams& params) OVERRIDE; | |
| 105 virtual void DidGetUserGesture() OVERRIDE; | 128 virtual void DidGetUserGesture() OVERRIDE; |
| 106 | 129 |
| 107 // Returns whether the user would stay in elevated state if he visits this | 130 // content::NotificationObserver implementation. |
| 108 // URL. | 131 virtual void Observe(int type, |
| 109 bool ShouldStayElevatedForURL(const GURL& url); | 132 const content::NotificationSource& source, |
| 133 const content::NotificationDetails& details) OVERRIDE; | |
| 110 | 134 |
| 111 // Owned by the profile, so outlives us. | 135 // Owned by the profile, so outlives us. |
| 112 ManagedUserService* managed_user_service_; | 136 ManagedUserService* managed_user_service_; |
| 113 | 137 |
| 114 // Owned by ManagedUserService. | 138 // Owned by ManagedUserService. |
| 115 const ManagedModeURLFilter* url_filter_; | 139 const ManagedModeURLFilter* url_filter_; |
| 116 | 140 |
| 117 // Owned by the InfoBarService, which has the same lifetime as this object. | 141 // Owned by the InfoBarService, which has the same lifetime as this object. |
| 118 InfoBarDelegate* warn_infobar_delegate_; | 142 InfoBarDelegate* warn_infobar_delegate_; |
| 119 InfoBarDelegate* preview_infobar_delegate_; | 143 InfoBarDelegate* preview_infobar_delegate_; |
| 120 | 144 |
| 121 // Whether we received a user gesture. | 145 // Whether we received a user gesture. |
| 122 // The goal is to allow automatic redirects (in order not to break the flow | 146 // The goal is to allow automatic redirects (in order not to break the flow |
| 123 // or show too many interstitials) while not allowing the user to navigate | 147 // or show too many interstitials) while not allowing the user to navigate |
| 124 // to blocked pages. We consider a redirect to be automatic if we did | 148 // to blocked pages. We consider a redirect to be automatic if we did |
| 125 // not get a user gesture. | 149 // not get a user gesture. |
| 126 bool got_user_gesture_; | 150 bool got_user_gesture_; |
| 127 ObserverState state_; | 151 ObserverState state_; |
| 128 std::set<GURL> navigated_urls_; | 152 std::set<GURL> navigated_urls_; |
| 129 GURL last_url_; | 153 GURL last_url_; |
| 130 | 154 |
| 131 // The elevation state corresponding to the current WebContents. | 155 // The elevation state corresponding to the current WebContents. |
| 132 // Will be set to true for non-managed users. | 156 // Will be set to true for non-managed users. |
| 133 bool is_elevated_; | 157 bool is_elevated_; |
| 134 | 158 |
| 159 base::WeakPtrFactory<ManagedModeNavigationObserver> weak_ptr_factory_; | |
| 160 std::vector<base::Callback<void(bool)> > callbacks_; | |
|
Adrian Kuegel
2013/03/28 14:28:34
Nit: you could document this variable.
Bernhard Bauer
2013/03/28 15:03:30
Done.
| |
| 161 | |
| 162 content::NotificationRegistrar registrar_; | |
| 163 | |
| 135 int last_allowed_page_; | 164 int last_allowed_page_; |
| 136 | 165 |
| 137 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); | 166 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); |
| 138 }; | 167 }; |
| 139 | 168 |
| 140 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 169 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |