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 50a1a18c0fa5d3565d1cb2d36034ff1dec294739..f829ae7dda0726da6e30ce8449c872664ee05fbd 100644 |
--- a/chrome/browser/printing/print_job_worker.cc |
+++ b/chrome/browser/printing/print_job_worker.cc |
@@ -1,10 +1,12 @@ |
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 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/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" |
@@ -95,6 +97,53 @@ 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()); |
+ |
+ // Disable recursive task processing. |
+ MessageLoop::current()->SetNestableTasksAllowed(false); |
jam
2011/02/18 01:55:07
why are you're doing this?
kmadhusu
2011/02/21 01:30:26
Based on our discussion, I removed this statement
|
+ |
+ 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(settings, 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. |