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

Unified Diff: chrome/browser/managed_mode/managed_mode_navigation_observer.cc

Issue 12413028: Add elevation to the managed mode navigation observer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Automatically reset tab elevation when navigating the frame to a non-special URL. Created 7 years, 9 months 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.cc
diff --git a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
index af66cf33aa5be0f03abd13c420302de2ee808fe3..aa60fb311385085d20304f72c286bb8e6244f8da 100644
--- a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
+++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
@@ -263,10 +263,13 @@ ManagedModeNavigationObserver::ManagedModeNavigationObserver(
preview_infobar_delegate_(NULL),
got_user_gesture_(false),
state_(RECORDING_URLS_BEFORE_PREVIEW),
+ is_elevated_(false),
last_allowed_page_(-1) {
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
+ if (!managed_user_service_->ProfileIsManaged())
+ is_elevated_ = true;
url_filter_ = managed_user_service_->GetURLFilterForUIThread();
}
@@ -341,6 +344,14 @@ void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() {
ClearObserverState();
}
+bool ManagedModeNavigationObserver::is_elevated() const {
+ return is_elevated_;
+}
+
+void ManagedModeNavigationObserver::set_elevated(bool is_elevated) {
+ is_elevated_ = is_elevated;
+}
+
void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) {
navigated_urls_.insert(url);
last_url_ = url;
@@ -355,6 +366,31 @@ bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost(
return last_url_.host() == url.host();
}
+namespace {
+const char kChromeWebstoreURL[] = "chrome.google.com/webstore/";
Bernhard Bauer 2013/03/21 15:52:58 1. Move constant declarations to the top of the fi
Adrian Kuegel 2013/03/21 16:30:04 1. Done 2. Still some reviewers (for example Joche
Bernhard Bauer 2013/03/22 09:24:28 Meh. My take on this: if there is nothing else tha
Adrian Kuegel 2013/03/22 09:46:21 Ok, I am using this constant now.
+}
+
+bool ManagedModeNavigationObserver::WillStayElevatedForURL(
+ const GURL& navigation_url) {
+ // chrome:// URLs have chrome as a host type in the GURL. But all
+ // chrome URLs in url_constants.h are specified with a chrome:// prefix.
+ // Therefore we insert a ":/" between host and path for the chrome:// URLs.
+ std::string url =
+ navigation_url.host() +
+ (navigation_url.host() == "chrome" ? ":/" : "") +
+ navigation_url.path();
Bernhard Bauer 2013/03/21 15:52:58 Sorry, I don't understand this. I'm also thinking
Adrian Kuegel 2013/03/21 16:30:04 True, I can use the host. Thanks for the tip :)
+
+ // Check if any of the special urls is a prefix of url. This is the case if
+ // the special url occurs at position 0 as a substring of url.
Bernhard Bauer 2013/03/21 15:52:58 base/string_util.h declares StartsWith() methods.
Adrian Kuegel 2013/03/21 16:30:04 Ok, I used that instead. It is probably easier to
+ return url.find(kChromeWebstoreURL) == 0 ||
+ url.find(chrome::kChromeUIHistoryURL) == 0 ||
+ url.find(chrome::kChromeUIHistoryFrameURL) == 0 ||
Bernhard Bauer 2013/03/21 15:52:58 If we only call this method for main frames, why d
Adrian Kuegel 2013/03/21 16:30:04 A user could enter the subframe URL manually. But
+ url.find(chrome::kChromeUIExtensionsURL) == 0 ||
+ url.find(chrome::kChromeUIExtensionsFrameURL) == 0 ||
+ url.find(chrome::kChromeUISettingsURL) == 0 ||
+ url.find(chrome::kChromeUISettingsFrameURL) == 0;
+}
+
void ManagedModeNavigationObserver::ClearObserverState() {
if (preview_infobar_delegate_) {
InfoBarService* infobar_service =
@@ -387,6 +423,8 @@ void ManagedModeNavigationObserver::NavigateToPendingEntry(
void ManagedModeNavigationObserver::DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) {
+ if (!WillStayElevatedForURL(params.url))
+ is_elevated_ = false;
content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation"));
@@ -438,13 +476,14 @@ void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame(
bool is_error_page,
bool is_iframe_srcdoc,
content::RenderViewHost* render_view_host) {
- if (!is_main_frame)
- return;
}
void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl(
const GURL& url,
content::RenderViewHost* render_view_host) {
+ if (!WillStayElevatedForURL(url))
Bernhard Bauer 2013/03/21 15:52:58 Do we actually need both of these checks?
Adrian Kuegel 2013/03/21 16:30:04 Yes. There are two cases: we do a real navigation,
+ is_elevated_ = false;
+
// This function is the last one to be called before the resource throttle
// shows the interstitial if the URL must be blocked.
DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec();

Powered by Google App Engine
This is Rietveld 408576698