diff options
-rw-r--r-- | chrome/browser/printing/print_job_worker.cc | 5 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_worker.h | 7 | ||||
-rw-r--r-- | printing/printing_context.h | 9 | ||||
-rw-r--r-- | printing/printing_context_cairo.cc | 3 | ||||
-rw-r--r-- | printing/printing_context_cairo.h | 3 | ||||
-rw-r--r-- | printing/printing_context_mac.h | 6 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 47 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 3 | ||||
-rw-r--r-- | printing/printing_context_win.h | 3 |
9 files changed, 60 insertions, 26 deletions
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index 3edac10..8eb6eaf 100644 --- a/chrome/browser/printing/print_job_worker.cc +++ b/chrome/browser/printing/print_job_worker.cc @@ -127,10 +127,9 @@ void PrintJobWorker::UpdatePrintSettings( } } } - // 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); + printing_context_->UpdatePrintSettings(new_settings, new_ranges); + delete new_settings; GetSettingsDone(result); } diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h index 8b0ab68..94bb2d9 100644 --- a/chrome/browser/printing/print_job_worker.h +++ b/chrome/browser/printing/print_job_worker.h @@ -44,8 +44,8 @@ class PrintJobWorker : public base::Thread { bool has_selection, bool use_overlays); - // Set the new print settings. This function takes ownership of |new_settings| - // and frees it. + // Set the new print settings. This function takes ownership of + // |new_settings|. void SetSettings(const DictionaryValue* const new_settings); // Starts the printing loop. Every pages are printed as soon as the data is @@ -98,7 +98,8 @@ class PrintJobWorker : public base::Thread { // back into the IO thread for GetSettingsDone(). void GetSettingsWithUIDone(PrintingContext::Result result); - // Called on the UI thread to update the print settings. + // Called on the UI thread to update the print settings. This function takes + // the ownership of |new_settings|. void UpdatePrintSettings(const DictionaryValue* const new_settings); // Reports settings back to owner_. diff --git a/printing/printing_context.h b/printing/printing_context.h index d7d5016..dca306b 100644 --- a/printing/printing_context.h +++ b/printing/printing_context.h @@ -13,6 +13,8 @@ #include "printing/print_settings.h" #include "ui/gfx/native_widget_types.h" +class DictionaryValue; + namespace printing { // An abstraction of a printer context, implemented by objects that describe the @@ -47,9 +49,10 @@ class PrintingContext { // default device settings. virtual Result UseDefaultSettings() = 0; - // Update print settings. As of now we are updating the page range settings. - // In the future, update other print job settings. - virtual Result UpdatePrintSettings(const PageRanges& ranges) = 0; + // Updates print settings. |job_settings| contains all print job settings + // information. |ranges| has the new page range settings. + virtual Result UpdatePrintSettings(const DictionaryValue* const job_settings, + const PageRanges& ranges) = 0; // Initializes with predefined settings. virtual Result InitWithSettings(const PrintSettings& settings) = 0; diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc index 052ba73..cb7a092 100644 --- a/printing/printing_context_cairo.cc +++ b/printing/printing_context_cairo.cc @@ -5,6 +5,7 @@ #include "printing/printing_context_cairo.h" #include "base/logging.h" +#include "base/values.h" #include "printing/units.h" #include "printing/print_settings_initializer_gtk.h" @@ -148,7 +149,7 @@ PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { } PrintingContext::Result PrintingContextCairo::UpdatePrintSettings( - const PageRanges& ranges) { + const DictionaryValue* const job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); settings_.ranges = ranges; diff --git a/printing/printing_context_cairo.h b/printing/printing_context_cairo.h index 514b341..192782f 100644 --- a/printing/printing_context_cairo.h +++ b/printing/printing_context_cairo.h @@ -40,7 +40,8 @@ class PrintingContextCairo : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); - virtual Result UpdatePrintSettings(const PageRanges& ranges); + virtual Result UpdatePrintSettings(const DictionaryValue* const job_settings, + const PageRanges& ranges); virtual Result InitWithSettings(const PrintSettings& settings); virtual Result NewDocument(const string16& document_name); virtual Result NewPage(); diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h index 8e2ba7d..e87dfce 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -29,7 +29,8 @@ class PrintingContextMac : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); - virtual Result UpdatePrintSettings(const PageRanges& ranges); + virtual Result UpdatePrintSettings(const DictionaryValue* const job_settings, + const PageRanges& ranges); virtual Result InitWithSettings(const PrintSettings& settings); virtual Result NewDocument(const string16& document_name); virtual Result NewPage(); @@ -43,6 +44,9 @@ class PrintingContextMac : public PrintingContext { // Read the settings from the given NSPrintInfo (and cache it for later use). void ParsePrintInfo(NSPrintInfo* print_info); + // Initializes PrintSettings from native print info object. + void InitPrintSettingsFromPrintInfo(const PageRanges& ranges); + // The native print info object. scoped_nsobject<NSPrintInfo> print_info_; diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index c297fad..1e354e0 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" #include "base/sys_string_conversions.h" +#include "base/values.h" #include "printing/print_settings_initializer_mac.h" namespace printing { @@ -50,6 +51,7 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, options |= NSPrintPanelShowsScaling; [panel setOptions:options]; + // Set the print job title text. if (parent_view) { NSString* job_title = [[parent_view window] title]; if (job_title) { @@ -80,18 +82,47 @@ PrintingContext::Result PrintingContextMac::UseDefaultSettings() { } PrintingContext::Result PrintingContextMac::UpdatePrintSettings( - const PageRanges& ranges) { + const DictionaryValue* const job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); // TODO (kmadhusu): Update other print job settings such as number of copies, // collate, etc., - // Update the print range information. - settings_.ranges = ranges; + ResetSettings(); + print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); + + std::string printer_name; + if (!job_settings->GetString("printerName", &printer_name)) + return OnError(); + + NSString* new_printer_name = base::SysUTF8ToNSString(printer_name); + if (!new_printer_name) + return OnError(); + + if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) { + NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name]; + if (new_printer == nil) + return OnError(); + [print_info_.get() setPrinter:new_printer]; + } + + InitPrintSettingsFromPrintInfo(ranges); return OK; } +void PrintingContextMac::InitPrintSettingsFromPrintInfo( + const PageRanges& ranges) { + PMPrintSession print_session = + static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); + PMPageFormat page_format = + static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); + PMPrinter printer; + PMSessionGetCurrentPrinter(print_session, &printer); + PrintSettingsInitializerMac::InitPrintSettings( + printer, page_format, ranges, false, &settings_); +} + void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { ResetSettings(); print_info_.reset([print_info retain]); @@ -103,15 +134,7 @@ void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; page_ranges.push_back(range); } - PMPrintSession print_session = - static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); - PMPageFormat page_format = - static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); - PMPrinter printer; - PMSessionGetCurrentPrinter(print_session, &printer); - - PrintSettingsInitializerMac::InitPrintSettings( - printer, page_format, page_ranges, false, &settings_); + InitPrintSettingsFromPrintInfo(page_ranges); } PrintingContext::Result PrintingContextMac::InitWithSettings( diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 32a44be..819c0077 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -11,6 +11,7 @@ #include "base/message_loop.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "printing/print_settings_initializer_win.h" #include "printing/printed_document.h" #include "skia/ext/platform_device_win.h" @@ -209,7 +210,7 @@ PrintingContext::Result PrintingContextWin::UseDefaultSettings() { } PrintingContext::Result PrintingContextWin::UpdatePrintSettings( - const PageRanges& ranges) { + const DictionaryValue* const job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); settings_.ranges = ranges; diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h index 4037536..a1af2bb 100644 --- a/printing/printing_context_win.h +++ b/printing/printing_context_win.h @@ -28,7 +28,8 @@ class PrintingContextWin : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); - virtual Result UpdatePrintSettings(const PageRanges& ranges); + virtual Result UpdatePrintSettings(const DictionaryValue* const job_settings, + const PageRanges& ranges); virtual Result InitWithSettings(const PrintSettings& settings); virtual Result NewDocument(const string16& document_name); virtual Result NewPage(); |