controller_pairing_screen_handler.cc revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 2014 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/controller_pairing_screen_handler.h" 6 7#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 8#include "content/public/browser/web_contents.h" 9 10namespace chromeos { 11 12namespace { 13 14const char kJsScreenPath[] = "login.ControllerPairingScreen"; 15 16const char kMethodContextChanged[] = "contextChanged"; 17 18const char kCallbackUserActed[] = "userActed"; 19const char kCallbackContextChanged[] = "contextChanged"; 20 21} // namespace 22 23ControllerPairingScreenHandler::ControllerPairingScreenHandler() 24 : BaseScreenHandler(kJsScreenPath), delegate_(NULL), show_on_init_(false) { 25} 26 27ControllerPairingScreenHandler::~ControllerPairingScreenHandler() { 28 if (delegate_) 29 delegate_->OnActorDestroyed(this); 30} 31 32void ControllerPairingScreenHandler::HandleUserActed( 33 const std::string& action) { 34 if (!delegate_) 35 return; 36 delegate_->OnUserActed(action); 37} 38 39void ControllerPairingScreenHandler::HandleContextChanged( 40 const base::DictionaryValue* diff) { 41 if (!delegate_) 42 return; 43 delegate_->OnScreenContextChanged(*diff); 44} 45 46void ControllerPairingScreenHandler::Initialize() { 47 if (!page_is_ready() || !delegate_) 48 return; 49 50 if (show_on_init_) { 51 Show(); 52 show_on_init_ = false; 53 } 54} 55 56void ControllerPairingScreenHandler::DeclareLocalizedValues( 57 LocalizedValuesBuilder* builder) { 58} 59 60void ControllerPairingScreenHandler::RegisterMessages() { 61 AddPrefixedCallback(kCallbackUserActed, 62 &ControllerPairingScreenHandler::HandleUserActed); 63 AddPrefixedCallback(kCallbackContextChanged, 64 &ControllerPairingScreenHandler::HandleContextChanged); 65} 66 67void ControllerPairingScreenHandler::Show() { 68 if (!page_is_ready()) { 69 show_on_init_ = true; 70 return; 71 } 72 ShowScreen(OobeUI::kScreenControllerPairing, NULL); 73} 74 75void ControllerPairingScreenHandler::Hide() { 76} 77 78void ControllerPairingScreenHandler::SetDelegate(Delegate* delegate) { 79 delegate_ = delegate; 80 if (page_is_ready()) 81 Initialize(); 82} 83 84void ControllerPairingScreenHandler::OnContextChanged( 85 const base::DictionaryValue& diff) { 86 CallJS(kMethodContextChanged, diff); 87} 88 89content::BrowserContext* ControllerPairingScreenHandler::GetBrowserContext() { 90 return web_ui()->GetWebContents()->GetBrowserContext(); 91} 92 93} // namespace chromeos 94