Reviewers: Ted C
CL:
https://codereview.chromium.org/2874623004/Message:
Hey Ted. Is this heading in the direction you'd suggested?
Description:
[vr] Introduce VrTabHelper
This is currently a boolean holder, but will eventually
be responsible for both setting per-dialog suppression
flags on the WebContents and informing VrShell when
suppression notifications need to shown to the user.
BUG=688122
Affected files (+68, -1 lines):
M chrome/browser/android/vr_shell/vr_shell.cc
A chrome/browser/android/vr_shell/vr_tab_helper.h
A chrome/browser/android/vr_shell/vr_tab_helper.cc
M chrome/browser/ui/tab_helpers.cc
Index: chrome/browser/android/vr_shell/vr_shell.cc
diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc
index 5d7b6bbb6ea9851693c9ed9fecc6710b1cadaaee..ae9d4b40bf2913e6c306e89801c8e24b78f2e48a 100644
--- a/chrome/browser/android/vr_shell/vr_shell.cc
+++ b/chrome/browser/android/vr_shell/vr_shell.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/android/vr_shell/vr_input_manager.h"
#include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
#include "chrome/browser/android/vr_shell/vr_shell_gl.h"
+#include "chrome/browser/android/vr_shell/vr_tab_helper.h"
#include "chrome/browser/android/vr_shell/vr_usage_monitor.h"
#include "chrome/browser/android/vr_shell/vr_web_contents_observer.h"
#include "content/public/browser/browser_thread.h"
@@ -62,8 +63,16 @@ namespace {
vr_shell::VrShell* g_instance;
void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
- if (contents && contents->GetRenderWidgetHostView())
+ if (contents && contents->GetRenderWidgetHostView()) {
+ // TODO(asimjour) Contents should not be aware of VR mode. Instead, we
+ // should add a flag for disabling specific UI such as the keyboard (see
+ // VrTabHelper for details).
contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
+
+ VrTabHelper* vr_tab_helper = VrTabHelper::FromWebContents(source);
+ DCHECK(vr_blocker_helper);
+ vr_tab_helper->set_is_in_vr(is_in_vr);
+ }
}
void LoadControllerModelTask(
Index: chrome/browser/android/vr_shell/vr_tab_helper.cc
diff --git a/chrome/browser/android/vr_shell/vr_tab_helper.cc b/chrome/browser/android/vr_shell/vr_tab_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3429663c86196d84701192ecb231fd2c97047edc
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_tab_helper.cc
@@ -0,0 +1,16 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/vr_tab_helper.h"
+
+#include "chrome/browser/android/vr_shell/vr_shell_delegate.h"
+#include "device/vr/android/gvr/gvr_delegate_provider.h"
+
+namespace vr_shell {
+
+VrTabHelper::VrTabHelper(content::WebContents* contents)
+ : content::WebContentsObserver(contents) {}
+VrTabHelper::~VrTabHelper() {}
+
+} // namespace vr_shell
Index: chrome/browser/android/vr_shell/vr_tab_helper.h
diff --git a/chrome/browser/android/vr_shell/vr_tab_helper.h b/chrome/browser/android/vr_shell/vr_tab_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..84cb9f1d32b8f850e206ff1ec88ac7ade545cccb
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_tab_helper.h
@@ -0,0 +1,40 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_TAB_HELPER_H_
+#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_TAB_HELPER_H_
+
+#include "base/macros.h"
+
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+namespace vr_shell {
+
+class VrTabHelper : public content::WebContentsObserver,
+ public content::WebContentsUserData<VrTabHelper> {
+ public:
+ ~VrTabHelper() override;
+
+ bool is_in_vr() const { return is_in_vr_; }
+
+ // Called by VrShell when we enter and exit vr mode. It finds us by looking us
+ // up on the WebContents. Eventually, we will also set a number of flags here
+ // as we enter and exit vr mode (see TODO below).
+ void set_is_in_vr(bool is_in_vr) { is_in_vr_ = is_in_vr_; }
+
+ private:
+ explicit VrTabHelper(content::WebContents* contents);
+
+ // TODO(asimjour): once we have per-dialog flags for disabling specific
+ // content-related popups, we should hang onto a pointer to the web contents
+ // and set those flags as we enter and exit vr mode.
+ bool in_vr_mode_;
+
+ DISALLOW_COPY_AND_ASSIGN(VrTabHelper);
+};
+
+} // namespace vr_shell
+
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_TAB_HELPER_H_
Index: chrome/browser/ui/tab_helpers.cc
diff --git a/chrome/browser/ui/tab_helpers.cc b/chrome/browser/ui/tab_helpers.cc
index a70d9b267a6c77c6f5809e67b6f51e800f5c6fe9..a76f609cdbd134422007a1641474700c2f66fdf2 100644
--- a/chrome/browser/ui/tab_helpers.cc
+++ b/chrome/browser/ui/tab_helpers.cc
@@ -77,6 +77,7 @@
#include "chrome/browser/android/offline_pages/recent_tab_helper.h"
#include "chrome/browser/android/search_geolocation/search_geolocation_disclosure_tab_helper.h"
#include "chrome/browser/android/voice_search_tab_helper.h"
+#include "chrome/browser/android/vr_tab_helper.h"
#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
#include "chrome/browser/ui/android/context_menu_helper.h"
#include "chrome/browser/ui/android/view_android_helper.h"
@@ -230,6 +231,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
SingleTabModeTabHelper::CreateForWebContents(web_contents);
ViewAndroidHelper::CreateForWebContents(web_contents);
VoiceSearchTabHelper::CreateForWebContents(web_contents);
+ VrTabHelper::CreateForWebContents(web_contents);
#else
BookmarkTabHelper::CreateForWebContents(web_contents);
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(