Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / captive_portal_view.cc
blob7b3c70940b68eadc07860581ff1ec319c4577883
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 "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 "ui/views/window/dialog_delegate.h"
17 #include "url/gurl.h"
19 namespace {
21 const char* CaptivePortalStartURL() {
22 return captive_portal::CaptivePortalDetector::kDefaultURL;
25 } // namespace
27 namespace chromeos {
29 CaptivePortalView::CaptivePortalView(Profile* profile,
30 CaptivePortalWindowProxy* proxy)
31 : SimpleWebViewDialog(profile),
32 proxy_(proxy),
33 redirected_(false) {
36 CaptivePortalView::~CaptivePortalView() {
39 void CaptivePortalView::StartLoad() {
40 SimpleWebViewDialog::StartLoad(GURL(CaptivePortalStartURL()));
43 bool CaptivePortalView::CanResize() const {
44 return false;
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);
59 } else {
60 DLOG(ERROR)
61 << "No active/default network, but captive portal window is shown.";
64 return l10n_util::GetStringFUTF16(IDS_LOGIN_CAPTIVE_PORTAL_WINDOW_TITLE,
65 network_name);
68 bool CaptivePortalView::ShouldShowWindowTitle() const {
69 return true;
72 views::NonClientFrameView* CaptivePortalView::CreateNonClientFrameView(
73 views::Widget* widget) {
74 return views::DialogDelegate::CreateDialogFrameView(widget);
77 void CaptivePortalView::NavigationStateChanged(
78 const content::WebContents* source, unsigned changed_flags) {
79 SimpleWebViewDialog::NavigationStateChanged(source, changed_flags);
81 // Naive way to determine the redirection. This won't be needed after portal
82 // detection will be done on the Chrome side.
83 GURL url = source->GetLastCommittedURL();
84 // Note, |url| will be empty for "client3.google.com/generate_204" page.
85 if (!redirected_ && url != GURL::EmptyGURL() &&
86 url != GURL(CaptivePortalStartURL())) {
87 DLOG(INFO) << CaptivePortalStartURL() << " vs " << url.spec();
88 redirected_ = true;
89 proxy_->OnRedirected();
93 void CaptivePortalView::LoadingStateChanged(content::WebContents* source) {
94 SimpleWebViewDialog::LoadingStateChanged(source);
95 // TODO(nkostylev): Fix case of no connectivity, check HTTP code returned.
96 // Disable this heuristic as it has false positives.
97 // Relying on just shill portal check to close dialog is fine.
98 // if (!is_loading && !redirected_)
99 // proxy_->OnOriginalURLLoaded();
102 } // namespace chromeos