| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/host_pairing_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/host_pairing_screen_handler.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 7 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 8 | 8 |
| 9 namespace chromeos { | 9 namespace chromeos { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const char kJsScreenPath[] = "login.HostPairingScreen"; | 13 const char kJsScreenPath[] = "login.HostPairingScreen"; |
| 14 | 14 |
| 15 const char kMethodContextChanged[] = "contextChanged"; | 15 const char kMethodContextChanged[] = "contextChanged"; |
| 16 | 16 |
| 17 // Sent from JS when screen is ready to receive context updates. |
| 18 // TODO(dzhioev): Move 'contextReady' logic to the base screen handler when |
| 19 // all screens migrate to context-based communications. |
| 20 const char kCallbackContextReady[] = "contextReady"; |
| 21 |
| 17 } // namespace | 22 } // namespace |
| 18 | 23 |
| 19 HostPairingScreenHandler::HostPairingScreenHandler() | 24 HostPairingScreenHandler::HostPairingScreenHandler() |
| 20 : BaseScreenHandler(kJsScreenPath), delegate_(NULL), show_on_init_(false) { | 25 : BaseScreenHandler(kJsScreenPath), |
| 26 delegate_(NULL), |
| 27 show_on_init_(false), |
| 28 js_context_ready_(false) { |
| 21 } | 29 } |
| 22 | 30 |
| 23 HostPairingScreenHandler::~HostPairingScreenHandler() { | 31 HostPairingScreenHandler::~HostPairingScreenHandler() { |
| 24 if (delegate_) | 32 if (delegate_) |
| 25 delegate_->OnActorDestroyed(this); | 33 delegate_->OnActorDestroyed(this); |
| 26 } | 34 } |
| 27 | 35 |
| 36 void HostPairingScreenHandler::HandleContextReady() { |
| 37 js_context_ready_ = true; |
| 38 OnContextChanged(context_cache_.storage()); |
| 39 } |
| 40 |
| 28 void HostPairingScreenHandler::Initialize() { | 41 void HostPairingScreenHandler::Initialize() { |
| 29 if (!page_is_ready() || !delegate_) | 42 if (!page_is_ready() || !delegate_) |
| 30 return; | 43 return; |
| 31 | 44 |
| 32 if (show_on_init_) { | 45 if (show_on_init_) { |
| 33 Show(); | 46 Show(); |
| 34 show_on_init_ = false; | 47 show_on_init_ = false; |
| 35 } | 48 } |
| 36 } | 49 } |
| 37 | 50 |
| 38 void HostPairingScreenHandler::DeclareLocalizedValues( | 51 void HostPairingScreenHandler::DeclareLocalizedValues( |
| 39 LocalizedValuesBuilder* builder) { | 52 LocalizedValuesBuilder* builder) { |
| 40 } | 53 } |
| 41 | 54 |
| 42 void HostPairingScreenHandler::RegisterMessages() { | 55 void HostPairingScreenHandler::RegisterMessages() { |
| 56 AddPrefixedCallback(kCallbackContextReady, |
| 57 &HostPairingScreenHandler::HandleContextReady); |
| 43 } | 58 } |
| 44 | 59 |
| 45 void HostPairingScreenHandler::Show() { | 60 void HostPairingScreenHandler::Show() { |
| 46 if (!page_is_ready()) { | 61 if (!page_is_ready()) { |
| 47 show_on_init_ = true; | 62 show_on_init_ = true; |
| 48 return; | 63 return; |
| 49 } | 64 } |
| 50 ShowScreen(OobeUI::kScreenHostPairing, NULL); | 65 ShowScreen(OobeUI::kScreenHostPairing, NULL); |
| 51 } | 66 } |
| 52 | 67 |
| 53 void HostPairingScreenHandler::Hide() { | 68 void HostPairingScreenHandler::Hide() { |
| 54 } | 69 } |
| 55 | 70 |
| 56 void HostPairingScreenHandler::SetDelegate(Delegate* delegate) { | 71 void HostPairingScreenHandler::SetDelegate(Delegate* delegate) { |
| 57 delegate_ = delegate; | 72 delegate_ = delegate; |
| 58 if (page_is_ready()) | 73 if (page_is_ready()) |
| 59 Initialize(); | 74 Initialize(); |
| 60 } | 75 } |
| 61 | 76 |
| 62 void HostPairingScreenHandler::OnContextChanged( | 77 void HostPairingScreenHandler::OnContextChanged( |
| 63 const base::DictionaryValue& diff) { | 78 const base::DictionaryValue& diff) { |
| 79 if (!js_context_ready_) { |
| 80 context_cache_.ApplyChanges(diff, NULL); |
| 81 return; |
| 82 } |
| 64 CallJS(kMethodContextChanged, diff); | 83 CallJS(kMethodContextChanged, diff); |
| 65 } | 84 } |
| 66 | 85 |
| 67 } // namespace chromeos | 86 } // namespace chromeos |
| OLD | NEW |