• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h"
6 
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 
11 namespace {
12 
13 const char kJsScreenPath[] = "cr.ui.DropDown";
14 
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";
20 
21 }  // namespace
22 
23 namespace chromeos {
24 
NetworkDropdownHandler()25 NetworkDropdownHandler::NetworkDropdownHandler()
26     : BaseScreenHandler(kJsScreenPath) {
27 }
28 
~NetworkDropdownHandler()29 NetworkDropdownHandler::~NetworkDropdownHandler() {
30 }
31 
AddObserver(Observer * observer)32 void NetworkDropdownHandler::AddObserver(Observer* observer) {
33   if (observer && !observers_.HasObserver(observer))
34     observers_.AddObserver(observer);
35 }
36 
RemoveObserver(Observer * observer)37 void NetworkDropdownHandler::RemoveObserver(Observer* observer) {
38   observers_.RemoveObserver(observer);
39 }
40 
DeclareLocalizedValues(LocalizedValuesBuilder * builder)41 void NetworkDropdownHandler::DeclareLocalizedValues(
42     LocalizedValuesBuilder* builder) {
43   builder->Add("selectNetwork", IDS_NETWORK_SELECTION_SELECT);
44   builder->Add("selectAnotherNetwork", IDS_ANOTHER_NETWORK_SELECTION_SELECT);
45 }
46 
Initialize()47 void NetworkDropdownHandler::Initialize() {
48 }
49 
RegisterMessages()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);
59 }
60 
OnConnectToNetworkRequested()61 void NetworkDropdownHandler::OnConnectToNetworkRequested() {
62   FOR_EACH_OBSERVER(Observer, observers_, OnConnectToNetworkRequested());
63 }
64 
HandleNetworkItemChosen(double id)65 void NetworkDropdownHandler::HandleNetworkItemChosen(double id) {
66   if (dropdown_.get()) {
67     dropdown_->OnItemChosen(static_cast<int>(id));
68   } else {
69     // It could happen with very low probability but still keep NOTREACHED to
70     // detect if it starts happening all the time.
71     NOTREACHED();
72   }
73 }
74 
HandleNetworkDropdownShow(const std::string & element_id,bool oobe)75 void NetworkDropdownHandler::HandleNetworkDropdownShow(
76     const std::string& element_id,
77     bool oobe) {
78   dropdown_.reset(new NetworkDropdown(this, web_ui(), oobe));
79 }
80 
HandleNetworkDropdownHide()81 void NetworkDropdownHandler::HandleNetworkDropdownHide() {
82   dropdown_.reset();
83 }
84 
HandleNetworkDropdownRefresh()85 void NetworkDropdownHandler::HandleNetworkDropdownRefresh() {
86   // Since language change is async,
87   // we may in theory be on another screen during this call.
88   if (dropdown_.get())
89     dropdown_->Refresh();
90 }
91 
92 }  // namespace chromeos
93