Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/browser/ui/webui/vr_shell/vr_shell_ui_message_handler.cc

Issue 2562733002: Implement our own GLThread for VR Shell. (Closed)
Patch Set: sigh Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/android/vr_shell/ui_interface.h" 13 #include "chrome/browser/android/vr_shell/ui_interface.h"
14 #include "chrome/browser/android/vr_shell/ui_scene.h" 14 #include "chrome/browser/android/vr_shell/ui_scene.h"
15 #include "chrome/browser/android/vr_shell/vr_shell.h" 15 #include "chrome/browser/android/vr_shell/vr_shell.h"
16 #include "content/public/browser/web_ui.h" 16 #include "content/public/browser/web_ui.h"
17 17
18 VrShellUIMessageHandler::VrShellUIMessageHandler() = default; 18 VrShellUIMessageHandler::VrShellUIMessageHandler() = default;
19 19
20 VrShellUIMessageHandler::~VrShellUIMessageHandler() { 20 VrShellUIMessageHandler::~VrShellUIMessageHandler() {
21 if (vr_shell_) { 21 if (vr_shell_) {
22 vr_shell_->GetUiInterfaceOnGL()->SetUiCommandHandler(nullptr); 22 vr_shell_->GetUiInterface()->SetUiCommandHandler(nullptr);
23 } 23 }
24 } 24 }
25 25
26 void VrShellUIMessageHandler::RegisterMessages() { 26 void VrShellUIMessageHandler::RegisterMessages() {
27 vr_shell_ = vr_shell::VrShell::GetWeakPtrOnUI(web_ui()->GetWebContents()); 27 vr_shell_ = vr_shell::VrShell::GetWeakPtr(web_ui()->GetWebContents());
28 28
29 web_ui()->RegisterMessageCallback( 29 web_ui()->RegisterMessageCallback(
30 "domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded, 30 "domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded,
31 base::Unretained(this))); 31 base::Unretained(this)));
32 web_ui()->RegisterMessageCallback( 32 web_ui()->RegisterMessageCallback(
33 "updateScene", base::Bind(&VrShellUIMessageHandler::HandleUpdateScene, 33 "updateScene", base::Bind(&VrShellUIMessageHandler::HandleUpdateScene,
34 base::Unretained(this))); 34 base::Unretained(this)));
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 web_ui()->RegisterMessageCallback( 38 web_ui()->RegisterMessageCallback(
39 "setUiCssSize", base::Bind(&VrShellUIMessageHandler::HandleSetUiCssSize, 39 "setUiCssSize", base::Bind(&VrShellUIMessageHandler::HandleSetUiCssSize,
40 base::Unretained(this))); 40 base::Unretained(this)));
41 } 41 }
42 42
43 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) { 43 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) {
44 AllowJavascript(); 44 AllowJavascript();
45 } 45 }
46 46
47 void VrShellUIMessageHandler::OnJavascriptAllowed() { 47 void VrShellUIMessageHandler::OnJavascriptAllowed() {
48 // If we don't have a VR Shell here, it means either the user manually loaded 48 // If we don't have a VR Shell here, it means either the user manually loaded
49 // this webui page and we want to silently fail to connect to native vr shell, 49 // this webui page and we want to silently fail to connect to native vr shell,
50 // or VR Shell was deleted, and this webui content is also about to be 50 // or VR Shell was deleted, and this webui content is also about to be
51 // deleted. 51 // deleted.
52 if (!vr_shell_) 52 if (!vr_shell_)
53 return; 53 return;
54 vr_shell_->GetUiInterfaceOnGL()->SetUiCommandHandler(this); 54 vr_shell_->GetUiInterface()->SetUiCommandHandler(this);
55 vr_shell_->OnDomContentsLoadedOnUI(); 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
62 // Copy the update instructions and handle them on the render thread. 62 // Copy the update instructions and handle them on the render thread.
63 // TODO(mthiesse): Clean this up.
63 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, 64 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands,
64 // TODO(mthiesse): Clean up threading around scene class. 65 // Unretained is safe because this callback will only be
65 base::Unretained(vr_shell_->GetSceneOnGL()), 66 // run on the GL thread, which owns the scene.
67 base::Unretained(vr_shell_->GetScene()),
66 base::Owned(args->CreateDeepCopy().release()), 68 base::Owned(args->CreateDeepCopy().release()),
67 vr_shell::UiScene::TimeInMicroseconds()); 69 vr_shell::UiScene::TimeInMicroseconds());
68 vr_shell_->QueueTaskOnUI(cb); 70 vr_shell_->QueueTask(cb);
69 } 71 }
70 72
71 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { 73 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) {
72 int action; 74 int action;
73 CHECK(args->GetInteger(0, &action)); 75 CHECK(args->GetInteger(0, &action));
74 if (vr_shell_) { 76 if (vr_shell_) {
75 vr_shell_->DoUiActionOnUI((vr_shell::UiAction) action); 77 vr_shell_->DoUiAction((vr_shell::UiAction) action);
76 } 78 }
77 } 79 }
78 80
79 void VrShellUIMessageHandler::HandleSetUiCssSize(const base::ListValue* args) { 81 void VrShellUIMessageHandler::HandleSetUiCssSize(const base::ListValue* args) {
80 CHECK(args->GetSize() == 3); 82 CHECK(args->GetSize() == 3);
81 double width, height, dpr; 83 double width, height, dpr;
82 CHECK(args->GetDouble(0, &width)); 84 CHECK(args->GetDouble(0, &width));
83 CHECK(args->GetDouble(1, &height)); 85 CHECK(args->GetDouble(1, &height));
84 CHECK(args->GetDouble(2, &dpr)); 86 CHECK(args->GetDouble(2, &dpr));
85 if (vr_shell_) { 87 if (vr_shell_) {
86 vr_shell_->SetUiCssSizeOnUI(width, height, dpr); 88 vr_shell_->SetUiCssSize(width, height, dpr);
87 } 89 }
88 } 90 }
89 91
90 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) { 92 void VrShellUIMessageHandler::SendCommandToUi(const base::Value& value) {
91 CallJavascriptFunction("vrShellUi.command", value); 93 CallJavascriptFunction("vrShellUi.command", value);
92 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698