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

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: Addressed review comments. 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 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) {
Lei Zhang 2011/02/24 03:49:32 Have you considered parsing (and maybe validating)
kmadhusu 2011/03/01 01:55:50 Fixed. Now UpdatePrintSettings() has a dictionary
+ 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 =
Lei Zhang 2011/02/24 03:49:32 nit: you don't need separate |settings| and |parse
kmadhusu 2011/03/01 01:55:50 Done.
+ static_cast<DictionaryValue*>(parsed_value.get());
+
+ // Create new PageRanges based on |new_settings|.
+ PageRanges new_ranges;
+ ListValue* pageRangeArray = NULL;
Lei Zhang 2011/02/24 03:49:32 you don't need this assignment or the ones below f
kmadhusu 2011/03/01 01:55:50 Done.
+ 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;
Lei Zhang 2011/02/24 03:49:32 Can you get rid of |printFrom| and |printTo|, inst
kmadhusu 2011/03/01 01:55:50 Done.
+ 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.

Powered by Google App Engine
This is Rietveld 408576698