Commit f088b1ea authored by Aldo Culquicondor's avatar Aldo Culquicondor Committed by Commit Bot

VR: Make VrWebContentsObserver platform independent

Bug: 891495
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:linux_vr;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I6b4aa77dc0c81b79afe681c31ed2b4a06f19dc37
Reviewed-on: https://chromium-review.googlesource.com/c/1257816Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Commit-Queue: Aldo Culquicondor <acondor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596201}
parent 76f882e6
...@@ -55,8 +55,6 @@ static_library("vr_android") { ...@@ -55,8 +55,6 @@ static_library("vr_android") {
"vr_shell.h", "vr_shell.h",
"vr_shell_delegate.cc", "vr_shell_delegate.cc",
"vr_shell_delegate.h", "vr_shell_delegate.h",
"vr_web_contents_observer.cc",
"vr_web_contents_observer.h",
"web_xr_presentation_state.cc", "web_xr_presentation_state.cc",
"web_xr_presentation_state.h", "web_xr_presentation_state.h",
] ]
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "chrome/browser/android/vr/vr_gl_thread.h" #include "chrome/browser/android/vr/vr_gl_thread.h"
#include "chrome/browser/android/vr/vr_input_connection.h" #include "chrome/browser/android/vr/vr_input_connection.h"
#include "chrome/browser/android/vr/vr_shell_delegate.h" #include "chrome/browser/android/vr/vr_shell_delegate.h"
#include "chrome/browser/android/vr/vr_web_contents_observer.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/vr_assets_component_installer.h" #include "chrome/browser/component_updater/vr_assets_component_installer.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
...@@ -47,6 +46,7 @@ ...@@ -47,6 +46,7 @@
#include "chrome/browser/vr/toolbar_helper.h" #include "chrome/browser/vr/toolbar_helper.h"
#include "chrome/browser/vr/ui_test_input.h" #include "chrome/browser/vr/ui_test_input.h"
#include "chrome/browser/vr/vr_tab_helper.h" #include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/vr/vr_web_contents_observer.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -252,7 +252,9 @@ void VrShell::SwapContents(JNIEnv* env, ...@@ -252,7 +252,9 @@ void VrShell::SwapContents(JNIEnv* env,
} }
vr_web_contents_observer_ = std::make_unique<VrWebContentsObserver>( vr_web_contents_observer_ = std::make_unique<VrWebContentsObserver>(
web_contents_, this, ui_, toolbar_.get()); web_contents_, ui_, toolbar_.get(),
base::BindOnce(&VrShell::ContentWebContentsDestroyed,
base::Unretained(this)));
// TODO(https://crbug.com/684661): Make SessionMetricsHelper tab-aware and // TODO(https://crbug.com/684661): Make SessionMetricsHelper tab-aware and
// able to track multiple tabs. // able to track multiple tabs.
...@@ -565,10 +567,6 @@ void VrShell::SetWebVrMode(JNIEnv* env, ...@@ -565,10 +567,6 @@ void VrShell::SetWebVrMode(JNIEnv* env,
} }
} }
void VrShell::OnFullscreenChanged(bool enabled) {
ui_->SetFullscreen(enabled);
}
bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) { bool VrShell::GetWebVrMode(JNIEnv* env, const JavaParamRef<jobject>& obj) {
return webvr_mode_; return webvr_mode_;
} }
......
...@@ -114,7 +114,6 @@ class VrShell : device::GvrGamepadDataProvider, ...@@ -114,7 +114,6 @@ class VrShell : device::GvrGamepadDataProvider,
base::android::ScopedJavaLocalRef<jobject> GetVrInputConnectionForTesting( base::android::ScopedJavaLocalRef<jobject> GetVrInputConnectionForTesting(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
void OnFullscreenChanged(bool enabled);
void OnLoadProgressChanged(JNIEnv* env, void OnLoadProgressChanged(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj, const base::android::JavaParamRef<jobject>& obj,
double progress); double progress);
......
...@@ -259,6 +259,8 @@ component("vr_common") { ...@@ -259,6 +259,8 @@ component("vr_common") {
"toolbar_helper.h", "toolbar_helper.h",
"ui_factory.cc", "ui_factory.cc",
"ui_factory.h", "ui_factory.h",
"vr_web_contents_observer.cc",
"vr_web_contents_observer.h",
] ]
public_deps = [ public_deps = [
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/android/vr/vr_web_contents_observer.h" #include "chrome/browser/vr/vr_web_contents_observer.h"
#include "chrome/browser/android/vr/vr_shell.h"
#include "chrome/browser/vr/toolbar_helper.h" #include "chrome/browser/vr/toolbar_helper.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
...@@ -13,22 +12,18 @@ ...@@ -13,22 +12,18 @@
namespace vr { namespace vr {
VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents, VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents,
VrShell* vr_shell,
BrowserUiInterface* ui_interface, BrowserUiInterface* ui_interface,
ToolbarHelper* toolbar) ToolbarHelper* toolbar,
base::OnceClosure on_destroy)
: WebContentsObserver(web_contents), : WebContentsObserver(web_contents),
vr_shell_(vr_shell),
ui_interface_(ui_interface), ui_interface_(ui_interface),
toolbar_(toolbar) { toolbar_(toolbar),
on_destroy_(std::move(on_destroy)) {
toolbar_->Update(); toolbar_->Update();
} }
VrWebContentsObserver::~VrWebContentsObserver() {} VrWebContentsObserver::~VrWebContentsObserver() {}
void VrWebContentsObserver::SetUiInterface(BrowserUiInterface* ui_interface) {
ui_interface_ = ui_interface;
}
void VrWebContentsObserver::DidStartLoading() { void VrWebContentsObserver::DidStartLoading() {
ui_interface_->SetLoading(true); ui_interface_->SetLoading(true);
} }
...@@ -59,11 +54,12 @@ void VrWebContentsObserver::DidChangeVisibleSecurityState() { ...@@ -59,11 +54,12 @@ void VrWebContentsObserver::DidChangeVisibleSecurityState() {
void VrWebContentsObserver::DidToggleFullscreenModeForTab( void VrWebContentsObserver::DidToggleFullscreenModeForTab(
bool entered_fullscreen, bool entered_fullscreen,
bool will_cause_resize) { bool will_cause_resize) {
vr_shell_->OnFullscreenChanged(entered_fullscreen); ui_interface_->SetFullscreen(entered_fullscreen);
} }
void VrWebContentsObserver::WebContentsDestroyed() { void VrWebContentsObserver::WebContentsDestroyed() {
vr_shell_->ContentWebContentsDestroyed(); DCHECK(on_destroy_);
std::move(on_destroy_).Run();
} }
void VrWebContentsObserver::RenderViewHostChanged( void VrWebContentsObserver::RenderViewHostChanged(
......
...@@ -2,10 +2,12 @@ ...@@ -2,10 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_VR_VR_WEB_CONTENTS_OBSERVER_H_ #ifndef CHROME_BROWSER_VR_VR_WEB_CONTENTS_OBSERVER_H_
#define CHROME_BROWSER_ANDROID_VR_VR_WEB_CONTENTS_OBSERVER_H_ #define CHROME_BROWSER_VR_VR_WEB_CONTENTS_OBSERVER_H_
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/vr/vr_export.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
namespace content { namespace content {
...@@ -16,19 +18,15 @@ namespace vr { ...@@ -16,19 +18,15 @@ namespace vr {
class BrowserUiInterface; class BrowserUiInterface;
class ToolbarHelper; class ToolbarHelper;
class VrShell;
class CONTENT_EXPORT VrWebContentsObserver class VR_EXPORT VrWebContentsObserver : public content::WebContentsObserver {
: public content::WebContentsObserver {
public: public:
VrWebContentsObserver(content::WebContents* web_contents, VrWebContentsObserver(content::WebContents* web_contents,
VrShell* vr_shell,
BrowserUiInterface* ui_interface, BrowserUiInterface* ui_interface,
ToolbarHelper* toolbar); ToolbarHelper* toolbar,
base::OnceClosure on_destroy);
~VrWebContentsObserver() override; ~VrWebContentsObserver() override;
void SetUiInterface(BrowserUiInterface* ui_interface);
private: private:
// WebContentsObserver implementation. // WebContentsObserver implementation.
void DidStartLoading() override; void DidStartLoading() override;
...@@ -47,13 +45,14 @@ class CONTENT_EXPORT VrWebContentsObserver ...@@ -47,13 +45,14 @@ class CONTENT_EXPORT VrWebContentsObserver
content::RenderViewHost* new_host) override; content::RenderViewHost* new_host) override;
// This class does not own these pointers. // This class does not own these pointers.
VrShell* vr_shell_;
BrowserUiInterface* ui_interface_; BrowserUiInterface* ui_interface_;
ToolbarHelper* toolbar_; ToolbarHelper* toolbar_;
base::OnceClosure on_destroy_;
DISALLOW_COPY_AND_ASSIGN(VrWebContentsObserver); DISALLOW_COPY_AND_ASSIGN(VrWebContentsObserver);
}; };
} // namespace vr } // namespace vr
#endif // CHROME_BROWSER_ANDROID_VR_VR_WEB_CONTENTS_OBSERVER_H_ #endif // CHROME_BROWSER_VR_VR_WEB_CONTENTS_OBSERVER_H_
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