summaryrefslogtreecommitdiffstats
path: root/chrome/browser/managed_mode
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-05 15:52:10 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-05 15:52:10 +0000
commit61f5da28ec237ed822bbb26c3a3264c2af8cefe1 (patch)
tree70789783e7b8a74c3dc35a2403273e991f735be7 /chrome/browser/managed_mode
parent3e4a35f4304e19dbe0b8afccdb8e67dbe2121e6a (diff)
downloadchromium_src-61f5da28ec237ed822bbb26c3a3264c2af8cefe1.zip
chromium_src-61f5da28ec237ed822bbb26c3a3264c2af8cefe1.tar.gz
chromium_src-61f5da28ec237ed822bbb26c3a3264c2af8cefe1.tar.bz2
Watch for filtering pref changes in ManagedModeInterstitial and unblock requests if they become allowed.
BUG=283379 Review URL: https://chromiumcodereview.appspot.com/23533014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/managed_mode')
-rw-r--r--chrome/browser/managed_mode/managed_mode_browsertest.cc32
-rw-r--r--chrome/browser/managed_mode/managed_mode_interstitial.cc54
-rw-r--r--chrome/browser/managed_mode/managed_mode_interstitial.h11
3 files changed, 90 insertions, 7 deletions
diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc
index 7199ee5..ab7488d 100644
--- a/chrome/browser/managed_mode/managed_mode_browsertest.cc
+++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc
@@ -238,4 +238,36 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
EXPECT_FALSE(results[1].blocked_visit());
}
+IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, Unblock) {
+ GURL test_url("http://www.example.com/files/simple.html");
+ ui_test_utils::NavigateToURL(browser(), test_url);
+
+ WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+
+ CheckShownPageIsInterstitial(web_contents);
+
+ content::WindowedNotificationObserver observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::NotificationService::AllSources());
+
+ // Set the host as allowed.
+ scoped_ptr<DictionaryValue> dict(new DictionaryValue);
+ dict->SetBooleanWithoutPathExpansion(test_url.host(), true);
+ policy::ProfilePolicyConnector* connector =
+ policy::ProfilePolicyConnectorFactory::GetForProfile(
+ browser()->profile());
+ policy::ManagedModePolicyProvider* policy_provider =
+ connector->managed_mode_policy_provider();
+ policy_provider->SetLocalPolicyForTesting(
+ policy::key::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(
+ ManagedUserService::MANUAL_ALLOW,
+ managed_user_service_->GetManualBehaviorForHost(test_url.host()));
+
+ observer.Wait();
+ EXPECT_EQ(test_url, web_contents->GetURL());
+}
+
} // namespace
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc
index b3daecc..afd06fa 100644
--- a/chrome/browser/managed_mode/managed_mode_interstitial.cc
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc
@@ -17,7 +17,6 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_ui.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
@@ -34,13 +33,37 @@ ManagedModeInterstitial::ManagedModeInterstitial(
const GURL& url,
const base::Callback<void(bool)>& callback)
: web_contents_(web_contents),
+ interstitial_page_(NULL),
url_(url),
- weak_ptr_factory_(this),
callback_(callback) {
+ if (ShouldProceed()) {
+ // It can happen that the site was only allowed very recently and the URL
+ // filter on the IO thread had not been updated yet. Proceed with the
+ // request without showing the interstitial.
+ DispatchContinueRequest(true);
+ delete this;
+ return;
+ }
+
+ // TODO(bauerb): Extract an observer callback on ManagedUserService for this.
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
- languages_ = profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
-
+ PrefService* prefs = profile->GetPrefs();
+ pref_change_registrar_.Init(prefs);
+ pref_change_registrar_.Add(
+ prefs::kDefaultManagedModeFilteringBehavior,
+ base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged,
+ base::Unretained(this)));
+ pref_change_registrar_.Add(
+ prefs::kManagedModeManualHosts,
+ base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged,
+ base::Unretained(this)));
+ pref_change_registrar_.Add(
+ prefs::kManagedModeManualURLs,
+ base::Bind(&ManagedModeInterstitial::OnFilteringPrefsChanged,
+ base::Unretained(this)));
+
+ languages_ = prefs->GetString(prefs::kAcceptLanguages);
interstitial_page_ =
content::InterstitialPage::Create(web_contents, true, url_, this);
interstitial_page_->Show();
@@ -125,12 +148,33 @@ void ManagedModeInterstitial::CommandReceived(const std::string& command) {
NOTREACHED();
}
-void ManagedModeInterstitial::OnProceed() { NOTREACHED(); }
+void ManagedModeInterstitial::OnProceed() {
+ // CHECK instead of DCHECK as defense in depth in case we'd accidentally
+ // proceed on a blocked page.
+ CHECK(ShouldProceed());
+ DispatchContinueRequest(true);
+}
void ManagedModeInterstitial::OnDontProceed() {
DispatchContinueRequest(false);
}
+bool ManagedModeInterstitial::ShouldProceed() {
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext());
+ ManagedUserService* managed_user_service =
+ ManagedUserServiceFactory::GetForProfile(profile);
+ ManagedModeURLFilter* url_filter =
+ managed_user_service->GetURLFilterForUIThread();
+ return url_filter->GetFilteringBehaviorForURL(url_) !=
+ ManagedModeURLFilter::BLOCK;
+}
+
+void ManagedModeInterstitial::OnFilteringPrefsChanged() {
+ if (ShouldProceed())
+ interstitial_page_->Proceed();
+}
+
void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.h b/chrome/browser/managed_mode/managed_mode_interstitial.h
index 656727c..06027d6 100644
--- a/chrome/browser/managed_mode/managed_mode_interstitial.h
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.h
@@ -9,7 +9,7 @@
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "base/memory/weak_ptr.h"
+#include "base/prefs/pref_change_registrar.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "url/gurl.h"
@@ -35,6 +35,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate {
virtual void OnProceed() OVERRIDE;
virtual void OnDontProceed() OVERRIDE;
+ // Returns whether the blocked URL is now allowed. Called initially before the
+ // interstitial is shown (to catch race conditions), or when the URL filtering
+ // prefs change.
+ bool ShouldProceed();
+
+ void OnFilteringPrefsChanged();
void DispatchContinueRequest(bool continue_request);
// Owns the interstitial, which owns us.
@@ -42,11 +48,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate {
content::InterstitialPage* interstitial_page_; // Owns us.
+ PrefChangeRegistrar pref_change_registrar_;
+
// The UI language. Used for formatting the URL for display.
std::string languages_;
GURL url_;
- base::WeakPtrFactory<ManagedModeInterstitial> weak_ptr_factory_;
base::Callback<void(bool)> callback_;
DISALLOW_COPY_AND_ASSIGN(ManagedModeInterstitial);