Commit 41a2423f authored by Ian Vollick's avatar Ian Vollick Committed by Commit Bot

[vr] Hide the voice search button in incognito mode

With this change, the voice search button is disabled via binding when
we are in incognito mode. Additionally, we store a bit on the model for
when we've got experimental VR features enabled so that it may more
easily be bound and toggled in tests. This also means that the ui scene
manager no longer needs to retain a pointer to the voice search button.
Further, we no longer add the button to control_elements_ since it will
inherit the visibility of the URL bar due to being in its subtree.

Bug: 779592
Change-Id: I92832f46b4cdf33e7a9caf57076001a24ff9ab83
Reviewed-on: https://chromium-review.googlesource.com/748774
Commit-Queue: Ian Vollick <vollick@chromium.org>
Reviewed-by: default avatarBiao She <bshe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513233}
parent ba1cb82a
...@@ -28,6 +28,9 @@ struct Model { ...@@ -28,6 +28,9 @@ struct Model {
ControllerModel controller; ControllerModel controller;
ReticleModel reticle; ReticleModel reticle;
bool experimental_features_enabled = false;
bool incognito = false;
std::vector<OmniboxSuggestion> omnibox_suggestions; std::vector<OmniboxSuggestion> omnibox_suggestions;
}; };
......
...@@ -85,6 +85,11 @@ bool UiSceneManagerTest::IsVisible(UiElementName name) const { ...@@ -85,6 +85,11 @@ bool UiSceneManagerTest::IsVisible(UiElementName name) const {
return IsElementFacingCamera(element); return IsElementFacingCamera(element);
} }
void UiSceneManagerTest::SetIncognito(bool incognito) {
model_->incognito = incognito;
manager_->SetIncognito(incognito);
}
void UiSceneManagerTest::VerifyElementsVisible( void UiSceneManagerTest::VerifyElementsVisible(
const std::string& trace_context, const std::string& trace_context,
const std::set<UiElementName>& names) const { const std::set<UiElementName>& names) const {
......
...@@ -50,6 +50,8 @@ class UiSceneManagerTest : public testing::Test { ...@@ -50,6 +50,8 @@ class UiSceneManagerTest : public testing::Test {
bool IsVisible(UiElementName name) const; bool IsVisible(UiElementName name) const;
void SetIncognito(bool incognito);
// Verify that only the elements in the set are visible. // Verify that only the elements in the set are visible.
void VerifyElementsVisible(const std::string& debug_name, void VerifyElementsVisible(const std::string& debug_name,
const std::set<UiElementName>& names) const; const std::set<UiElementName>& names) const;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/vr/ui_scene.h" #include "chrome/browser/vr/ui_scene.h"
#include "chrome/browser/vr/ui_scene_manager.h" #include "chrome/browser/vr/ui_scene_manager.h"
#include "chrome/browser/vr/vr_shell_renderer.h" #include "chrome/browser/vr/vr_shell_renderer.h"
#include "chrome/common/chrome_features.h"
namespace vr { namespace vr {
...@@ -33,6 +34,8 @@ Ui::Ui(UiBrowserInterface* browser, ...@@ -33,6 +34,8 @@ Ui::Ui(UiBrowserInterface* browser,
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
model_->started_for_autopresentation = model_->started_for_autopresentation =
ui_initial_state.web_vr_autopresentation_expected; ui_initial_state.web_vr_autopresentation_expected;
model_->experimental_features_enabled =
base::FeatureList::IsEnabled(features::kExperimentalVRFeatures);
} }
Ui::~Ui() = default; Ui::~Ui() = default;
...@@ -56,6 +59,7 @@ void Ui::SetToolbarState(const ToolbarState& state) { ...@@ -56,6 +59,7 @@ void Ui::SetToolbarState(const ToolbarState& state) {
} }
void Ui::SetIncognito(bool enabled) { void Ui::SetIncognito(bool enabled) {
model_->incognito = enabled;
scene_manager_->SetIncognito(enabled); scene_manager_->SetIncognito(enabled);
} }
......
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
#include "chrome/browser/vr/ui_scene_constants.h" #include "chrome/browser/vr/ui_scene_constants.h"
#include "chrome/browser/vr/vector_icons/vector_icons.h" #include "chrome/browser/vr/vector_icons/vector_icons.h"
#include "chrome/browser/vr/vr_gl_util.h" #include "chrome/browser/vr/vr_gl_util.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -556,20 +555,23 @@ void UiSceneManager::CreateViewportAwareRoot() { ...@@ -556,20 +555,23 @@ void UiSceneManager::CreateViewportAwareRoot() {
} }
void UiSceneManager::CreateVoiceSearchUiGroup(Model* model) { void UiSceneManager::CreateVoiceSearchUiGroup(Model* model) {
std::unique_ptr<UiElement> element; std::unique_ptr<UiElement> element = base::MakeUnique<Button>(
auto voice_search_button = base::MakeUnique<Button>(
base::Bind(&UiSceneManager::OnVoiceSearchButtonClicked, base::Bind(&UiSceneManager::OnVoiceSearchButtonClicked,
base::Unretained(this)), base::Unretained(this)),
base::MakeUnique<VectorIconButtonTexture>(vector_icons::kMicrophoneIcon)); base::MakeUnique<VectorIconButtonTexture>(vector_icons::kMicrophoneIcon));
voice_search_button_ = voice_search_button.get();
element = std::move(voice_search_button);
element->set_name(kVoiceSearchButton); element->set_name(kVoiceSearchButton);
element->set_draw_phase(kPhaseForeground); element->set_draw_phase(kPhaseForeground);
element->SetTranslate(kVoiceSearchButtonXOffset, 0.f, 0.f); element->SetTranslate(kVoiceSearchButtonXOffset, 0.f, 0.f);
element->SetSize(kCloseButtonWidth, kCloseButtonHeight); element->SetSize(kCloseButtonWidth, kCloseButtonHeight);
element->set_x_anchoring(XAnchoring::XRIGHT); element->set_x_anchoring(XAnchoring::XRIGHT);
control_elements_.push_back(element.get()); element->AddBinding(base::MakeUnique<Binding<bool>>(
base::Bind(
[](Model* m) {
return !m->incognito && m->experimental_features_enabled;
},
base::Unretained(model)),
base::Bind([](UiElement* e, const bool& v) { e->SetVisible(v); },
element.get())));
scene_->AddUiElement(kUrlBar, std::move(element)); scene_->AddUiElement(kUrlBar, std::move(element));
auto speech_recognition_prompt = base::MakeUnique<UiElement>(); auto speech_recognition_prompt = base::MakeUnique<UiElement>();
...@@ -1003,10 +1005,6 @@ void UiSceneManager::ConfigureScene() { ...@@ -1003,10 +1005,6 @@ void UiSceneManager::ConfigureScene() {
element->SetVisible(controls_visible); element->SetVisible(controls_visible);
} }
if (!base::FeatureList::IsEnabled(features::kExperimentalVRFeatures)) {
voice_search_button_->SetVisible(false);
}
// Close button is a special control element that needs to be hidden when in // Close button is a special control element that needs to be hidden when in
// WebVR, but it needs to be visible when in cct or fullscreen. // WebVR, but it needs to be visible when in cct or fullscreen.
close_button_->SetVisible(browsing_mode && (fullscreen_ || in_cct_)); close_button_->SetVisible(browsing_mode && (fullscreen_ || in_cct_));
......
...@@ -207,7 +207,6 @@ class UiSceneManager { ...@@ -207,7 +207,6 @@ class UiSceneManager {
Rect* ceiling_ = nullptr; Rect* ceiling_ = nullptr;
Grid* floor_ = nullptr; Grid* floor_ = nullptr;
UiElement* close_button_ = nullptr; UiElement* close_button_ = nullptr;
UiElement* voice_search_button_ = nullptr;
UrlBar* url_bar_ = nullptr; UrlBar* url_bar_ = nullptr;
TransientElement* webvr_url_toast_transient_parent_ = nullptr; TransientElement* webvr_url_toast_transient_parent_ = nullptr;
WebVrUrlToast* webvr_url_toast_ = nullptr; WebVrUrlToast* webvr_url_toast_ = nullptr;
......
...@@ -196,7 +196,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) { ...@@ -196,7 +196,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) {
GetBackgroundColor(&fullscreen_background); GetBackgroundColor(&fullscreen_background);
EXPECT_NE(initial_background, fullscreen_background); EXPECT_NE(initial_background, fullscreen_background);
manager_->SetIncognito(true); SetIncognito(true);
// Make sure background has changed for incognito. // Make sure background has changed for incognito.
SkColor incognito_background = SK_ColorBLACK; SkColor incognito_background = SK_ColorBLACK;
...@@ -204,7 +204,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) { ...@@ -204,7 +204,7 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) {
EXPECT_NE(fullscreen_background, incognito_background); EXPECT_NE(fullscreen_background, incognito_background);
EXPECT_NE(initial_background, incognito_background); EXPECT_NE(initial_background, incognito_background);
manager_->SetIncognito(false); SetIncognito(false);
SkColor no_longer_incognito_background = SK_ColorBLACK; SkColor no_longer_incognito_background = SK_ColorBLACK;
GetBackgroundColor(&no_longer_incognito_background); GetBackgroundColor(&no_longer_incognito_background);
EXPECT_EQ(fullscreen_background, no_longer_incognito_background); EXPECT_EQ(fullscreen_background, no_longer_incognito_background);
...@@ -214,17 +214,40 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) { ...@@ -214,17 +214,40 @@ TEST_F(UiSceneManagerTest, UiUpdatesForIncognito) {
GetBackgroundColor(&no_longer_fullscreen_background); GetBackgroundColor(&no_longer_fullscreen_background);
EXPECT_EQ(initial_background, no_longer_fullscreen_background); EXPECT_EQ(initial_background, no_longer_fullscreen_background);
manager_->SetIncognito(true); SetIncognito(true);
SkColor incognito_again_background = SK_ColorBLACK; SkColor incognito_again_background = SK_ColorBLACK;
GetBackgroundColor(&incognito_again_background); GetBackgroundColor(&incognito_again_background);
EXPECT_EQ(incognito_background, incognito_again_background); EXPECT_EQ(incognito_background, incognito_again_background);
manager_->SetIncognito(false); SetIncognito(false);
SkColor no_longer_incognito_again_background = SK_ColorBLACK; SkColor no_longer_incognito_again_background = SK_ColorBLACK;
GetBackgroundColor(&no_longer_incognito_again_background); GetBackgroundColor(&no_longer_incognito_again_background);
EXPECT_EQ(initial_background, no_longer_incognito_again_background); EXPECT_EQ(initial_background, no_longer_incognito_again_background);
} }
TEST_F(UiSceneManagerTest, VoiceSearchHiddenInIncognito) {
MakeManager(kNotInCct, kNotInWebVr);
model_->experimental_features_enabled = true;
EXPECT_TRUE(OnBeginFrame());
EXPECT_TRUE(IsVisible(kVoiceSearchButton));
SetIncognito(true);
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
// If experimental VR features are disabled, then we should never show the
// button, regardless of whether or not we're in incognito mode.
model_->experimental_features_enabled = false;
SetIncognito(false);
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
SetIncognito(true);
EXPECT_TRUE(OnBeginFrame());
EXPECT_FALSE(IsVisible(kVoiceSearchButton));
}
TEST_F(UiSceneManagerTest, WebVrAutopresented) { TEST_F(UiSceneManagerTest, WebVrAutopresented) {
MakeAutoPresentedManager(); MakeAutoPresentedManager();
......
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