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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/printing/print_job_worker.h" 5 #include "chrome/browser/printing/print_job_worker.h"
6 6
7 #include "base/json/json_reader.h"
7 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/values.h"
8 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/browser_thread.h" 11 #include "chrome/browser/browser_thread.h"
10 #include "chrome/browser/printing/print_job.h" 12 #include "chrome/browser/printing/print_job.h"
11 #include "chrome/common/notification_service.h" 13 #include "chrome/common/notification_service.h"
12 #include "printing/printed_document.h" 14 #include "printing/printed_document.h"
13 #include "printing/printed_page.h" 15 #include "printing/printed_page.h"
14 16
15 namespace printing { 17 namespace printing {
16 18
17 class PrintJobWorker::NotificationTask : public Task { 19 class PrintJobWorker::NotificationTask : public Task {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 BrowserThread::UI, FROM_HERE, 90 BrowserThread::UI, FROM_HERE,
89 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI, 91 NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI,
90 parent_view, document_page_count, 92 parent_view, document_page_count,
91 has_selection)); 93 has_selection));
92 } else { 94 } else {
93 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 95 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
94 NewRunnableMethod(this, &PrintJobWorker::UseDefaultSettings)); 96 NewRunnableMethod(this, &PrintJobWorker::UseDefaultSettings));
95 } 97 }
96 } 98 }
97 99
100 void PrintJobWorker::SetSettings(const std::string& new_settings) {
101 DCHECK_EQ(message_loop(), MessageLoop::current());
102 DCHECK_EQ(page_number_, PageNumber::npos());
103
104 // Disable recursive task processing.
105 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
106
107 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
108 NewRunnableMethod(this, &PrintJobWorker::UpdatePrintSettings,
109 new_settings));
110 }
111
112 void PrintJobWorker::UpdatePrintSettings(const std::string& new_settings) {
113 scoped_ptr<Value> parsed_value(base::JSONReader::Read(new_settings, false));
114 if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) {
115 NOTREACHED() << "Unable to parse print params";
116 return;
117 }
118 DictionaryValue* settings =
119 static_cast<DictionaryValue*>(parsed_value.get());
120
121 // Create new PageRanges based on |new_settings|.
122 PageRanges new_ranges;
123 ListValue* pageRangeArray = NULL;
124 if (settings->GetList("pageRange", &pageRangeArray)) {
125 for (size_t index = 0; index < pageRangeArray->GetSize(); index++) {
126 DictionaryValue* dict = NULL;
127 pageRangeArray->GetDictionary(index, &dict);
128 if (dict) {
129 int printFrom = 0;
130 int printTo = 0;
131 if (dict->GetInteger("from", &printFrom) &&
132 dict->GetInteger("to", &printTo)) {
133 PageRange range;
134 // Page numbers are 0-based.
135 range.from = printFrom - 1;
136 range.to = printTo - 1;
137 new_ranges.push_back(range);
138 }
139 }
140 }
141 }
142 PrintingContext::Result result =
143 printing_context_->UpdatePrintSettings(settings, new_ranges);
144 GetSettingsDone(result);
145 }
146
98 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { 147 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
99 // Most PrintingContext functions may start a message loop and process 148 // Most PrintingContext functions may start a message loop and process
100 // message recursively, so disable recursive task processing. 149 // message recursively, so disable recursive task processing.
101 MessageLoop::current()->SetNestableTasksAllowed(false); 150 MessageLoop::current()->SetNestableTasksAllowed(false);
102 151
103 // We can't use OnFailure() here since owner_ may not support notifications. 152 // We can't use OnFailure() here since owner_ may not support notifications.
104 153
105 // PrintJob will create the new PrintedDocument. 154 // PrintJob will create the new PrintedDocument.
106 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 155 owner_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
107 owner_, 156 owner_,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 printing::PrintJobWorker* obj) { 355 printing::PrintJobWorker* obj) {
307 DCHECK(!owner_.get()); 356 DCHECK(!owner_.get());
308 owner_ = obj->owner_; 357 owner_ = obj->owner_;
309 } 358 }
310 359
311 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee( 360 void RunnableMethodTraits<printing::PrintJobWorker>::ReleaseCallee(
312 printing::PrintJobWorker* obj) { 361 printing::PrintJobWorker* obj) {
313 DCHECK_EQ(owner_, obj->owner_); 362 DCHECK_EQ(owner_, obj->owner_);
314 owner_ = NULL; 363 owner_ = NULL;
315 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698