Chromium Code Reviews| 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" |
| 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_scene.h" | 14 #include "chrome/browser/android/vr_shell/ui_scene.h" |
| 14 #include "chrome/browser/android/vr_shell/vr_shell.h" | 15 #include "chrome/browser/android/vr_shell/vr_shell.h" |
| 15 #include "content/public/browser/web_ui.h" | 16 #include "content/public/browser/web_ui.h" |
| 16 | 17 |
| 17 VrShellUIMessageHandler::VrShellUIMessageHandler() = default; | 18 VrShellUIMessageHandler::VrShellUIMessageHandler() : |
|
bshe
2016/10/19 21:02:40
nit: : move colon to next line
cjgrant
2016/10/20 15:25:39
Done.
| |
| 19 weak_ptr_factory_(this) {} | |
| 18 | 20 |
| 19 VrShellUIMessageHandler::~VrShellUIMessageHandler() = default; | 21 VrShellUIMessageHandler::~VrShellUIMessageHandler() = default; |
| 20 | 22 |
| 21 void VrShellUIMessageHandler::RegisterMessages() { | 23 void VrShellUIMessageHandler::RegisterMessages() { |
| 22 vr_shell_ = vr_shell::VrShell::GetWeakPtr(web_ui()->GetWebContents()); | 24 vr_shell_ = vr_shell::VrShell::GetWeakPtr(web_ui()->GetWebContents()); |
| 23 | 25 |
| 24 web_ui()->RegisterMessageCallback( | 26 web_ui()->RegisterMessageCallback( |
| 25 "domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded, | 27 "domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded, |
| 26 base::Unretained(this))); | 28 base::Unretained(this))); |
| 27 web_ui()->RegisterMessageCallback( | 29 web_ui()->RegisterMessageCallback( |
| 28 "updateScene", base::Bind(&VrShellUIMessageHandler::HandleUpdateScene, | 30 "updateScene", base::Bind(&VrShellUIMessageHandler::HandleUpdateScene, |
| 29 base::Unretained(this))); | 31 base::Unretained(this))); |
| 30 web_ui()->RegisterMessageCallback( | 32 web_ui()->RegisterMessageCallback( |
| 31 "doAction", base::Bind(&VrShellUIMessageHandler::HandleDoAction, | 33 "doAction", base::Bind(&VrShellUIMessageHandler::HandleDoAction, |
| 32 base::Unretained(this))); | 34 base::Unretained(this))); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) { | 37 void VrShellUIMessageHandler::HandleDomLoaded(const base::ListValue* args) { |
| 36 if (!vr_shell_) | 38 if (!vr_shell_) |
| 37 return; | 39 return; |
| 38 | 40 |
| 41 vr_shell_->GetUiInterface()->SetUiMessageHandler( | |
| 42 weak_ptr_factory_.GetWeakPtr()); | |
| 39 vr_shell_->OnDomContentsLoaded(); | 43 vr_shell_->OnDomContentsLoaded(); |
| 40 } | 44 } |
| 41 | 45 |
| 42 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { | 46 void VrShellUIMessageHandler::HandleUpdateScene(const base::ListValue* args) { |
| 43 if (!vr_shell_) | 47 if (!vr_shell_) |
| 44 return; | 48 return; |
| 45 | 49 |
| 46 // Copy the update instructions and handle them on the render thread. | 50 // Copy the update instructions and handle them on the render thread. |
| 47 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, | 51 auto cb = base::Bind(&vr_shell::UiScene::HandleCommands, |
| 48 base::Unretained(vr_shell_->GetScene()), | 52 base::Unretained(vr_shell_->GetScene()), |
| 49 base::Owned(args->CreateDeepCopy().release()), | 53 base::Owned(args->CreateDeepCopy().release()), |
| 50 vr_shell::UiScene::TimeInMicroseconds()); | 54 vr_shell::UiScene::TimeInMicroseconds()); |
| 51 vr_shell_->QueueTask(cb); | 55 vr_shell_->QueueTask(cb); |
| 52 } | 56 } |
| 53 | 57 |
| 54 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { | 58 void VrShellUIMessageHandler::HandleDoAction(const base::ListValue* args) { |
| 55 int action; | 59 int action; |
| 56 CHECK(args->GetInteger(0, &action)); | 60 CHECK(args->GetInteger(0, &action)); |
| 57 if (vr_shell_) { | 61 if (vr_shell_) { |
| 58 vr_shell_->DoUiAction((vr_shell::UiAction) action); | 62 vr_shell_->DoUiAction((vr_shell::UiAction) action); |
| 59 } | 63 } |
| 60 } | 64 } |
| OLD | NEW |