Commit b38b120c authored by Christopher Grant's avatar Christopher Grant Committed by Commit Bot

VR: Add plumbing between UI and browser omnibox sites

This paves the way to plug in an AutocompleteController, and associated
UI.  Also, drive URL bar and WebVR toast state via model, as omnibox
will require some of the same data.

BUG=777542
R=vollick

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I29e96b5318e0d90b5530c12166db9fe780dba276
Reviewed-on: https://chromium-review.googlesource.com/772393
Commit-Queue: Christopher Grant <cjgrant@chromium.org>
Reviewed-by: default avatarBiao She <bshe@chromium.org>
Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517519}
parent 0b848fbe
......@@ -10,7 +10,8 @@
#include "chrome/browser/android/vr_shell/vr_shell.h"
#include "chrome/browser/android/vr_shell/vr_shell_gl.h"
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/ui.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -107,6 +108,12 @@ void VrGLThread::OnContentPaused(bool enabled) {
base::Bind(&VrShell::OnContentPaused, weak_vr_shell_, enabled));
}
void VrGLThread::Navigate(GURL gurl) {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&VrShell::Navigate, weak_vr_shell_, gurl));
}
void VrGLThread::NavigateBack() {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
......@@ -154,6 +161,19 @@ void VrGLThread::SetVoiceSearchActive(bool active) {
base::Bind(&VrShell::SetVoiceSearchActive, weak_vr_shell_, active));
}
void VrGLThread::StartAutocomplete(const base::string16& string) {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE,
base::Bind(&VrShell::StartAutocomplete, weak_vr_shell_, string));
}
void VrGLThread::StopAutocomplete() {
DCHECK(OnGlThread());
main_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&VrShell::StopAutocomplete, weak_vr_shell_));
}
void VrGLThread::SetFullscreen(bool enabled) {
DCHECK(OnMainThread());
task_runner()->PostTask(
......@@ -279,6 +299,14 @@ void VrGLThread::OnSpeechRecognitionStateChanged(int new_state) {
browser_ui_, new_state));
}
void VrGLThread::SetOmniboxSuggestions(
std::unique_ptr<vr::OmniboxSuggestions> suggestions) {
DCHECK(OnMainThread());
task_runner()->PostTask(
FROM_HERE, base::Bind(&vr::BrowserUiInterface::SetOmniboxSuggestions,
browser_ui_, base::Passed(std::move(suggestions))));
}
bool VrGLThread::OnMainThread() const {
return main_thread_task_runner_->BelongsToCurrentThread();
}
......
......@@ -22,6 +22,7 @@ namespace vr_shell {
class VrShell;
class VrShellGl;
struct OmniboxSuggestions;
class VrGLThread : public base::android::JavaHandlerThread,
public vr::ContentInputForwarder,
......@@ -55,6 +56,7 @@ class VrGLThread : public base::android::JavaHandlerThread,
// vr::UiBrowserInterface implementation (UI calling to VrShell).
void ExitPresent() override;
void ExitFullscreen() override;
void Navigate(GURL gurl) override;
void NavigateBack() override;
void ExitCct() override;
void OnUnsupportedMode(vr::UiUnsupportedMode mode) override;
......@@ -62,6 +64,8 @@ class VrGLThread : public base::android::JavaHandlerThread,
vr::ExitVrPromptChoice choice) override;
void OnContentScreenBoundsChanged(const gfx::SizeF& bounds) override;
void SetVoiceSearchActive(bool active) override;
void StartAutocomplete(const base::string16& string) override;
void StopAutocomplete() override;
// vr::BrowserUiInterface implementation (Browser calling to UI).
void SetWebVrMode(bool enabled, bool show_toast) override;
......@@ -82,6 +86,8 @@ class VrGLThread : public base::android::JavaHandlerThread,
void SetSpeechRecognitionEnabled(bool enabled) override;
void SetRecognitionResult(const base::string16& result) override;
void OnSpeechRecognitionStateChanged(int new_state) override;
void SetOmniboxSuggestions(
std::unique_ptr<vr::OmniboxSuggestions> result) override;
protected:
void Init() override;
......
......@@ -287,6 +287,13 @@ void VrShell::OnContentPaused(bool paused) {
device->Focus();
}
void VrShell::Navigate(GURL url) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_loadUrl(
env, j_vr_shell_,
base::android::ConvertUTF8ToJavaString(env, url.spec()));
}
void VrShell::NavigateBack() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_navigateBack(env, j_vr_shell_);
......@@ -746,6 +753,10 @@ void VrShell::SetVoiceSearchActive(bool active) {
}
}
void VrShell::StartAutocomplete(const base::string16& string) {}
void VrShell::StopAutocomplete() {}
bool VrShell::HasAudioPermission() {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_VrShellImpl_hasAudioPermission(env, j_vr_shell_);
......
......@@ -121,6 +121,7 @@ class VrShell : device::GvrGamepadDataProvider,
jboolean incognito,
jint id);
void OnContentPaused(bool paused);
void Navigate(GURL url);
void NavigateBack();
void ExitCct();
void ToggleCardboardGamepad(bool enabled);
......@@ -182,6 +183,8 @@ class VrShell : device::GvrGamepadDataProvider,
vr::ExitVrPromptChoice choice);
void OnContentScreenBoundsChanged(const gfx::SizeF& bounds);
void SetVoiceSearchActive(bool active);
void StartAutocomplete(const base::string16& string);
void StopAutocomplete();
bool HasAudioPermission();
void ProcessContentGesture(std::unique_ptr<blink::WebInputEvent> event,
......
......@@ -124,6 +124,8 @@ static_library("vr_common") {
"model/omnibox_suggestions.h",
"model/reticle_model.h",
"model/speech_recognition_model.h",
"model/toolbar_state.cc",
"model/toolbar_state.h",
"model/web_vr_timeout_state.h",
"pose_util.cc",
"pose_util.h",
......@@ -151,8 +153,6 @@ static_library("vr_common") {
"target_property.h",
"toolbar_helper.cc",
"toolbar_helper.h",
"toolbar_state.cc",
"toolbar_state.h",
"transition.cc",
"transition.h",
"ui.cc",
......
......@@ -10,6 +10,7 @@
namespace vr {
struct OmniboxSuggestions;
struct ToolbarState;
// The browser communicates state changes to the VR UI via this interface.
......@@ -36,6 +37,8 @@ class BrowserUiInterface {
virtual void SetSpeechRecognitionEnabled(bool enabled) = 0;
virtual void SetRecognitionResult(const base::string16& result) = 0;
virtual void OnSpeechRecognitionStateChanged(int new_state) = 0;
virtual void SetOmniboxSuggestions(
std::unique_ptr<OmniboxSuggestions> suggestions) = 0;
// Tab handling.
virtual void AppendToTabList(bool incognito,
......
......@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/vr/elements/ui_texture.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/ui_unsupported_mode.h"
#include "components/security_state/core/security_state.h"
#include "ui/gfx/geometry/rect_f.h"
......
......@@ -10,7 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/vr/elements/render_text_wrapper.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "components/security_state/core/security_state.h"
#include "components/toolbar/vector_icons.h"
#include "components/url_formatter/url_formatter.h"
......
......@@ -10,7 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/vr/elements/ui_texture.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/ui_unsupported_mode.h"
namespace gfx {
......
......@@ -10,6 +10,7 @@
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/reticle_model.h"
#include "chrome/browser/vr/model/speech_recognition_model.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/model/web_vr_timeout_state.h"
namespace vr {
......@@ -33,6 +34,7 @@ struct Model {
ModalPromptType active_modal_prompt_type = kModalPromptTypeNone;
ToolbarState toolbar_state;
std::vector<OmniboxSuggestion> omnibox_suggestions;
};
......
......@@ -8,8 +8,19 @@ namespace vr {
OmniboxSuggestion::OmniboxSuggestion(const base::string16& new_content,
const base::string16& new_description,
AutocompleteMatch::Type new_type)
: content(new_content), description(new_description), type(new_type) {}
AutocompleteMatch::Type new_type,
GURL new_destination)
: content(new_content),
description(new_description),
type(new_type),
destination(new_destination) {}
OmniboxSuggestion::OmniboxSuggestion(const OmniboxSuggestion& other) {
content = other.content;
description = other.description;
type = other.type;
destination = other.destination;
}
OmniboxSuggestions::OmniboxSuggestions() {}
......
......@@ -7,17 +7,21 @@
#include "base/strings/string16.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "url/gurl.h"
namespace vr {
struct OmniboxSuggestion {
OmniboxSuggestion(const base::string16& new_content,
const base::string16& new_description,
AutocompleteMatch::Type new_type);
AutocompleteMatch::Type new_type,
GURL new_destination);
OmniboxSuggestion(const OmniboxSuggestion& other);
base::string16 content;
base::string16 description;
AutocompleteMatch::Type type;
GURL destination;
};
struct OmniboxSuggestions {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/toolbar_state.h"
namespace vr {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_VR_TOOLBAR_STATE_H_
#define CHROME_BROWSER_VR_TOOLBAR_STATE_H_
#ifndef CHROME_BROWSER_VR_MODEL_TOOLBAR_STATE_H_
#define CHROME_BROWSER_VR_MODEL_TOOLBAR_STATE_H_
#include "components/security_state/core/security_state.h"
#include "url/gurl.h"
......@@ -39,4 +39,4 @@ struct ToolbarState {
} // namespace vr
#endif // CHROME_BROWSER_VR_TOOLBAR_STATE_H_
#endif // CHROME_BROWSER_VR_MODEL_TOOLBAR_STATE_H_
......@@ -18,6 +18,7 @@ class MockBrowserInterface : public UiBrowserInterface {
MOCK_METHOD0(ExitPresent, void());
MOCK_METHOD0(ExitFullscreen, void());
MOCK_METHOD1(Navigate, void(GURL gurl));
MOCK_METHOD0(NavigateBack, void());
MOCK_METHOD0(ExitCct, void());
MOCK_METHOD1(OnUnsupportedMode, void(UiUnsupportedMode mode));
......@@ -25,6 +26,8 @@ class MockBrowserInterface : public UiBrowserInterface {
void(UiUnsupportedMode reason, ExitVrPromptChoice choice));
MOCK_METHOD1(OnContentScreenBoundsChanged, void(const gfx::SizeF& bounds));
MOCK_METHOD1(SetVoiceSearchActive, void(bool active));
MOCK_METHOD1(StartAutocomplete, void(const base::string16& string));
MOCK_METHOD0(StopAutocomplete, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockBrowserInterface);
......
......@@ -5,10 +5,10 @@
#ifndef CHROME_BROWSER_VR_TEST_UI_PIXEL_TEST_H_
#define CHROME_BROWSER_VR_TEST_UI_PIXEL_TEST_H_
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/test/gl_test_environment.h"
#include "chrome/browser/vr/test/mock_browser_interface.h"
#include "chrome/browser/vr/test/mock_content_input_delegate.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/ui.h"
#include "chrome/browser/vr/ui_input_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -13,8 +13,8 @@
#include "chrome/browser/vr/controller_mesh.h"
#include "chrome/browser/vr/model/model.h"
#include "chrome/browser/vr/model/omnibox_suggestions.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/test/constants.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/ui.h"
#include "chrome/browser/vr/ui_element_renderer.h"
#include "chrome/browser/vr/ui_input_manager.h"
......@@ -288,7 +288,7 @@ void VrTestContext::CreateFakeOmniboxSuggestions() {
result->suggestions.emplace_back(OmniboxSuggestion(
base::UTF8ToUTF16("Suggestion ") + base::IntToString16(i + 1),
base::UTF8ToUTF16("Description text"),
AutocompleteMatch::Type::VOICE_SUGGEST));
AutocompleteMatch::Type::VOICE_SUGGEST, GURL("http://www.test.com/")));
}
ui_->SetOmniboxSuggestions(std::move(result));
}
......@@ -322,4 +322,8 @@ void VrTestContext::OnExitVrPromptResult(vr::UiUnsupportedMode reason,
}
void VrTestContext::OnContentScreenBoundsChanged(const gfx::SizeF& bounds) {}
void VrTestContext::StartAutocomplete(const base::string16& string) {}
void VrTestContext::StopAutocomplete() {}
void VrTestContext::Navigate(GURL gurl) {}
} // namespace vr
......@@ -43,6 +43,9 @@ class VrTestContext : public vr::UiBrowserInterface {
vr::ExitVrPromptChoice choice) override;
void OnContentScreenBoundsChanged(const gfx::SizeF& bounds) override;
void SetVoiceSearchActive(bool active) override;
void StartAutocomplete(const base::string16& string) override;
void StopAutocomplete() override;
void Navigate(GURL gurl) override;
private:
unsigned int CreateFakeContentTexture();
......
......@@ -6,7 +6,7 @@
#define CHROME_BROWSER_VR_TOOLBAR_HELPER_H_
#include "chrome/browser/vr/browser_ui_interface.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "chrome/browser/vr/model/toolbar_state.h"
class ToolbarModel;
class ToolbarModelDelegate;
......
......@@ -62,7 +62,7 @@ void Ui::SetFullscreen(bool enabled) {
}
void Ui::SetToolbarState(const ToolbarState& state) {
scene_manager_->SetToolbarState(state);
model_->toolbar_state = state;
}
void Ui::SetIncognito(bool enabled) {
......
......@@ -73,6 +73,8 @@ class Ui : public BrowserUiInterface {
void SetSpeechRecognitionEnabled(bool enabled) override;
void SetRecognitionResult(const base::string16& result) override;
void OnSpeechRecognitionStateChanged(int new_state) override;
void SetOmniboxSuggestions(
std::unique_ptr<OmniboxSuggestions> suggestions) override;
bool ShouldRenderWebVr();
void OnGlInitialized(unsigned int content_texture_id,
......@@ -92,8 +94,6 @@ class Ui : public BrowserUiInterface {
void OnContentBoundsChanged(int width, int height);
void OnPlatformControllerInitialized(PlatformController* controller);
void SetOmniboxSuggestions(std::unique_ptr<OmniboxSuggestions> suggestions);
private:
UiBrowserInterface* browser_;
......
......@@ -8,6 +8,7 @@
#include "chrome/browser/vr/exit_vr_prompt_choice.h"
#include "chrome/browser/vr/ui_unsupported_mode.h"
#include "ui/gfx/geometry/size_f.h"
#include "url/gurl.h"
namespace vr {
......@@ -19,6 +20,7 @@ class UiBrowserInterface {
virtual void ExitPresent() = 0;
virtual void ExitFullscreen() = 0;
virtual void Navigate(GURL gurl) = 0;
virtual void NavigateBack() = 0;
virtual void ExitCct() = 0;
virtual void OnUnsupportedMode(UiUnsupportedMode mode) = 0;
......@@ -26,6 +28,8 @@ class UiBrowserInterface {
ExitVrPromptChoice choice) = 0;
virtual void OnContentScreenBoundsChanged(const gfx::SizeF& bounds) = 0;
virtual void SetVoiceSearchActive(bool active) = 0;
virtual void StartAutocomplete(const base::string16& string) = 0;
virtual void StopAutocomplete() = 0;
};
} // namespace vr
......
......@@ -4,9 +4,9 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/vr/model/toolbar_state.h"
#include "chrome/browser/vr/test/constants.h"
#include "chrome/browser/vr/test/ui_pixel_test.h"
#include "chrome/browser/vr/toolbar_state.h"
#include "components/toolbar/vector_icons.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -170,7 +170,7 @@ UiSceneManager::UiSceneManager(UiBrowserInterface* browser,
CreateSystemIndicators();
CreateUrlBar(model);
CreateSuggestionList(model);
CreateWebVrUrlToast();
CreateWebVrUrlToast(model);
CreateCloseButton();
CreateScreenDimmer();
CreateToasts(model);
......@@ -847,6 +847,8 @@ void UiSceneManager::CreateUrlBar(Model* model) {
url_bar->SetSize(kUrlBarWidth, kUrlBarHeight);
url_bar->AddBinding(VR_BIND(bool, UiSceneManager, this, fullscreen(),
UiElement, url_bar.get(), SetVisible(!value)));
url_bar->AddBinding(VR_BIND_FUNC(ToolbarState, Model, model, toolbar_state,
UrlBar, url_bar.get(), SetToolbarState));
url_bar_ = url_bar.get();
scene_->AddUiElement(k2dBrowsingForeground, std::move(url_bar));
......@@ -925,24 +927,27 @@ TransientElement* UiSceneManager::AddTransientParent(UiElementName name,
return to_return;
}
void UiSceneManager::CreateWebVrUrlToast() {
void UiSceneManager::CreateWebVrUrlToast(Model* model) {
webvr_url_toast_transient_parent_ =
AddTransientParent(kWebVrUrlToastTransientParent, kWebVrViewportAwareRoot,
kWebVrUrlToastTimeoutSeconds, true);
auto url_bar = base::MakeUnique<WebVrUrlToast>(
auto element = base::MakeUnique<WebVrUrlToast>(
512,
base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this)));
url_bar->set_name(kWebVrUrlToast);
url_bar->set_opacity_when_visible(0.8f);
url_bar->set_draw_phase(kPhaseOverlayForeground);
url_bar->SetVisible(true);
url_bar->set_hit_testable(false);
url_bar->SetTranslate(0, kWebVrToastDistance * sin(kWebVrUrlToastRotationRad),
element->set_name(kWebVrUrlToast);
element->set_opacity_when_visible(0.8f);
element->set_draw_phase(kPhaseOverlayForeground);
element->SetVisible(true);
element->set_hit_testable(false);
element->SetTranslate(0, kWebVrToastDistance * sin(kWebVrUrlToastRotationRad),
-kWebVrToastDistance * cos(kWebVrUrlToastRotationRad));
url_bar->SetRotate(1, 0, 0, kWebVrUrlToastRotationRad);
url_bar->SetSize(kWebVrUrlToastWidth, kWebVrUrlToastHeight);
webvr_url_toast_ = url_bar.get();
scene_->AddUiElement(kWebVrUrlToastTransientParent, std::move(url_bar));
element->SetRotate(1, 0, 0, kWebVrUrlToastRotationRad);
element->SetSize(kWebVrUrlToastWidth, kWebVrUrlToastHeight);
element->AddBinding(VR_BIND_FUNC(ToolbarState, Model, model, toolbar_state,
WebVrUrlToast, element.get(),
SetToolbarState));
webvr_url_toast_ = element.get();
scene_->AddUiElement(kWebVrUrlToastTransientParent, std::move(element));
}
void UiSceneManager::CreateCloseButton() {
......@@ -1417,11 +1422,6 @@ void UiSceneManager::OnExitPromptChoice(bool chose_exit,
: ExitVrPromptChoice::CHOICE_STAY);
}
void UiSceneManager::SetToolbarState(const ToolbarState& state) {
url_bar_->SetToolbarState(state);
webvr_url_toast_->SetToolbarState(state);
}
void UiSceneManager::SetIsExiting() {
if (exiting_)
return;
......
......@@ -124,7 +124,6 @@ class UiSceneManager {
// BrowserUiInterface support methods.
void SetFullscreen(bool fullscreen);
void SetIncognito(bool incognito);
void SetToolbarState(const ToolbarState& state);
void SetWebVrMode(bool web_vr, bool show_toast);
void SetIsExiting();
void SetVideoCapturingIndicator(bool enabled);
......@@ -174,7 +173,7 @@ class UiSceneManager {
void CreateViewportAwareRoot();
void CreateUrlBar(Model* model);
void CreateSuggestionList(Model* model);
void CreateWebVrUrlToast();
void CreateWebVrUrlToast(Model* model);
void CreateCloseButton();
void CreateExitPrompt(Model* model);
void CreateAudioPermissionPrompt(Model* model);
......
......@@ -816,7 +816,7 @@ TEST_F(UiSceneManagerTest, OmniboxSuggestionBindings) {
model_->omnibox_suggestions.emplace_back(
OmniboxSuggestion(base::string16(), base::string16(),
AutocompleteMatch::Type::VOICE_SUGGEST));
AutocompleteMatch::Type::VOICE_SUGGEST, GURL()));
OnBeginFrame();
EXPECT_EQ(container->children().size(), 1u);
EXPECT_GT(NumVisibleChildren(kSuggestionLayout), initially_visible);
......
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