Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2979)

Unified Diff: chrome/browser/printing/print_job_worker.cc

Issue 6533006: Print Preview: Hook up the print button to initiate printing without displaying a print dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698