summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing/print_job_worker.cc
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-05 00:12:53 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-05 00:12:53 +0000
commit7868ecabafc39bcd917276899742be136cca2ae3 (patch)
treeb008edd73081d0df868eae216e18cc6dc56d382d /chrome/browser/printing/print_job_worker.cc
parentf41067c4ff04b9552c48e89169b28cf078c1a8ba (diff)
downloadchromium_src-7868ecabafc39bcd917276899742be136cca2ae3.zip
chromium_src-7868ecabafc39bcd917276899742be136cca2ae3.tar.gz
chromium_src-7868ecabafc39bcd917276899742be136cca2ae3.tar.bz2
(1) Hook up the print button to send the pages to the default printer for printing without displaying a native dialog.
(2) Made code changes to accept a print page range from the user and to print only those specified pages. BUG=none TEST=Enable print preview on mac, provide a valid page range and make sure print button in print preview works. Review URL: http://codereview.chromium.org/6533006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77003 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing/print_job_worker.cc')
-rw-r--r--chrome/browser/printing/print_job_worker.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index db0c341..3c7f862 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/printing/print_job.h"
#include "chrome/common/notification_service.h"
@@ -98,6 +99,41 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
}
}
+void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) {
+ DCHECK_EQ(message_loop(), MessageLoop::current());
+
+ 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* page_range_array;
+ if (new_settings->GetList("pageRange", &page_range_array)) {
+ for (size_t index = 0; index < page_range_array->GetSize(); ++index) {
+ DictionaryValue* dict;
+ if (page_range_array->GetDictionary(index, &dict)) {
+ 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|.
+ 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.