Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_omnibox.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_omnibox.cc b/chrome/browser/android/vr_shell/vr_omnibox.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0df96be5340ea0138a0ce6d734d76a0c5b04dee0 |
| --- /dev/null |
| +++ b/chrome/browser/android/vr_shell/vr_omnibox.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
bshe
2017/01/23 16:24:36
nit: 2017
cjgrant
2017/01/24 15:31:39
Done.
|
| +// 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_omnibox.h" |
| + |
| +#include <string> |
| + |
| +#include "components/omnibox/browser/autocomplete_classifier.h" |
| +#include "components/omnibox/browser/autocomplete_controller.h" |
| +#include "components/omnibox/browser/autocomplete_input.h" |
|
bshe
2017/01/23 16:24:36
I am not familiar with the classes that are used h
cjgrant
2017/01/24 15:31:39
Yes, I agree. Lets finish the first pass, then I'
|
| + |
| +namespace vr_shell { |
| + |
| +VrOmnibox::VrOmnibox(UiInterface* ui) |
| + : ui_(ui), |
| + profile_(ProfileManager::GetActiveUserProfile()), |
| + autocomplete_controller_(new AutocompleteController( |
|
mthiesse
2017/01/20 18:48:35
s/new AutocompleteController(/base::MakeUnique<Aut
cjgrant
2017/01/24 15:31:39
Done. Cool, I didn't know the intent of MakeUniqu
|
| + base::WrapUnique( |
| + new ChromeAutocompleteProviderClient(profile_.get())), |
| + this, |
| + AutocompleteClassifier::kDefaultOmniboxProviders)) {} |
| + |
| +VrOmnibox::~VrOmnibox() {} |
|
bshe
2017/01/23 16:24:37
use "= default"?
cjgrant
2017/01/24 15:31:39
Done. Funny that it's more characters than the al
|
| + |
| +void VrOmnibox::HandleInput(const base::DictionaryValue& dict) { |
| + base::string16 text; |
| + CHECK(dict.GetString("text", &text)); |
| + |
| + // TODO(cjgrant): Scrub and appropriately tune these parameters. |
| + GURL current_url; |
| + size_t cursor_pos = base::string16::npos; |
| + std::string desired_tld; |
| + metrics::OmniboxEventProto::PageClassification page_classification = |
| + metrics::OmniboxEventProto::OTHER; |
| + bool prevent_inline_autocomplete = false; |
| + bool prefer_keyword = false; |
| + bool allow_exact_keyword_match = false; |
| + bool want_asynchronous_matches = true; |
| + bool from_omnibox_focus = false; |
| + |
| + input_ = AutocompleteInput( |
|
mthiesse
2017/01/20 18:48:35
Don't think copying is necessary here, even though
cjgrant
2017/01/24 15:31:39
This was a direct ripoff of Clank's approach.
htt
|
| + text, cursor_pos, desired_tld, current_url, page_classification, |
| + prevent_inline_autocomplete, prefer_keyword, allow_exact_keyword_match, |
| + want_asynchronous_matches, from_omnibox_focus, |
| + ChromeAutocompleteSchemeClassifier(profile_.get())); |
| + autocomplete_controller_->Start(input_); |
| +} |
| + |
| +void VrOmnibox::OnResultChanged(bool default_match_changed) { |
| + const AutocompleteResult& result = autocomplete_controller_->result(); |
| + std::unique_ptr<base::ListValue> suggestions(new base::ListValue); |
|
mthiesse
2017/01/20 18:48:35
Prefer base::MakeUnique here and below.
( std::un
cjgrant
2017/01/24 15:31:39
Done, except I'm using auto. Other Chrome code do
|
| + |
| + for (const AutocompleteMatch& match : result) { |
| + std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
| + entry->SetString("description", match.contents); |
| + entry->SetString("url", match.destination_url.spec()); |
| + suggestions->Append(std::move(entry)); |
| + } |
| + |
| + ui_->SetOmniboxSuggestions(std::move(suggestions)); |
| +} |
| + |
| +} // namespace vr_shell |