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

Side by Side Diff: chrome/browser/printing/print_job_worker.cc

Issue 10483006: Print support for Windows Metro... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self CR changes Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // on the I/O thread. 62 // on the I/O thread.
63 DCHECK_EQ(owner_->message_loop(), MessageLoop::current()); 63 DCHECK_EQ(owner_->message_loop(), MessageLoop::current());
64 Stop(); 64 Stop();
65 } 65 }
66 66
67 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { 67 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
68 DCHECK(page_number_ == PageNumber::npos()); 68 DCHECK(page_number_ == PageNumber::npos());
69 owner_ = new_owner; 69 owner_ = new_owner;
70 } 70 }
71 71
72 void PrintJobWorker::SetPrintDestination(
73 PrintDestinationInterface* destination) {
74 DCHECK(destination_.get() == NULL);
robertshield 2012/06/28 17:48:54 Why is this DCHECK present? If it needs to be he
MAD 2012/06/28 19:05:51 It was just for debugging, forgot to remove... Tha
75 destination_ = destination;
76 }
77
72 void PrintJobWorker::GetSettings(bool ask_user_for_settings, 78 void PrintJobWorker::GetSettings(bool ask_user_for_settings,
73 gfx::NativeView parent_view, 79 gfx::NativeView parent_view,
74 int document_page_count, 80 int document_page_count,
75 bool has_selection, 81 bool has_selection,
76 MarginType margin_type) { 82 MarginType margin_type) {
77 DCHECK_EQ(message_loop(), MessageLoop::current()); 83 DCHECK_EQ(message_loop(), MessageLoop::current());
78 DCHECK_EQ(page_number_, PageNumber::npos()); 84 DCHECK_EQ(page_number_, PageNumber::npos());
79 85
80 // Recursive task processing is needed for the dialog in case it needs to be 86 // Recursive task processing is needed for the dialog in case it needs to be
81 // destroyed by a task. 87 // destroyed by a task.
82 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed 88 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed
83 // on the thread where the PrintDlgEx is called, and definitely both calls 89 // on the thread where the PrintDlgEx is called, and definitely both calls
84 // should happen on the same thread. See http://crbug.com/73466 90 // should happen on the same thread. See http://crbug.com/73466
85 // MessageLoop::current()->SetNestableTasksAllowed(true); 91 // MessageLoop::current()->SetNestableTasksAllowed(true);
86 printing_context_->set_margin_type(margin_type); 92 printing_context_->set_margin_type(margin_type);
87 93
88 if (ask_user_for_settings) { 94 // When we delegate to a destination, we don't ask the user for settings.
95 // TODO(mad): Ask the destination for settings.
96 if (ask_user_for_settings && destination_.get() == NULL) {
89 BrowserThread::PostTask( 97 BrowserThread::PostTask(
90 BrowserThread::UI, FROM_HERE, 98 BrowserThread::UI, FROM_HERE,
91 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), 99 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
92 base::Bind(&PrintJobWorker::GetSettingsWithUI, 100 base::Bind(&PrintJobWorker::GetSettingsWithUI,
93 base::Unretained(this), parent_view, 101 base::Unretained(this), parent_view,
94 document_page_count, has_selection))); 102 document_page_count, has_selection)));
95 } else { 103 } else {
96 BrowserThread::PostTask( 104 BrowserThread::PostTask(
97 BrowserThread::UI, FROM_HERE, 105 BrowserThread::UI, FROM_HERE,
98 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), 106 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Find first page to print. 242 // Find first page to print.
235 int page_count = document_->page_count(); 243 int page_count = document_->page_count();
236 if (!page_count) { 244 if (!page_count) {
237 // We still don't know how many pages the document contains. We can't 245 // We still don't know how many pages the document contains. We can't
238 // start to print the document yet since the header/footer may refer to 246 // start to print the document yet since the header/footer may refer to
239 // the document's page count. 247 // the document's page count.
240 return; 248 return;
241 } 249 }
242 // We have enough information to initialize page_number_. 250 // We have enough information to initialize page_number_.
243 page_number_.Init(document_->settings(), page_count); 251 page_number_.Init(document_->settings(), page_count);
252 if (destination_.get() != NULL)
253 destination_->SetPageCount(page_count);
244 } 254 }
245 DCHECK_NE(page_number_, PageNumber::npos()); 255 DCHECK_NE(page_number_, PageNumber::npos());
246 256
247 while (true) { 257 while (true) {
248 // Is the page available? 258 // Is the page available?
249 scoped_refptr<PrintedPage> page; 259 scoped_refptr<PrintedPage> page;
250 if (!document_->GetPage(page_number_.ToInt(), &page)) { 260 if (!document_->GetPage(page_number_.ToInt(), &page)) {
251 // We need to wait for the page to be available. 261 // We need to wait for the page to be available.
252 MessageLoop::current()->PostDelayedTask( 262 MessageLoop::current()->PostDelayedTask(
253 FROM_HERE, 263 FROM_HERE,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 FROM_HERE, base::Bind(NotificationCallback, make_scoped_refptr(owner_), 311 FROM_HERE, base::Bind(NotificationCallback, make_scoped_refptr(owner_),
302 JobEventDetails::NEW_PAGE, document_, 312 JobEventDetails::NEW_PAGE, document_,
303 make_scoped_refptr(page))); 313 make_scoped_refptr(page)));
304 314
305 // Preprocess. 315 // Preprocess.
306 if (printing_context_->NewPage() != PrintingContext::OK) { 316 if (printing_context_->NewPage() != PrintingContext::OK) {
307 OnFailure(); 317 OnFailure();
308 return; 318 return;
309 } 319 }
310 320
321 if (destination_.get() != NULL) {
322 std::vector<uint8> metabytes(page->metafile()->GetDataSize());
323 bool success = page->metafile()->GetData(
324 reinterpret_cast<void*>(&metabytes[0]), metabytes.size());
325 destination_->SetPageContent(
326 page->page_number(),
327 reinterpret_cast<void*>(&metabytes[0]),
328 metabytes.size());
329 return;
330 }
331
311 // Actual printing. 332 // Actual printing.
312 #if defined(OS_WIN) || defined(OS_MACOSX) 333 #if defined(OS_WIN) || defined(OS_MACOSX)
313 document_->RenderPrintedPage(*page, printing_context_->context()); 334 document_->RenderPrintedPage(*page, printing_context_->context());
314 #elif defined(OS_POSIX) 335 #elif defined(OS_POSIX)
315 document_->RenderPrintedPage(*page, printing_context_.get()); 336 document_->RenderPrintedPage(*page, printing_context_.get());
316 #endif 337 #endif
317 338
318 // Postprocess. 339 // Postprocess.
319 if (printing_context_->PageDone() != PrintingContext::OK) { 340 if (printing_context_->PageDone() != PrintingContext::OK) {
320 OnFailure(); 341 OnFailure();
(...skipping 19 matching lines...) Expand all
340 JobEventDetails::FAILED, document_, 361 JobEventDetails::FAILED, document_,
341 scoped_refptr<PrintedPage>())); 362 scoped_refptr<PrintedPage>()));
342 Cancel(); 363 Cancel();
343 364
344 // Makes sure the variables are reinitialized. 365 // Makes sure the variables are reinitialized.
345 document_ = NULL; 366 document_ = NULL;
346 page_number_ = PageNumber::npos(); 367 page_number_ = PageNumber::npos();
347 } 368 }
348 369
349 } // namespace printing 370 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698