diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:49:46 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-16 21:49:46 +0000 |
commit | 4bee23f2f19aa81bc95c662a56d8b3ec66d611de (patch) | |
tree | a0cb9315a01ce975bd9afd6c1d15e3c1b07e477d /chrome | |
parent | a1748e45f0b50f59ea37ce9d065b0bcfb47c8e91 (diff) | |
download | chromium_src-4bee23f2f19aa81bc95c662a56d8b3ec66d611de.zip chromium_src-4bee23f2f19aa81bc95c662a56d8b3ec66d611de.tar.gz chromium_src-4bee23f2f19aa81bc95c662a56d8b3ec66d611de.tar.bz2 |
GTK: Add a dialog for printing.
Add an infobar directing users to tell us if they have problems with printing.
Hide printing behind --enable-printing flag on linux/gtk.
BUG=9847
TEST=none
Review URL: http://codereview.chromium.org/200138
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser.cc | 10 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_gtk.cc | 138 | ||||
-rw-r--r-- | chrome/browser/printing/print_dialog_gtk.h | 55 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_message_filter_gtk.cc | 9 | ||||
-rw-r--r-- | chrome/browser/resources/linux-splash-chrome.html | 22 | ||||
-rw-r--r-- | chrome/browser/resources/linux-splash.html | 22 | ||||
-rw-r--r-- | chrome/chrome.gyp | 9 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 4 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 4 |
9 files changed, 260 insertions, 13 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 5ba9b8e..ea14851 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -2257,7 +2257,17 @@ void Browser::InitCommandState() { // Page-related commands command_updater_.UpdateCommandEnabled(IDC_CLOSE_POPUPS, true); + // TODO(estade): remove these ifdefs when printing is fully supported. +#if defined(OS_LINUX) +#if defined(TOOLKIT_GTK) + command_updater_.UpdateCommandEnabled(IDC_PRINT, + CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePrinting)); +#elif defined(TOOLKIT_VIEWS) + command_updater_.UpdateCommandEnabled(IDC_PRINT, false); +#endif +#else // !defined(OS_LINUX) command_updater_.UpdateCommandEnabled(IDC_PRINT, true); +#endif command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true); diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc new file mode 100644 index 0000000..81171a6 --- /dev/null +++ b/chrome/browser/printing/print_dialog_gtk.cc @@ -0,0 +1,138 @@ +// Copyright (c) 2009 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 "chrome/browser/printing/print_dialog_gtk.h" + +#include <gtk/gtkprintjob.h> +#include <gtk/gtkprintunixdialog.h> +#include <gtk/gtkpagesetupunixdialog.h> + +#include "base/logging.h" +#include "base/message_loop.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/tab_contents.h" + +namespace { + +// This is a temporary infobar designed to help gauge how many users are trying +// to print to printers that don't support PDF. +class PdfUnsupportedInfoBarDelegate : public LinkInfoBarDelegate { + public: + PdfUnsupportedInfoBarDelegate(Browser* browser) + : LinkInfoBarDelegate(NULL), + browser_(browser) { + } + + ~PdfUnsupportedInfoBarDelegate() {} + + virtual std::wstring GetMessageTextWithOffset(size_t* link_offset) const { + std::wstring message(L"Oops! Your printer does not support PDF. Please " + L"report this to us ."); + *link_offset = message.length() - 1; + return message; + } + + virtual std::wstring GetLinkText() const { + return std::wstring(L"here"); + } + + virtual Type GetInfoBarType() { + return ERROR_TYPE; + } + + virtual bool LinkClicked(WindowOpenDisposition disposition) { + browser_->OpenURL( + GURL("http://code.google.com/p/chromium/issues/detail?id=22027"), + GURL(), NEW_FOREGROUND_TAB, PageTransition::TYPED); + return true; + } + + private: + Browser* browser_; +}; + +} // namespace + +// static +void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path, + MessageLoop* loop) { + loop->PostTask(FROM_HERE, + NewRunnableFunction(&PrintDialogGtk::CreateDialogImpl, path)); +} + +// static +void PrintDialogGtk::CreateDialogImpl(const FilePath& path) { + new PrintDialogGtk(path); +} + +PrintDialogGtk::PrintDialogGtk(const FilePath& path_to_pdf) + : path_to_pdf_(path_to_pdf), + browser_(BrowserList::GetLastActive()) { + GtkWindow* parent = browser_->window()->GetNativeHandle(); + + // TODO(estade): We need a window title here. + dialog_ = gtk_print_unix_dialog_new(NULL, parent); + g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); + + gtk_widget_show_all(dialog_); +} + +PrintDialogGtk::~PrintDialogGtk() { +} + +void PrintDialogGtk::OnResponse(gint response_id) { + gtk_widget_hide(dialog_); + + switch (response_id) { + case GTK_RESPONSE_OK: { + GtkPrinter* printer = + gtk_print_unix_dialog_get_selected_printer( + GTK_PRINT_UNIX_DIALOG(dialog_)); + if (!gtk_printer_accepts_pdf(printer)) { + browser_->GetSelectedTabContents()->AddInfoBar( + new PdfUnsupportedInfoBarDelegate(browser_)); + break; + } + + GtkPrintSettings* settings = + gtk_print_unix_dialog_get_settings( + GTK_PRINT_UNIX_DIALOG(dialog_)); + GtkPageSetup* setup = gtk_print_unix_dialog_get_page_setup( + GTK_PRINT_UNIX_DIALOG(dialog_)); + + GtkPrintJob* job = + gtk_print_job_new(path_to_pdf_.value().c_str(), printer, + settings, setup); + gtk_print_job_set_source_file(job, path_to_pdf_.value().c_str(), NULL); + gtk_print_job_send(job, OnJobCompletedThunk, this, NULL); + g_object_unref(settings); + // Success; return early. + return; + } + case GTK_RESPONSE_CANCEL: { + break; + } + case GTK_RESPONSE_APPLY: + default: { + NOTREACHED(); + } + } + + // Delete this dialog. + OnJobCompleted(NULL, NULL); +} + +void PrintDialogGtk::OnJobCompleted(GtkPrintJob* job, GError* error) { + gtk_widget_destroy(dialog_); + + if (error) + LOG(ERROR) << "Printing failed: " << error->message; + + if (job) + g_object_unref(job); + + delete this; +} diff --git a/chrome/browser/printing/print_dialog_gtk.h b/chrome/browser/printing/print_dialog_gtk.h new file mode 100644 index 0000000..7f9cc7f --- /dev/null +++ b/chrome/browser/printing/print_dialog_gtk.h @@ -0,0 +1,55 @@ +// Copyright (c) 2009 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 CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ +#define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ + +#include <gtk/gtk.h> + +#include "base/basictypes.h" +#include "base/file_path.h" + +class Browser; +class MessageLoop; + +typedef struct _GtkPrintJob GtkPrintJob; + +// Currently this dialog only allows the user to choose a printer. +class PrintDialogGtk { + public: + // Called on the IO thread. Posts the dialog creation action on the given + // loop. + static void CreatePrintDialogForPdf(const FilePath& path, MessageLoop* loop); + + private: + explicit PrintDialogGtk(const FilePath& path_to_pdf); + ~PrintDialogGtk(); + + static void CreateDialogImpl(const FilePath& path); + + static void OnResponseThunk(GtkDialog* dialog, + gint response_id, + gpointer user_data) { + reinterpret_cast<PrintDialogGtk*>(user_data)->OnResponse(response_id); + } + void OnResponse(gint response_id); + + static void OnJobCompletedThunk(GtkPrintJob* print_job, + gpointer user_data, + GError* error) { + reinterpret_cast<PrintDialogGtk*>(user_data)->OnJobCompleted(print_job, + error); + } + void OnJobCompleted(GtkPrintJob* job, GError* error); + + FilePath path_to_pdf_; + + GtkWidget* dialog_; + + Browser* browser_; + + DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); +}; + +#endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ diff --git a/chrome/browser/renderer_host/resource_message_filter_gtk.cc b/chrome/browser/renderer_host/resource_message_filter_gtk.cc index 8533cac..3ae5343 100644 --- a/chrome/browser/renderer_host/resource_message_filter_gtk.cc +++ b/chrome/browser/renderer_host/resource_message_filter_gtk.cc @@ -14,6 +14,9 @@ #include "base/path_service.h" #include "base/singleton.h" #include "chrome/browser/chrome_thread.h" +#if defined(TOOLKIT_GTK) +#include "chrome/browser/printing/print_dialog_gtk.h" +#endif #include "chrome/common/chrome_paths.h" #include "chrome/common/render_messages.h" #include "chrome/common/x11_util.h" @@ -268,7 +271,11 @@ void ResourceMessageFilter::OnTempFileForPrintingWritten(int fd_in_browser) { return; } - // TODO(estade): print it. +#if defined(TOOLKIT_GTK) + PrintDialogGtk::CreatePrintDialogForPdf(it->second, ui_loop()); +#else + NOTIMPLEMENTED(); +#endif // Erase the entry in the map. map->erase(it); diff --git a/chrome/browser/resources/linux-splash-chrome.html b/chrome/browser/resources/linux-splash-chrome.html index 8430a43..6ea8589 100644 --- a/chrome/browser/resources/linux-splash-chrome.html +++ b/chrome/browser/resources/linux-splash-chrome.html @@ -44,12 +44,12 @@ <p>Every minute spent triaging and de-duplicating bugs is a minute spent not fixing them. If you have a good bug report (e.g. includes a stack trace or a reduced test case), first verify it exists in the <a - href="http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/">latest - build</a>, then <a - href="http://code.google.com/p/chromium/issues/list?can=1&q=os:linux"> - verify it hasn't been filed already</a>, then <a - href="http://code.google.com/p/chromium/issues/entry?template=Defect%20on%20Linux">file - your bug using the Linux-specific template</a>. + href="http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/"> + latest build</a>, then <a + href="http://code.google.com/p/chromium/issues/list?can=1&q=os:linux"> + verify it hasn't been filed already</a>, then <a + href="http://code.google.com/p/chromium/issues/entry?template=Defect%20on%20Linux"> + file your bug using the Linux-specific template</a>. <h3>How to help</h3> @@ -57,6 +57,16 @@ have <a href="http://dev.chromium.org/">documentation for developers</a> as well as mailing lists and an IRC channel. + <h3>Printing</h3> + + Basic printing support is now available with the --enable-printing flag. + There is no support for page preview, adjusting the margins, editing the + header/footer, etc. If you have bug reports, please file them, but be sure + to + <a href="http://code.google.com/p/chromium/issues/list?can=2&q=label:Printing#"> + search existing issues</a> first, because we know a lot of features are + missing. + </div> <p></p> diff --git a/chrome/browser/resources/linux-splash.html b/chrome/browser/resources/linux-splash.html index 06f5a85..26a0361 100644 --- a/chrome/browser/resources/linux-splash.html +++ b/chrome/browser/resources/linux-splash.html @@ -42,12 +42,12 @@ <p>Every minute spent triaging and de-duplicating bugs is a minute spent not fixing them. If you have a good bug report (e.g. includes a stack trace or a reduced test case), first verify it exists in the <a - href="http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/">latest - build</a>, then <a - href="http://code.google.com/p/chromium/issues/list?can=1&q=os:linux"> - verify it hasn't been filed already</a>, then <a - href="http://code.google.com/p/chromium/issues/entry?template=Defect%20on%20Linux">file - your bug using the Linux-specific template</a>. + href="http://build.chromium.org/buildbot/snapshots/chromium-rel-linux/"> + latest build</a>, then <a + href="http://code.google.com/p/chromium/issues/list?can=1&q=os:linux"> + verify it hasn't been filed already</a>, then <a + href="http://code.google.com/p/chromium/issues/entry?template=Defect%20on%20Linux"> + file your bug using the Linux-specific template</a>. <h3>How to help</h3> @@ -55,6 +55,16 @@ have <a href="http://dev.chromium.org/">documentation for developers</a> as well as mailing lists and an IRC channel. + <h3>Printing</h3> + + Basic printing support is now available with the --enable-printing flag. + There is no support for page preview, adjusting the margins, editing the + header/footer, etc. If you have bug reports, please file them, but be sure + to + <a href="http://code.google.com/p/chromium/issues/list?can=2&q=label:Printing#"> + search existing issues</a> first, because we know a lot of features are + missing. + </div> <p></p> diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 354dd05..fb4f905 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1660,6 +1660,8 @@ 'browser/plugin_service.h', 'browser/possible_url_model.cc', 'browser/possible_url_model.h', + 'browser/printing/print_dialog_gtk.cc', + 'browser/printing/print_dialog_gtk.h', 'browser/printing/print_job.cc', 'browser/printing/print_job.h', 'browser/printing/print_job_manager.cc', @@ -2231,6 +2233,7 @@ # '../build/linux/system.gyp:dbus-glib', # '../build/linux/system.gyp:gnome-keyring', '../build/linux/system.gyp:gtk', + '../build/linux/system.gyp:gtkprint', '../build/linux/system.gyp:nss', '../base/base.gyp:linux_versioninfo', ], @@ -2628,6 +2631,12 @@ ['exclude', '^browser/extensions/pack_extension_job.cc'], ], }], + ['OS=="linux" and toolkit_views==0', { + 'sources/': [ + ['include', '^browser/printing/print_dialog_gtk.cc'], + ['include', '^browser/printing/print_dialog_gtk.h'], + ], + }], ['chromeos==1',{ 'dependencies': [ '../third_party/protobuf2/protobuf.gyp:protobuf', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 6c9bd72..292d3d2 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -604,4 +604,8 @@ const wchar_t kExplicitlyAllowedPorts[] = L"explicitly-allowed-ports"; // is launched on the command line (e.g. by Selenium). Only needed on Mac. const wchar_t kActivateOnLaunch[] = L"activate-on-launch"; +#if defined(OS_LINUX) +const wchar_t kEnablePrinting[] = L"enable-printing"; +#endif + } // namespace switches diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 077127e..02f6430 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -245,6 +245,10 @@ extern const wchar_t kExplicitlyAllowedPorts[]; extern const wchar_t kActivateOnLaunch[]; +#if defined(OS_LINUX) +extern const wchar_t kEnablePrinting[]; +#endif + } // namespace switches #endif // CHROME_COMMON_CHROME_SWITCHES_H_ |