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

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: Split navigated_urls in two and refactor. 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 // Clears the state recorded in the observer.
27 // instantiation: 29 void ClearObserverState();
28 // * add the first N-1 to the whitelist such that only those URLs are 30
29 // allowed and not more general versions of them. 31 // 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 32 // 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 33 void AddSavedURLsToWhitelist();
32 // protocol.
33 void AddURLList();
34 34
35 private: 35 private:
36 // An observer can be in one of the following states:
37 // - RECORDING_URLS_BEFORE_PREVIEW: This is the initial state when the user
38 // navigates to a new page. In this state the navigated URLs that should be
39 // blocked are recorded. The Observer moves to the next state when an
40 // interstitial was shown and the user clicked "Preview" on the interstitial.
41 // - RECORDING_URLS_AFTER_PREVIEW: URLs that should be blocked are
42 // still recorded while the page redirect. The Observer moves to the next
43 // state after the page finished redirecting (DidNavigateMainFrame gets
44 // called).
45 // - NOT_RECORDING_URLS: The redirects have completed and blocked URLs are
46 // no longer being recorded.
47 enum ObserverState {
48 RECORDING_URLS_BEFORE_PREVIEW,
49 RECORDING_URLS_AFTER_PREVIEW,
50 NOT_RECORDING_URLS,
51 };
52
36 friend class WebContentsUserData<ManagedModeNavigationObserver>; 53 friend class WebContentsUserData<ManagedModeNavigationObserver>;
37 54
38 explicit ManagedModeNavigationObserver(content::WebContents* web_contents); 55 explicit ManagedModeNavigationObserver(content::WebContents* web_contents);
39 56
57 // Adding the temporary exception stops the ResourceThrottle from showing
58 // an interstitial for this RenderView.
59 void AddTemporaryException();
60 void RemoveTemporaryException();
61
62 void AddURLToPatternList(const GURL& url);
63 void AddURLAsLastPattern(const GURL& url);
64
40 // content::WebContentsObserver implementation. 65 // content::WebContentsObserver implementation.
66 // An example regarding the order in which these events take place for
67 // google.com in our case is as follows:
68 // 1. User types in google.com and clicks enter.
69 // -> NavigateToPendingEntry: http://google.com
70 // -> DidStartProvisionalLoadForFrame http://google.com
71 // -> ProvisionalChangeToMainFrameUrl http://google.com
72 // 2. Interstitial is shown to the user. User clicks "Preview".
73 // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect)
74 // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect)
75 // -> DidNavigateMainFrame http://www.google.com
76 // 3. Page is shown.
41 virtual void NavigateToPendingEntry( 77 virtual void NavigateToPendingEntry(
42 const GURL& url, 78 const GURL& url,
43 content::NavigationController::ReloadType reload_type) OVERRIDE; 79 content::NavigationController::ReloadType reload_type) OVERRIDE;
44 virtual void DidNavigateMainFrame( 80 virtual void DidNavigateMainFrame(
45 const content::LoadCommittedDetails& details, 81 const content::LoadCommittedDetails& details,
46 const content::FrameNavigateParams& params) OVERRIDE; 82 const content::FrameNavigateParams& params) OVERRIDE;
47 virtual void DidStartProvisionalLoadForFrame( 83 virtual void DidStartProvisionalLoadForFrame(
48 int64 frame_id, 84 int64 frame_id,
49 int64 parent_frame_id, 85 int64 parent_frame_id,
50 bool is_main_frame, 86 bool is_main_frame,
51 const GURL& url, 87 const GURL& url,
52 bool is_error_page, 88 bool is_error_page,
53 content::RenderViewHost* render_view_host) OVERRIDE; 89 content::RenderViewHost* render_view_host) OVERRIDE;
54 virtual void ProvisionalChangeToMainFrameUrl( 90 virtual void ProvisionalChangeToMainFrameUrl(
55 const GURL& url, 91 const GURL& url,
56 const GURL& opener_url, 92 const GURL& opener_url,
57 content::RenderViewHost* render_view_host) OVERRIDE; 93 content::RenderViewHost* render_view_host) OVERRIDE;
58 virtual void DidCommitProvisionalLoadForFrame( 94 virtual void DidCommitProvisionalLoadForFrame(
59 int64 frame_id, 95 int64 frame_id,
60 bool is_main_frame, 96 bool is_main_frame,
61 const GURL& url, 97 const GURL& url,
62 content::PageTransition transition_type, 98 content::PageTransition transition_type,
63 content::RenderViewHost* render_view_host) OVERRIDE; 99 content::RenderViewHost* render_view_host) OVERRIDE;
64 100
65 // Owned by ManagedMode (which is a singleton and outlives us). 101 // Owned by ManagedMode (which is a singleton and outlives us).
66 const ManagedModeURLFilter* url_filter_; 102 const ManagedModeURLFilter* url_filter_;
67 103
68 InfoBarDelegate* warn_infobar_delegate_; 104 InfoBarDelegate* warn_infobar_delegate_;
69 InfoBarDelegate* preview_infobar_delegate_; 105 InfoBarDelegate* preview_infobar_delegate_;
70 std::vector<GURL> navigated_urls_; 106
71 bool after_interstitial_; 107 ObserverState state_;
108 base::ListValue url_patterns_;
109 std::string last_url_pattern_;
72 110
73 int last_allowed_page_; 111 int last_allowed_page_;
74 112
75 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver); 113 DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver);
76 }; 114 };
77 115
78 #endif // CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_ 116 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698