Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / home_page_overlay_handler.cc
blob727305134635051f684e6c03963a044cc13493a6
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/home_page_overlay_handler.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/values.h"
10 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
11 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/metrics/proto/omnibox_event.pb.h"
16 #include "components/omnibox/browser/autocomplete_classifier.h"
17 #include "components/omnibox/browser/autocomplete_controller.h"
18 #include "components/omnibox/browser/autocomplete_input.h"
19 #include "components/omnibox/browser/autocomplete_result.h"
20 #include "content/public/browser/web_ui.h"
22 namespace options {
24 HomePageOverlayHandler::HomePageOverlayHandler() {
27 HomePageOverlayHandler::~HomePageOverlayHandler() {
30 void HomePageOverlayHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback(
32 "requestAutocompleteSuggestionsForHomePage",
33 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions,
34 base::Unretained(this)));
37 void HomePageOverlayHandler::InitializeHandler() {
38 Profile* profile = Profile::FromWebUI(web_ui());
39 autocomplete_controller_.reset(new AutocompleteController(
40 make_scoped_ptr(new ChromeAutocompleteProviderClient(profile)), this,
41 AutocompleteClassifier::kDefaultOmniboxProviders));
44 void HomePageOverlayHandler::GetLocalizedValues(
45 base::DictionaryValue* localized_strings) {
46 RegisterTitle(localized_strings, "homePageOverlay",
47 IDS_OPTIONS_HOMEPAGE_TITLE);
50 void HomePageOverlayHandler::RequestAutocompleteSuggestions(
51 const base::ListValue* args) {
52 base::string16 input;
53 CHECK_EQ(args->GetSize(), 1U);
54 CHECK(args->GetString(0, &input));
56 autocomplete_controller_->Start(AutocompleteInput(
57 input, base::string16::npos, std::string(), GURL(),
58 metrics::OmniboxEventProto::INVALID_SPEC, true, false, false, true, false,
59 ChromeAutocompleteSchemeClassifier(Profile::FromWebUI(web_ui()))));
62 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) {
63 const AutocompleteResult& result = autocomplete_controller_->result();
64 base::ListValue suggestions;
65 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions);
66 web_ui()->CallJavascriptFunction(
67 "HomePageOverlay.updateAutocompleteSuggestions", suggestions);
70 } // namespace options