aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-06-19 02:52:03 +0800
committerChristian Persch <chpe@src.gnome.org>2006-06-19 02:52:03 +0800
commitc6573cb04bdc216e7e5ea3657cb1186eaf0f1095 (patch)
tree769cc33a1564a50d1414cb6b6b6f7306c1635840 /embed/mozilla
parent0db1af2c76d4cae33992f82a1736f6ed743b7dc1 (diff)
downloadgsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.gz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.bz2
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.lz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.xz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.zst
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.zip
A embed/mozilla/GeckoPrintService.cpp: A
2006-06-18 Christian Persch <chpe@cvs.gnome.org> * configure.ac: * data/default-prefs-common.js: * embed/Makefile.am: * embed/ephy-embed-shell.c: (ephy_embed_shell_dispose), (ephy_embed_shell_set_page_setup), (ephy_embed_shell_get_page_setup), (ephy_embed_shell_set_print_settings), (ephy_embed_shell_get_print_settings): * embed/ephy-embed-shell.h: * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * embed/mozilla/EphyUtils.cpp: * embed/mozilla/EphyUtils.h: * embed/mozilla/Makefile.am: A embed/mozilla/GeckoPrintService.cpp: A embed/mozilla/GeckoPrintService.h: A embed/mozilla/GeckoPrintSession.cpp: A embed/mozilla/GeckoPrintSession.h: * embed/mozilla/MozRegisterComponents.cpp: R embed/mozilla/PrintingPromptService.cpp: R embed/mozilla/PrintingPromptService.h: * embed/mozilla/mozilla-embed-single.cpp: R embed/print-dialog.c: R embed/print-dialog.h: * src/ephy-shell.c: (ephy_shell_dispose), (ephy_shell_get_prefs_dialog): * src/ephy-shell.h: * src/epiphany.defs: * src/window-commands.c: (page_setup_done_cb), (window_cmd_file_print_setup): Drop libgnomeprint[ui] and use gtk printing.
Diffstat (limited to 'embed/mozilla')
-rw-r--r--embed/mozilla/EphyBrowser.cpp48
-rw-r--r--embed/mozilla/EphyBrowser.h1
-rw-r--r--embed/mozilla/EphyUtils.cpp235
-rw-r--r--embed/mozilla/EphyUtils.h11
-rw-r--r--embed/mozilla/GeckoPrintService.cpp500
-rw-r--r--embed/mozilla/GeckoPrintService.h52
-rw-r--r--embed/mozilla/GeckoPrintSession.cpp622
-rw-r--r--embed/mozilla/GeckoPrintSession.h93
-rw-r--r--embed/mozilla/Makefile.am6
-rw-r--r--embed/mozilla/MozRegisterComponents.cpp111
-rw-r--r--embed/mozilla/PrintingPromptService.cpp246
-rw-r--r--embed/mozilla/PrintingPromptService.h58
12 files changed, 1420 insertions, 563 deletions
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index afcc2b175..bfd3b9e92 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -67,6 +67,8 @@
#include <nsIHistoryEntry.h>
#include <nsIInterfaceRequestor.h>
#include <nsIInterfaceRequestorUtils.h>
+#include <nsIPrintSettings.h>
+#include <nsIPrintSettingsService.h>
#include <nsIScriptSecurityManager.h>
#include <nsIServiceManager.h>
#include <nsISHEntry.h>
@@ -98,14 +100,16 @@
#include "ephy-debug.h"
#include "ephy-embed.h"
+#include "ephy-embed-shell.h"
#include "ephy-string.h"
#include "ephy-zoom.h"
#include "mozilla-embed-event.h"
#include "mozilla-embed.h"
-#include "print-dialog.h"
+#include "AutoJSContextStack.h"
#include "EphyUtils.h"
#include "EventContext.h"
+#include "GeckoPrintService.h"
#include "EphyBrowser.h"
@@ -673,7 +677,20 @@ nsresult EphyBrowser::Print ()
nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
NS_ENSURE_TRUE (print, NS_ERROR_FAILURE);
- return print->Print (nsnull, nsnull);
+ nsCOMPtr<nsIPrintSettingsService> printSettingsService
+ (do_GetService("@mozilla.org/gfx/printsettings-service;1"));
+ NS_ENSURE_STATE (printSettingsService);
+
+ nsCOMPtr<nsIPrintSettings> settings;
+ printSettingsService->GetNewPrintSettings (getter_AddRefs (settings));
+ NS_ENSURE_STATE (settings);
+
+ nsresult rv;
+ AutoJSContextStack stack;
+ rv = stack.Init ();
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ return print->Print (settings, nsnull);
}
nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode)
@@ -682,21 +699,30 @@ nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode)
NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE);
- nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser));
- NS_ENSURE_TRUE (print, NS_ERROR_FAILURE);
+ nsCOMPtr<nsIWebBrowserPrint> print (do_GetInterface (mWebBrowser));
+ NS_ENSURE_STATE (print);
if (previewMode)
{
- EmbedPrintInfo *info;
+ nsCOMPtr<nsIPrintSettingsService> printSettingsService
+ (do_GetService("@mozilla.org/gfx/printsettings-service;1"));
+ NS_ENSURE_STATE (printSettingsService);
nsCOMPtr<nsIPrintSettings> settings;
- print->GetGlobalPrintSettings (getter_AddRefs(settings));
+ printSettingsService->GetNewPrintSettings (getter_AddRefs (settings));
+ NS_ENSURE_STATE (settings);
- info = ephy_print_get_print_info ();
- EphyUtils::CollatePrintSettings (info, settings, TRUE);
- ephy_print_info_free (info);
+ EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+ rv = GeckoPrintService::TranslateSettings (ephy_embed_shell_get_print_settings (shell),
+ ephy_embed_shell_get_page_setup (shell),
+ nsCString(),
+ PR_FALSE,
+ settings);
- rv = print->PrintPreview (nsnull, mDOMWindow, nsnull);
+ if (NS_SUCCEEDED (rv))
+ {
+ rv = print->PrintPreview (settings, mDOMWindow, nsnull);
+ }
}
else
{
@@ -705,7 +731,7 @@ nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode)
rv = print->GetDoingPrintPreview(&isPreview);
NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE);
- if (isPreview == PR_TRUE)
+ if (isPreview)
{
rv = print->ExitPrintPreview();
}
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index 6a775bf14..3a60dfd41 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -31,7 +31,6 @@
#include <nsIDOMEventListener.h>
#include <nsIDOMEventTarget.h>
#include <nsIDOMWindow.h>
-#include <nsIPrintSettings.h>
#include <nsIRequest.h>
#include <nsISHistory.h>
#include <nsIWebBrowserFocus.h>
diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp
index b0ed8df4b..ab6d78e1a 100644
--- a/embed/mozilla/EphyUtils.cpp
+++ b/embed/mozilla/EphyUtils.cpp
@@ -35,11 +35,11 @@
#include <nsServiceManagerUtils.h>
#include <nsStringAPI.h>
#include <nsXPCOM.h>
+#include <nsIXPConnect.h>
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
#include "ephy-file-helpers.h"
-#include "print-dialog.h"
#include "EphyUtils.h"
@@ -139,211 +139,38 @@ EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow)
return toplevel;
}
-nsresult
-EphyUtils::CollatePrintSettings (EmbedPrintInfo *info,
- nsIPrintSettings *options,
- gboolean preview)
+char *
+EphyUtils::ConvertUTF16toUTF8 (const PRUnichar *aText,
+ PRInt32 aMaxLength)
{
- NS_ENSURE_ARG (options);
-
- /* FIXME: for CUPS printers, print directly instead of to a tmp file? */
- const static PRUnichar pName[] = { 'P', 'o', 's', 't', 'S', 'c', 'r', 'i', 'p', 't', '/', 'd', 'e', 'f', 'a', 'u', 'l', 't', '\0' };
- options->SetPrinterName(nsString(pName).get());
-
- const static int frame_types[] = {
- nsIPrintSettings::kFramesAsIs,
- nsIPrintSettings::kSelectedFrame,
- nsIPrintSettings::kEachFrameSep
- };
-
- switch (info->range)
- {
- case GNOME_PRINT_RANGE_CURRENT:
- case GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE:
- case GNOME_PRINT_RANGE_ALL:
- options->SetPrintRange (nsIPrintSettings::kRangeAllPages);
- break;
- case GNOME_PRINT_RANGE_RANGE:
- options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
- options->SetStartPageRange (info->from_page);
- options->SetEndPageRange (info->to_page);
- break;
- case GNOME_PRINT_RANGE_SELECTION:
- options->SetPrintRange (nsIPrintSettings::kRangeSelection);
- break;
- }
-
- const GnomePrintUnit *unit, *inch, *mm;
- double value;
-
- mm = gnome_print_unit_get_by_abbreviation ((const guchar *) "mm");
- inch = gnome_print_unit_get_by_abbreviation ((const guchar *) "in");
- g_assert (mm != NULL && inch != NULL);
-
- /* top margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_TOP,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginTop (value);
- }
-
- /* bottom margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginBottom (value);
- }
-
- /* left margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginLeft (value);
- }
-
- /* right margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginRight (value);
- }
-
-
- nsString tmp;
-
- NS_CStringToUTF16 (nsCString(info->header_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrLeft (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->header_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrCenter (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->header_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrRight (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrLeft (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrCenter(tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrRight(tmp.get());
+ if (aText == nsnull) return NULL;
+
+ /* This depends on the assumption that
+ * typeof(PRUnichar) == typeof (gunichar2) == uint16,
+ * which should be pretty safe.
+ */
+ glong n_read = 0, n_written = 0;
+ char *converted = g_utf16_to_utf8 ((gunichar2*) aText, aMaxLength,
+ &n_read, &n_written, NULL);
+ /* FIXME loop from the end while !g_unichar_isspace (char)? */
+
+ return converted;
+}
- options->SetPrintToFile (PR_FALSE);
-
- if (preview)
- {
- options->SetPrintToFile (PR_FALSE);
- }
- else
- {
- char *base;
- const char *temp_dir;
-
- temp_dir = ephy_file_tmp_dir ();
- base = g_build_filename (temp_dir, "printXXXXXX", (char *) NULL);
- info->tempfile = ephy_file_tmp_filename (base, "ps");
- g_free (base);
-
- if (info->tempfile == NULL) return NS_ERROR_FAILURE;
+/* This isn't completely accurate: if you do window.prompt in one window, then
+ * call this in another window, it still returns TRUE ! Those are the wonders
+ * of recursive mainloops :-(
+ */
+PRBool
+EphyJSUtils::IsCalledFromScript ()
+{
+ nsresult rv;
+ nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
+ NS_ENSURE_SUCCESS (rv, PR_FALSE);
- NS_CStringToUTF16 (nsCString(info->tempfile),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPrintToFile (PR_TRUE);
- options->SetToFileName (tmp.get());
- }
-
- /* paper size */
- options->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
- options->SetPaperSizeUnit (nsIPrintSettings::kPaperSizeMillimeters);
-
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_WIDTH,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, mm))
- {
- options->SetPaperWidth (value);
- }
-
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_HEIGHT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, mm))
- {
- options->SetPaperHeight (value);
- }
-
- /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404
- * means that we cannot actually use any paper sizes except mozilla's
- * builtin list, and we must refer to them *by name*!
- */
-#ifndef HAVE_GECKO_1_9
- /* Gnome-Print names some papers differently than what moz understands */
- static const struct
- {
- const char *gppaper;
- const char *mozpaper;
- }
- paper_table [] =
- {
- { "USLetter", "Letter" },
- { "USLegal", "Legal" }
- };
-#endif /* !HAVE_GECKO_1_9 */
-
- /* paper name */
- char *string = (char *) gnome_print_config_get (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_SIZE);
- const char *paper = string;
-
-#ifndef HAVE_GECKO_1_9
- for (PRUint32 i = 0; i < G_N_ELEMENTS (paper_table); i++)
- {
- if (string != NULL &&
- g_ascii_strcasecmp (paper_table[i].gppaper, string) == 0)
- {
- paper = paper_table[i].mozpaper;
- break;
- }
- }
-#endif /* !HAVE_GECKO_1_9 */
-
- NS_CStringToUTF16 (nsCString(paper),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPaperName (tmp.get());
- g_free (string);
-
- /* paper orientation */
- string = (char *) gnome_print_config_get (info->config,
- (const guchar *) GNOME_PRINT_KEY_ORIENTATION);
- if (string == NULL) string = g_strdup ("R0");
-
- if (strncmp (string, "R90", 3) == 0 || strncmp (string, "R270", 4) == 0)
- {
- options->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
- }
- else
- {
- options->SetOrientation (nsIPrintSettings::kPortraitOrientation);
- }
- g_free (string);
-
- options->SetPrintInColor (info->print_color);
- options->SetPrintFrameType (frame_types[info->frame_type]);
+ nsCOMPtr<nsIXPCNativeCallContext> ncc;
+ rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc));
+ NS_ENSURE_SUCCESS(rv, PR_FALSE);
- return NS_OK;
+ return nsnull != ncc;
}
diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h
index cc607a9f9..c19ae088f 100644
--- a/embed/mozilla/EphyUtils.h
+++ b/embed/mozilla/EphyUtils.h
@@ -35,9 +35,7 @@ class nsAString;
class nsIDOMWindow;
class nsIFile;
class nsIIOService;
-class nsIPrintSettings;
class nsIURI;
-struct _EmbedPrintInfo;
namespace EphyUtils
{
@@ -59,10 +57,13 @@ namespace EphyUtils
GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow);
GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow);
+
+ char * ConvertUTF16toUTF8 (const PRUnichar*, PRInt32);
+}
- nsresult CollatePrintSettings (_EmbedPrintInfo *info,
- nsIPrintSettings *settings,
- gboolean preview);
+namespace EphyJSUtils
+{
+ PRBool IsCalledFromScript ();
}
#endif
diff --git a/embed/mozilla/GeckoPrintService.cpp b/embed/mozilla/GeckoPrintService.cpp
new file mode 100644
index 000000000..81a5bcc08
--- /dev/null
+++ b/embed/mozilla/GeckoPrintService.cpp
@@ -0,0 +1,500 @@
+/*
+ * Copyright (C) 2006 Christian Persch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#include "mozilla-config.h"
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtkwindow.h>
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkprintunixdialog.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkstock.h>
+
+#include <nsStringAPI.h>
+
+#include <nsCOMPtr.h>
+#include <nsIDOMWindow.h>
+#include <nsIDOMWindowInternal.h>
+
+#include "eel-gconf-extensions.h"
+#include "ephy-debug.h"
+#include "ephy-embed-shell.h"
+#include "ephy-file-helpers.h"
+#include "ephy-prefs.h"
+
+#include "AutoJSContextStack.h"
+#include "EphyUtils.h"
+#include "GeckoPrintSession.h"
+
+#include "GeckoPrintService.h"
+
+#define LITERAL(s) NS_REINTERPRET_CAST(const nsAString::char_type*, NS_L(s))
+
+/* From nsIDeviceContext.h */
+#define NS_ERROR_GFX_PRINTER_BASE (1) /* adjustable :-) */
+#define NS_ERROR_GFX_PRINTER_ACCESS_DENIED \
+ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+5)
+
+NS_IMPL_ISUPPORTS1 (GeckoPrintService,
+ nsIPrintingPromptService)
+
+GeckoPrintService::GeckoPrintService()
+{
+ LOG ("GeckoPrintService ctor [%p]", this);
+}
+
+GeckoPrintService::~GeckoPrintService()
+{
+ LOG ("GeckoPrintService dtor [%p]", this);
+}
+
+/* nsIPrintingPromptService implementation */
+
+/* void showPrintDialog (in nsIDOMWindow parent,
+ in nsIWebBrowserPrint webBrowserPrint,
+ in nsIPrintSettings printSettings); */
+NS_IMETHODIMP
+GeckoPrintService::ShowPrintDialog (nsIDOMWindow *aParent,
+ nsIWebBrowserPrint *aWebBrowserPrint,
+ nsIPrintSettings *aSettings)
+{
+ /* Locked down? */
+ if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINTING)) {
+ return NS_ERROR_GFX_PRINTER_ACCESS_DENIED;
+ }
+
+ GeckoPrintSession *session = GeckoPrintSession::FromSettings (aSettings);
+ NS_ENSURE_TRUE (session, NS_ERROR_INVALID_POINTER);
+
+ GtkWidget *parent = EphyUtils::FindGtkParent (aParent);
+ NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
+
+ PRBool isCalledFromScript = EphyJSUtils::IsCalledFromScript ();
+
+ nsresult rv;
+ AutoJSContextStack stack;
+ rv = stack.Init ();
+ if (NS_FAILED (rv)) {
+ return rv;
+ }
+
+ EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+
+ /* Print settings changes disallowed, just translate the settings */
+ if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP)) {
+ /* FIXME: we need to call session->SetSettings first, and for that we need a
+ * way to get the default printer object!
+ */
+ g_warning ("Printing with locked print setup doesn't work!");
+ return NS_ERROR_FAILURE;
+
+ /* If called from a script, give the user a way to cancel the print! */
+ if (isCalledFromScript) {
+ GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
+ GtkDialogFlags (0),
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_CANCEL,
+ "%s", _("Print this page?"));
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser");
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_PRINT,
+ GTK_RESPONSE_ACCEPT);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+
+ int response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ if (response != GTK_RESPONSE_ACCEPT) {
+ return NS_ERROR_ABORT;
+ }
+ }
+
+ nsCString sourceFile;
+ session->GetSourceFile (sourceFile);
+ if (!sourceFile.IsEmpty ()) {
+ rv = TranslateSettings (ephy_embed_shell_get_print_settings (shell),
+ ephy_embed_shell_get_page_setup (shell),
+ sourceFile, PR_TRUE, aSettings);
+ } else {
+ rv = NS_ERROR_ABORT;
+ }
+
+ return rv;
+ }
+
+ /* Not locked down, show the dialogue */
+
+#if 0
+ PRBool haveSelection = PR_FALSE;
+ rv = aSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &haveSelection);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ PRInt16 frameUI = 0;
+ rv = aSettings->GetHowToEnableFrameUI (&frameUI);
+ NS_ENSURE_SUCCESS (rv, rv);
+#endif
+
+ /* FIXME: this sucks! find some way to do all of this async! */
+ GtkWidget *dialog = gtk_print_unix_dialog_new (NULL /* FIXME title */,
+ GTK_WINDOW (parent));
+ GtkPrintUnixDialog *print_dialog = GTK_PRINT_UNIX_DIALOG (dialog);
+
+ gtk_print_unix_dialog_set_manual_capabilities
+ (print_dialog,
+ GtkPrintCapabilities (GTK_PRINT_CAPABILITY_PAGE_SET |
+ GTK_PRINT_CAPABILITY_COPIES |
+ GTK_PRINT_CAPABILITY_COLLATE |
+ GTK_PRINT_CAPABILITY_REVERSE |
+ GTK_PRINT_CAPABILITY_SCALE));
+ gtk_print_unix_dialog_set_page_setup (print_dialog,
+ ephy_embed_shell_get_page_setup (shell));
+ gtk_print_unix_dialog_set_settings (print_dialog,
+ ephy_embed_shell_get_print_settings (shell));
+
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "web-browser");
+
+ int response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_hide (dialog);
+
+ GtkPrinter *printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
+
+ if (response != GTK_RESPONSE_OK || !printer) {
+ gtk_widget_destroy (dialog);
+
+ return NS_ERROR_ABORT;
+ }
+
+ GtkPageSetup *pageSetup = gtk_print_unix_dialog_get_page_setup (print_dialog);
+ ephy_embed_shell_set_page_setup (shell, pageSetup);
+
+ GtkPrintSettings *settings = gtk_print_unix_dialog_get_settings (print_dialog);
+ ephy_embed_shell_set_print_settings (shell, settings);
+
+ /* This adopts the refcount of |settings| */
+ rv = session->SetSettings (settings, pageSetup, printer);
+
+ /* Now translate the settings to nsIPrintSettings */
+ if (NS_SUCCEEDED (rv)) {
+ nsCString sourceFile;
+ session->GetSourceFile (sourceFile);
+ if (!sourceFile.IsEmpty ()) {
+ rv = TranslateSettings (settings, pageSetup, sourceFile, PR_TRUE, aSettings);
+ } else {
+ rv = NS_ERROR_ABORT;
+ }
+ }
+
+ gtk_widget_destroy (dialog);
+
+ return rv;
+}
+
+/* void showProgress (in nsIDOMWindow parent,
+ in nsIWebBrowserPrint webBrowserPrint,
+ in nsIPrintSettings printSettings,
+ in nsIObserver openDialogObserver,
+ in boolean isForPrinting,
+ out nsIWebProgressListener webProgressListener,
+ out nsIPrintProgressParams printProgressParams,
+ out boolean notifyOnOpen); */
+NS_IMETHODIMP
+GeckoPrintService::ShowProgress (nsIDOMWindow *aParent,
+ nsIWebBrowserPrint *aWebBrowserPrint,
+ nsIPrintSettings *aPrintSettings,
+ nsIObserver *aOpenDialogObserver,
+ PRBool aIsForPrinting,
+ nsIWebProgressListener **_webProgressListener,
+ nsIPrintProgressParams **_printProgressParams,
+ PRBool *_notifyOnOpen)
+{
+ /* Print preview */
+ if (!aIsForPrinting) {
+ return NS_OK;
+ }
+
+ nsresult rv;
+ nsCOMPtr<nsIDOMWindowInternal> domWin (do_QueryInterface (aParent, &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsCOMPtr<nsIPrintSession> session;
+ rv = aPrintSettings->GetPrintSession (getter_AddRefs (session));
+ NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && session, nsnull);
+
+ nsCOMPtr<nsIPrintProgress> progress (do_QueryInterface (session, &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ /* Out print session implements those interfaces */
+ rv = CallQueryInterface (session, _webProgressListener);
+ rv |= CallQueryInterface (session, _printProgressParams);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ /* Setting this to PR_FALSE will make gecko immediately start printing
+ * when we return from this function.
+ * If we set this to PR_TRUE, we need to call aOpenDialogObserver::Observe
+ * (topic, subject and data don't matter) when we're ready for printing.
+ */
+ *_notifyOnOpen = PR_FALSE;
+
+ return progress->OpenProgressDialog (domWin, nsnull, nsnull, aOpenDialogObserver, _notifyOnOpen);
+}
+
+/* void showPageSetup (in nsIDOMWindow parent,
+ in nsIPrintSettings printSettings,
+ in nsIObserver aObs); */
+NS_IMETHODIMP GeckoPrintService::ShowPageSetup (nsIDOMWindow *aParent,
+ nsIPrintSettings *aPrintSettings,
+ nsIObserver *aObserver)
+{
+ /* Locked down? */
+ if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINTING) ||
+ eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP)) {
+ return NS_ERROR_ABORT;
+ }
+
+ GtkWidget *parent = EphyUtils::FindGtkParent (aParent);
+ NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER);
+
+ AutoJSContextStack stack;
+ nsresult rv = stack.Init ();
+ if (NS_FAILED (rv)) {
+ return rv;
+ }
+
+ EphyEmbedShell *shell = ephy_embed_shell_get_default ();
+ GtkPageSetup *new_setup =
+ gtk_print_run_page_setup_dialog (GTK_WINDOW (parent),
+ ephy_embed_shell_get_page_setup (shell),
+ ephy_embed_shell_get_print_settings (shell));
+ if (new_setup) {
+ ephy_embed_shell_set_page_setup (shell, new_setup);
+ g_object_unref (new_setup);
+ }
+
+ /* FIXME do we need to notify aObserver somehow? */
+ return NS_OK;
+}
+
+/* void showPrinterProperties (in nsIDOMWindow parent,
+ in wstring printerName,
+ in nsIPrintSettings printSettings); */
+NS_IMETHODIMP
+GeckoPrintService::ShowPrinterProperties (nsIDOMWindow *aParent,
+ const PRUnichar *aPrinterName,
+ nsIPrintSettings *aPrintSettings)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* Static methods */
+
+/* static */ nsresult
+GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings,
+ GtkPageSetup *aPageSetup,
+ const nsACString &aSourceFile,
+ PRBool aIsForPrinting,
+ nsIPrintSettings *aSettings)
+{
+ NS_ENSURE_ARG (aGtkSettings);
+ NS_ENSURE_ARG (aPageSetup);
+
+ /* Locked down? */
+ if (gtk_print_settings_get_print_to_file (aGtkSettings) &&
+ eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) {
+ return NS_ERROR_GFX_PRINTER_ACCESS_DENIED;
+ }
+
+ /* Initialisation */
+ aSettings->SetIsInitializedFromPrinter (PR_FALSE);
+ aSettings->SetIsInitializedFromPrefs (PR_FALSE);
+ aSettings->SetPrintSilent (PR_FALSE);
+ aSettings->SetShowPrintProgress (PR_TRUE);
+ aSettings->SetNumCopies (1);
+
+ /* We always print PS to a file and then hand that off to gtk-print */
+ aSettings->SetPrinterName (LITERAL ("PostScript/default"));
+
+ if (aIsForPrinting) {
+ aSettings->SetPrintToFile (PR_TRUE);
+
+ nsString sourceFile;
+ NS_CStringToUTF16 (aSourceFile,
+ NS_CSTRING_ENCODING_NATIVE_FILESYSTEM,
+ sourceFile);
+
+ aSettings->SetToFileName (sourceFile.get ());
+ } else {
+ /* Otherwise mozilla will create the file nevertheless and
+ * fail since we haven't set a name!
+ */
+ aSettings->SetPrintToFile (PR_FALSE);
+ }
+
+ /* This is the time between printing each page, in ms.
+ * It 'gives the user more time to press cancel' !
+ * We don't want any of this nonsense, so set this to a low value,
+ * just enough to update the print dialogue.
+ */
+ aSettings->SetPrintPageDelay (50);
+
+ if (aIsForPrinting) {
+ GtkPageSet pageSet = gtk_print_settings_get_page_set (aGtkSettings);
+ aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
+ pageSet != GTK_PAGE_SET_ODD);
+ aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages,
+ pageSet != GTK_PAGE_SET_EVEN);
+
+ aSettings->SetPrintReversed (gtk_print_settings_get_reverse (aGtkSettings));
+
+ GtkPrintPages printPages = gtk_print_settings_get_print_pages (aGtkSettings);
+ switch (printPages) {
+ case GTK_PRINT_PAGES_RANGES: {
+ int numRanges = 0;
+ GtkPageRange *pageRanges = gtk_print_settings_get_page_ranges (aGtkSettings, &numRanges);
+ if (numRanges > 0) {
+ /* FIXME: We can only support one range, ignore more ranges or raise error? */
+ aSettings->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
+ aSettings->SetStartPageRange (pageRanges[0].start);
+ aSettings->SetEndPageRange (pageRanges[1].end);
+
+ g_free (pageRanges);
+ }
+ break;
+ }
+ case GTK_PRINT_PAGES_CURRENT:
+ /* not supported, fall through */
+ case GTK_PRINT_PAGES_ALL:
+ aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages);
+ break;
+ /* FIXME: we need some custom ranges here, "Selection" and "Focused Frame" */
+ }
+ } else {
+ aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
+ aSettings->SetPrintOptions (nsIPrintSettings::kPrintEvenPages, PR_TRUE);
+ aSettings->SetPrintReversed (PR_FALSE);
+ aSettings->SetPrintRange (nsIPrintSettings::kRangeAllPages);
+ }
+
+ switch (gtk_print_settings_get_orientation (aGtkSettings)) {
+ case GTK_PAGE_ORIENTATION_PORTRAIT:
+ case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: /* not supported */
+ aSettings->SetOrientation (nsIPrintSettings::kPortraitOrientation);
+ break;
+ case GTK_PAGE_ORIENTATION_LANDSCAPE:
+ case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: /* not supported */
+ aSettings->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
+ break;
+ }
+
+ aSettings->SetPrintInColor (gtk_print_settings_get_use_color (aGtkSettings));
+
+ aSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters);
+ aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
+
+ // FIXME for some reason this is always NULL ??
+ // GtkPaperSize *paperSize = gtk_print_settings_get_paper_size (aGtkSettings);
+ GtkPaperSize *paperSize = gtk_page_setup_get_paper_size (aPageSetup);
+ if (!paperSize) {
+ return NS_ERROR_FAILURE;
+ }
+
+ aSettings->SetPaperSizeType (nsIPrintSettings::kPaperSizeDefined);
+ aSettings->SetPaperWidth (gtk_paper_size_get_width (paperSize, GTK_UNIT_MM));
+ aSettings->SetPaperHeight (gtk_paper_size_get_height (paperSize, GTK_UNIT_MM));
+
+#ifdef HAVE_GECKO_1_9
+ aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (gtk_paper_size_get_name (paperSize)).get ());
+#else
+{
+ /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404
+ * means that we cannot actually use any paper sizes except mozilla's
+ * builtin list, and we must refer to them *by name*!
+ */
+ static const struct {
+ const char gtkPaperName[13];
+ const char mozPaperName[10];
+ } paperTable [] = {
+ { GTK_PAPER_NAME_A5, "A5" },
+ { GTK_PAPER_NAME_A4, "A4" },
+ { GTK_PAPER_NAME_A3, "A3" },
+ { GTK_PAPER_NAME_LETTER, "Letter" },
+ { GTK_PAPER_NAME_LEGAL, "Legal" },
+ { GTK_PAPER_NAME_EXECUTIVE, "Executive" },
+ };
+
+ const char *paperName = gtk_paper_size_get_name (paperSize);
+
+ PRUint32 i;
+ for (i = 0; i < G_N_ELEMENTS (paperTable); i++) {
+ if (g_ascii_strcasecmp (paperTable[i].gtkPaperName, paperName) == 0) {
+ paperName = paperTable[i].mozPaperName;
+ break;
+ }
+ }
+ if (i == G_N_ELEMENTS (paperTable)) {
+ /* Not in table, fall back to A4 */
+ g_warning ("Unknown paper name '%s', falling back to A4", gtk_paper_size_get_name (paperSize));
+ paperName = paperTable[1].mozPaperName;
+ }
+
+ aSettings->SetPaperName (NS_ConvertUTF8toUTF16 (paperName).get ());
+}
+#endif /* !HAVE_GECKO_1_9 */
+
+ // gtk_paper_size_free (paperSize);
+
+ /* Sucky mozilla wants margins in inch! */
+ aSettings->SetMarginTop (gtk_page_setup_get_top_margin (aPageSetup, GTK_UNIT_INCH));
+ aSettings->SetMarginBottom (gtk_page_setup_get_bottom_margin (aPageSetup, GTK_UNIT_INCH));
+ aSettings->SetMarginLeft (gtk_page_setup_get_left_margin (aPageSetup, GTK_UNIT_INCH));
+ aSettings->SetMarginRight (gtk_page_setup_get_right_margin (aPageSetup, GTK_UNIT_INCH));
+
+#if 0
+ // FIXME !
+ aSettings->SetHeaderStrLeft(const PRUnichar * aHeaderStrLeft);
+ aSettings->SetHeaderStrCenter(const PRUnichar * aHeaderStrCenter);
+ aSettings->SetHeaderStrRight(const PRUnichar * aHeaderStrRight);
+ aSettings->SetFooterStrLeft(const PRUnichar * aFooterStrLeft);
+ aSettings->SetFooterStrCenter(const PRUnichar * aFooterStrCenter);
+ aSettings->SetFooterStrRight(const PRUnichar * aFooterStrRight);
+#endif
+
+ /* FIXME I think this is the right default, but this prevents the user
+ * from cancelling the print immediately, see the stupid comment in nsPrintEngine:
+ * "DO NOT allow the print job to be cancelled if it is Print FrameAsIs
+ * because it is only printing one page."
+ * We work around this by just not sending the job to the printer then.
+ */
+ aSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); /* FIXME setting */
+ aSettings->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible);
+
+ aSettings->SetScaling (gtk_print_settings_get_scale (aGtkSettings) / 100.0);
+ aSettings->SetShrinkToFit (PR_FALSE); /* FIXME setting */
+
+ aSettings->SetPrintBGColors (PR_FALSE); /* FIXME setting */
+ aSettings->SetPrintBGImages (PR_FALSE); /* FIXME setting */
+
+ /* aSettings->SetPlexName (LITERAL ("default")); */
+ /* aSettings->SetColorspace (LITERAL ("default")); */
+ /* aSettings->SetResolutionName (LITERAL ("default")); */
+ /* aSettings->SetDownloadFonts (PR_TRUE); */
+
+ return NS_OK;
+}
diff --git a/embed/mozilla/GeckoPrintService.h b/embed/mozilla/GeckoPrintService.h
new file mode 100644
index 000000000..c9e0eb6ad
--- /dev/null
+++ b/embed/mozilla/GeckoPrintService.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2006 Christian Persch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#ifndef GECKO_PRINT_SERVICE_H
+#define GECKO_PRINT_SERVICE_H
+
+#include <gtk/gtkpagesetup.h>
+#include <gtk/gtkprintsettings.h>
+
+#include <nsIPrintingPromptService.h>
+
+class nsIPrintSettings;
+
+/* 6a71ff30-7f4d-4d91-b71a-d5c9764b34be */
+#define GECKO_PRINT_SERVICE_IID \
+{ 0x6a71ff30, 0x7f4d, 0x4d91, \
+ { 0xb7, 0x1a, 0xd5, 0xc9, 0x76, 0x4b, 0x34, 0xbe } }
+
+#define GECKO_PRINT_SERVICE_CLASSNAME "Gecko Print Service"
+
+class GeckoPrintService : public nsIPrintingPromptService
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIPRINTINGPROMPTSERVICE
+
+ GeckoPrintService();
+ virtual ~GeckoPrintService();
+
+ static nsresult TranslateSettings (GtkPrintSettings*, GtkPageSetup *, const nsACString&, PRBool, nsIPrintSettings*);
+
+private:
+};
+
+#endif /* GECKO_PRINT_SERVICE_H */
diff --git a/embed/mozilla/GeckoPrintSession.cpp b/embed/mozilla/GeckoPrintSession.cpp
new file mode 100644
index 000000000..4d184eb9f
--- /dev/null
+++ b/embed/mozilla/GeckoPrintSession.cpp
@@ -0,0 +1,622 @@
+/*
+ * Copyright (C) 2006 Christian Persch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#include "mozilla-config.h"
+#include "config.h"
+
+#include <unistd.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <nsStringAPI.h>
+
+#include <nsIDOMWindow.h>
+#include <nsIDOMWindowInternal.h>
+#include <nsIPrintSettings.h>
+
+#include "ephy-debug.h"
+#include "ephy-embed-shell.h"
+#include "ephy-file-helpers.h"
+
+#include "EphyUtils.h"
+
+#include "GeckoPrintSession.h"
+
+#define MAX_STRING_LENGTH 512
+
+GeckoPrintSession::GeckoPrintSession ()
+: mSettings(NULL)
+, mPageSetup(NULL)
+, mPrinter(NULL)
+, mJob(NULL)
+, mProgressDialog(NULL)
+, mTitleLabel(NULL)
+, mProgressBar(NULL)
+, mStartPrintIdleID(0)
+, mSourceFileIsTemp(PR_FALSE)
+, mDone(PR_FALSE)
+, mCancelled(PR_FALSE)
+{
+ LOG ("GeckoPrintSession ctor [%p]", (void*) this);
+
+ /* FIXME: connect to "prepare-close" ? */
+ g_object_ref (ephy_embed_shell_get_default ());
+}
+
+GeckoPrintSession::~GeckoPrintSession ()
+{
+ LOG ("GeckoPrintSession dtor [%p]", (void*) this);
+
+ NS_ASSERTION (mStartPrintIdleID == 0, "Impossible");
+
+ if (!mDone && !mCancelled) {
+ Cancel ();
+ }
+ DestroyJob ();
+
+ if (mSettings) {
+ g_object_unref (mSettings);
+ }
+ if (mPageSetup) {
+ g_object_unref (mPageSetup);
+ }
+ if (mPrinter) {
+ g_object_unref (mPrinter);
+ }
+ if (mProgressDialog) {
+ gtk_widget_destroy (mProgressDialog);
+ }
+ if (mSourceFileIsTemp) {
+ unlink (mSourceFile.get ());
+ }
+
+ g_object_unref (ephy_embed_shell_get_default ());
+}
+
+void
+GeckoPrintSession::GetSourceFile (nsACString &aSource)
+{
+ aSource.Assign (mSourceFile);
+}
+
+nsresult
+GeckoPrintSession::SetSettings (GtkPrintSettings *aSettings,
+ GtkPageSetup *aPageSetup,
+ GtkPrinter *aPrinter)
+{
+ NS_ASSERTION (!mSettings && !mPageSetup && !mPrinter, "Already have settings!");
+
+ NS_ENSURE_ARG (aSettings);
+ mSettings = aSettings; /* this one is adopted */
+
+ NS_ENSURE_ARG (aPageSetup);
+ NS_ENSURE_ARG (aPrinter);
+
+ mPageSetup = (GtkPageSetup *) g_object_ref (aPageSetup);
+ mPrinter = (GtkPrinter *) g_object_ref (aPrinter);
+
+ /* Compute the source file name */
+ if (gtk_print_settings_get_print_to_file (mSettings)) {
+ /* FIXME: support gnome-VFS uris here! */
+ const char *fileURI = gtk_print_settings_get (aSettings, "export-uri");
+ NS_ENSURE_TRUE (fileURI, NS_ERROR_FAILURE);
+
+ char *fileName = g_filename_from_uri (fileURI, NULL, NULL);
+ NS_ENSURE_TRUE (fileURI, NS_ERROR_FAILURE);
+
+ mSourceFile.Assign (fileName);
+ g_free (fileName);
+ } else {
+ char *base, *tmpName;
+
+ /* FIXME: use pure glib here! */
+ base = g_build_filename (ephy_file_tmp_dir (), "print-XXXXXX", (const char *) NULL);
+ tmpName = ephy_file_tmp_filename (base, "ps");
+ g_free (base);
+
+ NS_ENSURE_TRUE (tmpName, NS_ERROR_FAILURE);
+ mSourceFile.Assign (tmpName);
+ g_free (tmpName);
+
+ mSourceFileIsTemp = PR_TRUE;
+ }
+
+ return NS_OK;
+}
+
+/* static methods */
+
+/* static */ GeckoPrintSession *
+GeckoPrintSession::FromSettings (nsIPrintSettings *aSettings)
+{
+ nsresult rv;
+ nsCOMPtr<nsIPrintSession> session;
+ rv = aSettings->GetPrintSession (getter_AddRefs (session));
+ NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && session, nsnull);
+
+ /* this is ok since the caller holds a ref to the settings which hold a ref to the session */
+ nsIPrintSession *sessionPtr = session.get();
+ return NS_STATIC_CAST (GeckoPrintSession*, sessionPtr);
+}
+
+/* static functions */
+
+static void
+ReleaseSession (GeckoPrintSession *aSession)
+{
+ NS_RELEASE (aSession);
+}
+
+static gboolean
+ProgressDeleteCallback (GtkDialog *aDialog)
+{
+ gtk_dialog_response (aDialog, GTK_RESPONSE_DELETE_EVENT);
+ return TRUE;
+}
+
+static void
+ProgressResponseCallback (GtkDialog *aDialog,
+ int aResponse,
+ GeckoPrintSession *aSession)
+{
+ aSession->Cancel ();
+}
+
+static gboolean
+StartPrintIdleCallback (GeckoPrintSession *aSession)
+{
+ aSession->StartPrinting ();
+
+ return FALSE;
+}
+
+static void
+JobStatusChangedCallback (GtkPrintJob *aJob,
+ GeckoPrintSession *aSession)
+{
+ aSession->JobStatusChanged ();
+}
+
+static void
+JobCompletedCallback (GtkPrintJob *aJob,
+ GeckoPrintSession *aSession,
+ GError *aError)
+{
+ aSession->JobDone ();
+
+ if (aError) {
+ aSession->JobError (aError->message);
+ }
+}
+
+/* Private methods */
+
+void
+GeckoPrintSession::SetProgress (PRInt32 aCurrent,
+ PRInt32 aMaximum)
+{
+ NS_ENSURE_TRUE (mProgressDialog, );
+
+ if (mCancelled) return;
+
+ /* Mozilla is weird */
+ if (aCurrent > aMaximum || (aCurrent == 100 && aMaximum == 100)) return;
+
+ double fraction = 0.0;
+ if (aMaximum > 0 && aCurrent >= 0) {
+ char *text = g_strdup_printf (_("Page %d of %d"), aCurrent, aMaximum);
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (mProgressBar), text);
+ g_free (text);
+
+ fraction = (double) aCurrent / (double) aMaximum;
+ }
+
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (mProgressBar), CLAMP (fraction, 0.0, 1.0));
+}
+
+void
+GeckoPrintSession::SetProgressText (const char *aText)
+{
+ NS_ENSURE_TRUE (mProgressDialog, );
+
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (mProgressBar), aText);
+}
+
+void
+GeckoPrintSession::Cancel ()
+{
+ SetProcessCanceledByUser (PR_TRUE);
+
+ if (mProgressDialog) {
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (mProgressDialog),
+ GTK_RESPONSE_CANCEL, FALSE);
+
+ SetProgress (0, 0);
+ SetProgressText (_("Cancelling print"));
+ }
+
+ if (mJob) {
+ /* FIXME: There's no way to cancel mJob! Bug #339323 */
+ }
+}
+
+void
+GeckoPrintSession::StartPrinting ()
+{
+ mStartPrintIdleID = 0;
+
+ GError *error = NULL;
+
+ /* FIXME: this could also be a print job to a file which was
+ * printed to a temp file and now needs to be uploaded to its
+ * final location with gnome-vfs.
+ */
+ if (gtk_print_settings_get_print_to_file (mSettings)) return;
+
+ NS_ENSURE_TRUE (mSettings && mPageSetup && mPrinter, );
+
+ mJob = gtk_print_job_new (mTitle.get (),
+ mPrinter,
+ mSettings,
+ mPageSetup);
+ if (!gtk_print_job_set_source_file (mJob, mSourceFile.get (), &error)) {
+ g_warning ("Couldn't set print job source: %s", error->message);
+ g_error_free (error);
+
+ g_object_unref (mJob);
+ mJob = NULL;
+
+ return;
+ }
+
+ /* Keep us alive until the job is done! */
+ NS_ADDREF_THIS ();
+ if (!gtk_print_job_send (mJob,
+ (GtkPrintJobCompleteFunc) JobCompletedCallback,
+ this,
+ (GDestroyNotify) ReleaseSession,
+ &error)) {
+ g_warning ("Couldn't start print job: %s", error->message);
+ g_error_free (error);
+
+ g_object_unref (mJob);
+ mJob = NULL;
+
+ NS_RELEASE_THIS ();
+ return;
+ };
+
+ g_signal_connect (mJob, "status-changed",
+ G_CALLBACK (JobStatusChangedCallback), this);
+}
+
+void
+GeckoPrintSession::JobStatusChanged ()
+{
+ NS_ENSURE_TRUE (mProgressDialog, );
+
+ LOG ("print session %p status changed %d\n", this, gtk_print_job_get_status (mJob));
+
+ if (gtk_print_job_get_status (mJob) == GTK_PRINT_STATUS_SENDING_DATA) {
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (mProgressBar), 0.75);
+ SetProgressText (_("Spooling..."));
+ }
+}
+
+void
+GeckoPrintSession::JobError (const char *aErrorMessage)
+{
+ LOG ("print job error: %s", aErrorMessage);
+
+ /* FIXME better text */
+ GtkWidget *dialog = gtk_message_dialog_new (NULL,
+ GtkDialogFlags (0),
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Print error"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", aErrorMessage);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show (dialog);
+}
+
+void
+GeckoPrintSession::JobDone ()
+{
+ NS_ENSURE_TRUE (mProgressDialog, );
+
+ mDone = PR_TRUE;
+
+ gtk_widget_hide (mProgressDialog);
+
+ DestroyJob ();
+}
+
+void
+GeckoPrintSession::DestroyJob ()
+{
+ NS_ENSURE_TRUE (mJob, );
+
+ g_signal_handlers_disconnect_by_func (mJob, (void*) JobStatusChangedCallback, this);
+ g_object_unref (mJob);
+ mJob = NULL;
+}
+
+void
+GeckoPrintSession::LaunchJobOnIdle ()
+{
+ NS_ASSERTION (!mStartPrintIdleID, "Already started printing!");
+
+ /* Don't send the job to the printer if the user cancelled the print */
+ if (mCancelled) return;
+
+ /* Keep us alive until the idle handler runs! */
+ NS_ADDREF_THIS ();
+ mStartPrintIdleID = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ (GSourceFunc) StartPrintIdleCallback,
+ this,
+ (GDestroyNotify) ReleaseSession);
+}
+
+/* XPCOM interfaces */
+
+NS_IMPL_THREADSAFE_ISUPPORTS5 (GeckoPrintSession,
+ nsIPrintSession,
+ nsIWebProgressListener,
+ nsIPrintProgress,
+ nsIPrintProgressParams,
+ nsISupportsWeakReference)
+
+/* nsIPrintSession implementation */
+
+/* nsIWebProgressListener implementation */
+
+/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
+NS_IMETHODIMP
+GeckoPrintSession::OnStateChange (nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ PRUint32 aStateFlags,
+ nsresult aStatus)
+{
+ if (NS_SUCCEEDED (aStatus) &&
+ aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
+ if (aStateFlags & nsIWebProgressListener::STATE_START) {
+ /* Printing starts now */
+ SetProgress (0, 0);
+ } else if ((aStateFlags & nsIWebProgressListener::STATE_STOP)) {
+ /* Printing done, upload to printer */
+ LaunchJobOnIdle ();
+ }
+ }
+
+ return NS_OK;
+}
+
+/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
+NS_IMETHODIMP
+GeckoPrintSession::OnProgressChange (nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ PRInt32 aCurSelfProgress,
+ PRInt32 aMaxSelfProgress,
+ PRInt32 aCurTotalProgress,
+ PRInt32 aMaxTotalProgress)
+{
+ SetProgress (aCurTotalProgress, aMaxTotalProgress);
+
+ return NS_OK;
+}
+
+/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI aLocation); */
+NS_IMETHODIMP
+GeckoPrintSession::OnLocationChange (nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ nsIURI *aLocation)
+{
+ NS_ASSERTION (0, "OnLocationChange reached!");
+ return NS_OK;
+}
+
+/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
+NS_IMETHODIMP
+GeckoPrintSession::OnStatusChange (nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ nsresult aStatus,
+ const PRUnichar *aMessage)
+{
+ NS_ASSERTION (0, "OnStatusChange reached!");
+ return NS_OK;
+}
+
+/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aState); */
+NS_IMETHODIMP
+GeckoPrintSession::OnSecurityChange (nsIWebProgress *aWebProgress,
+ nsIRequest *aRequest,
+ PRUint32 aState)
+{
+ NS_ASSERTION (0, "OnSecurityChange reached!");
+ return NS_OK;
+}
+
+/* nsIPrintProgress implementation */
+
+/* void openProgressDialog (in nsIDOMWindowInternal parent, in string dialogURL, in nsISupports parameters, in nsIObserver openDialogObserver, out boolean notifyOnOpen); */
+NS_IMETHODIMP
+GeckoPrintSession::OpenProgressDialog (nsIDOMWindowInternal *aParent,
+ const char *aDialogURL,
+ nsISupports *aParameters,
+ nsIObserver *aOpenDialogObserver,
+ PRBool *_notifyOnOpen)
+{
+ NS_ENSURE_STATE (!mProgressDialog);
+
+ nsCOMPtr<nsIDOMWindow> domWindow (do_QueryInterface (aParent));
+ GtkWidget *parent = EphyUtils::FindGtkParent (domWindow);
+
+ GtkWidget *vbox, *hbox, *image;
+
+ mProgressDialog = gtk_dialog_new ();
+ GtkDialog *dialog = GTK_DIALOG (mProgressDialog);
+
+ gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+
+ g_signal_connect (dialog, "delete-event",
+ G_CALLBACK (ProgressDeleteCallback), NULL);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (ProgressResponseCallback), this);
+
+ /* FIXME do we need transient? initially on top should suffice */
+ gtk_window_set_transient_for (GTK_WINDOW (dialog),
+ GTK_WINDOW (parent));
+
+ gtk_dialog_set_has_separator (dialog, FALSE);
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_box_set_spacing (GTK_BOX (dialog->vbox), 14); /* 2 * 5 + 14 = 24 */
+ gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
+
+ hbox = gtk_hbox_new (FALSE, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+ gtk_container_add (GTK_CONTAINER (dialog->vbox), hbox);
+
+ image = gtk_image_new_from_stock (GTK_STOCK_PRINT, GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+
+ mTitleLabel = gtk_label_new (NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (mTitleLabel), TRUE);
+ gtk_misc_set_alignment (GTK_MISC (mTitleLabel), 0.0, 0.0);
+ gtk_box_pack_start (GTK_BOX (vbox), mTitleLabel, FALSE, FALSE, 0);
+
+ mProgressBar = gtk_progress_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), mProgressBar, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (hbox);
+ gtk_window_present (GTK_WINDOW (dialog));
+
+ *_notifyOnOpen = PR_FALSE;
+
+ return NS_OK;
+}
+
+/* void closeProgressDialog (in boolean forceClose); */
+NS_IMETHODIMP
+GeckoPrintSession::CloseProgressDialog (PRBool forceClose)
+{
+ return NS_OK;
+}
+
+/* void registerListener (in nsIWebProgressListener listener); */
+NS_IMETHODIMP
+GeckoPrintSession::RegisterListener (nsIWebProgressListener *listener)
+{
+ return NS_OK;
+}
+
+/* void unregisterListener (in nsIWebProgressListener listener); */
+NS_IMETHODIMP
+GeckoPrintSession::UnregisterListener (nsIWebProgressListener *listener)
+{
+ return NS_OK;
+}
+
+/* void doneIniting (); */
+NS_IMETHODIMP
+GeckoPrintSession::DoneIniting()
+{
+ return NS_OK;
+}
+
+/* nsIPrompt getPrompter (); */
+NS_IMETHODIMP
+GeckoPrintSession::GetPrompter (nsIPrompt **_retval)
+{
+ g_return_val_if_reached (NS_ERROR_NOT_IMPLEMENTED);
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+/* attribute boolean processCanceledByUser; */
+NS_IMETHODIMP
+GeckoPrintSession::GetProcessCanceledByUser (PRBool *aProcessCanceledByUser)
+{
+ *aProcessCanceledByUser = mCancelled;
+ return NS_OK;
+}
+NS_IMETHODIMP
+GeckoPrintSession::SetProcessCanceledByUser (PRBool aProcessCanceledByUser)
+{
+ mCancelled = aProcessCanceledByUser;
+ return NS_OK;
+}
+
+/* nsIPrintProgressParams implementation */
+
+/* attribute wstring docTitle; */
+NS_IMETHODIMP
+GeckoPrintSession::GetDocTitle (PRUnichar * *aDocTitle)
+{
+ g_return_val_if_reached (NS_ERROR_NOT_IMPLEMENTED);
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+GeckoPrintSession::SetDocTitle (const PRUnichar * aDocTitle)
+{
+ NS_ENSURE_STATE (mProgressDialog);
+
+ char *converted = EphyUtils::ConvertUTF16toUTF8 (aDocTitle, MAX_STRING_LENGTH);
+ if (converted) {
+ mTitle.Assign (converted);
+
+ char *title = g_strdup_printf (_("Printing ā€œ%sā€"), converted);
+ gtk_window_set_title (GTK_WINDOW (mProgressDialog), title);
+ gtk_label_set_text (GTK_LABEL (mTitleLabel), title);
+ g_free (converted);
+ g_free (title);
+ }
+ return NS_OK;
+}
+
+/* attribute wstring docURL; */
+NS_IMETHODIMP
+GeckoPrintSession::GetDocURL (PRUnichar * *aDocURL)
+{
+ g_return_val_if_reached (NS_ERROR_NOT_IMPLEMENTED);
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+GeckoPrintSession::SetDocURL (const PRUnichar * aDocURL)
+{
+#if 0
+ NS_ENSURE_STATE (mJob);
+
+ char *converted = EphyUtils::ConvertUTF16toUTF8 (aDocTitle, MAX_STRING_LENGTH);
+ if (converted) {
+ g_free (converted);
+ }
+#endif
+ return NS_OK;
+}
diff --git a/embed/mozilla/GeckoPrintSession.h b/embed/mozilla/GeckoPrintSession.h
new file mode 100644
index 000000000..4b06a9f04
--- /dev/null
+++ b/embed/mozilla/GeckoPrintSession.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2006 Christian Persch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ */
+
+#ifndef GECKO_PRINT_SESSION_H
+#define GECKO_PRINT_SESSION_H
+
+#include <nsCOMPtr.h>
+#include <nsIPrintSession.h>
+#include <nsIWebProgressListener.h>
+#include <nsIPrintProgress.h>
+#include <nsIPrintProgressParams.h>
+#include <nsWeakReference.h>
+
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkprintjob.h>
+#include <gtk/gtkprinter.h>
+#include <gtk/gtkprintjob.h>
+
+class nsIPrintSettings;
+class nsIDOMWindow;
+
+/* 0940c973-97e7-476f-a612-4ed9473a0b36 */
+#define GECKO_PRINT_SESSION_IID \
+{ 0x0940c973, 0x97e7, 0x476f, \
+ { 0xa6, 0x12, 0x4e, 0xd9, 0x47, 0x3a, 0x0b, 0x36 } }
+
+#define GECKO_PRINT_SESSION_CLASSNAME "Gecko Print Session"
+
+class GeckoPrintSession : public nsIPrintSession,
+ public nsIPrintProgress,
+ public nsIPrintProgressParams,
+ public nsSupportsWeakReference
+{
+ public:
+ GeckoPrintSession();
+ virtual ~GeckoPrintSession();
+
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIPRINTSESSION
+ NS_DECL_NSIWEBPROGRESSLISTENER
+ NS_DECL_NSIPRINTPROGRESS
+ NS_DECL_NSIPRINTPROGRESSPARAMS
+
+ nsresult SetSettings (GtkPrintSettings*, GtkPageSetup*, GtkPrinter*);
+ void GetSourceFile (nsACString&);
+
+ static GeckoPrintSession *FromSettings (nsIPrintSettings *);
+
+ void Cancel ();
+ void StartPrinting ();
+ void JobStatusChanged ();
+ void JobDone ();
+ void JobError (const char *);
+
+ private:
+ GtkPrintSettings *mSettings;
+ GtkPageSetup *mPageSetup;
+ GtkPrinter *mPrinter;
+ GtkPrintJob *mJob;
+ GtkWidget *mProgressDialog;
+ GtkWidget *mTitleLabel;
+ GtkWidget *mProgressBar;
+ nsCString mSourceFile;
+ nsCString mTitle;
+ guint mStartPrintIdleID;
+ PRPackedBool mSourceFileIsTemp;
+ PRPackedBool mDone;
+ PRPackedBool mCancelled;
+
+ void SetProgress (PRInt32, PRInt32);
+ void SetProgressText (const char *); void LaunchJob ();
+ void LaunchJobOnIdle ();
+ void DestroyJob ();
+};
+
+#endif /* GECKO_PRINT_SESSION_H */
diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am
index 2e25a2a27..a117955ff 100644
--- a/embed/mozilla/Makefile.am
+++ b/embed/mozilla/Makefile.am
@@ -33,6 +33,10 @@ libephymozillaembed_la_SOURCES = \
EphyUtils.h \
EventContext.cpp \
EventContext.h \
+ GeckoPrintService.cpp \
+ GeckoPrintService.h \
+ GeckoPrintSession.cpp \
+ GeckoPrintSession.has \
GlobalHistory.cpp \
GlobalHistory.h \
MozDownload.cpp \
@@ -41,8 +45,6 @@ libephymozillaembed_la_SOURCES = \
MozillaPrivate.h \
MozRegisterComponents.cpp \
MozRegisterComponents.h \
- PrintingPromptService.cpp \
- PrintingPromptService.h \
mozilla-download.cpp \
mozilla-download.h \
mozilla-embed.cpp \
diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp
index b2fb94b02..0ec74ff17 100644
--- a/embed/mozilla/MozRegisterComponents.cpp
+++ b/embed/mozilla/MozRegisterComponents.cpp
@@ -29,12 +29,14 @@
#include <nsComponentManagerUtils.h>
#include <nsCOMPtr.h>
+#include <nsCURILoader.h>
#include <nsDocShellCID.h>
#include <nsICategoryManager.h>
#include <nsIComponentManager.h>
#include <nsIComponentRegistrar.h>
#include <nsIGenericFactory.h>
#include <nsILocalFile.h>
+#include <nsIScriptNameSpaceManager.h>
#include <nsIServiceManager.h>
#include <nsMemory.h>
#include <nsNetCID.h>
@@ -53,9 +55,10 @@
#include "EphyContentPolicy.h"
#include "EphyPromptService.h"
#include "EphySidebar.h"
+#include "GeckoPrintService.h"
+#include "GeckoPrintSession.h"
#include "GlobalHistory.h"
#include "MozDownload.h"
-#include "PrintingPromptService.h"
#ifdef ENABLE_FILEPICKER
#include "FilePicker.h"
@@ -77,7 +80,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(EphyContentPolicy)
NS_GENERIC_FACTORY_CONSTRUCTOR(EphyPromptService)
NS_GENERIC_FACTORY_CONSTRUCTOR(EphySidebar)
NS_GENERIC_FACTORY_CONSTRUCTOR(GContentHandler)
-NS_GENERIC_FACTORY_CONSTRUCTOR(GPrintingPromptService)
+NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintService)
+NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintSession)
NS_GENERIC_FACTORY_CONSTRUCTOR(MozDownload)
NS_GENERIC_FACTORY_CONSTRUCTOR(MozGlobalHistory)
@@ -96,41 +100,48 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSKeyPairDialogs)
NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSSecurityWarningDialogs)
#endif
+#define XPINSTALL_CONTRACTID NS_CONTENT_HANDLER_CONTRACTID_PREFIX "application/x-xpinstall"
+
/* class information */
NS_DECL_CLASSINFO(EphySidebar)
-static NS_METHOD
-RegisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath,
- const char *registryLocation, const char *componentType,
- const nsModuleComponentInfo *info)
+static nsresult
+RegisterCategories (void)
{
- nsCOMPtr<nsICategoryManager> cm =
- do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
- NS_ENSURE_TRUE (cm, NS_ERROR_FAILURE);
-
nsresult rv;
- char *oldval = nsnull;
- rv = cm->AddCategoryEntry ("content-policy",
- EPHY_CONTENT_POLICY_CONTRACTID,
- EPHY_CONTENT_POLICY_CONTRACTID,
- PR_TRUE, PR_TRUE, &oldval);
- if (oldval)
- nsMemory::Free (oldval);
- return rv;
-}
+ nsCOMPtr<nsICategoryManager> catMan =
+ do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
+ NS_ENSURE_SUCCESS (rv, rv);
-static NS_METHOD
-RegisterSidebar(nsIComponentManager *aCompMgr, nsIFile *aPath,
- const char *registryLocation, const char *componentType,
- const nsModuleComponentInfo *info)
-{
- nsCOMPtr<nsICategoryManager> cm =
- do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
- NS_ENSURE_TRUE (cm, NS_ERROR_FAILURE);
+ rv = catMan->AddCategoryEntry ("content-policy",
+ EPHY_CONTENT_POLICY_CONTRACTID,
+ EPHY_CONTENT_POLICY_CONTRACTID,
+ PR_FALSE /* don't persist */,
+ PR_TRUE /* replace */,
+ nsnull);
+
+ rv |= catMan->AddCategoryEntry (JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
+ "sidebar",
+ NS_SIDEBAR_CONTRACTID,
+ PR_FALSE /* don't persist */,
+ PR_TRUE /* replace */,
+ nsnull);
- return cm->AddCategoryEntry("JavaScript global property",
- "sidebar", NS_SIDEBAR_CONTRACTID,
- PR_FALSE, PR_TRUE, nsnull);
+#ifdef HAVE_GECKO_1_9
+ /* Unregister the XPI install trigger too
+ * Only do it on gecko 1.9 though, because it breaks in 1.8
+ * (because of https://bugzilla.mozilla.org/show_bug.cgi?id=329450)
+ */
+ rv |= catMan->DeleteCategoryEntry (JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY,
+ "InstallVersion",
+ PR_FALSE /* don't persist */);
+ rv |= catMan->DeleteCategoryEntry (JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
+ "InstallTrigger",
+ PR_FALSE /* don't persist */);
+ NS_ENSURE_SUCCESS (rv, rv);
+#endif
+
+ return rv;
}
static const nsModuleComponentInfo sAppComps[] = {
@@ -197,24 +208,29 @@ static const nsModuleComponentInfo sAppComps[] = {
MozGlobalHistoryConstructor
},
{
- G_PRINTINGPROMPTSERVICE_CLASSNAME,
- G_PRINTINGPROMPTSERVICE_CID,
- G_PRINTINGPROMPTSERVICE_CONTRACTID,
- GPrintingPromptServiceConstructor
+ GECKO_PRINT_SERVICE_CLASSNAME,
+ GECKO_PRINT_SERVICE_IID,
+ "@mozilla.org/embedcomp/printingprompt-service;1",
+ GeckoPrintServiceConstructor
+ },
+ {
+ GECKO_PRINT_SESSION_CLASSNAME,
+ GECKO_PRINT_SESSION_IID,
+ "@mozilla.org/gfx/printsession;1",
+ GeckoPrintSessionConstructor
},
{
EPHY_CONTENT_POLICY_CLASSNAME,
EPHY_CONTENT_POLICY_CID,
EPHY_CONTENT_POLICY_CONTRACTID,
EphyContentPolicyConstructor,
- RegisterContentPolicy
},
{
EPHY_SIDEBAR_CLASSNAME,
EPHY_SIDEBAR_CID,
NS_SIDEBAR_CONTRACTID,
EphySidebarConstructor,
- RegisterSidebar,
+ nsnull /* no register func */,
nsnull /* no unregister func */,
nsnull /* no factory destructor */,
NS_CI_INTERFACE_GETTER_NAME(EphySidebar),
@@ -314,5 +330,28 @@ mozilla_register_components (void)
}
}
+ rv = RegisterCategories();
+ ret = NS_SUCCEEDED (rv);
+
+ /* Unregister xpinstall content handler */
+ nsCID *cidPtr = nsnull;
+ rv = cr->ContractIDToCID (XPINSTALL_CONTRACTID, &cidPtr);
+ if (NS_SUCCEEDED (rv) && cidPtr)
+ {
+ nsCOMPtr<nsIFactory> factory;
+ rv = cm->GetClassObject (*cidPtr, NS_GET_IID (nsIFactory),
+ getter_AddRefs (factory));
+ if (NS_SUCCEEDED (rv))
+ {
+ rv = cr->UnregisterFactory (*cidPtr, factory);
+ }
+
+ nsMemory::Free (cidPtr);
+ }
+ if (NS_FAILED (rv))
+ {
+ g_warning ("Failed to unregister xpinstall content handler!\n");
+ }
+
return ret;
}
diff --git a/embed/mozilla/PrintingPromptService.cpp b/embed/mozilla/PrintingPromptService.cpp
deleted file mode 100644
index 121425060..000000000
--- a/embed/mozilla/PrintingPromptService.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2002 Philip Langdale
- * Copyright (C) 2003-2004 Christian Persch
- * Copyright (C) 2005 Juerg Billeter
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#include "mozilla-config.h"
-#include "config.h"
-
-#include <gtk/gtkdialog.h>
-
-#include <libgnomeprintui/gnome-print-dialog.h>
-
-#include "eel-gconf-extensions.h"
-#include "ephy-command-manager.h"
-#include "ephy-debug.h"
-#include "ephy-embed.h"
-#include "ephy-prefs.h"
-#include "print-dialog.h"
-
-#include <nsCOMPtr.h>
-#include <nsIPrintSettings.h>
-#include <nsIServiceManager.h>
-
-#include "EphyUtils.h"
-#include "AutoJSContextStack.h"
-
-#include "PrintingPromptService.h"
-
-/* Implementation file */
-NS_IMPL_ISUPPORTS3(GPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener, nsIPrintProgressParams)
-
-GPrintingPromptService::GPrintingPromptService()
-{
- LOG ("GPrintingPromptService ctor (%p)", this);
-
- mPrintInfo = NULL;
-}
-
-GPrintingPromptService::~GPrintingPromptService()
-{
- LOG ("GPrintingPromptService dtor (%p)", this);
-
- if (mPrintInfo != NULL)
- {
- ephy_print_info_free (mPrintInfo);
- }
-}
-
-/* void showPrintDialog (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings); */
-NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings)
-{
- EmbedPrintInfo *info;
- GtkWidget *dialog;
-
- if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINTING))
- {
- return NS_ERROR_ABORT;
- }
-
- nsresult rv;
- AutoJSContextStack stack;
- rv = stack.Init ();
- if (NS_FAILED (rv)) return rv;
-
- EphyEmbed *embed = EPHY_EMBED (EphyUtils::FindEmbed (parent));
- NS_ENSURE_TRUE (embed, NS_ERROR_FAILURE);
-
- info = ephy_print_get_print_info ();
-
- if (!eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP))
- {
- GtkWidget *gtkParent = EphyUtils::FindGtkParent(parent);
- NS_ENSURE_TRUE (gtkParent, NS_ERROR_FAILURE);
-
- dialog = ephy_print_dialog_new (gtkParent, info);
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- int ret;
-
- while (TRUE)
- {
- ret = gtk_dialog_run (GTK_DIALOG (dialog));;
-
- if (ret != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
- break;
-
- if (ephy_print_verify_postscript (GNOME_PRINT_DIALOG (dialog)))
- break;
- }
-
- gtk_widget_destroy (dialog);
-
- if (ret != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
- {
- ephy_print_info_free (info);
-
- return NS_ERROR_ABORT;
- }
- }
-
- /* work around mozilla bug which borks when printing selection without having one */
- if (info->range == GNOME_PRINT_RANGE_SELECTION &&
- ephy_command_manager_can_do_command
- (EPHY_COMMAND_MANAGER (embed), "cmd_copy") == FALSE)
- {
- info->range = GNOME_PRINT_RANGE_ALL;
- }
-
- EphyUtils::CollatePrintSettings (info, printSettings, FALSE);
-
- mPrintInfo = info;
-
- return NS_OK;
-}
-
-/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, in nsIObserver openDialogObserver, in boolean isForPrinting, out nsIWebProgressListener webProgressListener, out nsIPrintProgressParams printProgressParams, out boolean notifyOnOpen); */
-NS_IMETHODIMP GPrintingPromptService::ShowProgress(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings, nsIObserver *openDialogObserver, PRBool isForPrinting, nsIWebProgressListener **webProgressListener, nsIPrintProgressParams **printProgressParams, PRBool *notifyOnOpen)
-{
- *printProgressParams = NS_STATIC_CAST(nsIPrintProgressParams*, this);
- NS_ADDREF(*printProgressParams);
-
- *webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);
- NS_ADDREF(*webProgressListener);
-
- return NS_OK;
-}
-
-/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings, in nsIObserver printObserver); */
-NS_IMETHODIMP GPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent,
- nsIPrintSettings *printSettings,
- nsIObserver *printObserver)
-{
- EphyDialog *dialog;
- nsresult rv = NS_ERROR_ABORT;
-
- if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINTING) ||
- eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP))
- {
- return rv;
- }
-
- AutoJSContextStack stack;
- rv = stack.Init ();
- if (NS_FAILED (rv)) return rv;
-
- dialog = ephy_print_setup_dialog_new ();
- ephy_dialog_set_modal (dialog, TRUE);
-
- int ret = ephy_dialog_run (dialog);
- if (ret == GTK_RESPONSE_OK)
- {
- rv = NS_OK;
- }
-
- g_object_unref (dialog);
-
- return rv;
-}
-
-/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */
-NS_IMETHODIMP GPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in nsresult aStatus); */
-NS_IMETHODIMP GPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
-{
- if ((aStateFlags & STATE_STOP) && mPrintInfo)
- {
- if (NS_SUCCEEDED (aStatus))
- {
- ephy_print_do_print_and_free (mPrintInfo);
- }
- else
- {
- ephy_print_info_free (mPrintInfo);
- }
-
- mPrintInfo = NULL;
- }
- return NS_OK;
-}
-
-/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
-NS_IMETHODIMP GPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
-NS_IMETHODIMP GPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
-NS_IMETHODIMP GPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
-NS_IMETHODIMP GPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-/* attribute wstring docTitle; */
-NS_IMETHODIMP GPrintingPromptService::GetDocTitle(PRUnichar * *aDocTitle)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-NS_IMETHODIMP GPrintingPromptService::SetDocTitle(const PRUnichar * aDocTitle)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-/* attribute wstring docURL; */
-NS_IMETHODIMP GPrintingPromptService::GetDocURL(PRUnichar * *aDocURL)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-NS_IMETHODIMP GPrintingPromptService::SetDocURL(const PRUnichar * aDocURL)
-{
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
diff --git a/embed/mozilla/PrintingPromptService.h b/embed/mozilla/PrintingPromptService.h
deleted file mode 100644
index de0dfb353..000000000
--- a/embed/mozilla/PrintingPromptService.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2000 Marco Pesenti Gritti
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- */
-
-#ifndef __PrintingPromptService_h
-#define __PrintingPromptService_h
-
-#include "print-dialog.h"
-
-#include <nscore.h>
-#include <nsIPrintingPromptService.h>
-
-#define G_PRINTINGPROMPTSERVICE_CID \
-{ /* 5998a2d3-88ea-4c52-b4bb-4e7abd0d35e0 */ \
- 0x5998a2d3, \
- 0x88ea, \
- 0x4c52, \
- {0xb4, 0xbb, 0x4e, 0x7a, 0xbd, 0x0d, 0x35, 0xe0} \
-}
-
-#define G_PRINTINGPROMPTSERVICE_CLASSNAME "Epiphany's Printing Prompt Service"
-#define G_PRINTINGPROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/printingprompt-service;1"
-
-class GPrintingPromptService : public nsIPrintingPromptService,
- nsIWebProgressListener,
- nsIPrintProgressParams
-{
-public:
- NS_DECL_ISUPPORTS
- NS_DECL_NSIPRINTINGPROMPTSERVICE
- NS_DECL_NSIWEBPROGRESSLISTENER
- NS_DECL_NSIPRINTPROGRESSPARAMS
-
- GPrintingPromptService();
- virtual ~GPrintingPromptService();
- /* additional members */
-
-protected:
- EmbedPrintInfo *mPrintInfo;
-};
-
-#endif