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/webui_login_display.h"
8 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown.h"
9 #include "grit/generated_resources.h"
13 const char kJsScreenPath
[] = "cr.ui.DropDown";
15 // JS API callbacks names.
16 const char kJsApiNetworkItemChosen
[] = "networkItemChosen";
17 const char kJsApiNetworkDropdownShow
[] = "networkDropdownShow";
18 const char kJsApiNetworkDropdownHide
[] = "networkDropdownHide";
19 const char kJsApiNetworkDropdownRefresh
[] = "networkDropdownRefresh";
25 NetworkDropdownHandler::NetworkDropdownHandler()
26 : BaseScreenHandler(kJsScreenPath
) {
29 NetworkDropdownHandler::~NetworkDropdownHandler() {
32 void NetworkDropdownHandler::AddObserver(Observer
* observer
) {
33 if (observer
&& !observers_
.HasObserver(observer
))
34 observers_
.AddObserver(observer
);
37 void NetworkDropdownHandler::RemoveObserver(Observer
* observer
) {
38 observers_
.RemoveObserver(observer
);
41 void NetworkDropdownHandler::DeclareLocalizedValues(
42 LocalizedValuesBuilder
* builder
) {
43 builder
->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT
);
44 builder
->Add("selectAnotherNetwork", IDS_ANOTHER_NETWORK_SELECTION_SELECT
);
47 void NetworkDropdownHandler::Initialize() {
50 void NetworkDropdownHandler::RegisterMessages() {
51 AddCallback(kJsApiNetworkItemChosen
,
52 &NetworkDropdownHandler::HandleNetworkItemChosen
);
53 AddCallback(kJsApiNetworkDropdownShow
,
54 &NetworkDropdownHandler::HandleNetworkDropdownShow
);
55 AddCallback(kJsApiNetworkDropdownHide
,
56 &NetworkDropdownHandler::HandleNetworkDropdownHide
);
57 AddCallback(kJsApiNetworkDropdownRefresh
,
58 &NetworkDropdownHandler::HandleNetworkDropdownRefresh
);
61 void NetworkDropdownHandler::OnConnectToNetworkRequested(
62 const std::string
& service_path
) {
63 FOR_EACH_OBSERVER(Observer
, observers_
,
64 OnConnectToNetworkRequested(service_path
));
67 void NetworkDropdownHandler::HandleNetworkItemChosen(double id
) {
68 if (dropdown_
.get()) {
69 dropdown_
->OnItemChosen(static_cast<int>(id
));
71 // It could happen with very low probability but still keep NOTREACHED to
72 // detect if it starts happening all the time.
77 void NetworkDropdownHandler::HandleNetworkDropdownShow(
78 const std::string
& element_id
,
80 dropdown_
.reset(new NetworkDropdown(this, web_ui(), oobe
));
83 void NetworkDropdownHandler::HandleNetworkDropdownHide() {
87 void NetworkDropdownHandler::HandleNetworkDropdownRefresh() {
88 // Since language change is async,
89 // we may in theory be on another screen during this call.
94 } // namespace chromeos