| Index: chrome/browser/printing/print_job_worker.cc
|
| diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
|
| index 77ca7dfb18317a367d3b5b3e71801d1e51404691..491ceee66757bd6cf6bada4026e2e33ca6403766 100644
|
| --- a/chrome/browser/printing/print_job_worker.cc
|
| +++ b/chrome/browser/printing/print_job_worker.cc
|
| @@ -4,7 +4,9 @@
|
|
|
| #include "chrome/browser/printing/print_job_worker.h"
|
|
|
| +#include "base/json/json_reader.h"
|
| #include "base/message_loop.h"
|
| +#include "base/values.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/browser_thread.h"
|
| #include "chrome/browser/printing/print_job.h"
|
| @@ -98,6 +100,50 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
|
| }
|
| }
|
|
|
| +void PrintJobWorker::SetSettings(const std::string& new_settings) {
|
| + DCHECK_EQ(message_loop(), MessageLoop::current());
|
| + DCHECK_EQ(page_number_, PageNumber::npos());
|
| +
|
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| + NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings,
|
| + new_settings));
|
| +}
|
| +
|
| +void PrintJobWorker::UpdatePrintSettings(const std::string& new_settings) {
|
| + scoped_ptr<Value> parsed_value(base::JSONReader::Read(new_settings, false));
|
| + if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) {
|
| + NOTREACHED() << "Unable to parse print params";
|
| + return;
|
| + }
|
| + DictionaryValue* settings =
|
| + static_cast<DictionaryValue*>(parsed_value.get());
|
| +
|
| + // Create new PageRanges based on |new_settings|.
|
| + PageRanges new_ranges;
|
| + ListValue* pageRangeArray = NULL;
|
| + if (settings->GetList("pageRange", &pageRangeArray)) {
|
| + for (size_t index = 0; index < pageRangeArray->GetSize(); index++) {
|
| + DictionaryValue* dict = NULL;
|
| + pageRangeArray->GetDictionary(index, &dict);
|
| + if (dict) {
|
| + int printFrom = 0;
|
| + int printTo = 0;
|
| + if (dict->GetInteger("from", &printFrom) &&
|
| + dict->GetInteger("to", &printTo)) {
|
| + PageRange range;
|
| + // Page numbers are 0-based.
|
| + range.from = printFrom - 1;
|
| + range.to = printTo - 1;
|
| + new_ranges.push_back(range);
|
| + }
|
| + }
|
| + }
|
| + }
|
| + PrintingContext::Result result =
|
| + printing_context_->UpdatePrintSettings(new_ranges);
|
| + GetSettingsDone(result);
|
| +}
|
| +
|
| void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
|
| // Most PrintingContext functions may start a message loop and process
|
| // message recursively, so disable recursive task processing.
|
|
|