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/android/vr_shell/vr_shell.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell.h" |
6 | 6 |
7 #include <thread> | 7 #include <thread> |
8 | 8 |
9 #include "chrome/browser/android/vr_shell/ui_scene.h" | 9 #include "chrome/browser/android/vr_shell/ui_scene.h" |
10 #include "chrome/browser/android/vr_shell/vr_compositor.h" | 10 #include "chrome/browser/android/vr_shell/vr_compositor.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 481 } |
482 | 482 |
483 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 483 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
484 if (gvr_api_ == nullptr) | 484 if (gvr_api_ == nullptr) |
485 return; | 485 return; |
486 | 486 |
487 gvr_api_->RefreshViewerProfile(); | 487 gvr_api_->RefreshViewerProfile(); |
488 gvr_api_->ResumeTracking(); | 488 gvr_api_->ResumeTracking(); |
489 } | 489 } |
490 | 490 |
491 base::WeakPtr<VrShell> VrShell::GetWeakPtr() { | 491 base::WeakPtr<VrShell> VrShell::GetWeakPtr( |
492 // TODO: Ensure that only ui webcontents can request this weak ptr. | 492 const content::WebContents* web_contents) { |
493 if (g_instance != nullptr) | 493 // Ensure that the WebContents requesting the VrShell instance is the one |
| 494 // we created. |
| 495 if (g_instance != nullptr && |
| 496 g_instance->ui_cvc_->GetWebContents() == web_contents) |
494 return g_instance->weak_ptr_factory_.GetWeakPtr(); | 497 return g_instance->weak_ptr_factory_.GetWeakPtr(); |
495 return base::WeakPtr<VrShell>(nullptr); | 498 return base::WeakPtr<VrShell>(nullptr); |
496 } | 499 } |
497 | 500 |
498 void VrShell::OnDomContentsLoaded() { | 501 void VrShell::OnDomContentsLoaded() { |
499 // TODO(mthiesse): Setting the background to transparent after the DOM content | 502 // TODO(mthiesse): Setting the background to transparent after the DOM content |
500 // has loaded is a hack to work around the background not updating when we set | 503 // has loaded is a hack to work around the background not updating when we set |
501 // it to transparent unless we perform a very specific sequence of events. | 504 // it to transparent unless we perform a very specific sequence of events. |
502 // First the page background must load as not transparent, then we set the | 505 // First the page background must load as not transparent, then we set the |
503 // background of the renderer to transparent, then we update the page | 506 // background of the renderer to transparent, then we update the page |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 content::WebContents::FromJavaWebContents(content_web_contents)); | 596 content::WebContents::FromJavaWebContents(content_web_contents)); |
594 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( | 597 content::ContentViewCore* ui_core = content::ContentViewCore::FromWebContents( |
595 content::WebContents::FromJavaWebContents(ui_web_contents)); | 598 content::WebContents::FromJavaWebContents(ui_web_contents)); |
596 return reinterpret_cast<intptr_t>(new VrShell( | 599 return reinterpret_cast<intptr_t>(new VrShell( |
597 env, obj, c_core, | 600 env, obj, c_core, |
598 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, | 601 reinterpret_cast<ui::WindowAndroid*>(content_window_android), ui_core, |
599 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); | 602 reinterpret_cast<ui::WindowAndroid*>(ui_window_android))); |
600 } | 603 } |
601 | 604 |
602 } // namespace vr_shell | 605 } // namespace vr_shell |
OLD | NEW |