Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / network_dropdown_handler.cc
blobbdbf7fcb16d6166942be9fe47ce3b086770ddde7
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/ui/webui/chromeos/login/network_dropdown_handler.h"
7 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
8 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/login/localized_values_builder.h"
12 namespace {
14 const char kJsScreenPath[] = "cr.ui.DropDown";
16 // JS API callbacks names.
17 const char kJsApiNetworkItemChosen[] = "networkItemChosen";
18 const char kJsApiNetworkDropdownShow[] = "networkDropdownShow";
19 const char kJsApiNetworkDropdownHide[] = "networkDropdownHide";
20 const char kJsApiNetworkDropdownRefresh[] = "networkDropdownRefresh";
22 } // namespace
24 namespace chromeos {
26 NetworkDropdownHandler::NetworkDropdownHandler()
27 : BaseScreenHandler(kJsScreenPath) {
30 NetworkDropdownHandler::~NetworkDropdownHandler() {
33 void NetworkDropdownHandler::AddObserver(Observer* observer) {
34 if (observer && !observers_.HasObserver(observer))
35 observers_.AddObserver(observer);
38 void NetworkDropdownHandler::RemoveObserver(Observer* observer) {
39 observers_.RemoveObserver(observer);
42 void NetworkDropdownHandler::DeclareLocalizedValues(
43 ::login::LocalizedValuesBuilder* builder) {
44 builder->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT);
45 builder->Add("selectAnotherNetwork", IDS_ANOTHER_NETWORK_SELECTION_SELECT);
48 void NetworkDropdownHandler::Initialize() {
51 void NetworkDropdownHandler::RegisterMessages() {
52 AddCallback(kJsApiNetworkItemChosen,
53 &NetworkDropdownHandler::HandleNetworkItemChosen);
54 AddCallback(kJsApiNetworkDropdownShow,
55 &NetworkDropdownHandler::HandleNetworkDropdownShow);
56 AddCallback(kJsApiNetworkDropdownHide,
57 &NetworkDropdownHandler::HandleNetworkDropdownHide);
58 AddCallback(kJsApiNetworkDropdownRefresh,
59 &NetworkDropdownHandler::HandleNetworkDropdownRefresh);
62 void NetworkDropdownHandler::OnConnectToNetworkRequested() {
63 FOR_EACH_OBSERVER(Observer, observers_, OnConnectToNetworkRequested());
66 void NetworkDropdownHandler::HandleNetworkItemChosen(double id) {
67 if (dropdown_.get()) {
68 dropdown_->OnItemChosen(static_cast<int>(id));
69 } else {
70 // It could happen with very low probability but still keep NOTREACHED to
71 // detect if it starts happening all the time.
72 NOTREACHED();
76 void NetworkDropdownHandler::HandleNetworkDropdownShow(
77 const std::string& element_id,
78 bool oobe) {
79 dropdown_.reset(new NetworkDropdown(this, web_ui(), oobe));
82 void NetworkDropdownHandler::HandleNetworkDropdownHide() {
83 dropdown_.reset();
86 void NetworkDropdownHandler::HandleNetworkDropdownRefresh() {
87 // Since language change is async,
88 // we may in theory be on another screen during this call.
89 if (dropdown_.get())
90 dropdown_->Refresh();
93 } // namespace chromeos