summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/captive_portal/captive_portal_browsertest.cc6
-rw-r--r--chrome/browser/captive_portal/captive_portal_tab_helper.cc24
-rw-r--r--chrome/browser/captive_portal/captive_portal_tab_helper.h19
-rw-r--r--chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc2
-rw-r--r--chrome/browser/chrome_content_browser_client.cc7
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents.cc3
-rw-r--r--chrome/browser/ui/tab_contents/tab_contents.h13
7 files changed, 39 insertions, 35 deletions
diff --git a/chrome/browser/captive_portal/captive_portal_browsertest.cc b/chrome/browser/captive_portal/captive_portal_browsertest.cc
index 44848d9d..f002f6c 100644
--- a/chrome/browser/captive_portal/captive_portal_browsertest.cc
+++ b/chrome/browser/captive_portal/captive_portal_browsertest.cc
@@ -485,7 +485,8 @@ int NumLoadingTabs() {
}
bool IsLoginTab(TabContents* tab_contents) {
- return tab_contents->captive_portal_tab_helper()->IsLoginTab();
+ return CaptivePortalTabHelper::FromWebContents(
+ tab_contents->web_contents())->IsLoginTab();
}
// Tracks how many times each tab has been navigated since the Observer was
@@ -1539,7 +1540,8 @@ void CaptivePortalBrowserTest::SetSlowSSLLoadTime(
CaptivePortalTabReloader* CaptivePortalBrowserTest::GetTabReloader(
TabContents* tab_contents) const {
- return tab_contents->captive_portal_tab_helper()->GetTabReloaderForTest();
+ return CaptivePortalTabHelper::FromWebContents(
+ tab_contents->web_contents())->GetTabReloaderForTest();
}
// Make sure there's no test for a captive portal on HTTP timeouts. This will
diff --git a/chrome/browser/captive_portal/captive_portal_tab_helper.cc b/chrome/browser/captive_portal/captive_portal_tab_helper.cc
index 7f6ff24..4108f12b2 100644
--- a/chrome/browser/captive_portal/captive_portal_tab_helper.cc
+++ b/chrome/browser/captive_portal/captive_portal_tab_helper.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/captive_portal/captive_portal_login_detector.h"
#include "chrome/browser/captive_portal/captive_portal_tab_reloader.h"
#include "chrome/browser/captive_portal/captive_portal_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
@@ -26,18 +27,22 @@
namespace captive_portal {
+int CaptivePortalTabHelper::kUserDataKey;
+
CaptivePortalTabHelper::CaptivePortalTabHelper(
- Profile* profile,
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
+ // web_contents is NULL in unit tests.
+ profile_(web_contents ? Profile::FromBrowserContext(
+ web_contents->GetBrowserContext())
+ : NULL),
tab_reloader_(
new CaptivePortalTabReloader(
- profile,
+ profile_,
web_contents,
base::Bind(&CaptivePortalTabHelper::OpenLoginTab,
base::Unretained(this)))),
- login_detector_(new CaptivePortalLoginDetector(profile)),
- profile_(profile),
+ login_detector_(new CaptivePortalLoginDetector(profile_)),
pending_error_code_(net::OK),
provisional_render_view_host_(NULL) {
registrar_.Add(this,
@@ -243,8 +248,10 @@ void CaptivePortalTabHelper::OpenLoginTab() {
// 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_count(); ++i) {
- TabContents* tab_contents = chrome::GetTabContentsAt(browser, i);
- if (tab_contents->captive_portal_tab_helper()->IsLoginTab())
+ content::WebContents* web_contents = chrome::GetWebContentsAt(browser, i);
+ captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
+ captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents);
+ if (captive_portal_tab_helper->IsLoginTab())
return;
}
@@ -254,7 +261,10 @@ void CaptivePortalTabHelper::OpenLoginTab() {
browser,
CaptivePortalServiceFactory::GetForProfile(profile_)->test_url(),
content::PAGE_TRANSITION_TYPED);
- tab_contents->captive_portal_tab_helper()->SetIsLoginTab();
+ captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
+ captive_portal::CaptivePortalTabHelper::FromWebContents(
+ tab_contents->web_contents());
+ captive_portal_tab_helper->SetIsLoginTab();
}
} // namespace captive_portal
diff --git a/chrome/browser/captive_portal/captive_portal_tab_helper.h b/chrome/browser/captive_portal/captive_portal_tab_helper.h
index ac117b0..70e94c0 100644
--- a/chrome/browser/captive_portal/captive_portal_tab_helper.h
+++ b/chrome/browser/captive_portal/captive_portal_tab_helper.h
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/captive_portal/captive_portal_service.h"
+#include "chrome/browser/tab_contents/web_contents_user_data.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_observer.h"
@@ -51,12 +52,12 @@ class CaptivePortalTabReloader;
//
// For the design doc, see:
// https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlUdlUdoW9WRaEmfM/edit
-class CaptivePortalTabHelper : public content::WebContentsObserver,
- public content::NotificationObserver,
- public base::NonThreadSafe {
+class CaptivePortalTabHelper
+ : public content::WebContentsObserver,
+ public content::NotificationObserver,
+ public base::NonThreadSafe,
+ public WebContentsUserData<CaptivePortalTabHelper> {
public:
- CaptivePortalTabHelper(Profile* profile,
- content::WebContents* web_contents);
virtual ~CaptivePortalTabHelper();
// content::WebContentsObserver:
@@ -102,6 +103,10 @@ class CaptivePortalTabHelper : public content::WebContentsObserver,
friend class CaptivePortalBrowserTest;
friend class CaptivePortalTabHelperTest;
+ friend class WebContentsUserData<CaptivePortalTabHelper>;
+ static int kUserDataKey;
+ explicit CaptivePortalTabHelper(content::WebContents* web_contents);
+
// Called by Observe in response to the corresponding event.
void OnRedirect(int child_id,
ResourceType::Type resource_type,
@@ -128,12 +133,12 @@ class CaptivePortalTabHelper : public content::WebContentsObserver,
// Opens a login tab if the profile's active window doesn't have one already.
void OpenLoginTab();
+ Profile* profile_;
+
// Neither of these will ever be NULL.
scoped_ptr<CaptivePortalTabReloader> tab_reloader_;
scoped_ptr<CaptivePortalLoginDetector> login_detector_;
- Profile* profile_;
-
// If a provisional load has failed, and the tab is loading an error page, the
// error code associated with the error page we're loading.
// net::OK, otherwise.
diff --git a/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc b/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc
index 63c74ea..214dcbe 100644
--- a/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc
+++ b/chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc
@@ -65,7 +65,7 @@ class MockCaptivePortalTabReloader : public CaptivePortalTabReloader {
class CaptivePortalTabHelperTest : public TabContentsTestHarness {
public:
CaptivePortalTabHelperTest()
- : tab_helper_(NULL, NULL),
+ : tab_helper_(NULL),
mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>),
ui_thread_(content::BrowserThread::UI, &message_loop_) {
tab_helper_.SetTabReloaderForTest(mock_reloader_);
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index d345d79..0ee484c 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -1123,9 +1123,10 @@ void ChromeContentBrowserClient::AllowCertificateError(
}
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
- TabContents* tab_contents = TabContents::FromWebContents(tab);
- if (tab_contents)
- tab_contents->captive_portal_tab_helper()->OnSSLCertError(ssl_info);
+ captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
+ captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
+ if (captive_portal_tab_helper)
+ captive_portal_tab_helper->OnSSLCertError(ssl_info);
#endif
// Otherwise, display an SSL blocking page.
diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc
index fd96bc0..5faf4ad 100644
--- a/chrome/browser/ui/tab_contents/tab_contents.cc
+++ b/chrome/browser/ui/tab_contents/tab_contents.cc
@@ -156,8 +156,7 @@ TabContents::TabContents(WebContents* contents)
#endif
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
- captive_portal_tab_helper_.reset(
- new captive_portal::CaptivePortalTabHelper(profile(), web_contents()));
+ captive_portal::CaptivePortalTabHelper::CreateForWebContents(contents);
#endif
#if !defined(OS_ANDROID)
diff --git a/chrome/browser/ui/tab_contents/tab_contents.h b/chrome/browser/ui/tab_contents/tab_contents.h
index 4d5a8fd..3fa3784 100644
--- a/chrome/browser/ui/tab_contents/tab_contents.h
+++ b/chrome/browser/ui/tab_contents/tab_contents.h
@@ -69,10 +69,6 @@ namespace browser_sync {
class SyncedTabDelegate;
}
-namespace captive_portal {
-class CaptivePortalTabHelper;
-}
-
namespace chromeos {
class SimpleWebViewDialog;
class WebUILoginView;
@@ -188,12 +184,6 @@ class TabContents : public content::WebContentsObserver {
return blocked_content_tab_helper_.get();
}
-#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
- captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper() {
- return captive_portal_tab_helper_.get();
- }
-#endif
-
ConstrainedWindowTabHelper* constrained_window_tab_helper() {
return constrained_window_tab_helper_.get();
}
@@ -270,9 +260,6 @@ class TabContents : public content::WebContentsObserver {
scoped_ptr<AutofillExternalDelegate> autofill_external_delegate_;
scoped_ptr<AutomationTabHelper> automation_tab_helper_;
scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_;
-#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
- scoped_ptr<captive_portal::CaptivePortalTabHelper> captive_portal_tab_helper_;
-#endif
scoped_ptr<ConstrainedWindowTabHelper> constrained_window_tab_helper_;
scoped_ptr<CoreTabHelper> core_tab_helper_;
scoped_ptr<FaviconTabHelper> favicon_tab_helper_;