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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/ui/captive_portal_view.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/login/ui/captive_portal_window_proxy.h"
9 #include "chrome/grit/generated_resources.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 "components/captive_portal/captive_portal_detector.h"
14 #include "content/public/browser/web_contents.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/views/window/dialog_delegate.h"
21 const char* CaptivePortalStartURL() {
22 return captive_portal::CaptivePortalDetector::kDefaultURL
;
29 CaptivePortalView::CaptivePortalView(Profile
* profile
,
30 CaptivePortalWindowProxy
* proxy
)
31 : SimpleWebViewDialog(profile
),
36 CaptivePortalView::~CaptivePortalView() {
39 void CaptivePortalView::StartLoad() {
40 SimpleWebViewDialog::StartLoad(GURL(CaptivePortalStartURL()));
43 bool CaptivePortalView::CanResize() const {
47 ui::ModalType
CaptivePortalView::GetModalType() const {
48 return ui::MODAL_TYPE_SYSTEM
;
51 base::string16
CaptivePortalView::GetWindowTitle() const {
52 base::string16 network_name
;
53 const NetworkState
* default_network
=
54 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
55 std::string default_network_name
=
56 default_network
? default_network
->name() : std::string();
57 if (!default_network_name
.empty()) {
58 network_name
= base::ASCIIToUTF16(default_network_name
);
61 << "No active/default network, but captive portal window is shown.";
64 return l10n_util::GetStringFUTF16(IDS_LOGIN_CAPTIVE_PORTAL_WINDOW_TITLE
,
68 bool CaptivePortalView::ShouldShowWindowTitle() const {
72 views::NonClientFrameView
* CaptivePortalView::CreateNonClientFrameView(
73 views::Widget
* widget
) {
74 return views::DialogDelegate::CreateDialogFrameView(widget
);
77 void CaptivePortalView::NavigationStateChanged(
78 content::WebContents
* source
,
79 content::InvalidateTypes changed_flags
) {
80 SimpleWebViewDialog::NavigationStateChanged(source
, changed_flags
);
82 // Naive way to determine the redirection. This won't be needed after portal
83 // detection will be done on the Chrome side.
84 GURL url
= source
->GetLastCommittedURL();
85 // Note, |url| will be empty for "client3.google.com/generate_204" page.
86 if (!redirected_
&& url
!= GURL::EmptyGURL() &&
87 url
!= GURL(CaptivePortalStartURL())) {
89 proxy_
->OnRedirected();
93 void CaptivePortalView::LoadingStateChanged(content::WebContents
* source
,
94 bool to_different_document
) {
95 SimpleWebViewDialog::LoadingStateChanged(source
, to_different_document
);
96 // TODO(nkostylev): Fix case of no connectivity, check HTTP code returned.
97 // Disable this heuristic as it has false positives.
98 // Relying on just shill portal check to close dialog is fine.
99 // if (!is_loading && !redirected_)
100 // proxy_->OnOriginalURLLoaded();
103 } // namespace chromeos