summaryrefslogtreecommitdiffstats
path: root/chrome/browser/managed_mode
diff options
context:
space:
mode:
authortreib@chromium.org <treib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 07:30:42 +0000
committertreib@chromium.org <treib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-29 07:30:42 +0000
commitb8af2d1b0bbb50ae4e3546111296adeff5fa42b2 (patch)
tree6c2076e06d524ef48fbdb195e20a096575aa4acd /chrome/browser/managed_mode
parenta4a1e2e7b4f001383a521c80cab61ebd26545b4b (diff)
downloadchromium_src-b8af2d1b0bbb50ae4e3546111296adeff5fa42b2.zip
chromium_src-b8af2d1b0bbb50ae4e3546111296adeff5fa42b2.tar.gz
chromium_src-b8af2d1b0bbb50ae4e3546111296adeff5fa42b2.tar.bz2
Cleanup: Refactor ManagedModeInterstitial to not "delete this" in the ctor.
BUG= Review URL: https://codereview.chromium.org/250803004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/managed_mode')
-rw-r--r--chrome/browser/managed_mode/managed_mode_interstitial.cc36
-rw-r--r--chrome/browser/managed_mode/managed_mode_interstitial.h8
-rw-r--r--chrome/browser/managed_mode/managed_mode_navigation_observer.cc2
3 files changed, 34 insertions, 12 deletions
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc
index 04dede1..225b776 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;
diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.h b/chrome/browser/managed_mode/managed_mode_interstitial.h
index 06027d6..7acc205 100644
--- a/chrome/browser/managed_mode/managed_mode_interstitial.h
+++ b/chrome/browser/managed_mode/managed_mode_interstitial.h
@@ -23,12 +23,18 @@ class WebContents;
// blocked page, to decide later whether to manually allow it.
class ManagedModeInterstitial : public content::InterstitialPageDelegate {
public:
+ static void Show(content::WebContents* web_contents,
+ const GURL& url,
+ const base::Callback<void(bool)>& callback);
+
+ private:
ManagedModeInterstitial(content::WebContents* web_contents,
const GURL& url,
const base::Callback<void(bool)>& callback);
virtual ~ManagedModeInterstitial();
- private:
+ bool Init();
+
// InterstitialPageDelegate implementation.
virtual std::string GetHTMLContents() OVERRIDE;
virtual void CommandReceived(const std::string& command) OVERRIDE;
diff --git a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
index ef33758..12cb5b2 100644
--- a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
+++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc
@@ -233,7 +233,7 @@ void ManagedModeNavigationObserver::OnRequestBlocked(
navigation_observer->OnRequestBlockedInternal(url);
// Show the interstitial.
- new ManagedModeInterstitial(web_contents, url, callback);
+ ManagedModeInterstitial::Show(web_contents, url, callback);
}
void ManagedModeNavigationObserver::OnRequestBlockedInternal(const GURL& url) {