Commit c663cf53 authored by mthiesse's avatar mthiesse Committed by Commit bot

Ensure that the web contents trying to access native VR Shell is the webcontents we created.

BUG=641413

Review-Url: https://codereview.chromium.org/2384323003
Cr-Commit-Position: refs/heads/master@{#422812}
parent b31a8221
...@@ -657,9 +657,12 @@ void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { ...@@ -657,9 +657,12 @@ void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
controller_->OnResume(); controller_->OnResume();
} }
base::WeakPtr<VrShell> VrShell::GetWeakPtr() { base::WeakPtr<VrShell> VrShell::GetWeakPtr(
// TODO: Ensure that only ui webcontents can request this weak ptr. const content::WebContents* web_contents) {
if (g_instance != nullptr) // Ensure that the WebContents requesting the VrShell instance is the one
// we created.
if (g_instance != nullptr &&
g_instance->ui_cvc_->GetWebContents() == web_contents)
return g_instance->weak_ptr_factory_.GetWeakPtr(); return g_instance->weak_ptr_factory_.GetWeakPtr();
return base::WeakPtr<VrShell>(nullptr); return base::WeakPtr<VrShell>(nullptr);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
namespace content { namespace content {
class ContentViewCore; class ContentViewCore;
class WebContents;
} }
namespace ui { namespace ui {
...@@ -66,7 +67,8 @@ class VrShell : public device::GvrDelegate { ...@@ -66,7 +67,8 @@ class VrShell : public device::GvrDelegate {
bool enabled); bool enabled);
// html/js UI hooks. // html/js UI hooks.
static base::WeakPtr<VrShell> GetWeakPtr(); static base::WeakPtr<VrShell> GetWeakPtr(
const content::WebContents* web_contents);
UiScene* GetScene(); UiScene* GetScene();
void OnDomContentsLoaded(); void OnDomContentsLoaded();
void SetUiTextureSize(int width, int height); void SetUiTextureSize(int width, int height);
......
...@@ -18,7 +18,7 @@ VrShellUIMessageHandler::VrShellUIMessageHandler() {} ...@@ -18,7 +18,7 @@ VrShellUIMessageHandler::VrShellUIMessageHandler() {}
VrShellUIMessageHandler::~VrShellUIMessageHandler() {} VrShellUIMessageHandler::~VrShellUIMessageHandler() {}
void VrShellUIMessageHandler::RegisterMessages() { void VrShellUIMessageHandler::RegisterMessages() {
vr_shell_ = vr_shell::VrShell::GetWeakPtr(); vr_shell_ = vr_shell::VrShell::GetWeakPtr(web_ui()->GetWebContents());
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded, "domLoaded", base::Bind(&VrShellUIMessageHandler::HandleDomLoaded,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment