Commit 61f5da28 authored by bauerb@chromium.org's avatar bauerb@chromium.org

Watch for filtering pref changes in ManagedModeInterstitial and unblock...

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
parent 3e4a35f4
...@@ -238,4 +238,36 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, ...@@ -238,4 +238,36 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
EXPECT_FALSE(results[1].blocked_visit()); 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 } // namespace
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "grit/browser_resources.h" #include "grit/browser_resources.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
...@@ -34,13 +33,37 @@ ManagedModeInterstitial::ManagedModeInterstitial( ...@@ -34,13 +33,37 @@ ManagedModeInterstitial::ManagedModeInterstitial(
const GURL& url, const GURL& url,
const base::Callback<void(bool)>& callback) const base::Callback<void(bool)>& callback)
: web_contents_(web_contents), : web_contents_(web_contents),
interstitial_page_(NULL),
url_(url), url_(url),
weak_ptr_factory_(this),
callback_(callback) { 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* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext()); 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_ = interstitial_page_ =
content::InterstitialPage::Create(web_contents, true, url_, this); content::InterstitialPage::Create(web_contents, true, url_, this);
interstitial_page_->Show(); interstitial_page_->Show();
...@@ -125,12 +148,33 @@ void ManagedModeInterstitial::CommandReceived(const std::string& command) { ...@@ -125,12 +148,33 @@ void ManagedModeInterstitial::CommandReceived(const std::string& command) {
NOTREACHED(); 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() { void ManagedModeInterstitial::OnDontProceed() {
DispatchContinueRequest(false); 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) { void ManagedModeInterstitial::DispatchContinueRequest(bool continue_request) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request)); BrowserThread::IO, FROM_HERE, base::Bind(callback_, continue_request));
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/compiler_specific.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 "content/public/browser/interstitial_page_delegate.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -35,6 +35,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate { ...@@ -35,6 +35,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate {
virtual void OnProceed() OVERRIDE; virtual void OnProceed() OVERRIDE;
virtual void OnDontProceed() 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); void DispatchContinueRequest(bool continue_request);
// Owns the interstitial, which owns us. // Owns the interstitial, which owns us.
...@@ -42,11 +48,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate { ...@@ -42,11 +48,12 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate {
content::InterstitialPage* interstitial_page_; // Owns us. content::InterstitialPage* interstitial_page_; // Owns us.
PrefChangeRegistrar pref_change_registrar_;
// The UI language. Used for formatting the URL for display. // The UI language. Used for formatting the URL for display.
std::string languages_; std::string languages_;
GURL url_; GURL url_;
base::WeakPtrFactory<ManagedModeInterstitial> weak_ptr_factory_;
base::Callback<void(bool)> callback_; base::Callback<void(bool)> callback_;
DISALLOW_COPY_AND_ASSIGN(ManagedModeInterstitial); DISALLOW_COPY_AND_ASSIGN(ManagedModeInterstitial);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment