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

Unified 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: Moving ifs to switch. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/managed_mode/managed_mode_navigation_observer.h
diff --git a/chrome/browser/managed_mode/managed_mode_navigation_observer.h b/chrome/browser/managed_mode/managed_mode_navigation_observer.h
index 8ac23a817f41bd3865582df722ccf7c04e8f6203..c4d4edc2aa7380c152fa83871a0914b624bfab8f 100644
--- a/chrome/browser/managed_mode/managed_mode_navigation_observer.h
+++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.h
@@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_
-#define CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_
+#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_
+#define CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_
+#include <set>
+
+#include "base/values.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
@@ -17,27 +20,67 @@ class ManagedModeNavigationObserver
public:
virtual ~ManagedModeNavigationObserver();
+ // Sets the specific infobar as dismissed.
void WarnInfobarDismissed();
void PreviewInfobarDismissed();
- // Adds the url to the list of navigated URLs if it was not already there.
- void AddNavigatedURL(const GURL& url);
+ // Sets the state of the Observer from the outside.
+ void SetStateToRecordingAfterPreview();
+
+ // Returns whether the user should be allowed to navigate to this URL after
+ // he has clicked "Preview" on the interstitial.
+ bool CanTemporarilyNavigateHost(const GURL& url);
- // For the list of URLs that were navigated since the last Observer
- // instantiation:
- // * add the first N-1 to the whitelist such that only those URLs are
- // allowed and not more general versions of them.
- // * add only the host part of the last URL so that it allows all
- // pages on that domain. If it's HTTPS do the same but only on the HTTPS
- // protocol.
- void AddURLList();
+ // Clears the state recorded in the observer.
+ void ClearObserverState();
+
+ // Whitelist exact URLs for redirects and host patterns for the final URL.
+ // If the URL uses HTTPS whitelist only the host on HTTPS. Clears the
+ // observer state after adding the URLs.
+ void AddSavedURLsToWhitelistAndClearState();
private:
+ // An observer can be in one of the following states:
+ // - RECORDING_URLS_BEFORE_PREVIEW: This is the initial state when the user
+ // navigates to a new page. In this state the navigated URLs that should be
+ // blocked are recorded. The Observer moves to the next state when an
+ // interstitial was shown and the user clicked "Preview" on the interstitial.
+ // - RECORDING_URLS_AFTER_PREVIEW: URLs that should be blocked are
+ // still recorded while the page redirect. The Observer moves to the next
+ // state after the page finished redirecting (DidNavigateMainFrame gets
+ // called).
+ // - NOT_RECORDING_URLS: The redirects have completed and blocked URLs are
+ // no longer being recorded.
+ enum ObserverState {
+ RECORDING_URLS_BEFORE_PREVIEW,
+ RECORDING_URLS_AFTER_PREVIEW,
+ NOT_RECORDING_URLS,
+ };
+
friend class WebContentsUserData<ManagedModeNavigationObserver>;
explicit ManagedModeNavigationObserver(content::WebContents* web_contents);
+ // Adding the temporary exception stops the ResourceThrottle from showing
+ // an interstitial for this RenderView.
+ void AddTemporaryException();
+ void RemoveTemporaryException();
+
+ void AddURLToPatternList(const GURL& url);
+ void AddURLAsLastPattern(const GURL& url);
+
// content::WebContentsObserver implementation.
+ // An example regarding the order in which these events take place for
+ // google.com in our case is as follows:
+ // 1. User types in google.com and clicks enter.
+ // -> NavigateToPendingEntry: http://google.com
+ // -> DidStartProvisionalLoadForFrame http://google.com
+ // -> ProvisionalChangeToMainFrameUrl http://google.com
+ // 2. Interstitial is shown to the user. User clicks "Preview".
+ // -> ProvisionalChangeToMainFrameUrl http://www.google.com (redirect)
+ // -> DidCommitProvisionalLoadForFrame http://www.google.com (redirect)
+ // -> DidNavigateMainFrame http://www.google.com
+ // 3. Page is shown.
virtual void NavigateToPendingEntry(
const GURL& url,
content::NavigationController::ReloadType reload_type) OVERRIDE;
@@ -67,12 +110,14 @@ class ManagedModeNavigationObserver
InfoBarDelegate* warn_infobar_delegate_;
InfoBarDelegate* preview_infobar_delegate_;
- std::vector<GURL> navigated_urls_;
- bool after_interstitial_;
+
+ ObserverState state_;
+ std::set<GURL> navigated_urls_;
+ GURL last_url_;
int last_allowed_page_;
DISALLOW_COPY_AND_ASSIGN(ManagedModeNavigationObserver);
};
-#endif // CHROME_BROWSER_MANAGED_MODE_NAVIGATION_OBSERVER_H_
+#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_MODE_NAVIGATION_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698