diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index db0c3411dbccc4..3c7f8625de8fb2 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. diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h index 6b0183b64423a4..8b0ab689d34f7f 100644 --- a/chrome/browser/printing/print_job_worker.h +++ b/chrome/browser/printing/print_job_worker.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,6 +14,8 @@ #include "printing/printing_context.h" #include "ui/gfx/native_widget_types.h" +class DictionaryValue; + namespace printing { class PrintedDocument; @@ -42,6 +44,10 @@ 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. + void SetSettings(const DictionaryValue* const new_settings); + // Starts the printing loop. Every pages are printed as soon as the data is // available. Makes sure the new_document is the right one. void StartPrinting(PrintedDocument* new_document); @@ -92,6 +98,9 @@ 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. + void UpdatePrintSettings(const DictionaryValue* const new_settings); + // Reports settings back to owner_. void GetSettingsDone(PrintingContext::Result result); diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc index f39960f89ff0fd..e20ebc5cd3a81d 100644 --- a/chrome/browser/printing/printer_query.cc +++ b/chrome/browser/printing/printer_query.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,7 @@ #include "base/message_loop.h" #include "base/threading/thread_restrictions.h" +#include "base/values.h" #include "chrome/browser/printing/print_job_worker.h" namespace printing { @@ -78,10 +79,38 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, CancelableTask* callback) { DCHECK_EQ(io_message_loop_, MessageLoop::current()); DCHECK(!is_print_dialog_box_shown_); + if (!StartWorker(callback)) + return; + + // Real work is done in PrintJobWorker::Init(). + is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; + worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + worker_.get(), + &PrintJobWorker::GetSettings, + is_print_dialog_box_shown_, + parent_view, + expected_page_count, + has_selection, + use_overlays)); +} + +void PrinterQuery::SetSettings(const DictionaryValue& new_settings, + CancelableTask* callback) { + if (!StartWorker(callback)) + return; + + worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + worker_.get(), + &PrintJobWorker::SetSettings, + new_settings.DeepCopy())); +} + +bool PrinterQuery::StartWorker(CancelableTask* callback) { DCHECK(!callback_.get()); DCHECK(worker_.get()); if (!worker_.get()) - return; + return false; + // Lazy create the worker thread. There is one worker thread per print job. if (!worker_->message_loop()) { if (!worker_->Start()) { @@ -90,21 +119,11 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings, delete callback; } NOTREACHED(); - return; + return false; } } - callback_.reset(callback); - // Real work is done in PrintJobWorker::Init(). - is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; - worker_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - worker_.get(), - &PrintJobWorker::GetSettings, - is_print_dialog_box_shown_, - parent_view, - expected_page_count, - has_selection, - use_overlays)); + return true; } void PrinterQuery::StopWorker() { diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h index edc0c63e319c76..2a4c4680ec963b 100644 --- a/chrome/browser/printing/printer_query.h +++ b/chrome/browser/printing/printer_query.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,7 @@ #include "ui/gfx/native_widget_types.h" class CancelableTask; +class DictionaryValue; class MessageLoop; namespace base { @@ -51,6 +52,10 @@ class PrinterQuery : public PrintJobWorkerOwner { bool use_overlays, CancelableTask* callback); + // Updates the current settings with |new_settings| dictionary values. + void SetSettings(const DictionaryValue& new_settings, + CancelableTask* callback); + // Stops the worker thread since the client is done with this object. void StopWorker(); @@ -65,6 +70,10 @@ class PrinterQuery : public PrintJobWorkerOwner { private: virtual ~PrinterQuery(); + // Lazy create the worker thread. There is one worker thread per print job. + // Returns true, if worker thread exists or has been created. + bool StartWorker(CancelableTask* callback); + // Main message loop reference. Used to send notifications in the right // thread. MessageLoop* const io_message_loop_; diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc index e1132b41b789dc..1f5c4dbbdbb22d 100644 --- a/chrome/browser/printing/printing_message_filter.cc +++ b/chrome/browser/printing/printing_message_filter.cc @@ -99,6 +99,8 @@ bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, OnGetDefaultPrintSettings) IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, OnScriptedPrint) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_UpdatePrintSettings, + OnUpdatePrintSettings) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -263,3 +265,43 @@ void PrintingMessageFilter::OnScriptedPrintReply( printer_query->StopWorker(); } } + +void PrintingMessageFilter::OnUpdatePrintSettings( + int document_cookie, const DictionaryValue& job_settings, + IPC::Message* reply_msg) { + scoped_refptr printer_query; + print_job_manager_->PopPrinterQuery(document_cookie, &printer_query); + if (printer_query.get()) { + CancelableTask* task = NewRunnableMethod( + this, + &PrintingMessageFilter::OnUpdatePrintSettingsReply, + printer_query, + reply_msg); + printer_query->SetSettings(job_settings, task); + } +} + +void PrintingMessageFilter::OnUpdatePrintSettingsReply( + scoped_refptr printer_query, + IPC::Message* reply_msg) { + ViewMsg_Print_Params params; + if (!printer_query.get() || + printer_query->last_status() != printing::PrintingContext::OK) { + memset(¶ms, 0, sizeof(params)); + } else { + RenderParamsFromPrintSettings(printer_query->settings(), ¶ms); + params.document_cookie = printer_query->cookie(); + } + ViewHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params); + Send(reply_msg); + // If printing was enabled. + if (printer_query.get()) { + // If user hasn't cancelled. + if (printer_query->cookie() && printer_query->settings().dpi()) { + print_job_manager_->QueuePrinterQuery(printer_query.get()); + } else { + printer_query->StopWorker(); + } + } +} + diff --git a/chrome/browser/printing/printing_message_filter.h b/chrome/browser/printing/printing_message_filter.h index 686a2fbe58e707..e2c9c3cd615438 100644 --- a/chrome/browser/printing/printing_message_filter.h +++ b/chrome/browser/printing/printing_message_filter.h @@ -12,6 +12,7 @@ #include "base/shared_memory.h" #endif +class DictionaryValue; struct ViewHostMsg_ScriptedPrint_Params; namespace printing { @@ -66,6 +67,13 @@ class PrintingMessageFilter : public BrowserMessageFilter { int routing_id, IPC::Message* reply_msg); + void OnUpdatePrintSettings(int document_cookie, + const DictionaryValue& job_settings, + IPC::Message* reply_msg); + void OnUpdatePrintSettingsReply( + scoped_refptr printer_query, + IPC::Message* reply_msg); + printing::PrintJobManager* print_job_manager_; bool cloud_print_enabled_; diff --git a/chrome/browser/resources/print_preview.html b/chrome/browser/resources/print_preview.html index 20e7cc39b6dd05..9b0c91288d484a 100644 --- a/chrome/browser/resources/print_preview.html +++ b/chrome/browser/resources/print_preview.html @@ -25,7 +25,7 @@

Destination

Pages

- +
@@ -79,8 +79,5 @@

Color

- diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js index b1ceed8d8c2bca..25b53af491bfdd 100644 --- a/chrome/browser/resources/print_preview.js +++ b/chrome/browser/resources/print_preview.js @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,9 +10,8 @@ var expectedPageCount = 0; * Window onload handler, sets up the page. */ function load() { - $('print-button').addEventListener('click', function(e) { - chrome.send('print'); - }); + $('print-button').addEventListener('click', printFile); + $('cancel-button').addEventListener('click', function(e) { window.close(); }); @@ -20,6 +19,73 @@ function load() { chrome.send('getPrinters'); }; +/** + * Page range text validation. + * Returns true if |printFromText| and |printToText| are valid page numbers. + * TODO (kmadhusu): Get the expected page count and validate the page range + * with total number of pages. + */ +function isValidPageRange(printFromText, printToText) { + var numericExp = /^[0-9]+$/; + if (numericExp.test(printFromText) && numericExp.test(printToText)) { + var printFrom = Number(printFromText); + var printTo = Number(printToText); + if (printFrom <= printTo && printFrom != 0 && printTo != 0) + return true; + } + return false; +} + +/** + * Parse page range text. + * Eg: If page range is specified as '1-3,7-9,8'. Create an array with three + * elements. Each array element contains the range information. + * [{from:1, to:3}, {from:7, to:9}, {from:8, to:8}] + * TODO (kmadhusu): Handle invalid characters. + */ +function getPageRanges() { + var pageRangesInfo = []; + var pageRangeText = $('pages').value; + var pageRangeList = pageRangeText.replace(/\s/g, '').split(','); + for (var i = 0; i < pageRangeList.length; i++) { + var tempRange = pageRangeList[i].split('-'); + var printFrom = tempRange[0]; + var printTo; + if (tempRange.length > 1) + printTo = tempRange[1]; + else + printTo = tempRange[0]; + // Validate the page range information. + if (isValidPageRange(printFrom, printTo)) { + pageRangesInfo.push({'from': parseInt(printFrom, 10), + 'to': parseInt(printTo, 10)}); + } + } + return pageRangesInfo; +} + +function printFile() { + var selectedPrinter = $('printer-list').selectedIndex; + var printerName = $('printer-list').options[selectedPrinter].textContent; + var pageRanges = getPageRanges(); + var printAll = $('all-pages').checked; + var twoSided = $('two-sided').checked; + var copies = $('copies').value; + var collate = $('collate').checked; + var layout = $('layout').options[$('layout').selectedIndex].value; + var color = $('color').options[$('color').selectedIndex].value; + + var jobSettings = JSON.stringify({'printerName': printerName, + 'pageRange': pageRanges, + 'printAll': printAll, + 'twoSided': twoSided, + 'copies': copies, + 'collate': collate, + 'layout': layout, + 'color': color}); + chrome.send('print', [jobSettings]); +} + /** * Fill the printer list drop down. */ diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc index 4526b07af86ac7..2898519314ac85 100644 --- a/chrome/browser/ui/webui/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview_handler.cc @@ -4,10 +4,11 @@ #include "chrome/browser/ui/webui/print_preview_handler.h" +#include "base/json/json_reader.h" #include "base/threading/thread.h" #include "base/values.h" -#include "content/browser/renderer_host/render_view_host.h" #include "content/browser/browser_thread.h" +#include "content/browser/renderer_host/render_view_host.h" #include "printing/backend/print_backend.h" class EnumeratePrintersTaskProxy @@ -79,8 +80,29 @@ void PrintPreviewHandler::HandleGetPrinters(const ListValue*) { &EnumeratePrintersTaskProxy::EnumeratePrinters)); } -void PrintPreviewHandler::HandlePrint(const ListValue*) { - web_ui_->GetRenderViewHost()->PrintForPrintPreview(); +void PrintPreviewHandler::HandlePrint(const ListValue* args) { + std::string json_str; + if (!args->GetString(0, &json_str)) { + NOTREACHED() << "Could not read JSON argument"; + return; + } + + if (json_str.empty()) { + NOTREACHED() << "Empty print job settings"; + return; + } + scoped_ptr settings(static_cast( + base::JSONReader::Read(json_str, false))); + if (!settings.get() || !settings->IsType(Value::TYPE_DICTIONARY)) { + NOTREACHED() << "Print job settings must be a dictionary."; + return; + } + + if (settings->empty()) { + NOTREACHED() << "Print job settings dictionary is empty"; + return; + } + web_ui_->GetRenderViewHost()->PrintForPrintPreview(*settings); } void PrintPreviewHandler::SendPrinterList(const ListValue& printers) { diff --git a/chrome/browser/ui/webui/print_preview_handler.h b/chrome/browser/ui/webui/print_preview_handler.h index 5e8782026d3277..01cdba407d1036 100644 --- a/chrome/browser/ui/webui/print_preview_handler.h +++ b/chrome/browser/ui/webui/print_preview_handler.h @@ -32,7 +32,8 @@ class PrintPreviewHandler : public WebUIMessageHandler, // Get the list of printers. |args| is unused. void HandleGetPrinters(const ListValue* args); - // Print the preview PDF. |args| is unused. + // Get the job settings from Web UI and initiate printing. + // First element of |args| is a job settings json string. void HandlePrint(const ListValue* args); // Send the list of printers to the Web UI. diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 2b4db144b7a38f..ba6aa0b7875b4f 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -131,7 +131,8 @@ IPC_MESSAGE_ROUTED0(ViewMsg_PrintNodeUnderContextMenu) // Tells the renderer to print the print preview tab's PDF plugin without // showing the print dialog. -IPC_MESSAGE_ROUTED0(ViewMsg_PrintForPrintPreview) +IPC_MESSAGE_ROUTED1(ViewMsg_PrintForPrintPreview, + DictionaryValue /* settings*/) // Tells the render view to close. IPC_MESSAGE_ROUTED0(ViewMsg_Close) @@ -1713,6 +1714,13 @@ IPC_MESSAGE_ROUTED1(ViewHostMsg_DidPrintPage, IPC_SYNC_MESSAGE_ROUTED0_1(ViewHostMsg_GetDefaultPrintSettings, ViewMsg_Print_Params /* default_settings */) +// The renderer wants to update the current print settings with new +// |job_settings|. +IPC_SYNC_MESSAGE_ROUTED2_1(ViewHostMsg_UpdatePrintSettings, + int /* document_cookie */, + DictionaryValue /* job_settings */, + ViewMsg_Print_Params /* current_settings */) + // It's the renderer that controls the printing process when it is generated // by javascript. This step is about showing UI to the user to select the // final print settings. The output parameter is the same as diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 5ca14e6ec35946..974da5b5db2de2 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -139,7 +139,13 @@ bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { return handled; } -void PrintWebViewHelper::OnPrintForPrintPreview() { +void PrintWebViewHelper::OnPrintForPrintPreview( + const DictionaryValue& job_settings) { +#if defined(OS_MACOSX) + // If still not finished with earlier print request simply ignore. + if (print_web_view_) + return; + if (!render_view()->webview()) return; WebFrame* main_frame = render_view()->webview()->mainFrame(); @@ -155,7 +161,20 @@ void PrintWebViewHelper::OnPrintForPrintPreview() { return; } - PrintNode(&element, false, false); + if (!InitPrintSettings(element.document().frame(), &element)) { + NOTREACHED() << "Failed to initialize print page settings"; + return; + } + + if (!UpdatePrintSettings(job_settings)) { + NOTREACHED() << "Failed to update print page settings"; + DidFinishPrinting(true); // Release all printing resources. + return; + } + + // Render Pages for printing. + RenderPagesForPrint(element.document().frame(), &element); +#endif } void PrintWebViewHelper::OnPrint(bool is_preview) { @@ -499,10 +518,23 @@ bool PrintWebViewHelper::InitPrintSettings(WebFrame* frame, return false; } -bool PrintWebViewHelper::GetDefaultPrintSettings( - WebFrame* frame, - WebNode* node, - ViewMsg_Print_Params* params) { +bool PrintWebViewHelper::UpdatePrintSettings( + const DictionaryValue& job_settings) { + ViewMsg_PrintPages_Params settings; + if (!render_view()->Send(new ViewHostMsg_UpdatePrintSettings( + render_view()->routing_id(), + print_pages_params_->params.document_cookie, + job_settings, &settings.params))) { + NOTREACHED(); + return false; + } + print_pages_params_.reset(new ViewMsg_PrintPages_Params(settings)); + return true; +} + +bool PrintWebViewHelper::GetDefaultPrintSettings(WebFrame* frame, + WebNode* node, + ViewMsg_Print_Params* params) { if (!render_view()->Send(new ViewHostMsg_GetDefaultPrintSettings( render_view()->routing_id(), params))) { NOTREACHED(); diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 61d0a2ff6c4e27..84b136cfe40440 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -15,6 +15,8 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" #include "ui/gfx/size.h" +class DictionaryValue; + namespace gfx { class Size; } @@ -85,7 +87,11 @@ class PrintWebViewHelper : public RenderViewObserver , // Message handlers. Public for testing. void OnPrintingDone(int document_cookie, bool success); - void OnPrintForPrintPreview(); + + // Print the pages for print preview. Do not display the native print dialog + // for user settings. |job_settings| has new print job settings values. + void OnPrintForPrintPreview(const DictionaryValue& job_settings); + void OnPrintPages(); void OnPrintPreview(); void OnPrintNodeUnderContextMenu(); @@ -153,6 +159,11 @@ class PrintWebViewHelper : public RenderViewObserver , bool InitPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node); + // Update the current print settings with new |job_settings|. |job_settings| + // dictionary contains print job details such as printer name, number of + // copies, page range, etc. + bool UpdatePrintSettings(const DictionaryValue& job_settings); + // Get the default printer settings. bool GetDefaultPrintSettings(WebKit::WebFrame* frame, WebKit::WebNode* node, diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc index af2fdbf0d9fbef..1448beeb5f346d 100644 --- a/content/browser/renderer_host/render_view_host.cc +++ b/content/browser/renderer_host/render_view_host.cc @@ -1258,8 +1258,8 @@ void RenderViewHost::PrintNodeUnderContextMenu() { Send(new ViewMsg_PrintNodeUnderContextMenu(routing_id())); } -void RenderViewHost::PrintForPrintPreview() { - Send(new ViewMsg_PrintForPrintPreview(routing_id())); +void RenderViewHost::PrintForPrintPreview(const DictionaryValue& job_settings) { + Send(new ViewMsg_PrintForPrintPreview(routing_id(), job_settings)); } void RenderViewHost::OnMsgStartDragging( diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h index cc3bfacac8fe5a..bf365262ec0d1e 100644 --- a/content/browser/renderer_host/render_view_host.h +++ b/content/browser/renderer_host/render_view_host.h @@ -28,6 +28,7 @@ #include "webkit/glue/window_open_disposition.h" class ChildProcessSecurityPolicy; +class DictionaryValue; class FilePath; class GURL; class ListValue; @@ -328,8 +329,9 @@ class RenderViewHost : public RenderWidgetHost { // Prints the node that's under the context menu. void PrintNodeUnderContextMenu(); - // Triggers printing of the preview PDF. - void PrintForPrintPreview(); + // Triggers printing of the preview PDF. |job_settings| dictionary contains + // new print job settings information. + void PrintForPrintPreview(const DictionaryValue& job_settings); // Copies the image at the specified point. void CopyImageAt(int x, int y); diff --git a/printing/printing_context.h b/printing/printing_context.h index 6d51f0209c3de4..d7d50167dae759 100644 --- a/printing/printing_context.h +++ b/printing/printing_context.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -47,6 +47,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; + // 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 84aaa64b236472..c8b0ef3672a06a 100644 --- a/printing/printing_context_cairo.cc +++ b/printing/printing_context_cairo.cc @@ -151,6 +151,17 @@ PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { return OK; } +PrintingContext::Result PrintingContextCairo::UpdatePrintSettings( + const PageRanges& ranges) { + DCHECK(!in_print_job_); + + settings_.ranges = ranges; + + NOTIMPLEMENTED(); + + return FAILED; +} + PrintingContext::Result PrintingContextCairo::InitWithSettings( const PrintSettings& settings) { DCHECK(!in_print_job_); diff --git a/printing/printing_context_cairo.h b/printing/printing_context_cairo.h index 9a88eae8c1d399..514b3417c4144f 100644 --- a/printing/printing_context_cairo.h +++ b/printing/printing_context_cairo.h @@ -40,6 +40,7 @@ class PrintingContextCairo : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); + virtual Result UpdatePrintSettings(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 8f6bf34c41fa66..b7094602b91cea 100644 --- a/printing/printing_context_mac.h +++ b/printing/printing_context_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,6 +28,7 @@ class PrintingContextMac : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); + virtual Result UpdatePrintSettings(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.mm b/printing/printing_context_mac.mm index 1826c493e6feb6..575875d9d90f6b 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -80,6 +80,19 @@ return OK; } +PrintingContext::Result PrintingContextMac::UpdatePrintSettings( + 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; + + return OK; +} + void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { ResetSettings(); print_info_ = [print_info retain]; diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 3d40739f99449e..467bf3c7ad52b3 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -208,6 +208,17 @@ PrintingContext::Result PrintingContextWin::UseDefaultSettings() { return ParseDialogResult(dialog_options); } +PrintingContext::Result PrintingContextWin::UpdatePrintSettings( + const PageRanges& ranges) { + DCHECK(!in_print_job_); + + settings_.ranges = ranges; + + NOTIMPLEMENTED(); + + return FAILED; +} + PrintingContext::Result PrintingContextWin::InitWithSettings( const PrintSettings& settings) { DCHECK(!in_print_job_); diff --git a/printing/printing_context_win.h b/printing/printing_context_win.h index d42bf9742359bf..4037536d8858bc 100644 --- a/printing/printing_context_win.h +++ b/printing/printing_context_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,6 +28,7 @@ class PrintingContextWin : public PrintingContext { bool has_selection, PrintSettingsCallback* callback); virtual Result UseDefaultSettings(); + virtual Result UpdatePrintSettings(const PageRanges& ranges); virtual Result InitWithSettings(const PrintSettings& settings); virtual Result NewDocument(const string16& document_name); virtual Result NewPage();