summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorabodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 18:45:15 +0000
committerabodenha@chromium.org <abodenha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-08 18:45:15 +0000
commitea5e81d9e8236e0cfa9c9de9a39f63e4e7c476b3 (patch)
treee4ee09e4de3ada9c22bb8c3205fb40c3d080e280 /printing
parent01632e66fba4212e7e0ac5773ced0c4c1cc94564 (diff)
downloadchromium_src-ea5e81d9e8236e0cfa9c9de9a39f63e4e7c476b3.zip
chromium_src-ea5e81d9e8236e0cfa9c9de9a39f63e4e7c476b3.tar.gz
chromium_src-ea5e81d9e8236e0cfa9c9de9a39f63e4e7c476b3.tar.bz2
Get printing working in Aura.
Splits printing_context_cairo into gtk and no system dialog versions. No system dialog versions are used in Chrome OS and Aura. BUG=http://code.google.com/p/chromium-os/issues/detail?id=13915 TEST=Build Chrome with Aura. Hit ctrl-p from any web page. Print preview page should come up and should be able to print via Cloud Print. Review URL: http://codereview.chromium.org/8372030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/print_dialog_gtk_interface.h4
-rw-r--r--printing/printed_document_cairo.cc4
-rw-r--r--printing/printing.gyp48
-rw-r--r--printing/printing_context_aura.cc19
-rw-r--r--printing/printing_context_cairo.cc237
-rw-r--r--printing/printing_context_gtk.cc157
-rw-r--r--printing/printing_context_gtk.h (renamed from printing/printing_context_cairo.h)21
-rw-r--r--printing/printing_context_no_system_dialog.cc158
-rw-r--r--printing/printing_context_no_system_dialog.h50
9 files changed, 409 insertions, 289 deletions
diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h
index 22de95c..589ad71 100644
--- a/printing/print_dialog_gtk_interface.h
+++ b/printing/print_dialog_gtk_interface.h
@@ -6,7 +6,7 @@
#define PRINTING_PRINT_DIALOG_GTK_INTERFACE_H_
#include "base/string16.h"
-#include "printing/printing_context_cairo.h"
+#include "printing/printing_context_gtk.h"
namespace printing {
@@ -32,7 +32,7 @@ class PrintDialogGtkInterface {
// Shows the dialog and handles the response with |callback|. Only used when
// printing with the native print dialog.
virtual void ShowDialog(
- PrintingContextCairo::PrintSettingsCallback* callback) = 0;
+ PrintingContextGtk::PrintSettingsCallback* callback) = 0;
// Prints the document named |document_name| contained in |metafile|.
// Called from the print worker thread. Once called, the
diff --git a/printing/printed_document_cairo.cc b/printing/printed_document_cairo.cc
index 15193c7..7a1fb32 100644
--- a/printing/printed_document_cairo.cc
+++ b/printing/printed_document_cairo.cc
@@ -7,7 +7,7 @@
#include "base/logging.h"
#include "printing/page_number.h"
#include "printing/printed_page.h"
-#include "printing/printing_context_cairo.h"
+#include "printing/printing_context_gtk.h"
namespace printing {
@@ -27,7 +27,7 @@ void PrintedDocument::RenderPrintedPage(
{
base::AutoLock lock(lock_);
if (page.page_number() - 1 == mutable_.first_page) {
- reinterpret_cast<PrintingContextCairo*>(context)->PrintDocument(
+ reinterpret_cast<PrintingContextGtk*>(context)->PrintDocument(
page.metafile());
}
}
diff --git a/printing/printing.gyp b/printing/printing.gyp
index ca7f787..7c66b9a 100644
--- a/printing/printing.gyp
+++ b/printing/printing.gyp
@@ -66,13 +66,6 @@
'printed_pages_source.h',
'printing_context.cc',
'printing_context.h',
- 'printing_context_aura.cc',
- 'printing_context_cairo.cc',
- 'printing_context_cairo.h',
- 'printing_context_mac.mm',
- 'printing_context_mac.h',
- 'printing_context_win.cc',
- 'printing_context_win.h',
'print_dialog_gtk_interface.h',
'print_job_constants.cc',
'print_job_constants.h',
@@ -117,16 +110,25 @@
['exclude', 'metafile_skia_wrapper\\.(cc|h)$'],
],
}],
+ ['OS=="mac" and use_aura==0',{
+ 'sources': [
+ 'printing_context_mac.mm',
+ 'printing_context_mac.h',
+ ],
+ }],
['OS=="win"', {
'conditions': [
['use_aura==1', {
'sources!': [
'image_aura.cc',
'printed_document_aura.cc',
- 'printing_context_aura.cc',
],
- }],
- ],
+ }, { #else: use_aura==0
+ 'sources': [
+ 'printing_context_win.cc',
+ 'printing_context_win.h',
+ ],
+ }]],
'defines': [
# PRINT_BACKEND_AVAILABLE disables the default dummy implementation
# of the print backend and enables a custom implementation instead.
@@ -138,6 +140,12 @@
'backend/print_backend_win.cc',
],
}],
+ ['chromeos==1 or use_aura==1',{
+ 'sources': [
+ 'printing_context_no_system_dialog.cc',
+ 'printing_context_no_system_dialog.h',
+ ],
+ }],
['use_cups==1', {
'dependencies': [
'cups',
@@ -170,6 +178,12 @@
'backend/print_backend_chromeos.cc',
],
}],
+ ['OS=="linux" and chromeos==0', {
+ 'sources': [
+ 'printing_context_gtk.cc',
+ 'printing_context_gtk.h',
+ ],
+ }],
],
},
{
@@ -189,18 +203,18 @@
'page_setup_unittest.cc',
'pdf_metafile_cg_mac_unittest.cc',
'printed_page_unittest.cc',
- 'printing_context_win_unittest.cc',
'run_all_unittests.cc',
'units_unittest.cc',
],
'conditions': [
- ['toolkit_uses_gtk == 0', {'sources/': [['exclude', '_cairo_unittest\\.cc$']]}],
+ ['toolkit_uses_gtk == 0', {'sources/': [['exclude', '_gtk_unittest\\.cc$']]}],
['OS!="mac"', {'sources/': [['exclude', '_mac_unittest\\.(cc|mm?)$']]}],
- ['OS!="win"', {'sources/': [['exclude', '_win_unittest\\.cc$']]
- }, { # else: OS=="win"
- 'sources/': [['exclude', '_cairo_unittest\\.cc$']]
- }
- ],
+ ['OS!="win"', {'sources/': [['exclude', '_win_unittest\\.cc$']]}],
+ ['OS=="win" and use_aura == 0', {
+ 'sources': [
+ 'printing_context_win_unittest.cc',
+ ]
+ }],
['toolkit_uses_gtk == 1', {
'dependencies': [
'../build/linux/system.gyp:gtk',
diff --git a/printing/printing_context_aura.cc b/printing/printing_context_aura.cc
deleted file mode 100644
index 48c958b..0000000
--- a/printing/printing_context_aura.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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.
-
-#include "printing/printing_context.h"
-
-#include "base/logging.h"
-
-namespace printing {
-
-// static
-PrintingContext* PrintingContext::Create(const std::string& app_locale) {
- // TODO(saintlou): This a stub to allow us to build under Aura.
- // See issue: http://crbug.com/99282
- NOTIMPLEMENTED();
- return NULL;
-}
-
-} // namespace printing
diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc
deleted file mode 100644
index 81d8d92..0000000
--- a/printing/printing_context_cairo.cc
+++ /dev/null
@@ -1,237 +0,0 @@
-// 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.
-
-#include "printing/printing_context_cairo.h"
-
-// TODO(abodenha@chromium.org) The number of #ifdefs here has gotten too
-// large. Refactor this code into separate files for Linux and Chrome OS.
-
-#include "base/logging.h"
-#include "base/values.h"
-#include "printing/metafile.h"
-#include "printing/print_job_constants.h"
-#include "printing/units.h"
-
-#if defined(OS_CHROMEOS)
-#include <unicode/ulocdata.h>
-#include "printing/print_settings_initializer_gtk.h"
-#else
-#include <gtk/gtk.h>
-#include <gtk/gtkprintunixdialog.h>
-#include "printing/print_dialog_gtk_interface.h"
-#endif // defined(OS_CHROMEOS)
-
-#if !defined(OS_CHROMEOS)
-namespace {
- // Function pointer for creating print dialogs. |callback| is only used when
- // |show_dialog| is true.
- static printing::PrintDialogGtkInterface* (*create_dialog_func_)(
- printing::PrintingContextCairo* context) = NULL;
-} // namespace
-#endif // !defined(OS_CHROMEOS)
-
-namespace printing {
-
-// static
-PrintingContext* PrintingContext::Create(const std::string& app_locale) {
- return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale));
-}
-
-PrintingContextCairo::PrintingContextCairo(const std::string& app_locale)
-#if defined(OS_CHROMEOS)
- : PrintingContext(app_locale) {
-#else
- : PrintingContext(app_locale),
- print_dialog_(NULL) {
-#endif
-}
-
-PrintingContextCairo::~PrintingContextCairo() {
- ReleaseContext();
-
-#if !defined(OS_CHROMEOS)
- if (print_dialog_)
- print_dialog_->ReleaseDialog();
-#endif
-}
-
-#if !defined(OS_CHROMEOS)
-// static
-void PrintingContextCairo::SetCreatePrintDialogFunction(
- PrintDialogGtkInterface* (*create_dialog_func)(
- PrintingContextCairo* context)) {
- DCHECK(create_dialog_func);
- DCHECK(!create_dialog_func_);
- create_dialog_func_ = create_dialog_func;
-}
-
-void PrintingContextCairo::PrintDocument(const Metafile* metafile) {
- DCHECK(print_dialog_);
- DCHECK(metafile);
- print_dialog_->PrintDocument(metafile, document_name_);
-}
-#endif // !defined(OS_CHROMEOS)
-
-void PrintingContextCairo::AskUserForSettings(
- gfx::NativeView parent_view,
- int max_pages,
- bool has_selection,
- PrintSettingsCallback* callback) {
-#if defined(OS_CHROMEOS)
- callback->Run(OK);
-#else
- print_dialog_->ShowDialog(callback);
-#endif // defined(OS_CHROMEOS)
-}
-
-PrintingContext::Result PrintingContextCairo::UseDefaultSettings() {
- DCHECK(!in_print_job_);
-
- ResetSettings();
-#if defined(OS_CHROMEOS)
- // For Chrome OS use default values based on the app locale rather than rely
- // on GTK. Note that relying on the app locale does not work well if it is
- // different from the system locale, e.g. a user using Chinese ChromeOS in the
- // US. Eventually we need to get the defaults from the printer.
- // TODO(sanjeevr): We need a better feedback loop between the cloud print
- // dialog and this code.
- int dpi = 300;
- gfx::Size physical_size_device_units;
- gfx::Rect printable_area_device_units;
- int32_t width = 0;
- int32_t height = 0;
- UErrorCode error = U_ZERO_ERROR;
- ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
- if (error != U_ZERO_ERROR) {
- // If the call failed, assume a paper size of 8.5 x 11 inches.
- LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
- << error;
- width = static_cast<int>(8.5 * dpi);
- height = static_cast<int>(11 * dpi);
- } else {
- // ulocdata_getPaperSize returns the width and height in mm.
- // Convert this to pixels based on the dpi.
- width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi);
- height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi);
- }
-
- physical_size_device_units.SetSize(width, height);
- printable_area_device_units.SetRect(
- static_cast<int>(PrintSettingsInitializerGtk::kLeftMarginInInch * dpi),
- static_cast<int>(PrintSettingsInitializerGtk::kTopMarginInInch * dpi),
- width - (PrintSettingsInitializerGtk::kLeftMarginInInch +
- PrintSettingsInitializerGtk::kRightMarginInInch) * dpi,
- height - (PrintSettingsInitializerGtk::kTopMarginInInch +
- PrintSettingsInitializerGtk::kBottomMarginInInch) * dpi);
-
- settings_.set_dpi(dpi);
- settings_.SetPrinterPrintableArea(physical_size_device_units,
- printable_area_device_units,
- dpi);
-#else
- if (!print_dialog_) {
- print_dialog_ = create_dialog_func_(this);
- print_dialog_->AddRefToDialog();
- }
- print_dialog_->UseDefaultSettings();
-#endif // defined(OS_CHROMEOS)
-
- return OK;
-}
-
-PrintingContext::Result PrintingContextCairo::UpdatePrinterSettings(
- const DictionaryValue& job_settings, const PageRanges& ranges) {
-#if defined(OS_CHROMEOS)
- bool landscape = false;
-
- if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
- return OnError();
-
- if (settings_.dpi() == 0)
- UseDefaultSettings();
-
- settings_.SetOrientation(landscape);
- settings_.ranges = ranges;
-
- return OK;
-#else
- DCHECK(!in_print_job_);
-
- if (!print_dialog_) {
- print_dialog_ = create_dialog_func_(this);
- print_dialog_->AddRefToDialog();
- }
-
- if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_))
- return OnError();
-
- return OK;
-#endif
-}
-
-PrintingContext::Result PrintingContextCairo::InitWithSettings(
- const PrintSettings& settings) {
- DCHECK(!in_print_job_);
-
- settings_ = settings;
-
- return OK;
-}
-
-PrintingContext::Result PrintingContextCairo::NewDocument(
- const string16& document_name) {
- DCHECK(!in_print_job_);
- in_print_job_ = true;
-
-#if !defined(OS_CHROMEOS)
- document_name_ = document_name;
-#endif // !defined(OS_CHROMEOS)
-
- return OK;
-}
-
-PrintingContext::Result PrintingContextCairo::NewPage() {
- if (abort_printing_)
- return CANCEL;
- DCHECK(in_print_job_);
-
- // Intentional No-op.
-
- return OK;
-}
-
-PrintingContext::Result PrintingContextCairo::PageDone() {
- if (abort_printing_)
- return CANCEL;
- DCHECK(in_print_job_);
-
- // Intentional No-op.
-
- return OK;
-}
-
-PrintingContext::Result PrintingContextCairo::DocumentDone() {
- if (abort_printing_)
- return CANCEL;
- DCHECK(in_print_job_);
-
- ResetSettings();
- return OK;
-}
-
-void PrintingContextCairo::Cancel() {
- abort_printing_ = true;
- in_print_job_ = false;
-}
-
-void PrintingContextCairo::ReleaseContext() {
- // Intentional No-op.
-}
-
-gfx::NativeDrawingContext PrintingContextCairo::context() const {
- // Intentional No-op.
- return NULL;
-}
-
-} // namespace printing
diff --git a/printing/printing_context_gtk.cc b/printing/printing_context_gtk.cc
new file mode 100644
index 0000000..8d47e6a
--- /dev/null
+++ b/printing/printing_context_gtk.cc
@@ -0,0 +1,157 @@
+// 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.
+
+#include "printing/printing_context_gtk.h"
+
+#include <gtk/gtk.h>
+#include <gtk/gtkprintunixdialog.h>
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "printing/metafile.h"
+#include "printing/print_dialog_gtk_interface.h"
+#include "printing/print_job_constants.h"
+#include "printing/units.h"
+
+namespace {
+ // Function pointer for creating print dialogs. |callback| is only used when
+ // |show_dialog| is true.
+ static printing::PrintDialogGtkInterface* (*create_dialog_func_)(
+ printing::PrintingContextGtk* context) = NULL;
+} // namespace
+
+namespace printing {
+
+// static
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(new PrintingContextGtk(app_locale));
+}
+
+PrintingContextGtk::PrintingContextGtk(const std::string& app_locale)
+ : PrintingContext(app_locale),
+ print_dialog_(NULL) {
+}
+
+PrintingContextGtk::~PrintingContextGtk() {
+ ReleaseContext();
+
+ if (print_dialog_)
+ print_dialog_->ReleaseDialog();
+}
+
+// static
+void PrintingContextGtk::SetCreatePrintDialogFunction(
+ PrintDialogGtkInterface* (*create_dialog_func)(
+ PrintingContextGtk* context)) {
+ DCHECK(create_dialog_func);
+ DCHECK(!create_dialog_func_);
+ create_dialog_func_ = create_dialog_func;
+}
+
+void PrintingContextGtk::PrintDocument(const Metafile* metafile) {
+ DCHECK(print_dialog_);
+ DCHECK(metafile);
+ print_dialog_->PrintDocument(metafile, document_name_);
+}
+
+void PrintingContextGtk::AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ PrintSettingsCallback* callback) {
+ print_dialog_->ShowDialog(callback);
+}
+
+PrintingContext::Result PrintingContextGtk::UseDefaultSettings() {
+ DCHECK(!in_print_job_);
+
+ ResetSettings();
+ if (!print_dialog_) {
+ print_dialog_ = create_dialog_func_(this);
+ print_dialog_->AddRefToDialog();
+ }
+ print_dialog_->UseDefaultSettings();
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::UpdatePrinterSettings(
+ const DictionaryValue& job_settings, const PageRanges& ranges) {
+ DCHECK(!in_print_job_);
+
+ if (!print_dialog_) {
+ print_dialog_ = create_dialog_func_(this);
+ print_dialog_->AddRefToDialog();
+ }
+
+ if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_))
+ return OnError();
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::InitWithSettings(
+ const PrintSettings& settings) {
+ DCHECK(!in_print_job_);
+
+ settings_ = settings;
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::NewDocument(
+ const string16& document_name) {
+ DCHECK(!in_print_job_);
+ in_print_job_ = true;
+
+ document_name_ = document_name;
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::NewPage() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ // Intentional No-op.
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::PageDone() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ // Intentional No-op.
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextGtk::DocumentDone() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ ResetSettings();
+ return OK;
+}
+
+void PrintingContextGtk::Cancel() {
+ abort_printing_ = true;
+ in_print_job_ = false;
+}
+
+void PrintingContextGtk::ReleaseContext() {
+ // Intentional No-op.
+}
+
+gfx::NativeDrawingContext PrintingContextGtk::context() const {
+ // Intentional No-op.
+ return NULL;
+}
+
+} // namespace printing
+
diff --git a/printing/printing_context_cairo.h b/printing/printing_context_gtk.h
index 088f01b..2dddd43 100644
--- a/printing/printing_context_cairo.h
+++ b/printing/printing_context_gtk.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PRINTING_PRINTING_CONTEXT_CAIRO_H_
-#define PRINTING_PRINTING_CONTEXT_CAIRO_H_
+#ifndef PRINTING_PRINTING_CONTEXT_GTK_H_
+#define PRINTING_PRINTING_CONTEXT_GTK_H_
#include <string>
@@ -18,20 +18,18 @@ namespace printing {
class Metafile;
class PrintDialogGtkInterface;
-class PRINTING_EXPORT PrintingContextCairo : public PrintingContext {
+class PRINTING_EXPORT PrintingContextGtk : public PrintingContext {
public:
- explicit PrintingContextCairo(const std::string& app_locale);
- virtual ~PrintingContextCairo();
+ explicit PrintingContextGtk(const std::string& app_locale);
+ virtual ~PrintingContextGtk();
-#if !defined(OS_CHROMEOS)
// Sets the function that creates the print dialog.
static void SetCreatePrintDialogFunction(
PrintDialogGtkInterface* (*create_dialog_func)(
- PrintingContextCairo* context));
+ PrintingContextGtk* context));
// Prints the document contained in |metafile|.
void PrintDocument(const Metafile* metafile);
-#endif
// PrintingContext implementation.
virtual void AskUserForSettings(gfx::NativeView parent_view,
@@ -52,14 +50,13 @@ class PRINTING_EXPORT PrintingContextCairo : public PrintingContext {
virtual gfx::NativeDrawingContext context() const;
private:
-#if !defined(OS_CHROMEOS)
string16 document_name_;
PrintDialogGtkInterface* print_dialog_;
-#endif
- DISALLOW_COPY_AND_ASSIGN(PrintingContextCairo);
+ DISALLOW_COPY_AND_ASSIGN(PrintingContextGtk);
};
} // namespace printing
-#endif // PRINTING_PRINTING_CONTEXT_CAIRO_H_
+#endif // PRINTING_PRINTING_CONTEXT_GTK_H_
+
diff --git a/printing/printing_context_no_system_dialog.cc b/printing/printing_context_no_system_dialog.cc
new file mode 100644
index 0000000..dac11d4
--- /dev/null
+++ b/printing/printing_context_no_system_dialog.cc
@@ -0,0 +1,158 @@
+// 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.
+
+#include "printing/printing_context_no_system_dialog.h"
+
+#include <unicode/ulocdata.h>
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "printing/metafile.h"
+#include "printing/print_job_constants.h"
+#include "printing/units.h"
+
+namespace printing {
+
+// static
+PrintingContext* PrintingContext::Create(const std::string& app_locale) {
+ return static_cast<PrintingContext*>(
+ new PrintingContextNoSystemDialog(app_locale));
+}
+
+PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
+ const std::string& app_locale) : PrintingContext(app_locale) {
+}
+
+PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
+ ReleaseContext();
+}
+
+void PrintingContextNoSystemDialog::AskUserForSettings(
+ gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ PrintSettingsCallback* callback) {
+ // We don't want to bring up a dialog here. Ever. Just signal the callback.
+ callback->Run(OK);
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
+ DCHECK(!in_print_job_);
+
+ ResetSettings();
+ // TODO(abodenha): Fetch these settings from the OS where possible. See
+ // bug 102583.
+ // TODO(sanjeevr): We need a better feedback loop between the cloud print
+ // dialog and this code.
+ int dpi = 300;
+ gfx::Size physical_size_device_units;
+ gfx::Rect printable_area_device_units;
+ int32_t width = 0;
+ int32_t height = 0;
+ UErrorCode error = U_ZERO_ERROR;
+ ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
+ if (error != U_ZERO_ERROR) {
+ // If the call failed, assume a paper size of 8.5 x 11 inches.
+ LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
+ << error;
+ width = static_cast<int>(8.5 * dpi);
+ height = static_cast<int>(11 * dpi);
+ } else {
+ // ulocdata_getPaperSize returns the width and height in mm.
+ // Convert this to pixels based on the dpi.
+ width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi);
+ height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi);
+ }
+
+ physical_size_device_units.SetSize(width, height);
+
+ // Assume full page is printable for now.
+ printable_area_device_units.SetRect(0, 0, width, height);
+
+ settings_.set_dpi(dpi);
+ settings_.SetPrinterPrintableArea(physical_size_device_units,
+ printable_area_device_units,
+ dpi);
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
+ const DictionaryValue& job_settings, const PageRanges& ranges) {
+ bool landscape = false;
+
+ if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
+ return OnError();
+
+ if (settings_.dpi() == 0)
+ UseDefaultSettings();
+
+ settings_.SetOrientation(landscape);
+ settings_.ranges = ranges;
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
+ const PrintSettings& settings) {
+ DCHECK(!in_print_job_);
+
+ settings_ = settings;
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
+ const string16& document_name) {
+ DCHECK(!in_print_job_);
+ in_print_job_ = true;
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ // Intentional No-op.
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ // Intentional No-op.
+
+ return OK;
+}
+
+PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
+ if (abort_printing_)
+ return CANCEL;
+ DCHECK(in_print_job_);
+
+ ResetSettings();
+ return OK;
+}
+
+void PrintingContextNoSystemDialog::Cancel() {
+ abort_printing_ = true;
+ in_print_job_ = false;
+}
+
+void PrintingContextNoSystemDialog::ReleaseContext() {
+ // Intentional No-op.
+}
+
+gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
+ // Intentional No-op.
+ return NULL;
+}
+
+} // namespace printing
+
diff --git a/printing/printing_context_no_system_dialog.h b/printing/printing_context_no_system_dialog.h
new file mode 100644
index 0000000..0f9316d
--- /dev/null
+++ b/printing/printing_context_no_system_dialog.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
+#define PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
+
+#include <string>
+
+#include "printing/printing_context.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace printing {
+
+class Metafile;
+
+class PRINTING_EXPORT PrintingContextNoSystemDialog : public PrintingContext {
+ public:
+ explicit PrintingContextNoSystemDialog(const std::string& app_locale);
+ virtual ~PrintingContextNoSystemDialog();
+
+ // PrintingContext implementation.
+ virtual void AskUserForSettings(gfx::NativeView parent_view,
+ int max_pages,
+ bool has_selection,
+ PrintSettingsCallback* callback);
+ virtual Result UseDefaultSettings();
+ virtual Result UpdatePrinterSettings(
+ const base::DictionaryValue& job_settings,
+ const PageRanges& ranges);
+ virtual Result InitWithSettings(const PrintSettings& settings);
+ virtual Result NewDocument(const string16& document_name);
+ virtual Result NewPage();
+ virtual Result PageDone();
+ virtual Result DocumentDone();
+ virtual void Cancel();
+ virtual void ReleaseContext();
+ virtual gfx::NativeDrawingContext context() const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PrintingContextNoSystemDialog);
+};
+
+} // namespace printing
+
+#endif // PRINTING_PRINTING_CONTEXT_NO_SYSTEM_DIALOG_H_
+