Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "printing/backend/print_backend.h" | 10 #include "printing/backend/print_backend.h" |
| 10 | 11 |
| 11 PrintPreviewHandler::PrintPreviewHandler() | 12 PrintPreviewHandler::PrintPreviewHandler() |
| 12 : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { | 13 : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { |
| 13 } | 14 } |
| 14 | 15 |
| 15 PrintPreviewHandler::~PrintPreviewHandler() { | 16 PrintPreviewHandler::~PrintPreviewHandler() { |
| 16 } | 17 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 28 printing::PrinterList printer_list; | 29 printing::PrinterList printer_list; |
| 29 print_backend_->EnumeratePrinters(&printer_list); | 30 print_backend_->EnumeratePrinters(&printer_list); |
| 30 for (printing::PrinterList::iterator index = printer_list.begin(); | 31 for (printing::PrinterList::iterator index = printer_list.begin(); |
| 31 index != printer_list.end(); ++index) { | 32 index != printer_list.end(); ++index) { |
| 32 printers.Append(new StringValue(index->printer_name)); | 33 printers.Append(new StringValue(index->printer_name)); |
| 33 } | 34 } |
| 34 | 35 |
| 35 web_ui_->CallJavascriptFunction(L"setPrinters", printers); | 36 web_ui_->CallJavascriptFunction(L"setPrinters", printers); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void PrintPreviewHandler::HandlePrint(const ListValue*) { | 39 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| 39 web_ui_->GetRenderViewHost()->PrintForPrintPreview(); | 40 std::string json_str; |
| 41 CHECK(args->GetString(0, &json_str)) << "Could not read JSON argument"; | |
|
Lei Zhang
2011/03/02 23:28:54
I would not do a CHECK here. This would imply if t
kmadhusu
2011/03/04 19:39:02
Fixed.
| |
| 42 if (json_str.empty()) { | |
| 43 NOTREACHED() << "Empty print job settings"; | |
| 44 return; | |
| 45 } | |
| 46 scoped_ptr<DictionaryValue> settings(static_cast<DictionaryValue*>( | |
| 47 base::JSONReader::Read(json_str, false))); | |
| 48 CHECK(settings.get() && settings->IsType(Value::TYPE_DICTIONARY)) | |
| 49 << "Print job settings must be a dictionary."; | |
| 50 | |
| 51 CHECK(!settings->empty()) << "Print job settings dictionary is empty"; | |
| 52 web_ui_->GetRenderViewHost()->PrintForPrintPreview(*settings); | |
| 40 } | 53 } |
| OLD | NEW |