| 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" | |
| 16 #include "components/autocomplete/autocomplete_input.h" | 15 #include "components/autocomplete/autocomplete_input.h" |
| 17 #include "components/metrics/proto/omnibox_event.pb.h" | 16 #include "components/metrics/proto/omnibox_event.pb.h" |
| 18 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 19 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 21 | 20 |
| 22 namespace options { | 21 namespace options { |
| 23 | 22 |
| 24 HomePageOverlayHandler::HomePageOverlayHandler() { | 23 HomePageOverlayHandler::HomePageOverlayHandler() { |
| 25 } | 24 } |
| 26 | 25 |
| 27 HomePageOverlayHandler::~HomePageOverlayHandler() { | 26 HomePageOverlayHandler::~HomePageOverlayHandler() { |
| 28 } | 27 } |
| 29 | 28 |
| 30 void HomePageOverlayHandler::RegisterMessages() { | 29 void HomePageOverlayHandler::RegisterMessages() { |
| 31 web_ui()->RegisterMessageCallback( | 30 web_ui()->RegisterMessageCallback( |
| 32 "requestAutocompleteSuggestionsForHomePage", | 31 "requestAutocompleteSuggestionsForHomePage", |
| 33 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions, | 32 base::Bind(&HomePageOverlayHandler::RequestAutocompleteSuggestions, |
| 34 base::Unretained(this))); | 33 base::Unretained(this))); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void HomePageOverlayHandler::InitializeHandler() { | 36 void HomePageOverlayHandler::InitializeHandler() { |
| 38 Profile* profile = Profile::FromWebUI(web_ui()); | 37 Profile* profile = Profile::FromWebUI(web_ui()); |
| 39 autocomplete_controller_.reset(new AutocompleteController(profile, | 38 autocomplete_controller_.reset(new AutocompleteController(profile, this, |
| 40 TemplateURLServiceFactory::GetForProfile(profile), this, | |
| 41 AutocompleteClassifier::kDefaultOmniboxProviders)); | 39 AutocompleteClassifier::kDefaultOmniboxProviders)); |
| 42 } | 40 } |
| 43 | 41 |
| 44 void HomePageOverlayHandler::GetLocalizedValues( | 42 void HomePageOverlayHandler::GetLocalizedValues( |
| 45 base::DictionaryValue* localized_strings) { | 43 base::DictionaryValue* localized_strings) { |
| 46 RegisterTitle(localized_strings, "homePageOverlay", | 44 RegisterTitle(localized_strings, "homePageOverlay", |
| 47 IDS_OPTIONS_HOMEPAGE_TITLE); | 45 IDS_OPTIONS_HOMEPAGE_TITLE); |
| 48 } | 46 } |
| 49 | 47 |
| 50 void HomePageOverlayHandler::RequestAutocompleteSuggestions( | 48 void HomePageOverlayHandler::RequestAutocompleteSuggestions( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 61 | 59 |
| 62 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) { | 60 void HomePageOverlayHandler::OnResultChanged(bool default_match_changed) { |
| 63 const AutocompleteResult& result = autocomplete_controller_->result(); | 61 const AutocompleteResult& result = autocomplete_controller_->result(); |
| 64 base::ListValue suggestions; | 62 base::ListValue suggestions; |
| 65 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); | 63 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); |
| 66 web_ui()->CallJavascriptFunction( | 64 web_ui()->CallJavascriptFunction( |
| 67 "HomePageOverlay.updateAutocompleteSuggestions", suggestions); | 65 "HomePageOverlay.updateAutocompleteSuggestions", suggestions); |
| 68 } | 66 } |
| 69 | 67 |
| 70 } // namespace options | 68 } // namespace options |
| OLD | NEW |