(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
This commit is contained in:
chrome
browser
printing
print_job_worker.ccprint_job_worker.hprinter_query.ccprinter_query.hprinting_message_filter.ccprinting_message_filter.h
resources
ui
common
renderer
content/browser/renderer_host
printing
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,23 +79,9 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
|
||||
CancelableTask* callback) {
|
||||
DCHECK_EQ(io_message_loop_, MessageLoop::current());
|
||||
DCHECK(!is_print_dialog_box_shown_);
|
||||
DCHECK(!callback_.get());
|
||||
DCHECK(worker_.get());
|
||||
if (!worker_.get())
|
||||
if (!StartWorker(callback))
|
||||
return;
|
||||
// Lazy create the worker thread. There is one worker thread per print job.
|
||||
if (!worker_->message_loop()) {
|
||||
if (!worker_->Start()) {
|
||||
if (callback) {
|
||||
callback->Cancel();
|
||||
delete callback;
|
||||
}
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
@ -107,6 +94,38 @@ void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
|
||||
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 false;
|
||||
|
||||
// Lazy create the worker thread. There is one worker thread per print job.
|
||||
if (!worker_->message_loop()) {
|
||||
if (!worker_->Start()) {
|
||||
if (callback) {
|
||||
callback->Cancel();
|
||||
delete callback;
|
||||
}
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
callback_.reset(callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PrinterQuery::StopWorker() {
|
||||
if (worker_.get()) {
|
||||
// http://crbug.com/66082: We're blocking on the PrinterQuery's worker
|
||||
|
@ -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_;
|
||||
|
@ -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<printing::PrinterQuery> 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<printing::PrinterQuery> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<printing::PrinterQuery> printer_query,
|
||||
IPC::Message* reply_msg);
|
||||
|
||||
printing::PrintJobManager* print_job_manager_;
|
||||
|
||||
bool cloud_print_enabled_;
|
||||
|
@ -25,7 +25,7 @@
|
||||
<section>
|
||||
<h3>Pages</h3>
|
||||
<div>
|
||||
<input id="pages" type="textbox"></input>
|
||||
<input id="pages" type="text"></input>
|
||||
<label>
|
||||
<input id="all-pages" type="checkbox">
|
||||
<span i18n-content="optionAllPages"></span>
|
||||
@ -42,7 +42,7 @@
|
||||
<section>
|
||||
<h3>Copies</h3>
|
||||
<div>
|
||||
<input id="copies" type="textbox"></input>
|
||||
<input id="copies" type="text" value="1"></input>
|
||||
<div>
|
||||
<label>
|
||||
<input id="collate" type="checkbox">
|
||||
@ -56,8 +56,8 @@
|
||||
<h3>Layout</h3>
|
||||
<div>
|
||||
<select id="layout">
|
||||
<option i18n-content="optionPortrait"></option>
|
||||
<option i18n-content="optionLandscape"></option>
|
||||
<option value="0" i18n-content="optionPortrait"></option>
|
||||
<option value="1" i18n-content="optionLandscape"></option>
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
@ -66,8 +66,8 @@
|
||||
<h3>Color</h3>
|
||||
<div>
|
||||
<select id="color">
|
||||
<option i18n-content="optionColor"></option>
|
||||
<option i18n-content="optionBw"></option>
|
||||
<option value="0" i18n-content="optionBw"></option>
|
||||
<option value="1" i18n-content="optionColor"></option>
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
@ -79,8 +79,5 @@
|
||||
<p id="no-plugin" class="hidden" i18n-content="noPlugin"></p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
console.log('in bottom script');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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<DictionaryValue> settings(static_cast<DictionaryValue*>(
|
||||
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) {
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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_);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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 @@ PrintingContext::Result PrintingContextMac::UseDefaultSettings() {
|
||||
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];
|
||||
|
@ -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_);
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user