Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/managed_mode/managed_mode_navigation_observer.h

Issue 12887005: Show interstitial from ManagedModeNavigationObserver instead of ManagedModeResourceThrottle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:
26 typedef base::Callback<void(bool)> SuccessCallback;
27
22 virtual ~ManagedModeNavigationObserver(); 28 virtual ~ManagedModeNavigationObserver();
23 29
30 // Called when a network request was blocked. The passed in |callback| is
31 // called with the result of the interstitial, i.e. whether we should proceed
32 // with the request or not.
33 static void DidBlockRequest(int render_process_id,
34 int render_view_id,
35 const GURL& url,
36 const SuccessCallback& callback);
37
24 // Sets the specific infobar as dismissed. 38 // Sets the specific infobar as dismissed.
25 void WarnInfobarDismissed(); 39 void WarnInfobarDismissed();
26 void PreviewInfobarDismissed(); 40 void PreviewInfobarDismissed();
27 41
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 42 // Returns whether the user should be allowed to navigate to this URL after
32 // he has clicked "Preview" on the interstitial. 43 // he has clicked "Preview" on the interstitial.
33 bool CanTemporarilyNavigateHost(const GURL& url); 44 bool CanTemporarilyNavigateHost(const GURL& url);
34 45
35 // Clears the state recorded in the observer. 46 // Clears the state recorded in the observer.
36 void ClearObserverState(); 47 void ClearObserverState();
37 48
38 // Whitelists exact URLs for redirects and host patterns for the final URL. 49 // 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 50 // If the URL uses HTTPS, whitelists only the host on HTTPS. Clears the
40 // observer state after adding the URLs. 51 // observer state after adding the URLs.
(...skipping 17 matching lines...) Expand all
58 // called). 69 // called).
59 enum ObserverState { 70 enum ObserverState {
60 RECORDING_URLS_BEFORE_PREVIEW, 71 RECORDING_URLS_BEFORE_PREVIEW,
61 RECORDING_URLS_AFTER_PREVIEW, 72 RECORDING_URLS_AFTER_PREVIEW,
62 }; 73 };
63 74
64 friend class content::WebContentsUserData<ManagedModeNavigationObserver>; 75 friend class content::WebContentsUserData<ManagedModeNavigationObserver>;
65 76
66 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); 77 explicit ManagedModeNavigationObserver(content::WebContents* web_contents);
67 78
79 // Shows the blocking interstitial if it is not already shown.
80 void ShowInterstitial(const GURL& url);
81
82 // Queues up a callback to be called with the result of the interstitial.
83 void AddInterstitialCallback(const GURL& url,
84 const SuccessCallback& callback);
85
86 // Dispatches the result of the interstitial to all pending callbacks.
87 void OnInterstitialResult(bool result);
88
68 // Adding the temporary exception stops the ResourceThrottle from showing 89 // Adding the temporary exception stops the ResourceThrottle from showing
69 // an interstitial for this RenderView. This allows the user to navigate 90 // an interstitial for this RenderView. This allows the user to navigate
70 // around on the website after clicking preview. 91 // around on the website after clicking preview.
71 void AddTemporaryException(); 92 void AddTemporaryException();
72 // Updates the ResourceThrottle with the latest user navigation status. 93 // Updates the ResourceThrottle with the latest user navigation status.
73 void UpdateExceptionNavigationStatus(); 94 void UpdateExceptionNavigationStatus();
74 void RemoveTemporaryException(); 95 void RemoveTemporaryException();
75 96
76 void AddURLToPatternList(const GURL& url); 97 void AddURLToPatternList(const GURL& url);
77 98
99 // Returns whether the user would stay in elevated state if he visits this
100 // URL.
101 bool ShouldStayElevatedForURL(const GURL& url);
102
78 // content::WebContentsObserver implementation. 103 // content::WebContentsObserver implementation.
79 // An example regarding the order in which these events take place for 104 // An example regarding the order in which these events take place for
80 // google.com in our case is as follows: 105 // google.com in our case is as follows:
81 // 1. User types in google.com and clicks enter. 106 // 1. User types in google.com and clicks enter.
82 // -> NavigateToPendingEntry: http://google.com 107 // -> NavigateToPendingEntry: http://google.com
83 // -> DidStartProvisionalLoadForFrame http://google.com 108 // -> DidStartProvisionalLoadForFrame http://google.com
84 // -> ProvisionalChangeToMainFrameUrl http://google.com 109 // -> ProvisionalChangeToMainFrameUrl http://google.com
85 // 2. Interstitial is shown to the user. User clicks "Preview". 110 // 2. Interstitial is shown to the user. User clicks "Preview".
86 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) 111 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect)
87 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) 112 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect)
88 // -> DidNavigateMainFrame http://www.google.com 113 // -> DidNavigateMainFrame http://www.google.com
89 // 3. Page is shown. 114 // 3. Page is shown.
90 virtual void NavigateToPendingEntry( 115 virtual void NavigateToPendingEntry(
91 const GURL& url, 116 const GURL& url,
92 content::NavigationController::ReloadType reload_type) OVERRIDE; 117 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( 118 virtual void ProvisionalChangeToMainFrameUrl(
97 const GURL& url, 119 const GURL& url,
98 content::RenderViewHost* render_view_host) OVERRIDE; 120 content::RenderViewHost* render_view_host) OVERRIDE;
99 virtual void DidCommitProvisionalLoadForFrame( 121 virtual void DidCommitProvisionalLoadForFrame(
100 int64 frame_id, 122 int64 frame_id,
101 bool is_main_frame, 123 bool is_main_frame,
102 const GURL& url, 124 const GURL& url,
103 content::PageTransition transition_type, 125 content::PageTransition transition_type,
104 content::RenderViewHost* render_view_host) OVERRIDE; 126 content::RenderViewHost* render_view_host) OVERRIDE;
127 virtual void DidNavigateMainFrame(
128 const content::LoadCommittedDetails& details,
129 const content::FrameNavigateParams& params) OVERRIDE;
105 virtual void DidGetUserGesture() OVERRIDE; 130 virtual void DidGetUserGesture() OVERRIDE;
106 131
107 // Returns whether the user would stay in elevated state if he visits this 132 // content::NotificationObserver implementation.
108 // URL. 133 virtual void Observe(int type,
109 bool ShouldStayElevatedForURL(const GURL& url); 134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) OVERRIDE;
110 136
111 // Owned by the profile, so outlives us. 137 // Owned by the profile, so outlives us.
112 ManagedUserService* managed_user_service_; 138 ManagedUserService* managed_user_service_;
113 139
114 // Owned by ManagedUserService. 140 // Owned by ManagedUserService.
115 const ManagedModeURLFilter* url_filter_; 141 const ManagedModeURLFilter* url_filter_;
116 142
117 // Owned by the InfoBarService, which has the same lifetime as this object. 143 // Owned by the InfoBarService, which has the same lifetime as this object.
118 InfoBarDelegate* warn_infobar_delegate_; 144 InfoBarDelegate* warn_infobar_delegate_;
119 InfoBarDelegate* preview_infobar_delegate_; 145 InfoBarDelegate* preview_infobar_delegate_;
120 146
121 // Whether we received a user gesture. 147 // Whether we received a user gesture.
122 // The goal is to allow automatic redirects (in order not to break the flow 148 // 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 149 // 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 150 // to blocked pages. We consider a redirect to be automatic if we did
125 // not get a user gesture. 151 // not get a user gesture.
126 bool got_user_gesture_; 152 bool got_user_gesture_;
127 ObserverState state_; 153 ObserverState state_;
128 std::set<GURL> navigated_urls_; 154 std::set<GURL> navigated_urls_;
129 GURL last_url_; 155 GURL last_url_;
130 156
131 // The elevation state corresponding to the current WebContents. 157 // The elevation state corresponding to the current WebContents.
132 // Will be set to true for non-managed users. 158 // Will be set to true for non-managed users.
133 bool is_elevated_; 159 bool is_elevated_;
134 160
161 base::WeakPtrFactory<ManagedModeNavigationObserver> weak_ptr_factory_;
162
163 // These callbacks get queued up when we show the blocking interstitial and
164 // are posted to the IO thread with the result of the interstitial, i.e.
165 // whether the user successfully authenticated to continue.
166 std::vector<SuccessCallback> callbacks_;
167
168 content::NotificationRegistrar registrar_;
169
135 int last_allowed_page_; 170 int last_allowed_page_;
136 171
137 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); 172 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver);
138 }; 173 };
139 174
140 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ 175 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698