This source file includes following definitions.
- CaptivePortalStartURL
- redirected_
- StartLoad
- CanResize
- GetModalType
- GetWindowTitle
- ShouldShowWindowTitle
- CreateNonClientFrameView
- NavigationStateChanged
- LoadingStateChanged
#include "chrome/browser/chromeos/login/captive_portal_view.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/captive_portal/captive_portal_detector.h"
#include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/window/dialog_delegate.h"
#include "url/gurl.h"
namespace {
const char* CaptivePortalStartURL() {
return captive_portal::CaptivePortalDetector::kDefaultURL;
}
}
namespace chromeos {
CaptivePortalView::CaptivePortalView(Profile* profile,
CaptivePortalWindowProxy* proxy)
: SimpleWebViewDialog(profile),
proxy_(proxy),
redirected_(false) {
}
CaptivePortalView::~CaptivePortalView() {
}
void CaptivePortalView::StartLoad() {
SimpleWebViewDialog::StartLoad(GURL(CaptivePortalStartURL()));
}
bool CaptivePortalView::CanResize() const {
return false;
}
ui::ModalType CaptivePortalView::GetModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
base::string16 CaptivePortalView::GetWindowTitle() const {
base::string16 network_name;
const NetworkState* default_network =
NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
std::string default_network_name =
default_network ? default_network->name() : std::string();
if (!default_network_name.empty()) {
network_name = base::ASCIIToUTF16(default_network_name);
} else {
DLOG(ERROR)
<< "No active/default network, but captive portal window is shown.";
}
return l10n_util::GetStringFUTF16(IDS_LOGIN_CAPTIVE_PORTAL_WINDOW_TITLE,
network_name);
}
bool CaptivePortalView::ShouldShowWindowTitle() const {
return true;
}
views::NonClientFrameView* CaptivePortalView::CreateNonClientFrameView(
views::Widget* widget) {
return views::DialogDelegate::CreateDialogFrameView(widget);
}
void CaptivePortalView::NavigationStateChanged(
const content::WebContents* source, unsigned changed_flags) {
SimpleWebViewDialog::NavigationStateChanged(source, changed_flags);
GURL url = source->GetLastCommittedURL();
if (!redirected_ && url != GURL::EmptyGURL() &&
url != GURL(CaptivePortalStartURL())) {
redirected_ = true;
proxy_->OnRedirected();
}
}
void CaptivePortalView::LoadingStateChanged(content::WebContents* source,
bool to_different_document) {
SimpleWebViewDialog::LoadingStateChanged(source, to_different_document);
}
}