| 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/ui/webui/vr_shell/vr_shell_ui_message_handler.h" | 5 #include "chrome/browser/ui/webui/vr_shell/vr_shell_ui_message_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 web_ui()->RegisterMessageCallback( | 35 web_ui()->RegisterMessageCallback( |
| 36 "doAction", base::Bind(&VrShellUIMessageHandler::HandleDoAction, | 36 "doAction", base::Bind(&VrShellUIMessageHandler::HandleDoAction, |
| 37 base::Unretained(this))); | 37 base::Unretained(this))); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) { | 40 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) { |
| 41 AllowJavascript(); | 41 AllowJavascript(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void VrShellUIMessageHandler::OnJavascriptAllowed() { | 44 void VrShellUIMessageHandler::OnJavascriptAllowed() { |
| 45 CHECK(vr_shell_); | 45 // If we don't have a VR Shell here, it means either the user manually loaded |
| 46 // this webui page and we want to silently fail to connect to native vr shell, |
| 47 // or VR Shell was deleted, and this webui content is also about to be |
| 48 // deleted. |
| 49 if (!vr_shell_) |
| 50 return; |
| 46 vr_shell_->GetUiInterface()->SetUiCommandHandler(this); | 51 vr_shell_->GetUiInterface()->SetUiCommandHandler(this); |
| 47 vr_shell_->OnDomContentsLoaded(); | 52 vr_shell_->OnDomContentsLoaded(); |
| 48 } | 53 } |
| 49 | 54 |
| 50 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { | 55 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { |
| 51 if (!vr_shell_) | 56 if (!vr_shell_) |
| 52 return; | 57 return; |
| 53 | 58 |
| 54 // Copy the update instructions and handle them on the render thread. | 59 // Copy the update instructions and handle them on the render thread. |
| 55 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, | 60 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, |
| 56 base::Unretained(vr_shell_->GetScene()), | 61 base::Unretained(vr_shell_->GetScene()), |
| 57 base::Owned(args->CreateDeepCopy().release()), | 62 base::Owned(args->CreateDeepCopy().release()), |
| 58 vr_shell::UiScene::TimeInMicroseconds()); | 63 vr_shell::UiScene::TimeInMicroseconds()); |
| 59 vr_shell_->QueueTask(cb); | 64 vr_shell_->QueueTask(cb); |
| 60 } | 65 } |
| 61 | 66 |
| 62 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { | 67 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { |
| 63 int action; | 68 int action; |
| 64 CHECK(args->GetInteger(0, &action)); | 69 CHECK(args->GetInteger(0, &action)); |
| 65 if (vr_shell_) { | 70 if (vr_shell_) { |
| 66 vr_shell_->DoUiAction((vr_shell::UiAction) action); | 71 vr_shell_->DoUiAction((vr_shell::UiAction) action); |
| 67 } | 72 } |
| 68 } | 73 } |
| 69 | 74 |
| 70 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) { | 75 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) { |
| 71 CallJavascriptFunction("vrShellUi.command", value); | 76 CallJavascriptFunction("vrShellUi.command", value); |
| 72 } | 77 } |
| OLD | NEW |