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_NAVIGATION_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
6 #define CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
7 | 7 |
8 #include <set> | |
9 | |
10 #include "base/values.h" | |
8 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
9 #include "content/public/browser/web_contents_user_data.h" | 12 #include "content/public/browser/web_contents_user_data.h" |
10 | 13 |
11 class InfoBarDelegate; | 14 class InfoBarDelegate; |
12 class ManagedModeURLFilter; | 15 class ManagedModeURLFilter; |
13 | 16 |
14 class ManagedModeNavigationObserver | 17 class ManagedModeNavigationObserver |
15 : public content::WebContentsObserver, | 18 : public content::WebContentsObserver, |
16 public content::WebContentsUserData<ManagedModeNavigationObserver> { | 19 public content::WebContentsUserData<ManagedModeNavigationObserver> { |
17 public: | 20 public: |
18 virtual ~ManagedModeNavigationObserver(); | 21 virtual ~ManagedModeNavigationObserver(); |
19 | 22 |
23 // Sets the specific infobar as dismissed. | |
20 void WarnInfobarDismissed(); | 24 void WarnInfobarDismissed(); |
21 void PreviewInfobarDismissed(); | 25 void PreviewInfobarDismissed(); |
22 | 26 |
23 // Adds the url to the list of navigated URLs if it was not already there. | 27 // Sets the state of the Observer from the outside. |
24 void AddNavigatedURL(const GURL& url); | 28 void SetStateToRecordingAfterPreview(); |
25 | 29 |
26 // For the list of URLs that were navigated since the last Observer | 30 // Returns whether the user should be allowed to navigate to this URL after |
27 // instantiation: | 31 // he has clicked "Preview" on the interstitial. |
28 // * add the first N-1 to the whitelist such that only those URLs are | 32 bool CanTemporarilyNavigateHost(const GURL& url); |
29 // allowed and not more general versions of them. | 33 |
30 // * add only the host part of the last URL so that it allows all | 34 // Clears the state recorded in the observer. |
31 // pages on that domain. If it's HTTPS do the same but only on the HTTPS | 35 void ClearObserverState(); |
32 // protocol. | 36 |
33 void AddURLList(); | 37 // Whitelist exact URLs for redirects and host patterns for the final URL. |
Pam (message me for reviews)
2012/12/06 15:11:56
nit: please be descriptive rather than imperative
Sergiu
2013/01/04 15:44:07
Done.
| |
38 // If the URL uses HTTPS whitelist only the host on HTTPS. Clears the | |
39 // observer state after adding the URLs. | |
40 void AddSavedURLsToWhitelistAndClearState(); | |
34 | 41 |
35 private: | 42 private: |
43 // An observer can be in one of the following states: | |
44 // - RECORDING_URLS_BEFORE_PREVIEW: This is the initial state when the user | |
45 // navigates to a new page. In this state the navigated URLs that should be | |
46 // blocked are recorded. The Observer moves to the next state when an | |
47 // interstitial was shown and the user clicked "Preview" on the interstitial. | |
48 // - RECORDING_URLS_AFTER_PREVIEW: URLs that should be blocked are | |
49 // still recorded while the page redirect. The Observer moves to the next | |
Pam (message me for reviews)
2012/12/06 15:11:56
nit: ...redirects.
Sergiu
2013/01/04 15:44:07
Done.
| |
50 // state after the page finished redirecting (DidNavigateMainFrame gets | |
51 // called). | |
52 // - NOT_RECORDING_URLS: The redirects have completed and blocked URLs are | |
53 // no longer being recorded. | |
54 enum ObserverState { | |
55 RECORDING_URLS_BEFORE_PREVIEW, | |
56 RECORDING_URLS_AFTER_PREVIEW, | |
57 NOT_RECORDING_URLS, | |
58 }; | |
59 | |
36 friend class WebContentsUserData<ManagedModeNavigationObserver>; | 60 friend class WebContentsUserData<ManagedModeNavigationObserver>; |
37 | 61 |
38 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); | 62 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); |
39 | 63 |
64 // Adding the temporary exception stops the ResourceThrottle from showing | |
65 // an interstitial for this RenderView. | |
Pam (message me for reviews)
2012/12/06 15:11:56
When would this be used? Is it so you can navigate
Sergiu
2013/01/04 15:44:07
Exactly, added a comment to clarify that.
| |
66 void AddTemporaryException(); | |
67 void RemoveTemporaryException(); | |
68 | |
69 void AddURLToPatternList(const GURL& url); | |
70 void AddURLAsLastPattern(const GURL& url); | |
71 | |
40 // content::WebContentsObserver implementation. | 72 // content::WebContentsObserver implementation. |
73 // An example regarding the order in which these events take place for | |
74 // google.com in our case is as follows: | |
75 // 1. User types in google.com and clicks enter. | |
76 // -> NavigateToPendingEntry: http://google.com | |
77 // -> DidStartProvisionalLoadForFrame http://google.com | |
78 // -> ProvisionalChangeToMainFrameUrl http://google.com | |
79 // 2. Interstitial is shown to the user. User clicks "Preview". | |
80 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) | |
81 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) | |
82 // -> DidNavigateMainFrame http://www.google.com | |
83 // 3. Page is shown. | |
41 virtual void NavigateToPendingEntry( | 84 virtual void NavigateToPendingEntry( |
42 const GURL& url, | 85 const GURL& url, |
43 content::NavigationController::ReloadType reload_type) OVERRIDE; | 86 content::NavigationController::ReloadType reload_type) OVERRIDE; |
44 virtual void DidNavigateMainFrame( | 87 virtual void DidNavigateMainFrame( |
45 const content::LoadCommittedDetails& details, | 88 const content::LoadCommittedDetails& details, |
46 const content::FrameNavigateParams& params) OVERRIDE; | 89 const content::FrameNavigateParams& params) OVERRIDE; |
47 virtual void DidStartProvisionalLoadForFrame( | 90 virtual void DidStartProvisionalLoadForFrame( |
48 int64 frame_id, | 91 int64 frame_id, |
49 int64 parent_frame_id, | 92 int64 parent_frame_id, |
50 bool is_main_frame, | 93 bool is_main_frame, |
51 const GURL& url, | 94 const GURL& url, |
52 bool is_error_page, | 95 bool is_error_page, |
53 content::RenderViewHost* render_view_host) OVERRIDE; | 96 content::RenderViewHost* render_view_host) OVERRIDE; |
54 virtual void ProvisionalChangeToMainFrameUrl( | 97 virtual void ProvisionalChangeToMainFrameUrl( |
55 const GURL& url, | 98 const GURL& url, |
56 const GURL& opener_url, | 99 const GURL& opener_url, |
57 content::RenderViewHost* render_view_host) OVERRIDE; | 100 content::RenderViewHost* render_view_host) OVERRIDE; |
58 virtual void DidCommitProvisionalLoadForFrame( | 101 virtual void DidCommitProvisionalLoadForFrame( |
59 int64 frame_id, | 102 int64 frame_id, |
60 bool is_main_frame, | 103 bool is_main_frame, |
61 const GURL& url, | 104 const GURL& url, |
62 content::PageTransition transition_type, | 105 content::PageTransition transition_type, |
63 content::RenderViewHost* render_view_host) OVERRIDE; | 106 content::RenderViewHost* render_view_host) OVERRIDE; |
64 | 107 |
65 // Owned by ManagedMode (which is a singleton and outlives us). | 108 // Owned by ManagedMode (which is a singleton and outlives us). |
66 const ManagedModeURLFilter* url_filter_; | 109 const ManagedModeURLFilter* url_filter_; |
67 | 110 |
68 InfoBarDelegate* warn_infobar_delegate_; | 111 InfoBarDelegate* warn_infobar_delegate_; |
69 InfoBarDelegate* preview_infobar_delegate_; | 112 InfoBarDelegate* preview_infobar_delegate_; |
70 std::vector<GURL> navigated_urls_; | 113 |
71 bool after_interstitial_; | 114 ObserverState state_; |
115 std::set<GURL> navigated_urls_; | |
116 GURL last_url_; | |
72 | 117 |
73 int last_allowed_page_; | 118 int last_allowed_page_; |
74 | 119 |
75 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); | 120 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); |
76 }; | 121 }; |
77 | 122 |
78 #endif // CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 123 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
OLD | NEW |