Commit 336131fe authored by Biao She's avatar Biao She Committed by Commit Bot

Navigate to webpage directly if the recognition result is a URL


Bug: 779590
Change-Id: Ie2897ca6de11a4a84c0b54eb3937b355b46a0f33
Reviewed-on: https://chromium-review.googlesource.com/789536
Commit-Queue: Biao She <bshe@chromium.org>
Reviewed-by: default avatarChristopher Grant <cjgrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519718}
parent 55cd40ff
......@@ -755,7 +755,6 @@ public class VrShellImpl
@CalledByNative
private void loadUrl(String url) {
// TODO(bshe): reuse voice suggestion provider if possible.
assert mTab != null;
mTab.loadUrl(new LoadUrlParams(url));
}
......
......@@ -13,16 +13,18 @@
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/search_engines/util.h"
namespace vr {
namespace vr_shell {
AutocompleteController::AutocompleteController(BrowserUiInterface* ui)
: profile_(ProfileManager::GetActiveUserProfile()),
autocomplete_controller_(base::MakeUnique<::AutocompleteController>(
base::MakeUnique<ChromeAutocompleteProviderClient>(profile_),
this,
AutocompleteClassifier::DefaultOmniboxProviders())),
ui_(ui) {}
AutocompleteController::AutocompleteController(vr::BrowserUiInterface* ui)
: profile_(ProfileManager::GetActiveUserProfile()), ui_(ui) {
auto client = base::MakeUnique<ChromeAutocompleteProviderClient>(profile_);
client_ = client.get();
autocomplete_controller_ = base::MakeUnique<::AutocompleteController>(
std::move(client), this,
AutocompleteClassifier::DefaultOmniboxProviders());
}
AutocompleteController::~AutocompleteController() = default;
......@@ -37,13 +39,29 @@ void AutocompleteController::Stop() {
autocomplete_controller_->Stop(true);
}
GURL AutocompleteController::GetUrlFromVoiceInput(const base::string16& input) {
AutocompleteMatch match;
base::string16 culled_input;
base::RemoveChars(input, base::ASCIIToUTF16(" "), &culled_input);
client_->Classify(culled_input, false, false,
metrics::OmniboxEventProto::INVALID_SPEC, &match, nullptr);
if (match.destination_url.is_valid() &&
(match.type == AutocompleteMatchType::URL_WHAT_YOU_TYPED ||
match.type == AutocompleteMatchType::HISTORY_URL ||
match.type == AutocompleteMatchType::NAVSUGGEST)) {
return match.destination_url;
}
return GURL(GetDefaultSearchURLForSearchTerms(
client_->GetTemplateURLService(), input));
}
void AutocompleteController::OnResultChanged(bool default_match_changed) {
auto suggestions = base::MakeUnique<OmniboxSuggestions>();
auto suggestions = base::MakeUnique<vr::OmniboxSuggestions>();
for (const auto& match : autocomplete_controller_->result()) {
suggestions->suggestions.emplace_back(OmniboxSuggestion(
suggestions->suggestions.emplace_back(vr::OmniboxSuggestion(
match.contents, match.description, match.type, match.destination_url));
}
ui_->SetOmniboxSuggestions(std::move(suggestions));
}
} // namespace vr
} // namespace vr_shell
......@@ -10,33 +10,45 @@
#include "base/macros.h"
#include "base/values.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "url/gurl.h"
class AutocompleteController;
class ChromeAutocompleteProviderClient;
class Profile;
namespace vr {
class BrowserUiInterface;
}
namespace vr_shell {
class AutocompleteController : public AutocompleteControllerDelegate {
public:
explicit AutocompleteController(BrowserUiInterface* ui);
explicit AutocompleteController(vr::BrowserUiInterface* ui);
AutocompleteController();
~AutocompleteController() override;
void Start(const base::string16& text);
void Stop();
// If |input| can be classified as URL, this function returns a GURL
// representation of that URL. Otherwise, it returns a GURL which navigates
// to the default search engine with |input| as query.
// This function runs independently of any currently-running autocomplete
// session.
GURL GetUrlFromVoiceInput(const base::string16& input);
private:
void OnResultChanged(bool default_match_changed) override;
Profile* profile_;
ChromeAutocompleteProviderClient* client_;
std::unique_ptr<::AutocompleteController> autocomplete_controller_;
BrowserUiInterface* ui_;
vr::BrowserUiInterface* ui_;
DISALLOW_COPY_AND_ASSIGN(AutocompleteController);
};
} // namespace vr
} // namespace vr_shell
#endif // CHROME_BROWSER_ANDROID_VR_SHELL_AUTOCOMPLETE_CONTROLLER_H_
......@@ -32,14 +32,11 @@
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/vr/toolbar_helper.h"
#include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/vr/web_contents_event_forwarder.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/util.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
......@@ -156,7 +153,7 @@ VrShell::VrShell(JNIEnv* env,
ui_initial_state, reprojected_rendering_, HasDaydreamSupport(env));
ui_ = gl_thread_.get();
toolbar_ = base::MakeUnique<vr::ToolbarHelper>(ui_, this);
autocomplete_controller_ = base::MakeUnique<vr::AutocompleteController>(ui_);
autocomplete_controller_ = base::MakeUnique<AutocompleteController>(ui_);
gl_thread_->Start();
......@@ -927,14 +924,11 @@ bool VrShell::ShouldDisplayURL() const {
}
void VrShell::OnVoiceResults(const base::string16& result) {
TemplateURLService* template_url_service =
TemplateURLServiceFactory::GetForProfile(
ProfileManager::GetActiveUserProfile());
GURL url(GetDefaultSearchURLForSearchTerms(template_url_service, result));
JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_loadUrl(
env, j_vr_shell_,
base::android::ConvertUTF8ToJavaString(env, url.spec()));
base::android::ConvertUTF8ToJavaString(
env, autocomplete_controller_->GetUrlFromVoiceInput(result).spec()));
}
// ----------------------------------------------------------------------------
......
......@@ -39,7 +39,6 @@ class WindowAndroid;
} // namespace ui
namespace vr {
class AutocompleteController;
class BrowserUiInterface;
class ToolbarHelper;
class WebContentsEventForwarder;
......@@ -48,6 +47,7 @@ class WebContentsEventForwarder;
namespace vr_shell {
class AndroidUiGestureTarget;
class AutocompleteController;
class VrCompositor;
class VrGLThread;
class VrMetricsHelper;
......@@ -252,7 +252,7 @@ class VrShell : device::GvrGamepadDataProvider,
// These instances make use of ui_ (provided by gl_thread_), and hence must be
// destroyed before gl_thread_;
std::unique_ptr<vr::ToolbarHelper> toolbar_;
std::unique_ptr<vr::AutocompleteController> autocomplete_controller_;
std::unique_ptr<vr_shell::AutocompleteController> autocomplete_controller_;
std::unique_ptr<vr::SpeechRecognizer> speech_recognizer_;
bool reprojected_rendering_;
......
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