| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/vr_shell/ui_interface.h" | 5 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/webui/vr_shell/vr_shell_ui_message_handler.h" | 7 #include "chrome/browser/ui/webui/vr_shell/vr_shell_ui_message_handler.h" |
| 8 #include "url/gurl.h" |
| 8 | 9 |
| 9 namespace vr_shell { | 10 namespace vr_shell { |
| 10 | 11 |
| 11 UiInterface::UiInterface() { | 12 UiInterface::UiInterface() { |
| 12 SetMode(Mode::STANDARD); | 13 SetMode(Mode::STANDARD); |
| 13 } | 14 } |
| 14 | 15 |
| 15 UiInterface::~UiInterface() {} | 16 UiInterface::~UiInterface() {} |
| 16 | 17 |
| 17 void UiInterface::SetUiCommandHandler(UiCommandHandler* handler) { | |
| 18 handler_ = handler; | |
| 19 } | |
| 20 | |
| 21 void UiInterface::SetMode(Mode mode) { | 18 void UiInterface::SetMode(Mode mode) { |
| 22 updates_.SetInteger("mode", static_cast<int>(mode)); | 19 updates_.SetInteger("mode", static_cast<int>(mode)); |
| 23 FlushUpdates(); | 20 FlushUpdates(); |
| 24 } | 21 } |
| 25 | 22 |
| 26 void UiInterface::SetSecureOrigin(bool secure) { | 23 void UiInterface::SetSecureOrigin(bool secure) { |
| 27 updates_.SetBoolean("secureOrigin", secure); | 24 updates_.SetBoolean("secureOrigin", secure); |
| 28 FlushUpdates(); | 25 FlushUpdates(); |
| 29 } | 26 } |
| 30 | 27 |
| 28 void UiInterface::SetLoading(bool loading) { |
| 29 updates_.SetBoolean("loading", loading); |
| 30 FlushUpdates(); |
| 31 } |
| 32 |
| 33 void UiInterface::SetURL(const GURL& url) { |
| 34 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
| 35 details->SetString("host", url.host()); |
| 36 details->SetString("path", url.path()); |
| 37 |
| 38 updates_.Set("url", std::move(details)); |
| 39 FlushUpdates(); |
| 40 } |
| 41 |
| 31 void UiInterface::OnDomContentsLoaded() { | 42 void UiInterface::OnDomContentsLoaded() { |
| 32 loaded_ = true; | 43 loaded_ = true; |
| 33 #if defined(ENABLE_VR_SHELL_UI_DEV) | 44 #if defined(ENABLE_VR_SHELL_UI_DEV) |
| 34 updates_.SetBoolean("enableReloadUi", true); | 45 updates_.SetBoolean("enableReloadUi", true); |
| 35 #endif | 46 #endif |
| 36 FlushUpdates(); | 47 FlushUpdates(); |
| 37 } | 48 } |
| 38 | 49 |
| 50 void UiInterface::SetUiCommandHandler(UiCommandHandler* handler) { |
| 51 handler_ = handler; |
| 52 } |
| 53 |
| 39 void UiInterface::FlushUpdates() { | 54 void UiInterface::FlushUpdates() { |
| 40 if (loaded_ && handler_) { | 55 if (loaded_ && handler_) { |
| 41 handler_->SendCommandToUi(updates_); | 56 handler_->SendCommandToUi(updates_); |
| 42 updates_.Clear(); | 57 updates_.Clear(); |
| 43 } | 58 } |
| 44 } | 59 } |
| 45 | 60 |
| 46 } // namespace vr_shell | 61 } // namespace vr_shell |
| OLD | NEW |