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

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 77ca7dfb18317a367d3b5b3e71801d1e51404691..2f0c27d537b52a8d8e06896533526b64927d7c30 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/printing/print_job_worker.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 +99,44 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
}
}
+void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) {
+ DCHECK_EQ(message_loop(), MessageLoop::current());
+ DCHECK_EQ(page_number_, PageNumber::npos());
Lei Zhang 2011/03/02 23:28:54 Do we need this DCHECK here?
kmadhusu 2011/03/04 19:39:02 It is not required. Fixed.
+
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings,
+ new_settings));
+}
+
+void PrintJobWorker::UpdatePrintSettings(
+ const DictionaryValue* const new_settings) {
+ // Create new PageRanges based on |new_settings|.
+ PageRanges new_ranges;
+ ListValue* pageRangeArray;
Lei Zhang 2011/03/02 23:28:54 nit: pageRangeArray -> page_range_array.
kmadhusu 2011/03/04 19:39:02 Done.
+ if (new_settings->GetList("pageRange", &pageRangeArray)) {
+ for (size_t index = 0; index < pageRangeArray->GetSize(); index++) {
Lei Zhang 2011/03/02 23:28:54 index++ -> ++index
kmadhusu 2011/03/04 19:39:02 Done.
+ DictionaryValue* dict;
+ pageRangeArray->GetDictionary(index, &dict);
+ if (dict) {
Lei Zhang 2011/03/02 23:28:54 This is not the right way to check if |dict| is va
kmadhusu 2011/03/04 19:39:02 Fixed.
+ PageRange range;
+ if (dict->GetInteger("from", &range.from) &&
+ dict->GetInteger("to", &range.to)) {
+ // Page numbers are 0-based.
+ range.from--;
+ range.to--;
+ new_ranges.push_back(range);
+ }
+ }
+ }
+ }
+ // We don't update any other print job settings now, so delete |new_settings|.
+ if (new_settings)
Lei Zhang 2011/03/02 23:28:54 You don't need this check, you've already assumed
kmadhusu 2011/03/04 19:39:02 Done.
+ delete new_settings;
+ 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