Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / suggestions_internals / suggestions_internals_ui_handler.cc
blob020d441241b17a7da87c342d50a82ba8e8c5f463
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/suggestions_internals/suggestions_internals_ui_handler.h"
7 #include "base/bind.h"
8 #include "base/values.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
11 #include "content/public/browser/web_ui.h"
13 namespace {
15 const size_t kSuggestionsCount = 100;
17 } // namespace
19 SuggestionsInternalsUIHandler::SuggestionsInternalsUIHandler(Profile* profile)
20 : profile_(profile) {}
22 SuggestionsInternalsUIHandler::~SuggestionsInternalsUIHandler() {}
24 void SuggestionsInternalsUIHandler::OnSuggestionsReady() {
25 if (suggestions_combiner_->GetPageValues()) {
26 web_ui()->CallJavascriptFunction("suggestionsInternals.setSuggestions",
27 *suggestions_combiner_->GetPageValues());
31 void SuggestionsInternalsUIHandler::RegisterMessages() {
32 // Setup the suggestions sources.
33 suggestions_combiner_.reset(new SuggestionsCombiner(this, profile_));
34 suggestions_combiner_->SetSuggestionsCount(kSuggestionsCount);
35 suggestions_combiner_->EnableDebug(true);
37 web_ui()->RegisterMessageCallback("getSuggestions",
38 base::Bind(&SuggestionsInternalsUIHandler::HandleGetSuggestions,
39 base::Unretained(this)));
42 void SuggestionsInternalsUIHandler::HandleGetSuggestions(
43 const base::ListValue* one_element_input_string) {
44 suggestions_combiner_->FetchItems(Profile::FromWebUI(web_ui()));