OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/options/home_page_overlay_handler.h" | 5 #include "chrome/browser/ui/webui/options/home_page_overlay_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
11 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 11 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
12 #include "chrome/browser/autocomplete/autocomplete_result.h" | 12 #include "chrome/browser/autocomplete/autocomplete_result.h" |
13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "components/autocomplete/autocomplete_input.h" | 16 #include "components/autocomplete/autocomplete_input.h" |
16 #include "components/metrics/proto/omnibox_event.pb.h" | 17 #include "components/metrics/proto/omnibox_event.pb.h" |
17 #include "content/public/browser/web_ui.h" | 18 #include "content/public/browser/web_ui.h" |
18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 | 21 |
21 namespace options { | 22 namespace options { |
22 | 23 |
23 HomePageOverlayHandler::HomePageOverlayHandler() { | 24 HomePageOverlayHandler::HomePageOverlayHandler() { |
24 } | 25 } |
25 | 26 |
26 HomePageOverlayHandler::~HomePageOverlayHandler() { | 27 HomePageOverlayHandler::~HomePageOverlayHandler() { |
27 } | 28 } |
28 | 29 |
29 void HomePageOverlayHandler::RegisterMessages() { | 30 void HomePageOverlayHandler::RegisterMessages() { |
30 web_ui()->RegisterMessageCallback( | 31 web_ui()->RegisterMessageCallback( |
31 "requestAutocompleteSuggestionsForHomePage", | 32 "requestAutocompleteSuggestionsForHomePage", |
32 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions, | 33 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions, |
33 base::Unretained(this))); | 34 base::Unretained(this))); |
34 } | 35 } |
35 | 36 |
36 void HomePageOverlayHandler::InitializeHandler() { | 37 void HomePageOverlayHandler::InitializeHandler() { |
37 Profile* profile = Profile::FromWebUI(web_ui()); | 38 Profile* profile = Profile::FromWebUI(web_ui()); |
38 autocomplete_controller_.reset(new AutocompleteController(profile, this, | 39 autocomplete_controller_.reset(new AutocompleteController(profile, |
| 40 TemplateURLServiceFactory::GetForProfile(profile), this, |
39 AutocompleteClassifier::kDefaultOmniboxProviders)); | 41 AutocompleteClassifier::kDefaultOmniboxProviders)); |
40 } | 42 } |
41 | 43 |
42 void HomePageOverlayHandler::GetLocalizedValues( | 44 void HomePageOverlayHandler::GetLocalizedValues( |
43 base::DictionaryValue* localized_strings) { | 45 base::DictionaryValue* localized_strings) { |
44 RegisterTitle(localized_strings, "homePageOverlay", | 46 RegisterTitle(localized_strings, "homePageOverlay", |
45 IDS_OPTIONS_HOMEPAGE_TITLE); | 47 IDS_OPTIONS_HOMEPAGE_TITLE); |
46 } | 48 } |
47 | 49 |
48 void HomePageOverlayHandler::RequestAutocompleteSuggestions( | 50 void HomePageOverlayHandler::RequestAutocompleteSuggestions( |
(...skipping 10 matching lines...) Expand all Loading... |
59 | 61 |
60 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) { | 62 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) { |
61 const AutocompleteResult& result = autocomplete_controller_->result(); | 63 const AutocompleteResult& result = autocomplete_controller_->result(); |
62 base::ListValue suggestions; | 64 base::ListValue suggestions; |
63 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); | 65 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); |
64 web_ui()->CallJavascriptFunction( | 66 web_ui()->CallJavascriptFunction( |
65 "HomePageOverlay.updateAutocompleteSuggestions", suggestions); | 67 "HomePageOverlay.updateAutocompleteSuggestions", suggestions); |
66 } | 68 } |
67 | 69 |
68 } // namespace options | 70 } // namespace options |
OLD | NEW |