summaryrefslogtreecommitdiffstats
path: root/components/dom_distiller/webui/dom_distiller_handler.cc
blob: c05cc0dec73461288d668bf031c7a3d2aa198392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/dom_distiller/webui/dom_distiller_handler.h"

#include "base/bind.h"
#include "base/values.h"
#include "content/public/browser/web_ui.h"

namespace dom_distiller {

DomDistillerHandler::DomDistillerHandler()
    : weak_ptr_factory_(this) {
}

DomDistillerHandler::~DomDistillerHandler() {}

void DomDistillerHandler::RegisterMessages() {
  web_ui()->RegisterMessageCallback(
      "requestEntries",
      base::Bind(&DomDistillerHandler::HandleRequestEntries,
      base::Unretained(this)));
}

void DomDistillerHandler::HandleRequestEntries(const ListValue* args) {
  base::ListValue entries;

  // Add some temporary placeholder entries.
  scoped_ptr<base::DictionaryValue> entry1(new base::DictionaryValue());
  entry1->SetString("title", "Google");
  entry1->SetString("url", "http://www.google.com/");
  entries.Append(entry1.release());
  scoped_ptr<base::DictionaryValue> entry2(new base::DictionaryValue());
  entry2->SetString("title", "Chrome");
  entry2->SetString("url", "http://www.chrome.com/");
  entries.Append(entry2.release());

  web_ui()->CallJavascriptFunction("onGotEntries", entries);
}

}  // namespace dom_distiller