1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/login/captive_portal_view.h" 6 7 #include "base/strings/utf_string_conversions.h" 8 #include "chrome/browser/captive_portal/captive_portal_detector.h" 9 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h" 10 #include "chromeos/network/network_handler.h" 11 #include "chromeos/network/network_state.h" 12 #include "chromeos/network/network_state_handler.h" 13 #include "content/public/browser/web_contents.h" 14 #include "grit/generated_resources.h" 15 #include "ui/base/l10n/l10n_util.h" 16 #include "url/gurl.h" 17 18 namespace { 19 20 const char* CaptivePortalStartURL() { 21 return captive_portal::CaptivePortalDetector::kDefaultURL; 22 } 23 24 } // namespace 25 26 namespace chromeos { 27 28 CaptivePortalView::CaptivePortalView(Profile* profile, 29 CaptivePortalWindowProxy* proxy) 30 : SimpleWebViewDialog(profile), 31 proxy_(proxy), 32 redirected_(false) { 33 } 34 35 CaptivePortalView::~CaptivePortalView() { 36 } 37 38 void CaptivePortalView::StartLoad() { 39 SimpleWebViewDialog::StartLoad(GURL(CaptivePortalStartURL())); 40 } 41 42 bool CaptivePortalView::CanResize() const { 43 return false; 44 } 45 46 ui::ModalType CaptivePortalView::GetModalType() const { 47 return ui::MODAL_TYPE_SYSTEM; 48 } 49 50 string16 CaptivePortalView::GetWindowTitle() const { 51 string16 network_name; 52 const NetworkState* default_network = 53 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 54 std::string default_network_name = 55 default_network ? default_network->name() : std::string(); 56 if (!default_network_name.empty()) { 57 network_name = ASCIIToUTF16(default_network_name); 58 } else { 59 DLOG(ERROR) 60 << "No active/default network, but captive portal window is shown."; 61 } 62 63 return l10n_util::GetStringFUTF16(IDS_LOGIN_CAPTIVE_PORTAL_WINDOW_TITLE, 64 network_name); 65 } 66 67 bool CaptivePortalView::ShouldShowWindowTitle() const { 68 return true; 69 } 70 71 void CaptivePortalView::NavigationStateChanged( 72 const content::WebContents* source, unsigned changed_flags) { 73 SimpleWebViewDialog::NavigationStateChanged(source, changed_flags); 74 75 // Naive way to determine the redirection. This won't be needed after portal 76 // detection will be done on the Chrome side. 77 GURL url = source->GetLastCommittedURL(); 78 // Note, |url| will be empty for "client3.google.com/generate_204" page. 79 if (!redirected_ && url != GURL::EmptyGURL() && 80 url != GURL(CaptivePortalStartURL())) { 81 DLOG(INFO) << CaptivePortalStartURL() << " vs " << url.spec(); 82 redirected_ = true; 83 proxy_->OnRedirected(); 84 } 85 } 86 87 void CaptivePortalView::LoadingStateChanged(content::WebContents* source) { 88 SimpleWebViewDialog::LoadingStateChanged(source); 89 // TODO(nkostylev): Fix case of no connectivity, check HTTP code returned. 90 // Disable this heuristic as it has false positives. 91 // Relying on just shill portal check to close dialog is fine. 92 // if (!is_loading && !redirected_) 93 // proxy_->OnOriginalURLLoaded(); 94 } 95 96 } // namespace chromeos 97