Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / home_page_overlay_handler.cc
blob80b98ae46ae33f989d4a205f579cfd24ff8a87f6
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/autocomplete_classifier.h"
11 #include "chrome/browser/autocomplete/autocomplete_controller.h"
12 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "components/metrics/proto/omnibox_event.pb.h"
17 #include "components/omnibox/autocomplete_input.h"
18 #include "components/omnibox/autocomplete_result.h"
19 #include "content/public/browser/web_ui.h"
21 namespace options {
23 HomePageOverlayHandler::HomePageOverlayHandler() {
26 HomePageOverlayHandler::~HomePageOverlayHandler() {
29 void HomePageOverlayHandler::RegisterMessages() {
30 web_ui()->RegisterMessageCallback(
31 "requestAutocompleteSuggestionsForHomePage",
32 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions,
33 base::Unretained(this)));
36 void HomePageOverlayHandler::InitializeHandler() {
37 Profile* profile = Profile::FromWebUI(web_ui());
38 autocomplete_controller_.reset(new AutocompleteController(profile,
39 TemplateURLServiceFactory::GetForProfile(profile), this,
40 AutocompleteClassifier::kDefaultOmniboxProviders));
43 void HomePageOverlayHandler::GetLocalizedValues(
44 base::DictionaryValue* localized_strings) {
45 RegisterTitle(localized_strings, "homePageOverlay",
46 IDS_OPTIONS_HOMEPAGE_TITLE);
49 void HomePageOverlayHandler::RequestAutocompleteSuggestions(
50 const base::ListValue* args) {
51 base::string16 input;
52 CHECK_EQ(args->GetSize(), 1U);
53 CHECK(args->GetString(0, &input));
55 autocomplete_controller_->Start(AutocompleteInput(
56 input, base::string16::npos, std::string(), GURL(),
57 metrics::OmniboxEventProto::INVALID_SPEC, true, false, false, true,
58 ChromeAutocompleteSchemeClassifier(Profile::FromWebUI(web_ui()))));
61 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) {
62 const AutocompleteResult& result = autocomplete_controller_->result();
63 base::ListValue suggestions;
64 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions);
65 web_ui()->CallJavascriptFunction(
66 "HomePageOverlay.updateAutocompleteSuggestions", suggestions);
69 } // namespace options