OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ | 5 #ifndef CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ |
6 #define CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ | 6 #define CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/interstitials/security_interstitial_page.h" | 13 #include "chrome/browser/interstitials/security_interstitial_page.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace content{ | 16 namespace content{ |
16 class WebContents; | 17 class WebContents; |
17 } | 18 } |
18 | 19 |
19 // This class is responsible for showing/hiding the interstitial page that is | 20 // This class is responsible for showing/hiding the interstitial page that is |
20 // shown when a captive portal triggers an SSL error. | 21 // shown when a captive portal triggers an SSL error. |
21 // It deletes itself when the interstitial page is closed. | 22 // It deletes itself when the interstitial page is closed. |
22 // | 23 // |
23 // This class should only be used on the UI thread because its implementation | 24 // This class should only be used on the UI thread because its implementation |
24 // uses captive_portal::CaptivePortalService, which can only be accessed on the | 25 // uses captive_portal::CaptivePortalService, which can only be accessed on the |
25 // UI thread. Only used when ENABLE_CAPTIVE_PORTAL_DETECTION is true. | 26 // UI thread. Only used when ENABLE_CAPTIVE_PORTAL_DETECTION is true. |
26 class CaptivePortalBlockingPage : public SecurityInterstitialPage { | 27 class CaptivePortalBlockingPage : public SecurityInterstitialPage { |
27 public: | 28 public: |
28 // Interstitial type, for testing. | 29 // Interstitial type, for testing. |
29 static const void* kTypeForTesting; | 30 static const void* kTypeForTesting; |
30 | 31 |
| 32 class Delegate { |
| 33 public: |
| 34 virtual ~Delegate() {} |
| 35 |
| 36 // Returns true if the connection is a Wi-Fi connection. |
| 37 virtual bool IsWifiConnection() const = 0; |
| 38 // Returns the SSID of the connected Wi-Fi network, if any. |
| 39 virtual std::string GetWiFiSSID() const = 0; |
| 40 }; |
| 41 |
31 CaptivePortalBlockingPage(content::WebContents* web_contents, | 42 CaptivePortalBlockingPage(content::WebContents* web_contents, |
32 const GURL& request_url, | 43 const GURL& request_url, |
33 const GURL& login_url, | 44 const GURL& login_url, |
34 const base::Callback<void(bool)>& callback); | 45 const base::Callback<void(bool)>& callback); |
35 ~CaptivePortalBlockingPage() override; | 46 ~CaptivePortalBlockingPage() override; |
36 | 47 |
37 // SecurityInterstitialPage method: | 48 // SecurityInterstitialPage method: |
38 const void* GetTypeForTesting() const override; | 49 const void* GetTypeForTesting() const override; |
39 | 50 |
40 void SetWiFiConnectionForTesting(bool is_wifi_connection) { | 51 void SetDelegateForTesting(Delegate* delegate) { delegate_.reset(delegate); } |
41 is_wifi_connection_ = is_wifi_connection; | |
42 } | |
43 | |
44 void SetWiFiSSIDForTesting(const std::string& wifi_ssid) { | |
45 wifi_ssid_ = wifi_ssid; | |
46 } | |
47 | 52 |
48 protected: | 53 protected: |
49 // SecurityInterstitialPage methods: | 54 // SecurityInterstitialPage methods: |
50 void PopulateInterstitialStrings( | 55 void PopulateInterstitialStrings( |
51 base::DictionaryValue* load_time_data) override; | 56 base::DictionaryValue* load_time_data) override; |
52 bool ShouldCreateNewNavigation() const override; | 57 bool ShouldCreateNewNavigation() const override; |
53 | 58 |
54 // InterstitialPageDelegate method: | 59 // InterstitialPageDelegate method: |
55 void CommandReceived(const std::string& command) override; | 60 void CommandReceived(const std::string& command) override; |
56 | 61 |
57 private: | 62 private: |
58 // URL of the login page, opened when the user clicks the "Connect" button. | 63 // URL of the login page, opened when the user clicks the "Connect" button. |
59 GURL login_url_; | 64 GURL login_url_; |
60 // True if on a Wi-Fi connection. | 65 scoped_ptr<Delegate> delegate_; |
61 bool is_wifi_connection_; | |
62 // SSID of the connected network if the connection is a Wi-Fi connection. | |
63 std::string wifi_ssid_; | |
64 | |
65 base::Callback<void(bool)> callback_; | 66 base::Callback<void(bool)> callback_; |
66 | 67 |
67 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPage); | 68 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBlockingPage); |
68 }; | 69 }; |
69 | 70 |
70 #endif // CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ | 71 #endif // CHROME_BROWSER_SSL_CAPTIVE_PORTAL_BLOCKING_PAGE_H_ |
OLD | NEW |