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..aa9ed199a55bfaf80c6207191123d7cab6d2f7ca 100644 |
--- a/chrome/browser/printing/print_job_worker.cc |
+++ b/chrome/browser/printing/print_job_worker.cc |
@@ -4,9 +4,12 @@ |
#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/dom_ui/web_ui_util.h" |
#include "chrome/browser/printing/print_job.h" |
#include "chrome/common/notification_service.h" |
#include "printing/printed_document.h" |
@@ -95,6 +98,63 @@ 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); |
+ |
+ 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++) { |
+ std::string json_str( |
+ web_ui_util::GetJsonResponseFromArgumentList(pageRangeArray, index)); |
+ if (json_str.empty()) |
+ continue; |
+ |
+ scoped_ptr<Value> parsed_val(base::JSONReader::Read(json_str, false)); |
+ if (!parsed_val.get() || !parsed_val->IsType(Value::TYPE_DICTIONARY)) { |
+ NOTREACHED() << "Unable to parse page range params"; |
+ continue; |
+ } |
+ DictionaryValue* dict = static_cast<DictionaryValue*>(parsed_val.get()); |
+ if (dict) { |
+ int printFrom = 0; |
+ int printTo = 0; |
+ if (dict->GetInteger("from", &printFrom) && |
+ dict->GetInteger("to", &printTo)) { |
+ if (!(printFrom < 1) && !(printTo < 1)) { |
+ PageRange range; |
+ range.from = printFrom - 1; |
+ range.to = printTo - 1; |
+ new_ranges.push_back(range); |
+ } |
+ } |
+ } |
+ } |
+ } |
+ PrintingContext::Result result = |
+ printing_context_->UpdatePrintSettings(new_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. |