summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui/print_preview_handler.cc
blob: cee9be4d5f20e11c33438865dd1e8ad1d55a7cde (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
// Copyright (c) 2010 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 "chrome/browser/dom_ui/print_preview_handler.h"

#include "base/values.h"
#include "printing/backend/print_backend.h"

PrintPreviewHandler::PrintPreviewHandler()
    : print_backend_(printing::PrintBackend::CreateInstance(NULL)) {
}

PrintPreviewHandler::~PrintPreviewHandler() {
}

void PrintPreviewHandler::RegisterMessages() {
  dom_ui_->RegisterMessageCallback("getPreview",
      NewCallback(this, &PrintPreviewHandler::HandleGetPreview));
  dom_ui_->RegisterMessageCallback("getPrinters",
      NewCallback(this, &PrintPreviewHandler::HandleGetPrinters));
}

void PrintPreviewHandler::HandleGetPreview(const ListValue*) {
  // TODO(thestig) Hook this up properly when PDF generation works.
  StringValue dummy_url("chrome://print/dummy.pdf");
  dom_ui_->CallJavascriptFunction(L"createPDFPlugin", dummy_url);
}

void PrintPreviewHandler::HandleGetPrinters(const ListValue*) {
  ListValue printers;

  printing::PrinterList printer_list;
  print_backend_->EnumeratePrinters(&printer_list);
  for (printing::PrinterList::iterator index = printer_list.begin();
       index != printer_list.end(); ++index) {
    printers.Append(new StringValue(index->printer_name));
  }

  dom_ui_->CallJavascriptFunction(L"setPrinters", printers);
}