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.
5 #include "chrome/browser/chromeos/login/captive_portal_view.h"
7 #include "ash/wm/custom_frame_view_ash.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/captive_portal/captive_portal_detector.h"
10 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
11 #include "chromeos/network/network_handler.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "content/public/browser/web_contents.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/views/window/dialog_delegate.h"
22 const char* CaptivePortalStartURL() {
23 return captive_portal::CaptivePortalDetector::kDefaultURL;
30 CaptivePortalView::CaptivePortalView(Profile* profile,
31 CaptivePortalWindowProxy* proxy)
32 : SimpleWebViewDialog(profile),
37 CaptivePortalView::~CaptivePortalView() {
40 void CaptivePortalView::StartLoad() {
41 SimpleWebViewDialog::StartLoad(GURL(CaptivePortalStartURL()));
44 bool CaptivePortalView::CanResize() const {
48 ui::ModalType CaptivePortalView::GetModalType() const {
49 return ui::MODAL_TYPE_SYSTEM;
52 string16 CaptivePortalView::GetWindowTitle() const {
53 string16 network_name;
54 const NetworkState* default_network =
55 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
56 std::string default_network_name =
57 default_network ? default_network->name() : std::string();
58 if (!default_network_name.empty()) {
59 network_name = ASCIIToUTF16(default_network_name);
62 << "No active/default network, but captive portal window is shown.";
65 return l10n_util::GetStringFUTF16(IDS_LOGIN_CAPTIVE_PORTAL_WINDOW_TITLE,
69 bool CaptivePortalView::ShouldShowWindowTitle() const {
73 views::NonClientFrameView* CaptivePortalView::CreateNonClientFrameView(
74 views::Widget* widget) {
75 if (views::DialogDelegate::UseNewStyle()) {
76 const bool force_opaque_border = false;
77 return views::DialogDelegate::CreateNewStyleFrameView(widget,
80 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(widget);
81 // Always use "active" look.
82 frame->SetInactiveRenderingDisabled(true);
86 void CaptivePortalView::NavigationStateChanged(
87 const content::WebContents* source, unsigned changed_flags) {
88 SimpleWebViewDialog::NavigationStateChanged(source, changed_flags);
90 // Naive way to determine the redirection. This won't be needed after portal
91 // detection will be done on the Chrome side.
92 GURL url = source->GetLastCommittedURL();
93 // Note, |url| will be empty for "client3.google.com/generate_204" page.
94 if (!redirected_ && url != GURL::EmptyGURL() &&
95 url != GURL(CaptivePortalStartURL())) {
96 DLOG(INFO) << CaptivePortalStartURL() << " vs " << url.spec();
98 proxy_->OnRedirected();
102 void CaptivePortalView::LoadingStateChanged(content::WebContents* source) {
103 SimpleWebViewDialog::LoadingStateChanged(source);
104 // TODO(nkostylev): Fix case of no connectivity, check HTTP code returned.
105 // Disable this heuristic as it has false positives.
106 // Relying on just shill portal check to close dialog is fine.
107 // if (!is_loading && !redirected_)
108 // proxy_->OnOriginalURLLoaded();
111 } // namespace chromeos