| Index: chrome/browser/captive_portal/captive_portal_tab_helper.cc
|
| diff --git a/chrome/browser/captive_portal/captive_portal_tab_helper.cc b/chrome/browser/captive_portal/captive_portal_tab_helper.cc
|
| index bd4895ba17342cc89d57e098a669ab17a8d0c978..993b1eddb63ea60839771f8c7822ec9afcd1c20d 100644
|
| --- a/chrome/browser/captive_portal/captive_portal_tab_helper.cc
|
| +++ b/chrome/browser/captive_portal/captive_portal_tab_helper.cc
|
| @@ -31,6 +31,12 @@ using content::ResourceType;
|
|
|
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(CaptivePortalTabHelper);
|
|
|
| +// The delay before displaying the SSL interstitial for cert errors.
|
| +// - If a "captive portal detected" result arrives in this many seconds,
|
| +// a captive portal interstitial is displayed.
|
| +// - Otherwise, an SSL interstitial is displayed.
|
| +const int kDefaultSSLInterstitialDisplayDelay = 2;
|
| +
|
| CaptivePortalTabHelper::CaptivePortalTabHelper(
|
| content::WebContents* web_contents)
|
| : content::WebContentsObserver(web_contents),
|
| @@ -42,11 +48,13 @@ CaptivePortalTabHelper::CaptivePortalTabHelper(
|
| new CaptivePortalTabReloader(
|
| profile_,
|
| web_contents,
|
| - base::Bind(&CaptivePortalTabHelper::OpenLoginTab,
|
| - base::Unretained(this)))),
|
| + base::Bind(&CaptivePortalTabHelper::OpenLoginTabForWebContents,
|
| + web_contents, false))),
|
| login_detector_(new CaptivePortalLoginDetector(profile_)),
|
| web_contents_(web_contents),
|
| pending_error_code_(net::OK),
|
| + ssl_error_delay_(
|
| + base::TimeDelta::FromSeconds(kDefaultSSLInterstitialDisplayDelay)),
|
| provisional_render_view_host_(NULL) {
|
| registrar_.Add(this,
|
| chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
|
| @@ -193,6 +201,48 @@ bool CaptivePortalTabHelper::IsLoginTab() const {
|
| return login_detector_->is_login_tab();
|
| }
|
|
|
| +base::TimeDelta CaptivePortalTabHelper::GetSSLErrorDelay() const {
|
| + return ssl_error_delay_;
|
| +}
|
| +
|
| +// static
|
| +void CaptivePortalTabHelper::OpenLoginTabForWebContents(
|
| + content::WebContents* web_contents,
|
| + bool focus) {
|
| + Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
|
| +
|
| + // If the Profile doesn't have a tabbed browser window open, do nothing.
|
| + if (!browser)
|
| + return;
|
| +
|
| + // Check if the Profile's topmost browser window already has a login tab.
|
| + // If so, do nothing.
|
| + // TODO(mmenke): Consider focusing that tab, at least if this is the tab
|
| + // helper for the currently active tab for the profile.
|
| + for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
|
| + content::WebContents* contents =
|
| + browser->tab_strip_model()->GetWebContentsAt(i);
|
| + CaptivePortalTabHelper* captive_portal_tab_helper =
|
| + CaptivePortalTabHelper::FromWebContents(contents);
|
| + if (captive_portal_tab_helper->IsLoginTab()) {
|
| + if (focus)
|
| + browser->tab_strip_model()->ActivateTabAt(i, false);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + // Otherwise, open a login tab. Only end up here when a captive portal result
|
| + // was received, so it's safe to assume profile has a CaptivePortalService.
|
| + content::WebContents* new_contents = chrome::AddSelectedTabWithURL(
|
| + browser,
|
| + CaptivePortalServiceFactory::GetForProfile(
|
| + browser->profile())->test_url(),
|
| + ui::PAGE_TRANSITION_TYPED);
|
| + CaptivePortalTabHelper* captive_portal_tab_helper =
|
| + CaptivePortalTabHelper::FromWebContents(new_contents);
|
| + captive_portal_tab_helper->SetIsLoginTab();
|
| +}
|
| +
|
| void CaptivePortalTabHelper::OnRedirect(int child_id,
|
| ResourceType resource_type,
|
| const GURL& new_url) {
|
| @@ -231,37 +281,11 @@ void CaptivePortalTabHelper::SetTabReloaderForTest(
|
| tab_reloader_.reset(tab_reloader);
|
| }
|
|
|
| -CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() {
|
| - return tab_reloader_.get();
|
| +void CaptivePortalTabHelper::SetSSLErrorDelayForTest(
|
| + base::TimeDelta ssl_error_delay) {
|
| + ssl_error_delay_ = ssl_error_delay;
|
| }
|
|
|
| -void CaptivePortalTabHelper::OpenLoginTab() {
|
| - Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
|
| -
|
| - // If the Profile doesn't have a tabbed browser window open, do nothing.
|
| - if (!browser)
|
| - return;
|
| -
|
| - // Check if the Profile's topmost browser window already has a login tab.
|
| - // If so, do nothing.
|
| - // TODO(mmenke): Consider focusing that tab, at least if this is the tab
|
| - // helper for the currently active tab for the profile.
|
| - for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
|
| - content::WebContents* web_contents =
|
| - browser->tab_strip_model()->GetWebContentsAt(i);
|
| - CaptivePortalTabHelper* captive_portal_tab_helper =
|
| - CaptivePortalTabHelper::FromWebContents(web_contents);
|
| - if (captive_portal_tab_helper->IsLoginTab())
|
| - return;
|
| - }
|
| -
|
| - // Otherwise, open a login tab. Only end up here when a captive portal result
|
| - // was received, so it's safe to assume |profile_| has a CaptivePortalService.
|
| - content::WebContents* web_contents = chrome::AddSelectedTabWithURL(
|
| - browser,
|
| - CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(),
|
| - ui::PAGE_TRANSITION_TYPED);
|
| - CaptivePortalTabHelper* captive_portal_tab_helper =
|
| - CaptivePortalTabHelper::FromWebContents(web_contents);
|
| - captive_portal_tab_helper->SetIsLoginTab();
|
| +CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() {
|
| + return tab_reloader_.get();
|
| }
|
|
|