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

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: Address review comments. 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..ee0dbfd54421e99bd69cf9601d65d23a42d95079 100644
--- a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
+++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
@@ -8,6 +8,7 @@
#include "base/i18n/rtl.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
+#include "base/string_util.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/infobars/infobar_service.h"
@@ -43,6 +44,8 @@ using content::UserMetricsAction;
namespace {
+const char kChromeWebstoreURL[] = "chrome.google.com/webstore/";
+
// For use in histograms.
enum PreviewInfobarCommand {
INFOBAR_ACCEPT,
@@ -263,10 +266,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 +347,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 +369,28 @@ bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost(
return last_url_.host() == url.host();
}
+namespace {
+}
+
+bool ManagedModeNavigationObserver::ShouldStayElevatedForURL(
+ 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.spec();
+ if (navigation_url.host() == "chrome") {
+ // The path contains the actual host name, but starts with a "/". Remove
+ // the "/".
+ url = navigation_url.path().substr(1);
+ }
+
+ // Check if any of the special urls is a prefix of url.
Bernhard Bauer 2013/03/22 09:24:28 Nit: it's "URL" (plural URLs) if you talk about an
Adrian Kuegel 2013/03/22 09:46:21 Done.
+ return StartsWithASCII(url, chrome::kChromeUIHistoryHost, false) ||
+ StartsWithASCII(url, chrome::kChromeUIExtensionsHost, false) ||
Bernhard Bauer 2013/03/22 09:24:28 Nit: Might be nicer to align these?
Adrian Kuegel 2013/03/22 09:46:21 Done.
+ StartsWithASCII(url, chrome::kChromeUISettingsHost, false) ||
+ StartsWithASCII(url, kChromeWebstoreURL, false);
+}
+
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 (!ShouldStayElevatedForURL(params.url))
+ is_elevated_ = false;
content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation"));
@@ -430,21 +468,12 @@ void ManagedModeNavigationObserver::DidNavigateMainFrame(
got_user_gesture_ = false;
}
-void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame(
- int64 frame_id,
- int64 parent_frame_id,
- bool is_main_frame,
- const GURL& validated_url,
- 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 (!ShouldStayElevatedForURL(url))
+ 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();
« no previous file with comments | « chrome/browser/managed_mode/managed_mode_navigation_observer.h ('k') | chrome/browser/managed_mode/managed_user_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698