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 "content/public/browser/web_contents_observer.h" | 8 #include "content/public/browser/web_contents_observer.h" |
9 #include "content/public/browser/web_contents_user_data.h" | 9 #include "content/public/browser/web_contents_user_data.h" |
10 | 10 |
11 class InfoBarDelegate; | 11 class InfoBarDelegate; |
12 class ManagedModeURLFilter; | 12 class ManagedModeURLFilter; |
13 | 13 |
14 class ManagedModeNavigationObserver | 14 class ManagedModeNavigationObserver |
15 : public content::WebContentsObserver, | 15 : public content::WebContentsObserver, |
16 public content::WebContentsUserData<ManagedModeNavigationObserver> { | 16 public content::WebContentsUserData<ManagedModeNavigationObserver> { |
17 public: | 17 public: |
18 virtual ~ManagedModeNavigationObserver(); | 18 virtual ~ManagedModeNavigationObserver(); |
19 | 19 |
20 // The resource throttle contains an observer:hostname map to check when | |
21 // deciding whether to show an interstitial or not. These functions | |
22 // add/remove the current observer to/from that map. | |
23 void AddObserverOnIOThread(); | |
24 void RemoveObserverOnIOThread(); | |
25 | |
26 // Sets the specific infobar as dismissed. | |
20 void WarnInfobarDismissed(); | 27 void WarnInfobarDismissed(); |
21 void PreviewInfobarDismissed(); | 28 void PreviewInfobarDismissed(); |
22 | 29 |
30 // Dismisses an infobar without user action on the infobar itself. | |
Bernhard Bauer
2012/11/26 16:06:30
"Dismiss" means a user action (clicking on the lit
Sergiu
2012/11/27 15:37:34
You were right, it's pretty unsafe to have it set
| |
31 void DismissInfobar(InfoBarDelegate** dismissed_infobar_delegate); | |
32 | |
23 // Adds the url to the list of navigated URLs if it was not already there. | 33 // Adds the url to the list of navigated URLs if it was not already there. |
24 void AddNavigatedURL(const GURL& url); | 34 void SaveNavigatedURL(const GURL& url); |
Bernhard Bauer
2012/11/26 16:06:30
This method could be private?
Sergiu
2012/11/27 15:37:34
Made private.
| |
25 | 35 |
26 // For the list of URLs that were navigated since the last Observer | 36 // Whitelist exact URLs for redirects and host patterns for the final URL. |
27 // instantiation: | 37 // If the URL uses HTTPS whitelist only the host on HTTPS. |
28 // * add the first N-1 to the whitelist such that only those URLs are | 38 void AddSavedURLsToWhitelist(); |
29 // allowed and not more general versions of them. | 39 |
30 // * add only the host part of the last URL so that it allows all | 40 // Marks/clears the current interstitial state. |
Bernhard Bauer
2012/11/26 16:06:30
I would like for this class not to know about inte
Sergiu
2012/11/27 15:37:34
Refactored the two variables after_interstitial an
| |
31 // pages on that domain. If it's HTTPS do the same but only on the HTTPS | 41 void MarkShownInterstitial(); |
32 // protocol. | 42 void ClearShownInterstitial(); |
33 void AddURLList(); | 43 |
44 // Clears the state recorded in relation with a shown interstitial. | |
45 void ClearInterstitialState(); | |
34 | 46 |
35 private: | 47 private: |
36 friend class WebContentsUserData<ManagedModeNavigationObserver>; | 48 friend class WebContentsUserData<ManagedModeNavigationObserver>; |
37 | 49 |
38 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); | 50 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); |
39 | 51 |
40 // content::WebContentsObserver implementation. | 52 // content::WebContentsObserver implementation. |
53 // An example regarding the order in which these event take place for | |
Bernhard Bauer
2012/11/26 16:06:30
Nit: "events"
Sergiu
2012/11/27 15:37:34
Done.
| |
54 // google.com in our case is as follows: | |
55 // 1. User types in google.com and clicks enter. | |
56 // -> NavigateToPendingEntry: http://google.com | |
57 // -> DidStartProvisionalLoadForFrame http://google.com | |
58 // -> ProvisionalChangeToMainFrameUrl http://google.com | |
59 // 2. Interstitial is shown to the user. User clicks "Preview". | |
60 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) | |
61 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) | |
62 // -> DidNavigateMainFrame http://www.google.com | |
63 // 3. Page is shown. | |
41 virtual void NavigateToPendingEntry( | 64 virtual void NavigateToPendingEntry( |
42 const GURL& url, | 65 const GURL& url, |
43 content::NavigationController::ReloadType reload_type) OVERRIDE; | 66 content::NavigationController::ReloadType reload_type) OVERRIDE; |
44 virtual void DidNavigateMainFrame( | 67 virtual void DidNavigateMainFrame( |
45 const content::LoadCommittedDetails& details, | 68 const content::LoadCommittedDetails& details, |
46 const content::FrameNavigateParams& params) OVERRIDE; | 69 const content::FrameNavigateParams& params) OVERRIDE; |
47 virtual void DidStartProvisionalLoadForFrame( | 70 virtual void DidStartProvisionalLoadForFrame( |
48 int64 frame_id, | 71 int64 frame_id, |
49 int64 parent_frame_id, | 72 int64 parent_frame_id, |
50 bool is_main_frame, | 73 bool is_main_frame, |
(...skipping 11 matching lines...) Expand all Loading... | |
62 content::PageTransition transition_type, | 85 content::PageTransition transition_type, |
63 content::RenderViewHost* render_view_host) OVERRIDE; | 86 content::RenderViewHost* render_view_host) OVERRIDE; |
64 | 87 |
65 // Owned by ManagedMode (which is a singleton and outlives us). | 88 // Owned by ManagedMode (which is a singleton and outlives us). |
66 const ManagedModeURLFilter* url_filter_; | 89 const ManagedModeURLFilter* url_filter_; |
67 | 90 |
68 InfoBarDelegate* warn_infobar_delegate_; | 91 InfoBarDelegate* warn_infobar_delegate_; |
69 InfoBarDelegate* preview_infobar_delegate_; | 92 InfoBarDelegate* preview_infobar_delegate_; |
70 std::vector<GURL> navigated_urls_; | 93 std::vector<GURL> navigated_urls_; |
71 bool after_interstitial_; | 94 bool after_interstitial_; |
95 bool redirects_completed_; | |
Bernhard Bauer
2012/11/26 16:06:30
I think we should have an explicit state enum here
Sergiu
2012/11/27 15:37:34
Done.
| |
72 | 96 |
73 int last_allowed_page_; | 97 int last_allowed_page_; |
74 | 98 |
75 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); | 99 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); |
76 }; | 100 }; |
77 | 101 |
78 #endif // CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 102 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
OLD | NEW |