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

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

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

Powered by Google App Engine
This is Rietveld 408576698