Index: chrome/browser/managed_mode/managed_mode_interstitial.cc |
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc |
index 04dede1c3e74322fa7bb27c609560e072e194cc4..225b776e339cd7856a0018852bf69b555f42cedf 100644 |
--- a/chrome/browser/managed_mode/managed_mode_interstitial.cc |
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc |
@@ -33,6 +33,19 @@ |
using content::BrowserThread; |
+// static |
+void ManagedModeInterstitial::Show(content::WebContents* web_contents, |
+ const GURL& url, |
+ const base::Callback<void(bool)>& callback) { |
+ ManagedModeInterstitial* interstitial = |
+ new ManagedModeInterstitial(web_contents, url, callback); |
+ |
+ // If Init() does not complete fully, immediately delete the interstitial. |
+ if (!interstitial->Init()) |
+ delete interstitial; |
+ // Otherwise |interstitial_page_| is responsible for deleting it. |
+} |
+ |
ManagedModeInterstitial::ManagedModeInterstitial( |
content::WebContents* web_contents, |
const GURL& url, |
@@ -40,19 +53,22 @@ ManagedModeInterstitial::ManagedModeInterstitial( |
: web_contents_(web_contents), |
interstitial_page_(NULL), |
url_(url), |
- callback_(callback) { |
+ callback_(callback) {} |
+ |
+ManagedModeInterstitial::~ManagedModeInterstitial() {} |
+ |
+bool ManagedModeInterstitial::Init() { |
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; |
+ return false; |
} |
- InfoBarService* service = InfoBarService::FromWebContents(web_contents); |
+ InfoBarService* service = InfoBarService::FromWebContents(web_contents_); |
if (service) { |
- // Remove all the infobars which are attached to |web_contents| and for |
+ // Remove all the infobars which are attached to |web_contents_| and for |
// which ShouldExpire() returns true. |
content::LoadCommittedDetails details; |
// |details.is_in_page| is default false, and |details.is_main_frame| is |
@@ -60,7 +76,7 @@ ManagedModeInterstitial::ManagedModeInterstitial( |
// true. |
DCHECK(details.is_navigation_to_different_page()); |
const content::NavigationController& controller = |
- web_contents->GetController(); |
+ web_contents_->GetController(); |
details.entry = controller.GetActiveEntry(); |
if (controller.GetLastCommittedEntry()) { |
details.previous_entry_index = controller.GetLastCommittedEntryIndex(); |
@@ -78,7 +94,7 @@ ManagedModeInterstitial::ManagedModeInterstitial( |
// TODO(bauerb): Extract an observer callback on ManagedUserService for this. |
Profile* profile = |
- Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
+ Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
PrefService* prefs = profile->GetPrefs(); |
pref_change_registrar_.Init(prefs); |
pref_change_registrar_.Add( |
@@ -96,11 +112,11 @@ ManagedModeInterstitial::ManagedModeInterstitial( |
languages_ = prefs->GetString(prefs::kAcceptLanguages); |
interstitial_page_ = |
- content::InterstitialPage::Create(web_contents, true, url_, this); |
+ content::InterstitialPage::Create(web_contents_, true, url_, this); |
interstitial_page_->Show(); |
-} |
-ManagedModeInterstitial::~ManagedModeInterstitial() {} |
+ return true; |
+} |
std::string ManagedModeInterstitial::GetHTMLContents() { |
base::DictionaryValue strings; |