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_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. | |
|
Bernhard Bauer
2012/11/27 18:44:46
The map is from RenderView to hostname, not from o
Sergiu
2012/11/28 12:53:25
Done.
| |
| 23 void AddTemporaryException(); | |
|
Bernhard Bauer
2012/11/27 18:44:46
Can you make these methods private?
Sergiu
2012/11/28 12:53:25
Done.
| |
| 24 void RemoveTemporaryException(); | |
| 25 | |
| 26 // Sets the specific infobar as dismissed. | |
| 20 void WarnInfobarDismissed(); | 27 void WarnInfobarDismissed(); |
| 21 void PreviewInfobarDismissed(); | 28 void PreviewInfobarDismissed(); |
| 22 | 29 |
| 23 // Adds the url to the list of navigated URLs if it was not already there. | 30 // Sets the state of the Observer from the outside. |
| 24 void AddNavigatedURL(const GURL& url); | 31 void SetStateToRecordingAfterPreview(); |
| 25 | 32 |
| 26 // For the list of URLs that were navigated since the last Observer | 33 // Clears the state recorded in the observer. |
| 27 // instantiation: | 34 void ClearObserverState(); |
| 28 // * add the first N-1 to the whitelist such that only those URLs are | 35 |
| 29 // allowed and not more general versions of them. | 36 // Whitelist exact URLs for redirects and host patterns for the final URL. |
| 30 // * add only the host part of the last URL so that it allows all | 37 // If the URL uses HTTPS whitelist only the host on HTTPS. |
| 31 // pages on that domain. If it's HTTPS do the same but only on the HTTPS | 38 void AddSavedURLsToWhitelist(); |
| 32 // protocol. | |
| 33 void AddURLList(); | |
| 34 | 39 |
| 35 private: | 40 private: |
| 36 friend class WebContentsUserData<ManagedModeNavigationObserver>; | 41 friend class WebContentsUserData<ManagedModeNavigationObserver>; |
| 37 | 42 |
| 38 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); | 43 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); |
| 39 | 44 |
| 45 // Adds the url to the list of navigated URLs if it was not already there. | |
| 46 void SaveNavigatedURL(const GURL& url); | |
| 47 | |
| 40 // content::WebContentsObserver implementation. | 48 // content::WebContentsObserver implementation. |
| 49 // An example regarding the order in which these events take place for | |
| 50 // google.com in our case is as follows: | |
| 51 // 1. User types in google.com and clicks enter. | |
| 52 // -> NavigateToPendingEntry: http://google.com | |
| 53 // -> DidStartProvisionalLoadForFrame http://google.com | |
| 54 // -> ProvisionalChangeToMainFrameUrl http://google.com | |
| 55 // 2. Interstitial is shown to the user. User clicks "Preview". | |
| 56 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect) | |
| 57 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect) | |
| 58 // -> DidNavigateMainFrame http://www.google.com | |
| 59 // 3. Page is shown. | |
| 41 virtual void NavigateToPendingEntry( | 60 virtual void NavigateToPendingEntry( |
| 42 const GURL& url, | 61 const GURL& url, |
| 43 content::NavigationController::ReloadType reload_type) OVERRIDE; | 62 content::NavigationController::ReloadType reload_type) OVERRIDE; |
| 44 virtual void DidNavigateMainFrame( | 63 virtual void DidNavigateMainFrame( |
| 45 const content::LoadCommittedDetails& details, | 64 const content::LoadCommittedDetails& details, |
| 46 const content::FrameNavigateParams& params) OVERRIDE; | 65 const content::FrameNavigateParams& params) OVERRIDE; |
| 47 virtual void DidStartProvisionalLoadForFrame( | 66 virtual void DidStartProvisionalLoadForFrame( |
| 48 int64 frame_id, | 67 int64 frame_id, |
| 49 int64 parent_frame_id, | 68 int64 parent_frame_id, |
| 50 bool is_main_frame, | 69 bool is_main_frame, |
| 51 const GURL& url, | 70 const GURL& url, |
| 52 bool is_error_page, | 71 bool is_error_page, |
| 53 content::RenderViewHost* render_view_host) OVERRIDE; | 72 content::RenderViewHost* render_view_host) OVERRIDE; |
| 54 virtual void ProvisionalChangeToMainFrameUrl( | 73 virtual void ProvisionalChangeToMainFrameUrl( |
| 55 const GURL& url, | 74 const GURL& url, |
| 56 const GURL& opener_url, | 75 const GURL& opener_url, |
| 57 content::RenderViewHost* render_view_host) OVERRIDE; | 76 content::RenderViewHost* render_view_host) OVERRIDE; |
| 58 virtual void DidCommitProvisionalLoadForFrame( | 77 virtual void DidCommitProvisionalLoadForFrame( |
| 59 int64 frame_id, | 78 int64 frame_id, |
| 60 bool is_main_frame, | 79 bool is_main_frame, |
| 61 const GURL& url, | 80 const GURL& url, |
| 62 content::PageTransition transition_type, | 81 content::PageTransition transition_type, |
| 63 content::RenderViewHost* render_view_host) OVERRIDE; | 82 content::RenderViewHost* render_view_host) OVERRIDE; |
| 64 | 83 |
| 65 // Owned by ManagedMode (which is a singleton and outlives us). | 84 // Owned by ManagedMode (which is a singleton and outlives us). |
| 66 const ManagedModeURLFilter* url_filter_; | 85 const ManagedModeURLFilter* url_filter_; |
| 67 | 86 |
| 87 enum ObserverState { | |
|
Bernhard Bauer
2012/11/27 18:44:46
Type declarations like enums come before methods.
Sergiu
2012/11/28 12:53:25
Done.
| |
| 88 RECORDING_URLS_BEFORE_PREVIEW, | |
|
Bernhard Bauer
2012/11/27 18:44:46
We should have some explanation for these states.
Sergiu
2012/11/28 12:53:25
I've commented the states near the definition, ple
| |
| 89 RECORDING_URLS_AFTER_PREVIEW, | |
| 90 NOT_RECORDING_URLS, | |
| 91 }; | |
| 92 | |
| 93 ObserverState state_; | |
|
Bernhard Bauer
2012/11/27 18:44:46
I think it would be nice if we could group state m
Sergiu
2012/11/28 12:53:25
Hopefully better now.
| |
| 94 | |
| 68 InfoBarDelegate* warn_infobar_delegate_; | 95 InfoBarDelegate* warn_infobar_delegate_; |
| 69 InfoBarDelegate* preview_infobar_delegate_; | 96 InfoBarDelegate* preview_infobar_delegate_; |
| 70 std::vector<GURL> navigated_urls_; | 97 std::vector<GURL> navigated_urls_; |
| 71 bool after_interstitial_; | |
| 72 | 98 |
| 73 int last_allowed_page_; | 99 int last_allowed_page_; |
| 74 | 100 |
| 75 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); | 101 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); |
| 76 }; | 102 }; |
| 77 | 103 |
| 78 #endif // CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_ | 104 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_ |
| OLD | NEW |