diff options
author | akuegel@chromium.org <akuegel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-21 00:47:32 +0000 |
---|---|---|
committer | akuegel@chromium.org <akuegel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-21 00:47:32 +0000 |
commit | bddf6153d15b02f44f1ff3a8795ca8639827cc0d (patch) | |
tree | 421658e0e42dab772388f60a2c2d8a1736db9274 | |
parent | 0e2f43b6a863a7e6f0840ca60e0f598d28e4e413 (diff) | |
download | chromium_src-bddf6153d15b02f44f1ff3a8795ca8639827cc0d.zip chromium_src-bddf6153d15b02f44f1ff3a8795ca8639827cc0d.tar.gz chromium_src-bddf6153d15b02f44f1ff3a8795ca8639827cc0d.tar.bz2 |
Require authentication when clicking the preview button on
the managed mode interstitial. Only when the user
successfully authenticates, the preview is shown. The
authentication is reset once the user does another
navigation.
BUG=171370
TEST=Manual,Browser Test
Review URL: https://chromiumcodereview.appspot.com/12330007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183683 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 54 insertions, 1 deletions
diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc index d26dafa..2f29c92 100644 --- a/chrome/browser/managed_mode/managed_mode_browsertest.cc +++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/managed_mode/managed_mode.h" +#include "chrome/browser/managed_mode/managed_mode_interstitial.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/prefs/pref_registry_syncable.h" @@ -17,6 +18,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/browser/ui/web_contents_modal_dialog_manager.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" @@ -524,3 +526,28 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, managed_user_service_->GetManualBehaviorForHost( "www.new-example.com")); } + +// Now check that the passphrase dialog is shown when a passphrase is specified +// and the user clicks on the preview button. +IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, + PreviewAuthenticationRequired) { + // Set a passphrase. + PrefService* pref_service = browser()->profile()->GetPrefs(); + pref_service->SetString(prefs::kManagedModeLocalPassphrase, "test"); + + // Navigate to an URL which should be blocked. + GURL test_url("http://www.example.com/files/simple.html"); + ui_test_utils::NavigateToURL(browser(), test_url); + WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); + InterstitialPage* interstitial_page = tab->GetInterstitialPage(); + + // Get the ManagedModeInterstitial delegate. + content::InterstitialPageDelegate* delegate = + interstitial_page->GetDelegateForTesting(); + + // Simulate the click on the "preview" button. + delegate->CommandReceived("\"preview\""); + WebContentsModalDialogManager* web_contents_modal_dialog_manager = + WebContentsModalDialogManager::FromWebContents(tab); + EXPECT_TRUE(web_contents_modal_dialog_manager->IsShowingDialog()); +} diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc index e585274..322e67f 100644 --- a/chrome/browser/managed_mode/managed_mode_interstitial.cc +++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc @@ -8,8 +8,11 @@ #include "base/metrics/histogram.h" #include "base/prefs/pref_service.h" #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" +#include "chrome/browser/managed_mode/managed_user_service.h" +#include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_util.h" +#include "chrome/browser/ui/webui/managed_user_passphrase_dialog.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" @@ -69,6 +72,7 @@ ManagedModeInterstitial::ManagedModeInterstitial( const base::Callback<void(bool)>& callback) : web_contents_(web_contents), url_(url), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), callback_(callback) { Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); @@ -129,7 +133,19 @@ void ManagedModeInterstitial::CommandReceived(const std::string& command) { UMA_HISTOGRAM_ENUMERATION("ManagedMode.BlockingInterstitialCommand", PREVIEW, HISTOGRAM_BOUNDING_VALUE); - interstitial_page_->Proceed(); + Profile* profile = + Profile::FromBrowserContext(web_contents_->GetBrowserContext()); + ManagedUserService* service = + ManagedUserServiceFactory::GetForProfile(profile); + if (service->IsElevated()) { + OnAuthorizationResult(true); + return; + } + // Will be deleted automatically when the dialog is closed. + new ManagedUserPassphraseDialog( + web_contents_, + base::Bind(&ManagedModeInterstitial::OnAuthorizationResult, + weak_ptr_factory_.GetWeakPtr())); return; } @@ -160,6 +176,11 @@ void ManagedModeInterstitial::OnDontProceed() { DispatchContinueRequest(false); } +void ManagedModeInterstitial::OnAuthorizationResult(bool success) { + if (success) + 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 887f1f7..98aeaef 100644 --- a/chrome/browser/managed_mode/managed_mode_interstitial.h +++ b/chrome/browser/managed_mode/managed_mode_interstitial.h @@ -9,6 +9,7 @@ #include "base/callback.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" #include "content/public/browser/interstitial_page_delegate.h" #include "googleurl/src/gurl.h" @@ -46,6 +47,9 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate { virtual void OnProceed() OVERRIDE; virtual void OnDontProceed() OVERRIDE; + // Will be called when the passphrase dialog is closed, which is shown after + // clicking the preview button. + void OnAuthorizationResult(bool success); void DispatchContinueRequest(bool continue_request); // Owns the interstitial, which owns us. @@ -57,6 +61,7 @@ class ManagedModeInterstitial : public content::InterstitialPageDelegate { std::string languages_; GURL url_; + base::WeakPtrFactory<ManagedModeInterstitial> weak_ptr_factory_; base::Callback<void(bool)> callback_; DISALLOW_COPY_AND_ASSIGN(ManagedModeInterstitial); |