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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // deleted. | 51 // deleted. |
52 if (!vr_shell_) | 52 if (!vr_shell_) |
53 return; | 53 return; |
54 vr_shell_->GetUiInterface()->SetUiCommandHandler(this); | 54 vr_shell_->GetUiInterface()->SetUiCommandHandler(this); |
55 vr_shell_->OnDomContentsLoaded(); | 55 vr_shell_->OnDomContentsLoaded(); |
56 } | 56 } |
57 | 57 |
58 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { | 58 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { |
59 if (!vr_shell_) | 59 if (!vr_shell_) |
60 return; | 60 return; |
61 | 61 vr_shell_->UpdateScene(args); |
62 // Copy the update instructions and handle them on the render thread. | |
63 // TODO(mthiesse): Clean this up. | |
64 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, | |
65 // Unretained is safe because this callback will only be | |
66 // run on the GL thread, which owns the scene. | |
67 base::Unretained(vr_shell_->GetScene()), | |
68 base::Owned(args->CreateDeepCopy().release()), | |
69 vr_shell::UiScene::TimeInMicroseconds()); | |
70 vr_shell_->QueueTask(cb); | |
71 } | 62 } |
72 | 63 |
73 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { | 64 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { |
74 int action; | 65 int action; |
75 CHECK(args->GetInteger(0, &action)); | 66 CHECK(args->GetInteger(0, &action)); |
76 if (vr_shell_) { | 67 if (vr_shell_) { |
77 vr_shell_->DoUiAction((vr_shell::UiAction) action); | 68 vr_shell_->DoUiAction((vr_shell::UiAction) action); |
78 } | 69 } |
79 } | 70 } |
80 | 71 |
81 void VrShellUIMessageHandler::HandleSetUiCssSize(const base::ListValue* args) { | 72 void VrShellUIMessageHandler::HandleSetUiCssSize(const base::ListValue* args) { |
82 CHECK(args->GetSize() == 3); | 73 CHECK(args->GetSize() == 3); |
83 double width, height, dpr; | 74 double width, height, dpr; |
84 CHECK(args->GetDouble(0, &width)); | 75 CHECK(args->GetDouble(0, &width)); |
85 CHECK(args->GetDouble(1, &height)); | 76 CHECK(args->GetDouble(1, &height)); |
86 CHECK(args->GetDouble(2, &dpr)); | 77 CHECK(args->GetDouble(2, &dpr)); |
87 if (vr_shell_) { | 78 if (vr_shell_) { |
88 vr_shell_->SetUiCssSize(width, height, dpr); | 79 vr_shell_->SetUiCssSize(width, height, dpr); |
89 } | 80 } |
90 } | 81 } |
91 | 82 |
92 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) { | 83 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) { |
93 CallJavascriptFunction("vrShellUi.command", value); | 84 CallJavascriptFunction("vrShellUi.command", value); |
94 } | 85 } |
OLD | NEW |