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 ...@@ -755,7 +755,6 @@ public class VrShellImpl
@CalledByNative @CalledByNative
private void loadUrl(String url) { private void loadUrl(String url) {
// TODO(bshe): reuse voice suggestion provider if possible.
assert mTab != null; assert mTab != null;
mTab.loadUrl(new LoadUrlParams(url)); mTab.loadUrl(new LoadUrlParams(url));
} }
......
...@@ -13,16 +13,18 @@ ...@@ -13,16 +13,18 @@
#include "components/omnibox/browser/autocomplete_classifier.h" #include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h" #include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h" #include "components/omnibox/browser/autocomplete_input.h"
#include "components/search_engines/util.h"
namespace vr { namespace vr_shell {
AutocompleteController::AutocompleteController(BrowserUiInterface* ui) AutocompleteController::AutocompleteController(vr::BrowserUiInterface* ui)
: profile_(ProfileManager::GetActiveUserProfile()), : profile_(ProfileManager::GetActiveUserProfile()), ui_(ui) {
autocomplete_controller_(base::MakeUnique<::AutocompleteController>( auto client = base::MakeUnique<ChromeAutocompleteProviderClient>(profile_);
base::MakeUnique<ChromeAutocompleteProviderClient>(profile_), client_ = client.get();
this, autocomplete_controller_ = base::MakeUnique<::AutocompleteController>(
AutocompleteClassifier::DefaultOmniboxProviders())), std::move(client), this,
ui_(ui) {} AutocompleteClassifier::DefaultOmniboxProviders());
}
AutocompleteController::~AutocompleteController() = default; AutocompleteController::~AutocompleteController() = default;
...@@ -37,13 +39,29 @@ void AutocompleteController::Stop() { ...@@ -37,13 +39,29 @@ void AutocompleteController::Stop() {
autocomplete_controller_->Stop(true); 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) { 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()) { 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)); match.contents, match.description, match.type, match.destination_url));
} }
ui_->SetOmniboxSuggestions(std::move(suggestions)); ui_->SetOmniboxSuggestions(std::move(suggestions));
} }
} // namespace vr } // namespace vr_shell
...@@ -10,33 +10,45 @@ ...@@ -10,33 +10,45 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h" #include "base/values.h"
#include "components/omnibox/browser/autocomplete_controller_delegate.h" #include "components/omnibox/browser/autocomplete_controller_delegate.h"
#include "url/gurl.h"
class AutocompleteController; class AutocompleteController;
class ChromeAutocompleteProviderClient;
class Profile; class Profile;
namespace vr { namespace vr {
class BrowserUiInterface; class BrowserUiInterface;
}
namespace vr_shell {
class AutocompleteController : public AutocompleteControllerDelegate { class AutocompleteController : public AutocompleteControllerDelegate {
public: public:
explicit AutocompleteController(BrowserUiInterface* ui); explicit AutocompleteController(vr::BrowserUiInterface* ui);
AutocompleteController(); AutocompleteController();
~AutocompleteController() override; ~AutocompleteController() override;
void Start(const base::string16& text); void Start(const base::string16& text);
void Stop(); 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: private:
void OnResultChanged(bool default_match_changed) override; void OnResultChanged(bool default_match_changed) override;
Profile* profile_; Profile* profile_;
ChromeAutocompleteProviderClient* client_;
std::unique_ptr<::AutocompleteController> autocomplete_controller_; std::unique_ptr<::AutocompleteController> autocomplete_controller_;
BrowserUiInterface* ui_; vr::BrowserUiInterface* ui_;
DISALLOW_COPY_AND_ASSIGN(AutocompleteController); DISALLOW_COPY_AND_ASSIGN(AutocompleteController);
}; };
} // namespace vr } // namespace vr_shell
#endif // CHROME_BROWSER_ANDROID_VR_SHELL_AUTOCOMPLETE_CONTROLLER_H_ #endif // CHROME_BROWSER_ANDROID_VR_SHELL_AUTOCOMPLETE_CONTROLLER_H_
...@@ -32,14 +32,11 @@ ...@@ -32,14 +32,11 @@
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
#include "chrome/browser/profiles/profile_manager.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/toolbar_helper.h"
#include "chrome/browser/vr/vr_tab_helper.h" #include "chrome/browser/vr/vr_tab_helper.h"
#include "chrome/browser/vr/web_contents_event_forwarder.h" #include "chrome/browser/vr/web_contents_event_forwarder.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.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_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
...@@ -156,7 +153,7 @@ VrShell::VrShell(JNIEnv* env, ...@@ -156,7 +153,7 @@ VrShell::VrShell(JNIEnv* env,
ui_initial_state, reprojected_rendering_, HasDaydreamSupport(env)); ui_initial_state, reprojected_rendering_, HasDaydreamSupport(env));
ui_ = gl_thread_.get(); ui_ = gl_thread_.get();
toolbar_ = base::MakeUnique<vr::ToolbarHelper>(ui_, this); toolbar_ = base::MakeUnique<vr::ToolbarHelper>(ui_, this);
autocomplete_controller_ = base::MakeUnique<vr::AutocompleteController>(ui_); autocomplete_controller_ = base::MakeUnique<AutocompleteController>(ui_);
gl_thread_->Start(); gl_thread_->Start();
...@@ -927,14 +924,11 @@ bool VrShell::ShouldDisplayURL() const { ...@@ -927,14 +924,11 @@ bool VrShell::ShouldDisplayURL() const {
} }
void VrShell::OnVoiceResults(const base::string16& result) { 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(); JNIEnv* env = base::android::AttachCurrentThread();
Java_VrShellImpl_loadUrl( Java_VrShellImpl_loadUrl(
env, j_vr_shell_, 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; ...@@ -39,7 +39,6 @@ class WindowAndroid;
} // namespace ui } // namespace ui
namespace vr { namespace vr {
class AutocompleteController;
class BrowserUiInterface; class BrowserUiInterface;
class ToolbarHelper; class ToolbarHelper;
class WebContentsEventForwarder; class WebContentsEventForwarder;
...@@ -48,6 +47,7 @@ class WebContentsEventForwarder; ...@@ -48,6 +47,7 @@ class WebContentsEventForwarder;
namespace vr_shell { namespace vr_shell {
class AndroidUiGestureTarget; class AndroidUiGestureTarget;
class AutocompleteController;
class VrCompositor; class VrCompositor;
class VrGLThread; class VrGLThread;
class VrMetricsHelper; class VrMetricsHelper;
...@@ -252,7 +252,7 @@ class VrShell : device::GvrGamepadDataProvider, ...@@ -252,7 +252,7 @@ class VrShell : device::GvrGamepadDataProvider,
// These instances make use of ui_ (provided by gl_thread_), and hence must be // These instances make use of ui_ (provided by gl_thread_), and hence must be
// destroyed before gl_thread_; // destroyed before gl_thread_;
std::unique_ptr<vr::ToolbarHelper> toolbar_; 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_; std::unique_ptr<vr::SpeechRecognizer> speech_recognizer_;
bool reprojected_rendering_; 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