diff options
82 files changed, 0 insertions, 22391 deletions
diff --git a/embed/mozilla/AutoJSContextStack.cpp b/embed/mozilla/AutoJSContextStack.cpp deleted file mode 100644 index 97fa84f33..000000000 --- a/embed/mozilla/AutoJSContextStack.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsServiceManagerUtils.h> - -#include "AutoJSContextStack.h" - -AutoJSContextStack::~AutoJSContextStack() -{ - if (mStack) - { - JSContext* cx; - mStack->Pop (&cx); - - NS_ASSERTION(cx == nsnull, "We pushed a null context but popped a non-null context!?"); - } -} - -nsresult -AutoJSContextStack::Init() -{ - nsresult rv; - mStack = do_GetService ("@mozilla.org/js/xpc/ContextStack;1", &rv); - if (NS_FAILED (rv)) return rv; - - return mStack->Push (nsnull); -} diff --git a/embed/mozilla/AutoJSContextStack.h b/embed/mozilla/AutoJSContextStack.h deleted file mode 100644 index 0db423a64..000000000 --- a/embed/mozilla/AutoJSContextStack.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef AUTO_JSCONTEXTSTACK_H -#define AUTO_JSCONTEXTSTACK_H - -struct JSContext; - -#include <nsCOMPtr.h> -#include <nsIJSContextStack.h> - -class AutoJSContextStack -{ - public: - AutoJSContextStack () { } - ~AutoJSContextStack (); - - nsresult Init (); - - private: - nsCOMPtr<nsIJSContextStack> mStack; -}; - -#endif diff --git a/embed/mozilla/AutoModalDialog.cpp b/embed/mozilla/AutoModalDialog.cpp deleted file mode 100644 index 034730850..000000000 --- a/embed/mozilla/AutoModalDialog.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright © 2006, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Some code taken from mozilla/embedding/components/windowwatcher/src/nsPromptService.cpp - * which was under MPL/LGPL/GPL tri-licence and is here being used under the licence above. - * Original notice: - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - */ - -#include <xpcom-config.h> -#include <config.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsIDOMDocumentEvent.h> -#include <nsIDOMDocument.h> -#include <nsIDOMEvent.h> -#include <nsIDOMEventTarget.h> -#include <nsIPrivateDOMEvent.h> -#include <nsPIDOMWindow.h> -#include <nsServiceManagerUtils.h> -#include <nsThreadUtils.h> -#endif /* HAVE_GECKO_1_9 */ - -#include <gtk/gtkdialog.h> - -#include "EphyUtils.h" - -#include "AutoModalDialog.h" - -AutoModalDialog::AutoModalDialog (nsIDOMWindow *aWindow, - PRBool aNotifyDOM) - : mWindow (aWindow), - mStack (), - mModalState (aWindow), -#ifdef HAVE_GECKO_1_9 - mDefaultEnabled (DispatchEvent ("DOMWillOpenModalDialog", aNotifyDOM)), -#else - mDefaultEnabled (PR_TRUE), -#endif - mContextPushed (NS_SUCCEEDED (mStack.Init ())) -{ -} - -AutoModalDialog::~AutoModalDialog () -{ -#ifdef HAVE_GECKO_1_9 - if (mDefaultEnabled) { - DispatchEvent ("DOMModalDialogClosed", PR_TRUE); - } -#endif /* HAVE_GECKO_1_9 */ -} - -GtkWindow * -AutoModalDialog::GetParent () -{ - return GTK_WINDOW (EphyUtils::FindGtkParent (mWindow)); -} - -int -AutoModalDialog::Run (GtkDialog *aDialog) -{ - NS_ASSERTION (ShouldShow(), "Calling ::Run on a prevented dialogue!"); - - nsCOMPtr<nsPIDOMWindow> pWindow (do_QueryInterface (mWindow)); - - // Reset popup state while opening a modal dialog, and firing - // events about the dialog, to prevent the current state from - // being active the whole time a modal dialog is open. - nsAutoPopupStatePusher popupStatePusher (pWindow, openAbused); - -#if 1 - return gtk_dialog_run (aDialog); -#else - /* Do NOT use gtk_dialog_run here, since it blocks the network thread! - * See https://bugzilla.mozilla.org/show_bug.cgi?id=338225 - */ - - g_object_ref_sink (aDialog); - mResponse = GTK_RESPONSE_DELETE_EVENT; - - gulong responseHandler = g_signal_connect (aDialog, "response", - G_CALLBACK (ResponseCallback), - reinterpret_cast<void*>(this)); - gulong deleteHandler = g_signal_connect (aDialog, "delete-event", - G_CALLBACK (DeleteCallback), NULL); - - gtk_window_present (GTK_WINDOW (aDialog)); - - nsCOMPtr<nsIThread> thread (do_GetCurrentThread ()); - NS_ASSERTION (thread, "No UI thread?"); - - mContinueModalLoop = PR_TRUE; - while (mContinueModalLoop) { - if (!NS_ProcessNextEvent (thread)) - break; - } - - g_signal_handler_disconnect (aDialog, responseHandler); - g_signal_handler_disconnect (aDialog, deleteHandler); - g_object_unref (aDialog); - - return mResponse; -#endif -} - -#ifdef HAVE_GECKO_1_9 - -PRBool -AutoModalDialog::DispatchEvent (const char *aEventName, - PRBool aDoNotify) -{ - if (!mWindow || !aDoNotify) { - return PR_TRUE; - } - - nsCOMPtr<nsIDOMDocument> domdoc; - mWindow->GetDocument (getter_AddRefs (domdoc)); - - nsCOMPtr<nsIDOMDocumentEvent> docevent (do_QueryInterface (domdoc)); - nsCOMPtr<nsIDOMEvent> event; - - PRBool defaultActionEnabled = PR_TRUE; - - if (docevent) { - docevent->CreateEvent (NS_LITERAL_STRING ("Events"), getter_AddRefs (event)); - - nsCOMPtr<nsIPrivateDOMEvent> privateEvent (do_QueryInterface (event)); - if (privateEvent) { - event->InitEvent (NS_ConvertASCIItoUTF16 (aEventName), PR_TRUE, PR_TRUE); - - privateEvent->SetTrusted(PR_TRUE); - - nsCOMPtr<nsIDOMEventTarget> target (do_QueryInterface (mWindow)); - - target->DispatchEvent (event, &defaultActionEnabled); - } - } - - return defaultActionEnabled; -} - -/* static */ void PR_CALLBACK -AutoModalDialog::ResponseCallback (GtkWidget *aDialog, - int aResponse, - void *aData) -{ - AutoModalDialog *obj = reinterpret_cast<AutoModalDialog*>(aData); - - gtk_widget_hide (aDialog); - obj->mResponse = aResponse; - obj->mContinueModalLoop = PR_FALSE; -} - -/* static */ gboolean PR_CALLBACK -AutoModalDialog::DeleteCallback (GtkWidget *aDialog, - void *aEvent, - void *aData) -{ - gtk_dialog_response (GTK_DIALOG (aDialog), GTK_RESPONSE_DELETE_EVENT); - return TRUE; -} - -#endif /* HAVE_GECKO_1_9 */ diff --git a/embed/mozilla/AutoModalDialog.h b/embed/mozilla/AutoModalDialog.h deleted file mode 100644 index f20a22149..000000000 --- a/embed/mozilla/AutoModalDialog.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright © 2006, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef AUTOMODALDIALOG_H -#define AUTOMODALDIALOG_H - -#include <nsCOMPtr.h> - -#include <gtk/gtkwidget.h> - -#include "AutoJSContextStack.h" -#include "AutoWindowModalState.h" - -/** - * AutoModalDialog: - * A stack-based helper class for modal GTK+ dialogues. - * - * You MUST check ::ShouldShow() before showing the dialogue! - */ -class AutoModalDialog -{ - public: - AutoModalDialog (nsIDOMWindow *, PRBool); - ~AutoModalDialog (); - - GtkWindow *GetParent (); - - PRBool ShouldShow () { return mDefaultEnabled && mContextPushed; } - - int Run (GtkDialog *aDialog); - - private: - // stack only please - void *operator new (size_t) CPP_THROW_NEW; - - nsCOMPtr<nsIDOMWindow> mWindow; - - AutoJSContextStack mStack; - AutoWindowModalState mModalState; - -#ifdef HAVE_GECKO_1_9 - static void PR_CALLBACK ResponseCallback (GtkWidget*, int, void*); - static gboolean PR_CALLBACK DeleteCallback (GtkWidget*, void*, void*); - - PRBool DispatchEvent (const char*, PRBool); - - int mResponse; - PRBool mContinueModalLoop; -#endif - - PRBool mDefaultEnabled; - PRBool mContextPushed; -}; - -#endif diff --git a/embed/mozilla/AutoWindowModalState.cpp b/embed/mozilla/AutoWindowModalState.cpp deleted file mode 100644 index 0ff11e4ab..000000000 --- a/embed/mozilla/AutoWindowModalState.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include <mozilla-config.h> -#include "config.h" - -#include "AutoWindowModalState.h" - -AutoWindowModalState::AutoWindowModalState (nsIDOMWindow *aWindow) -{ -#ifdef HAVE_GECKO_1_8_1 - if (aWindow) { - mWindow = do_QueryInterface (aWindow); - NS_ASSERTION (mWindow, "Should have a window here!"); - } - - if (mWindow) { -#ifdef HAVE_GECKO_1_9 - mWindow->EnterModalState (); -#else - nsCOMPtr<nsPIDOMWindow_MOZILLA_1_8_BRANCH> window (do_QueryInterface (mWindow)); - NS_ENSURE_TRUE (window, ); - - window->EnterModalState (); -#endif /* HAVE_GECKO_1_9 */ - } -#endif /* HAVE_GECKO_1_8_1 */ -} - -AutoWindowModalState::~AutoWindowModalState() -{ -#ifdef HAVE_GECKO_1_8_1 - if (mWindow) { -#ifdef HAVE_GECKO_1_9 - mWindow->LeaveModalState (); -#else - nsCOMPtr<nsPIDOMWindow_MOZILLA_1_8_BRANCH> window (do_QueryInterface (mWindow)); - NS_ENSURE_TRUE (window, ); - - window->LeaveModalState (); -#endif /* HAVE_GECKO_1_9 */ - } -#endif /* HAVE_GECKO_1_8_1 */ -} diff --git a/embed/mozilla/AutoWindowModalState.h b/embed/mozilla/AutoWindowModalState.h deleted file mode 100644 index 557865799..000000000 --- a/embed/mozilla/AutoWindowModalState.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef AUTO_WINDOWMODALSTATE_H -#define AUTO_WINDOWMODALSTATE_H - -#include <nsCOMPtr.h> -#include <nsPIDOMWindow.h> - -class AutoWindowModalState -{ - public: - AutoWindowModalState (nsIDOMWindow *); - ~AutoWindowModalState (); - - private: - - nsCOMPtr<nsPIDOMWindow> mWindow; -}; - -#endif diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp deleted file mode 100644 index 3535d362c..000000000 --- a/embed/mozilla/ContentHandler.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright © 2001 Philip Langdale - * Copyright © 2003 Marco Pesenti Gritti - * Copyright © 2003 Xan Lopez - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gi18n.h> -#include <gio/gio.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkimage.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkstock.h> - -#include <nsStringAPI.h> - -#include <nsCExternalHandlerService.h> -#include <nsComponentManagerUtils.h> -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsILocalFile.h> -#include <nsIMIMEInfo.h> -#include <nsIURL.h> -#include <nsMemory.h> -#include <nsNetError.h> -#include <nsServiceManagerUtils.h> - -#include "eel-gconf-extensions.h" -#include "ephy-debug.h" -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" -#include "ephy-file-chooser.h" -#include "ephy-file-helpers.h" -#include "ephy-gui.h" -#include "ephy-prefs.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" -#include "MozDownload.h" - -#include "ContentHandler.h" - -/* FIXME: we don't generally have a timestamp for the user action which initiated this - * content handler. - */ -GContentHandler::GContentHandler() -: mUserTime(0) -{ - LOG ("GContentHandler ctor (%p)", this); -} - -GContentHandler::~GContentHandler() -{ - LOG ("GContentHandler dtor (%p)", this); -} - -NS_IMPL_ISUPPORTS1(GContentHandler, nsIHelperAppLauncherDialog) - -/* void show (in nsIHelperAppLauncher aLauncher, in nsISupports aContext, in unsigned long aReason); */ -NS_IMETHODIMP -GContentHandler::Show (nsIHelperAppLauncher *aLauncher, - nsISupports *aContext, - PRUint32 aReason) -{ - nsresult rv; - EphyEmbedSingle *single; - gboolean handled = FALSE; - - /* FIXME: handle aForced / aReason argument in some way? */ - - mContext = aContext; - - /* Check for a potential veto */ - nsCOMPtr<nsIDOMWindow> window (do_GetInterface (aContext)); - GtkWidget *embed = EphyUtils::FindEmbed (window); - if (EPHY_IS_EMBED (embed)) - { - if (g_object_get_data (G_OBJECT (embed), "content-handler-deny")) - { - return NS_OK; - } - } - - mLauncher = aLauncher; - rv = Init (); - NS_ENSURE_SUCCESS (rv, rv); - - single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); - g_signal_emit_by_name (single, "handle_content", mMimeType.get(), - mUrl.get(), &handled); - - if (!handled) - { - MIMEInitiateAction (); - } - else - { - mLauncher->Cancel (NS_BINDING_ABORTED); - } - - return NS_OK; -} - -/* nsILocalFile promptForSaveToFile (in nsISupports aWindowContext, in wstring aDefaultFile, in wstring aSuggestedFileExtension); */ -NS_IMETHODIMP GContentHandler::PromptForSaveToFile( - nsIHelperAppLauncher *aLauncher, - nsISupports *aWindowContext, - const PRUnichar *aDefaultFile, - const PRUnichar *aSuggestedFileExtension, - nsILocalFile **_retval) -{ - EphyFileChooser *dialog; - int response; - char *filename = NULL; - nsCString defaultFile; - - NS_UTF16ToCString (nsString (aDefaultFile), - NS_CSTRING_ENCODING_UTF8, defaultFile); - - if (mAction != CONTENT_ACTION_SAVEAS) - { - return BuildDownloadPath (defaultFile.get(), _retval); - } - nsCOMPtr<nsIDOMWindow> parentDOMWindow (do_GetInterface (aWindowContext)); - - AutoModalDialog modalDialog (parentDOMWindow, PR_FALSE); - if (!modalDialog.ShouldShow ()) - return NS_ERROR_FAILURE; - - GtkWindow *parentWindow = modalDialog.GetParent (); - - dialog = ephy_file_chooser_new (_("Save"), GTK_WIDGET (parentWindow), - GTK_FILE_CHOOSER_ACTION_SAVE, - CONF_STATE_SAVE_DIR, - EPHY_FILE_FILTER_ALL); - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), defaultFile.get()); - - if (parentWindow) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (parentWindow)), - GTK_WINDOW (dialog)); - } - - /* FIXME: this will only be the real user time if we came from ::Show */ - ephy_gui_window_update_user_time (GTK_WIDGET (dialog), (guint32) mUserTime); - - /* FIXME: modal -- mozilla sucks! */ - do - { - g_free (filename); - response = modalDialog.Run (GTK_DIALOG (dialog)); - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - } while (response == GTK_RESPONSE_ACCEPT - && !ephy_gui_check_location_writable (GTK_WIDGET (dialog), filename)); - - if (response == GTK_RESPONSE_ACCEPT) - { - nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - NS_ENSURE_TRUE (destFile, NS_ERROR_FAILURE); - - destFile->InitWithNativePath (nsCString (filename)); - g_free (filename); - - NS_IF_ADDREF (*_retval = destFile); - - gtk_widget_destroy (GTK_WIDGET (dialog)); - - return NS_OK; - } - else - { - gtk_widget_destroy (GTK_WIDGET (dialog)); - g_free (filename); - - return NS_ERROR_FAILURE; - } -} - -NS_METHOD GContentHandler::Init () -{ - nsresult rv; - - NS_ENSURE_TRUE (mLauncher, NS_ERROR_FAILURE); - - nsCOMPtr<nsIMIMEInfo> MIMEInfo; - mLauncher->GetMIMEInfo (getter_AddRefs(MIMEInfo)); - NS_ENSURE_TRUE (MIMEInfo, NS_ERROR_FAILURE); - - rv = MIMEInfo->GetMIMEType (mMimeType); - - nsCOMPtr<nsIURI> uri; - mLauncher->GetSource (getter_AddRefs(uri)); - NS_ENSURE_TRUE (uri, NS_ERROR_FAILURE); - - uri->GetSpec (mUrl); - - return NS_OK; -} - -static void -response_cb (GtkWidget *dialog, - int response, - GContentHandler *self) -{ - gtk_widget_destroy (dialog); - - if (response > 0) - { - self->mAction = (ContentAction) response; - } - else - { - self->mAction = CONTENT_ACTION_NONE; - } - - self->MIMEDoAction (); -} - -static void -release_cb (GContentHandler *data) -{ - NS_RELEASE (data); -} - -NS_METHOD GContentHandler::MIMEConfirmAction () -{ - GtkWidget *dialog, *button, *image; - const char *action_label; - char *mime_description; - nsCString file_name; - - nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (mContext); - GtkWindow *parentWindow = GTK_WINDOW (EphyUtils::FindGtkParent(parentDOMWindow)); - - action_label = (mAction == CONTENT_ACTION_OPEN) || - (mAction == CONTENT_ACTION_OPEN_TMP) ? - GTK_STOCK_OPEN : STOCK_DOWNLOAD; - - mime_description = g_content_type_get_description (mMimeType.get()); - if (mime_description == NULL) - { - /* Translators: The text before the "|" is context to help you decide on - * the correct translation. You MUST OMIT it in the translated string. */ - mime_description = g_strdup (Q_("File Type:|Unknown")); - } - - /* We have one tiny, minor issue, the filename can be empty (""), - is that severe enough to be completely fixed ? */ - nsString suggested; - - mLauncher->GetSuggestedFileName (suggested); - NS_UTF16ToCString (suggested, - NS_CSTRING_ENCODING_UTF8, file_name); - - if (mPermission != EPHY_MIME_PERMISSION_SAFE && mHelperApp) - { - dialog = gtk_message_dialog_new - (parentWindow, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, - _("Download this potentially unsafe file?")); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - /* translators: First %s is the file type description, - Second %s is the file name */ - _("File Type: “%s”.\n\nIt is unsafe to open “%s” as " - "it could potentially damage your documents or " - "invade your privacy. You can download it instead."), - mime_description, file_name.get()); - } - else if (mAction == CONTENT_ACTION_OPEN_TMP && mHelperApp) - { - dialog = gtk_message_dialog_new - (parentWindow, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - _("Open this file?")); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - /* translators: First %s is the file type description, - Second %s is the file name, - Third %s is the application used to open the file */ - _("File Type: “%s”.\n\nYou can open “%s” using “%s” or save it."), - mime_description, file_name.get(), g_app_info_get_name (mHelperApp)); - } - else - { - dialog = gtk_message_dialog_new - (parentWindow, GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - _("Download this file?")); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - /* translators: First %s is the file type description, - Second %s is the file name */ - _("File Type: “%s”.\n\nYou have no application able to open “%s”. " - "You can download it instead."), - mime_description, file_name.get()); - } - - g_free (mime_description); - - button = gtk_button_new_with_label (_("_Save As...")); - image = gtk_image_new_from_stock (GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (button), image); - /* don't show the image! see bug #307818 */ - gtk_widget_show (button); - gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, CONTENT_ACTION_SAVEAS); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG (dialog), - action_label, mAction); - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - int defaultResponse = mAction == CONTENT_ACTION_NONE - ? (int) GTK_RESPONSE_CANCEL - : (int) mAction; - gtk_dialog_set_default_response (GTK_DIALOG (dialog), defaultResponse); - - NS_ADDREF_THIS(); - g_signal_connect_data (dialog, "response", - G_CALLBACK (response_cb), this, - (GClosureNotify) release_cb, (GConnectFlags) 0); - - /* FIXME: should find a way to get the user time of the user action which - * initiated this content handler - */ - gtk_window_present (GTK_WINDOW (dialog)); - - return NS_OK; -} - -NS_METHOD GContentHandler::MIMEInitiateAction (void) -{ - gboolean auto_downloads; - - if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_SAVE_TO_DISK)) return NS_OK; - - auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS); - - mHelperApp = g_app_info_get_default_for_type (mMimeType.get(), TRUE); - mPermission = ephy_file_check_mime (mMimeType.get()); - - /* HACK! Check that this 'helper application' isn't Epiphany itself, - * see bug #310023. - */ - if (mHelperApp) - { - const char *id = g_app_info_get_id (mHelperApp); - - /* FIXME! menu editing can make this check fail!!!! */ - if (id && strcmp (id, "epiphany.desktop") == 0) - { - mHelperApp = nsnull; - } - } - - if (auto_downloads) - { - mAction = CONTENT_ACTION_OPEN; - } - else - { - mAction = CONTENT_ACTION_OPEN_TMP; - } - - if (!mHelperApp || mPermission != EPHY_MIME_PERMISSION_SAFE) - { - mAction = CONTENT_ACTION_DOWNLOAD; - } - - if (!auto_downloads || mAction == CONTENT_ACTION_DOWNLOAD) - { - MIMEConfirmAction (); - } - else - { - MIMEDoAction (); - } - - return NS_OK; -} - -NS_METHOD GContentHandler::MIMEDoAction (void) -{ - /* This is okay, since we either clicked on a button, or we get 0 */ - mUserTime = gtk_get_current_event_time (); - - nsCOMPtr<nsIMIMEInfo> mimeInfo; - mLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo)); - NS_ENSURE_TRUE (mimeInfo, NS_ERROR_FAILURE); - -#ifndef HAVE_GECKO_1_9 - char *info = NULL; - - if (mAction == CONTENT_ACTION_OPEN) - { - g_return_val_if_fail (mHelperApp, NS_ERROR_FAILURE); - - const char *id; - id = g_app_info_get_id (mHelperApp); - - /* The current time is fine here as the user has just clicked - * a button (it is used as the time for the application opening) - */ - info = g_strdup_printf ("gnome-default:%d:%s", gtk_get_current_event_time(), id); - } - else if (mAction == CONTENT_ACTION_DOWNLOAD) - { - info = g_strdup_printf ("gnome-browse-to-file:%d", gtk_get_current_event_time()); - } - - if (info != NULL) - { - nsString desc; - NS_CStringToUTF16 (nsCString (info), - NS_CSTRING_ENCODING_UTF8, desc); - g_free (info); - - /* HACK we use the application description to ask - MozDownload to open the file when download - is finished */ - mimeInfo->SetApplicationDescription (desc); - } - else - { - mimeInfo->SetApplicationDescription (nsString ()); - } -#endif /* HAVE_GECKO_1_9 */ - - if (mAction == CONTENT_ACTION_OPEN) - { - mLauncher->SaveToDisk (nsnull, PR_FALSE); - } - else if (mAction == CONTENT_ACTION_OPEN_TMP) - { - mLauncher->LaunchWithApplication (nsnull, PR_FALSE); - } - else if (mAction == CONTENT_ACTION_NONE) - { - mLauncher->Cancel (NS_BINDING_ABORTED); - } - else - { - mLauncher->SaveToDisk (nsnull, PR_FALSE); - } - -#ifdef HAVE_GECKO_1_9 - /* We have to do this work down here because the external helper app modifies the - * value after calling SaveToDisk. - */ - nsHandlerInfoAction action; - if (mAction == CONTENT_ACTION_DOWNLOAD) { - action = EPHY_ACTION_BROWSE_TO_FILE; - - /* This won't be able to transport the activation time so we cannot - * do startup notification, but it's the best that was available - */ - mimeInfo->SetPreferredAction (action); - } -#endif - - return NS_OK; -} diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h deleted file mode 100644 index 366aae482..000000000 --- a/embed/mozilla/ContentHandler.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti, - * Copyright © 2003 Xan Lopez - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef CONTENT_HANDLER_H -#define CONTENT_HANDLER_H - -#include <gio/gio.h> - -#include <nsCOMPtr.h> -#include <nsIFile.h> -#include <nsIHelperAppLauncherDialog.h> -#include <nsIURI.h> - -#include "ephy-file-helpers.h" - - -typedef enum -{ - CONTENT_ACTION_OPEN = 1, - CONTENT_ACTION_OPEN_TMP, - CONTENT_ACTION_DOWNLOAD, - CONTENT_ACTION_SAVEAS, - CONTENT_ACTION_NONE -} ContentAction; - -#define G_CONTENTHANDLER_CID \ -{ /* 16072c4a-23a6-4996-9beb-9335c06bbeae */ \ - 0x16072c4a, \ - 0x23a6, \ - 0x4996, \ - {0x9b, 0xeb, 0x93, 0x35, 0xc0, 0x6b, 0xbe, 0xae} \ -} - -class GContentHandler : public nsIHelperAppLauncherDialog -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIHELPERAPPLAUNCHERDIALOG - - GContentHandler(); - virtual ~GContentHandler(); - - NS_METHOD MIMEDoAction (); - ContentAction mAction; - private: - - NS_METHOD Init (); - - NS_METHOD MIMEInitiateAction (); - NS_METHOD MIMEConfirmAction (); - - nsCOMPtr<nsIHelperAppLauncher> mLauncher; - nsCOMPtr<nsISupports> mContext; - - GAppInfo *mHelperApp; - EphyMimePermission mPermission; - - nsCString mUrl; - nsCString mMimeType; - PRUint32 mUserTime; -}; - -#endif /* CONTENT_HANDLER_H */ diff --git a/embed/mozilla/EphyAboutModule.cpp b/embed/mozilla/EphyAboutModule.cpp deleted file mode 100644 index 8ced9bc9b..000000000 --- a/embed/mozilla/EphyAboutModule.cpp +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Copyright © 2001 Matt Aubury, Philip Langdale - * Copyright © 2004 Crispin Flowerday - * Copyright © 2005 Christian Persch - * Copyright © 2005 Adam Hooper - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <string.h> - -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsStringGlue.h> -#include <nsINetUtil.h> -#else -#define MOZILLA_INTERNAL_API 1 -#include <nsString.h> -#include <nsEscape.h> -#endif - -#include <nsAutoPtr.h> -#include <nsCOMPtr.h> -#include <nsIChannel.h> -#include <nsIInputStreamChannel.h> -#include <nsIInputStream.h> -#include <nsIIOService.h> -#include <nsIOutputStream.h> -#include <nsIScriptSecurityManager.h> -#include <nsStorageStream.h> -#include <nsIURI.h> -#include <nsNetCID.h> -#include <nsNetUtil.h> -#include <nsServiceManagerUtils.h> - -#include "ephy-debug.h" - -#include "EphyRedirectChannel.h" - -#include "EphyAboutModule.h" - -EphyAboutModule::EphyAboutModule() -{ - LOG ("EphyAboutModule ctor [%p]\n", this); -} - -EphyAboutModule::~EphyAboutModule() -{ - LOG ("EphyAboutModule dtor [%p]\n", this); -} - -NS_IMPL_ISUPPORTS1 (EphyAboutModule, nsIAboutModule) - -/* nsIChannel newChannel (in nsIURI aURI); */ -NS_IMETHODIMP -EphyAboutModule::NewChannel(nsIURI *aURI, - nsIChannel **_retval) -{ - NS_ENSURE_ARG(aURI); - - nsCAutoString path; - aURI->GetPath (path); - - if (strncmp (path.get(), "neterror?", strlen ("neterror?")) == 0) - { - return CreateErrorPage (aURI, _retval); - } - - if (strncmp (path.get (), "recover?", strlen ("recover?")) == 0) - { - return CreateRecoverPage (aURI, _retval); - } - - if (strcmp (path.get (), "epiphany") == 0) - { - return Redirect (nsDependentCString ("file://" SHARE_DIR "/epiphany.xhtml"), _retval); - } - - return NS_ERROR_ILLEGAL_VALUE; -} - -#ifdef HAVE_GECKO_1_9 -/* unsigned long getURIFlags(in nsIURI aURI); */ -NS_IMETHODIMP -EphyAboutModule::GetURIFlags (nsIURI *aURI, - PRUint32 *_result) -{ - *_result = 0; - return NS_OK; -} -#endif - -/* private functions */ - -nsresult -EphyAboutModule::Redirect(const nsACString &aURL, - nsIChannel **_retval) -{ - *_retval = nsnull; - - nsresult rv; - nsCOMPtr<nsIURI> uri; - rv = NS_NewURI (getter_AddRefs (uri), aURL); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIChannel> tempChannel; - rv = NS_NewChannel (getter_AddRefs (tempChannel), uri); - NS_ENSURE_SUCCESS (rv, rv); - - tempChannel->SetOriginalURI (uri); - - nsCOMPtr<nsIScriptSecurityManager> securityManager = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIPrincipal> principal; - rv = securityManager->GetCodebasePrincipal(uri, getter_AddRefs(principal)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = tempChannel->SetOwner(principal); - NS_ENSURE_SUCCESS (rv, rv); - - tempChannel.swap (*_retval); - - return NS_OK; -} - -nsresult -EphyAboutModule::ParseURL(const char *aURL, - nsACString &aCode, - nsACString &aRawOriginURL, - nsACString &aOriginURL, - nsACString &aOriginCharset, - nsACString &aTitle) -{ -#ifdef HAVE_GECKO_1_9 - nsCOMPtr<nsINetUtil> netUtil (do_GetService (NS_NETUTIL_CONTRACTID)); - NS_ENSURE_TRUE (netUtil, NS_ERROR_FAILURE); -#endif - - /* The page URL is of the form "about:neterror?e=<errorcode>&u=<URL>&c=<charset>&d=<description>" */ - const char *query = strstr (aURL, "?"); - if (!query) return NS_ERROR_FAILURE; - - /* skip the '?' */ - ++query; - - char **params = g_strsplit (query, "&", -1); - if (!params) return NS_ERROR_FAILURE; - - for (PRUint32 i = 0; params[i] != NULL; ++i) - { - char *param = params[i]; - - if (strlen (param) <= 2) continue; - - switch (param[0]) - { - case 'e': -#ifdef HAVE_GECKO_1_9 - netUtil->UnescapeString (nsDependentCString (param + 2), 0, aCode); -#else - aCode.Assign (nsUnescape (param + 2)); -#endif - break; - case 'u': - aRawOriginURL.Assign (param + 2); -#ifdef HAVE_GECKO_1_9 - netUtil->UnescapeString (nsDependentCString (param + 2), 0, aOriginURL); -#else - aOriginURL.Assign (nsUnescape (param + 2)); -#endif - break; - case 'c': -#ifdef HAVE_GECKO_1_9 - netUtil->UnescapeString (nsDependentCString (param + 2), 0, aOriginCharset); -#else - aOriginCharset.Assign (nsUnescape (param + 2)); -#endif - break; - /* The next one is not used in neterror but recover: */ - case 't': -#ifdef HAVE_GECKO_1_9 - netUtil->UnescapeString (nsDependentCString (param + 2), 0, aTitle); -#else - aTitle.Assign (nsUnescape (param + 2)); -#endif - break; - case 'd': - /* we don't need mozilla's description parameter */ - default: - break; - } - } - - g_strfreev (params); - - return NS_OK; -} - -nsresult -EphyAboutModule::GetErrorMessage(nsIURI *aURI, - const char *aError, - char **aStockIcon, - char **aTitle, - char **aPrimary, - char **aSecondary, - char **aTertiary, - char **aLinkIntro) -{ - nsresult rv = NS_OK; - - *aStockIcon = GTK_STOCK_DIALOG_ERROR; - - if (strcmp (aError, "protocolNotFound") == 0) - { - nsCAutoString scheme; - aURI->GetScheme (scheme); - - /* Translators: %s is the name of a protocol, like "http" etc. */ - *aTitle = g_strdup_printf (_("“%s” Protocol is not Supported"), scheme.get()); - /* Translators: %s is the name of a protocol, like "http" etc. */ - *aPrimary = g_strdup_printf (_("“%s” protocol is not supported."), scheme.get()); - /* FIXME: get the list of supported protocols from necko */ - *aSecondary = g_strdup (_("Supported protocols are “http”, “https”, “ftp”, “file”, “smb” " - "and “sftp”.")); - } - else if (strcmp (aError, "fileNotFound") == 0) - { - nsCAutoString path; - aURI->GetPath (path); - - /* Translators: %s is the path and filename, for example "/home/user/test.html" */ - *aTitle = g_markup_printf_escaped (_("File “%s” not Found"), path.get()); - /* Translators: %s is the path and filename, for example "/home/user/test.html" */ - *aPrimary = g_markup_printf_escaped (_("File “%s” not found."), path.get()); - *aSecondary = g_strdup (_("Check the location of the file and try again.")); - } - else if (strcmp (aError, "dnsNotFound") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped (_("“%s” Could not be Found"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped (_("“%s” could not be found."), - host.get()); - *aSecondary = g_strdup (_("Check that you are connected to the internet, and " - "that the address is correct.")); - *aLinkIntro = _("If this page used to exist, you may find an archived version:"); - } - else if (strcmp (aError, "connectionFailure") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” Refused the Connection"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” refused the connection."), - host.get()); - - /* FIXME what about 127.0.0.* ? */ - if (strcmp (host.get(), "localhost") == 0) - { - PRInt32 port; - aURI->GetPort (&port); - - *aSecondary = g_strdup (_("Likely causes of the problem are")); - - /* Try to get the service name attached to that port */ - if (port != -1) - { - struct servent *serv; - - if ((serv = getservbyport (htons (port), NULL)) != NULL) - { - *aTertiary = g_markup_printf_escaped ( - _("<ul>" - "<li>the service ""%s"" isn't started.</li>" - "Try to start it using the Services Configuration Tool in " - "System > Control Center, or</ul>" - "<ul><li>the port number %d is wrong.</li>" - "</ul>"), - serv->s_name, port); - } - else - { - *aTertiary = g_markup_printf_escaped ( - _("<ul>" - "<li>some service isn't started, or</li>" - "<li>the port number %d is wrong.</li>" - "</ul>"), - port); - } - } - else - { - *aTertiary = _("<ul>" - "<li>some service isn't started, or</li>" - "<li>you got the port number wrong.</li>" - "</ul>"); - } - } - else - { - *aSecondary = g_strdup (_("The server may be busy or you may have a " - "network connection problem. Try again later.")); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - } - else if (strcmp (aError, "netInterrupt") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” Interrupted the Connection"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” interrupted the connection."), - host.get()); - *aSecondary = g_strdup (_("The server may be busy or you may have a " - "network connection problem. Try again later.")); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netTimeout") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” is not Responding"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” is not responding."), - host.get()); - *aSecondary = g_strdup (_("The connection was lost because the " - "server took too long to respond.")); - *aTertiary = _("The server may be busy or you may have a network " - "connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "malformedURI") == 0) - { - *aTitle = g_strdup (_("Invalid Address")); - *aPrimary = g_strdup (_("Invalid address.")); - *aSecondary = g_strdup (_("The address you entered is not valid.")); - } - else if (strcmp (aError, "redirectLoop") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” Redirected Too Many Times"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_strdup (_("This page cannot load because of a problem with the Web site.")); - - *aSecondary = g_markup_printf_escaped - (_("The server “%s” is redirecting in a way that will never complete."), - host.get()); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "unknownSocketType") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” Requires an Encrypted Connection"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” requires an encrypted connection."), - host.get()); - *aSecondary = g_strdup (_("The document could not be loaded because " - "encryption support is not installed.")); - } - else if (strcmp (aError, "netReset") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("“%s” Dropped the Connection"), - host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” dropped the connection."), - host.get()); - *aSecondary = g_strdup (_("The server dropped the connection " - "before any data could be read.")); - *aTertiary = _("The server may be busy or you may have a " - "network connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netOffline") == 0) - { - /* Error is a bit too strong here */ - *aStockIcon = GTK_STOCK_DIALOG_INFO; - - *aTitle = g_strdup (_("Cannot Load Document Whilst Working Offline")); - *aPrimary = g_strdup (_("Cannot load document whilst working offline.")); - *aSecondary = g_strdup (_("To view this document, disable “Work Offline” and try again.")); - } - else if (strcmp (aError, "deniedPortAccess") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - PRInt32 port = -1; - aURI->GetPort (&port); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aTitle = g_markup_printf_escaped - (_("Access Denied to Port “%d” of “%s”"), - port > 0 ? port : 80, host.get()); - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("Access denied to port “%d” of “%s”."), - port > 0 ? port : 80, host.get()); - *aSecondary = g_strdup (_("This address uses a network port which is " - "normally used for purposes other than Web browsing.")); - /* Translators: this means that the request to load the URL has been cancelled */ - *aTertiary = _("The request has been cancelled for your protection."); - } - else if (strcmp (aError, "proxyResolveFailure") == 0 || - strcmp (aError, "proxyConnectFailure") == 0) - { - *aTitle = g_strdup (_("Could not Connect to Proxy Server")); - *aPrimary = g_strdup (_("Could not connect to proxy server.")); - *aSecondary = g_strdup (_("Check your proxy server settings. " - "If the connection still fails, there may be " - "a problem with your proxy server or your " - "network connection.")); - } - /* This was introduced in gecko 1.9 */ - else if (strcmp (aError, "contentEncodingError") == 0) - { - *aTitle = g_strdup (_("Could not Display Content")); - *aPrimary = g_strdup (_("Could not display content.")); - *aSecondary = g_strdup (_("The page uses an unsupported or invalid form of compression.")); - } - else - { - rv = NS_ERROR_ILLEGAL_VALUE; - } - - return rv; -} - -nsresult -EphyAboutModule::CreateErrorPage(nsIURI *aErrorURI, - nsIChannel **_retval) -{ - *_retval = nsnull; - - /* First parse the arguments */ - nsresult rv; - nsCAutoString spec; - rv = aErrorURI->GetSpec (spec); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv), rv); - - nsCAutoString error, rawurl, url, charset, dummy; - rv = ParseURL (spec.get (), error, rawurl, url, charset, dummy); - if (NS_FAILED (rv)) return rv; - if (error.IsEmpty () || rawurl.IsEmpty () || url.IsEmpty()) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIURI> uri; - rv = NS_NewURI (getter_AddRefs (uri), url, charset.get()); - /* FIXME can uri be NULL if the original url was invalid? */ - NS_ENSURE_SUCCESS (rv, rv); - - char *stock_id = nsnull, *title = nsnull, *primary = nsnull, - *secondary = nsnull, *tertiary = nsnull, *linkintro = nsnull; - rv = GetErrorMessage (uri, error.get(), &stock_id, &title, &primary, - &secondary, &tertiary, &linkintro); - - /* we don't know about this error code. - * FIXME: We'd like to forward to mozilla's about:neterror handler, - * but I don't know how to. So just redirect to the same page that - * mozilla's handler redirects to. - */ - if (rv == NS_ERROR_ILLEGAL_VALUE) - { - nsCAutoString newurl(spec); - - /* remove "about:neterror" part and insert mozilla's error page url */ - newurl.Cut(0, strlen ("about:neterror")); - newurl.Insert("chrome://global/content/netError.xhtml", 0); - - return Redirect (newurl, _retval); - } - NS_ENSURE_SUCCESS (rv, rv); - NS_ENSURE_TRUE (primary && secondary, NS_ERROR_FAILURE); - - nsCOMPtr<nsIChannel> channel; - rv = WritePage (aErrorURI, uri, aErrorURI, rawurl, title, stock_id, primary, secondary, tertiary, linkintro, getter_AddRefs (channel)); - NS_ENSURE_SUCCESS (rv, rv); - - g_free (title); - g_free (primary); - g_free (secondary); - - channel.swap (*_retval); - - return NS_OK; -} - -nsresult -EphyAboutModule::CreateRecoverPage(nsIURI *aRecoverURI, - nsIChannel **_retval) -{ - *_retval = nsnull; - - /* First parse the arguments */ - nsresult rv; - nsCAutoString spec; - rv = aRecoverURI->GetSpec (spec); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv), rv); - - nsCAutoString error, rawurl, url, charset, title; - rv = ParseURL (spec.get (), error, rawurl, url, charset, title); - if (NS_FAILED (rv)) return rv; - if (rawurl.IsEmpty () || url.IsEmpty()) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIURI> uri; - rv = NS_NewURI(getter_AddRefs (uri), url, charset.get()); - NS_ENSURE_SUCCESS (rv, rv); - - char *secondary = g_markup_printf_escaped - /* Translators: %s refers to the LSB distributor ID, for instance MandrivaLinux */ - (_("This page was loading when the web browser closed unexpectedly. " - "This might happen again if you reload the page. If it does, please report " - "the problem to the %s developers."), - LSB_DISTRIBUTOR); - - nsCOMPtr<nsIChannel> channel; - rv = WritePage (aRecoverURI, uri, uri, rawurl, title.get(), - GTK_STOCK_DIALOG_INFO, title.get() /* as primary */, - secondary, nsnull, nsnull, getter_AddRefs (channel)); - NS_ENSURE_SUCCESS (rv, rv); - - nsRefPtr<EphyRedirectChannel> redirectChannel (new EphyRedirectChannel (channel)); - if (!redirectChannel) return NS_ERROR_OUT_OF_MEMORY; - - g_free (secondary); - - NS_ADDREF(*_retval = redirectChannel); - - return NS_OK; -} - -nsresult -EphyAboutModule::WritePage(nsIURI *aOriginalURI, - nsIURI *aURI, - nsIURI *aChannelURI, - const nsACString &aRawURL, - const char *aTitle, - const char *aStockIcon, - const char *aPrimary, - const char *aSecondary, - const char *aTertiary, - const char *aLinkIntro, - nsIChannel **_retval) -{ - *_retval = nsnull; - - nsCOMPtr<nsIStorageStream> storageStream (do_CreateInstance(NS_STORAGESTREAM_CONTRACTID)); - NS_ENSURE_TRUE (storageStream, NS_ERROR_OUT_OF_MEMORY); - - nsresult rv; - rv = storageStream->Init (16384, (PRUint32) -1, nsnull); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIOutputStream> stream; - rv = storageStream->GetOutputStream (0, getter_AddRefs (stream)); - NS_ENSURE_SUCCESS (rv, rv); - - char *language = g_strdup (pango_language_to_string (gtk_get_default_language ())); - g_strdelimit (language, "_-@", '\0'); - - Write (stream, - "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" - "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " - "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" - "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\""); - Write (stream, language); - Write (stream, - "\" xml:lang=\""); - Write (stream, language); - Write (stream, - "\">\n" - "<head>\n" - "<title>"); - Write (stream, aTitle); - /* no favicon for now, it would pollute the favicon cache */ - /* "<link rel=\"icon\" type=\"image/png\" href=\"moz-icon://stock/gtk-dialog-error?size=16\" />\n" */ - Write (stream, - "</title>\n" - "<style type=\"text/css\">\n" - "div#body {\n" - "top: 12px;\n" - "right: 12px;\n" - "bottom: 12px;\n" - "left: 12px;\n" - "overflow: auto;\n" - - "background: -moz-dialog url('moz-icon://stock/"); - Write (stream, aStockIcon); - Write (stream, - "?size=dialog') no-repeat 12px 12px;\n" - "color: -moz-dialogtext;\n" - "font: message-box;\n" - "border: 1px solid -moz-dialogtext;\n" - - "padding: 12px 12px 12px 72px;\n" - "}\n" - - "h1 {\n" - "margin: 0;\n" - "font-size: 1.2em;\n" - "}\n" - "</style>\n" - "</head>\n" - "<body dir=\""); - Write (stream, - gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL ? "rtl" : "ltr"); - Write (stream, - "\">\n" - "<div id=\"body\">" - "<h1>"); - Write (stream, aPrimary); - Write (stream, - "</h1>\n"); - if (aSecondary) - { - Write (stream, "<p>"); - Write (stream, aSecondary); - if (aTertiary) - { - Write (stream, " "); - Write (stream, aTertiary); - } - Write (stream, "</p>\n"); - } - - PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; - aURI->SchemeIs ("http", &isHttp); - aURI->SchemeIs ("https", &isHttps); - if (aLinkIntro && (isHttp || isHttps)) - { - nsCString raw(aRawURL); - - Write (stream, "<p>"); - Write (stream, aLinkIntro); - Write (stream, "<ul>\n"); - Write (stream, "<li><a href=\"http://www.google.com/search?q=cache:"); - Write (stream, raw.get()); - Write (stream, "\">"); - /* Translators: The text before the "|" is context to help you decide on - * the correct translation. You MUST OMIT it in the translated string. */ - Write (stream, Q_("You may find an old version:|in the Google Cache")); - Write (stream, "</a></li>\n"); - - Write (stream, "<li><a href=\"http://web.archive.org/web/*/"); - Write (stream, raw.get()); - Write (stream, "\">"); - /* Translators: The text before the "|" is context to help you decide on - * the correct translation. You MUST OMIT it in the translated string. */ - Write (stream, Q_("You may find an old version:|in the Internet Archive")); - Write (stream, "</a></li>\n" - "</ul>\n" - "</p>"); - } - - Write (stream, - "</div>\n" - "</body>\n" - "</html>\n"); - - g_free (language); - - /* finish the rendering */ - nsCOMPtr<nsIInputStream> inputStream; - rv = storageStream->NewInputStream (0, getter_AddRefs (inputStream)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIChannel> channel; - rv = NS_NewInputStreamChannel (getter_AddRefs (channel), - aChannelURI, - inputStream, - NS_LITERAL_CSTRING ("application/xhtml+xml"), - NS_LITERAL_CSTRING ("utf-8")); - NS_ENSURE_SUCCESS (rv, rv); - - rv = channel->SetOriginalURI (aOriginalURI); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIScriptSecurityManager> securityManager - (do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIPrincipal> principal; - rv = securityManager->GetCodebasePrincipal (aOriginalURI, getter_AddRefs (principal)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = channel->SetOwner(principal); - NS_ENSURE_SUCCESS (rv, rv); - - channel.swap (*_retval); - - return NS_OK; -} - -nsresult -EphyAboutModule::Write(nsIOutputStream *aStream, - const char *aText) -{ - PRUint32 bytesWritten; - return aStream->Write (aText, strlen (aText), &bytesWritten); -} diff --git a/embed/mozilla/EphyAboutModule.h b/embed/mozilla/EphyAboutModule.h deleted file mode 100644 index 21a269c49..000000000 --- a/embed/mozilla/EphyAboutModule.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright © 2001 Matt Aubury, Philip Langdale - * Copyright © 2004 Crispin Flowerday - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_ABOUT_MODULE_H -#define EPHY_ABOUT_MODULE_H - -#include <nsIAboutModule.h> - -/* a9aea13e-21de-4be8-a07e-a05f11658c55 */ -#define EPHY_ABOUT_MODULE_CID \ -{ 0xa9aea13e, 0x21de, 0x4be8, \ - { 0xa0, 0x7e, 0xa0, 0x5f, 0x11, 0x65, 0x8c, 0x55 } } - -#define EPHY_ABOUT_NETERROR_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "neterror" -#define EPHY_ABOUT_NETERROR_CLASSNAME "Epiphany about:neterror module" - -#define EPHY_ABOUT_EPIPHANY_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "epiphany" -#define EPHY_ABOUT_EPIPHANY_CLASSNAME "Epiphany about:epiphany module" -#define EPHY_ABOUT_RECOVER_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "recover" -#define EPHY_ABOUT_RECOVER_CLASSNAME "Epiphany about:recover module" - -class nsIChannel; -class nsIOutputStream; -class nsIInputStreamChannel; -class nsIURI; - -class EphyAboutModule : public nsIAboutModule -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIABOUTMODULE - - EphyAboutModule(); - virtual ~EphyAboutModule(); - - private: - nsresult Redirect(const nsACString&, nsIChannel**); - nsresult ParseURL(const char*, nsACString&, nsACString&, nsACString&, nsACString&, nsACString&); - nsresult GetErrorMessage(nsIURI*, const char*, char**, char**, char**, char**, char**, char**); - nsresult CreateErrorPage(nsIURI*, nsIChannel**); - nsresult CreateRecoverPage(nsIURI*, nsIChannel**); - nsresult WritePage(nsIURI*, nsIURI*, nsIURI*, const nsACString&, const char*, const char*, const char*, const char*, const char*, const char*, nsIChannel**); - nsresult Write(nsIOutputStream*, const char*); -}; - -#endif /* EPHY_ABOUT_MODULE_H */ diff --git a/embed/mozilla/EphyBadCertRejector.cpp b/embed/mozilla/EphyBadCertRejector.cpp deleted file mode 100644 index 99ffe4393..000000000 --- a/embed/mozilla/EphyBadCertRejector.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include "EphyBadCertRejector.h" - -NS_IMPL_THREADSAFE_ISUPPORTS1 (EphyBadCertRejector, nsIBadCertListener) - -/* boolean confirmUnknownIssuer (in nsIInterfaceRequestor socketInfo, in nsIX509Cert cert, out short certAddType); */ -NS_IMETHODIMP -EphyBadCertRejector::ConfirmUnknownIssuer(nsIInterfaceRequestor *socketInfo, - nsIX509Cert *cert, - PRInt16 *certAddType, - PRBool *_retval) -{ - *certAddType = nsIBadCertListener::UNINIT_ADD_FLAG; - *_retval = PR_FALSE; - return NS_OK; -} - -/* boolean confirmMismatchDomain (in nsIInterfaceRequestor socketInfo, in AUTF8String targetURL, in nsIX509Cert cert); */ -NS_IMETHODIMP -EphyBadCertRejector::ConfirmMismatchDomain(nsIInterfaceRequestor *socketInfo, - const nsACString & targetURL, - nsIX509Cert *cert, - PRBool *_retval) -{ - *_retval = PR_FALSE; - return NS_OK; -} - -/* boolean confirmCertExpired (in nsIInterfaceRequestor socketInfo, in nsIX509Cert cert); */ -NS_IMETHODIMP -EphyBadCertRejector::ConfirmCertExpired(nsIInterfaceRequestor *socketInfo, - nsIX509Cert *cert, - PRBool *_retval) -{ - *_retval = PR_FALSE; - return NS_OK; -} - -/* void notifyCrlNextupdate (in nsIInterfaceRequestor socketInfo, in AUTF8String targetURL, in nsIX509Cert cert); */ -NS_IMETHODIMP -EphyBadCertRejector::NotifyCrlNextupdate(nsIInterfaceRequestor *socketInfo, - const nsACString & targetURL, - nsIX509Cert *cert) -{ - return NS_OK; -} diff --git a/embed/mozilla/EphyBadCertRejector.h b/embed/mozilla/EphyBadCertRejector.h deleted file mode 100644 index dcab75c6c..000000000 --- a/embed/mozilla/EphyBadCertRejector.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_BAD_CERT_REJECTOR_H -#define EPHY_BAD_CERT_REJECTOR_H - -#include <nsIBadCertListener.h> - -class EphyBadCertRejector : public nsIBadCertListener -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIBADCERTLISTENER - - EphyBadCertRejector () { } - ~EphyBadCertRejector () { } -}; - -#endif diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp deleted file mode 100644 index 7963d5e7b..000000000 --- a/embed/mozilla/EphyBrowser.cpp +++ /dev/null @@ -1,1900 +0,0 @@ -/* - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003, 2004, 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <string.h> -#include <unistd.h> - -#include <nsStringAPI.h> - -#include <gtkmozembed.h> -#include <gtkmozembed_internal.h> -#include <nsIChannel.h> -#include <nsICommandManager.h> -#include <nsIContentViewer.h> -#include <nsIDocCharset.h> -#include <nsIDocShellTreeItem.h> -#include <nsIDocShellTreeNode.h> -#include <nsIDocShellTreeOwner.h> -#include <nsIDOM3Document.h> -#include <nsIDOMAbstractView.h> -#include <nsIDOMAbstractView.h> -#include <nsIDOMCSSPrimitiveValue.h> -#include <nsIDOMCSSStyleDeclaration.h> -#include <nsIDOMCSSStyleDeclaration.h> -#include <nsIDOMCSSValue.h> -#include <nsIDOMDocument.h> -#include <nsIDOMDocumentView.h> -#include <nsIDOMDocumentView.h> -#include <nsIDOMElement.h> -#include <nsIDOMEvent.h> -#include <nsIDOMEventTarget.h> -#include <nsIDOMHTMLCollection.h> -#include <nsIDOMHTMLDocument.h> -#include <nsIDOMHTMLDocument.h> -#include <nsIDOMHTMLElement.h> -#include <nsIDOMHTMLFormElement.h> -#include <nsIDOMHTMLInputElement.h> -#include <nsIDOMHTMLTextAreaElement.h> -#include <nsIDOMKeyEvent.h> -#include <nsIDOMMouseEvent.h> -#include <nsIDOMNode.h> -#include <nsIDOMNSEvent.h> -#include <nsIDOMNSEventTarget.h> -#include <nsIDOMPopupBlockedEvent.h> -#include <nsIDOMViewCSS.h> -#include <nsIDOMWindow2.h> -#include <nsIDOMXMLDocument.h> -#include <nsIDOMLocation.h> -#include <nsIDOMNSLocation.h> -#include <nsIHistoryEntry.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIPrintSettings.h> -#include <nsIPrintSettingsService.h> -#include <nsIScriptSecurityManager.h> -#include <nsIServiceManager.h> -#include <nsISHEntry.h> -#include <nsISHistory.h> -#include <nsISHistoryInternal.h> -#include <nsISimpleEnumerator.h> -#include <nsIURI.h> -#include <nsIWebBrowserFocus.h> -#include <nsIWebBrowserPrint.h> -#include <nsIWebPageDescriptor.h> -#include <nsMemory.h> -#include <nsServiceManagerUtils.h> - -#ifdef HAVE_MOZILLA_PSM -#include <nsICertificateDialogs.h> -#include <nsISSLStatus.h> -#include <nsISSLStatusProvider.h> -#include <nsITransportSecurityInfo.h> -#include <nsIX509Cert.h> -#endif - -#ifdef ALLOW_PRIVATE_API -#include <nsIContentPolicy.h> -#include <nsIDocShell.h> -#include <nsIDOMWindowInternal.h> -#include <nsIImageDocument.h> -#include <nsIMarkupDocumentViewer.h> -#endif - -#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 "AutoJSContextStack.h" -#include "EphyUtils.h" -#include "EventContext.h" -#include "GeckoPrintService.h" - -#ifdef HAVE_GECKO_1_9 -#include <ephyIAddCertExceptionParams.h> -#include <nsAutoPtr.h> -#include <nsComponentManagerUtils.h> -#include <nsIArray.h> -#include <nsIClassInfo.h> -#include <nsIDialogParamBlock.h> -#include <nsIMutableArray.h> -#include <nsIProgrammingLanguage.h> -#include <nsISupportsArray.h> -#include <nsIWindowWatcher.h> -#endif - -#include "EphyBrowser.h" - - -#ifdef HAVE_GECKO_1_9 - -class EphyAddCertExceptionParams : public ephyIAddCertExceptionParams, - public nsIDialogParamBlock, - public nsIClassInfo - -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_EPHYIADDCERTEXCEPTIONPARAMS - NS_FORWARD_SAFE_NSIDIALOGPARAMBLOCK (mParamBlock) - NS_DECL_NSICLASSINFO - - EphyAddCertExceptionParams (const nsAString& aLocation, PRBool aPrefetch = PR_TRUE) - : mParamBlock (do_CreateInstance (NS_DIALOGPARAMBLOCK_CONTRACTID)), - mLocation (aLocation), - mPrefetch (aPrefetch), - mExceptionAdded (PR_FALSE) { g_print ("%s\n", G_STRFUNC); } - - private: - ~EphyAddCertExceptionParams () { g_print ("%s\n", G_STRFUNC); } - - nsCOMPtr<nsIDialogParamBlock> mParamBlock; - nsString mLocation; - PRBool mPrefetch; - PRBool mExceptionAdded; -}; - -NS_IMPL_ISUPPORTS3 (EphyAddCertExceptionParams, ephyIAddCertExceptionParams, nsIDialogParamBlock, nsIClassInfo) - -/* nsISupports getHelperForLanguage (in PRUint32 language); */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetHelperForLanguage(PRUint32 language, nsISupports **_retval) -{ - g_print ("%s\n", G_STRFUNC); - *_retval = nsnull; - return NS_OK; -} - -/* readonly attribute string contractID; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetContractID(char * *aContractID) -{ - g_print ("%s\n", G_STRFUNC); - *aContractID = nsnull; - return NS_OK; -} - -/* readonly attribute string classDescription; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetClassDescription(char * *aClassDescription) -{ - g_print ("%s\n", G_STRFUNC); - *aClassDescription = nsnull; - return NS_OK; -} - -/* readonly attribute nsCIDPtr classID; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetClassID(nsCID * *aClassID) -{ - g_print ("%s\n", G_STRFUNC); - return NS_ERROR_FAILURE; -} - -/* readonly attribute PRUint32 implementationLanguage; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetImplementationLanguage(PRUint32 *aImplementationLanguage) -{ - g_print ("%s\n", G_STRFUNC); - *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS; - return NS_OK; -} - -/* readonly attribute PRUint32 flags; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetFlags(PRUint32 *aFlags) -{ - g_print ("%s\n", G_STRFUNC); - *aFlags = 0; - return NS_OK; -} - -/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) -{ - g_print ("%s\n", G_STRFUNC); - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP EphyAddCertExceptionParams::GetInterfaces (PRUint32 *count, nsIID * **array) -{ - g_print ("%s\n", G_STRFUNC); - nsIID **iids = static_cast<nsIID**>(NS_Alloc (1 * sizeof (nsIID*))); - if (!iids) - return NS_ERROR_OUT_OF_MEMORY; - - iids[0] = static_cast<nsIID*>(NS_Alloc (sizeof (nsIID))); - if (!iids[0]) - return NS_ERROR_OUT_OF_MEMORY; - memcpy (iids[0], &NS_GET_IID (ephyIAddCertExceptionParams), sizeof (nsIID)); - - *count = 1; - *array = iids; - - g_print ("DONE %s\n", G_STRFUNC); - return NS_OK; -} - -/* readonly attribute boolean prefetchCert; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetPrefetchCert(PRBool *aPrefetchCert) -{ - g_print ("%s\n", G_STRFUNC); - *aPrefetchCert = mPrefetch; - return NS_OK; -} - -/* readonly attribute AString location; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetLocation(nsAString & aLocation) -{ - g_print ("%s\n", G_STRFUNC); - g_print ("mLocation=%s\n", NS_ConvertUTF16toUTF8(mLocation).get()); - aLocation.Assign (mLocation); - return NS_OK; -} - -/* attribute boolean exceptionAdded; */ -NS_IMETHODIMP EphyAddCertExceptionParams::GetExceptionAdded(PRBool *aExceptionAdded) -{ - g_print ("%s\n", G_STRFUNC); - *aExceptionAdded = mExceptionAdded; - return NS_OK; -} - -NS_IMETHODIMP EphyAddCertExceptionParams::SetExceptionAdded(PRBool aExceptionAdded) -{ - g_print ("%s\n", G_STRFUNC); - mExceptionAdded = aExceptionAdded; - return NS_OK; -} - -#endif /* HAVE_GECKO_1_9 */ - - -NS_IMPL_ISUPPORTS1(EphyEventListener, nsIDOMEventListener) - -NS_IMETHODIMP -EphyDOMLinkEventListener::HandleEvent (nsIDOMEvent* aDOMEvent) -{ - nsCOMPtr<nsIDOMEventTarget> eventTarget; - aDOMEvent->GetTarget(getter_AddRefs(eventTarget)); - - nsCOMPtr<nsIDOMElement> linkElement (do_QueryInterface (eventTarget)); - if (!linkElement) return NS_ERROR_FAILURE; - - nsresult rv; - nsString value; - rv = linkElement->GetAttribute (NS_LITERAL_STRING ("rel"), value); - if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - - nsCString rel; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, rel); - - if (g_ascii_strcasecmp (rel.get(), "SHORTCUT ICON") == 0 || - g_ascii_strcasecmp (rel.get(), "ICON") == 0) - { - nsCOMPtr<nsIDOMDocument> domDoc; - linkElement->GetOwnerDocument(getter_AddRefs(domDoc)); - NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (domDoc)); - NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMAbstractView> abstractView; - docView->GetDefaultView (getter_AddRefs (abstractView)); - - nsCOMPtr<nsIDOMWindow> domWin (do_QueryInterface (abstractView)); - NS_ENSURE_TRUE (domWin, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMWindow> topDomWin; - domWin->GetTop (getter_AddRefs (topDomWin)); - - nsCOMPtr<nsISupports> domWinAsISupports (do_QueryInterface (domWin)); - nsCOMPtr<nsISupports> topDomWinAsISupports (do_QueryInterface (topDomWin)); - /* disallow subframes to set favicon */ - if (domWinAsISupports != topDomWinAsISupports) return NS_OK; - - nsCOMPtr<nsIURI> docUri; - rv = GetDocURI (linkElement, getter_AddRefs (docUri)); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && docUri, NS_ERROR_FAILURE); - - rv = linkElement->GetAttribute (NS_LITERAL_STRING ("href"), value); - if (NS_FAILED (rv) || !value.Length()) return NS_ERROR_FAILURE; - - nsCString cLink; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cLink); - - nsCString faviconUrl; - rv = docUri->Resolve (cLink, faviconUrl); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - nsCOMPtr<nsIURI> favUri; - EphyUtils::NewURI (getter_AddRefs (favUri), faviconUrl); - NS_ENSURE_TRUE (favUri, NS_ERROR_FAILURE); - - /* Only proceed for http favicons. Bug #312291 */ - PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; - favUri->SchemeIs ("http", &isHttp); - favUri->SchemeIs ("https", &isHttps); - if (!isHttp && !isHttps) return NS_OK; - - /* check if load is allowed */ - nsCOMPtr<nsIScriptSecurityManager> secMan - (do_GetService("@mozilla.org/scriptsecuritymanager;1")); - /* refuse if we can't check */ - NS_ENSURE_TRUE (secMan, NS_OK); - - rv = secMan->CheckLoadURI(docUri, favUri, - nsIScriptSecurityManager::STANDARD); - /* failure means it didn't pass the security check */ - if (NS_FAILED (rv)) return NS_OK; - - /* security check passed, now check with content policy */ - nsCOMPtr<nsIContentPolicy> policy = - do_GetService("@mozilla.org/layout/content-policy;1"); - /* refuse if we can't check */ - NS_ENSURE_TRUE (policy, NS_OK); - - linkElement->GetAttribute (NS_LITERAL_STRING ("type"), value); - - nsCString cTypeVal; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cTypeVal); - - PRInt16 decision = 0; - rv = policy->ShouldLoad (nsIContentPolicy::TYPE_IMAGE, - favUri, docUri, eventTarget, - cTypeVal, nsnull, - &decision); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - if (decision != nsIContentPolicy::ACCEPT) return NS_OK; - - /* Hide password part */ - nsCString user; - favUri->GetUsername (user); - favUri->SetUserPass (user); - - nsCString spec; - favUri->GetSpec (spec); - - /* ok, we accept this as a valid favicon for this site */ - g_signal_emit_by_name (mOwner->mEmbed, "ge_favicon", spec.get()); - } - else if (g_ascii_strcasecmp (rel.get (), "search") == 0) - { - linkElement->GetAttribute (NS_LITERAL_STRING ("type"), value); - - nsCString cTypeVal; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cTypeVal); - - if (g_ascii_strcasecmp (cTypeVal.get (), - "application/opensearchdescription+xml") == 0) - { - rv = linkElement->GetAttribute (NS_LITERAL_STRING ("href"), value); - if (NS_FAILED (rv) || !value.Length()) return NS_ERROR_FAILURE; - - nsCString cLink; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cLink); - - nsCOMPtr<nsIURI> docUri; - rv = GetDocURI (linkElement, getter_AddRefs (docUri)); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && docUri, NS_ERROR_FAILURE); - - nsCString resolvedLink; - rv = docUri->Resolve (cLink, resolvedLink); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - linkElement->GetAttribute (NS_LITERAL_STRING ("title"), value); - - nsCString cTitle; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cTitle); - - g_signal_emit_by_name (mOwner->mEmbed, "ge_search_link", - cTypeVal.get(), cTitle.get(), resolvedLink.get()); - } - } - else if (g_ascii_strcasecmp (rel.get (), "alternate") == 0) - { - linkElement->GetAttribute (NS_LITERAL_STRING ("type"), value); - - nsCString cTypeVal; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cTypeVal); - - if (g_ascii_strcasecmp (cTypeVal.get (), "application/rss+xml") == 0 || - g_ascii_strcasecmp (cTypeVal.get (), "application/atom+xml") == 0) - { - rv = linkElement->GetAttribute (NS_LITERAL_STRING ("href"), value); - if (NS_FAILED (rv) || !value.Length()) return NS_ERROR_FAILURE; - - nsCString cLink; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cLink); - - nsCOMPtr<nsIURI> docUri; - rv = GetDocURI (linkElement, getter_AddRefs (docUri)); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && docUri, NS_ERROR_FAILURE); - - /* Hide password part */ - nsCString user; - docUri->GetUsername (user); - docUri->SetUserPass (user); - - nsCString resolvedLink; - rv = docUri->Resolve (cLink, resolvedLink); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - linkElement->GetAttribute (NS_LITERAL_STRING ("title"), value); - - nsCString cTitle; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cTitle); - - g_signal_emit_by_name (mOwner->mEmbed, "ge_feed_link", - cTypeVal.get(), cTitle.get(), resolvedLink.get()); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -EphyMiscDOMEventsListener::HandleEvent (nsIDOMEvent* aDOMEvent) -{ - /* make sure the event is trusted */ - nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aDOMEvent)); - NS_ENSURE_TRUE (nsEvent, NS_ERROR_FAILURE); - PRBool isTrusted = PR_FALSE; - nsEvent->GetIsTrusted (&isTrusted); - if (!isTrusted) return NS_OK; - - nsresult rv; - nsString type; - rv = aDOMEvent->GetType (type); - NS_ENSURE_SUCCESS (rv, rv); - - nsCString cType; - NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType); - - if (g_ascii_strcasecmp (cType.get(), "DOMContentLoaded") == 0) - { - g_signal_emit_by_name (mOwner->mEmbed, "dom_content_loaded", - (gpointer)aDOMEvent); - } - else if (g_ascii_strcasecmp (cType.get(), "DOMWindowClose") == 0) - { - gboolean prevent = FALSE; - - g_signal_emit_by_name (mOwner->mEmbed, "close-request", &prevent); - - if (prevent) - { - aDOMEvent->PreventDefault (); - } - } - - return NS_OK; -} - -nsresult -EphyDOMLinkEventListener::GetDocURI (nsIDOMElement *aElement, - nsIURI **aDocURI) -{ - nsCOMPtr<nsIDOMDocument> domDoc; - aElement->GetOwnerDocument (getter_AddRefs(domDoc)); - - nsCOMPtr<nsIDOM3Document> doc (do_QueryInterface (domDoc)); - NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); - - nsresult rv; - nsString spec; - rv = doc->GetDocumentURI (spec); - NS_ENSURE_SUCCESS (rv, rv); - - nsCString encoding; - rv = mOwner->GetEncoding (encoding); - NS_ENSURE_SUCCESS (rv, rv); - - return EphyUtils::NewURI (aDocURI, spec, encoding.get()); -} - -NS_IMETHODIMP -EphyPopupBlockEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) -{ - nsCOMPtr<nsIDOMPopupBlockedEvent> popupEvent = - do_QueryInterface (aDOMEvent); - NS_ENSURE_TRUE (popupEvent, NS_ERROR_FAILURE); - - nsCOMPtr<nsIURI> popupWindowURI; - popupEvent->GetPopupWindowURI (getter_AddRefs (popupWindowURI)); - - nsCString popupWindowURIString; - nsresult rv; - - if (popupWindowURI) - { - rv = popupWindowURI->GetSpec (popupWindowURIString); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - } - - nsString popupWindowFeatures; - rv = popupEvent->GetPopupWindowFeatures (popupWindowFeatures); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - nsCString popupWindowFeaturesString; - NS_UTF16ToCString (popupWindowFeatures, - NS_CSTRING_ENCODING_UTF8, - popupWindowFeaturesString); - - nsCString popupWindowNameString; -#ifdef HAVE_GECKO_1_9 - nsString popupWindowName; - rv = popupEvent->GetPopupWindowName (popupWindowName); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - NS_UTF16ToCString (popupWindowName, - NS_CSTRING_ENCODING_UTF8, - popupWindowNameString); -#endif - - g_signal_emit_by_name(mOwner->mEmbed, "ge-popup-blocked", - popupWindowURI == NULL ? NULL : popupWindowURIString.get(), - popupWindowNameString.get(), - popupWindowFeaturesString.get()); - - return NS_OK; -} - -NS_IMETHODIMP -EphyModalAlertEventListener::HandleEvent (nsIDOMEvent * aDOMEvent) -{ - NS_ENSURE_TRUE (mOwner, NS_ERROR_FAILURE); - - nsresult rv; - nsString type; - rv = aDOMEvent->GetType (type); - NS_ENSURE_SUCCESS (rv, rv); - - nsCString cType; - NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType); - - LOG ("ModalAlertListener event %s", cType.get()); - - if (strcmp (cType.get(), "DOMWillOpenModalDialog") == 0) - { - gboolean retval = FALSE; - g_signal_emit_by_name (mOwner->mEmbed, "ge-modal-alert", &retval); - - /* suppress alert */ - if (retval) - { - aDOMEvent->PreventDefault (); - aDOMEvent->StopPropagation(); - } - } - else if (strcmp (cType.get(), "DOMModalDialogClosed") == 0) - { - g_signal_emit_by_name (mOwner->mEmbed, "ge-modal-alert-closed"); - } - - return NS_OK; -} - -NS_IMETHODIMP -EphyDOMScrollEventListener::HandleEvent (nsIDOMEvent * aEvent) -{ - nsresult rv; - nsCOMPtr<nsIDOMMouseEvent> mouseEvent (do_QueryInterface (aEvent, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - PRBool isAlt = PR_FALSE, isControl = PR_FALSE, isShift = PR_FALSE; - mouseEvent->GetAltKey (&isAlt); - mouseEvent->GetCtrlKey (&isControl); - mouseEvent->GetShiftKey (&isShift); - /* GetMetaKey is always false on gtk2 mozilla */ - - if (isControl && !isAlt && !isShift) - { - PRInt32 detail = 0; - mouseEvent->GetDetail(&detail); - - float zoom; - rv = mOwner->GetZoom (&zoom); - NS_ENSURE_SUCCESS (rv, rv); - - zoom = ephy_zoom_get_changed_zoom_level (zoom, detail > 0 ? 1 : detail < 0 ? -1 : 0); - rv = mOwner->SetZoom (zoom); - if (NS_SUCCEEDED (rv)) - { - g_signal_emit_by_name (mOwner->mEmbed, "ge_zoom_change", zoom); - } - - /* we consumed the event */ - aEvent->PreventDefault(); - } - - return NS_OK; -} - -#ifdef HAVE_GECKO_1_9 - -NS_IMETHODIMP -EphyCommandEventListener::HandleEvent (nsIDOMEvent *aDOMEvent) -{ - /* make sure the event is trusted */ - nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aDOMEvent)); - NS_ENSURE_TRUE (nsEvent, NS_ERROR_FAILURE); - PRBool isTrusted = PR_FALSE; - nsEvent->GetIsTrusted (&isTrusted); - if (!isTrusted) return NS_OK; - - nsresult rv; - nsCOMPtr<nsIDOMEventTarget> originalTarget; - rv = nsEvent->GetOriginalTarget (getter_AddRefs (originalTarget)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIDOMNode> node (do_QueryInterface (originalTarget)); - if (!node) - return NS_OK; - - nsCOMPtr<nsIDOMDocument> document; - rv = node->GetOwnerDocument (getter_AddRefs (document)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIDOM3Document> doc3 (do_QueryInterface (document)); - NS_ENSURE_TRUE (doc3, NS_ERROR_FAILURE); - - nsString documentURI; - rv = doc3->GetDocumentURI (documentURI); - NS_ENSURE_SUCCESS (rv, rv); - - if (!g_str_has_prefix (NS_ConvertUTF16toUTF8 (documentURI).get(), - "about:neterror?e=nssBadCert&")) - return NS_OK; - - nsCOMPtr<nsIDOMElement> docElement (do_QueryInterface (document)); - - nsCOMPtr<nsIDOMElement> buttonElement; - rv = document->GetElementById (NS_LITERAL_STRING("exceptionDialogButton"), - getter_AddRefs (buttonElement)); - if (NS_FAILED (rv) || !buttonElement) - return NS_OK; - - nsCOMPtr<nsIDOMNode> buttonNode (do_QueryInterface (buttonElement)); - NS_ENSURE_TRUE (buttonNode, NS_OK); - - g_print ("here1\n"); - /* Event was for this button? */ - if (!SameCOMIdentity (node, buttonNode)) - return NS_OK; - g_print ("here2\n"); - - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (document)); - NS_ENSURE_TRUE (docView, NS_OK); - - nsCOMPtr<nsIDOMAbstractView> view; - rv = docView->GetDefaultView (getter_AddRefs (view)); - NS_ENSURE_SUCCESS (rv, NS_OK); - - nsCOMPtr<nsIDOMWindow> window (do_QueryInterface (view)); - NS_ENSURE_TRUE (window, NS_OK); - - nsCOMPtr<nsIDOMWindowInternal> windowInternal (do_QueryInterface (window)); - NS_ENSURE_TRUE (windowInternal, NS_OK); - - nsCOMPtr<nsIDOMLocation> domLocation; - rv = windowInternal->GetLocation (getter_AddRefs (domLocation)); - if (NS_FAILED (rv)) - return NS_OK; - - nsCOMPtr<nsIDOMNSLocation> domNSLocation (do_QueryInterface (domLocation)); - NS_ENSURE_TRUE (domNSLocation, NS_OK); - - nsString locationHref; - domLocation->GetHref (locationHref); - - nsRefPtr<EphyAddCertExceptionParams> params (new EphyAddCertExceptionParams (locationHref, PR_TRUE)); - if (!params) - return NS_ERROR_OUT_OF_MEMORY; - - nsCOMPtr<nsIWindowWatcher> ww (do_GetService (NS_WINDOWWATCHER_CONTRACTID)); - if (!ww) - return NS_ERROR_FAILURE; - - { - AutoJSContextStack stack; - if (NS_FAILED (stack.Init ())) - return NS_OK; - - nsISupports *arguments = static_cast<nsISupports*>(static_cast<ephyIAddCertExceptionParams*>(params)); - nsCOMPtr<nsIDOMWindow> dialog; - rv = ww->OpenWindow (window, - "chrome://pippki/content/exceptionDialog.xul", - "_blank", - "chrome,centerscreen,modal", - arguments, - getter_AddRefs (dialog)); - g_print ("done openwindow %x\n", rv); - if (NS_FAILED (rv)) - return rv; - } - - PRBool exceptionAdded; - params->GetExceptionAdded (&exceptionAdded); - g_print ("exceptionAdded %d\n", exceptionAdded); - if (exceptionAdded) - return domNSLocation->Reload (); - - - return NS_OK; -} - -#endif /* HAVE_GECKO_1_9 */ - -NS_IMPL_ISUPPORTS1(EphyContextMenuListener, nsIDOMContextMenuListener) - -NS_IMETHODIMP -EphyContextMenuListener::ContextMenu (nsIDOMEvent* aDOMEvent) -{ - nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aDOMEvent); - NS_ENSURE_TRUE (mouseEvent, NS_ERROR_FAILURE); - - MozillaEmbedEvent *info; - info = mozilla_embed_event_new (static_cast<gpointer>(aDOMEvent)); - - nsresult rv; - EventContext context; - context.Init (mOwner); - rv = context.GetMouseEventInfo (mouseEvent, MOZILLA_EMBED_EVENT (info)); - - /* Don't do any magic handling if we can't actually show the context - * menu, this can happen for XUL pages (e.g. about:config) - */ - if (NS_FAILED (rv)) - { - g_object_unref (info); - return NS_OK; - } - - if (info->button == 0) - { - /* Translate relative coordinates to absolute values, and try - * to avoid covering links by adding a little offset - */ - int x, y; - gdk_window_get_origin (GTK_WIDGET (mOwner->mEmbed)->window, &x, &y); - info->x += x + 6; - info->y += y + 6; - - // Set the keycode to something sensible - info->keycode = nsIDOMKeyEvent::DOM_VK_CONTEXT_MENU; - } - - if (info->modifier == GDK_CONTROL_MASK) - { - info->context = EPHY_EMBED_CONTEXT_DOCUMENT; - } - - gboolean retval = FALSE; - nsCOMPtr<nsIDOMDocument> domDoc; - rv = context.GetTargetDocument (getter_AddRefs(domDoc)); - if (NS_SUCCEEDED(rv)) - { - mOwner->PushTargetDocument (domDoc); - - g_signal_emit_by_name (mOwner->mEmbed, "ge_context_menu", - info, &retval); - - mOwner->PopTargetDocument (); - } - - /* We handled the event, block javascript calls */ - if (retval) - { - aDOMEvent->PreventDefault(); - aDOMEvent->StopPropagation(); - } - - g_object_unref (info); - - return NS_OK; -} - -NS_IMETHODIMP -EphyContextMenuListener::HandleEvent (nsIDOMEvent* aDOMEvent) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -EphyBrowser::EphyBrowser () -: mDOMLinkEventListener(nsnull) -, mMiscDOMEventsListener(nsnull) -, mDOMScrollEventListener(nsnull) -, mPopupBlockEventListener(nsnull) -, mModalAlertListener(nsnull) -#ifdef HAVE_GECKO_1_9 -, mCommandEventListener(nsnull) -#endif -, mContextMenuListener(nsnull) -, mInitialized(PR_FALSE) -{ - LOG ("EphyBrowser ctor (%p)", this); -} - -EphyBrowser::~EphyBrowser () -{ - LOG ("EphyBrowser dtor (%p)", this); -} - -nsresult EphyBrowser::Init (EphyEmbed *embed) -{ - if (mInitialized) return NS_OK; - - mEmbed = GTK_WIDGET (embed); - - gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED (gtk_bin_get_child (GTK_BIN (embed))), - getter_AddRefs(mWebBrowser)); - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - mWebBrowserFocus = do_QueryInterface (mWebBrowser); - NS_ENSURE_TRUE (mWebBrowserFocus, NS_ERROR_FAILURE); - - mWebBrowser->GetContentDOMWindow (getter_AddRefs (mDOMWindow)); - NS_ENSURE_TRUE (mDOMWindow, NS_ERROR_FAILURE); - - /* This will instantiate an about:blank doc if necessary */ - nsresult rv; - nsCOMPtr<nsIDOMDocument> domDocument; - rv = mDOMWindow->GetDocument (getter_AddRefs (domDocument)); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - mDOMLinkEventListener = new EphyDOMLinkEventListener(this); - if (!mDOMLinkEventListener) return NS_ERROR_OUT_OF_MEMORY; - - mMiscDOMEventsListener = new EphyMiscDOMEventsListener(this); - if (!mMiscDOMEventsListener) return NS_ERROR_OUT_OF_MEMORY; - - mDOMScrollEventListener = new EphyDOMScrollEventListener(this); - if (!mDOMScrollEventListener) return NS_ERROR_OUT_OF_MEMORY; - - mPopupBlockEventListener = new EphyPopupBlockEventListener(this); - if (!mPopupBlockEventListener) return NS_ERROR_OUT_OF_MEMORY; - - mModalAlertListener = new EphyModalAlertEventListener (this); - if (!mModalAlertListener) return NS_ERROR_OUT_OF_MEMORY; - -#ifdef HAVE_GECKO_1_9 - mCommandEventListener = new EphyCommandEventListener(this); - if (!mCommandEventListener) return NS_ERROR_OUT_OF_MEMORY; -#endif - - mContextMenuListener = new EphyContextMenuListener(this); - if (!mContextMenuListener) return NS_ERROR_OUT_OF_MEMORY; - - rv = GetListener(); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - rv = AttachListeners(); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - -#ifdef HAVE_MOZILLA_PSM - nsCOMPtr<nsIDocShell> docShell (do_GetInterface (mWebBrowser, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = docShell->GetSecurityUI (getter_AddRefs (mSecurityInfo)); - if (!mSecurityInfo) - { - g_warning ("Failed to get nsISecureBrowserUI!\n"); - } - NS_ENSURE_SUCCESS (rv, rv); -#endif /* HAVE_MOZILLA_PSM */ - - mInitialized = PR_TRUE; - - return NS_OK; -} - -nsresult -EphyBrowser::GetListener (void) -{ - if (mEventTarget) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMWindow> domWindowExternal; - mWebBrowser->GetContentDOMWindow (getter_AddRefs(domWindowExternal)); - - nsCOMPtr<nsIDOMWindow2> domWindow (do_QueryInterface (domWindowExternal)); - NS_ENSURE_TRUE (domWindow, NS_ERROR_FAILURE); - - domWindow->GetWindowRoot (getter_AddRefs(mEventTarget)); - NS_ENSURE_TRUE (mEventTarget, NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult -EphyBrowser::AttachListeners(void) -{ - NS_ENSURE_TRUE (mEventTarget, NS_ERROR_FAILURE); - - nsresult rv; - nsCOMPtr<nsIDOMNSEventTarget> target (do_QueryInterface (mEventTarget, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = target->AddEventListener(NS_LITERAL_STRING ("DOMLinkAdded"), - mDOMLinkEventListener, PR_FALSE, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMContentLoaded"), - mMiscDOMEventsListener, PR_FALSE, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMWindowClose"), - mMiscDOMEventsListener, PR_FALSE, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMMouseScroll"), - mDOMScrollEventListener, PR_TRUE /* capture */, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMPopupBlocked"), - mPopupBlockEventListener, PR_FALSE, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMWillOpenModalDialog"), - mModalAlertListener, PR_TRUE, PR_FALSE); - rv |= target->AddEventListener(NS_LITERAL_STRING ("DOMModalDialogClosed"), - mModalAlertListener, PR_TRUE, PR_FALSE); -#ifdef HAVE_GECKO_1_9 - rv |= target->AddEventListener(NS_LITERAL_STRING ("command"), - mCommandEventListener, PR_FALSE, PR_FALSE); -#endif - rv |= target->AddEventListener(NS_LITERAL_STRING ("contextmenu"), - mContextMenuListener, PR_TRUE /* capture */, PR_FALSE); - NS_ENSURE_SUCCESS (rv, rv); - - return NS_OK; -} - -nsresult -EphyBrowser::DetachListeners(void) -{ - if (!mEventTarget) return NS_OK; - - nsresult rv; - rv = mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMLinkAdded"), - mDOMLinkEventListener, PR_FALSE); - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMContentLoaded"), - mMiscDOMEventsListener, PR_FALSE); - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMWindowClose"), - mMiscDOMEventsListener, PR_FALSE); - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMMouseScroll"), - mDOMScrollEventListener, PR_TRUE); /* capture */ - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMPopupBlocked"), - mPopupBlockEventListener, PR_FALSE); - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMWillOpenModalDialog"), - mModalAlertListener, PR_TRUE); - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("DOMModalDialogClosed"), - mModalAlertListener, PR_TRUE); -#ifdef HAVE_GECKO_1_9 - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("command"), - mCommandEventListener, PR_FALSE); -#endif - rv |= mEventTarget->RemoveEventListener(NS_LITERAL_STRING ("contextmenu"), - mContextMenuListener, PR_TRUE /* capture */); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult EphyBrowser::Print () -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); - NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - - 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) -{ - nsresult rv; - - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebBrowserPrint> print (do_GetInterface (mWebBrowser)); - NS_ENSURE_STATE (print); - - if (previewMode) - { - 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); - - EphyEmbedShell *shell = ephy_embed_shell_get_default (); - rv = GeckoPrintService::TranslateSettings (ephy_embed_shell_get_print_settings (shell), - ephy_embed_shell_get_page_setup (shell), - NULL, - nsCString(), - nsIPrintSettings::kFramesAsIs, - PR_FALSE, - settings); - - if (NS_SUCCEEDED (rv)) - { - rv = print->PrintPreview (settings, mDOMWindow, nsnull); - } - } - else - { - PRBool isPreview = PR_FALSE; - - rv = print->GetDoingPrintPreview(&isPreview); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - if (isPreview) - { - rv = print->ExitPrintPreview(); - } - } - - return rv; -} - -nsresult EphyBrowser::PrintPreviewNumPages (int *numPages) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); - NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - - return print->GetPrintPreviewNumPages(numPages); -} - -nsresult EphyBrowser::PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); - NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - - return print->PrintPreviewNavigate(navType, pageNum); -} - -nsresult EphyBrowser::GetSHistory (nsISHistory **aSHistory) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebNavigation> ContentNav = do_QueryInterface (mWebBrowser); - NS_ENSURE_TRUE (ContentNav, NS_ERROR_FAILURE); - - nsCOMPtr<nsISHistory> SessionHistory; - ContentNav->GetSessionHistory (getter_AddRefs (SessionHistory)); - NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); - - *aSHistory = SessionHistory.get(); - NS_IF_ADDREF (*aSHistory); - - return NS_OK; -} - -nsresult EphyBrowser::CopySHistory (EphyBrowser *dest, PRBool copy_back, - PRBool copy_forward, PRBool copy_current) -{ - nsresult rv; - - nsCOMPtr<nsISHistory> h_src; - GetSHistory (getter_AddRefs(h_src)); - NS_ENSURE_TRUE (h_src, NS_ERROR_FAILURE); - - PRInt32 count, index; - h_src->GetCount (&count); - h_src->GetIndex (&index); - - nsCOMPtr<nsISHistory> h_dest; - dest->GetSHistory (getter_AddRefs (h_dest)); - NS_ENSURE_TRUE (h_dest, NS_ERROR_FAILURE); - - nsCOMPtr<nsISHistoryInternal> hi_dest = do_QueryInterface (h_dest); - NS_ENSURE_TRUE (hi_dest, NS_ERROR_FAILURE); - - if (count) - { - nsCOMPtr<nsIHistoryEntry> he; - nsCOMPtr<nsISHEntry> she, dhe; - - for (PRInt32 i = (copy_back ? 0 : index + 1); - i < (copy_forward ? count : index + 1); - i++) - { - rv = h_src->GetEntryAtIndex (i, PR_FALSE, - getter_AddRefs (he)); - NS_ENSURE_SUCCESS (rv, rv); - - she = do_QueryInterface (he); - NS_ENSURE_TRUE (she, NS_ERROR_FAILURE); - - rv = she->Clone(getter_AddRefs (dhe)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = hi_dest->AddEntry (dhe, PR_TRUE); - NS_ENSURE_SUCCESS (rv, rv); - } - - if (copy_current) - { - nsCOMPtr<nsIWebNavigation> wn_dest = do_QueryInterface (dest->mWebBrowser); - NS_ENSURE_TRUE (wn_dest, NS_ERROR_FAILURE); - - rv = wn_dest->GotoIndex(index); - if (!NS_SUCCEEDED(rv)) return NS_ERROR_FAILURE; - } - } - - return NS_OK; -} - -nsresult EphyBrowser::Destroy () -{ - DetachListeners (); - - mWebBrowser = nsnull; - mDOMWindow = nsnull; - mEventTarget = nsnull; - mEmbed = nsnull; - - mInitialized = PR_FALSE; - - return NS_OK; -} - -nsresult EphyBrowser::GoToHistoryIndex (PRInt16 index) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebNavigation> ContentNav = do_QueryInterface (mWebBrowser); - NS_ENSURE_TRUE (ContentNav, NS_ERROR_FAILURE); - - return ContentNav->GotoIndex (index); -} - -nsresult EphyBrowser::SetZoom (float aZoom) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIContentViewer> contentViewer; - GetContentViewer (getter_AddRefs(contentViewer)); - NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); - - nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); - NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - - return mdv->SetTextZoom (aZoom); -} - -nsresult EphyBrowser::GetContentViewer (nsIContentViewer **aViewer) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDocShell> ourDocShell(do_GetInterface(mWebBrowser)); - NS_ENSURE_TRUE (ourDocShell, NS_ERROR_FAILURE); - - return ourDocShell->GetContentViewer(aViewer); -} - -nsresult EphyBrowser::GetZoom (float *aZoom) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIContentViewer> contentViewer; - GetContentViewer (getter_AddRefs(contentViewer)); - NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); - - nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); - NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - - return mdv->GetTextZoom (aZoom); -} - -nsresult -EphyBrowser::ScrollLines (PRInt32 aNumLines) -{ - nsCOMPtr<nsIDOMWindow> DOMWindow; - - mWebBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow)); - if (!DOMWindow) - { - DOMWindow = mDOMWindow; - } - NS_ENSURE_TRUE (DOMWindow, NS_ERROR_FAILURE); - - return DOMWindow->ScrollByLines (aNumLines); -} - -nsresult -EphyBrowser::ScrollPages (PRInt32 aNumPages) -{ - nsCOMPtr<nsIDOMWindow> DOMWindow; - - mWebBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow)); - if (!DOMWindow) - { - DOMWindow = mDOMWindow; - } - NS_ENSURE_TRUE (DOMWindow, NS_ERROR_FAILURE); - - return DOMWindow->ScrollByPages (aNumPages); -} - -nsresult -EphyBrowser::ScrollPixels (PRInt32 aDeltaX, - PRInt32 aDeltaY) -{ - nsCOMPtr<nsIDOMWindow> DOMWindow; - - mWebBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow)); - if (!DOMWindow) - { - DOMWindow = mDOMWindow; - } - NS_ENSURE_TRUE (DOMWindow, NS_ERROR_FAILURE); - - return DOMWindow->ScrollBy (aDeltaX, aDeltaY); -} - -nsresult -EphyBrowser::GetDocument (nsIDOMDocument **aDOMDocument) -{ - return mDOMWindow->GetDocument (aDOMDocument); -} - -nsresult -EphyBrowser::GetTargetDocument (nsIDOMDocument **aDOMDocument) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - /* Use the current target document */ - if (mTargetDocument) - { - *aDOMDocument = mTargetDocument.get(); - - NS_IF_ADDREF(*aDOMDocument); - - return NS_OK; - } - - /* Use the focused document */ - nsresult rv; - nsCOMPtr<nsIDOMWindow> DOMWindow; - rv = mWebBrowserFocus->GetFocusedWindow (getter_AddRefs(DOMWindow)); - if (NS_SUCCEEDED (rv) && DOMWindow) - { - return DOMWindow->GetDocument (aDOMDocument); - } - - /* Use the main document */ - return mDOMWindow->GetDocument (aDOMDocument); -} - -nsresult EphyBrowser::GetSHInfo (PRInt32 *count, PRInt32 *index) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsISHistory> SessionHistory; - GetSHistory (getter_AddRefs(SessionHistory)); - NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); - - SessionHistory->GetCount (count); - SessionHistory->GetIndex (index); - - return NS_OK; -} - -nsresult EphyBrowser::GetSHTitleAtIndex (PRInt32 index, PRUnichar **title) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsISHistory> SessionHistory; - GetSHistory (getter_AddRefs(SessionHistory)); - NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); - - nsCOMPtr<nsIHistoryEntry> he; - SessionHistory->GetEntryAtIndex (index, PR_FALSE, - getter_AddRefs (he)); - NS_ENSURE_TRUE (he, NS_ERROR_FAILURE); - - nsresult rv; - rv = he->GetTitle (title); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && title, NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult EphyBrowser::GetSHUrlAtIndex (PRInt32 index, nsACString &url) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsISHistory> SessionHistory; - GetSHistory (getter_AddRefs(SessionHistory)); - NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); - - nsCOMPtr<nsIHistoryEntry> he; - SessionHistory->GetEntryAtIndex (index, PR_FALSE, - getter_AddRefs (he)); - NS_ENSURE_TRUE (he, NS_ERROR_FAILURE); - - nsCOMPtr<nsIURI> uri; - he->GetURI (getter_AddRefs(uri)); - NS_ENSURE_TRUE (uri, NS_ERROR_FAILURE); - - nsresult rv; - rv = uri->GetSpec(url); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && url.Length(), NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult EphyBrowser::GetPageDescriptor(nsISupports **aPageDescriptor) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDocShell> ds = do_GetInterface (mWebBrowser); - - nsCOMPtr<nsIWebPageDescriptor> wpd = do_QueryInterface (ds); - NS_ENSURE_TRUE (wpd, NS_ERROR_FAILURE); - - *aPageDescriptor = wpd.get(); - NS_IF_ADDREF (*aPageDescriptor); - - return NS_OK; -} - -nsresult EphyBrowser::GetDOMWindow (nsIDOMWindow **aDOMWindow) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - NS_IF_ADDREF (*aDOMWindow = mDOMWindow); - - return NS_OK; -} - -nsresult EphyBrowser::GetDocumentURI (nsIURI **aURI) -{ - if (!mDOMWindow) return NS_ERROR_NOT_INITIALIZED; - - nsresult rv; - nsCOMPtr<nsIWebNavigation> webNav (do_GetInterface (mDOMWindow, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - return webNav->GetCurrentURI (aURI); -} - -nsresult EphyBrowser::GetTargetDocumentURI (nsIURI **aURI) -{ - if (!mWebBrowser) return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr<nsIDOMDocument> domDoc; - GetTargetDocument (getter_AddRefs(domDoc)); - NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (domDoc)); - NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMAbstractView> abstractView; - docView->GetDefaultView (getter_AddRefs (abstractView)); - NS_ENSURE_TRUE (abstractView, NS_ERROR_FAILURE); - /* the abstract view is really the DOM window */ - - nsresult rv; - nsCOMPtr<nsIWebNavigation> webNav (do_GetInterface (abstractView, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - return webNav->GetCurrentURI (aURI); -} - -nsresult EphyBrowser::ForceEncoding (const char *encoding) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIContentViewer> contentViewer; - GetContentViewer (getter_AddRefs(contentViewer)); - NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); - - nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); - NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - - return mdv->SetForceCharacterSet (nsCString(encoding)); -} - -nsresult EphyBrowser::GetEncoding (nsACString &encoding) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDocCharset> docCharset = do_GetInterface (mWebBrowser); - NS_ENSURE_TRUE (docCharset, NS_ERROR_FAILURE); - - char *charset; - docCharset->GetCharset (&charset); - encoding = charset; - nsMemory::Free (charset); - - return NS_OK; -} - -nsresult EphyBrowser::GetForcedEncoding (nsACString &encoding) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIContentViewer> contentViewer; - GetContentViewer (getter_AddRefs(contentViewer)); - NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); - - nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); - NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - - nsresult rv; - rv = mdv->GetForceCharacterSet (encoding); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult EphyBrowser::PushTargetDocument (nsIDOMDocument *domDoc) -{ - mTargetDocument = domDoc; - - return NS_OK; -} - -nsresult EphyBrowser::PopTargetDocument () -{ - mTargetDocument = nsnull; - - return NS_OK; -} - -nsresult EphyBrowser::DoCommand (const char *command) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsICommandManager> cmdManager; - cmdManager = do_GetInterface (mWebBrowser); - NS_ENSURE_TRUE (cmdManager, NS_ERROR_FAILURE); - - return cmdManager->DoCommand (command, nsnull, nsnull); -} - -nsresult EphyBrowser::GetCommandState (const char *command, PRBool *enabled) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsICommandManager> cmdManager; - cmdManager = do_GetInterface (mWebBrowser); - NS_ENSURE_TRUE (cmdManager, NS_ERROR_FAILURE); - - return cmdManager->IsCommandEnabled (command, nsnull, enabled); -} - -#define NUM_MODIFIED_TEXTFIELDS_REQUIRED 2 - -PRBool -EphyBrowser::CompareFormsText (nsAString &aDefaultText, nsAString &aUserText) -{ - if (aDefaultText.Length() != aUserText.Length()) - { - return FALSE; - } - - /* Mozilla Bug 218277, 195946 and others */ - const PRUnichar *text = aDefaultText.BeginReading(); - for (PRUint32 i = 0; i < aDefaultText.Length(); i++) - { - if (text[i] == 0xa0) - { - aDefaultText.Replace (i, 1, ' '); - } - } - - return (memcmp (aDefaultText.BeginReading(), - aUserText.BeginReading(), - aUserText.Length() * sizeof (PRUnichar)) == 0); -} - -nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUint32 *aNumTextFields, PRBool *aHasTextArea) -{ - nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(aDomDoc); - /* it's okay not to be a HTML doc (happens for XUL documents, like about:config) */ - if (!htmlDoc) return NS_OK; - - nsCOMPtr<nsIDOMHTMLCollection> forms; - htmlDoc->GetForms (getter_AddRefs (forms)); - if (!forms) return NS_OK; /* it's ok not to have any forms */ - - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (aDomDoc)); - nsCOMPtr<nsIDOMViewCSS> defaultCSSView; - if (docView) - { - nsCOMPtr<nsIDOMAbstractView> defaultView; - docView->GetDefaultView (getter_AddRefs (defaultView)); - defaultCSSView = do_QueryInterface (defaultView); - } - - const PRUnichar visibilityLiteral[] = { 'v', 'i', 's', 'i', 'b', 'i', 'l', 'i', 't', 'y', '\0' }; - const PRUnichar visibleLiteral[] = { 'v', 'i', 's', 'i', 'b', 'l', 'e', '\0' }; - nsString visibilityAttr(visibilityLiteral); - nsString visibleAttr(visibleLiteral); - nsString EmptyString; - nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle; - nsCOMPtr<nsIDOMCSSValue> cssValue; - nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue; - - PRUint32 formNum; - forms->GetLength (&formNum); - - /* check all forms */ - for (PRUint32 formIndex = 0; formIndex < formNum; formIndex++) - { - nsCOMPtr<nsIDOMNode> formNode; - forms->Item (formIndex, getter_AddRefs (formNode)); - if (!formNode) continue; - - nsCOMPtr<nsIDOMHTMLFormElement> formElement = do_QueryInterface (formNode); - if (!formElement) continue; - - PRBool isVisible = PR_FALSE; - nsresult rv; - computedStyle = nsnull; - - /* Check defaultCSSView for NULL, see bug #327764 */ - if (defaultCSSView && - NS_SUCCEEDED (defaultCSSView->GetComputedStyle (formElement, EmptyString, - getter_AddRefs (computedStyle))) && - computedStyle) - { - rv = computedStyle->GetPropertyCSSValue(visibilityAttr, getter_AddRefs (cssValue)); - if (NS_SUCCEEDED (rv) && cssValue) - { - nsString value; - rv = cssValue->GetCssText (value); - if (NS_SUCCEEDED (rv) && value.Length ()) - { - /* what to do for "collapse" and "inherit" values? */ - isVisible = CompareFormsText (value, visibleAttr); - } - } - } - - if (!isVisible) - { - LOG ("Form node %p is invisible\n", formNode.get()); - continue; - } - - nsCOMPtr<nsIDOMHTMLCollection> formElements; - formElement->GetElements (getter_AddRefs (formElements)); - if (!formElements) continue; - - PRUint32 elementNum; - formElements->GetLength (&elementNum); - - /* check all input elements in the form for user input */ - for (PRUint32 elementIndex = 0; elementIndex < elementNum; elementIndex++) - { - nsCOMPtr<nsIDOMNode> domNode; - formElements->Item (elementIndex, getter_AddRefs (domNode)); - if (!domNode) continue; - - nsCOMPtr<nsIDOMElement> domElement (do_QueryInterface (domNode)); - if (!domElement) continue; - - isVisible = PR_FALSE; - computedStyle = nsnull; - /* Check defaultCSSView for NULL, see bug #327764 */ - if (defaultCSSView && - NS_SUCCEEDED (defaultCSSView->GetComputedStyle (domElement, EmptyString, - getter_AddRefs (computedStyle))) && - computedStyle) - { - rv = computedStyle->GetPropertyCSSValue(visibilityAttr, getter_AddRefs (cssValue)); - if (NS_SUCCEEDED (rv) && cssValue) - { - nsString value; - rv = cssValue->GetCssText (value); - if (NS_SUCCEEDED (rv) && value.Length ()) - { - /* what to do for "collapse" and "inherit" values? */ - isVisible = CompareFormsText (value, visibleAttr); - } - } - } - - if (!isVisible) - { - LOG("Form node %p element %p is invisible\n", formNode.get(), domNode.get()); - continue; - } - - nsCOMPtr<nsIDOMHTMLTextAreaElement> areaElement = do_QueryInterface (domNode); - if (areaElement) - { - PRBool isDisabled = PR_TRUE; - areaElement->GetDisabled (&isDisabled); - if (isDisabled) - { - LOG ("Form node %p element %p [textarea] is disabled\n", formNode.get(), areaElement.get()); - continue; - } - - nsString defaultText, userText; - areaElement->GetDefaultValue (defaultText); - areaElement->GetValue (userText); - - if (!CompareFormsText (defaultText, userText)) - { - *aHasTextArea = PR_TRUE; - return NS_OK; - } - - continue; - } - - nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(domNode); - if (!inputElement) continue; - - PRBool isDisabled = PR_TRUE; - inputElement->GetDisabled (&isDisabled); - if (isDisabled) - { - LOG ("Form node %p element %p [input] is disabled\n", formNode.get(), inputElement.get()); - continue; - } - - nsString type; - inputElement->GetType(type); - - nsCString cType; - NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType); - - if (g_ascii_strcasecmp (cType.get(), "text") == 0) - { - nsString defaultText, userText; - PRInt32 max_length; - inputElement->GetDefaultValue (defaultText); - inputElement->GetValue (userText); - inputElement->GetMaxLength (&max_length); - - /* There are forms for which defaultValue is longer than - * userValue. Mozilla consider this not a bug [see WONTFIXed - * bug 232057], but we need to check for this here. - */ - if (defaultText.Length() > (PRUint32)max_length) - { - defaultText.Cut (max_length, PR_UINT32_MAX); - } - - if (!CompareFormsText (defaultText, userText)) - { - (*aNumTextFields)++; - if (*aNumTextFields >= NUM_MODIFIED_TEXTFIELDS_REQUIRED) - { - return NS_OK; - } - } - } - } - } - - return NS_OK; -} - -nsresult EphyBrowser::GetHasModifiedForms (PRBool *modified) -{ - *modified = PR_FALSE; - - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDocShell> rootDocShell = do_GetInterface (mWebBrowser); - NS_ENSURE_TRUE (rootDocShell, NS_ERROR_FAILURE); - - nsCOMPtr<nsISimpleEnumerator> enumerator; - rootDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent, - nsIDocShell::ENUMERATE_FORWARDS, - getter_AddRefs(enumerator)); - NS_ENSURE_TRUE (enumerator, NS_ERROR_FAILURE); - - PRBool hasMore; - PRBool hasTextArea = PR_FALSE; - PRUint32 numTextFields = 0; - while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) - { - nsCOMPtr<nsISupports> element; - enumerator->GetNext (getter_AddRefs(element)); - if (!element) continue; - - nsCOMPtr<nsIDocShell> docShell = do_QueryInterface (element); - if (!docShell) continue; - - nsCOMPtr<nsIContentViewer> contentViewer; - docShell->GetContentViewer (getter_AddRefs(contentViewer)); - if (!contentViewer) continue; - - nsCOMPtr<nsIDOMDocument> domDoc; - contentViewer->GetDOMDocument (getter_AddRefs (domDoc)); - - nsresult rv; - rv = GetDocumentHasModifiedForms (domDoc, &numTextFields, &hasTextArea); - if (NS_SUCCEEDED (rv) && - (numTextFields >= NUM_MODIFIED_TEXTFIELDS_REQUIRED || hasTextArea)) - { - *modified = PR_TRUE; - break; - } - } - - return NS_OK; -} - -nsresult -EphyBrowser::GetSecurityInfo (PRUint32 *aState, nsACString &aDescription) -{ -#ifdef HAVE_MOZILLA_PSM - NS_ENSURE_TRUE (mSecurityInfo, NS_ERROR_FAILURE); - - nsresult rv; - rv = mSecurityInfo->GetState (aState); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - nsString tooltip; - rv = mSecurityInfo->GetTooltipText (tooltip); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - NS_UTF16ToCString (tooltip, - NS_CSTRING_ENCODING_UTF8, aDescription); - - return NS_OK; -#else - return NS_ERROR_NOT_IMPLEMENTED; -#endif -} - -nsresult -EphyBrowser::ShowCertificate () -{ -#ifdef HAVE_MOZILLA_PSM - NS_ENSURE_TRUE (mSecurityInfo, NS_ERROR_FAILURE); - - nsCOMPtr<nsISSLStatusProvider> statusProvider (do_QueryInterface (mSecurityInfo)); - NS_ENSURE_TRUE (statusProvider, NS_ERROR_FAILURE); - - nsCOMPtr<nsISSLStatus> SSLStatus; - statusProvider->GetSSLStatus (getter_AddRefs (SSLStatus)); - NS_ENSURE_TRUE (SSLStatus, NS_ERROR_FAILURE); - - nsCOMPtr<nsIX509Cert> serverCert; - SSLStatus->GetServerCert (getter_AddRefs (serverCert)); - NS_ENSURE_TRUE (serverCert, NS_ERROR_FAILURE); - - nsCOMPtr<nsICertificateDialogs> certDialogs (do_GetService (NS_CERTIFICATEDIALOGS_CONTRACTID)); - NS_ENSURE_TRUE (certDialogs, NS_ERROR_FAILURE); - - nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface (mDOMWindow)); - - return certDialogs->ViewCert (requestor, serverCert); -#else - return NS_OK; -#endif -} - -EphyEmbedDocumentType -EphyBrowser::GetDocumentType () -{ - EphyEmbedDocumentType type = EPHY_EMBED_DOCUMENT_OTHER; - - NS_ENSURE_TRUE (mDOMWindow, type); - - nsresult rv; - nsCOMPtr<nsIDOMDocument> domDoc; - rv = GetDocument (getter_AddRefs (domDoc)); - NS_ENSURE_SUCCESS (rv, type); - - nsCOMPtr<nsIDOMHTMLDocument> htmlDoc (do_QueryInterface (domDoc)); - nsCOMPtr<nsIDOMXMLDocument> xmlDoc (do_QueryInterface (domDoc)); - nsCOMPtr<nsIImageDocument> imgDoc (do_QueryInterface (domDoc)); - - if (xmlDoc) - { - type = EPHY_EMBED_DOCUMENT_XML; - } - else if (imgDoc) - { - type = EPHY_EMBED_DOCUMENT_IMAGE; - } - else if (htmlDoc) - { - type = EPHY_EMBED_DOCUMENT_HTML; - } - - return type; -} - -nsresult -EphyBrowser::Close () -{ - nsCOMPtr<nsIDOMWindowInternal> domWin (do_QueryInterface (mDOMWindow)); - NS_ENSURE_TRUE (domWin, NS_ERROR_FAILURE); - - return domWin->Close(); -} - -nsresult -EphyBrowser::GetPIDOMWindow(nsPIDOMWindow **aPIWin) -{ - *aPIWin = nsnull; - - // get the private DOM window - nsCOMPtr<nsPIDOMWindow> domWindowPrivate = do_QueryInterface(mDOMWindow); - NS_ENSURE_TRUE (domWindowPrivate, NS_ERROR_UNEXPECTED); - - // and the root window for that DOM window - *aPIWin = domWindowPrivate->GetPrivateRoot(); - - if (*aPIWin) - { - NS_ADDREF(*aPIWin); - return NS_OK; - } - - return NS_ERROR_FAILURE; - -} - -nsresult -EphyBrowser::LoadURI(const char *aURI, - PRUint32 aLoadFlags, - nsIURI *aReferrer) -{ - nsString uURI; - nsresult rv = NS_OK; - - NS_CStringToUTF16 (nsCString (aURI), NS_CSTRING_ENCODING_UTF8, uURI); - - if (uURI.Length() == 0) return NS_OK; - - nsCOMPtr<nsIWebNavigation> contentNav = do_QueryInterface (mWebBrowser); - NS_ENSURE_TRUE (contentNav, NS_ERROR_FAILURE); - - nsCOMPtr<nsPIDOMWindow> piWin; - rv = GetPIDOMWindow(getter_AddRefs(piWin)); - NS_ENSURE_SUCCESS (rv, rv); - - nsAutoPopupStatePusher popupStatePusher(piWin, openAllowed); - - rv = contentNav->LoadURI(uURI.get(), // URI string - aLoadFlags, // Load flags - aReferrer, // Referring URI - nsnull, // Post data - nsnull); // extra headers - - return rv; -} - diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h deleted file mode 100644 index 18520fc03..000000000 --- a/embed/mozilla/EphyBrowser.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright © 2000-2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_BROWSER_H -#define EPHY_BROWSER_H - -#include "ephy-embed.h" -#include <gtk/gtkwidget.h> - -#include <gtkmozembed.h> -#include <nsCOMPtr.h> -#include <nsIDOMContextMenuListener.h> -#include <nsIDOMDocument.h> -#include <nsIDOMEventListener.h> -#include <nsIDOMEventTarget.h> -#include <nsIDOMWindow.h> -#include <nsIRequest.h> -#include <nsISHistory.h> -#include <nsIWebBrowserFocus.h> -#include <nsIWebBrowser.h> -#include <nsIWebNavigation.h> -#include <nsPIDOMWindow.h> - -#ifdef ALLOW_PRIVATE_API -#include <nsIContentViewer.h> -#endif - -#ifdef HAVE_MOZILLA_PSM -#include <nsISecureBrowserUI.h> -#endif - -class EphyBrowser; - -class EphyEventListener : public nsIDOMEventListener -{ -public: - NS_DECL_ISUPPORTS - - // nsIDOMEventListener - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) = 0; - - EphyEventListener(EphyBrowser *aOwner) : mOwner(aOwner) { }; - virtual ~EphyEventListener() { }; - -protected: - EphyBrowser *mOwner; -}; - -class EphyDOMLinkEventListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyDOMLinkEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -private: - nsresult GetDocURI (nsIDOMElement *aElement, - nsIURI **aDocURI); - -}; - -class EphyPopupBlockEventListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyPopupBlockEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -}; - -class EphyModalAlertEventListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyModalAlertEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -}; - -class EphyMiscDOMEventsListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyMiscDOMEventsListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -}; - -class EphyDOMScrollEventListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyDOMScrollEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -}; - -#ifdef HAVE_GECKO_1_9 -class EphyCommandEventListener : public EphyEventListener -{ -public: - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - - EphyCommandEventListener(EphyBrowser *aOwner) : EphyEventListener(aOwner) { }; -}; -#else -class EphyCommandEventListener; -#endif /* HAVE_GECKO_1_9 */ - -class EphyContextMenuListener : public nsIDOMContextMenuListener -{ -public: - NS_DECL_ISUPPORTS - - // nsIDOMContextMenuListener - NS_IMETHOD ContextMenu(nsIDOMEvent *aEvent); - NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); - - EphyContextMenuListener(EphyBrowser *aOwner) : mOwner(aOwner) { }; - virtual ~EphyContextMenuListener() { }; - -protected: - EphyBrowser *mOwner; -}; - -class EphyBrowser -{ -friend class EphyEventListener; -friend class EphyDOMLinkEventListener; -friend class EphyMiscDOMEventsListener; -friend class EphyDOMScrollEventListener; -friend class EphyPopupBlockEventListener; -friend class EphyModalAlertEventListener; -friend class EphyCommandEventListener; -friend class EphyContextMenuListener; -public: - EphyBrowser(); - ~EphyBrowser(); - - nsresult Init (EphyEmbed *embed); - nsresult Destroy (void); - - nsresult DoCommand (const char *command); - nsresult GetCommandState (const char *command, PRBool *enabled); - - nsresult SetZoom (float aTextZoom); - nsresult GetZoom (float *aTextZoom); - - nsresult ScrollLines (PRInt32 aNumLines); - nsresult ScrollPages (PRInt32 aNumPages); - nsresult ScrollPixels (PRInt32 aDeltaX, PRInt32 aDeltaY); - - nsresult Print (); - nsresult SetPrintPreviewMode (PRBool previewMode); - nsresult PrintPreviewNumPages (int *numPages); - nsresult PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum); - - nsresult GetPageDescriptor(nsISupports **aPageDescriptor); - - nsresult GetSHInfo (PRInt32 *count, PRInt32 *index); - nsresult GetSHTitleAtIndex (PRInt32 index, PRUnichar **title); - nsresult GetSHUrlAtIndex (PRInt32 index, nsACString &url); - nsresult GoToHistoryIndex (PRInt16 index); - - nsresult ForceEncoding (const char *encoding); - nsresult GetEncoding (nsACString &encoding); - nsresult GetForcedEncoding (nsACString &encoding); - - nsresult PushTargetDocument (nsIDOMDocument *domDoc); - nsresult PopTargetDocument (); - - nsresult GetDocument (nsIDOMDocument **aDOMDocument); - nsresult GetTargetDocument (nsIDOMDocument **aDOMDocument); - nsresult GetDocumentURI (nsIURI **aURI); - nsresult GetTargetDocumentURI (nsIURI **aURI); - nsresult GetDOMWindow (nsIDOMWindow **window); - nsresult GetPIDOMWindow(nsPIDOMWindow **aPIWin); - - nsresult GetHasModifiedForms (PRBool *modified); - - nsresult GetSecurityInfo (PRUint32 *aState, nsACString &aDescription); - nsresult ShowCertificate (); - - nsresult CopySHistory (EphyBrowser *dest, PRBool copy_back, - PRBool copy_forward, PRBool copy_current); - - nsresult Close (); - - nsresult LoadURI(const char *aURI, - PRUint32 aLoadFlags = nsIWebNavigation::LOAD_FLAGS_NONE, - nsIURI *aReferrer = nsnull); - - EphyEmbedDocumentType GetDocumentType (); - - nsCOMPtr<nsIWebBrowser> mWebBrowser; -private: - GtkWidget *mEmbed; - - nsCOMPtr<nsIWebBrowserFocus> mWebBrowserFocus; - nsCOMPtr<nsIDOMDocument> mTargetDocument; - nsCOMPtr<nsIDOMEventTarget> mEventTarget; - nsCOMPtr<nsIDOMWindow> mDOMWindow; - EphyDOMLinkEventListener *mDOMLinkEventListener; - EphyMiscDOMEventsListener *mMiscDOMEventsListener; - EphyDOMScrollEventListener *mDOMScrollEventListener; - EphyPopupBlockEventListener *mPopupBlockEventListener; - EphyModalAlertEventListener *mModalAlertListener; -#ifdef HAVE_GECKO_1_9 - EphyCommandEventListener *mCommandEventListener; -#endif - EphyContextMenuListener *mContextMenuListener; - PRBool mInitialized; -#ifdef HAVE_MOZILLA_PSM - nsCOMPtr<nsISecureBrowserUI> mSecurityInfo; -#endif - - nsresult GetListener (void); - nsresult AttachListeners (void); - nsresult DetachListeners (void); - nsresult GetSHistory (nsISHistory **aSHistory); - nsresult GetContentViewer (nsIContentViewer **aViewer); - nsresult GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUint32 *aNumTextFields, PRBool *aHasTextArea); - PRBool CompareFormsText (nsAString &aDefaultText, nsAString &aUserText); -}; - -#endif /* !EPHY_BROWSER_H */ diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp deleted file mode 100644 index 9f789ebcd..000000000 --- a/embed/mozilla/EphyContentPolicy.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright © 2003 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsICategoryManager.h> -#include <nsIDOMAbstractView.h> -#include <nsIDOMDocument.h> -#include <nsIDOMDocumentView.h> -#include <nsIDOMNode.h> -#include <nsIDOMWindow.h> -#include <nsIURI.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOMCID.h> - -#include "eel-gconf-extensions.h" -#include "ephy-adblock-manager.h" -#include "ephy-debug.h" -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" - -#include "EphyUtils.h" - -#include "EphyContentPolicy.h" - -#define CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS "/apps/epiphany/lockdown/disable_unsafe_protocols" -#define CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS "/apps/epiphany/lockdown/additional_safe_protocols" - -NS_IMPL_ISUPPORTS1(EphyContentPolicy, nsIContentPolicy) - -EphyContentPolicy::EphyContentPolicy() -{ - LOG ("EphyContentPolicy ctor (%p)", this); - - mLocked = eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS); - - mSafeProtocols = eel_gconf_get_string_list (CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS); -} - -EphyContentPolicy::~EphyContentPolicy() -{ - LOG ("EphyContentPolicy dtor (%p)", this); - - g_slist_foreach (mSafeProtocols, (GFunc) g_free, NULL); - g_slist_free (mSafeProtocols); -} - -GtkWidget * -EphyContentPolicy::GetEmbedFromContext (nsISupports *aContext) -{ - /* - * aContext is either an nsIDOMWindow, an nsIDOMNode, or NULL. If it's - * an nsIDOMNode, we need the nsIDOMWindow to get the EphyEmbed. - */ - if (aContext == NULL) return NULL; - - nsCOMPtr<nsIDOMWindow> window; - - nsCOMPtr<nsIDOMNode> node (do_QueryInterface (aContext)); - if (node != NULL) - { - nsCOMPtr<nsIDOMDocument> domDocument; - - node->GetOwnerDocument (getter_AddRefs (domDocument)); - if (domDocument == NULL) return NULL; /* resource://... */ - - nsCOMPtr<nsIDOMDocumentView> docView = - do_QueryInterface (domDocument); - NS_ENSURE_TRUE (docView, NULL); - - nsCOMPtr<nsIDOMAbstractView> view; - - docView->GetDefaultView (getter_AddRefs (view)); - - window = do_QueryInterface (view); - } - else - { - window = do_QueryInterface (aContext); - } - NS_ENSURE_TRUE (window, NULL); - - GtkWidget *embed = EphyUtils::FindEmbed (window); - if (!EPHY_IS_EMBED (embed)) return NULL; - - return embed; -} - -NS_IMETHODIMP -EphyContentPolicy::ShouldLoad(PRUint32 aContentType, - nsIURI *aContentLocation, - nsIURI *aRequestingLocation, - nsISupports *aContext, - const nsACString &aMimeTypeGuess, - nsISupports *aExtra, - PRInt16 *aDecision) -{ - NS_ENSURE_ARG (aContentLocation); - NS_ENSURE_ARG_POINTER (aDecision); - - *aDecision = nsIContentPolicy::ACCEPT; - - /* We have to always allow these, else forms and scrollbars break */ - PRBool isChrome = PR_FALSE, isResource = PR_FALSE; - aContentLocation->SchemeIs ("chrome", &isChrome); - aContentLocation->SchemeIs ("resource", &isResource); - if (isChrome || isResource) return NS_OK; - - /* is this url allowed ? */ - nsCString contentSpec; - aContentLocation->GetSpec (contentSpec); - - EphyAdBlockManager *adblock_manager = - EPHY_ADBLOCK_MANAGER (ephy_embed_shell_get_adblock_manager (embed_shell)); - - static PRBool kBlockType[] = { - PR_FALSE /* unused/unknown, don't block */, - PR_TRUE /* TYPE_OTHER */, - PR_TRUE /* TYPE_SCRIPT */, - PR_TRUE /* TYPE_IMAGE */, - PR_FALSE /* TYPE_STYLESHEET */, - PR_TRUE /* TYPE_OBJECT */, - PR_FALSE /* TYPE_DOCUMENT */, - PR_TRUE /* TYPE_SUBDOCUMENT */, - PR_TRUE /* TYPE_REFRESH */, -#ifdef HAVE_GECKO_1_9 - PR_FALSE /* TYPE_XBEL */, - PR_TRUE /* TYPE_PING */, - PR_FALSE /* TYPE_XMLHTTPREQUEST */, - PR_TRUE /* TYPE_OBJECT_SUBREQUEST */, -#endif /* HAVE_GECKO_1_9 */ - }; - - if (kBlockType[aContentType < G_N_ELEMENTS (kBlockType) ? aContentType : 0]) - { - GtkWidget *embed = GetEmbedFromContext (aContext); - - if (embed && - !ephy_adblock_manager_should_load (adblock_manager, - EPHY_EMBED (embed), - contentSpec.get (), - AdUriCheckType (aContentType))) - { - *aDecision = nsIContentPolicy::REJECT_REQUEST; - - g_signal_emit_by_name (embed, - "content-blocked", - contentSpec.get ()); - return NS_OK; - } - } - - PRBool isHttps = PR_FALSE; - aContentLocation->SchemeIs ("https", &isHttps); - if (isHttps) return NS_OK; - - PRBool isHttp = PR_FALSE; - aContentLocation->SchemeIs ("http", &isHttp); - if (isHttp) return NS_OK; - - if (strcmp (contentSpec.get(), "about:blank") == 0) return NS_OK; - - nsCString contentScheme; - aContentLocation->GetScheme (contentScheme); - - /* first general lockdown check */ - if (mLocked && - !g_slist_find_custom (mSafeProtocols, contentScheme.get(), (GCompareFunc) strcmp)) - { - *aDecision = nsIContentPolicy::REJECT_REQUEST; - } - - return NS_OK; -} - -NS_IMETHODIMP -EphyContentPolicy::ShouldProcess(PRUint32 aContentType, - nsIURI *aContentLocation, - nsIURI *aRequestingLocation, - nsISupports *aContext, - const nsACString &aMimeType, - nsISupports *aExtra, - PRInt16 *aDecision) -{ - *aDecision = nsIContentPolicy::ACCEPT; - return NS_OK; -} - - -/* static */ NS_METHOD -EphyContentPolicy::Register (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const char* aComponentType, - const nsModuleComponentInfo* aInfo) -{ - nsresult rv; - nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = catMan->AddCategoryEntry ("content-policy", - EPHY_CONTENT_POLICY_CONTRACTID, - EPHY_CONTENT_POLICY_CONTRACTID, - PR_FALSE /* don't persist */, - PR_TRUE /* replace */, - nsnull); - NS_ENSURE_SUCCESS (rv, rv); - - return rv; -} - -/* static */ NS_METHOD -EphyContentPolicy::Unregister (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const nsModuleComponentInfo* aInfo) -{ - nsresult rv; - nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = catMan->DeleteCategoryEntry ("content-policy", - EPHY_CONTENT_POLICY_CONTRACTID, - PR_FALSE /* don't persist */); - NS_ENSURE_SUCCESS (rv, rv); - - return rv; -} diff --git a/embed/mozilla/EphyContentPolicy.h b/embed/mozilla/EphyContentPolicy.h deleted file mode 100644 index 0bc68ced7..000000000 --- a/embed/mozilla/EphyContentPolicy.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright © 2003 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_CONTENT_POLICY_H -#define EPHY_CONTENT_POLICY_H - -#include <glib.h> -#include <glib-object.h> -#include <gtk/gtkwidget.h> - -#include <nsIContentPolicy.h> - -#include "ephy-embed.h" - -class nsIComponentManager; -class nsIFile; -struct nsModuleComponentInfo; - -#define EPHY_CONTENT_POLICY_CONTRACTID "@gnome.org/projects/epiphany/epiphany-content-policy;1" -#define EPHY_CONTENT_POLICY_CLASSNAME "Epiphany Content Policy Class" - -#define EPHY_CONTENT_POLICY_CID \ -{ /* 6bb60b15-b7bd-4023-a19e-ab691bc3fb43 */ \ - 0x6bb60b15, \ - 0xb7bd, \ - 0x4023, \ - { 0xa1, 0x9e, 0xab, 0x69, 0x1b, 0xc3, 0xfb, 0x43 } \ -} - -class EphyContentPolicy : public nsIContentPolicy -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSICONTENTPOLICY - - EphyContentPolicy(); - - static NS_METHOD Register (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const char* aComponentType, - const nsModuleComponentInfo* aInfo); - - static NS_METHOD Unregister (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const nsModuleComponentInfo* aInfo); - - private: - ~EphyContentPolicy(); - - static GtkWidget *GetEmbedFromContext (nsISupports *aContext); - - gboolean mLocked; - GSList *mSafeProtocols; -}; - -#endif diff --git a/embed/mozilla/EphyDirectoryProvider.cpp b/embed/mozilla/EphyDirectoryProvider.cpp deleted file mode 100644 index c1971a1a8..000000000 --- a/embed/mozilla/EphyDirectoryProvider.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright © 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <string.h> - -#ifndef HAVE_GECKO_1_9 -// for nsNetUtil.h -#define MOZILLA_INTERNAL_API 1 -#endif - -#include <nsStringAPI.h> - -#include <nsAppDirectoryServiceDefs.h> -#include <nsCOMPtr.h> -#include <nsEnumeratorUtils.h> -#include <nsIDirectoryService.h> -#include <nsIIOService.h> -#include <nsILocalFile.h> -#include <nsISupportsArray.h> -#include <nsIToolkitChromeRegistry.h> -#include <nsNetUtil.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsIArray.h> -#include <nsIMutableArray.h> -#endif - -#include "EphyDirectoryProvider.h" - -NS_IMPL_ISUPPORTS2 (EphyDirectoryProvider, - nsIDirectoryServiceProvider, - nsIDirectoryServiceProvider2) - - -/* nsIFile getFile (in string prop, out PRBool persistent); */ -NS_IMETHODIMP -EphyDirectoryProvider::GetFile (const char *prop, - PRBool *persistent, - nsIFile **_retval) -{ - return NS_ERROR_FAILURE; -} - -/* nsISimpleEnumerator getFiles (in string prop); */ -NS_IMETHODIMP -EphyDirectoryProvider::GetFiles (const char *prop, - nsISimpleEnumerator **_retval) -{ - nsresult rv = NS_ERROR_FAILURE; - - if (prop && strcmp (prop, NS_CHROME_MANIFESTS_FILE_LIST) == 0) - { - nsCOMPtr<nsILocalFile> manifestDir; - rv = NS_NewNativeLocalFile (nsDependentCString(SHARE_DIR "/chrome"), PR_TRUE, - getter_AddRefs (manifestDir)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsISupports> element (do_QueryInterface (manifestDir, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - /* FIXME: this sucks! - * When we don't implement a directory service provider, - * the chrome registry takes its manifests files from the - * app chrome dir; but it doesn't append this dir when - * we do provide our own (additional) chrome manifest dirs! - * http://lxr.mozilla.org/seamonkey/source/chrome/src/nsChromeRegistry.cpp#1147 - */ - nsCOMPtr<nsIProperties> dirServ (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIFile> chromeDir; - rv = dirServ->Get (NS_APP_CHROME_DIR, NS_GET_IID (nsIFile), - getter_AddRefs (chromeDir)); - NS_ENSURE_SUCCESS (rv, rv); - -#ifdef HAVE_GECKO_1_9 - nsCOMPtr<nsIMutableArray> array (do_CreateInstance(NS_ARRAY_CONTRACTID)); - if(!array) - return NS_ERROR_OUT_OF_MEMORY; - rv = array->AppendElement (manifestDir, PR_FALSE); - rv |= array->AppendElement (chromeDir, PR_FALSE); - NS_ENSURE_SUCCESS (rv, rv); - - rv = array->Enumerate(_retval); -#else - nsCOMPtr<nsISupportsArray> array; - rv = NS_NewISupportsArray (getter_AddRefs (array)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = array->AppendElement (manifestDir); - rv |= array->AppendElement (chromeDir); - NS_ENSURE_SUCCESS (rv, rv); - - rv = NS_NewArrayEnumerator (_retval, array); -#endif /* HAVE_GECKO_1_9 */ - - NS_ENSURE_SUCCESS (rv, rv); - - rv = NS_SUCCESS_AGGREGATE_RESULT; - } - - return rv; -} diff --git a/embed/mozilla/EphyDirectoryProvider.h b/embed/mozilla/EphyDirectoryProvider.h deleted file mode 100644 index ca66f9d4d..000000000 --- a/embed/mozilla/EphyDirectoryProvider.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_DIRECTORY_PROVIDER_H -#define EPHY_DIRECTORY_PROVIDER_H - -#include <nsIDirectoryService.h> - -class EphyDirectoryProvider : public nsIDirectoryServiceProvider2 -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIDIRECTORYSERVICEPROVIDER - NS_DECL_NSIDIRECTORYSERVICEPROVIDER2 - - EphyDirectoryProvider() { } - virtual ~EphyDirectoryProvider() { } -}; - -#endif /* EPHY_DIRECTORY_PROVIDER_H */ diff --git a/embed/mozilla/EphyFind.cpp b/embed/mozilla/EphyFind.cpp deleted file mode 100644 index 0b7d8bf89..000000000 --- a/embed/mozilla/EphyFind.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib.h> - -#include <nsStringAPI.h> - -#include <gtkmozembed.h> -#include <gtkmozembed_internal.h> -#include <nsComponentManagerUtils.h> -#include <nsCOMPtr.h> -#include <nsIDocShell.h> -#include <nsIDOMAbstractView.h> -#include <nsIDOMDocumentEvent.h> -#include <nsIDOMDocument.h> -#include <nsIDOMDocumentView.h> -#include <nsIDOMElement.h> -#include <nsIDOMEvent.h> -#include <nsIDOMEventTarget.h> -#include <nsIDOMHTMLAnchorElement.h> -#include <nsIDOMKeyEvent.h> -#include <nsIDOMNode.h> -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsISelectionController.h> -#include <nsISelectionDisplay.h> -#include <nsITypeAheadFind.h> -#include <nsIWebBrowserFocus.h> -#include <nsIWebBrowser.h> -#include <nsServiceManagerUtils.h> - -#ifndef HAVE_GECKO_1_9 -#include <nsIDocShellTreeItem.h> -#include <nsISimpleEnumerator.h> -#endif - -#include "ephy-debug.h" - -#include "EphyFind.h" - -#define NS_TYPEAHEADFIND_CONTRACTID "@mozilla.org/typeaheadfind;1" - -static const PRUnichar kKeyEvents[] = { 'K', 'e', 'y', 'E', 'v', 'e', 'n', 't', 's', '\0' }; -static const PRUnichar kKeyPress[] = { 'k', 'e', 'y', 'p', 'r', 'e', 's', 's', '\0' }; - -EphyFind::EphyFind () -: mCurrentEmbed(nsnull) -, mAttention(PR_FALSE) -{ - LOG ("EphyFind ctor [%p]", this); -} - -EphyFind::~EphyFind () -{ - LOG ("EphyFind dtor [%p]", this); -} - -nsresult -EphyFind::SetEmbed (EphyEmbed *aEmbed) -{ - nsresult rv = NS_OK; - if (aEmbed == mCurrentEmbed) return rv; - - SetSelectionAttention (PR_FALSE); - - mCurrentEmbed = nsnull; - mWebBrowser = nsnull; - - rv = NS_ERROR_FAILURE; - gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED (gtk_bin_get_child (GTK_BIN (aEmbed))), - getter_AddRefs (mWebBrowser)); - NS_ENSURE_TRUE (mWebBrowser, rv); - - nsCOMPtr<nsIDocShell> docShell (do_GetInterface (mWebBrowser, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - if (!mFinder) { - mFinder = do_CreateInstance (NS_TYPEAHEADFIND_CONTRACTID, &rv); - NS_ENSURE_SUCCESS (rv, rv); - - rv = mFinder->Init (docShell); -#ifdef HAVE_GECKO_1_9 - mFinder->SetSelectionModeAndRepaint (nsISelectionController::SELECTION_ON); -#else - mFinder->SetFocusLinks (PR_TRUE); -#endif - } else { - rv = mFinder->SetDocShell (docShell); - } - NS_ENSURE_SUCCESS (rv, rv); - - mCurrentEmbed = aEmbed; - - return rv; -} - -void -EphyFind::SetFindProperties (const char *aSearchString, - PRBool aCaseSensitive) -{ - if (!mFinder) return; - - mFinder->SetCaseSensitive (aCaseSensitive); - /* search string is set on ::Find */ -} - -void -EphyFind::SetSelectionAttention (PRBool aAttention) -{ - if (aAttention == mAttention) return; - - mAttention = aAttention; - - PRInt16 display; - if (aAttention) { - display = nsISelectionController::SELECTION_ATTENTION; - } else { - display = nsISelectionController::SELECTION_ON; - } - -#ifdef HAVE_GECKO_1_9 - if (mFinder) { - mFinder->SetSelectionModeAndRepaint (display); - } -#else - nsresult rv; - nsCOMPtr<nsIDocShell> shell (do_GetInterface (mWebBrowser, &rv)); - /* It's okay for this to fail, if the tab is closing, or if - * we weren't attached to any tab yet - */ - if (NS_FAILED (rv) || !shell) return; - - nsCOMPtr<nsISimpleEnumerator> enumerator; - rv = shell->GetDocShellEnumerator (nsIDocShellTreeItem::typeContent, - nsIDocShell::ENUMERATE_FORWARDS, - getter_AddRefs (enumerator)); - NS_ENSURE_SUCCESS (rv, ); - - PRBool hasMore = PR_FALSE; - while (NS_SUCCEEDED (enumerator->HasMoreElements (&hasMore)) && hasMore) { - nsCOMPtr<nsISupports> element; - enumerator->GetNext (getter_AddRefs (element)); - if (!element) continue; - - nsCOMPtr<nsISelectionDisplay> sd (do_GetInterface (element)); - if (!sd) continue; - - nsCOMPtr<nsISelectionController> controller (do_QueryInterface (sd)); - if (!controller) continue; - - controller->SetDisplaySelection (display); - } -#endif /* HAVE_GECKO_1_9 */ -} - -EphyEmbedFindResult -EphyFind::Find (const char *aSearchString, - PRBool aLinksOnly) -{ - if (!mFinder) return EPHY_EMBED_FIND_NOTFOUND; - - nsString uSearchString; - NS_CStringToUTF16 (nsCString (aSearchString ? aSearchString : ""), - NS_CSTRING_ENCODING_UTF8, uSearchString); - - SetSelectionAttention (PR_TRUE); - - nsresult rv; - PRUint16 found = nsITypeAheadFind::FIND_NOTFOUND; - rv = mFinder->Find (uSearchString, aLinksOnly, &found); - - return (EphyEmbedFindResult) found; -} - -EphyEmbedFindResult -EphyFind::FindAgain (PRBool aForward, - PRBool aLinksOnly) -{ - if (!mFinder) return EPHY_EMBED_FIND_NOTFOUND; - - SetSelectionAttention (PR_TRUE); - - nsresult rv; - PRUint16 found = nsITypeAheadFind::FIND_NOTFOUND; -#ifdef HAVE_GECKO_1_9 - rv = mFinder->FindAgain (!aForward, aLinksOnly, &found); -#else - if (aForward) { - rv = mFinder->FindNext (&found); - } else { - rv = mFinder->FindPrevious (&found); - } -#endif - - return (EphyEmbedFindResult) found; -} - -PRBool -EphyFind::ActivateLink (GdkModifierType aMask) -{ - nsresult rv; - nsCOMPtr<nsIDOMElement> link; - rv = mFinder->GetFoundLink (getter_AddRefs (link)); - if (NS_FAILED (rv) || !link) return FALSE; - - nsCOMPtr<nsIDOMDocument> doc; - rv = link->GetOwnerDocument (getter_AddRefs (doc)); - NS_ENSURE_TRUE (doc, FALSE); - - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (doc)); - NS_ENSURE_TRUE (docView, FALSE); - - nsCOMPtr<nsIDOMAbstractView> abstractView; - docView->GetDefaultView (getter_AddRefs (abstractView)); - NS_ENSURE_TRUE (abstractView, FALSE); - - nsCOMPtr<nsIDOMDocumentEvent> docEvent (do_QueryInterface (doc)); - NS_ENSURE_TRUE (docEvent, FALSE); - - nsCOMPtr<nsIDOMEvent> event; - rv = docEvent->CreateEvent (nsString(kKeyEvents), getter_AddRefs (event)); - NS_ENSURE_SUCCESS (rv, FALSE); - - nsCOMPtr<nsIDOMKeyEvent> keyEvent (do_QueryInterface (event)); - NS_ENSURE_TRUE (keyEvent, FALSE); - - rv = keyEvent->InitKeyEvent (nsString (kKeyPress), - PR_TRUE /* bubble */, - PR_TRUE /* cancelable */, - abstractView, - (aMask & GDK_CONTROL_MASK) != 0, - (aMask & GDK_MOD1_MASK) != 0 /* Alt */, - (aMask & GDK_SHIFT_MASK) != 0, - /* FIXME when we upgrade to gtk 2.10 */ - PR_FALSE /* Meta */, - nsIDOMKeyEvent::DOM_VK_RETURN, - 0); - NS_ENSURE_SUCCESS (rv, FALSE); - - nsCOMPtr<nsIDOMEventTarget> target (do_QueryInterface (link)); - NS_ENSURE_TRUE (target, FALSE); - - PRBool defaultPrevented = PR_FALSE; - rv = target->DispatchEvent (event, &defaultPrevented); - - return NS_SUCCEEDED (rv) && defaultPrevented; -} diff --git a/embed/mozilla/EphyFind.h b/embed/mozilla/EphyFind.h deleted file mode 100644 index 34c30517d..000000000 --- a/embed/mozilla/EphyFind.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef TYPEAHEADFIND_H -#define TYPEAHEADFIND_H - -#include <gdk/gdktypes.h> - -class nsITypeAheadFind; -class nsIWebBrowser; -class nsIWebBrowserFind; - -#include <nsCOMPtr.h> - -#include "ephy-embed.h" -#include "ephy-embed-find.h" - -class EphyFind -{ - public: - EphyFind (); - ~EphyFind (); - - nsresult SetEmbed (EphyEmbed *aEmbed); - void SetFindProperties (const char *aSearchString, - PRBool aCaseSensitive); - void SetSelectionAttention (PRBool aAttention); - EphyEmbedFindResult Find (const char *aSearchString, - PRBool aLinksOnly); - EphyEmbedFindResult FindAgain (PRBool aForward, - PRBool aLinksOnly); - PRBool ActivateLink (GdkModifierType aMask); - - private: - EphyEmbed *mCurrentEmbed; - - nsCOMPtr<nsIWebBrowser> mWebBrowser; - - nsCOMPtr<nsITypeAheadFind> mFinder; - PRPackedBool mAttention; -}; - -#endif /* !TYPEAHEADFIND_H */ diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp deleted file mode 100644 index f09a6ee0e..000000000 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Chimera code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * David Hyatt <hyatt@netscape.com> - * Simon Fraser <sfraser@netscape.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gi18n.h> - -#include <nsStringAPI.h> - -#include <nsComponentManagerUtils.h> -#include <nsIChannel.h> -#include <nsIDOMDocument.h> -#include <nsIDOMHTMLDocument.h> -#include <nsIDownload.h> -#include <nsIHttpChannel.h> -#include <nsIInputStream.h> -#include <nsILocalFile.h> -#include <nsIMIMEHeaderParam.h> -#include <nsIMIMEInfo.h> -#include <nsIMIMEService.h> -#include <nsIPrefService.h> -#include <nsIPromptService.h> -#include <nsIURI.h> -#include <nsIURL.h> -#include <nsIWebBrowserPersist.h> -#include <nsIWindowWatcher.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOMCID.h> - -#include "eel-gconf-extensions.h" -#include "ephy-debug.h" -#include "ephy-file-chooser.h" -#include "ephy-gui.h" -#include "ephy-prefs.h" - -#ifndef HAVE_GECKO_1_9 -#include "EphyBadCertRejector.h" -#endif -#include "MozDownload.h" - -#include "EphyHeaderSniffer.h" - -EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, - nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData, - EphyEmbedSingle *single) -: mPersist(aPersist) -, mEmbedPersist(aEmbedPersist) -, mTmpFile(aFile) -, mURL(aURL) -, mOriginalURI(nsnull) -, mDocument(aDocument) -, mPostData(aPostData) -{ - LOG ("EphyHeaderSniffer ctor (%p)", this); - - nsCOMPtr<nsIWindowWatcher> watcher - (do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - if (!watcher) return; - - watcher->GetNewAuthPrompter (nsnull, getter_AddRefs (mAuthPrompt)); - - mSingle = single; - EphyEmbedSingle **cache_ptr = &mSingle; - g_object_add_weak_pointer (G_OBJECT (mSingle), - (gpointer *) cache_ptr); -} - -EphyHeaderSniffer::~EphyHeaderSniffer() -{ - LOG ("EphyHeaderSniffer dtor (%p)", this); - - if (mSingle) - { - EphyEmbedSingle **cache_ptr = &mSingle; - g_object_remove_weak_pointer (G_OBJECT (mSingle), - (gpointer *) cache_ptr); - } -} - -NS_IMPL_ISUPPORTS3 (EphyHeaderSniffer, - nsIWebProgressListener, - nsIInterfaceRequestor, - nsIAuthPrompt) - -NS_IMETHODIMP -EphyHeaderSniffer::HandleContent () -{ - gboolean handled = FALSE; - nsCString uriSpec; - - if (mPostData || !mSingle) return NS_ERROR_FAILURE; - - mURL->GetSpec (uriSpec); - - g_signal_emit_by_name (mSingle, "handle_content", mContentType.get(), - uriSpec.get(), &handled); - - return handled ? NS_OK : NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -EphyHeaderSniffer::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, - PRUint32 aStatus) -{ - if (aStateFlags & nsIWebProgressListener::STATE_START) - { - /* be sure to keep it alive while we save since it owns - us as a listener and keep ourselves alive */ - nsCOMPtr<nsIWebBrowserPersist> kungFuDeathGrip(mPersist); - nsCOMPtr<nsIWebProgressListener> kungFuSuicideGrip(this); - - nsresult rv; - nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest, &rv); - if (!channel) return rv; - channel->GetContentType(mContentType); - - nsCOMPtr<nsIURI> origURI; - channel->GetOriginalURI(getter_AddRefs(origURI)); - - nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); - if (httpChannel) - { - httpChannel->GetResponseHeader(nsCString("content-disposition"), - mContentDisposition); - } - - mPersist->CancelSave(); - - PRBool exists; - mTmpFile->Exists(&exists); - if (exists) - { - mTmpFile->Remove(PR_FALSE); - } - - rv = HandleContent (); - if (NS_SUCCEEDED (rv)) return NS_OK; - - rv = PerformSave(origURI); - if (NS_FAILED(rv)) - { - /* FIXME put up some UI */ - - } - } - - return NS_OK; -} - -NS_IMETHODIMP -EphyHeaderSniffer::OnProgressChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - return NS_OK; -} - -NS_IMETHODIMP -EphyHeaderSniffer::OnLocationChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - return NS_OK; -} - -NS_IMETHODIMP -EphyHeaderSniffer::OnStatusChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - return NS_OK; -} - -NS_IMETHODIMP -EphyHeaderSniffer::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -/* void getInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */ -NS_IMETHODIMP -EphyHeaderSniffer::GetInterface(const nsIID & uuid, void * *result) -{ -#ifndef HAVE_GECKO_1_9 - if (uuid.Equals (NS_GET_IID (nsIBadCertListener)) && - mEmbedPersist) - { - EphyEmbedPersistFlags flags; - - g_object_get (mEmbedPersist, "flags", &flags, (char *) NULL); - - if (flags & EPHY_EMBED_PERSIST_NO_CERTDIALOGS) - { - EphyBadCertRejector *badCertRejector = new EphyBadCertRejector (); - if (!badCertRejector) return NS_ERROR_OUT_OF_MEMORY; - - *result = static_cast<nsIBadCertListener*>(badCertRejector); - NS_ADDREF (badCertRejector); - - return NS_OK; - } - } -#endif - - return NS_ERROR_NO_INTERFACE; -} - -static void -filechooser_response_cb (GtkWidget *dialog, - gint response, - EphyHeaderSniffer* sniffer) -{ - if (response == GTK_RESPONSE_ACCEPT) - { - char *filename; - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - - if (ephy_gui_check_location_writable (dialog, filename) == FALSE) - { - g_free (filename); - return; - } - - nsCOMPtr<nsILocalFile> destFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - if (destFile) - { - destFile->InitWithNativePath (nsCString (filename)); - - sniffer->InitiateDownload (destFile); - } - - g_free (filename); - } - - // FIXME how to inform user of failed save ? - - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) -{ - nsresult rv; - EphyEmbedPersistFlags flags; - PRBool askDownloadDest; - - mOriginalURI = inOriginalURI; - - flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); - askDownloadDest = flags & EPHY_EMBED_PERSIST_ASK_DESTINATION; - - nsString defaultFileName; - - if (!defaultFileName.Length() && mContentDisposition.Length()) - { - /* 1 Use the HTTP header suggestion. */ - nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar = - do_GetService("@mozilla.org/network/mime-hdrparam;1"); - - if (mimehdrpar) - { - nsCString fallbackCharset; - if (mURL) - { - mURL->GetOriginCharset(fallbackCharset); - } - - nsString fileName; - - rv = mimehdrpar->GetParameter (mContentDisposition, "filename", - fallbackCharset, PR_TRUE, nsnull, - fileName); - if (NS_FAILED(rv) || !fileName.Length()) - { - rv = mimehdrpar->GetParameter (mContentDisposition, "name", - fallbackCharset, PR_TRUE, nsnull, - fileName); - } - - if (NS_SUCCEEDED(rv) && fileName.Length()) - { - defaultFileName = fileName; - } - } - } - - if (!defaultFileName.Length()) - { - /* 2 For file URLs, use the file name. */ - - nsCOMPtr<nsIURL> url(do_QueryInterface(mURL)); - if (url) - { - nsCString fileNameCString; - url->GetFileName(fileNameCString); - NS_CStringToUTF16 (fileNameCString, NS_CSTRING_ENCODING_UTF8, - defaultFileName); - } - } - - if (!defaultFileName.Length() && mDocument) - { - /* 3 Use the title of the document. */ - - nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(mDocument)); - if (htmlDoc) - { - htmlDoc->GetTitle(defaultFileName); - } - } - - if (!defaultFileName.Length() && mURL) - { - /* 4 Use the host. */ - nsCString hostName; - mURL->GetHost(hostName); - NS_CStringToUTF16 (hostName, NS_CSTRING_ENCODING_UTF8, - defaultFileName); - } - - /* 5 One last case to handle about:blank and other untitled pages. */ - if (!defaultFileName.Length()) - { - NS_CStringToUTF16 (nsCString(_("Untitled")), - NS_CSTRING_ENCODING_UTF8, defaultFileName); - } - - /* Validate the file name to ensure legality. */ - nsCString cDefaultFileName; - NS_UTF16ToCString (defaultFileName, NS_CSTRING_ENCODING_UTF8, - cDefaultFileName); - char *default_name = g_strdup (cDefaultFileName.get()); - default_name = g_strdelimit (default_name, "/\\:", ' '); - - const char *key; - key = ephy_embed_persist_get_persist_key (EPHY_EMBED_PERSIST (mEmbedPersist)); - - /* FIXME: do better here by using nsITextToSubURI service, like in - * http://lxr.mozilla.org/seamonkey/source/xpfe/communicator/resources/content/contentAreaUtils.js#763 - */ - char *filename = g_uri_unescape_string (default_name, NULL); - - if (!g_utf8_validate (filename, -1, NULL)) - { - g_free (filename); - filename = g_strdup (default_name); - } - - g_free (default_name); - - if (askDownloadDest) - { - EphyFileChooser *dialog; - GtkWindow *window; - const char *title; - guint32 user_time; - - title = ephy_embed_persist_get_fc_title (EPHY_EMBED_PERSIST (mEmbedPersist)); - window = ephy_embed_persist_get_fc_parent (EPHY_EMBED_PERSIST (mEmbedPersist)); - - user_time = ephy_embed_persist_get_user_time (EPHY_EMBED_PERSIST (mEmbedPersist)); - if (user_time == 0) - { - g_warning ("EphyHeaderSniffer::PerformSave without valid user time!\n"); - } - - dialog = ephy_file_chooser_new (title ? title: _("Save"), - GTK_WIDGET (window), - GTK_FILE_CHOOSER_ACTION_SAVE, - key ? key : CONF_STATE_SAVE_DIR, - EPHY_FILE_FILTER_ALL_SUPPORTED); - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); - - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), - filename); - - g_signal_connect (dialog, "response", - G_CALLBACK (filechooser_response_cb), this); - - ephy_gui_window_update_user_time (GTK_WIDGET (dialog), user_time); - gtk_widget_show (GTK_WIDGET (dialog)); - - g_free (filename); - return NS_OK; - } - /* FIXME: how to inform user of failed save ? */ - - nsCOMPtr<nsILocalFile> destFile; - BuildDownloadPath (filename, getter_AddRefs (destFile)); - g_free (filename); - NS_ENSURE_TRUE (destFile, NS_ERROR_FAILURE); - - return InitiateDownload (destFile); -} - -nsresult EphyHeaderSniffer::InitiateDownload (nsILocalFile *aDestFile) -{ - LOG ("Initiating download"); - - return InitiateMozillaDownload (mDocument, mURL, aDestFile, - mContentType.get(), mOriginalURI, mEmbedPersist, - mPostData, nsnull, -1); -} diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h deleted file mode 100644 index ec73c3164..000000000 --- a/embed/mozilla/EphyHeaderSniffer.h +++ /dev/null @@ -1,95 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Chimera code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * David Hyatt <hyatt@netscape.com> - * Simon Fraser <sfraser@netscape.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * $Id$ - */ - -#ifndef EPHY_HEADER_SNIFFER_H -#define EPHY_HEADER_SNIFFER_H - -class nsIDOMDocument; -class nsIFile; -class nsIInputStream; -class nsILocalFile; -class nsIURI; -class nsIWebBrowserPersist; - -#include <nsCOMPtr.h> -#include <nsIAuthPrompt.h> -#include <nsIInterfaceRequestor.h> -#include <nsIWebProgressListener.h> - -#include "mozilla-embed-persist.h" -#include "ephy-embed-single.h" - -class EphyHeaderSniffer : public nsIWebProgressListener, - public nsIInterfaceRequestor, - public nsIAuthPrompt -{ -public: - EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, - nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, - nsIInputStream* aPostData, EphyEmbedSingle *single); - virtual ~EphyHeaderSniffer (); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - NS_FORWARD_SAFE_NSIAUTHPROMPT(mAuthPrompt) - NS_DECL_NSIINTERFACEREQUESTOR - - nsresult InitiateDownload (nsILocalFile *aDestFile); - -protected: - nsresult PerformSave (nsIURI* inOriginalURI); - nsresult HandleContent (); - -private: - nsIWebBrowserPersist* mPersist; /* Weak. It owns us as a listener. */ - MozillaEmbedPersist *mEmbedPersist; - EphyEmbedSingle *mSingle; - nsCOMPtr<nsIFile> mTmpFile; - nsCOMPtr<nsIURI> mURL; - nsCOMPtr<nsIURI> mOriginalURI; - nsCOMPtr<nsIDOMDocument> mDocument; - nsCOMPtr<nsIInputStream> mPostData; - nsCString mContentType; - nsCString mContentDisposition; - nsCOMPtr<nsIAuthPrompt> mAuthPrompt; -}; - -#endif /* !EPHY_HEADER_SNIFFER_H */ diff --git a/embed/mozilla/EphyHistoryListener.cpp b/embed/mozilla/EphyHistoryListener.cpp deleted file mode 100644 index 232c3ccb9..000000000 --- a/embed/mozilla/EphyHistoryListener.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsCURILoader.h> -#include <nsIChannel.h> -#include <nsIDocumentLoader.h> -#include <nsIHttpChannel.h> -#include <nsIRequest.h> -#include <nsIRequestObserver.h> -#include <nsISupportsUtils.h> -#include <nsIURI.h> -#include <nsIWebProgress.h> -#include <nsNetCID.h> -#include <nsServiceManagerUtils.h> - -#include "EphyUtils.h" - -#include "ephy-debug.h" - -#include "EphyHistoryListener.h" - -EphyHistoryListener::EphyHistoryListener () -{ - LOG ("EphyHistoryListener ctor"); -} - -EphyHistoryListener::~EphyHistoryListener () -{ - LOG ("EphyHistoryListener dtor"); -} - -nsresult -EphyHistoryListener::Init (EphyHistory *aHistory) -{ - mHistory = aHistory; - - nsresult rv; - nsCOMPtr<nsIWebProgress> webProgress - (do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv)); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && webProgress, rv); - - rv = webProgress->AddProgressListener - (static_cast<nsIWebProgressListener*>(this), - nsIWebProgress::NOTIFY_STATE_REQUEST); - - return rv; -} - -NS_IMPL_ISUPPORTS2 (EphyHistoryListener, - nsIWebProgressListener, - nsISupportsWeakReference) - -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in nsresult aStatus); */ -NS_IMETHODIMP -EphyHistoryListener::OnStateChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRUint32 aStateFlags, - nsresult aStatus) -{ - nsresult rv = NS_OK; - - /* we only care about redirects */ - if (! (aStateFlags & nsIWebProgressListener::STATE_REDIRECTING)) - { - return rv; - } - - nsCOMPtr<nsIChannel> channel (do_QueryInterface (aRequest)); - nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface (channel)); - if (!httpChannel) return rv; - - PRUint32 status = 0; - rv = httpChannel->GetResponseStatus (&status); - if (rv == NS_ERROR_NOT_AVAILABLE) return NS_OK; - NS_ENSURE_SUCCESS (rv, rv); - - /* we're only interested in 301 redirects (moved permanently) */ - if (status != 301) return NS_OK; - - nsCOMPtr<nsIURI> fromURI; - rv = channel->GetURI (getter_AddRefs (fromURI)); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && fromURI, rv); - - nsCString location; - rv = httpChannel->GetResponseHeader - (nsCString ("Location"), location); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && location.Length(), rv); - - nsCOMPtr<nsIURI> toURI; - rv = EphyUtils::NewURI (getter_AddRefs (toURI), location, - nsnull /* use origin charset of fromURI */, fromURI); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && toURI, rv); - - nsCString fromSpec, toSpec; - rv = fromURI->GetSpec (fromSpec); - rv |= toURI->GetSpec(toSpec); - NS_ENSURE_SUCCESS (rv, rv); - - g_signal_emit_by_name (mHistory, "redirect", - fromSpec.get(), toSpec.get()); - - return rv; -} - -/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */ -NS_IMETHODIMP -EphyHistoryListener::OnProgressChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - NS_NOTREACHED("notification excluded in AddProgressListener(...)"); - return NS_OK; -} - -/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */ -NS_IMETHODIMP -EphyHistoryListener::OnLocationChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsIURI *location) -{ - NS_NOTREACHED("notification excluded in AddProgressListener(...)"); - return NS_OK; -} - -/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */ -NS_IMETHODIMP -EphyHistoryListener::OnStatusChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - nsresult aStatus, - const PRUnichar *aMessage) -{ - NS_NOTREACHED("notification excluded in AddProgressListener(...)"); - return NS_OK; -} - -/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */ -NS_IMETHODIMP -EphyHistoryListener::OnSecurityChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRUint32 state) -{ - NS_NOTREACHED("notification excluded in AddProgressListener(...)"); - return NS_OK; -} diff --git a/embed/mozilla/EphyHistoryListener.h b/embed/mozilla/EphyHistoryListener.h deleted file mode 100644 index 23f955f05..000000000 --- a/embed/mozilla/EphyHistoryListener.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_REDIRECT_LISTENER_H -#define EPHY_REDIRECT_LISTENER_H - -#include "ephy-history.h" - -#include <nsIWebProgressListener.h> -#include <nsWeakReference.h> - -/* 6a9533c6-f068-4e63-8225-5feba0b54d6b */ -#define EPHY_REDIRECTLISTENER_CID \ -{ 0x6a9533c6, 0xf068, 0x4e63, { 0x82, 0x25, 0x5f, 0xeb, 0xa0, 0xb5, 0x4d, 0x6b } } -#define EPHY_REDIRECTLISTENER_CLASSNAME "Epiphany Redirect Listener Class" - -class EphyHistoryListener : public nsIWebProgressListener, - public nsSupportsWeakReference -{ - public: - EphyHistoryListener(); - virtual ~EphyHistoryListener(); - - nsresult Init (EphyHistory *aHistory); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - private: - EphyHistory *mHistory; -}; - -#endif /* EPHY_REDIRECT_LISTENER_H */ diff --git a/embed/mozilla/EphyPromptService.cpp b/embed/mozilla/EphyPromptService.cpp deleted file mode 100644 index 3229a89da..000000000 --- a/embed/mozilla/EphyPromptService.cpp +++ /dev/null @@ -1,1117 +0,0 @@ -/* - * Copyright © 2005, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib.h> -#include <glib-object.h> -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsIDOMWindow.h> -#include <nsServiceManagerUtils.h> - -#include "ephy-embed-shell.h" -#include "ephy-gui.h" -#include "ephy-debug.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" - -#undef ENABLE_AUTHPROMPT2 -#ifdef ENABLE_AUTHPROMPT2 -#include <nsIStringBundle.h> -#include "nsIChannel.h" -#include "nsIProxiedChannel.h" -#include "nsIProxyInfo.h" -#include "nsNetCID.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsIIDNService.h" -#include "nsIAuthInformation.h" -#endif /* ENABLE_AUTHPROMPT2 */ - -#include "EphyPromptService.h" - -#define TIMEOUT 1000 /* ms */ -#define TIMEOUT_DATA_KEY "timeout" - -#define MAX_MESSAGE_LENGTH 512 -#define MAX_TITLE_LENGTH 256 -#define MAX_BUTTON_TEXT_LENGTH 128 - -enum -{ - RESPONSE_ABORT_SCRIPT = 42 -}; - -class Prompter -{ -public: - Prompter (const char*, nsIDOMWindow*, const PRUnichar*, const PRUnichar*); - ~Prompter(); - - void AddStockButton (const char*, int); - void AddButtonWithFlags (PRInt32, PRUint32, const PRUnichar*, PRUint32); - void AddButtonsWithFlags (PRUint32, const PRUnichar*, const PRUnichar*, const PRUnichar*); - void AddCheckbox (const PRUnichar*, PRBool*); - void GetCheckboxState (PRBool *); - void AddEntry (const char *, const PRUnichar *, PRBool); - void GetText (PRUint32, PRUnichar **); - void AddSelect (PRUint32, const PRUnichar **, PRInt32); - void GetSelected (PRInt32*); - - PRInt32 Run (PRBool * = nsnull); - void Show (); - - PRBool IsCalledFromScript (); - void PerformScriptAbortion (); - - char *ConvertAndTruncateString (const PRUnichar *, PRInt32 = -1); - char* ConvertAndEscapeButtonText (const PRUnichar *, PRInt32 = -1); - -private: - nsCOMPtr<nsIDOMWindow> mWindow; - GtkDialog *mDialog; - GtkWidget *mVBox; - GtkWidget *mCheck; - GtkSizeGroup *mSizeGroup; - GtkWidget *mEntries[2]; - GtkWidget *mCombo; - PRInt32 mNumButtons; - PRInt32 mNumEntries; - PRInt32 mDefaultResponse; - PRInt32 mUnaffirmativeResponse; - PRInt32 mResponse; - PRBool mSuccess; - PRBool mDelay; -}; - -Prompter::Prompter (const char *aStock, - nsIDOMWindow *aParent, - const PRUnichar *aTitle, - const PRUnichar *aText) - : mWindow (aParent) - , mDialog(nsnull) - , mVBox(nsnull) - , mCheck(nsnull) - , mSizeGroup(nsnull) - , mCombo(nsnull) - , mNumButtons(0) - , mNumEntries(0) - , mDefaultResponse(GTK_RESPONSE_ACCEPT) - , mUnaffirmativeResponse(0) - , mResponse(GTK_RESPONSE_CANCEL) - , mSuccess(PR_FALSE) - , mDelay(PR_FALSE) -{ - GtkWidget *parent, *hbox, *label, *image; - - g_object_ref (ephy_embed_shell_get_default ()); - - mEntries[0] = mEntries[1] = nsnull; - - mDialog = GTK_DIALOG (gtk_dialog_new ()); - g_object_ref_sink (mDialog); - - char *title = NULL; - if (aTitle) - { - title = ConvertAndTruncateString (aTitle, MAX_TITLE_LENGTH); - } - - gtk_window_set_title (GTK_WINDOW (mDialog), title ? title : ""); - g_free (title); - - gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE); - - parent = EphyUtils::FindGtkParent (aParent); - if (GTK_IS_WINDOW (parent)) - { - gtk_window_set_transient_for (GTK_WINDOW (mDialog), - GTK_WINDOW (parent)); - - gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (parent)), - GTK_WINDOW (mDialog)); - } - - gtk_dialog_set_has_separator (mDialog, FALSE); - gtk_window_set_resizable (GTK_WINDOW (mDialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (mDialog), 5); - gtk_box_set_spacing (GTK_BOX (mDialog->vbox), 14); /* 2 * 5 + 14 = 24 */ - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (mDialog)->vbox), hbox); - - image = gtk_image_new_from_stock (aStock, 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); - - mVBox = gtk_vbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (hbox), mVBox, TRUE, TRUE, 0); - - char *text = NULL; - if (aText) - { - text = ConvertAndTruncateString (aText, MAX_MESSAGE_LENGTH); - } - - label = gtk_label_new (text); - g_free (text); - - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - /* Guard against overlong nonbreakable text (exploit) */ - gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); - - gtk_box_pack_start (GTK_BOX (mVBox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - - if (IsCalledFromScript ()) - { - gtk_dialog_add_button (GTK_DIALOG (mDialog), - _("_Abort Script"), - RESPONSE_ABORT_SCRIPT); - } - - gtk_widget_show (image); - gtk_widget_show (mVBox); - gtk_widget_show (hbox); -} - -Prompter::~Prompter () -{ - if (mSizeGroup) - { - g_object_unref (mSizeGroup); - } - - gtk_widget_destroy (GTK_WIDGET (mDialog)); - g_object_unref (mDialog); - - g_object_unref (ephy_embed_shell_get_default ()); -} - -void -Prompter::AddStockButton (const char *aStock, - int aResponse) -{ - gtk_dialog_add_button (GTK_DIALOG (mDialog), - aStock, aResponse); - ++mNumButtons; -} - -void -Prompter::AddButtonWithFlags (PRInt32 aNum, - PRUint32 aFlags, - const PRUnichar *aText, - PRUint32 aDefault) -{ - if (aFlags == 0) return; - - const char *label = NULL; - char *freeme = NULL; - gboolean isAffirmative = FALSE; - switch (aFlags) - { - case nsIPromptService::BUTTON_TITLE_OK: - label = GTK_STOCK_OK; - isAffirmative = TRUE; - break; - - case nsIPromptService::BUTTON_TITLE_CANCEL: - label = GTK_STOCK_CANCEL; - break; - - case nsIPromptService::BUTTON_TITLE_YES: - label = GTK_STOCK_YES; - isAffirmative = TRUE; - break; - - case nsIPromptService::BUTTON_TITLE_NO: - label = GTK_STOCK_NO; - break; - - case nsIPromptService::BUTTON_TITLE_SAVE: - label = GTK_STOCK_SAVE; - isAffirmative = TRUE; - break; - - case nsIPromptService::BUTTON_TITLE_DONT_SAVE: - label = _("Don't Save"); - break; - - case nsIPromptService::BUTTON_TITLE_REVERT: - label = GTK_STOCK_REVERT_TO_SAVED; - break; - - case nsIPromptService::BUTTON_TITLE_IS_STRING: - default: - label = freeme = ConvertAndEscapeButtonText (aText, MAX_BUTTON_TEXT_LENGTH); - /* We can't tell, so assume it's affirmative */ - isAffirmative = TRUE; - break; - } - - if (label == NULL) return; - - gtk_dialog_add_button (mDialog, label, aNum); - ++mNumButtons; - - if (isAffirmative && mDelay) - { - gtk_dialog_set_response_sensitive (mDialog, aNum, FALSE); - } - - if (!isAffirmative) - { - mUnaffirmativeResponse = aNum; - } - - if (aDefault) - { - mDefaultResponse = aNum; - } - - g_free (freeme); -} - -void -Prompter::AddButtonsWithFlags (PRUint32 aFlags, - const PRUnichar *aText0, - const PRUnichar *aText1, - const PRUnichar *aText2) -{ - mDelay = (aFlags & nsIPromptService::BUTTON_DELAY_ENABLE) != 0; - mDefaultResponse = -1; - - /* Reverse the order, on the assumption that what we passed is the - * 'windows' button order, and we want HIG order. - */ - AddButtonWithFlags (2, ((aFlags / nsIPromptService::BUTTON_POS_2) & 0xff), aText2, - aFlags & nsIPromptService::BUTTON_POS_2_DEFAULT); - AddButtonWithFlags (1, ((aFlags / nsIPromptService::BUTTON_POS_1) & 0xff), aText1, - aFlags & nsIPromptService::BUTTON_POS_1_DEFAULT); - AddButtonWithFlags (0, ((aFlags / nsIPromptService::BUTTON_POS_0) & 0xff), aText0, - aFlags & nsIPromptService::BUTTON_POS_0_DEFAULT); - - /* If no default was set, use the 'rightmost' unaffirmative response. - * This happens with the suite's password manager prompt. - */ - if (mDefaultResponse == -1) - { - mDefaultResponse = mUnaffirmativeResponse; - } -} - -void -Prompter::AddCheckbox (const PRUnichar *aText, - PRBool *aState) -{ - if (!aState || !aText) return; - - char *label = ConvertAndEscapeButtonText (aText, 2 * MAX_BUTTON_TEXT_LENGTH); - mCheck = gtk_check_button_new_with_mnemonic (label); - g_free (label); - - gtk_label_set_line_wrap (GTK_LABEL (GTK_BIN (mCheck)->child), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mCheck), *aState); - gtk_box_pack_start (GTK_BOX (mVBox), mCheck, FALSE, FALSE, 0); - gtk_widget_show (mCheck); -} - -void -Prompter::GetCheckboxState (PRBool *aState) -{ - if (!aState || !mCheck) return; - - *aState = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (mCheck)); -} - -void -Prompter::AddEntry (const char *aLabel, - const PRUnichar *aValue, - PRBool aIsPassword) -{ - if (!mSizeGroup) - { - mSizeGroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - } - - GtkWidget *hbox = gtk_hbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (mVBox), hbox, FALSE, FALSE, 0); - - GtkWidget *label = nsnull; - if (aLabel) - { - label = gtk_label_new_with_mnemonic (aLabel); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); - gtk_size_group_add_widget (mSizeGroup, label); - } - - GtkWidget *entry = mEntries[mNumEntries++] = gtk_entry_new (); - gtk_entry_set_visibility (GTK_ENTRY (entry), !aIsPassword); - gtk_entry_set_activates_default(GTK_ENTRY (entry), TRUE); - - if (aValue) - { - nsCString cValue; - NS_UTF16ToCString (nsDependentString(aValue), - NS_CSTRING_ENCODING_UTF8, cValue); - - gtk_entry_set_text (GTK_ENTRY (entry), cValue.get()); - } - - if (label) - { - gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); - } - - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - gtk_widget_show_all (hbox); -} - -void -Prompter::GetText (PRUint32 aNum, - PRUnichar **aValue) -{ - if (!aValue || !mEntries[aNum]) return; - - const char *text = gtk_entry_get_text (GTK_ENTRY (mEntries[aNum])); - if (!text) return; - - nsString value; - NS_CStringToUTF16 (nsDependentCString (text), - NS_CSTRING_ENCODING_UTF8, value); - - *aValue = NS_StringCloneData (value); -} - -void -Prompter::AddSelect (PRUint32 aCount, - const PRUnichar **aList, - PRInt32 aDefault) -{ - mCombo = gtk_combo_box_new_text (); - - for (PRUint32 i = 0; i < aCount; i++) - { - /* FIXME: use "" instead in this case? */ - if (!aList[i] || !aList[i][0]) continue; - - nsCString cData; - NS_UTF16ToCString (nsDependentString(aList[i]), NS_CSTRING_ENCODING_UTF8, cData); - - gtk_combo_box_append_text (GTK_COMBO_BOX (mCombo), cData.get()); - } - - gtk_combo_box_set_active (GTK_COMBO_BOX (mCombo), aDefault); - - gtk_box_pack_start (GTK_BOX (mVBox), mCombo, FALSE, FALSE, 0); - gtk_widget_show (mCombo); -} - -void -Prompter::GetSelected (PRInt32 *aSelected) -{ - if (!aSelected || !mCombo) return; - - *aSelected = gtk_combo_box_get_active (GTK_COMBO_BOX (mCombo)); -} - -static gboolean -EnableResponse (GtkDialog *aDialog) -{ - g_object_steal_data (G_OBJECT (aDialog), TIMEOUT_DATA_KEY); - - gtk_dialog_set_response_sensitive (aDialog, 0, TRUE); - gtk_dialog_set_response_sensitive (aDialog, 1, TRUE); - gtk_dialog_set_response_sensitive (aDialog, 2, TRUE); - - return FALSE; -} - -static void -RemoveTimeout (gpointer idptr) -{ - guint timeout = GPOINTER_TO_UINT (idptr); - - g_return_if_fail (timeout != 0); - - g_source_remove (timeout); -} - -PRInt32 -Prompter::Run (PRBool *aSuccess) -{ -#if 0 - AutoEventQueue queue; - if (NS_FAILED (queue.Init())) - { - if (aSuccess) - { - *aSuccess = PR_FALSE; - } - mSuccess = PR_FALSE; - - return GTK_RESPONSE_CANCEL; - } -#endif - - AutoModalDialog modalDialog (mWindow, PR_TRUE); - if (!modalDialog.ShouldShow ()) - return GTK_RESPONSE_CANCEL; - - if (mDelay) - { - guint timeout = g_timeout_add (TIMEOUT, - (GSourceFunc) EnableResponse, - mDialog); - g_object_set_data_full (G_OBJECT (mDialog), TIMEOUT_DATA_KEY, - GUINT_TO_POINTER (timeout), - (GDestroyNotify) RemoveTimeout); - } - - gtk_dialog_set_default_response (GTK_DIALOG (mDialog), mDefaultResponse); - - GtkWidget *widget = GTK_WIDGET (mDialog); - gtk_widget_show (widget); - mResponse = modalDialog.Run (mDialog); - gtk_widget_hide (widget); - - g_object_set_data (G_OBJECT (mDialog), TIMEOUT_DATA_KEY, NULL); - - mSuccess = (GTK_RESPONSE_ACCEPT == mResponse); - if (aSuccess) - { - *aSuccess = mSuccess; - } - - if (mResponse == RESPONSE_ABORT_SCRIPT) - { - PerformScriptAbortion (); - } - - return mResponse; -} - -static void -DeletePrompter (gpointer aPromptPtr, - GObject *aZombie) -{ - Prompter *prompt = static_cast<Prompter*>(aPromptPtr); - - delete prompt; -} - -void -Prompter::Show () -{ - /* We don't need it anymore */ - mWindow = nsnull; - - gtk_window_set_modal (GTK_WINDOW (mDialog), FALSE); - - g_signal_connect (mDialog, "response", - G_CALLBACK (gtk_widget_destroy), NULL); - g_object_weak_ref (G_OBJECT (mDialog), - (GWeakNotify) DeletePrompter, - static_cast<gpointer>(this)); - - gtk_widget_show (GTK_WIDGET (mDialog)); -} - -PRBool -Prompter::IsCalledFromScript() -{ -#if 0 - nsCOMPtr<nsIXPConnect> xpconnect (do_GetService (nsIXPConnect::GetCID())); - NS_ENSURE_TRUE (xpconnect, PR_FALSE); - - nsresult rv; - nsCOMPtr<nsIXPCNativeCallContext> ncc; - rv = xpconnect->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS (rv, PR_FALSE); - - if (!ncc) return PR_FALSE; - - JSContext *cx = nsnull; - rv = ncc->GetJSContext (&cx); - g_print ("GetJSContext rv=%x, cx=%p\n", rv, cx); - - NS_ENSURE_SUCCESS (rv, PR_FALSE); - - return cx != nsnull; -#endif - return PR_FALSE; -} - -void -Prompter::PerformScriptAbortion() -{ -#if 0 - /* FIXME: can we only stop the calling script, not all scripts in the context? */ - - nsCOMPtr<nsIXPConnect> xpconnect (do_GetService (nsIXPConnect::GetCID())); - NS_ENSURE_TRUE (xpconnect, ); - - nsresult rv; - nsCOMPtr<nsIXPCNativeCallContext> ncc; - rv = xpconnect->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS (rv, ); - NS_ENSURE_TRUE (ncc, ); - - JSContext *cx = nsnull; - rv = ncc->GetJSContext (&cx); - g_print ("GetJSContext rv=%x, cx=%p\n", rv, cx); - NS_ENSURE_SUCCESS (rv, ); - NS_ENSURE_TRUE (cx, ); - - g_print ("Would now disable scripts\n"); -// MozillaPrivate::SetScriptsEnabled (cx, PR_FALSE, PR_FALSE); -#endif -} - -char * -Prompter::ConvertAndTruncateString (const PRUnichar *aText, - PRInt32 aMaxLength) -{ - 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; -} - -char * -Prompter::ConvertAndEscapeButtonText(const PRUnichar *aText, - PRInt32 aMaxLength) -{ - char *converted = ConvertAndTruncateString (aText, aMaxLength); - if (converted == NULL) return NULL; - - char *escaped = (char*) g_malloc (strlen (converted) + 1); - char *q = escaped; - for (const char *p = converted; *p; ++p, ++q) - { - if (*p == '&') - { - if (*(p+1) == '&') - { - *q = '&'; - ++p; - } - else - { - *q = '_'; - } - } - else - { - *q = *p; - } - } - - /* Null termination */ - *q = '\0'; - - g_free (converted); - - return escaped; -} - -/* FIXME: needs THREADSAFE? */ -#ifdef ENABLE_AUTHPROMPT2 /* gecko 1.9 only */ -NS_IMPL_THEADSAFE_ISUPPORTS3 (EphyPromptService, - nsIPromptService, - nsIPromptService2, - nsINonBlockingAlertService) -#elif defined(HAVE_NSINONBLOCKINGALERTSERVICE_H) -NS_IMPL_ISUPPORTS2 (EphyPromptService, - nsIPromptService, - nsINonBlockingAlertService) -#else -NS_IMPL_ISUPPORTS1 (EphyPromptService, - nsIPromptService) -#endif - -EphyPromptService::EphyPromptService() -{ - LOG ("EphyPromptService ctor (%p)", this); -} - -EphyPromptService::~EphyPromptService() -{ - LOG ("EphyPromptService dtor (%p)", this); -} - -/* nsIPromptService implementation */ - -/* void alert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */ -NS_IMETHODIMP -EphyPromptService::Alert (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText) -{ - Prompter prompt (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.Run (); - - return NS_OK; -} - -/* void alertCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::AlertCheck (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - const PRUnichar *aCheckMsg, - PRBool *aCheckState) -{ - Prompter prompt (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - prompt.Run (); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* boolean confirm (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */ -NS_IMETHODIMP -EphyPromptService::Confirm (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - - Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.Run (_retval); - - return NS_OK; -} - -/* boolean confirmCheck (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::ConfirmCheck (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - const PRUnichar *aCheckMsg, - PRBool *aCheckState, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - - Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - prompt.Run (_retval); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* PRInt32 confirmEx (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in unsigned long aButtonFlags, in wstring aButton0Title, in wstring aButton1Title, in wstring aButton2Title, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::ConfirmEx (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRUint32 aButtonFlags, - const PRUnichar *aButton0Title, - const PRUnichar *aButton1Title, - const PRUnichar *aButton2Title, - const PRUnichar *aCheckMsg, - PRBool *aCheckState, - PRInt32 *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - - Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText); - prompt.AddButtonsWithFlags (aButtonFlags, aButton0Title, - aButton1Title, aButton2Title); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - *_retval = prompt.Run (nsnull); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* boolean prompt (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aValue, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::Prompt (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRUnichar **aValue, - const PRUnichar *aCheckMsg, - PRBool *aCheckState, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - NS_ENSURE_ARG_POINTER (aValue); - - Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddEntry (nsnull, *aValue, PR_FALSE); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - prompt.Run (_retval); - prompt.GetText (0, aValue); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* boolean promptUsernameAndPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aUsername, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::PromptUsernameAndPassword (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRUnichar **aUsername, - PRUnichar **aPassword, - const PRUnichar *aCheckMsg, - PRBool *aCheckState, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - NS_ENSURE_ARG_POINTER (aUsername); - NS_ENSURE_ARG_POINTER (aPassword); - - Prompter prompt (GTK_STOCK_DIALOG_AUTHENTICATION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddEntry (_("_Username:"), *aUsername, PR_FALSE); - prompt.AddEntry (_("_Password:"), *aPassword, PR_TRUE); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - prompt.Run (_retval); - prompt.GetText (0, aUsername); - prompt.GetText (1, aPassword); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* boolean promptPassword (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, inout wstring aPassword, in wstring aCheckMsg, inout boolean aCheckState); */ -NS_IMETHODIMP -EphyPromptService::PromptPassword (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRUnichar **aPassword, - const PRUnichar *aCheckMsg, - PRBool *aCheckState, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - NS_ENSURE_ARG_POINTER (aPassword); - - Prompter prompt (GTK_STOCK_DIALOG_AUTHENTICATION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddEntry (_("_Password:"), *aPassword, PR_TRUE); - prompt.AddCheckbox (aCheckMsg, aCheckState); - - // FIXME: Add a CAPSLOCK indicator? - - prompt.Run (_retval); - prompt.GetText (0, aPassword); - prompt.GetCheckboxState (aCheckState); - - return NS_OK; -} - -/* boolean select (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText, in PRUint32 aCount, [array, size_is (aCount)] in wstring aSelectList, out long aOutSelection); */ -NS_IMETHODIMP -EphyPromptService::Select (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText, - PRUint32 aCount, - const PRUnichar **aSelectList, - PRInt32 *aOutSelection, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - NS_ENSURE_ARG_POINTER (aOutSelection); - - Prompter prompt (GTK_STOCK_DIALOG_QUESTION, aParent, aDialogTitle, aText); - prompt.AddStockButton (GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); - prompt.AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt.AddSelect (aCount, aSelectList, *aOutSelection); - - prompt.Run (_retval); - prompt.GetSelected (aOutSelection); - - return NS_OK; -} - -#if HAVE_NSINONBLOCKINGALERTSERVICE_H - -/* showNonBlockingAlert (in nsIDOMWindow aParent, in wstring aDialogTitle, in wstring aText); */ -NS_IMETHODIMP -EphyPromptService::ShowNonBlockingAlert (nsIDOMWindow *aParent, - const PRUnichar *aDialogTitle, - const PRUnichar *aText) -{ - Prompter *prompt = new Prompter (GTK_STOCK_DIALOG_INFO, aParent, aDialogTitle, aText); - if (!prompt) return NS_ERROR_OUT_OF_MEMORY; - - prompt->AddStockButton (GTK_STOCK_OK, GTK_RESPONSE_ACCEPT); - prompt->Show (); - - return NS_OK; -} - -#endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */ - -#ifdef ENABLE_AUTHPROMPT2 - -static void -NS_GetAuthHostPort(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo, - PRBool machineProcessing, nsCString& host, PRInt32* port) -{ - nsCOMPtr<nsIURI> uri; - nsresult rv = aChannel->GetURI(getter_AddRefs(uri)); - if (NS_FAILED(rv)) - return; - - // Have to distinguish proxy auth and host auth here... - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - if (flags & nsIAuthInformation::AUTH_PROXY) { - nsCOMPtr<nsIProxiedChannel> proxied(do_QueryInterface(aChannel)); - NS_ASSERTION(proxied, "proxy auth needs nsIProxiedChannel"); - - nsCOMPtr<nsIProxyInfo> info; - proxied->GetProxyInfo(getter_AddRefs(info)); - NS_ASSERTION(info, "proxy auth needs nsIProxyInfo"); - - nsCAutoString idnhost; - info->GetHost(idnhost); - info->GetPort(port); - - if (machineProcessing) { - nsCOMPtr<nsIIDNService> idnService = - do_GetService(NS_IDNSERVICE_CONTRACTID); - if (idnService) { - idnService->ConvertUTF8toACE(idnhost, host); - } else { - // Not much we can do here... - host = idnhost; - } - } else { - host = idnhost; - } - } else { - if (machineProcessing) { - uri->GetAsciiHost(host); - *port = NS_GetRealPort(uri); - } else { - uri->GetHost(host); - uri->GetPort(port); - } - } -} - -static nsresult -MakeDialogText(nsIChannel* aChannel, nsIAuthInformation* aAuthInfo, - nsString& message) -{ - nsresult rv; - nsCOMPtr<nsIStringBundleService> bundleSvc = - do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr<nsIStringBundle> bundle; - rv = bundleSvc->CreateBundle("chrome://global/locale/prompts.properties", - getter_AddRefs(bundle)); - NS_ENSURE_SUCCESS(rv, rv); - - // figure out what message to display... - nsCAutoString host; - PRInt32 port; - NS_GetAuthHostPort(aChannel, aAuthInfo, PR_FALSE, host, &port); - - nsAutoString displayHost; - CopyUTF8toUTF16(host, displayHost); - - nsCOMPtr<nsIURI> uri; - aChannel->GetURI(getter_AddRefs(uri)); - - nsCAutoString scheme; - uri->GetScheme(scheme); - - nsAutoString username; - aAuthInfo->GetUsername(username); - - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - PRBool proxyAuth = (flags & nsIAuthInformation::AUTH_PROXY) != 0; - - nsAutoString realm; - aAuthInfo->GetRealm(realm); - - // Append the port if it was specified - if (port != -1) { - displayHost.Append(PRUnichar(':')); - displayHost.AppendInt(port); - } - - NS_NAMED_LITERAL_STRING(proxyText, "EnterUserPasswordForProxy"); - NS_NAMED_LITERAL_STRING(originText, "EnterUserPasswordForRealm"); - NS_NAMED_LITERAL_STRING(noRealmText, "EnterUserPasswordFor"); - NS_NAMED_LITERAL_STRING(passwordText, "EnterPasswordFor"); - - const PRUnichar *text; - if (proxyAuth) { - text = proxyText.get(); - } else { - text = originText.get(); - - // prepend "scheme://" - nsAutoString schemeU; - CopyASCIItoUTF16(scheme, schemeU); - schemeU.AppendLiteral("://"); - displayHost.Insert(schemeU, 0); - } - - const PRUnichar *strings[] = { realm.get(), displayHost.get() }; - PRUint32 count = NS_ARRAY_LENGTH(strings); - - if (flags & nsIAuthInformation::ONLY_PASSWORD) { - text = passwordText.get(); - strings[0] = username.get(); - } else if (!proxyAuth && realm.IsEmpty()) { - text = noRealmText.get(); - count--; - strings[0] = strings[1]; - } - - rv = bundle->FormatStringFromName(text, strings, count, getter_Copies(message)); - return rv; -} - -/* static */ nsresult -EphyPromptService::PromptPasswordAdapter(nsIPromptService* aService, - nsIDOMWindow* aParent, - nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - PRBool* retval) -{ - // construct the message string - nsString message; - MakeDialogText(aChannel, aAuthInfo, message); - - nsAutoString defaultUser, defaultDomain, defaultPass; - aAuthInfo->GetUsername(defaultUser); - aAuthInfo->GetDomain(defaultDomain); - aAuthInfo->GetPassword(defaultPass); - - PRUint32 flags; - aAuthInfo->GetFlags(&flags); - - if ((flags & nsIAuthInformation::NEED_DOMAIN) && !defaultDomain.IsEmpty()) { - defaultDomain.Append(PRUnichar('\\')); - defaultUser.Insert(defaultDomain, 0); - } - - // NOTE: Allocation failure is not fatal here (just default to empty string - // if allocation fails) - PRUnichar *user = ToNewUnicode(defaultUser), - *pass = ToNewUnicode(defaultPass); - nsresult rv; - if (flags & nsIAuthInformation::ONLY_PASSWORD) - rv = aService->PromptPassword(aParent, nsnull, message.get(), - &pass, aCheckLabel, - aCheckValue, retval); - else - rv = aService->PromptUsernameAndPassword(aParent, nsnull, message.get(), - &user, &pass, aCheckLabel, - aCheckValue, retval); - - nsString userStr(user); - nsString passStr(pass); - aAuthInfo->SetUsername(userStr); - aAuthInfo->SetPassword(passStr); - - return rv; -} - -/* boolean promptAuth (in nsIDOMWindow aParent, in nsIChannel aChannel, in PRUint32 level, in nsIAuthInformation authInfo, in wstring checkboxLabel, inout boolean checkValue); */ -NS_METHOD -EphyPromptService::PromptAuth(nsIDOMWindow *aParent, - nsIChannel *aChannel, - PRUint32 level, - nsIAuthInformation *authInfo, - const PRUnichar *checkboxLabel, - PRBool *checkValue, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER (_retval); - NS_ENSURE_ARG_POINTER (authInfo); - - return EphyPromptService::PromptPasswordAdapter(this, - aParent, - aChannel, - level, - authInfo, - checkboxLabel, - checkValue, - _retval); -} - -/* nsICancelable asyncPromptAuth (in nsIDOMWindow aParent, in nsIChannel aChannel, in nsIAuthPromptCallback aCallback, in nsISupports aContext, in PRUint32 level, in nsIAuthInformation authInfo, in wstring checkboxLabel, inout boolean checkValue); */ -NS_METHOD EphyPromptService::AsyncPromptAuth(nsIDOMWindow *aParent, - nsIChannel *aChannel, - nsIAuthPromptCallback *aCallback, - nsISupports *aContext, - PRUint32 level, - nsIAuthInformation *authInfo, - const PRUnichar *checkboxLabel, - PRBool *checkValue, - nsICancelable **_retval) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -#endif /* ENABLE_AUTHPROMPT2 */ diff --git a/embed/mozilla/EphyPromptService.h b/embed/mozilla/EphyPromptService.h deleted file mode 100644 index 0c2b1fa02..000000000 --- a/embed/mozilla/EphyPromptService.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright © 2005, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_PROMPT_SERVICE_H -#define EPHY_PROMPT_SERVICE_H - -#include <nsIPromptService.h> - -#if HAVE_NSINONBLOCKINGALERTSERVICE_H -#include <nsINonBlockingAlertService.h> -#endif - -#ifdef ENABLE_AUTHPROMPT2 -#include <nsIPromptService2.h> -#endif - -#define EPHY_PROMPT_SERVICE_IID \ -{ /* 6e8b90d4-78a6-41c5-98da-b1559a40d30d */ \ - 0x6e8b90d4, 0x78a6, 0x41c5, \ - { 0x98, 0xda, 0xb1, 0x55, 0x9a, 0x40, 0xd3, 0x0d } } - -#define EPHY_PROMPT_SERVICE_CLASSNAME "Epiphany Prompt Service" - -class EphyPromptService : -#ifdef ENABLE_AUTHPROMPT2 - public nsIPromptService2 -#else - public nsIPromptService -#endif -#if HAVE_NSINONBLOCKINGALERTSERVICE_H - , public nsINonBlockingAlertService -#endif -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPROMPTSERVICE -#ifdef ENABLE_AUTHPROMPT2 - NS_DECL_NSIPROMPTSERVICE2 -#endif -#if HAVE_NSINONBLOCKINGALERTSERVICE_H - NS_DECL_NSINONBLOCKINGALERTSERVICE -#endif - - EphyPromptService(); - virtual ~EphyPromptService(); - - protected: -#ifdef ENABLE_AUTHPROMPT2 - static nsresult PromptPasswordAdapter(nsIPromptService* aService, - nsIDOMWindow* aParent, - nsIChannel* aChannel, - PRUint32 aLevel, - nsIAuthInformation* aAuthInfo, - const PRUnichar* aCheckLabel, - PRBool* aCheckValue, - PRBool* retval); -#endif /* ENABLE_AUTHPROMPT2 */ -}; - -#endif /* EPHY_PROMPT_SERVICE_H */ diff --git a/embed/mozilla/EphyRedirectChannel.cpp b/embed/mozilla/EphyRedirectChannel.cpp deleted file mode 100644 index 6e493bfad..000000000 --- a/embed/mozilla/EphyRedirectChannel.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include "EphyRedirectChannel.h" - -NS_IMPL_ISUPPORTS2 (EphyWrappedChannel, nsIRequest, nsIChannel) - -NS_IMETHODIMP -EphyRedirectChannel::SetLoadFlags(nsLoadFlags aFlags) -{ - return mChannel->SetLoadFlags (aFlags | LOAD_REPLACE); -} diff --git a/embed/mozilla/EphyRedirectChannel.h b/embed/mozilla/EphyRedirectChannel.h deleted file mode 100644 index bcec1f1e5..000000000 --- a/embed/mozilla/EphyRedirectChannel.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2005 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_REDIRECT_CHANNEL_H -#define EPHY_REDIRECT_CHANNEL_H - -#include <nsCOMPtr.h> -#include <nsIChannel.h> - -class EphyWrappedChannel : public nsIChannel -{ - public: - NS_DECL_ISUPPORTS - NS_FORWARD_NSIREQUEST (mChannel->) - NS_FORWARD_NSICHANNEL (mChannel->) - - EphyWrappedChannel (nsIChannel *aChannel) : mChannel (aChannel) { } - virtual ~EphyWrappedChannel () { } - - protected: - nsCOMPtr<nsIChannel> mChannel; -}; - -class EphyRedirectChannel : public EphyWrappedChannel -{ - public: - EphyRedirectChannel (nsIChannel *aChannel) : EphyWrappedChannel (aChannel) { } - virtual ~EphyRedirectChannel () { } - - NS_IMETHOD SetLoadFlags (nsLoadFlags aFlags); -}; - -#endif /* !EPHY_REDIRECT_CHANNEL_H */ diff --git a/embed/mozilla/EphySidebar.cpp b/embed/mozilla/EphySidebar.cpp deleted file mode 100644 index 94bd52b8a..000000000 --- a/embed/mozilla/EphySidebar.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright © 2002 Philip Langdale - * Copyright © 2004 Crispin Flowerday - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsICategoryManager.h> -#include <nsIScriptNameSpaceManager.h> -#include <nsMemory.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOMCID.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsIClassInfoImpl.h> -#endif - -#include "ephy-debug.h" -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" - -#include "EphySidebar.h" - -NS_IMPL_ISUPPORTS1_CI(EphySidebar, nsISidebar) - -EphySidebar::EphySidebar() -{ -} - -EphySidebar::~EphySidebar() -{ -} - -/* void addPanel (in wstring aTitle, in string aContentURL, in string aCustomizeURL); */ -NS_IMETHODIMP -EphySidebar::AddPanel (const PRUnichar *aTitle, - const char *aContentURL, - const char *aCustomizeURL) -{ - NS_ENSURE_ARG (aTitle); - NS_ENSURE_ARG (aContentURL); - - nsCString title; - EphyEmbedSingle *single; - - /* FIXME: length-limit string */ - NS_UTF16ToCString (nsDependentString(aTitle), - NS_CSTRING_ENCODING_UTF8, title); - - LOG ("Adding sidebar, url=%s title=%s", aContentURL, title.get()); - - single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); - - gboolean result = FALSE; - g_signal_emit_by_name (single, "add-sidebar", - aContentURL, title.get(), &result); - - return NS_OK; -} - -/* void addPersistentPanel (in wstring aTitle, in string aContentURL, in string aCustomizeURL); */ -NS_IMETHODIMP -EphySidebar::AddPersistentPanel (const PRUnichar *aTitle, - const char *aContentURL, - const char *aCustomizeURL) -{ - return AddPanel (aTitle, aContentURL, aCustomizeURL); -} - -/* void addSearchEngine (in string engineURL, in string iconURL, in wstring suggestedTitle, in wst -ring suggestedCategory); */ -NS_IMETHODIMP -EphySidebar::AddSearchEngine (const char *aEngineURL, - const char *aIconURL, - const PRUnichar *aSuggestedTitle, - const PRUnichar *aSuggestedCategory) -{ - NS_ENSURE_ARG (aSuggestedTitle); - NS_ENSURE_ARG (aIconURL); - NS_ENSURE_ARG (aEngineURL); - - nsCString title; - EphyEmbedSingle *single; - - /* FIXME: length-limit string */ - NS_UTF16ToCString (nsDependentString(aSuggestedTitle), - NS_CSTRING_ENCODING_UTF8, title); - - LOG ("Adding search engine, engineurl=%s iconurl=%s title=%s", aEngineURL, aIconURL, title.get()); - - single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); - - gboolean result = FALSE; - g_signal_emit_by_name (single, "add-search-engine", - aEngineURL, aIconURL, title.get(), &result); - - return NS_OK; -} - -#ifdef HAVE_GECKO_1_9 - -/* void addMicrosummaryGenerator (in string generatorURL); */ -NS_IMETHODIMP -EphySidebar::AddMicrosummaryGenerator (const char *generatorURL) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -#endif /* HAVE_GECKO_1_9 */ - -/* static */ NS_METHOD -EphySidebar::Register (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const char* aComponentType, - const nsModuleComponentInfo* aInfo) -{ - nsresult rv; - nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = catMan->AddCategoryEntry (JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, - "sidebar", - NS_SIDEBAR_CONTRACTID, - PR_FALSE /* don't persist */, - PR_TRUE /* replace */, - nsnull); - NS_ENSURE_SUCCESS (rv, rv); - - return rv; -} - -/* static */ NS_METHOD -EphySidebar::Unregister (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const nsModuleComponentInfo* aInfo) -{ - nsresult rv; - nsCOMPtr<nsICategoryManager> catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = catMan->DeleteCategoryEntry (JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, - "sidebar", - PR_FALSE /* don't persist */); - NS_ENSURE_SUCCESS (rv, rv); - - return rv; -} diff --git a/embed/mozilla/EphySidebar.h b/embed/mozilla/EphySidebar.h deleted file mode 100644 index 37efa0bf8..000000000 --- a/embed/mozilla/EphySidebar.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2002 Philip Langdale - * Copyright © 2004 Crispin Flowerday - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_SIDEBAR_H -#define EPHY_SIDEBAR_H - -#include <nsISidebar.h> - -class nsIComponentManager; -class nsIFile; -struct nsModuleComponentInfo; - -#define EPHY_SIDEBAR_CLASSNAME \ - "Epiphany's Sidebar Implementation" - -#define EPHY_SIDEBAR_CID \ -{ /* {50f13159-f9b9-44b3-b18e-6ee5d85a202a} */ \ - 0x50f13159, \ - 0xf9b9, \ - 0x44b3, \ - {0xb1, 0x8e, 0x6e, 0xe5, 0xd8, 0x5a, 0x20, 0x2a} \ -} - -class EphySidebar : public nsISidebar -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSISIDEBAR - - EphySidebar(); - - static NS_METHOD Register (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const char* aComponentType, - const nsModuleComponentInfo* aInfo); - - static NS_METHOD Unregister (nsIComponentManager* aComponentManager, - nsIFile* aPath, - const char* aRegistryLocation, - const nsModuleComponentInfo* aInfo); - - private: - ~EphySidebar(); -}; - -#endif /* ! EPHY_SIDEBAR_H */ - diff --git a/embed/mozilla/EphySingle.cpp b/embed/mozilla/EphySingle.cpp deleted file mode 100644 index 74eaf21d6..000000000 --- a/embed/mozilla/EphySingle.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright © 2003 Christian Persch - * Copyright © 2003 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsICookie.h> -#include <nsICookie2.h> -#include <nsICookieManager.h> -#include <nsIHttpChannel.h> -#include <nsIObserverService.h> -#include <nsIPermission.h> -#include <nsIPermissionManager.h> -#include <nsIPropertyBag2.h> -#include <nsIServiceManager.h> -#include <nsIURI.h> -#include <nsServiceManagerUtils.h> -#include <nsWeakReference.h> - -#ifdef ALLOW_PRIVATE_API -#include <nsIIDNService.h> -#endif - -#include "ephy-debug.h" - -#include "EphySingle.h" - -NS_IMPL_ISUPPORTS1(EphySingle, nsIObserver) - -EphySingle::EphySingle() -: mOwner(nsnull) -, mIsOnline(PR_TRUE) /* nsIOService doesn't send an initial notification, assume we start on-line */ -{ - LOG ("EphySingle ctor"); -} - -nsresult -EphySingle::Init (EphyEmbedSingle *aOwner) -{ - mObserverService = do_GetService ("@mozilla.org/observer-service;1"); - NS_ENSURE_TRUE (mObserverService, NS_ERROR_FAILURE); - - nsresult rv; - rv = mObserverService->AddObserver (this, "cookie-changed", PR_FALSE); - rv |= mObserverService->AddObserver (this, "cookie-rejected", PR_FALSE); - rv |= mObserverService->AddObserver (this, "perm-changed", PR_FALSE); - rv |= mObserverService->AddObserver (this, "network:offline-status-changed", PR_FALSE); - rv |= mObserverService->AddObserver (this, "signonChanged", PR_FALSE); - rv |= mObserverService->AddObserver (this, "http-on-examine-response", PR_FALSE); - rv |= mObserverService->AddObserver (this, "http-on-modify-request", PR_FALSE); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - mOwner = aOwner; - - LOG ("EphySingle::Init"); - - return NS_OK; -} - -nsresult -EphySingle::Detach () -{ - LOG ("EphySingle::Detach"); - - if (mObserverService) - { - mObserverService->RemoveObserver (this, "cookie-changed"); - mObserverService->RemoveObserver (this, "cookie-rejected"); - mObserverService->RemoveObserver (this, "perm-changed"); - mObserverService->RemoveObserver (this, "signonChanged"); - mObserverService->RemoveObserver (this, "network:offline-status-changed"); - mObserverService->RemoveObserver (this, "http-on-examine-response"); - mObserverService->RemoveObserver (this, "http-on-modify-request"); - -#if 1 - /* HACK: Work around https://bugzilla.mozilla.org/show_bug.cgi?id=292699 */ - mObserverService->NotifyObservers(nsnull, "profile-change-net-teardown", nsnull); -#endif - } - - return NS_OK; -} - -EphySingle::~EphySingle() -{ - LOG ("EphySingle dtor"); - - mOwner = nsnull; -} - -nsresult -EphySingle::EmitCookieNotification (const char *name, - nsISupports *aSubject) -{ - LOG ("EmitCookieNotification %s", name); - - nsCOMPtr<nsICookie> cookie = do_QueryInterface (aSubject); - NS_ENSURE_TRUE (cookie, NS_ERROR_FAILURE); - - EphyCookie *info = mozilla_cookie_to_ephy_cookie (cookie); - - g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), name, info); - - ephy_cookie_free (info); - - return NS_OK; -} - -nsresult -EphySingle::EmitPermissionNotification (const char *name, - nsISupports *aSubject) -{ - LOG ("EmitPermissionNotification %s", name); - - nsCOMPtr<nsIPermission> perm = do_QueryInterface (aSubject); - NS_ENSURE_TRUE (perm, NS_ERROR_FAILURE); - - EphyPermissionInfo *info = - mozilla_permission_to_ephy_permission (perm); - - g_signal_emit_by_name (EPHY_PERMISSION_MANAGER (mOwner), name, info); - - ephy_permission_info_free (info); - - return NS_OK; -} - -nsresult -EphySingle::ExamineCookies (nsISupports *aSubject) -{ - PRBool isBlockingCookiesChannel = PR_FALSE; - - nsCOMPtr<nsIPropertyBag2> props (do_QueryInterface(aSubject)); - if (props && - NS_SUCCEEDED (props->GetPropertyAsBool( - NS_LITERAL_STRING("epiphany-blocking-cookies"), - &isBlockingCookiesChannel)) && - isBlockingCookiesChannel) - { - nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(aSubject)); - - if (httpChannel) - httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Cookie"), - EmptyCString(), PR_FALSE); - } - - return NS_OK; -} - -nsresult -EphySingle::ExamineResponse (nsISupports *aSubject) -{ - return ExamineCookies (aSubject); -} - -nsresult -EphySingle::ExamineRequest (nsISupports *aSubject) -{ - return ExamineCookies (aSubject); -} - -/* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */ -NS_IMETHODIMP EphySingle::Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *aData) -{ - nsresult rv = NS_OK; - - LOG ("EphySingle::Observe topic %s", aTopic); - - if (strcmp (aTopic, "http-on-examine-response") == 0) - { - rv = ExamineResponse (aSubject); - } - else if (strcmp (aTopic, "http-on-modify-request") == 0) - { - rv = ExamineRequest (aSubject); - } - else if (strcmp (aTopic, "cookie-changed") == 0) - { - /* "added" */ - if (aData[0] == 'a') - { - rv = EmitCookieNotification ("cookie-added", aSubject); - } - /* "deleted" */ - else if (aData[0] == 'd') - { - rv = EmitCookieNotification ("cookie-deleted", aSubject); - } - /* "changed" */ - else if (aData[0] == 'c' && aData[1] == 'h') - { - rv = EmitCookieNotification ("cookie-changed", aSubject); - } - /* "cleared" */ - else if (aData[0] == 'c' && aData[1] == 'l') - { - LOG ("EphySingle::cookie-changed::cleared"); - - g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), "cookies-cleared"); - } - else - { - g_warning ("EphySingle unexpected data!\n"); - rv = NS_ERROR_FAILURE; - } - } - else if (strcmp (aTopic, "cookie-rejected") == 0) - { - LOG ("EphySingle::cookie-rejected"); - - nsCOMPtr<nsIURI> uri = do_QueryInterface (aSubject); - if (uri) - { - nsCString spec; - uri->GetSpec (spec); - - g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), "cookie-rejected", spec.get()); - } - else - { - rv = NS_ERROR_FAILURE; - } - } - else if (strcmp (aTopic, "perm-changed") == 0) - { - /* "added" */ - if (aData[0] == 'a') - { - rv = EmitPermissionNotification ("permission-added", aSubject); - } - /* "deleted" */ - else if (aData[0] == 'd') - { - rv = EmitPermissionNotification ("permission-deleted", aSubject); - } - /* "changed" */ - else if (aData[0] == 'c' && aData[1] == 'h') - { - rv = EmitPermissionNotification ("permission-changed", aSubject); - } - /* "cleared" */ - else if (aData[0] == 'c' && aData[1] == 'l') - { - LOG ("EphySingle::perm-changed::cleared"); - - g_signal_emit_by_name (EPHY_PERMISSION_MANAGER (mOwner), "permissions-cleared"); - } - else - { - g_warning ("EphySingle unexpected data!\n"); - rv = NS_ERROR_FAILURE; - } - } - else if (strcmp (aTopic, "signonChanged") == 0) - { - /* aData can be PRUnichar[] "signons", "rejects", "nocaptures" and "nopreviews" */ - if (aData[0] == 's') - { - g_signal_emit_by_name (mOwner, "passwords-changed"); - } - } - else if (strcmp (aTopic, "network:offline-status-changed") == 0) - { - /* aData is either (PRUnichar[]) "offline" or "online" */ - mIsOnline = (aData && aData[0] == 'o' && aData[1] == 'n'); - - g_object_notify (G_OBJECT (mOwner), "network-status"); - } - else - { - g_warning ("EphySingle observed unknown topic '%s'!\n", aTopic); - rv = NS_ERROR_FAILURE; - } - - LOG ("EphySingle::Observe %s", NS_SUCCEEDED (rv) ? "success" : "FAILURE"); - - return rv; -} - -EphyCookie * -mozilla_cookie_to_ephy_cookie (nsICookie *cookie) -{ - EphyCookie *info; - - nsCString transfer; - - cookie->GetHost (transfer); - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, nsnull); - - nsCString decoded; - /* ToUTF8 never fails, no need to check return value */ - idnService->ConvertACEtoUTF8 (transfer, decoded); - - info = ephy_cookie_new (); - info->domain = g_strdup (decoded.get()); - - cookie->GetName (transfer); - info->name = g_strdup (transfer.get()); - cookie->GetValue (transfer); - info->value = g_strdup (transfer.get()); - cookie->GetPath (transfer); - info->path = g_strdup (transfer.get()); - - PRBool isSecure; - cookie->GetIsSecure (&isSecure); - info->is_secure = isSecure != PR_FALSE; - - PRUint64 dateTime; - cookie->GetExpires (&dateTime); - info->expires = dateTime; - - nsCOMPtr<nsICookie2> cookie2 = do_QueryInterface (cookie); - NS_ENSURE_TRUE (cookie2, info); - - PRBool isSession; - cookie2->GetIsSession (&isSession); - info->is_session = isSession != PR_FALSE; - - if (!isSession) - { - PRInt64 expiry; - cookie2->GetExpiry (&expiry); - info->real_expires = expiry; - } - -#ifdef HAVE_GECKO_1_9 - PRBool isHttpOnly = PR_FALSE; - cookie2->GetIsHttpOnly (&isHttpOnly); - info->is_http_only = isHttpOnly != PR_FALSE; -#endif - - return info; -} - -EphyPermissionInfo * -mozilla_permission_to_ephy_permission (nsIPermission *perm) -{ - nsresult rv; - nsCString type; - rv = perm->GetType(type); - NS_ENSURE_SUCCESS (rv, NULL); - - PRUint32 cap; - perm->GetCapability(&cap); - EphyPermission permission; - switch (cap) - { - case nsIPermissionManager::ALLOW_ACTION: - permission = EPHY_PERMISSION_ALLOWED; - break; - case nsIPermissionManager::DENY_ACTION: - permission = EPHY_PERMISSION_DENIED; - break; - case nsIPermissionManager::UNKNOWN_ACTION: - default : - permission = EPHY_PERMISSION_DEFAULT; - break; - } - - nsCString host; - perm->GetHost(host); - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, nsnull); - - nsCString decodedHost; - idnService->ConvertACEtoUTF8 (host, decodedHost); - - return ephy_permission_info_new (decodedHost.get(), type.get(), permission); -} diff --git a/embed/mozilla/EphySingle.h b/embed/mozilla/EphySingle.h deleted file mode 100644 index f30d7340a..000000000 --- a/embed/mozilla/EphySingle.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2003 Christian Persch - * Copyright © 2003 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_SINGLE_H -#define EPHY_SINGLE_H - -#include <nsCOMPtr.h> -#include <nsIObserver.h> -#include <nsIObserverService.h> - -#include "ephy-cookie-manager.h" -#include "ephy-embed-single.h" -#include "ephy-permission-manager.h" - -class nsICookie; -class nsIPermission; - -class EphySingle : public nsIObserver -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - - EphySingle(); - virtual ~EphySingle(); - - nsresult Init (EphyEmbedSingle *aOwner); - nsresult Detach (); - - PRBool IsOnline() { return mIsOnline; } - -protected: - nsresult EmitCookieNotification (const char *name, nsISupports *aSubject); - nsresult EmitPermissionNotification (const char *name, nsISupports *aSubject); - nsresult ExamineResponse (nsISupports *aSubject); - nsresult ExamineRequest (nsISupports *aSubject); - nsresult ExamineCookies (nsISupports *aSubject); - -private: - nsCOMPtr<nsIObserverService> mObserverService; - EphyEmbedSingle *mOwner; - PRBool mIsOnline; -}; - -EphyCookie *mozilla_cookie_to_ephy_cookie (nsICookie *cookie); - -EphyPermissionInfo *mozilla_permission_to_ephy_permission (nsIPermission *perm); - -#endif diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp deleted file mode 100644 index e5c4fb119..000000000 --- a/embed/mozilla/EphyUtils.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright © 2004 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <gtkmozembed.h> -#include <nsCOMPtr.h> -#include <nsIDOMWindow.h> -#include <nsIEmbeddingSiteWindow.h> -#include <nsIFile.h> -#include <nsIIOService.h> -#include <nsIServiceManager.h> -#include <nsIURI.h> -#include <nsIWebBrowserChrome.h> -#include <nsIWindowWatcher.h> -#include <nsIXPConnect.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOM.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsPIDOMWindow.h> -#include <nsIScriptContext.h> -#include <nsIScriptGlobalObject.h> -#endif - -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" -#include "ephy-file-helpers.h" - -#include "EphyUtils.h" - -nsresult -EphyUtils::GetIOService (nsIIOService **ioService) -{ - nsresult rv; - - nsCOMPtr<nsIServiceManager> mgr; - NS_GetServiceManager (getter_AddRefs (mgr)); - if (!mgr) return NS_ERROR_FAILURE; - - rv = mgr->GetServiceByContractID ("@mozilla.org/network/io-service;1", - NS_GET_IID (nsIIOService), - (void **)ioService); - return rv; -} - -nsresult -EphyUtils::NewURI (nsIURI **result, - const nsAString &spec, - const char *charset, - nsIURI *baseURI) -{ - nsCString cSpec; - NS_UTF16ToCString (spec, NS_CSTRING_ENCODING_UTF8, cSpec); - - return NewURI (result, cSpec, charset, baseURI); -} - -nsresult -EphyUtils::NewURI (nsIURI **result, - const nsACString &spec, - const char *charset, - nsIURI *baseURI) -{ - nsresult rv; - nsCOMPtr<nsIIOService> ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - return ioService->NewURI (spec, charset, baseURI, result); -} - -nsresult -EphyUtils::NewFileURI (nsIURI **result, - nsIFile *spec) -{ - nsresult rv; - nsCOMPtr<nsIIOService> ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - return ioService->NewFileURI (spec, result); -} - -GtkWidget * -EphyUtils::FindEmbed (nsIDOMWindow *aDOMWindow) -{ - if (!aDOMWindow) return nsnull; - - nsCOMPtr<nsIWindowWatcher> wwatch - (do_GetService("@mozilla.org/embedcomp/window-watcher;1")); - NS_ENSURE_TRUE (wwatch, nsnull); - - /* this DOM window may belong to some inner frame, we need - * to get the topmost DOM window to get the embed - */ - nsCOMPtr<nsIDOMWindow> topWindow; - aDOMWindow->GetTop (getter_AddRefs (topWindow)); - if (!topWindow) return nsnull; - - nsCOMPtr<nsIWebBrowserChrome> windowChrome; - wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome)); - NS_ENSURE_TRUE (windowChrome, nsnull); - - nsCOMPtr<nsIEmbeddingSiteWindow> window (do_QueryInterface(windowChrome)); - NS_ENSURE_TRUE (window, nsnull); - - nsresult rv; - GtkWidget *mozembed; - GtkWidget **cache_ptr = &mozembed; - rv = window->GetSiteWindow ((void **) cache_ptr); - NS_ENSURE_SUCCESS (rv, nsnull); - - return gtk_widget_get_parent (mozembed); -} - -GtkWidget * -EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow) -{ - GtkWidget *embed = FindEmbed (aDOMWindow); - if (!embed) return nsnull; - - GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (embed)); - if (!GTK_WIDGET_TOPLEVEL (toplevel)) return nsnull; - - return toplevel; -} - -char * -EphyUtils::ConvertUTF16toUTF8 (const PRUnichar *aText, - PRInt32 aMaxLength) -{ - 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; -} - -/* 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 () -{ -#if 1 - return PR_FALSE; -#else - nsresult rv; - nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); - NS_ENSURE_SUCCESS (rv, PR_FALSE); - - nsCOMPtr<nsIXPCNativeCallContext> ncc; - rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS(rv, PR_FALSE); - - return nsnull != ncc; -#endif -} - -/* NOTE: Only call this when we're SURE that we're called directly from JS! */ -nsIDOMWindow * -EphyJSUtils::GetDOMWindowFromCallContext () -{ - /* TODO: We could do this on 1.8, but we'd need to use headers which include private string API - * so we'll have to move this to MozillaPrivate - */ -#if 0 - nsresult rv; - nsCOMPtr<nsIXPConnect> xpc (do_GetService(nsIXPConnect::GetCID(), &rv)); - NS_ENSURE_SUCCESS (rv, nsnull); - - nsCOMPtr<nsIXPCNativeCallContext> ncc; - rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc)); - NS_ENSURE_SUCCESS (rv, nsnull); - - JSContext *cx = nsnull; - rv = ncc->GetJSContext(&cx); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && cx, nsnull); - - nsIScriptContext* scriptContext = GetScriptContextFromJSContext (cx); - if (!scriptContext) return nsnull; - - nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); - if (!globalObject) return nsnull; - - nsCOMPtr<nsPIDOMWindow> piWindow (do_QueryInterface (globalObject)); - if (!piWindow) return nsnull; - - return piWindow->GetOuterWindow (); -#else - return nsnull; -#endif -} diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h deleted file mode 100644 index 9d69fbb27..000000000 --- a/embed/mozilla/EphyUtils.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright © 2004 Marco Pesenti Gritti - * - * 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_UTILS_H -#define EPHY_UTILS_H - -// cannot include EphyUtils with internal strings! -#ifdef MOZILLA_INTERNAL_API -#error Cannot use EphyUtils with MOZILLA_INTERNAL_API -#endif - -#include <nscore.h> - -#include <gtk/gtkwidget.h> - -class nsACString; -class nsAString; -class nsIDOMWindow; -class nsIFile; -class nsIIOService; -class nsIURI; - -namespace EphyUtils -{ - nsresult GetIOService (nsIIOService **ioService); - - nsresult NewURI (nsIURI **result, - const nsAString &spec, - const char *charset = nsnull, - nsIURI *baseURI = nsnull); - - nsresult NewURI (nsIURI **result, - const nsACString &spec, - const char *charset = nsnull, - nsIURI *baseURI = nsnull); - - nsresult NewFileURI (nsIURI **result, - nsIFile *spec); - - GtkWidget *FindEmbed (nsIDOMWindow *aDOMWindow); - - GtkWidget *FindGtkParent (nsIDOMWindow *aDOMWindow); - - char * ConvertUTF16toUTF8 (const PRUnichar*, PRInt32); -} - -namespace EphyJSUtils -{ - PRBool IsCalledFromScript (); - - /* not addref'd! */ nsIDOMWindow* GetDOMWindowFromCallContext (); -} - -#endif diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp deleted file mode 100644 index 6e22fce8a..000000000 --- a/embed/mozilla/EventContext.cpp +++ /dev/null @@ -1,1105 +0,0 @@ -/* - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * Copyright © 2004 Crispin Flowerday - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <gdk/gdkkeysyms.h> - -#include <nsStringAPI.h> - -#include <nsComponentManagerUtils.h> -#include <nsIDOM3Node.h> -#include <nsIDOMAbstractView.h> -#include <nsIDOMCharacterData.h> -#include <nsIDOMCSSPrimitiveValue.h> -#include <nsIDOMCSSStyleDeclaration.h> -#include <nsIDOMDocument.h> -#include <nsIDOMDocumentView.h> -#include <nsIDOMElementCSSInlineStyle.h> -#include <nsIDOMElement.h> -#include <nsIDOMEvent.h> -#include <nsIDOMEventTarget.h> -#include <nsIDOMEventTarget.h> -#include <nsIDOMHTMLAnchorElement.h> -#include <nsIDOMHTMLAreaElement.h> -#include <nsIDOMHTMLBodyElement.h> -#include <nsIDOMHTMLButtonElement.h> -#include <nsIDOMHTMLEmbedElement.h> -#include <nsIDOMHTMLImageElement.h> -#include <nsIDOMHTMLInputElement.h> -#include <nsIDOMHTMLIsIndexElement.h> -#include <nsIDOMHTMLLabelElement.h> -#include <nsIDOMHTMLLegendElement.h> -#include <nsIDOMHTMLMapElement.h> -#include <nsIDOMHTMLObjectElement.h> -#include <nsIDOMHTMLSelectElement.h> -#include <nsIDOMHTMLTextAreaElement.h> -#include <nsIDOMKeyEvent.h> -#include <nsIDOMMouseEvent.h> -#include <nsIDOMNode.h> -#include <nsIDOMNodeList.h> -#include <nsIDOMNSHTMLDocument.h> -#include <nsIDOMNSUIEvent.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIServiceManager.h> -#include <nsIURI.h> - -#ifdef ALLOW_PRIVATE_API -#include <nsIDOMNSEvent.h> -#include <nsIDOMNSHTMLElement.h> -#include <nsIDOMViewCSS.h> -#include <nsIDOMViewCSS.h> -#include <nsIDOMXULDocument.h> -#include <nsITextToSubURI.h> -#endif - -#include "ephy-debug.h" - -#include "EphyBrowser.h" -#include "EphyUtils.h" - -#include "EventContext.h" - - -#define KEY_CODE 256 - -EventContext::EventContext () -{ - LOG ("EventContext ctor [%p]", this); -} - -EventContext::~EventContext () -{ - LOG ("EventContext dtor [%p]", this); -} - -nsresult EventContext::Init (EphyBrowser *browser) -{ - mBrowser = browser; - mDOMDocument = nsnull; - - return NS_OK; -} - -nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult) -{ - nsString text; - nsCOMPtr<nsIDOMNode> node; - aNode->GetFirstChild(getter_AddRefs(node)); - PRUint32 depth = 1; - - while (node && depth) - { - nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node)); - PRUint16 nodeType; - - node->GetNodeType(&nodeType); - if (charData && nodeType == nsIDOMNode::TEXT_NODE) - { - /* Add this text to our collection. */ - text += ' '; - nsString data; - charData->GetData(data); - text += data; - } - else - { - nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node)); - if (img) - { - nsString altText; - img->GetAlt(altText); - if (altText.Length()) - { - text = altText; - break; - } - } - } - - /* Find the next node to test. */ - PRBool hasChildNodes; - node->HasChildNodes(&hasChildNodes); - if (hasChildNodes) - { - nsCOMPtr<nsIDOMNode> temp = node; - temp->GetFirstChild(getter_AddRefs(node)); - depth++; - } - else - { - nsCOMPtr<nsIDOMNode> nextSibling; - node->GetNextSibling(getter_AddRefs(nextSibling)); - if (nextSibling) - { - node = nextSibling; - } - else - { - nsCOMPtr<nsIDOMNode> parentNode; - node->GetParentNode(getter_AddRefs(parentNode)); - if (!parentNode) - { - node = nsnull; - } - else - { - parentNode->GetNextSibling(getter_AddRefs(nextSibling)); - node = nextSibling; - depth--; - } - } - } - } - - /* FIXME we should trim spaces here */ - - aResult = text; - - return NS_OK; -} - -/* FIXME: we should resolve against the element's base, not the document's base */ -nsresult EventContext::ResolveBaseURL (const nsAString &relurl, nsACString &url) -{ - nsCString cRelURL; - NS_UTF16ToCString (relurl, NS_CSTRING_ENCODING_UTF8, cRelURL); - - return mBaseURI->Resolve (cRelURL, url); -} - -nsresult EventContext::Unescape (const nsACString &aEscaped, nsACString &aUnescaped) -{ - if (!aEscaped.Length()) return NS_ERROR_FAILURE; - - nsCOMPtr<nsITextToSubURI> escaper - (do_CreateInstance ("@mozilla.org/intl/texttosuburi;1")); - NS_ENSURE_TRUE (escaper, NS_ERROR_FAILURE); - - nsresult rv; - nsCString encoding; - rv = mBrowser->GetEncoding (encoding); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - nsString unescaped; - rv = escaper->UnEscapeURIForUI (encoding, aEscaped, unescaped); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && unescaped.Length(), NS_ERROR_FAILURE); - - NS_UTF16ToCString (unescaped, NS_CSTRING_ENCODING_UTF8, aUnescaped); - - return NS_OK; -} - -nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, - MozillaEmbedEvent *info) -{ - nsresult rv; - - const PRUnichar hrefLiteral[] = {'h', 'r', 'e', 'f', '\0'}; - const PRUnichar imgLiteral[] = {'i', 'm', 'g', '\0'}; - const PRUnichar typeLiteral[] = {'t', 'y', 'p', 'e', '\0'}; - const PRUnichar xlinknsLiteral[] = {'h', 't', 't', 'p', ':', '/', '/','w', - 'w', 'w', '.', 'w', '3', '.', 'o', 'r', - 'g', '/', '1', '9', '9', '9', '/', 'x', - 'l', 'i', 'n', 'k', '\0'}; - const PRUnichar bodyLiteral[] = { 'b', 'o', 'd', 'y', '\0' }; - - mEmbedEvent = info; - - info->context = EPHY_EMBED_CONTEXT_DOCUMENT; - - nsCOMPtr<nsIDOMNode> node = do_QueryInterface(EventTarget, &rv); - if (NS_FAILED(rv) || !node) return NS_ERROR_FAILURE; - - /* Is page xul ? then do not display context menus - * FIXME I guess there is an easier way ... */ - /* From philipl: This test needs to be here otherwise we - * arrogantly assume we can QI to a HTMLElement, which is - * not true for xul content. */ - - nsCOMPtr<nsIDOMDocument> domDoc; - rv = node->GetOwnerDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(rv) || !domDoc) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMXULDocument> xul_document = do_QueryInterface(domDoc); - if (xul_document) - { - info->context = EPHY_EMBED_CONTEXT_NONE; - return NS_ERROR_FAILURE; - } - - mDOMDocument = domDoc; - - rv = mBrowser->GetEncoding (mCharset); - NS_ENSURE_SUCCESS (rv, rv); - - /* Get base URI and CSS view */ - nsCOMPtr<nsIDOMDocumentView> docView (do_QueryInterface (domDoc)); - NS_ENSURE_TRUE (docView, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMAbstractView> abstractView; - docView->GetDefaultView (getter_AddRefs (abstractView)); - NS_ENSURE_TRUE (abstractView, NS_ERROR_FAILURE); - /* the abstract view is really the DOM window */ - - mViewCSS = do_QueryInterface (abstractView); - NS_ENSURE_TRUE (mViewCSS, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebNavigation> webNav (do_GetInterface (abstractView, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = webNav->GetCurrentURI (getter_AddRefs (mBaseURI)); - NS_ENSURE_SUCCESS (rv, rv); - - // Now we know that the page isn't a xul window, we can try and - // do something useful with it. - - PRUint16 type; - rv = node->GetNodeType(&type); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - PRBool has_image = PR_FALSE; - - nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(node); - if ((nsIDOMNode::ELEMENT_NODE == type) && element) - { - nsString uTag; - rv = element->GetLocalName(uTag); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - nsCString tag; - NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag); - - if (g_ascii_strcasecmp (tag.get(), "img") == 0) - { - nsString img; - nsCOMPtr <nsIDOMHTMLImageElement> image = - do_QueryInterface(node, &rv); - if (NS_FAILED(rv) || !image) return NS_ERROR_FAILURE; - - rv = image->GetSrc (img); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - SetStringProperty ("image", img); - info->context |= EPHY_EMBED_CONTEXT_IMAGE; - has_image = PR_TRUE; - } - else if (g_ascii_strcasecmp (tag.get(), "area") == 0) - { - nsCOMPtr <nsIDOMHTMLAreaElement> area = - do_QueryInterface(node, &rv); - if (NS_FAILED(rv) || !area) return NS_ERROR_FAILURE; - - // Parent node is the map itself - nsCOMPtr<nsIDOMNode> parentNode; - node->GetParentNode (getter_AddRefs(parentNode)); - - nsCOMPtr <nsIDOMHTMLMapElement> map = - do_QueryInterface(parentNode, &rv); - if (NS_FAILED(rv) || !area) return NS_ERROR_FAILURE; - - nsString mapName; - rv = map->GetName (mapName); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - // Now we are searching for all the images with a usemap attribute - nsCOMPtr<nsIDOMNodeList> imgs; - rv = mDOMDocument->GetElementsByTagName (nsString(imgLiteral), - getter_AddRefs (imgs)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - PRUint32 imgs_count; - rv = imgs->GetLength (&imgs_count); - if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - - for (PRUint32 i = 0; i < imgs_count; i++) - { - nsCOMPtr<nsIDOMNode> aNode; - rv = imgs->Item (i, getter_AddRefs (aNode)); - if (NS_FAILED (rv)) continue; - - nsCOMPtr<nsIDOMHTMLImageElement> img = - do_QueryInterface(aNode, &rv); - if (NS_FAILED(rv) || !img) continue; - - nsString imgMapName; - rv = img->GetUseMap (imgMapName); - if (NS_FAILED (rv)) continue; - - // usemap always starts with # - imgMapName.Cut (0,1); - - // Check if the current image is attached to the map we are looking for - if (imgMapName.Equals(mapName)) - { - nsString imgSrc; - rv = img->GetSrc (imgSrc); - if (NS_FAILED(rv)) continue; - - SetStringProperty ("image", imgSrc); - info->context |= EPHY_EMBED_CONTEXT_IMAGE; - has_image = PR_TRUE; - - break; - } - } - } - else if (g_ascii_strcasecmp (tag.get(), "input") == 0) - { - CheckInput (node); - } - else if (g_ascii_strcasecmp (tag.get(), "textarea") == 0) - { - info->context |= EPHY_EMBED_CONTEXT_INPUT; - } - else if (g_ascii_strcasecmp (tag.get(), "object") == 0) - { - nsCOMPtr<nsIDOMHTMLObjectElement> object; - object = do_QueryInterface (node); - if (!element) return NS_ERROR_FAILURE; - - nsString value; - object->GetType(value); - - nsCString cValue; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); - - // MIME types are always lower case - if (g_str_has_prefix (cValue.get(), "image/")) - { - nsString img; - - rv = object->GetData (img); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - nsCString cImg; - rv = ResolveBaseURL (img, cImg); - if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - - SetStringProperty ("image", cImg.get()); - info->context |= EPHY_EMBED_CONTEXT_IMAGE; - has_image = PR_TRUE; - } - else - { - info->context = EPHY_EMBED_CONTEXT_NONE; - return NS_OK; - } - } - else if (g_ascii_strcasecmp (tag.get(), "html") == 0) - { - /* Clicked on part of the page without a <body>, so - * look for a background image in the body tag */ - nsCOMPtr<nsIDOMNodeList> nodeList; - - rv = mDOMDocument->GetElementsByTagName (nsString(bodyLiteral), - getter_AddRefs (nodeList)); - if (NS_SUCCEEDED (rv) && nodeList) - { - nsCOMPtr<nsIDOMNode> bodyNode; - nodeList->Item (0, getter_AddRefs (bodyNode)); - - nsString cssurl; - rv = GetCSSBackground (bodyNode, cssurl); - if (NS_SUCCEEDED (rv)) - { - nsCString bgimg; - rv = ResolveBaseURL (cssurl, bgimg); - if (NS_FAILED (rv)) - return NS_ERROR_FAILURE; - - SetStringProperty ("image", bgimg.get()); - info->context |= EPHY_EMBED_CONTEXT_IMAGE; - has_image = PR_TRUE; - } - } - } - } - - /* Is page framed ? */ - PRBool framed; - IsPageFramed (node, &framed); - SetIntProperty ("framed_page", framed); - - /* Bubble out, looking for items of interest */ - while (node) - { - nsCOMPtr <nsIDOMElement> dom_elem = do_QueryInterface(node); - if (dom_elem) - { - nsString value; - dom_elem->GetAttributeNS (nsString(xlinknsLiteral), - nsString(typeLiteral), value); - - nsCString cValue; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); - - if (g_ascii_strcasecmp (cValue.get(), "simple") == 0) - { - info->context |= EPHY_EMBED_CONTEXT_LINK; - dom_elem->GetAttributeNS (nsString(xlinknsLiteral), - nsString(hrefLiteral), value); - - SetURIProperty (node, "link", value); - CheckLinkScheme (value); - } - } - - rv = node->GetNodeType(&type); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - element = do_QueryInterface(node); - if ((nsIDOMNode::ELEMENT_NODE == type) && element) - { - nsString uTag; - rv = element->GetLocalName(uTag); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - nsCString tag; - NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag); - - /* Link */ - if (g_ascii_strcasecmp (tag.get(), "a") == 0) - { - nsString tmp; - - rv = GatherTextUnder (node, tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("linktext", tmp); - - nsCOMPtr <nsIDOMHTMLAnchorElement> anchor = - do_QueryInterface(node); - - nsCString href; - anchor->GetHref (tmp); - NS_UTF16ToCString (tmp, NS_CSTRING_ENCODING_UTF8, href); - - if (g_str_has_prefix (href.get(), "mailto:")) - { - /* cut "mailto:" */ - href.Cut (0, 7); - - char *str = g_strdup (href.get()); - g_strdelimit (str, "?", '\0'); - - nsCString unescapedHref; - rv = Unescape (nsCString(str), unescapedHref); - if (NS_SUCCEEDED (rv) && unescapedHref.Length()) - { - SetStringProperty ("email", unescapedHref.get()); - info->context |= EPHY_EMBED_CONTEXT_EMAIL_LINK; - } - g_free (str); - } - - if (anchor && tmp.Length()) - { - info->context |= EPHY_EMBED_CONTEXT_LINK; - - SetURIProperty (node, "link", tmp); - CheckLinkScheme (tmp); - rv = anchor->GetHreflang (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_lang", tmp); - rv = anchor->GetTarget (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_target", tmp); - rv = anchor->GetRel (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_rel", tmp); - rv = anchor->GetRev (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_rev", tmp); - rv = element->GetTitle (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_title", tmp); - rv = anchor->GetType (tmp); - if (NS_SUCCEEDED(rv)) - SetStringProperty ("link_type", tmp); - - nsCString linkType; - NS_UTF16ToCString (tmp, NS_CSTRING_ENCODING_UTF8, linkType); - - if (g_ascii_strcasecmp (linkType.get(), "text/smartbookmark") == 0) - { - SetIntProperty ("link_is_smart", TRUE); - - nsCOMPtr<nsIDOMNode> childNode; - node->GetFirstChild (getter_AddRefs(childNode)); - if (childNode) - { - nsCOMPtr <nsIDOMHTMLImageElement> image = - do_QueryInterface(childNode, &rv); - - if (image) - { - nsString img; - rv = image->GetSrc (img); - if (!NS_FAILED(rv)) - { - SetStringProperty ("image", img); - } - } - } - } - else - { - SetIntProperty ("link_is_smart", FALSE); - } - } - - } - else if (g_ascii_strcasecmp (tag.get(), "option") == 0) - { - info->context = EPHY_EMBED_CONTEXT_NONE; - return NS_OK; - } - else if (g_ascii_strcasecmp (tag.get(), "area") == 0) - { - info->context |= EPHY_EMBED_CONTEXT_LINK; - nsCOMPtr <nsIDOMHTMLAreaElement> area = - do_QueryInterface(node, &rv); - if (NS_SUCCEEDED(rv) && area) - { - nsString href; - rv = area->GetHref (href); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - - SetURIProperty (node, "link", href); - CheckLinkScheme (href); - } - } - else if (g_ascii_strcasecmp (tag.get(), "input") == 0) - { - CheckInput (node); - } - else if (g_ascii_strcasecmp (tag.get(), "textarea") == 0) - { - info->context |= EPHY_EMBED_CONTEXT_INPUT; - } - - if (!has_image) - { - nsString cssurl; - rv = GetCSSBackground (node, cssurl); - if (NS_SUCCEEDED (rv)) - { - nsCString bgimg; - - rv = ResolveBaseURL (cssurl, bgimg); - if (NS_FAILED (rv)) - return NS_ERROR_FAILURE; - SetStringProperty ("image", bgimg.get()); - info->context |= EPHY_EMBED_CONTEXT_IMAGE; - has_image = PR_TRUE; - } - } - } - - nsCOMPtr<nsIDOMNode> parentNode; - node->GetParentNode (getter_AddRefs(parentNode)); - node = parentNode; - } - - return NS_OK; -} - -nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAString& url) -{ - if (!mViewCSS) return NS_ERROR_NOT_INITIALIZED; - - nsresult rv; - - const PRUnichar bgimage[] = {'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', 'n', 'd', - '-', 'i', 'm', 'a', 'g', 'e', '\0'}; - - nsCOMPtr<nsIDOMElement> element = do_QueryInterface (node); - NS_ENSURE_TRUE (element, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMCSSStyleDeclaration> decl; - mViewCSS->GetComputedStyle (element, nsString(), - getter_AddRefs (decl)); - NS_ENSURE_TRUE (decl, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMCSSValue> CSSValue; - decl->GetPropertyCSSValue (nsString(bgimage), - getter_AddRefs (CSSValue)); - - nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue = - do_QueryInterface (CSSValue); - if (!primitiveValue) return NS_ERROR_FAILURE; - - PRUint16 type; - rv = primitiveValue->GetPrimitiveType (&type); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - if (type != nsIDOMCSSPrimitiveValue::CSS_URI) return NS_ERROR_FAILURE; - - rv = primitiveValue->GetStringValue (url); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - return NS_OK; -} - -nsresult EventContext::GetTargetCoords (nsIDOMEventTarget *aTarget, PRInt32 *aX, PRInt32 *aY) -{ - /* Calculate the node coordinates relative to the widget origin */ - nsCOMPtr<nsIDOMNSHTMLElement> elem (do_QueryInterface(aTarget)); - - PRInt32 x = 0, y = 0; - while (elem) - { - PRInt32 val; - elem->GetOffsetTop(&val); y += val; - elem->GetScrollTop(&val); y -= val; - elem->GetOffsetLeft(&val); x += val; - elem->GetScrollLeft(&val); x -= val; - - nsCOMPtr<nsIDOMElement> parent; - elem->GetOffsetParent (getter_AddRefs (parent)); - elem = do_QueryInterface(parent); - } - - *aX = x; - *aY = y; - - return NS_OK; -} - -nsresult EventContext::GetMouseEventInfo (nsIDOMMouseEvent *aMouseEvent, MozillaEmbedEvent *info) -{ - /* FIXME: casting 32-bit guint* to PRUint16* below will break on big-endian */ - PRUint16 btn = 1729; - aMouseEvent->GetButton (&btn); - - switch (btn) - { - /* mozilla's button counting is one-off from gtk+'s */ - case 0: - info->button = 1; - break; - case 1: - info->button = 2; - break; - case 2: - info->button = 3; - break; - - case (PRUint16) -1: - /* when the user submits a form with Return, mozilla synthesises - * a _mouse_ click event with btn=65535 (-1). - */ - default: - info->button = 0; - break; - } - - if (info->button != 0) - { - /* OTOH, casting only between (un)signedness is safe */ - aMouseEvent->GetScreenX ((PRInt32*)&info->x); - aMouseEvent->GetScreenY ((PRInt32*)&info->y); - } - else /* this is really a keyboard event */ - { - nsCOMPtr<nsIDOMEventTarget> eventTarget; - aMouseEvent->GetTarget (getter_AddRefs (eventTarget)); - - GetTargetCoords (eventTarget, (PRInt32*)&info->x, (PRInt32*)&info->y); - } - - /* be sure we are not clicking on the scroolbars */ - - nsCOMPtr<nsIDOMNSEvent> nsEvent = do_QueryInterface(aMouseEvent); - if (!nsEvent) return NS_ERROR_FAILURE; - -#ifdef MOZ_NSIDOMNSEVENT_GETISTRUSTED - /* make sure the event is trusted */ - PRBool isTrusted = PR_FALSE; - nsEvent->GetIsTrusted (&isTrusted); - if (!isTrusted) return NS_ERROR_UNEXPECTED; -#endif /* MOZ_NSIDOMNSEVENT_GETISTRUSTED */ - - nsresult rv; - nsCOMPtr<nsIDOMEventTarget> OriginalTarget; - rv = nsEvent->GetOriginalTarget(getter_AddRefs(OriginalTarget)); - if (NS_FAILED (rv) || !OriginalTarget) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMNode> OriginalNode = do_QueryInterface(OriginalTarget); - if (!OriginalNode) return NS_ERROR_FAILURE; - - nsString nodename; - OriginalNode->GetNodeName(nodename); - nsCString cNodeName; - NS_UTF16ToCString (nodename, NS_CSTRING_ENCODING_UTF8, cNodeName); - - if (g_ascii_strcasecmp (cNodeName.get(), "xul:scrollbarbutton") == 0 || - g_ascii_strcasecmp (cNodeName.get(), "xul:thumb") == 0 || - g_ascii_strcasecmp (cNodeName.get(), "xul:vbox") == 0 || - g_ascii_strcasecmp (cNodeName.get(), "xul:spacer") == 0 || - g_ascii_strcasecmp (cNodeName.get(), "xul:slider") == 0) - return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMEventTarget> EventTarget; - rv = aMouseEvent->GetTarget(getter_AddRefs(EventTarget)); - if (NS_FAILED (rv) || !EventTarget) return NS_ERROR_FAILURE; - - rv = GetEventContext (EventTarget, info); - if (NS_FAILED (rv)) return rv; - - /* Get the modifier */ - - PRBool mod_key; - - info->modifier = 0; - - aMouseEvent->GetAltKey(&mod_key); - if (mod_key) info->modifier |= GDK_MOD1_MASK; - - aMouseEvent->GetShiftKey(&mod_key); - if (mod_key) info->modifier |= GDK_SHIFT_MASK; - - /* no need to check GetMetaKey, it's always PR_FALSE, - * see widget/src/gtk2/nsWindow.cpp:InitMouseEvent - */ - - aMouseEvent->GetCtrlKey(&mod_key); - if (mod_key) info->modifier |= GDK_CONTROL_MASK; - - return NS_OK; -} - -nsresult EventContext::GetKeyEventInfo (nsIDOMKeyEvent *aKeyEvent, MozillaEmbedEvent *info) -{ -#ifdef MOZ_NSIDOMNSEVENT_GETISTRUSTED - /* make sure the event is trusted */ - nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aKeyEvent)); - NS_ENSURE_TRUE (nsEvent, NS_ERROR_FAILURE); - - PRBool isTrusted = PR_FALSE; - nsEvent->GetIsTrusted (&isTrusted); - if (!isTrusted) return NS_ERROR_UNEXPECTED; -#endif /* MOZ_NSIDOMNSEVENT_GETISTRUSTED */ - - - info->button = 0; - - nsresult rv; - PRUint32 keyCode; - rv = aKeyEvent->GetKeyCode(&keyCode); - if (NS_FAILED(rv)) return rv; - info->keycode = keyCode; - - nsCOMPtr<nsIDOMEventTarget> target; - rv = aKeyEvent->GetTarget(getter_AddRefs(target)); - if (NS_FAILED(rv) || !target) return NS_ERROR_FAILURE; - - GetTargetCoords (target, (PRInt32*)&info->x, (PRInt32*)&info->y); - - /* Context */ - rv = GetEventContext (target, info); - if (NS_FAILED(rv)) return rv; - - /* Get the modifier */ - - PRBool mod_key; - - info->modifier = 0; - - aKeyEvent->GetAltKey(&mod_key); - if (mod_key) info->modifier |= GDK_MOD1_MASK; - - aKeyEvent->GetShiftKey(&mod_key); - if (mod_key) info->modifier |= GDK_SHIFT_MASK; - - aKeyEvent->GetMetaKey(&mod_key); - if (mod_key) info->modifier |= GDK_MOD2_MASK; - - aKeyEvent->GetCtrlKey(&mod_key); - if (mod_key) info->modifier |= GDK_CONTROL_MASK; - - return NS_OK; -} - -nsresult EventContext::IsPageFramed (nsIDOMNode *node, PRBool *Framed) -{ - nsresult rv; - - nsCOMPtr<nsIDOMDocument> mainDocument; - rv = mBrowser->GetDocument (getter_AddRefs(mainDocument)); - if (NS_FAILED (rv) || !mainDocument) return NS_ERROR_FAILURE; - - nsCOMPtr<nsIDOMDocument> nodeDocument; - rv = node->GetOwnerDocument (getter_AddRefs(nodeDocument)); - if (NS_FAILED (rv) || !nodeDocument) return NS_ERROR_FAILURE; - - *Framed = (mainDocument != nodeDocument); - - return NS_OK; -} - -nsresult EventContext::GetTargetDocument (nsIDOMDocument **domDoc) -{ - if (!mDOMDocument) return NS_ERROR_FAILURE; - - *domDoc = mDOMDocument.get(); - - NS_IF_ADDREF(*domDoc); - - return NS_OK; -} - -nsresult EventContext::CheckInput (nsIDOMNode *aNode) -{ - const PRUnichar typeLiteral[] = { 't', 'y', 'p', 'e', '\0' }; - - nsCOMPtr<nsIDOMElement> element; - element = do_QueryInterface (aNode); - if (!element) return NS_ERROR_FAILURE; - - nsString uValue; - element->GetAttribute (nsString(typeLiteral), uValue); - - nsCString value; - NS_UTF16ToCString (uValue, NS_CSTRING_ENCODING_UTF8, value); - - if (g_ascii_strcasecmp (value.get(), "image") == 0) - { - mEmbedEvent->context |= EPHY_EMBED_CONTEXT_IMAGE; - nsCOMPtr<nsIDOMHTMLInputElement> input; - input = do_QueryInterface (aNode); - if (!input) return NS_ERROR_FAILURE; - - nsresult rv; - nsString img; - rv = input->GetSrc (img); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - nsCString cImg; - rv = ResolveBaseURL (img, cImg); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - SetStringProperty ("image", cImg.get()); - } - else if (g_ascii_strcasecmp (value.get(), "radio") != 0 && - g_ascii_strcasecmp (value.get(), "submit") != 0 && - g_ascii_strcasecmp (value.get(), "reset") != 0 && - g_ascii_strcasecmp (value.get(), "hidden") != 0 && - g_ascii_strcasecmp (value.get(), "button") != 0 && - g_ascii_strcasecmp (value.get(), "checkbox") != 0) - { - mEmbedEvent->context |= EPHY_EMBED_CONTEXT_INPUT; - - if (g_ascii_strcasecmp (value.get(), "password") == 0) - { - mEmbedEvent->context |= EPHY_EMBED_CONTEXT_INPUT_PASSWORD; - } - } - - return NS_OK; -} - -nsresult EventContext::CheckLinkScheme (const nsAString &link) -{ - nsCOMPtr<nsIURI> uri; - EphyUtils::NewURI (getter_AddRefs (uri), link); - if (!uri) return NS_ERROR_FAILURE; - - nsresult rv; - nsCString scheme; - rv = uri->GetScheme (scheme); - if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - - if (g_ascii_strcasecmp (scheme.get(), "http") == 0 || - g_ascii_strcasecmp (scheme.get(), "https") == 0 || - g_ascii_strcasecmp (scheme.get(), "ftp") == 0 || - g_ascii_strcasecmp (scheme.get(), "file") == 0 || - g_ascii_strcasecmp (scheme.get(), "smb") == 0 || - g_ascii_strcasecmp (scheme.get(), "sftp") == 0 || - g_ascii_strcasecmp (scheme.get(), "ssh") == 0 || - g_ascii_strcasecmp (scheme.get(), "data") == 0 || - g_ascii_strcasecmp (scheme.get(), "resource") == 0 || - g_ascii_strcasecmp (scheme.get(), "about") == 0 || - g_ascii_strcasecmp (scheme.get(), "gopher") == 0) - { - SetIntProperty ("link-has-web-scheme", TRUE); - } - - return NS_OK; -} - -nsresult EventContext::SetIntProperty (const char *name, int value) -{ - - GValue *val = g_new0 (GValue, 1); - - g_value_init (val, G_TYPE_INT); - - g_value_set_int (val, value); - - mozilla_embed_event_set_property (mEmbedEvent, name, val); - - return NS_OK; -} - -nsresult EventContext::SetStringProperty (const char *name, const char *value) -{ - GValue *val = g_new0 (GValue, 1); - - g_value_init (val, G_TYPE_STRING); - - g_value_set_string (val, value); - - mozilla_embed_event_set_property (mEmbedEvent, name, val); - - return NS_OK; -} - -nsresult EventContext::SetStringProperty (const char *name, const nsAString &value) -{ - nsCString cValue; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); - return SetStringProperty (name, cValue.get()); -} - -nsresult EventContext::SetURIProperty (nsIDOMNode *node, const char *name, const nsACString &value) -{ - nsresult rv; - nsCOMPtr<nsIURI> uri; - rv = EphyUtils::NewURI (getter_AddRefs (uri), value, mCharset.Length () ? mCharset.get() : nsnull, mBaseURI); - if (NS_SUCCEEDED (rv) && uri) - { - /* Hide password part */ - nsCString user; - uri->GetUsername (user); - uri->SetUserPass (user); - - nsCString spec; - uri->GetSpec (spec); - rv = SetStringProperty (name, spec.get()); - } - else - { - rv = SetStringProperty (name, nsCString(value).get()); - } - - return rv; -} - -nsresult EventContext::SetURIProperty (nsIDOMNode *node, const char *name, const nsAString &value) -{ - nsCString cValue; - NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); - return SetURIProperty (node, name, cValue); -} - -/* static */ -PRBool -EventContext::CheckKeyPress (nsIDOMKeyEvent *aEvent) -{ - PRBool retval = PR_FALSE; - - /* make sure the event is trusted */ - nsCOMPtr<nsIDOMNSEvent> nsEvent (do_QueryInterface (aEvent)); - NS_ENSURE_TRUE (nsEvent, retval); - PRBool isTrusted = PR_FALSE; - nsEvent->GetIsTrusted (&isTrusted); - if (!isTrusted) return retval; - - /* check for alt/ctrl */ - PRBool isCtrl = PR_FALSE, isAlt = PR_FALSE; - aEvent->GetCtrlKey (&isCtrl); - aEvent->GetAltKey (&isAlt); - if (isCtrl || isAlt) return retval; - - nsCOMPtr<nsIDOMNSUIEvent> uiEvent (do_QueryInterface (aEvent)); - NS_ENSURE_TRUE (uiEvent, retval); - - /* check for already handled event */ - PRBool isPrevented = PR_FALSE; - uiEvent->GetPreventDefault (&isPrevented); - if (isPrevented) return retval; - - /* check for form controls */ - nsresult rv; - nsCOMPtr<nsIDOMEventTarget> target; - rv = aEvent->GetTarget (getter_AddRefs (target)); - NS_ENSURE_SUCCESS (rv, retval); - - nsCOMPtr<nsIDOMHTMLInputElement> inputElement (do_QueryInterface (target)); - if (inputElement) - { - nsString type; - inputElement->GetType (type); - - nsCString (cType); - NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType); - - if (g_ascii_strcasecmp (cType.get(), "text") == 0 || - g_ascii_strcasecmp (cType.get(), "password") == 0 || - g_ascii_strcasecmp (cType.get(), "file") == 0) return retval; - } - - nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea; - nsCOMPtr<nsIDOMHTMLSelectElement> selectElement; - nsCOMPtr<nsIDOMHTMLIsIndexElement> indexElement; - nsCOMPtr<nsIDOMHTMLObjectElement> objectElement; - nsCOMPtr<nsIDOMHTMLEmbedElement> embedElement; - - if ((textArea = do_QueryInterface (target)) || - (selectElement = do_QueryInterface (target)) || - (indexElement = do_QueryInterface (target)) || - (objectElement = do_QueryInterface (target)) || - (embedElement = do_QueryInterface (target))) return retval; - - /* check for design mode */ - nsCOMPtr<nsIDOMNode> node (do_QueryInterface (target, &rv)); - NS_ENSURE_SUCCESS (rv, PR_FALSE); - - nsCOMPtr<nsIDOMDocument> doc; - rv = node->GetOwnerDocument (getter_AddRefs (doc)); - NS_ENSURE_SUCCESS (rv, retval); - - nsCOMPtr<nsIDOMXULDocument> xul_document (do_QueryInterface(doc, &rv)); - if (xul_document) return retval; - - nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc (do_QueryInterface (doc)); - if (htmlDoc) - { - nsString uDesign; - rv = htmlDoc->GetDesignMode (uDesign); - NS_ENSURE_SUCCESS (rv, retval); - - nsCString design; - NS_UTF16ToCString (uDesign, NS_CSTRING_ENCODING_UTF8, design); - - retval = g_ascii_strcasecmp (design.get(), "on") != 0; - } - else - { - retval = PR_TRUE; - } - - return retval; -} diff --git a/embed/mozilla/EventContext.h b/embed/mozilla/EventContext.h deleted file mode 100644 index ddffcf1fc..000000000 --- a/embed/mozilla/EventContext.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright © 2000-2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EVENT_CONTEXT_H -#define EVENT_CONTEXT_H - -#include "ephy-embed.h" -#include "mozilla-embed-event.h" - -class EphyBrowser; -class nsIDOMDocument; -class nsIDOMEvent; -class nsIDOMEventTarget; -class nsIDOMHTMLAnchorElement; -class nsIDOMHTMLAreaElement; -class nsIDOMHTMLBodyElement; -class nsIDOMKeyEvent; -class nsIDOMMouseEvent; -class nsIDOMNode; -class nsIDOMViewCSS; -class nsIURI; - -class EventContext -{ -public: - EventContext(); - ~EventContext(); - - nsresult Init (EphyBrowser *wrapper); - nsresult GetMouseEventInfo (nsIDOMMouseEvent *event, MozillaEmbedEvent *info); - nsresult GetKeyEventInfo (nsIDOMKeyEvent *event, MozillaEmbedEvent *info); - nsresult GetTargetDocument (nsIDOMDocument **domDoc); - - static PRBool CheckKeyPress (nsIDOMKeyEvent *aEvent); - -private: - EphyBrowser *mBrowser; - MozillaEmbedEvent *mEmbedEvent; - nsCOMPtr<nsIDOMDocument> mDOMDocument; - nsCOMPtr<nsIDOMViewCSS> mViewCSS; - nsCOMPtr<nsIURI> mBaseURI; - nsCString mCharset; - - nsresult GetTargetCoords (nsIDOMEventTarget *aTarget, PRInt32 *aX, PRInt32 *aY); - nsresult GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult); - nsresult ResolveBaseURL (const nsAString &relurl, nsACString &url); - nsresult Unescape (const nsACString &aEscaped, nsACString &aUnescaped); - nsresult GetEventContext (nsIDOMEventTarget *EventTarget, - MozillaEmbedEvent *info); - nsresult GetCSSBackground (nsIDOMNode *node, nsAString& url); - nsresult IsPageFramed (nsIDOMNode *node, PRBool *Framed); - nsresult CheckInput (nsIDOMNode *node); - nsresult CheckLinkScheme (const nsAString &link); - nsresult SetIntProperty (const char *name, int value); - nsresult SetStringProperty (const char *name, const char *value); - nsresult SetStringProperty (const char *name, const nsAString &value); - nsresult SetURIProperty (nsIDOMNode *node, const char *name, const nsAString &value); - nsresult SetURIProperty (nsIDOMNode *node, const char *name, const nsACString &value); -}; - -#endif diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp deleted file mode 100644 index a35912809..000000000 --- a/embed/mozilla/FilePicker.cpp +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright © 2001 Philip Langdale - * Copyright © 2003, 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gconvert.h> -#include <glib/gi18n.h> -#include <gtk/gtkfilefilter.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkstock.h> - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsIDOMWindow.h> -#include <nsIFileURL.h> -#include <nsILocalFile.h> -#include <nsIPromptService.h> -#include <nsIServiceManager.h> -#include <nsIURI.h> -#include <nsNetCID.h> -#include <nsComponentManagerUtils.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOMCID.h> - -#include "ephy-debug.h" -#include "ephy-gui.h" -#include "ephy-prefs.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" - -#include "FilePicker.h" - -NS_IMPL_ISUPPORTS1(GFilePicker, nsIFilePicker) - -GFilePicker::GFilePicker() -: mDialog(nsnull) -, mMode(nsIFilePicker::modeOpen) -{ - LOG ("GFilePicker ctor (%p)", this); -} - -GFilePicker::~GFilePicker() -{ - LOG ("GFilePicker dtor (%p)", this); - - if (mDialog) - { - g_object_remove_weak_pointer (G_OBJECT (mDialog), (gpointer *) &mDialog); - gtk_widget_destroy (GTK_WIDGET (mDialog)); - } -} - -/* void init (in nsIDOMWindow parent, in AString title, in short mode); */ -NS_IMETHODIMP GFilePicker::Init(nsIDOMWindow *parent, const nsAString& title, PRInt16 mode) -{ - LOG ("GFilePicker::Init"); - - mParent = do_QueryInterface (parent); - - GtkWidget *gtkparent = EphyUtils::FindGtkParent (parent); - - NS_ENSURE_TRUE (gtkparent, NS_ERROR_FAILURE); - - - nsCString cTitle; - - NS_UTF16ToCString (title, NS_CSTRING_ENCODING_UTF8, cTitle); - - mMode = mode; - - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - switch (mode) - { - case nsIFilePicker::modeGetFolder: - action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; - break; - case nsIFilePicker::modeOpenMultiple: - case nsIFilePicker::modeOpen: - action = GTK_FILE_CHOOSER_ACTION_OPEN; - break; - case nsIFilePicker::modeSave: - action = GTK_FILE_CHOOSER_ACTION_SAVE; - break; - default: - g_assert_not_reached (); - break; - } - - mDialog = ephy_file_chooser_new (cTitle.get(), gtkparent, action, - CONF_STATE_UPLOAD_DIR, - EPHY_FILE_FILTER_NONE); - - if (parent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (gtkparent)), - GTK_WINDOW (mDialog)); - } - - if (mode == nsIFilePicker::modeOpenMultiple) - { - gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (mDialog), TRUE); - } - if (mMode == nsIFilePicker::modeSave) - { - gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (mDialog), TRUE); - } - - g_object_add_weak_pointer (G_OBJECT (mDialog), (gpointer *) &mDialog); - - return NS_OK; -} - -/* void appendFilters (in long filterMask); */ -NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 filterMask) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - LOG ("GFilePicker::AppendFilters mask=%d", filterMask); - - // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/res/locale/en-US/filepicker.properties - // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/src/nsFilePicker.js line 131 ff - - if (filterMask & nsIFilePicker::filterAll) - { - ephy_file_chooser_add_pattern_filter (mDialog, _("All files"), - "*", (char*) NULL); - } - if (filterMask & nsIFilePicker::filterHTML) - { - ephy_file_chooser_add_mime_filter (mDialog, _("Web pages"), - "text/html", - "application/xhtml+xml", - "text/xml", - (char *) NULL); - } - if (filterMask & nsIFilePicker::filterText) - { - ephy_file_chooser_add_pattern_filter (mDialog, _("Text files"), - "*.txt", "*.text", NULL); - } - if (filterMask & nsIFilePicker::filterImages) - { - ephy_file_chooser_add_mime_filter (mDialog, _("Images"), - "image/png", - "image/jpeg", - "image/gif", - (char *) NULL); - } - if (filterMask & nsIFilePicker::filterXML) - { - ephy_file_chooser_add_pattern_filter (mDialog, _("XML files"), - "*.xml", (char *) NULL); - } - if (filterMask & nsIFilePicker::filterXUL) - { - ephy_file_chooser_add_pattern_filter (mDialog, _("XUL files"), - "*.xul", (char *) NULL); - } - - return NS_OK; -} - -/* void appendFilter (in AString title, in AString filter); */ - -NS_IMETHODIMP GFilePicker::AppendFilter(const nsAString& title, const nsAString& filter) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - LOG ("GFilePicker::AppendFilter"); - - if (!filter.Length()) return NS_ERROR_FAILURE; - - nsCString pattern; - NS_UTF16ToCString (filter, NS_CSTRING_ENCODING_UTF8, pattern); - - char **patterns; - patterns = g_strsplit (pattern.get(), ";", -1); - if (!patterns) return NS_ERROR_FAILURE; - - GtkFileFilter *filth; - filth = gtk_file_filter_new (); - - for (int i = 0; patterns[i] != NULL; i++) - { - gtk_file_filter_add_pattern (filth, g_strstrip (patterns[i])); - } - - nsCString cTitle; - NS_UTF16ToCString (title, NS_CSTRING_ENCODING_UTF8, cTitle); - - gtk_file_filter_set_name (filth, cTitle.get()); - - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (mDialog), filth); - - g_strfreev (patterns); - - return NS_OK; -} - -/* attribute AString defaultString; */ -NS_IMETHODIMP GFilePicker::GetDefaultString(nsAString& aDefaultString) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - LOG ("GFilePicker::GetDefaultString"); - - aDefaultString = mDefaultString; - - return NS_OK; -} - -NS_IMETHODIMP GFilePicker::SetDefaultString(const nsAString& aDefaultString) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - mDefaultString.Assign (aDefaultString); - - if (mMode == nsIFilePicker::modeSave) - { - nsCString defaultString; - NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_UTF8, - defaultString); - - LOG ("GFilePicker::SetDefaultString %s", defaultString.get()); - - if (!defaultString.Length()) return NS_ERROR_FAILURE; - - /* set_current_name takes UTF-8, not a filename */ - gtk_file_chooser_set_current_name - (GTK_FILE_CHOOSER (mDialog), defaultString.get()); - } - - return NS_OK; -} - -/* attribute AString defaultExtension; */ -NS_IMETHODIMP GFilePicker::GetDefaultExtension(nsAString& aDefaultExtension) -{ - LOG ("GFilePicker::GetDefaultExtension"); - - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP GFilePicker::SetDefaultExtension(const nsAString& aDefaultExtension) -{ - LOG ("GFilePicker::SetDefaultExtension"); - - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute long filterIndex; */ -NS_IMETHODIMP GFilePicker::GetFilterIndex(PRInt32 *aFilterIndex) -{ - LOG ("GFilePicker::GetFilterIndex"); - - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP GFilePicker::SetFilterIndex(PRInt32 aFilterIndex) -{ - LOG ("GFilePicker::SetFilterIndex index=%d", aFilterIndex); - - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute nsILocalFile displayDirectory; */ -NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - LOG ("GFilePicker::GetDisplayDirectory"); - - char *dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (mDialog)); - - if (dir != NULL) - { - nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - file->InitWithNativePath (nsCString (dir)); - NS_IF_ADDREF (*aDisplayDirectory = file); - - g_free (dir); - } - - return NS_OK; -} - -NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - nsCString dir; - aDisplayDirectory->GetNativePath (dir); - - LOG ("GFilePicker::SetDisplayDirectory to %s", dir.get()); - - if (mDefaultString.Length() && mMode != nsIFilePicker::modeSave) - { - nsCString defaultString; - NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, - defaultString); - - char *filename = g_build_filename (dir.get(), defaultString.get(), (char *) NULL); - LOG ("Setting filename to %s", filename); - gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (mDialog), filename); - g_free (filename); - } - else - { - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog), - dir.get()); - } - - return NS_OK; -} - -/* readonly attribute nsILocalFile file; */ -NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile **aFile) -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - char *filename; - - LOG ("GFilePicker::GetFile"); - - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); - - if (filename != NULL) - { - nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - file->InitWithNativePath (nsCString (filename)); - NS_IF_ADDREF (*aFile = file); - - g_free (filename); - } - - return NS_OK; -} - -#ifdef HAVE_GECKO_1_9 -/* readonly attribute nsIURI fileURL; */ -NS_IMETHODIMP GFilePicker::GetFileURL(nsIURI **aFileURL) -#else -/* readonly attribute nsIFileURL fileURL; */ -NS_IMETHODIMP GFilePicker::GetFileURL(nsIFileURL **aFileURL) -#endif -{ - NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - - LOG ("GFilePicker::GetFileURL"); - - nsCOMPtr<nsILocalFile> file; - GetFile (getter_AddRefs(file)); - NS_ENSURE_TRUE (file, NS_ERROR_FAILURE); - - nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance (NS_STANDARDURL_CONTRACTID); - fileURL->SetFile(file); - NS_IF_ADDREF(*aFileURL = fileURL); - - return NS_OK; -} - -/* readonly attribute nsISimpleEnumerator files; */ -NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles) -{ - // Not sure if we need to implement it at all, it's used nowhere - // in mozilla, but I guess a javascript might call it? - - LOG ("GFilePicker::GetFiles"); - - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* short show (); */ -NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval) -{ - AutoModalDialog modalDialog (mParent, PR_FALSE); - if (!modalDialog.ShouldShow ()) { - *_retval = nsIFilePicker::returnCancel; - return NS_OK; - } - - mParent = nsnull; - - LOG ("GFilePicker::Show"); - - gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE); - gtk_window_set_destroy_with_parent (GTK_WINDOW (mDialog), FALSE); - - /* If there's just the "ALL" filter, it's no use showing the filters! */ - GSList *filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (mDialog)); - if (g_slist_length (filters) == 1) - { - GtkFileFilter *filter = GTK_FILE_FILTER (filters->data); - const char *name = gtk_file_filter_get_name (filter); - - if (!name || strcmp (name, _("All files")) == 0) - { - gtk_file_chooser_remove_filter (GTK_FILE_CHOOSER (mDialog), - filter); - } - } - g_slist_free (filters); - - gtk_widget_show (GTK_WIDGET (mDialog)); - - int response; - char *filename = NULL; - - do - { - response = modalDialog.Run (GTK_DIALOG (mDialog)); - - g_free (filename); - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); - - LOG ("GFilePicker::Show response=%d, filename=%s", response, filename); - } - while (response == GTK_RESPONSE_ACCEPT && - mMode == nsIFilePicker::modeSave && - !ephy_gui_check_location_writable (GTK_WIDGET (mDialog), filename)); - - gtk_widget_hide (GTK_WIDGET (mDialog)); - - if (response == GTK_RESPONSE_ACCEPT && filename != NULL) - { - *_retval = nsIFilePicker::returnOK; - } - else - { - *_retval = nsIFilePicker::returnCancel; - } - - g_free (filename); - - return NS_OK; -} diff --git a/embed/mozilla/FilePicker.h b/embed/mozilla/FilePicker.h deleted file mode 100644 index fa63c56b1..000000000 --- a/embed/mozilla/FilePicker.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright © 2001 Philip Langdale - * Copyright © 2003 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_FILEPICKER_H -#define EPHY_FILEPICKER_H - -#include <nsIFilePicker.h> - -class nsIDOMWindow; - -#include "ephy-file-chooser.h" - -#define G_FILEPICKER_CID \ -{ /* 3636dc79-0b42-4bad-8a3f-ae15d3671d17 */ \ - 0x3636dc79, \ - 0x0b42, \ - 0x4bad, \ - {0x8a, 0x3f, 0xae, 0x15, 0xd3, 0x67, 0x1d, 0x17} \ -} - -#define G_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1" -#define G_FILEPICKER_CLASSNAME "Epiphany File Picker Implementation" - -class nsIFactory; - -extern nsresult NS_NewFilePickerFactory(nsIFactory** aFactory); - -class GFilePicker : public nsIFilePicker -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIFILEPICKER - - GFilePicker(); - virtual ~GFilePicker(); - -private: - EphyFileChooser *mDialog; - PRInt16 mMode; - nsString mDefaultString; - nsCOMPtr<nsIDOMWindow> mParent; -}; - -#endif diff --git a/embed/mozilla/GeckoCookiePromptService.cpp b/embed/mozilla/GeckoCookiePromptService.cpp deleted file mode 100644 index b228e7c93..000000000 --- a/embed/mozilla/GeckoCookiePromptService.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright © 2003 Tommi Komulainen <tommi.komulainen@iki.fi> - * Copyright © 2004, 2007 Christian Persch - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * 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 <glib/gi18n.h> - -#include <gtk/gtkbox.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkwindow.h> - -#include <nsStringAPI.h> - -#include "ephy-debug.h" -#include "ephy-gui.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" - -#include "GeckoCookiePromptService.h" - -NS_IMPL_ISUPPORTS1 (GeckoCookiePromptService, nsICookiePromptService) - -GeckoCookiePromptService::GeckoCookiePromptService() -{ - LOG ("GeckoCookiePromptService ctor [%p]", this); -} - -GeckoCookiePromptService::~GeckoCookiePromptService() -{ - LOG ("GeckoCookiePromptService dtor [%p]", this); -} - -/* boolean cookieDialog (in nsIDOMWindow parent, in nsICookie cookie, in ACString hostname, in long cookiesFromHost, in boolean changingCookie, inout boolean checkValue); */ -NS_IMETHODIMP -GeckoCookiePromptService::CookieDialog (nsIDOMWindow *aParent, - nsICookie *aCookie, - const nsACString &aHostname, - PRInt32 aCookiesFromHost, - PRBool aChangingCookie, - PRBool *_checkValue, - PRBool *_retval) -{ - NS_ENSURE_ARG (aParent); - NS_ENSURE_ARG (aCookie); - NS_ENSURE_ARG_POINTER (_checkValue); - NS_ENSURE_ARG_POINTER (_retval); - - // TODO short-circuit and accept session cookies as per preference - // TODO until mozilla starts supporting it natively? - - AutoModalDialog modalDialog (aParent, PR_FALSE); - if (!modalDialog.ShouldShow ()) { - *_retval = PR_FALSE; - *_checkValue = PR_FALSE; - return NS_OK; - } - - GtkWindow *parent = modalDialog.GetParent (); - NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER); - - nsCString host(aHostname); - - GtkWidget *dialog = gtk_message_dialog_new - (parent, - GTK_DIALOG_MODAL /* FIXME mozilla sucks! */, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - _("Accept cookie from %s?"), - host.get()); - GtkWindow *window = GTK_WINDOW (dialog); - GtkDialog *gdialog = GTK_DIALOG (dialog); - GtkMessageDialog *message_dialog = GTK_MESSAGE_DIALOG (dialog); - - gtk_window_set_icon_name (window, EPHY_STOCK_EPHY); - gtk_window_set_title (window, _("Accept Cookie?")); - - if (aChangingCookie) { - gtk_message_dialog_format_secondary_text - (message_dialog, - _("The site wants to modify an existing cookie.")); - } else if (aCookiesFromHost == 0) { - gtk_message_dialog_format_secondary_text - (message_dialog, - _("The site wants to set a cookie.")); - } else if (aCookiesFromHost == 1) { - gtk_message_dialog_format_secondary_text - (message_dialog, - _("The site wants to set a second cookie.")); - } else { - char *num_text = g_strdup_printf - (ngettext ("You already have %d cookie from this site.", - "You already have %d cookies from this site.", - aCookiesFromHost), - aCookiesFromHost); - - gtk_message_dialog_format_secondary_text - (message_dialog, - "The site %s wants to set another cookie. %s", - host.get(), num_text); - g_free (num_text); - } - - GtkWidget *checkbutton; - checkbutton = gtk_check_button_new_with_mnemonic - (_("Apply this _decision to all cookies from this site")); - gtk_widget_show (checkbutton); - gtk_box_pack_start (GTK_BOX (ephy_gui_message_dialog_get_content_box (dialog)), - checkbutton, FALSE, FALSE, 0); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), *_checkValue); - - gtk_dialog_add_button (gdialog, - _("_Reject"), GTK_RESPONSE_REJECT); - gtk_dialog_add_button (gdialog, - _("_Accept"), GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response (gdialog, GTK_RESPONSE_ACCEPT); - - int response = modalDialog.Run (gdialog); - - if (response == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_REJECT) { - *_retval = (response == GTK_RESPONSE_ACCEPT); - *_checkValue = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton)); - } else { - /* if the dialog was closed, but no button was pressed, - * consider it as 'Reject' but ignore the checkbutton - */ - *_retval = PR_FALSE; - *_checkValue = PR_FALSE; - } - - gtk_widget_destroy (dialog); - - return NS_OK; -} diff --git a/embed/mozilla/GeckoCookiePromptService.h b/embed/mozilla/GeckoCookiePromptService.h deleted file mode 100644 index 7092a2982..000000000 --- a/embed/mozilla/GeckoCookiePromptService.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2003 Tommi Komulainen <tommi.komulainen@iki.fi> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * 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 COOKIEPROMPTSERVICE_H -#define COOKIEPROMPTSERVICE_H - -#include <nsICookiePromptService.h> - -/* 50766a18-0b34-41d9-8f6c-4612200e6556 */ -#define EPHY_COOKIEPROMPTSERVICE_CID \ - { 0x50766a18, 0x0b34, 0x41d9, { 0x8f, 0x6c, 0x46, 0x12, 0x20, 0x0e, 0x65, 0x56 } } - -#define EPHY_COOKIEPROMPTSERVICE_CLASSNAME "Epiphany Cookie Prompt Service" -#define EPHY_COOKIEPROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/cookieprompt-service;1" - -class GeckoCookiePromptService : public nsICookiePromptService { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSICOOKIEPROMPTSERVICE - - GeckoCookiePromptService(); - - private: - ~GeckoCookiePromptService(); -}; - -#endif /* COOKIEPROMPTSERVICE_H */ diff --git a/embed/mozilla/GeckoFormSigningDialog.cpp b/embed/mozilla/GeckoFormSigningDialog.cpp deleted file mode 100644 index cf538c145..000000000 --- a/embed/mozilla/GeckoFormSigningDialog.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gtk/gtk.h> -#include <glade/glade-xml.h> - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.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 "AutoModalDialog.h" -#include "EphyUtils.h" - -#include "GeckoFormSigningDialog.h" - -#define LITERAL(s) reinterpret_cast<const nsAString::char_type*>(NS_L(s)) - -NS_IMPL_ISUPPORTS1 (GeckoFormSigningDialog, - nsIFormSigningDialog) - -GeckoFormSigningDialog::GeckoFormSigningDialog() -{ - LOG ("GeckoFormSigningDialog ctor [%p]", this); -} - -GeckoFormSigningDialog::~GeckoFormSigningDialog() -{ - LOG ("GeckoFormSigningDialog dtor [%p]", this); -} - -/* nsIFormSigningDialog implementation */ - -/* boolean confirmSignText (in nsIInterfaceRequestor ctxt, - in AString host, - in AString signText, - [array, size_is (count)] in wstring certNickList, - [array, size_is (count)] in wstring certDetailsList, - in PRUint32 count, - out PRInt32 selectedIndex, - out AString password); */ -NS_IMETHODIMP -GeckoFormSigningDialog::ConfirmSignText (nsIInterfaceRequestor *ctx, - const nsAString & host, - const nsAString & signText, - const PRUnichar **certNickList, - const PRUnichar **certDetailsList, - PRUint32 count, - PRInt32 *selectedIndex, - nsAString &_password, - PRBool *_cancelled) -{ - /* FIXME: limit |signText| to a sensitlbe length (maybe 100k)? */ - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - if (!parent) { - parent = EphyJSUtils::GetDOMWindowFromCallContext (); - g_print ("Fallback window %p\n", (void*)parent.get()); - } - GtkWidget *gparent = EphyUtils::FindGtkParent (parent); - - AutoModalDialog modalDialog (parent, PR_TRUE); - if (!modalDialog.ShouldShow ()) { - *_cancelled = PR_TRUE; - return NS_OK; - } - - GladeXML *gxml = glade_xml_new (ephy_file ("form-signing-dialog.glade"), - "form_signing_dialog", NULL); - g_return_val_if_fail (gxml, NS_ERROR_FAILURE); - - GtkWidget *dialog = glade_xml_get_widget (gxml, "form_signing_dialog"); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (gparent)); - - GtkLabel *primary_label = GTK_LABEL (glade_xml_get_widget (gxml, "primary_label")); - char *primary = g_strdup_printf (_("The web site “%s” requests that you sign the following text:"), - NS_ConvertUTF16toUTF8 (host).get ()); - gtk_label_set_text (primary_label, primary); - g_free (primary); - - GtkTextView *textview = GTK_TEXT_VIEW (glade_xml_get_widget (gxml, "textview")); - NS_ConvertUTF16toUTF8 text (signText); - gtk_text_buffer_set_text (gtk_text_view_get_buffer (textview), - text.get (), text.Length ()); - - GtkTable *table = GTK_TABLE (glade_xml_get_widget (gxml, "table")); - GtkComboBox *combo = GTK_COMBO_BOX (gtk_combo_box_new_text ()); - for (PRUint32 i = 0; i < count; ++i) { - gtk_combo_box_append_text (combo, NS_ConvertUTF16toUTF8 (certNickList[i]).get ()); - } - - gtk_combo_box_set_active (combo, 0); - gtk_table_attach (table, GTK_WIDGET (combo), 1, 2, 0, 1, - GtkAttachOptions (0), GtkAttachOptions (0), 0, 0); - gtk_widget_show (GTK_WIDGET (combo)); - - /* FIXME: Add "View Certificate" button */ - - GtkEntry *password_entry = GTK_ENTRY (glade_xml_get_widget (gxml, "password_entry")); - - GtkWidget *button = gtk_dialog_add_button (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Sign text"), - GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); - gtk_widget_grab_focus (button); - - /* FIXME: make Sign insensitive for some time (proportional to text length, with maximum?) */ - - g_object_unref (gxml); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - - *_cancelled = response != GTK_RESPONSE_ACCEPT; - - if (response == GTK_RESPONSE_ACCEPT) { - _password = NS_ConvertUTF8toUTF16 (gtk_entry_get_text (password_entry)); - *selectedIndex = gtk_combo_box_get_active (combo); - } - - gtk_widget_destroy (dialog); - - return NS_OK; -} diff --git a/embed/mozilla/GeckoFormSigningDialog.h b/embed/mozilla/GeckoFormSigningDialog.h deleted file mode 100644 index a4438e9d1..000000000 --- a/embed/mozilla/GeckoFormSigningDialog.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef GECKO_FORMSIGNINGDIALOGS_H -#define GECKO_FORMSIGNINGDIALOGS_H - -#include <nsIFormSigningDialog.h> - -/* 4e42a43e-fbc5-40cc-bcbb-8cbc4e2101eb */ -#define GECKO_FORMSIGNINGDIALOGS_CID \ -{ 0x4e42a43e, 0xfbc5, 0x40cc, { 0xbc, 0xbb, 0x8c, 0xbc, 0x4e, 0x21, 0x01, 0xeb } } - -#define GECKO_FORMSIGNINGDIALOGS_CLASSNAME "Gecko Form Signing Dialogs" - -class GeckoFormSigningDialog : public nsIFormSigningDialog -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIFORMSIGNINGDIALOG - - GeckoFormSigningDialog(); - ~GeckoFormSigningDialog(); -}; - -#endif /* GECKO_FORMSIGNINGDIALOGS_H */ diff --git a/embed/mozilla/GeckoPrintService.cpp b/embed/mozilla/GeckoPrintService.cpp deleted file mode 100644 index de2020397..000000000 --- a/embed/mozilla/GeckoPrintService.cpp +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Copyright © 2006, 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib.h> -#include <glib/gi18n.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkprintunixdialog.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkwindow.h> -#include <glade/glade-xml.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-gui.h" -#include "ephy-prefs.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" -#include "GeckoPrintSession.h" - -#include "GeckoPrintService.h" - -/* Some printing keys */ - -#define CONF_PRINT_BG_COLORS "/apps/epiphany/dialogs/print_background_colors" -#define CONF_PRINT_BG_IMAGES "/apps/epiphany/dialogs/print_background_images" -#define CONF_PRINT_COLOR "/apps/epiphany/dialogs/print_color" -#define CONF_PRINT_DATE "/apps/epiphany/dialogs/print_date" -#define CONF_PRINT_PAGE_NUMBERS "/apps/epiphany/dialogs/print_page_numbers" -#define CONF_PRINT_PAGE_TITLE "/apps/epiphany/dialogs/print_page_title" -#define CONF_PRINT_PAGE_URL "/apps/epiphany/dialogs/print_page_url" - -#define LITERAL(s) 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) -#define NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+4) - -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); - - /* Print settings changes disallowed, just translate the settings */ - if (eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_PRINT_SETUP)) { - return PrintUnattended (aParent, aSettings); - } - - /* Not locked down, show the dialogue */ - - nsresult rv; -#if 0 - PRBool haveSelection = PR_FALSE; - rv = aSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &haveSelection); - NS_ENSURE_SUCCESS (rv, rv); -#endif - - PRInt16 frameUI = nsIPrintSettings::kFrameEnableAll; - rv = aSettings->GetHowToEnableFrameUI (&frameUI); - NS_ENSURE_SUCCESS (rv, rv); - - AutoModalDialog modalDialog (aParent, PR_TRUE); - if (!modalDialog.ShouldShow ()) - return NS_ERROR_ABORT; - - GtkWindow *parent = modalDialog.GetParent (); - NS_ENSURE_TRUE(parent, NS_ERROR_INVALID_POINTER); - - EphyEmbedShell *shell = ephy_embed_shell_get_default (); - - GladeXML *xml = glade_xml_new (ephy_file ("print.glade"), - "print_dialog_custom_tab", NULL); - if (!xml) { - return NS_ERROR_FAILURE; - } - - /* Build the custom tab */ - GtkWidget *custom_tab = glade_xml_get_widget (xml, "custom_tab_container"); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_bg_colors_checkbutton"), CONF_PRINT_BG_COLORS); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_bg_images_checkbutton"), CONF_PRINT_BG_IMAGES); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_date_checkbutton"), CONF_PRINT_DATE); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_page_numbers_checkbutton"), CONF_PRINT_PAGE_NUMBERS); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_page_title_checkbutton"), CONF_PRINT_PAGE_TITLE); - ephy_gui_connect_checkbutton_to_gconf (glade_xml_get_widget (xml, "print_page_url_checkbutton"), CONF_PRINT_PAGE_URL); - - GtkWidget *frame_box = glade_xml_get_widget (xml, "frame_box"); - GtkWidget *print_frames_normal = glade_xml_get_widget (xml, "print_frames_normal"); - GtkWidget *print_frames_selected = glade_xml_get_widget (xml, "print_frames_selected"); - GtkWidget *print_frames_separately = glade_xml_get_widget (xml, "print_frames_separately"); - - /* FIXME: store/load from pref */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print_frames_normal), TRUE); - - if (frameUI == nsIPrintSettings::kFrameEnableAll) { - /* Allow all frame options */ - gtk_widget_set_sensitive (frame_box, TRUE); - } else if (frameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) { - /* Allow all except "selected frame" */ - gtk_widget_set_sensitive (frame_box, TRUE); - gtk_widget_set_sensitive (print_frames_selected, FALSE); - /* Preselect this one, since the default above only prints _one page_ ! */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (print_frames_separately), TRUE); - } - - /* 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); - - GtkPrintCapabilities capabilities = - GtkPrintCapabilities (GTK_PRINT_CAPABILITY_PAGE_SET | - GTK_PRINT_CAPABILITY_COPIES | - GTK_PRINT_CAPABILITY_COLLATE | - GTK_PRINT_CAPABILITY_REVERSE | - GTK_PRINT_CAPABILITY_SCALE | - GTK_PRINT_CAPABILITY_GENERATE_PS); -#ifdef HAVE_GECKO_1_9 - capabilities = GtkPrintCapabilities (capabilities | GTK_PRINT_CAPABILITY_GENERATE_PDF); -#endif - gtk_print_unix_dialog_set_manual_capabilities (print_dialog, capabilities); - - 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)); - - /* Remove custom tab from its dummy window and put it in the print dialogue */ - g_object_ref_sink (custom_tab); - gtk_container_remove (GTK_CONTAINER (custom_tab->parent), custom_tab); - gtk_print_unix_dialog_add_custom_tab (print_dialog, custom_tab, - gtk_label_new (_("Options"))); /* FIXME better name! */ - g_object_unref (custom_tab); - g_object_unref (xml); - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - int response = modalDialog.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; - } - - PRInt16 printFrames = nsIPrintSettings::kNoFrames; - if (frameUI != nsIPrintSettings::kFrameEnableNone) { - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_normal))) { - printFrames = nsIPrintSettings::kFramesAsIs; - } else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_selected))) { - printFrames = nsIPrintSettings::kSelectedFrame; - } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (print_frames_separately))) { - printFrames = nsIPrintSettings::kEachFrameSep; - } - } - - GtkPageSetup *pageSetup = gtk_print_unix_dialog_get_page_setup (print_dialog); /* no reference owned */ - 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); - - /* We copy the setup and settings so we can modify them to unset - * options handled by gecko. - */ - GtkPageSetup *pageSetupCopy = gtk_page_setup_copy (pageSetup); - pageSetup = pageSetupCopy; - - GtkPrintSettings *settingsCopy = gtk_print_settings_copy (settings); - g_object_unref (settings); - settings = settingsCopy; - - rv = session->SetSettings (aSettings, 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, printer, sourceFile, printFrames, PR_TRUE, aSettings); - } else { - rv = NS_ERROR_FAILURE; - } - } - - gtk_widget_destroy (dialog); - - g_object_unref (settings); - g_object_unref (pageSetup); - - 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); - - /* Our 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) -{ - /* This function is never called from gecko code */ -#if 0 - /* 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; - } - - AutoWindowModalState modalState (aParent); - - 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; -#endif - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* 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; -} - -/* Private methods */ - -#if 0 -typedef struct -{ - GMainLoop *mainLoop; - GtkPrinter *mPrinter; - guint timeout; - int response; - guint cancelled : 1; -} FindPrinterData; - -static void -FreeFindPrinterData (FindPrinterData *data) -{ - if (data->printer) { - g_object_unref (data->printer); - } -} - -static void -DialogResponseCallback (GtkWidget *aDialog, - int aResponse, - FindPrinterData *data) -{ - data->response = aResponse; - g_main_loop_quit (data->mainloop); -} - -static void -TimeoutCallback (FindPrinterData *data) -{ - data->cancelled = TRUE; - g_main_loop_quit (data->mainLoop); - data->mainLoop = NULL; - return FALSE; -} - -static gboolean -PrinterEnumerateCallback (GtkPrinter *aPrinter, - FindPrinterData *data) -{ - if (data->cancelled) - return TRUE; - - if ((data->printerName && - strcmp (data->printerName, gtk_printer_get_name (aPrinter)) == 0) || - (!data->printerName && - gtk_printer_is_default (aPrinter))) { - data->printer = g_object_ref (aPrinter); - return TRUE; - } - - return FALSE; -} -#endif - -nsresult -GeckoPrintService::PrintUnattended (nsIDOMWindow *aParent, - nsIPrintSettings *aPrintSettings) -{ - return NS_ERROR_NOT_IMPLEMENTED; -#if 0 - 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; - } - - AutoWindowModalState modalState (aParent); - - EphyEmbedShell *shell = ephy_embed_shell_get_default (); - GtkPrintSettings *settings = ephy_embed_shell_get_print_settings (shell); - NS_ENSURE_TRUE (settings, NS_ERROR_FAILURE); - - const char *printer = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_PRINTER); -#if 0 - if (!printer || !printer[0]) { - return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; - } -#endif - /* We need to find the printer, so we need to run a mainloop. - * If called from a script, give the user a way to cancel the print; - * otherwise we'll just show a generic progress message. - */ - GtkWidget *dialog; - if (isCalledFromScript) { - dialog = gtk_message_dialog_new (GTK_WINDOW (parent), - GtkDialogFlags (0), - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_CANCEL, - "%s", _("Print this page?")); - gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_PRINT, - GTK_RESPONSE_ACCEPT); - } else { - dialog = gtk_message_dialog_new (GTK_WINDOW (parent), - GtkDialogFlags (0), - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_CANCEL, - "%s", _("Preparing to print")); - } - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - - FindPrinterData *data = g_new0 (PrinterData, 1); - data->dialog = dialog; - - g_signal_connect (dialog, "response", - G_CALLBACK (DialogResponseCallback), data); - - /* Don't run forever */ - data->timeoutId = g_timeout_add (PRINTER_ENUMERATE_TIMEOUT, - (GSourceFunc) EnumerateTimoutCallback, - data); - /* Enumerate printers until we find our printer */ - gtk_enumerate_printers ((GtkPrinterFunc) PrinterEnumerateCallback, - data, - (GDestroyNotify) EnumerateDestroyCallback, FALSE); - - /* Now run the mainloop */ - int response = gtk_dialog_run (GTK_DIALOG (dialog)); - Printer - gtk_widget_destroy (dialog); - - if (response != GTK_RESPONSE_ACCEPT) { - return NS_ERROR_ABORT; - } - - nsCString sourceFile; - session->GetSourceFile (sourceFile); - if (!sourceFile.IsEmpty ()) { - rv = TranslateSettings (settings, - ephy_embed_shell_get_page_setup (shell), - sourceFile, PR_TRUE, aSettings); - } else { - rv = NS_ERROR_FAILURE; - } - - return rv; - } -#endif /* if 0 */ -} - -/* Static methods */ - -/* static */ nsresult -GeckoPrintService::TranslateSettings (GtkPrintSettings *aGtkSettings, - GtkPageSetup *aPageSetup, - GtkPrinter *aPrinter, - const nsACString &aSourceFile, - PRInt16 aPrintFrames, - PRBool aIsForPrinting, - nsIPrintSettings *aSettings) -{ - NS_ENSURE_ARG (aPrinter); - NS_ENSURE_ARG (aGtkSettings); - NS_ENSURE_ARG (aPageSetup); - -#if 0 - /* 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; - } -#endif - - GtkPrintCapabilities capabilities = gtk_printer_get_capabilities (aPrinter); - - /* Initialisation */ - aSettings->SetIsInitializedFromPrinter (PR_FALSE); /* FIXME: PR_TRUE? */ - aSettings->SetIsInitializedFromPrefs (PR_FALSE); /* FIXME: PR_TRUE? */ - aSettings->SetPrintSilent (PR_FALSE); - aSettings->SetShowPrintProgress (PR_TRUE); - - /* 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) { -#ifdef HAVE_GECKO_1_9 - NS_ENSURE_TRUE (aPrinter, NS_ERROR_FAILURE); - - const char *format = gtk_print_settings_get (aGtkSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT); - if (!format) - format = "ps"; - - if (strcmp (format, "pdf") == 0 && - gtk_printer_accepts_pdf (aPrinter)) { - aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPDF); - } else if (strcmp (format, "ps") == 0 && - gtk_printer_accepts_ps (aPrinter)) { - aSettings->SetOutputFormat (nsIPrintSettings::kOutputFormatPS); - } else { - g_warning ("Output format '%s' specified, but printer '%s' does not support it!", - format, gtk_printer_get_name (aPrinter)); - return NS_ERROR_FAILURE; - } -#endif - - int n_copies = gtk_print_settings_get_n_copies (aGtkSettings); - if (n_copies <= 0) - return NS_ERROR_FAILURE; - if (capabilities & GTK_PRINT_CAPABILITY_COPIES) { - aSettings->SetNumCopies (1); - } else { - /* We have to copy them ourself */ - aSettings->SetNumCopies (n_copies); - gtk_print_settings_set_n_copies (aGtkSettings, 1); - } - - gboolean reverse = gtk_print_settings_get_reverse (aGtkSettings); - if (capabilities & GTK_PRINT_CAPABILITY_REVERSE) { - aSettings->SetPrintReversed (PR_FALSE); - } else { - aSettings->SetPrintReversed (reverse); - gtk_print_settings_set_reverse (aGtkSettings, FALSE); - } - - 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); - - 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); - /* Gecko page numbers start at 1, while gtk page numbers start at 0 */ - aSettings->SetStartPageRange (pageRanges[0].start + 1); - aSettings->SetEndPageRange (pageRanges[0].end + 1); - - g_free (pageRanges); - break; - } - /* Fall-through to PAGES_ALL */ - } - 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); - } - - /* And clear those in the settings, so the printer doesn't try to apply them too */ - gtk_print_settings_set_print_pages (aGtkSettings, GTK_PRINT_PAGES_ALL); - gtk_print_settings_set_page_ranges (aGtkSettings, NULL, 0); - gtk_print_settings_set_page_set (aGtkSettings, GTK_PAGE_SET_ALL); - - /* We must use the page setup here instead of the print settings, see gtk bug #485685 */ - switch (gtk_page_setup_get_orientation (aPageSetup)) { - 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); - -#ifndef HAVE_GECKO_1_9 - aSettings->SetPaperSize (nsIPrintSettings::kPaperSizeDefined); -#endif - - 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 */ - - /* 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)); - - aSettings->SetHeaderStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_TITLE) ? LITERAL ("&T") : LITERAL ("")); - aSettings->SetHeaderStrCenter (LITERAL ("")); - aSettings->SetHeaderStrRight (eel_gconf_get_boolean (CONF_PRINT_PAGE_URL) ? LITERAL ("&U") : LITERAL ("")); - aSettings->SetFooterStrLeft (eel_gconf_get_boolean (CONF_PRINT_PAGE_NUMBERS) ? LITERAL ("&PT") : LITERAL ("")); - aSettings->SetFooterStrCenter (LITERAL ("")); - aSettings->SetFooterStrRight (eel_gconf_get_boolean (CONF_PRINT_DATE) ? LITERAL ("&D") : LITERAL ("")); - - aSettings->SetPrintFrameType (aPrintFrames); - aSettings->SetPrintFrameTypeUsage (nsIPrintSettings::kUseSettingWhenPossible); - - /* FIXME: only if GTK_PRINT_CAPABILITY_SCALE is not set? */ - aSettings->SetScaling (gtk_print_settings_get_scale (aGtkSettings) / 100.0); - gtk_print_settings_set_scale (aGtkSettings, 1.0); - - aSettings->SetShrinkToFit (PR_FALSE); /* FIXME setting */ - - aSettings->SetPrintBGColors (eel_gconf_get_boolean (CONF_PRINT_BG_COLORS) != FALSE); - aSettings->SetPrintBGImages (eel_gconf_get_boolean (CONF_PRINT_BG_IMAGES) != FALSE); - - /* aSettings->SetPlexName (LITERAL ("default")); */ - /* aSettings->SetColorspace (LITERAL ("default")); */ - /* aSettings->SetResolutionName (LITERAL ("default")); */ - /* aSettings->SetDownloadFonts (PR_TRUE); */ - - /* Unset those setting that we can handle, so they don't get applied - * again for the print job. - */ - /* gtk_print_settings_set_collate (aGtkSettings, FALSE); not yet */ - /* FIXME: Unset the orientation for the print job? */ - /* gtk_page_setup_set_orientation (aPageSetup, GTK_PAGE_ORIENTATION_PORTRAIT); */ - /* FIXME: unset output format -> "ps" ? */ - - return NS_OK; -} diff --git a/embed/mozilla/GeckoPrintService.h b/embed/mozilla/GeckoPrintService.h deleted file mode 100644 index c2e21cf3e..000000000 --- a/embed/mozilla/GeckoPrintService.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef GECKO_PRINT_SERVICE_H -#define GECKO_PRINT_SERVICE_H - -#include <gtk/gtkpagesetup.h> -#include <gtk/gtkprintsettings.h> -#include <gtk/gtkprinter.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 *, GtkPrinter *, const nsACString&, PRInt16, PRBool, nsIPrintSettings*); - -private: - nsresult PrintUnattended (nsIDOMWindow *, nsIPrintSettings *); -}; - -#endif /* GECKO_PRINT_SERVICE_H */ diff --git a/embed/mozilla/GeckoPrintSession.cpp b/embed/mozilla/GeckoPrintSession.cpp deleted file mode 100644 index ddf968283..000000000 --- a/embed/mozilla/GeckoPrintSession.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 (nsIPrintSettings *aPrintSettings, - GtkPrintSettings *aSettings, - GtkPageSetup *aPageSetup, - GtkPrinter *aPrinter) -{ - NS_ASSERTION (!mPrintSettings && !mSettings && !mPageSetup && !mPrinter, "Already have settings!"); - - NS_ENSURE_ARG (aPrintSettings); - NS_ENSURE_ARG (aSettings); - - mPrintSettings = aPrintSettings; - mSettings = (GtkPrintSettings *) g_object_ref (aSettings); - - NS_ENSURE_ARG (aPageSetup); - NS_ENSURE_ARG (aPrinter); - - mPageSetup = (GtkPageSetup *) g_object_ref (aPageSetup); - mPrinter = (GtkPrinter *) g_object_ref (aPrinter); - -#if 0 - /* 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 -#endif - { - char *base, *tmpName; - - /* FIXME: use pure glib here (g_mkstemp)! */ - 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 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")); /* FIXME text! */ - } - - if (mJob) { - /* FIXME: There's no way to cancel mJob! Bug #339323 */ - } -} - -void -GeckoPrintSession::StartPrinting () -{ - mStartPrintIdleID = 0; - - GError *error = NULL; - -#if 0 - /* 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; -#endif - - 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)) { - /* FIXME: error dialogue! */ - g_warning ("Couldn't set print job source: %s", error->message); - g_error_free (error); - - g_object_unref (mJob); - mJob = NULL; - - return; - } - - g_signal_connect (mJob, "status-changed", - G_CALLBACK (JobStatusChangedCallback), this); - - /* Keep us alive until the job is done! */ - NS_ADDREF_THIS (); - gtk_print_job_send (mJob, - (GtkPrintJobCompleteFunc) JobCompletedCallback, - this, - (GDestroyNotify) ReleaseSession); -} - -void -GeckoPrintSession::JobStatusChanged () -{ - NS_ENSURE_TRUE (mProgressDialog, ); - - LOG ("print session %p status changed %d\n", this, gtk_print_job_get_status (mJob)); - - /* FIXME: are any other status codes relevant info for the user? */ - if (gtk_print_job_get_status (mJob) == GTK_PRINT_STATUS_SENDING_DATA) { - gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (mProgressBar), 0.75); - /* FIXME text! */ - 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 () -{ - if (!mJob) return; - - 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), 5); - - 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; - if (mPrintSettings) { - mPrintSettings->SetIsCancelled (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 deleted file mode 100644 index 027f01e23..000000000 --- a/embed/mozilla/GeckoPrintSession.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 (nsIPrintSettings *, GtkPrintSettings*, GtkPageSetup*, GtkPrinter*); - void GetSourceFile (nsACString&); - - static GeckoPrintSession *FromSettings (nsIPrintSettings *); - - void Cancel (); - void StartPrinting (); - void JobStatusChanged (); - void JobDone (); - void JobError (const char *); - - private: - nsCOMPtr<nsIPrintSettings> mPrintSettings; - 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 LaunchJobOnIdle (); - void DestroyJob (); -}; - -#endif /* GECKO_PRINT_SESSION_H */ diff --git a/embed/mozilla/GeckoSpellCheckEngine.cpp b/embed/mozilla/GeckoSpellCheckEngine.cpp deleted file mode 100644 index 59ab5df2d..000000000 --- a/embed/mozilla/GeckoSpellCheckEngine.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -//#include <bonobo.h> -#include <stdio.h> -#include <stdlib.h> - -#include <nsStringAPI.h> - -#include <mozIPersonalDictionary.h> -#include <nsMemory.h> - -#include "ephy-debug.h" - -#include "GeckoSpellCheckEngine.h" - -#ifndef HAVE_GECKO_1_9 -#define ToNewUnicode NS_StringCloneData -#endif - -GeckoSpellCheckEngine::GeckoSpellCheckEngine () -{ - LOG ("GeckoSpellCheckEngine ctor [%p]", (void*) this); - mSpeller = ephy_spell_check_get_default (); -} - -GeckoSpellCheckEngine::~GeckoSpellCheckEngine () -{ - LOG ("GeckoSpellCheckEngine dtor [%p]", (void*) this); - g_object_unref (mSpeller); -} - -NS_IMPL_ISUPPORTS1 (GeckoSpellCheckEngine, - mozISpellCheckingEngine) - -/* nsISpellCheckEngine implementation */ - -/* attribute wstring dictionary; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetDictionary (PRUnichar * *aDictionary) -{ - /* Gets the identifier of the current dictionary */ - char *code = ephy_spell_check_get_language (mSpeller); - if (!code) { - return NS_ERROR_FAILURE; - } - - *aDictionary = ToNewUnicode (NS_ConvertUTF8toUTF16 (code)); - g_free (code); - - return NS_OK; -} - -NS_IMETHODIMP GeckoSpellCheckEngine::SetDictionary (const PRUnichar * aDictionary) -{ - return NS_OK; -} - -/* readonly attribute wstring language; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetLanguage (PRUnichar * *aLanguage) -{ - /* Gets the identifier of the current dictionary */ - char *code = ephy_spell_check_get_language (mSpeller); - if (!code) { - return NS_ERROR_FAILURE; - } - - *aLanguage = ToNewUnicode (NS_ConvertUTF8toUTF16 (code)); - g_free (code); - - return NS_OK; -} - -/* readonly attribute boolean providesPersonalDictionary; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetProvidesPersonalDictionary (PRBool *aProvidesPersonalDictionary) -{ - *aProvidesPersonalDictionary = PR_FALSE; - return NS_OK; -} - -/* readonly attribute boolean providesWordUtils; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetProvidesWordUtils (PRBool *aProvidesWordUtils) -{ - *aProvidesWordUtils = PR_FALSE; - return NS_OK; -} - -/* readonly attribute wstring name; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetName (PRUnichar * *aName) -{ - /* It's fine to leave this unimplemented */ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute wstring copyright; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetCopyright (PRUnichar * *aCopyright) -{ - /* It's fine to leave this unimplemented */ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute mozIPersonalDictionary personalDictionary; */ -NS_IMETHODIMP GeckoSpellCheckEngine::GetPersonalDictionary (mozIPersonalDictionary * *aPersonalDictionary) -{ - NS_IF_ADDREF (*aPersonalDictionary = mPersonalDictionary); - return NS_OK; -} - -NS_IMETHODIMP GeckoSpellCheckEngine::SetPersonalDictionary (mozIPersonalDictionary * aPersonalDictionary) -{ - mPersonalDictionary = aPersonalDictionary; - return NS_OK; -} - -/* void getDictionaryList ([array, size_is (count)] out wstring dictionaries, out PRUint32 count); */ -NS_IMETHODIMP -GeckoSpellCheckEngine::GetDictionaryList (PRUnichar ***_dictionaries, - PRUint32 *_count) -{ - *_count = 1; - *_dictionaries = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *)); // only one entry - *_dictionaries[0] = ToNewUnicode (NS_LITERAL_STRING ("en")); - return NS_OK; -} - -/* boolean check (in wstring word); */ -NS_IMETHODIMP GeckoSpellCheckEngine::Check (const PRUnichar *word, - PRBool *_retval) -{ - NS_ENSURE_STATE (mSpeller); - NS_ENSURE_ARG (word); - - NS_ConvertUTF16toUTF8 converted (word); - - gboolean correct = FALSE; - if (!ephy_spell_check_check_word (mSpeller, - converted.get (), - converted.Length (), - &correct)) - return NS_ERROR_FAILURE; - - *_retval = correct != FALSE; - - return NS_OK; -} - -/* void suggest (in wstring word, [array, size_is (count)] out wstring suggestions, out PRUint32 count); */ -NS_IMETHODIMP GeckoSpellCheckEngine::Suggest (const PRUnichar *word, - PRUnichar ***_suggestions, - PRUint32 *_count) -{ -#if 0 - NS_ENSURE_STATE (mSpeller); - NS_ENSURE_ARG (word); - - NS_ConvertUTF16toUTF8 converted (word); - - gsize count; - char **suggestions = ephy_spell_check_get_suggestions (mSpeller, - converted.get (), - converted.Length (), - &count); - - *_count = count; - *_suggestions = nsnull; - - PRUnichar **array = nsnull; - if (count > 0) { - NS_ASSERTION (suggestions, "Count > 0 but suggestions are NULL?"); - array = (PRUnichar **) nsMemory::Alloc (count * sizeof (PRUnichar *)); - if (array) { - *_suggestions = array; - - for (gsize i = 0; i < count; ++i) { - NS_ConvertUTF8toUTF16 sugg (suggestions[i]); - array[i] = ToNewUnicode (sugg); - } - } - - ephy_spell_check_free_suggestions (mSpeller, suggestions); - } - - return array ? NS_OK : NS_ERROR_OUT_OF_MEMORY; -#endif - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/embed/mozilla/GeckoSpellCheckEngine.h b/embed/mozilla/GeckoSpellCheckEngine.h deleted file mode 100644 index b70f6c970..000000000 --- a/embed/mozilla/GeckoSpellCheckEngine.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef GECKO_SPELL_CHECK_ENGINE_H -#define GECKO_SPELL_CHECK_ENGINE_H - -#include <nsCOMPtr.h> -#include <mozISpellCheckingEngine.h> - -#include "ephy-spell-check.h" - -class mozIPersonalDictionary; - -/* 26948b8b-d136-4a78-a9c5-3a145812b649 */ -#define GECKO_SPELL_CHECK_ENGINE_IID \ -{ 0x26948b8b, 0xd136, 0x4a78, { 0xa9, 0xc5, 0x3a, 0x14, 0x58, 0x12, 0xb6, 0x49 } } - -#define GECKO_SPELL_CHECK_ENGINE_CONTRACTID "@mozilla.org/spellchecker/myspell;1" -#define GECKO_SPELL_CHECK_ENGINE_CLASSNAME "Gecko Print Settings" - -class GeckoSpellCheckEngine : public mozISpellCheckingEngine -{ - public: - GeckoSpellCheckEngine(); - virtual ~GeckoSpellCheckEngine(); - - NS_DECL_ISUPPORTS - NS_DECL_MOZISPELLCHECKINGENGINE - - private: - nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary; - EphySpellCheck *mSpeller; -}; - -#endif /* GECKO_SPELL_CHECK_ENGINE_H */ diff --git a/embed/mozilla/GlobalHistory.cpp b/embed/mozilla/GlobalHistory.cpp deleted file mode 100644 index efcda79f9..000000000 --- a/embed/mozilla/GlobalHistory.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright © 2001, 2004 Philip Langdale - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsIURI.h> - -#include "ephy-embed-shell.h" - -#include "GlobalHistory.h" - - -#define MAX_TITLE_LENGTH 2048 -#define MAX_URL_LENGTH 16384 - -#ifdef HAVE_NSIGLOBALHISTORY3_H -NS_IMPL_ISUPPORTS2 (MozGlobalHistory, nsIGlobalHistory2, nsIGlobalHistory3) -#else -NS_IMPL_ISUPPORTS1 (MozGlobalHistory, nsIGlobalHistory2) -#endif /* HAVE_NSIGLOBALHISTORY3_H */ - -MozGlobalHistory::MozGlobalHistory () -{ - mGlobalHistory = EPHY_HISTORY (ephy_embed_shell_get_global_history (embed_shell)); - - mHistoryListener = new EphyHistoryListener (); - mHistoryListener->Init (mGlobalHistory); -} - -MozGlobalHistory::~MozGlobalHistory () -{ -} - -/* void addURI (in nsIURI aURI, in boolean aRedirect, in boolean aToplevel, in nsIURI aReferrer); */ -NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, - PRBool aRedirect, - PRBool aToplevel, - nsIURI *aReferrer) -{ - nsresult rv; - - NS_ENSURE_ARG (aURI); - - // filter out unwanted URIs such as chrome: etc - // The model is really if we don't know differently then add which basically - // means we are suppose to try all the things we know not to allow in and - // then if we don't bail go on and allow it in. But here lets compare - // against the most common case we know to allow in and go on and say yes - // to it. - - PRBool isHTTP = PR_FALSE, isHTTPS = PR_FALSE; - rv = aURI->SchemeIs("http", &isHTTP); - rv |= aURI->SchemeIs("https", &isHTTPS); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - if (!isHTTP && !isHTTPS) - { - static const char *schemes[] = { "javascript", - "data", - "about", - "chrome", - "resource", - "view-source" }; - - for (PRUint32 i = 0; i < G_N_ELEMENTS (schemes); ++i) - { - PRBool result = PR_FALSE; - if (NS_SUCCEEDED (aURI->SchemeIs (schemes[i], &result)) && result) - { - return NS_OK; - } - } - } - - nsCString spec; - rv = aURI->GetSpec(spec); - NS_ENSURE_TRUE (NS_SUCCEEDED(rv) && spec.Length(), rv); - - if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - - ephy_history_add_page (mGlobalHistory, spec.get(), aRedirect, aToplevel); - - return NS_OK; -} - -/* boolean isVisited (in nsIURI aURI); */ -NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, - PRBool *_retval) -{ - NS_ENSURE_ARG (aURI); - - *_retval = PR_FALSE; - - nsCString spec; - aURI->GetSpec(spec); - - if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - - *_retval = ephy_history_is_page_visited (mGlobalHistory, spec.get()); - - return NS_OK; -} - -/* void setPageTitle (in nsIURI aURI, in AString aTitle); */ -NS_IMETHODIMP MozGlobalHistory::SetPageTitle(nsIURI *aURI, - const nsAString & aTitle) -{ - NS_ENSURE_ARG (aURI); - - nsCString spec; - aURI->GetSpec(spec); - - if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - - nsString uTitle (aTitle); - - /* 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*) uTitle.get(), MAX_TITLE_LENGTH, - &n_read, &n_written, NULL); - /* FIXME loop from the end while !g_unichar_isspace (char)? */ - if (converted == NULL) return NS_OK; - - ephy_history_set_page_title (mGlobalHistory, spec.get(), converted); - - g_free (converted); - - return NS_OK; -} - -#ifdef HAVE_NSIGLOBALHISTORY3_H - -#ifdef HAVE_GECKO_1_9 - -/* unsigned long getURIGeckoFlags(in nsIURI aURI); */ -NS_IMETHODIMP -MozGlobalHistory::GetURIGeckoFlags(nsIURI *aURI, - PRUint32* aFlags) -{ - *aFlags = 0; - - nsCString spec; - aURI->GetSpec(spec); - - if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - - EphyNode *page = ephy_history_get_page (mGlobalHistory, spec.get()); - - GValue value = { 0, }; - if (page != NULL && - ephy_node_get_property (page, EPHY_NODE_PAGE_PROP_GECKO_FLAGS, &value)) - { - *aFlags = (PRUint32) (gulong) g_value_get_long (&value); - g_value_unset (&value); - - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -/* void setURIGeckoFlags(in nsIURI aURI, in unsigned long aFlags); */ -NS_IMETHODIMP -MozGlobalHistory::SetURIGeckoFlags(nsIURI *aURI, - PRUint32 aFlags) -{ - nsCString spec; - aURI->GetSpec(spec); - - if (spec.Length () > MAX_URL_LENGTH) return NS_OK; - - EphyNode *page = ephy_history_get_page (mGlobalHistory, spec.get()); - if (page != NULL) - { - ephy_node_set_property_long (page, - EPHY_NODE_PAGE_PROP_GECKO_FLAGS, - aFlags); - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -#endif /* HAVE_GECKO_1_9 */ - -/* void addDocumentRedirect (in nsIChannel - aOldChannel, - in nsIChannel aNewChannel, - in PRInt32 aFlags, - in boolean aTopLevel); */ -NS_IMETHODIMP -MozGlobalHistory::AddDocumentRedirect(nsIChannel *aOldChannel, - nsIChannel *aNewChannel, - PRInt32 aFlags, - PRBool aTopLevel) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -#endif /* HAVE_NSIGLOBALHISTORY3_H */ diff --git a/embed/mozilla/GlobalHistory.h b/embed/mozilla/GlobalHistory.h deleted file mode 100644 index 8397874a0..000000000 --- a/embed/mozilla/GlobalHistory.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright © 2001, 2004 Philip Langdale - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef EPHY_GLOBAL_HISTORY_H -#define EPHY_GLOBAL_HISTORY_H - -#ifdef HAVE_NSIGLOBALHISTORY3_H -#include <nsIGlobalHistory3.h> -#else -#include <nsIGlobalHistory2.h> -#endif /* HAVE_NSIGLOBALHISTORY3_H */ - -#include <nsAutoPtr.h> -#include <nsCOMPtr.h> - -#include "ephy-history.h" - -#include "EphyHistoryListener.h" - -#define EPHY_GLOBALHISTORY_CLASSNAME "Epiphany Global History Implementation" - -#define EPHY_GLOBALHISTORY_CID \ -{ 0xbe0c42c1, \ - 0x39d4, \ - 0x4271, \ - { 0xb7, 0x9e, 0xf7, 0xaa, 0x49, 0xeb, 0x6a, 0x15} \ -} - -#ifdef HAVE_NSIGLOBALHISTORY3_H -class MozGlobalHistory: public nsIGlobalHistory3 -#else -class MozGlobalHistory: public nsIGlobalHistory2 -#endif /* HAVE_NSIGLOBALHISTORY3_H */ -{ - public: - MozGlobalHistory (); - virtual ~MozGlobalHistory(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIGLOBALHISTORY2 -#ifdef HAVE_NSIGLOBALHISTORY3_H - NS_DECL_NSIGLOBALHISTORY3 -#endif /* HAVE_NSIGLOBALHISTORY3_H */ - - private: - EphyHistory *mGlobalHistory; - nsRefPtr<EphyHistoryListener> mHistoryListener; -}; - -#endif /* EPHY_GLOBAL_HISTORY_H */ diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp deleted file mode 100644 index ee699a23d..000000000 --- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * GtkNSSClientAuthDialogs.cpp - * - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gi18n.h> -#include <gtk/gtkcelllayout.h> -#include <gtk/gtkcellrenderer.h> -#include <gtk/gtkcellrenderertext.h> -#include <gtk/gtkcombobox.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkexpander.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkimage.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkliststore.h> -#include <gtk/gtkmenuitem.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtkprogressbar.h> -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtkstock.h> -#include <gtk/gtktextbuffer.h> -#include <gtk/gtktextview.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtktreemodel.h> -#include <gtk/gtkvbox.h> - -#include <nsStringAPI.h> - -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIServiceManager.h> - -#include "ephy-debug.h" -#include "ephy-gui.h" -#include "ephy-state.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" -#include "EphyUtils.h" - -#include "GtkNSSClientAuthDialogs.h" - -GtkNSSClientAuthDialogs::GtkNSSClientAuthDialogs() -{ - LOG ("GtkNSSClientAuthDialogs ctor (%p)", this); -} - - -GtkNSSClientAuthDialogs::~GtkNSSClientAuthDialogs() -{ - LOG ("GtkNSSClientAuthDialogs dtor (%p)", this); -} - -NS_IMPL_THREADSAFE_ISUPPORTS1 (GtkNSSClientAuthDialogs, - nsIClientAuthDialogs) - -/** - * Indent a widget according the HIG - * - * @returns: The new indented widget - */ -static GtkWidget* -higgy_indent_widget (GtkWidget *widget) -{ - GtkWidget *hbox; - GtkWidget *label; - - hbox = gtk_hbox_new (FALSE, 6); - - label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, TRUE, 6); - gtk_widget_show (label); - - gtk_box_pack_start (GTK_BOX(hbox), widget, TRUE, TRUE, 0); - - return hbox; -} - -static void -combo_changed_cb (GtkComboBox *combo, GtkTextView *textview) -{ - GtkTreeModel *model; - GtkTreeIter iter; - GtkTextBuffer *buffer; - int index; - - model = gtk_combo_box_get_model (combo); - index = gtk_combo_box_get_active (combo); - buffer = gtk_text_view_get_buffer (textview); - - if (gtk_tree_model_iter_nth_child (model, &iter, NULL, index)) - { - char *text; - - gtk_tree_model_get (model, &iter, 1, &text, -1); - - gtk_text_buffer_set_text (buffer, text, -1); - - g_free (text); - } - else - { - gtk_text_buffer_set_text (buffer, "", -1); - } -} - -NS_IMETHODIMP -GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, - const PRUnichar *cn, - const PRUnichar *organization, - const PRUnichar *issuer, - const PRUnichar **certNickList, - const PRUnichar **certDetailsList, - PRUint32 count, PRInt32 *selectedIndex, - PRBool *canceled) -{ - GtkWidget *dialog, *label, *vbox, *textview; - GtkWidget *details, *expander, *hbox, *image; - GtkWidget *combo; - GtkListStore *store; - GtkTreeIter iter; - GtkCellRenderer *renderer; - char *msg, *markup_text; - PRUint32 i; - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *canceled = PR_TRUE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - dialog = gtk_dialog_new_with_buttons ("", - gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - _("_Select Certificate"), - GTK_RESPONSE_OK, - (char *) NULL); - - if (gparent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (gparent), - GTK_WINDOW (dialog)); - } - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - gtk_dialog_set_has_separator (GTK_DIALOG (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(GTK_DIALOG (dialog)->vbox), 14); /* 24 = 2 * 5 + 14 */ - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, - 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); - gtk_widget_show (image); - - vbox = gtk_vbox_new (FALSE, 12); - gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - label = gtk_label_new (NULL); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); - gtk_widget_show (label); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - msg = g_markup_printf_escaped (_("Choose a certificate to present as identification to “%s”."), - NS_ConvertUTF16toUTF8 (cn).get()); - markup_text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", - _("Select a certificate to identify yourself."), - msg); - gtk_label_set_markup (GTK_LABEL (label), markup_text); - g_free (msg); - g_free (markup_text); - - /* Create and populate the combo */ - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - for (i = 0; i < count; i++) - { - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - 0, NS_ConvertUTF16toUTF8 (certNickList[i]).get(), - 1, NS_ConvertUTF16toUTF8 (certDetailsList[i]).get(), - -1); - } - - combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); - g_object_unref (store); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, - "text", 0, - (char *) NULL); - - gtk_widget_show (combo); - gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, TRUE, 0); - - expander = gtk_expander_new_with_mnemonic (_("Certificate _Details")); - ephy_state_add_expander (GTK_WIDGET (expander), "client-auth-dialog-expander", FALSE); - - gtk_widget_show (expander); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), expander, FALSE, FALSE, 0); - - /* Create the text box */ - textview = gtk_text_view_new (); - gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE); - gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE); - gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD); - gtk_widget_set_size_request (GTK_WIDGET (textview), -1, 100); - gtk_widget_show (textview); - - details = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (details), GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (details), GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (details), textview); - gtk_widget_show (details); - - details = higgy_indent_widget (details); - gtk_container_set_border_width (GTK_CONTAINER (details), 5); - gtk_widget_show (details); - - gtk_container_add (GTK_CONTAINER (expander), details); - - g_signal_connect (G_OBJECT (combo), "changed", - G_CALLBACK (combo_changed_cb), - textview); - - gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); - - /* run the dialog */ - int res = modalDialog.Run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_OK) - { - *canceled = PR_FALSE; - *selectedIndex = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); - } - else - { - *canceled = PR_TRUE; - } - - gtk_widget_destroy (dialog); - return NS_OK; -} diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.h b/embed/mozilla/GtkNSSClientAuthDialogs.h deleted file mode 100644 index 0aa582700..000000000 --- a/embed/mozilla/GtkNSSClientAuthDialogs.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * - * $Id$ - */ - -#ifndef GTKNSSCLIENTAUTHDIALOGS_H -#define GTKNSSCLIENTAUTHDIALOGS_H 1 - -#include <nsIClientAuthDialogs.h> - -// 55b3837e-dbde-4c24-9247-f328e3012485 -#define GTK_NSSCLIENTAUTHDIALOGS_CID \ - {0x55b3837e, 0xdbde, 0x4c24, {0x92, 0x47, 0xf3, 0x28, 0xe3, 0x01, 0x24, 0x85}} - -#define GTK_NSSCLIENTAUTHDIALOGS_CLASSNAME "Gtk NSS Client Auth Dialogs" - -class GtkNSSClientAuthDialogs -: public nsIClientAuthDialogs -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSICLIENTAUTHDIALOGS - - GtkNSSClientAuthDialogs(); - virtual ~GtkNSSClientAuthDialogs(); -}; - - -#endif /* GTKNSSCLIENTAUTHDIALOGS_H */ diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp deleted file mode 100644 index 6346ecb83..000000000 --- a/embed/mozilla/GtkNSSDialogs.cpp +++ /dev/null @@ -1,1725 +0,0 @@ -/* - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * Copyright © 2006 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -/* - * This file provides Gtk implementations of the mozilla Certificate dialogs - * such as the ones displayed when connecting to a site with a self-signed - * or expired certificate. - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <time.h> - -#include <glib/gi18n.h> -#include <gtk/gtkalignment.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkcellrenderertext.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkeditable.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkimage.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmessagedialog.h> -#include <gtk/gtkprogressbar.h> -#include <gtk/gtksizegroup.h> -#include <gtk/gtkstock.h> -#include <gtk/gtktable.h> -#include <gtk/gtktextbuffer.h> -#include <gtk/gtktextview.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtktreeselection.h> -#include <gtk/gtktreestore.h> -#include <gtk/gtktreeview.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkcombobox.h> -#include <gconf/gconf-client.h> -#include <glade/glade-xml.h> - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsIArray.h> -#include <nsIASN1Object.h> -#include <nsIASN1Sequence.h> -#include <nsICRLInfo.h> -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIPKCS11ModuleDB.h> -#include <nsIPKCS11Slot.h> -#include <nsIPK11Token.h> -#include <nsIPK11TokenDB.h> -#include <nsIServiceManager.h> -#include <nsISimpleEnumerator.h> -#include <nsIX509CertDB.h> -#include <nsIX509Cert.h> -#include <nsIX509CertValidity.h> -#include <nsMemory.h> -#include <nsServiceManagerUtils.h> - -#ifdef HAVE_NSIMUTABLEARRAY_H -#include <nsIMutableArray.h> -#endif - -#include "ephy-file-helpers.h" -#include "ephy-gui.h" -#include "ephy-password-dialog.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" - -#include "EphyUtils.h" - -#include "GtkNSSDialogs.h" - -NS_DEFINE_CID (kX509CertCID, NS_IX509CERT_IID); -NS_DEFINE_CID (kASN1ObjectCID, NS_IASN1OBJECT_IID); - -enum -{ - NSSDIALOG_RESPONSE_VIEW_CERT = 10 -}; - -GtkNSSDialogs::GtkNSSDialogs () -{ -} - -GtkNSSDialogs::~GtkNSSDialogs () -{ -} - -#ifdef HAVE_GECKO_1_9 -NS_IMPL_THREADSAFE_ISUPPORTS4 (GtkNSSDialogs, - nsITokenPasswordDialogs, - nsICertificateDialogs, - nsITokenDialogs, - nsIDOMCryptoDialogs) -#else -NS_IMPL_THREADSAFE_ISUPPORTS5 (GtkNSSDialogs, - nsITokenPasswordDialogs, - nsIBadCertListener, - nsICertificateDialogs, - nsITokenDialogs, - nsIDOMCryptoDialogs) -#endif - -/* There's also nsICertPickDialogs which is implemented in mozilla - * but has no callers. So we don't implement it. - * Same for nsIUserCertPicker which is only used in mailnews. - */ - -/** - * Call the mozilla service to display a certificate - */ -static void -view_certificate (nsIInterfaceRequestor *ctx, nsIX509Cert *cert) -{ - nsresult rv; - nsCOMPtr<nsICertificateDialogs> certDialogs = - do_GetService (NS_CERTIFICATEDIALOGS_CONTRACTID, &rv); - NS_ENSURE_SUCCESS (rv, ); - - certDialogs->ViewCert (ctx, cert); -} - -/** - * Indent a widget according the HIG - * - * @returns: The new indented widget - */ -static GtkWidget* -higgy_indent_widget (GtkWidget *widget) -{ - GtkWidget *hbox; - GtkWidget *label; - - hbox = gtk_hbox_new (FALSE, 6); - - label = gtk_label_new (NULL); - gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, TRUE, 6); - gtk_widget_show (label); - - gtk_box_pack_start (GTK_BOX(hbox), widget, TRUE, TRUE, 0); - - return hbox; -} - -/** - * Setup up a dialog with the correct HIG'gy spacings, adding the content_widget - */ -static void -higgy_setup_dialog (GtkDialog *dialog, const gchar *stock_icon, - GtkWidget **content_label, - GtkWidget **content_vbox) -{ - GtkWidget *hbox, *label, *image, *vbox; - - g_return_if_fail (GTK_IS_DIALOG (dialog)); - g_return_if_fail (content_label); - - gtk_dialog_set_has_separator (dialog, FALSE); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); - gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox); - - image = gtk_image_new_from_stock (stock_icon, 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); - - label = gtk_label_new (NULL); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); - - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - - gtk_widget_show (image); - gtk_widget_show (vbox); - gtk_widget_show (hbox); - gtk_widget_show (label); - - /* Set up the spacing for the dialog internal widgets */ - gtk_box_set_spacing (GTK_BOX(dialog->vbox), 14); /* 24 = 2 * 5 + 14 */ - - *content_label = label; - if (content_vbox) - { - *content_vbox = vbox; - } -} - -#ifndef HAVE_GECKO_1_9 -/** - * Display a dialog box, showing 'View Certificate', 'Cancel', - * and 'Accept' buttons. Optionally a checkbox can be shown, - * or the text can be NULL to avoid it being displayed - * - * @returns: GTK_RESPONSE_ACCEPT if the user clicked Accept - */ -static gint -display_cert_warning_box (nsIInterfaceRequestor *ctx, - nsIX509Cert *cert, - const char *markup_text, - const char *checkbox_text, - gboolean *checkbox_value, - const char *affirmative_text) -{ - GtkWidget *dialog, *label, *checkbox, *vbox, *button; - int res; - - g_return_val_if_fail (markup_text, GTK_RESPONSE_CANCEL); - g_return_val_if_fail (!checkbox_text || checkbox_value, GTK_RESPONSE_CANCEL); - - /* NOTE: Due to a mozilla bug [https://bugzilla.mozilla.org/show_bug.cgi?id=306288], - * we will always end up without a parent! - */ - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - return GTK_RESPONSE_CANCEL; - - GtkWindow *gparent = modalDialog.GetParent (); - - dialog = gtk_dialog_new_with_buttons ("", gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - (char *) NULL); - if (gparent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (gparent), - GTK_WINDOW (dialog)); - } - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - higgy_setup_dialog (GTK_DIALOG (dialog), - GTK_STOCK_DIALOG_WARNING, &label, &vbox); - - /* Add the buttons */ - gtk_dialog_add_button (GTK_DIALOG (dialog), _("_View Certificate"), - NSSDIALOG_RESPONSE_VIEW_CERT); - - button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - - if (affirmative_text == NULL) - { - affirmative_text = _("_Accept"); - } - - gtk_dialog_add_button (GTK_DIALOG (dialog), affirmative_text, - GTK_RESPONSE_ACCEPT); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - - if (checkbox_text) - { - checkbox = gtk_check_button_new_with_mnemonic (checkbox_text); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), - *checkbox_value); - - gtk_box_pack_start (GTK_BOX (vbox), checkbox, TRUE, TRUE, 0); - } - else - { - checkbox = 0; - } - - /* We don't want focus on the checkbox */ - gtk_widget_grab_focus (button); - - gtk_label_set_markup (GTK_LABEL (label), markup_text); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - gtk_widget_show_all (dialog); - - while (1) - { - res = modalDialog.Run (GTK_DIALOG (dialog)); - if (res == NSSDIALOG_RESPONSE_VIEW_CERT) - { - view_certificate (ctx, cert); - continue; - } - - break; - } - - if (res == GTK_RESPONSE_ACCEPT && checkbox) - { - *checkbox_value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox)); - } - - gtk_widget_destroy (dialog); - return res; -} -#endif /* HAVE_GECKO_1_9 */ - -/* Helper functions */ - -nsresult -GtkNSSDialogs::GetTokenAndSlotFromName (const PRUnichar *aName, - nsIPK11Token **aToken, - nsIPKCS11Slot **aSlot) -{ - nsresult rv = NS_ERROR_FAILURE; - *aToken = nsnull; - *aSlot = nsnull; - - nsCOMPtr<nsIPK11TokenDB> tokenDB = do_GetService("@mozilla.org/security/pk11tokendb;1"); - nsCOMPtr<nsIPKCS11ModuleDB> pkcs11DB = do_GetService("@mozilla.org/security/pkcs11moduledb;1"); - if (!tokenDB || !pkcs11DB) return rv; - - rv = tokenDB->FindTokenByName (aName, aToken); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && *aToken, rv); - - pkcs11DB->FindSlotByName (aName, aSlot); - - NS_ENSURE_TRUE (*aSlot, NS_ERROR_FAILURE); - -#ifdef GNOME_ENABLE_DEBUG - /* Dump some info about this token */ - nsIPK11Token *token = *aToken; - PRUnichar *tName, *tLabel, *tManID, *tHWVersion, *tFWVersion, *tSN; - PRInt32 minPwdLen; - PRBool needsInit, isHW, needsLogin, isFriendly; - - token->GetTokenName(&tName); - token->GetTokenLabel(&tLabel); - token->GetTokenManID(&tManID); - token->GetTokenHWVersion(&tHWVersion); - token->GetTokenFWVersion(&tFWVersion); - token->GetTokenSerialNumber(&tSN); - token->GetMinimumPasswordLength(&minPwdLen); - token->GetNeedsUserInit(&needsInit); - token->IsHardwareToken(&isHW); - token->NeedsLogin(&needsLogin); - token->IsFriendly(&isFriendly); - - g_print ("Token '%s' has \nName: %s\nLabel: %s\nManID: %s\nHWversion: %s\nFWVersion: %s\nSN: %s\n" - "MinPwdLen: %d\nNeedsUserInit: %d\nIsHWToken: %d\nNeedsLogin: %d\nIsFriendly: %d\n\n", - NS_ConvertUTF16toUTF8(aName).get(), - - NS_ConvertUTF16toUTF8(tName).get(), - NS_ConvertUTF16toUTF8(tLabel).get(), - NS_ConvertUTF16toUTF8(tManID).get(), - NS_ConvertUTF16toUTF8(tHWVersion).get(), - NS_ConvertUTF16toUTF8(tFWVersion).get(), - NS_ConvertUTF16toUTF8(tSN).get(), - minPwdLen, - needsInit, - isHW, - needsLogin, - isFriendly); - - nsIPKCS11Slot *slot = *aSlot; - PRUnichar*slDesc; - slot->GetDesc(&slDesc); - g_print ("Slot description: %s\n", NS_ConvertUTF16toUTF8 (slDesc).get()); -#endif - - return NS_OK; -} - -#ifndef HAVE_GECKO_1_9 - -NS_IMETHODIMP -GtkNSSDialogs::ConfirmMismatchDomain (nsIInterfaceRequestor *ctx, - const nsACString &targetURL, - nsIX509Cert *cert, PRBool *_retval) -{ - char *first, *second, *msg; - int res; - - nsString commonName; - cert->GetCommonName (commonName); - - NS_ConvertUTF16toUTF8 cCommonName (commonName); - - nsCString cTargetUrl (targetURL); - - first = g_markup_printf_escaped (_("The site “%s” returned security information for " - "“%s”. It is possible that someone is intercepting " - "your communication to obtain your confidential " - "information."), - cTargetUrl.get(), cCommonName.get()); - - second = g_markup_printf_escaped (_("You should only accept the security information if you " - "trust “%s” and “%s”."), - cTargetUrl.get(), cCommonName.get()); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n\n%s", - _("Accept incorrect security information?"), - first, second); - - res = display_cert_warning_box (ctx, cert, msg, NULL, NULL, NULL); - - g_free (second); - g_free (first); - g_free (msg); - - *_retval = (res == GTK_RESPONSE_ACCEPT); - return NS_OK; -} - - -NS_IMETHODIMP -GtkNSSDialogs::ConfirmUnknownIssuer (nsIInterfaceRequestor *ctx, - nsIX509Cert *cert, PRInt16 *outAddType, - PRBool *_retval) -{ - gboolean accept_perm = FALSE; - char *secondary, *tertiary, *msg; - int res; - - nsString commonName; - cert->GetCommonName (commonName); - - NS_ConvertUTF16toUTF8 cCommonName (commonName); - - secondary = g_markup_printf_escaped - (_("It was not possible to automatically trust “%s”. " - "It is possible that someone is intercepting your " - "communication to obtain your confidential information."), - cCommonName.get()); - - tertiary = g_markup_printf_escaped - (_("You should only connect to the site if you are certain " - "you are connected to “%s”."), - cCommonName.get()); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n\n%s", - _("Connect to untrusted site?"), - secondary, tertiary); - - res = display_cert_warning_box (ctx, cert, msg, - _("_Trust this security information from now on"), - &accept_perm, _("Co_nnect")); - g_free (tertiary); - g_free (secondary); - g_free (msg); - - if (res != GTK_RESPONSE_ACCEPT) - { - *_retval = PR_FALSE; - *outAddType = UNINIT_ADD_FLAG; - } - else - { - if (accept_perm) - { - *_retval = PR_TRUE; - *outAddType = ADD_TRUSTED_PERMANENTLY; - } - else - { - *_retval = PR_TRUE; - *outAddType = ADD_TRUSTED_FOR_SESSION; - } - } - - return NS_OK; -} - - -/* boolean confirmCertExpired (in nsIInterfaceRequestor socketInfo, - in nsIX509Cert cert); */ -NS_IMETHODIMP -GtkNSSDialogs::ConfirmCertExpired (nsIInterfaceRequestor *ctx, - nsIX509Cert *cert, PRBool *_retval) -{ - nsresult rv; - PRTime now = PR_Now(); - PRTime notAfter, notBefore, timeToUse; - PRInt64 normalizedTime; - time_t t; - struct tm tm; - char formattedDate[128]; - char *fdate; - const char *primary, *text; - char *secondary, *msg; - - *_retval = PR_FALSE; - - nsCOMPtr<nsIX509CertValidity> validity; - rv = cert->GetValidity (getter_AddRefs(validity)); - if (NS_FAILED(rv)) return rv; - - rv = validity->GetNotAfter (¬After); - if (NS_FAILED(rv)) return rv; - - rv = validity->GetNotBefore (¬Before); - if (NS_FAILED(rv)) return rv; - - if (LL_CMP(now, >, notAfter)) - { - primary = _("Accept expired security information?"); - /* Translators: first %s is a hostname, second %s is a time/date */ - text = _("The security information for “%s” " - "expired on %s."); - timeToUse = notAfter; - } - else - { - primary = _("Accept not yet valid security information?"); - /* Translators: first %s is a hostname, second %s is a time/date */ - text = _("The security information for “%s” isn't valid until %s."); - timeToUse = notBefore; - } - - nsString commonName; - cert->GetCommonName (commonName); - - NS_ConvertUTF16toUTF8 cCommonName (commonName); - - LL_DIV (normalizedTime, timeToUse, PR_USEC_PER_SEC); - LL_L2UI (t, normalizedTime); - /* To translators: this a time format that is used while displaying the - * expiry or start date of an SSL certificate, for the format see - * strftime(3) */ - strftime (formattedDate, sizeof(formattedDate), _("%a %d %b %Y"), - localtime_r (&t, &tm)); - /* FIXME! this isn't actually correct, LC_CTIME codeset could be different than locale codeset! */ - fdate = g_locale_to_utf8 (formattedDate, -1, NULL, NULL, NULL); - - secondary = g_markup_printf_escaped (text, cCommonName.get(), fdate); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n\n%s", - primary, secondary, - _("You should ensure that your computer's time is correct.")); - - int res = display_cert_warning_box (ctx, cert, msg, NULL, NULL, NULL); - - g_free (fdate); - g_free (msg); - g_free (secondary); - - *_retval = (res == GTK_RESPONSE_ACCEPT); - - return NS_OK; -} - -/* void notifyCrlNextupdate (in nsIInterfaceRequestor socketInfo, - in AUTF8String targetURL, - in nsIX509Cert cert); */ -NS_IMETHODIMP -GtkNSSDialogs::NotifyCrlNextupdate (nsIInterfaceRequestor *ctx, - const nsACString & targetURL, - nsIX509Cert *cert) -{ - nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = EphyUtils::FindGtkParent (parent); - - nsCString cTargetUrl (targetURL); - - nsString commonName; - cert->GetCommonName (commonName); - - GtkWidget *dialog = gtk_message_dialog_new - (GTK_WINDOW (gparent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("Cannot establish connection to “%s”"), - cTargetUrl.get ()); - - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - _("The certificate revocation list (CRL) from “%s” " - "needs to be updated.\n\n" - "Please ask your system administrator for assistance."), - NS_ConvertUTF16toUTF8 (commonName).get ()); - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - g_signal_connect (dialog, "response", - (GCallback) gtk_widget_destroy, NULL); - - gtk_widget_show_all (dialog); - return NS_OK; -} - -#endif /* HAVE_GECKO_1_9 */ - -NS_IMETHODIMP -GtkNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, - nsIX509Cert *cert, - PRUint32 *_trust, - PRBool *_retval) -{ - GtkWidget *dialog, *label; - char *msg, *primary; - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *_retval = PR_FALSE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - dialog = gtk_dialog_new_with_buttons (_("Trust new Certificate Authority?"), gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - _("_View Certificate"), - NSSDIALOG_RESPONSE_VIEW_CERT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - _("_Trust CA"), GTK_RESPONSE_ACCEPT, - (char *) NULL); - - if (gparent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (gparent), - GTK_WINDOW (dialog)); - } - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - higgy_setup_dialog (GTK_DIALOG (dialog), GTK_STOCK_DIALOG_WARNING, - &label, NULL); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); - - nsString commonName; - cert->GetCommonName (commonName); - - NS_ConvertUTF16toUTF8 cCommonName (commonName); - - primary = g_markup_printf_escaped (_("Trust new Certificate Authority “%s” to identify web sites?"), - cCommonName.get()); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", - primary, - _("Before trusting a Certificate Authority (CA) you should " - "verify the certificate is authentic.")); - gtk_label_set_markup (GTK_LABEL (label), msg); - g_free (primary); - g_free (msg); - - gtk_widget_show_all (dialog); - int ret; - - while (1) - { - ret = modalDialog.Run (GTK_DIALOG (dialog)); - if (ret == NSSDIALOG_RESPONSE_VIEW_CERT) - { - view_certificate (ctx, cert); - continue; - } - - break; - } - - if (ret != GTK_RESPONSE_ACCEPT) - { - *_retval = PR_FALSE; - } - else - { - if (ret == GTK_RESPONSE_ACCEPT) - { - *_trust |= nsIX509CertDB::TRUSTED_SSL; - } - else - { - *_trust = nsIX509CertDB::UNTRUSTED; - } - - *_retval = PR_TRUE; - } - gtk_widget_destroy (dialog); - - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSDialogs::NotifyCACertExists (nsIInterfaceRequestor *ctx) -{ - GtkWidget *dialog, *label; - char * msg; - - nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWindow *gparent = GTK_WINDOW (EphyUtils::FindGtkParent (parent)); - - dialog = gtk_dialog_new_with_buttons ("", gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, - GTK_RESPONSE_OK, - (char *) NULL); - - if (gparent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (gparent), - GTK_WINDOW (dialog)); - } - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - higgy_setup_dialog (GTK_DIALOG (dialog), GTK_STOCK_DIALOG_ERROR, - &label, NULL); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", - _("Certificate already exists."), - _("The certificate has already been imported.")); - gtk_label_set_markup (GTK_LABEL (label), msg); - g_free (msg); - - g_signal_connect (G_OBJECT (dialog), - "response", - (GCallback)gtk_widget_destroy, NULL); - - gtk_widget_show_all (dialog); - return NS_OK; -} - -/* FIXME: This interface sucks! There is way to know the name of the certificate! */ -NS_IMETHODIMP -GtkNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, - nsAString &_password, - PRBool *_retval) -{ - GtkWidget *dialog; - char *msg; - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *_retval = PR_FALSE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - dialog = ephy_password_dialog_new (GTK_WIDGET (gparent), - _("Select Password"), - EphyPasswordDialogFlags(EPHY_PASSWORD_DIALOG_FLAGS_SHOW_NEW_PASSWORD | - EPHY_PASSWORD_DIALOG_FLAGS_SHOW_QUALITY_METER)); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - - /* FIXME: set accept button text to (_("_Back Up Certificate") ? - * That's not actually correct, since this function is also called from other places! - */ - - msg = g_markup_printf_escaped (_("Select a password to protect this certificate")); - gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), msg); - g_free (msg); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - gtk_widget_hide (dialog); - - if (response == GTK_RESPONSE_ACCEPT) - { - const char *text = ephy_password_dialog_get_new_password (EPHY_PASSWORD_DIALOG (dialog)); - g_return_val_if_fail (text != NULL, NS_ERROR_FAILURE); - NS_CStringToUTF16 (nsDependentCString (text), - NS_CSTRING_ENCODING_UTF8, _password); - } - - *_retval = response == GTK_RESPONSE_ACCEPT; - - gtk_widget_destroy (dialog); - - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, - nsAString &_password, - PRBool *_retval) -{ - g_print ("GtkNSSDialogs::GetPKCS12FilePassword\n"); - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *_retval = PR_FALSE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - GtkWidget *dialog = ephy_password_dialog_new - (GTK_WIDGET (gparent), - "", - EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD)); - EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog); - /* FIXME: set accept button text to _("I_mport Certificate") ? */ - - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - - /* FIXME: mozilla sucks, no way to get the name of the certificate / cert file! */ - char *msg = g_markup_printf_escaped (_("Enter the password for this certificate")); - gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), msg); - g_free (msg); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - - if (response == GTK_RESPONSE_ACCEPT) - { - const char *pwd = ephy_password_dialog_get_password (password_dialog); - NS_CStringToUTF16 (nsDependentCString (pwd), - NS_CSTRING_ENCODING_UTF8, _password); - } - - *_retval = response == GTK_RESPONSE_ACCEPT; - - gtk_widget_destroy (dialog); - - return NS_OK; -} - - -static void -set_table_row (GtkWidget *table, - int& row, - const char *title, - const char *text) -{ - GtkWidget *header, *label; - char *bold; - - if (text == NULL || text[0] == 0) return; - - bold = g_markup_printf_escaped ("<b>%s</b>", title); - header = gtk_label_new (bold); - g_free (bold); - - gtk_label_set_use_markup (GTK_LABEL (header), TRUE); - gtk_misc_set_alignment (GTK_MISC (header), 0, 0); - gtk_widget_show (header); - gtk_table_attach (GTK_TABLE (table), header, 0, 1, row, row+1, - GTK_FILL, GTK_FILL, 0, 0); - - label = gtk_label_new (text); - gtk_misc_set_alignment (GTK_MISC (label), 0, 0); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); - gtk_label_set_max_width_chars (GTK_LABEL (label), 48); - gtk_widget_show (label); - gtk_table_attach_defaults (GTK_TABLE (table), label, 1, 2, row, row+1); - - row++; -} - -NS_IMETHODIMP -GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl) -{ - - GtkWidget *dialog, *label, *table, *vbox; - nsresult rv; - char *msg; - - nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); - GtkWidget *gparent = EphyUtils::FindGtkParent (parent); - - dialog = gtk_dialog_new_with_buttons ("", - GTK_WINDOW (gparent), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_OK, - (char *) NULL); - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - gtk_window_set_title (GTK_WINDOW (dialog), _("Certificate Revocation List Imported")); - - /* Needed because gparent == NULL always because of mozilla sucks */ - gtk_window_set_skip_pager_hint (GTK_WINDOW (dialog), TRUE); - gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE); - - higgy_setup_dialog (GTK_DIALOG (dialog), GTK_STOCK_DIALOG_INFO, - &label, &vbox); - - msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>", - _("Certificate Revocation List (CRL) successfully imported")); - gtk_label_set_markup (GTK_LABEL (label), msg); - g_free (msg); - - table = gtk_table_new (2, 3, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), 6); - gtk_table_set_col_spacings (GTK_TABLE (table), 12); - - nsString org, orgUnit, nextUpdate; - rv = crl->GetOrganization (org); - if (NS_FAILED(rv)) return rv; - - rv = crl->GetOrganizationalUnit (orgUnit); - if (NS_FAILED(rv)) return rv; - - rv = crl->GetNextUpdateLocale (nextUpdate); - if (NS_FAILED(rv)) return rv; - - int row = 0; - set_table_row (table, row, _("Organization:"), NS_ConvertUTF16toUTF8 (org).get ()); - - set_table_row (table, row, _("Unit:"), NS_ConvertUTF16toUTF8 (orgUnit).get ()); - - set_table_row (table, row, _("Next Update:"), NS_ConvertUTF16toUTF8 (nextUpdate).get ()); - - gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); - - gtk_widget_show_all (dialog); - g_signal_connect (G_OBJECT (dialog), - "response", - (GCallback)gtk_widget_destroy, NULL); - - gtk_widget_show_all (dialog); - return NS_OK; -} - -/** - * Help function to fill in the labels on the General tab - */ -static void -set_label_cert_attribute (GladeXML* gxml, const char* label_id, nsAString &value) -{ - GtkWidget *label; - label = glade_xml_get_widget (gxml, label_id); - - g_return_if_fail (GTK_IS_LABEL (label)); - - if (!value.Length()) { - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - char *msg = g_strdup_printf ("<i><%s></i>", - _("Not part of certificate")); - gtk_label_set_markup (GTK_LABEL (label), msg); - g_free (msg); - } - else - { - gtk_label_set_use_markup (GTK_LABEL (label), FALSE); - gtk_label_set_text (GTK_LABEL (label), NS_ConvertUTF16toUTF8 (value).get()); - } -} - - -/** - * Do that actual filling in of the certificate tree - */ -static gboolean -fill_cert_chain_tree (GtkTreeView *treeview, nsIArray *certChain) -{ - nsresult rv; - GtkTreeModel * model = gtk_tree_view_get_model (treeview); - - GtkTreeIter parent; - PRUint32 numCerts; - rv = certChain->GetLength (&numCerts); - if (NS_FAILED(rv) || numCerts < 1) return FALSE; - - for (int i = (int)numCerts-1 ; i >= 0; i--) - { - nsCOMPtr<nsIX509Cert> nsCert; - rv = certChain->QueryElementAt (i, kX509CertCID, - getter_AddRefs(nsCert)); - if (NS_FAILED(rv)) return FALSE; - - GtkTreeIter iter; - gtk_tree_store_append (GTK_TREE_STORE (model), &iter, - (i == (int)numCerts-1) ? NULL : &parent); - - nsString value; - rv = nsCert->GetCommonName (value); - if (NS_FAILED(rv)) return FALSE; - - NS_ConvertUTF16toUTF8 cValue (value); - - nsIX509Cert *nsCertP = nsCert; - if (value.Length()) - { - gtk_tree_store_set (GTK_TREE_STORE(model), &iter, - 0, cValue.get(), - 1, nsCertP, - -1); - } - else - { - char * title; - rv = nsCert->GetWindowTitle (&title); - if (NS_FAILED(rv)) return FALSE; - - gtk_tree_store_set (GTK_TREE_STORE(model), - &iter, 0, title, 1, nsCertP, -1); - nsMemory::Free (title); - } - parent = iter; - } - gtk_tree_view_expand_all (GTK_TREE_VIEW (treeview)); - - /* And select the last entry, and scroll the view so it's visible */ - GtkTreeSelection *select = gtk_tree_view_get_selection (treeview); - GtkTreePath *path = gtk_tree_model_get_path (model, &parent); - gtk_tree_selection_select_path (select, path); - gtk_tree_view_scroll_to_cell (treeview, path, NULL, TRUE, 0.5, 0.0); - gtk_tree_path_free (path); - - return TRUE; -} - -/** - * Add an ASN object to the treeview, recursing if the object was a - * sequence - */ -static void -add_asn1_object_to_tree(GtkTreeModel *model, nsIASN1Object *object, GtkTreeIter *parent) -{ - nsString dispNameU; - object->GetDisplayName(dispNameU); - - GtkTreeIter iter; - gtk_tree_store_append (GTK_TREE_STORE (model), &iter, parent); - - gtk_tree_store_set (GTK_TREE_STORE(model), &iter, - 0, NS_ConvertUTF16toUTF8 (dispNameU).get(), - 1, object, - -1); - - nsCOMPtr<nsIASN1Sequence> sequence(do_QueryInterface(object)); - if (!sequence) return; - - nsCOMPtr<nsIMutableArray> asn1Objects; - sequence->GetASN1Objects(getter_AddRefs(asn1Objects)); - - PRUint32 numObjects; - asn1Objects->GetLength(&numObjects); - if (!asn1Objects) return; - - for (PRUint32 i = 0; i < numObjects ; i++) - { - nsCOMPtr<nsIASN1Object> currObject; - asn1Objects->QueryElementAt (i, kASN1ObjectCID, - getter_AddRefs (currObject)); - add_asn1_object_to_tree (model, currObject, &iter); - } -} - - -/** - * Update the "Certificate Fields" treeview when a different cert - * is selected in the hierarchy text view - */ -static void -cert_chain_tree_view_selection_changed_cb (GtkTreeSelection *selection, - GtkWidget* tree_view) -{ - GtkTreeIter iter; - nsIX509Cert *nsCert; - nsresult rv; - GtkTreeModel * model; - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - { - gtk_tree_model_get (model, &iter, 1, &nsCert, -1); - - nsCOMPtr<nsIASN1Object> object; - rv = nsCert->GetASN1Structure (getter_AddRefs(object)); - if (NS_FAILED(rv)) return; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); - gtk_tree_store_clear (GTK_TREE_STORE (model)); - add_asn1_object_to_tree (model, object, NULL); - - gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view)); - } -} - -/** - * When the "Certificate Field" treeview is changed, update the - * text_view to display the value of the currently selected field - */ -static void -field_tree_view_selection_changed_cb (GtkTreeSelection *selection, - GtkWidget* text_view) -{ - GtkTreeIter iter; - GtkTreeModel *model; - GtkTextBuffer * text_buffer = - gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); - - if (gtk_tree_selection_get_selected (selection, &model, &iter)) - { - nsIASN1Object *object; - - gtk_tree_model_get (model, &iter, 1, &object, -1); - - nsString dispValU; - object->GetDisplayValue(dispValU); - - gtk_text_buffer_set_text (text_buffer, NS_ConvertUTF16toUTF8 (dispValU).get(), -1); - } - else - { - gtk_text_buffer_set_text (text_buffer, "", 0); - } -} - -/** - * Setup the various treeviews, the textview, and fill the treeviews - */ -static gboolean -setup_view_cert_tree (GtkWidget *dialog, GladeXML*gxml, nsIArray *certChain) -{ - GtkCellRenderer *renderer; - GtkWidget *chain_tree_view, *field_tree_view, *text_view; - PangoFontDescription *monospace_font_desc; - GConfClient *conf_client; - char *monospace_font; - - chain_tree_view = glade_xml_get_widget (gxml, "treeview_cert_chain"); - field_tree_view = glade_xml_get_widget (gxml, "treeview_cert_info"); - text_view = glade_xml_get_widget (gxml, "textview_field_value"); - - /* Setup the certificate chain view */ - GtkTreeStore *store = gtk_tree_store_new (2, - G_TYPE_STRING, - G_TYPE_POINTER); - gtk_tree_view_set_model (GTK_TREE_VIEW (chain_tree_view), GTK_TREE_MODEL (store)); - g_object_unref (store); - - - renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (chain_tree_view), - 0, "Certificate", - renderer, - "text", 0, - (char *) NULL); - - GtkTreeSelection *select = gtk_tree_view_get_selection (GTK_TREE_VIEW (chain_tree_view)); - gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE); - - g_signal_connect (G_OBJECT (select), "changed", - G_CALLBACK (cert_chain_tree_view_selection_changed_cb), - field_tree_view); - - /* Setup the certificate field view */ - store = gtk_tree_store_new (2, - G_TYPE_STRING, - G_TYPE_POINTER); - gtk_tree_view_set_model (GTK_TREE_VIEW (field_tree_view), GTK_TREE_MODEL (store)); - g_object_unref (store); - - - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (field_tree_view), - 0, "Certificate Field", - renderer, - "text", 0, - (char *) NULL); - - select = gtk_tree_view_get_selection (GTK_TREE_VIEW (field_tree_view)); - gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE); - - g_signal_connect (G_OBJECT (select), "changed", - G_CALLBACK (field_tree_view_selection_changed_cb), - text_view); - - /* Get the text_view displaying a propertional font - * - * Pick up the monospace font from desktop preferences */ - conf_client = gconf_client_get_default (); - monospace_font = gconf_client_get_string (conf_client, - "/desktop/gnome/interface/monospace_font_name", NULL); - if (monospace_font) - { - monospace_font_desc = pango_font_description_from_string (monospace_font); - gtk_widget_modify_font (text_view, monospace_font_desc); - pango_font_description_free (monospace_font_desc); - } - g_object_unref (conf_client); - - /* And fill the certificate chain tree */ - return fill_cert_chain_tree (GTK_TREE_VIEW (chain_tree_view), certChain); -} - -/* void viewCert (in nsIX509Cert cert); */ -NS_IMETHODIMP -GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, - nsIX509Cert *cert) -{ - GtkWidget *dialog, *widget; - GladeXML *gxml; - nsString value; - PRUint32 verifystate, count; - PRUnichar ** usage; - GtkSizeGroup * sizegroup; - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - return NS_OK; - - GtkWindow *gparent = modalDialog.GetParent (); - - gxml = glade_xml_new (ephy_file ("certificate-dialogs.glade"), - "viewcert_dialog", NULL); - g_return_val_if_fail (gxml != NULL, NS_ERROR_FAILURE); - - dialog = glade_xml_get_widget (gxml, "viewcert_dialog"); - g_return_val_if_fail (dialog != NULL, NS_ERROR_FAILURE); - - if (gparent) - { - gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(gparent)); - gtk_window_group_add_window (ephy_gui_ensure_window_group (GTK_WINDOW (gparent)), - GTK_WINDOW (dialog)); - gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - } - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - gtk_window_set_title (GTK_WINDOW (dialog), _("Certificate Properties")); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); - - /* Set up the GtkSizeGroup so that the columns line up */ - sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - widget = glade_xml_get_widget (gxml, "label_size1"); - gtk_size_group_add_widget (sizegroup, widget); - widget = glade_xml_get_widget (gxml, "label_size2"); - gtk_size_group_add_widget (sizegroup, widget); - widget = glade_xml_get_widget (gxml, "label_size3"); - gtk_size_group_add_widget (sizegroup, widget); - widget = glade_xml_get_widget (gxml, "label_size4"); - gtk_size_group_add_widget (sizegroup, widget); - g_object_unref (sizegroup); - - nsresult rv; - rv = cert->GetUsagesArray (FALSE, &verifystate, &count, &usage); - if (NS_FAILED(rv)) return rv; - - const char * text; - switch (verifystate) - { - case nsIX509Cert::VERIFIED_OK: - text = _("This certificate has been verified for the following uses:"); - break; - case nsIX509Cert::CERT_REVOKED: - text = _("Could not verify this certificate because it has been revoked."); - break; - case nsIX509Cert::CERT_EXPIRED: - text = _("Could not verify this certificate because it has expired."); - break; - case nsIX509Cert::CERT_NOT_TRUSTED: - text = _("Could not verify this certificate because it is not trusted."); - break; - case nsIX509Cert::ISSUER_NOT_TRUSTED: - text = _("Could not verify this certificate because the issuer is not trusted."); - break; - case nsIX509Cert::ISSUER_UNKNOWN: - text = _("Could not verify this certificate because the issuer is unknown."); - break; - case nsIX509Cert::INVALID_CA: - text = _("Could not verify this certificate because the CA certificate is invalid."); - break; - case nsIX509Cert::NOT_VERIFIED_UNKNOWN: - case nsIX509Cert::USAGE_NOT_ALLOWED: - default: - text = _("Could not verify this certificate for unknown reasons."); - } - - char *vmsg = g_strdup_printf ("<b>%s</b>", text); - widget = glade_xml_get_widget (gxml, "label_verify_text"); - g_return_val_if_fail (GTK_IS_LABEL (widget), NS_ERROR_FAILURE); - gtk_label_set_markup (GTK_LABEL (widget), vmsg); - g_free (vmsg); - - if (count > 0) - { - GtkWidget *vbox = gtk_vbox_new (FALSE, 3); - GtkWidget *indent; - for (PRUint32 i = 0 ; i < count ; i++) - { - GtkWidget *label = gtk_label_new (NS_ConvertUTF16toUTF8 (usage[i]).get()); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - nsMemory::Free (usage[i]); - } - nsMemory::Free (usage); - indent = higgy_indent_widget (vbox); - widget = glade_xml_get_widget (gxml, "vbox_validity"); - g_return_val_if_fail (GTK_IS_BOX (widget), NS_ERROR_FAILURE); - - gtk_box_pack_start (GTK_BOX (widget), indent, FALSE, FALSE, 0); - } - - cert->GetCommonName (value); - set_label_cert_attribute (gxml, "label_cn", value); - - cert->GetOrganization (value); - set_label_cert_attribute (gxml, "label_o", value); - - cert->GetOrganizationalUnit (value); - set_label_cert_attribute (gxml, "label_ou", value); - - cert->GetSerialNumber (value); - set_label_cert_attribute (gxml, "label_serial", value); - - rv = cert->GetIssuerCommonName (value); - if (NS_FAILED(rv)) return rv; - set_label_cert_attribute (gxml, "label_issuer_cn", value); - - cert->GetIssuerOrganization (value); - set_label_cert_attribute (gxml, "label_issuer_o", value); - - cert->GetIssuerOrganizationUnit (value); - set_label_cert_attribute (gxml, "label_issuer_ou", value); - - nsCOMPtr<nsIX509CertValidity> validity; - rv = cert->GetValidity (getter_AddRefs(validity)); - if (NS_FAILED(rv)) return rv; - - rv = validity->GetNotAfterLocalDay (value); - if (NS_FAILED(rv)) return rv; - set_label_cert_attribute (gxml, "label_notafter", value); - - rv = validity->GetNotBeforeLocalDay (value); - if (NS_FAILED(rv)) return rv; - set_label_cert_attribute (gxml, "label_notbefore", value); - - cert->GetSha1Fingerprint (value); - set_label_cert_attribute (gxml, "label_sha_print", value); - - cert->GetMd5Fingerprint (value); - set_label_cert_attribute (gxml, "label_md5_print", value); - - /* Hold a reference to each certificate in the chain while the - * dialog is displayed, this holds the reference for the ASN - * objects as well */ - - nsCOMPtr<nsIArray> certChain; - rv = cert->GetChain (getter_AddRefs(certChain)); - if (NS_FAILED(rv)) return rv; - - gboolean ret = setup_view_cert_tree (dialog, gxml, certChain); - if (ret == FALSE) return NS_ERROR_FAILURE; - - g_object_unref (gxml); - - gtk_widget_show_all (dialog); - - int res; - while (1) - { - res = modalDialog.Run (GTK_DIALOG (dialog)); - if (res == GTK_RESPONSE_HELP) - { - ephy_gui_help (GTK_WINDOW (dialog), "epiphany", "using-certificate-viewer"); - continue; - } - break; - } - - gtk_widget_destroy (dialog); - return NS_OK; -} - -/* nsITokenPasswordDialogs */ - -/* NOTE: This interface totally sucks, see https://bugzilla.mozilla.org/show_bug.cgi?id=306993 */ - -/* void setPassword (in nsIInterfaceRequestor ctx, in wstring tokenName, out boolean canceled); */ -NS_IMETHODIMP -GtkNSSDialogs::SetPassword(nsIInterfaceRequestor *aCtx, - const PRUnichar *aTokenName, - PRBool *aCancelled) -{ - NS_ENSURE_ARG_POINTER(aCancelled); - - nsresult rv; - nsCOMPtr<nsIPK11Token> token; - nsCOMPtr<nsIPKCS11Slot> slot; - rv = GetTokenAndSlotFromName (aTokenName, getter_AddRefs (token), - getter_AddRefs (slot)); - NS_ENSURE_SUCCESS (rv, rv); - NS_ENSURE_TRUE (token && slot, NS_ERROR_FAILURE); - - AutoJSContextStack stack; - rv = stack.Init (); - if (NS_FAILED (rv)) return rv; - - PRUint32 status = nsIPKCS11Slot::SLOT_UNINITIALIZED; - slot->GetStatus (&status); - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *aCancelled = PR_TRUE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - EphyPasswordDialogFlags flags = - EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_NEW_PASSWORD | - EPHY_PASSWORD_DIALOG_FLAGS_SHOW_QUALITY_METER); - if (status != nsIPKCS11Slot::SLOT_UNINITIALIZED) - flags = EphyPasswordDialogFlags (flags | EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD); - - GtkWidget *dialog = ephy_password_dialog_new - (GTK_WIDGET (gparent), - _("Change Token Password"), - flags); - EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog); - - char *message; - if (status == nsIPKCS11Slot::SLOT_UNINITIALIZED) { - message = g_markup_printf_escaped (_("Choose a password for the “%s” token"), - NS_ConvertUTF16toUTF8 (aTokenName).get ()); - } else { - message = g_markup_printf_escaped (_("Change the password for the “%s” token"), - NS_ConvertUTF16toUTF8 (aTokenName).get ()); - } - - gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), - message); - g_free (message); - - int response; - nsString oldPassword; - PRBool pwdOk, needsLogin; - do { - response = modalDialog.Run (GTK_DIALOG (dialog)); - - if (status != nsIPKCS11Slot::SLOT_UNINITIALIZED) - { - const char *pwd = ephy_password_dialog_get_password (password_dialog); - oldPassword = NS_ConvertUTF8toUTF16 (pwd); - } - } while (response == GTK_RESPONSE_OK && - status != nsIPKCS11Slot::SLOT_UNINITIALIZED && - NS_SUCCEEDED (token->NeedsLogin (&needsLogin)) && needsLogin && - NS_SUCCEEDED (token->CheckPassword (oldPassword.get (), &pwdOk) && - !pwdOk)); - - if (response == GTK_RESPONSE_ACCEPT) - { - const char *pwd = ephy_password_dialog_get_new_password (password_dialog); - - NS_ConvertUTF8toUTF16 newPassword (pwd); - - if (status == nsIPKCS11Slot::SLOT_UNINITIALIZED) - { - rv = token->InitPassword (newPassword.get ()); - } - else - { - rv = token->ChangePassword (oldPassword.get (), - newPassword.get ()); - } - } - else - { - rv = NS_OK; - } - - gtk_widget_destroy (GTK_WIDGET (dialog)); - - *aCancelled = response != GTK_RESPONSE_ACCEPT; - - return rv; -} - -/* void getPassword (in nsIInterfaceRequestor ctx, in wstring tokenName, out wstring password, out boolean canceled); */ -NS_IMETHODIMP -GtkNSSDialogs::GetPassword(nsIInterfaceRequestor *aCtx, - const PRUnichar *aTokenName, - PRUnichar **aPassword, - PRBool *aCancelled) -{ - NS_ENSURE_ARG_POINTER(aCancelled); - - nsresult rv; - nsCOMPtr<nsIPK11Token> token; - nsCOMPtr<nsIPKCS11Slot> slot; - rv = GetTokenAndSlotFromName (aTokenName, getter_AddRefs (token), - getter_AddRefs (slot)); - NS_ENSURE_SUCCESS (rv, rv); - NS_ENSURE_TRUE (token && slot, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *aCancelled = PR_TRUE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - EphyPasswordDialogFlags flags = - EphyPasswordDialogFlags (EPHY_PASSWORD_DIALOG_FLAGS_SHOW_PASSWORD); - - GtkWidget *dialog = ephy_password_dialog_new - (GTK_WIDGET (gparent), - _("Get Token Password"), /* FIXME */ - flags); - EphyPasswordDialog *password_dialog = EPHY_PASSWORD_DIALOG (dialog); - - /* Translators: A "token" is something that enables the user to authenticate himself or - * prove his credentials. This can be either a hardware device (e.g. a smart-card), or - * a data file (e.g. a cryptographic certificate). - */ - char *message = g_markup_printf_escaped (_("Please enter the password for the “%s” token"), - NS_ConvertUTF16toUTF8 (aTokenName).get ()); - gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), - message); - g_free (message); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - - if (response == GTK_RESPONSE_ACCEPT) - { - const char *pwd = ephy_password_dialog_get_password (password_dialog); - *aPassword = NS_StringCloneData (NS_ConvertUTF8toUTF16 (pwd)); - } - - gtk_widget_destroy (GTK_WIDGET (dialog)); - - *aCancelled = response != GTK_RESPONSE_ACCEPT; - - return NS_OK; -} - -/* nsITokenDialogs */ - -static void -SelectionChangedCallback (GtkComboBox *combo, - GtkDialog *dialog) -{ - int active = gtk_combo_box_get_active (combo); - gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_ACCEPT, active >= 0); -} - -/* void ChooseToken (in nsIInterfaceRequestor ctx, - [array, size_is (count)] in wstring tokenNameList, - in unsigned long count, - out wstring tokenName, - out boolean canceled); */ -NS_IMETHODIMP -GtkNSSDialogs::ChooseToken (nsIInterfaceRequestor *aContext, - const PRUnichar **tokenNameList, - PRUint32 count, - PRUnichar **_tokenName, - PRBool *_cancelled) -{ - NS_ENSURE_ARG (tokenNameList); - NS_ENSURE_ARG (count); - - /* Didn't you know it? MOZILLA SUCKS! ChooseToken is always called with |aContext| == NULL! See - * http://bonsai.mozilla.org/cvsblame.cgi?file=mozilla/security/manager/ssl/src/nsKeygenHandler.cpp&rev=1.39&mark=346#346 - * Need to investigate if we it's always called directly from code called from JS, in which case we - * can use EphyJSUtils::GetDOMWindowFromCallContext. - */ - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aContext)); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) { - *_cancelled = PR_TRUE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - GtkWidget *dialog = gtk_message_dialog_new - (gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_OTHER, - GTK_BUTTONS_CANCEL, - _("Please select a token:")); - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - GtkWidget *combo = gtk_combo_box_new_text (); - for (PRUint32 i = 0; i < count; ++i) { - gtk_combo_box_append_text (GTK_COMBO_BOX (combo), - NS_ConvertUTF16toUTF8 (tokenNameList[i]).get ()); - } - gtk_combo_box_set_active (GTK_COMBO_BOX (combo), -1); - g_signal_connect (combo, "changed", - G_CALLBACK (SelectionChangedCallback), dialog); - - /* FIXME: View Cert button? */ - - GtkWidget *vbox = GTK_MESSAGE_DIALOG (dialog)->label->parent; - gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0); - - gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Select"), - GTK_RESPONSE_ACCEPT); - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - int selected = gtk_combo_box_get_active (GTK_COMBO_BOX (combo)); - - gtk_widget_destroy (dialog); - - *_cancelled = response != GTK_RESPONSE_ACCEPT; - - if (response == GTK_RESPONSE_ACCEPT) { - NS_ENSURE_TRUE (selected >= 0 && selected < (int) count, NS_ERROR_FAILURE); - *_tokenName = NS_StringCloneData (nsDependentString (tokenNameList[selected])); - } - - return NS_OK; -} - -#ifdef HAVE_GECKO_1_9 -/* void displayProtectedAuth (in nsIInterfaceRequestor ctx, in nsIProtectedAuthThread runnable); */ -NS_IMETHODIMP -GtkNSSDialogs::DisplayProtectedAuth (nsIInterfaceRequestor *ctx, - nsIProtectedAuthThread *runnable) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -#endif /* HAVE_GECKO_1_9 */ - -/* nsIDOMCryptoDialogs */ - -/* Note: this interface sucks! See https://bugzilla.mozilla.org/show_bug.cgi?id=341914 */ - -/* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */ -NS_IMETHODIMP -GtkNSSDialogs::ConfirmKeyEscrow (nsIX509Cert *aEscrowAuthority, - PRBool *_retval) -{ - NS_ENSURE_ARG (aEscrowAuthority); - - nsresult rv; - AutoJSContextStack stack; - rv = stack.Init (); - if (NS_FAILED (rv)) return rv; - -#if 0 - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (aCtx)); -#endif - nsCOMPtr<nsIDOMWindow> parent (EphyJSUtils::GetDOMWindowFromCallContext ()); - - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) { - *_retval = PR_FALSE; - return NS_OK; - } - - GtkWindow *gparent = modalDialog.GetParent (); - - /* FIXME: is that guaranteed to be non-empty? */ - nsString commonName; - aEscrowAuthority->GetCommonName (commonName); - - GtkWidget *dialog = gtk_message_dialog_new - (gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_WARNING /* QUESTION really but it's also a strong warnings... */, - GTK_BUTTONS_NONE, - _("Escrow the secret key?")); - - /* FIXME: If I understand the documentation of generateCRMFRequest - * correctly, key escrow is never used for signing keys (if it were, - * we'd have to warn that the cert authority can forge your signature - * too). - */ - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), - _("The certificate authority “%s” requests that you give it a copy " - "of the newly generated secret key.\n\n" - "This will enable the certificate authority read any " - "communications encrypted with this key " - "without your knowledge or consent.\n\n" - "It is strongly recommended not to allow it."), - NS_ConvertUTF16toUTF8 (commonName).get ()); - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - GtkWidget *button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Reject"), - GTK_RESPONSE_REJECT); - gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Allow"), - GTK_RESPONSE_ACCEPT); - /* FIXME: View Cert button? */ - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); - gtk_widget_grab_focus (button); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - *_retval = response == GTK_RESPONSE_ACCEPT; - - return NS_OK; -} diff --git a/embed/mozilla/GtkNSSDialogs.h b/embed/mozilla/GtkNSSDialogs.h deleted file mode 100644 index 91e89f370..000000000 --- a/embed/mozilla/GtkNSSDialogs.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * Copyright © 2006 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef GTKNSSDIALOGS_H -#define GTKNSSDIALOGS_H 1 - -#ifndef HAVE_GECKO_1_9 -#include <nsIBadCertListener.h> -#endif -#include <nsICertificateDialogs.h> -#include <nsITokenPasswordDialogs.h> -#include <nsITokenDialogs.h> -#include <nsIDOMCryptoDialogs.h> - -class nsIPK11Token; -class nsIPKCS11Slot; - -/* 7a50a10d-9425-4e12-84b1-5822edacd8ce */ -#define GTK_NSSDIALOGS_CID \ - {0x7a50a10d, 0x9425, 0x4e12, {0x84, 0xb1, 0x58, 0x22, 0xed, 0xac, 0xd8, 0xce}} - -#define GTK_NSSDIALOGS_CLASSNAME "Gtk NSS Dialogs" - -class GtkNSSDialogs : public nsICertificateDialogs, -#ifndef HAVE_GECKO_1_9 - public nsIBadCertListener, -#endif - public nsITokenPasswordDialogs, - public nsITokenDialogs, - public nsIDOMCryptoDialogs -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSICERTIFICATEDIALOGS -#ifndef HAVE_GECKO_1_9 - NS_DECL_NSIBADCERTLISTENER -#endif - NS_DECL_NSITOKENPASSWORDDIALOGS - NS_DECL_NSITOKENDIALOGS - NS_DECL_NSIDOMCRYPTODIALOGS - - GtkNSSDialogs(); - virtual ~GtkNSSDialogs(); - - private: - nsresult GetTokenAndSlotFromName(const PRUnichar*, nsIPK11Token**, nsIPKCS11Slot**); -}; - -#endif /* GTKNSSDIALOGS_H */ diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp deleted file mode 100644 index 916cf5b7c..000000000 --- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * GtkNSSKeyPairDialogs.cpp - * - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -/* - * This file provides Gtk implementations of the mozilla Generating Key Pair - * dialogs. - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gi18n.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkimage.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmain.h> -#include <gtk/gtkprogressbar.h> -#include <gtk/gtkstock.h> -#include <gtk/gtkvbox.h> - -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIKeygenThread.h> -#include <nsIObserver.h> -#include <nsIServiceManager.h> - -#include "ephy-debug.h" -#include "ephy-gui.h" -#include "ephy-stock-icons.h" - -#include "AutoModalDialog.h" - -#include "GtkNSSKeyPairDialogs.h" - -GtkNSSKeyPairDialogs::GtkNSSKeyPairDialogs () -{ - LOG ("GtkNSSKeyPairDialogs ctor (%p)", this); -} - -GtkNSSKeyPairDialogs::~GtkNSSKeyPairDialogs () -{ - LOG ("GtkNSSKeyPairDialogs dtor (%p)", this); -} - -NS_IMPL_THREADSAFE_ISUPPORTS1 (GtkNSSKeyPairDialogs, - nsIGeneratingKeypairInfoDialogs) - -class KeyPairObserver : public nsIObserver -{ -public: - NS_DECL_NSIOBSERVER - NS_DECL_ISUPPORTS - - KeyPairObserver() : close_called (FALSE) {}; - virtual ~KeyPairObserver() {}; - - gboolean close_called; -}; - -NS_IMPL_ISUPPORTS1 (KeyPairObserver, nsIObserver); - -NS_IMETHODIMP KeyPairObserver::Observe (nsISupports *aSubject, const char *aTopic, - const PRUnichar *aData) -{ - close_called = TRUE; - return NS_OK; -} - -/* ------------------------------------------------------------ */ -static void -begin_busy (GtkWidget *widget) -{ - static GdkCursor *cursor = NULL; - - if (cursor == NULL) cursor = gdk_cursor_new (GDK_WATCH); - - if (!GTK_WIDGET_REALIZED (widget)) gtk_widget_realize (GTK_WIDGET(widget)); - - gdk_window_set_cursor (GTK_WIDGET (widget)->window, cursor); - - /* Eek! FIXME: AutoJSContextStack! */ - while (gtk_events_pending ()) gtk_main_iteration (); -} - -static void -end_busy (GtkWidget *widget) -{ - gdk_window_set_cursor (GTK_WIDGET(widget)->window, NULL); -} - - -struct KeyPairInfo -{ - GtkWidget *progress; - GtkWidget *dialog; - KeyPairObserver *helper; -}; - - -static gboolean -generating_timeout_cb (KeyPairInfo *info) -{ - gtk_progress_bar_pulse (GTK_PROGRESS_BAR (info->progress)); - - if (info->helper->close_called) - { - gtk_dialog_response (GTK_DIALOG (info->dialog), GTK_RESPONSE_OK); - } - return TRUE; -} - - -/* void displayGeneratingKeypairInfo (in nsIInterfaceRequestor ctx, - in nsIKeygenThread runnable); */ -NS_IMETHODIMP -GtkNSSKeyPairDialogs::DisplayGeneratingKeypairInfo (nsIInterfaceRequestor *ctx, - nsIKeygenThread *runnable) -{ - GtkWidget *dialog, *progress, *label, *vbox; - gint timeout_id; - - nsCOMPtr<nsIDOMWindow> parent (do_GetInterface (ctx)); - AutoModalDialog modalDialog (parent, PR_FALSE); - if (!modalDialog.ShouldShow ()) - return NS_ERROR_ABORT; - - GtkWindow *gparent = modalDialog.GetParent (); - - dialog = gtk_dialog_new_with_buttons ("", gparent, - GTK_DIALOG_DESTROY_WITH_PARENT, (char *) NULL); - - if (gparent) - { - gtk_window_group_add_window (ephy_gui_ensure_window_group (gparent), - GTK_WINDOW (dialog)); - } - - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); - - vbox = gtk_vbox_new (FALSE, 12); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0); - - label = gtk_label_new (NULL); - gtk_label_set_use_markup (GTK_LABEL (label), TRUE); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); - - char *msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", - _("Generating Private Key."), - _("Please wait while a new private key is " - "generated. This process could take a few minutes." )); - gtk_label_set_markup (GTK_LABEL(label), msg); - g_free (msg); - - progress = gtk_progress_bar_new (); - gtk_box_pack_start (GTK_BOX (vbox), progress, TRUE, TRUE, 0); - - /* Create a helper class that just waits for close events - * from the other thread */ - nsCOMPtr<KeyPairObserver> helper = new KeyPairObserver; - - KeyPairInfo callback_data = { progress, dialog, helper }; - timeout_id = g_timeout_add (100, (GSourceFunc)generating_timeout_cb, &callback_data); - - gtk_widget_show_all (dialog); - gtk_widget_hide (GTK_DIALOG (dialog)->action_area); - - begin_busy (dialog); - runnable->StartKeyGeneration (helper); - int res = modalDialog.Run (GTK_DIALOG (dialog)); - if (res != GTK_RESPONSE_OK && helper->close_called == FALSE) - { - /* Ignore the already_closed flag, our nsIDOMWindowInterna::Close - * function just sets a flag, it doesn't close the window, so we - * dont have a race condition */ - PRBool already_closed = FALSE; - runnable->UserCanceled (&already_closed); - } - - g_source_remove (timeout_id); - end_busy (dialog); - gtk_widget_destroy (dialog); - return NS_OK; -} diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.h b/embed/mozilla/GtkNSSKeyPairDialogs.h deleted file mode 100644 index f4b92d9e1..000000000 --- a/embed/mozilla/GtkNSSKeyPairDialogs.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2003 Crispin Flowerday <gnome@flowerday.cx> - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * - * $Id$ - */ - -#ifndef GTKNSSKEYPAIRDIALOGS_H -#define GTKNSSKEYPAIRDIALOGS_H 1 - -#include <nsIGenKeypairInfoDlg.h> - -// 6a8b1aff-ae8b-4751-982e-4ce5ad544100 -#define GTK_NSSKEYPAIRDIALOGS_CID \ - {0x6a8b1aff, 0xae8b, 0x4751, {0x98, 0x2e, 0x4c, 0xe5, 0xad, 0x54, 0x41, 0x10}} - -#define GTK_NSSKEYPAIRDIALOGS_CLASSNAME "Gtk NSS Key Pair Dialogs" - -class GtkNSSKeyPairDialogs -: public nsIGeneratingKeypairInfoDialogs -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIGENERATINGKEYPAIRINFODIALOGS - - GtkNSSKeyPairDialogs(); - virtual ~GtkNSSKeyPairDialogs(); -}; - - -#endif /* GTKNSSKEYPAIRDIALOGS_H */ diff --git a/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp b/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp deleted file mode 100644 index 4e8d80c6d..000000000 --- a/embed/mozilla/GtkNSSSecurityWarningDialogs.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Terry Hayes <thayes@netscape.com> - * Javier Delgadillo <javi@netscape.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * Copyright © 2005 Christian Persch - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gi18n.h> -#include <gtk/gtkbox.h> -#include <gtk/gtkdialog.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkvbox.h> - -#include "ephy-stock-icons.h" - -#include <nsCOMPtr.h> -#include <nsIDOMWindow.h> -#include <nsIInterfaceRequestor.h> -#include <nsIInterfaceRequestorUtils.h> -#include <nsIPrefBranch.h> -#include <nsIPrefService.h> -#include <nsIServiceManager.h> -#include <nsServiceManagerUtils.h> - -#include "AutoModalDialog.h" - -#include "GtkNSSSecurityWarningDialogs.h" - -NS_IMPL_THREADSAFE_ISUPPORTS1 (GtkNSSSecurityWarningDialogs, nsISecurityWarningDialogs) - -#define ENTER_SITE_PREF "security.warn_entering_secure" -#define WEAK_SITE_PREF "security.warn_entering_weak" -#define MIXEDCONTENT_PREF "security.warn_viewing_mixed" -#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure" - -GtkNSSSecurityWarningDialogs::GtkNSSSecurityWarningDialogs() -{ -} - -GtkNSSSecurityWarningDialogs::~GtkNSSSecurityWarningDialogs() -{ -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmEnteringSecure (nsIInterfaceRequestor *aContext, - PRBool *_retval) -{ - DoDialog (aContext, - ENTER_SITE_PREF, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - GTK_RESPONSE_OK, - _("Security Notice"), - _("This page is loaded over a secure connection"), - _("For secure pages, the address entry has a distinct " - "color and a locked padlock icon is displayed.\n\n" - "The padlock icon in the statusbar also indicates " - "whether a page is secure."), - nsnull, _retval); - - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmEnteringWeak (nsIInterfaceRequestor *aContext, - PRBool *_retval) -{ - DoDialog (aContext, - WEAK_SITE_PREF, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - GTK_RESPONSE_OK, - _("Security Warning"), - _("This page is loaded over a low security connection"), - _("Any information you see or enter on this page could " - "easily be intercepted by a third party."), - nsnull, _retval); - - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmLeavingSecure (nsIInterfaceRequestor *aContext, - PRBool *_retval) -{ - /* don't prompt */ - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmMixedMode (nsIInterfaceRequestor *aContext, - PRBool *_retval) -{ - DoDialog (aContext, - MIXEDCONTENT_PREF, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - GTK_RESPONSE_OK, - _("Security Warning"), - _("Some parts of this page are loaded over an insecure connection"), - _("Some information you see or enter will be sent over an insecure " - "connection, and could easily be intercepted by a third party."), - nsnull, _retval); - - *_retval = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmPostToInsecure (nsIInterfaceRequestor *aContext, - PRBool* _retval) -{ - DoDialog (aContext, - INSECURE_SUBMIT_PREF, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CANCEL, - GTK_RESPONSE_ACCEPT, - _("Security Warning"), - _("Send this information over an insecure connection?"), - _("The information you have entered will be sent over an " - "insecure connection, and could easily be intercepted " - "by a third party."), - _("_Send"), - _retval); - - return NS_OK; -} - -NS_IMETHODIMP -GtkNSSSecurityWarningDialogs::ConfirmPostToInsecureFromSecure (nsIInterfaceRequestor *aContext, - PRBool* _retval) -{ - DoDialog (aContext, - nsnull, /* No preference for this one - it's too important */ - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CANCEL, - GTK_RESPONSE_CANCEL, - _("Security Warning"), - _("Send this information over an insecure connection?"), - _("Although this page was loaded over a secure connection, " - "the information you have entered will be sent over an " - "insecure connection, and could easily be intercepted by " - "a third party."), - _("_Send"), - _retval); - - return NS_OK; -} - -void -GtkNSSSecurityWarningDialogs::DoDialog (nsIInterfaceRequestor *aContext, - const char *aPrefName, - GtkMessageType aType, - GtkButtonsType aButtons, - int aDefaultResponse, - const char *aTitle, - const char *aPrimary, - const char *aSecondary, - const char *aButtonText, - PRBool *_retval) -{ - *_retval = PR_FALSE; - - nsresult rv; - PRBool show = PR_TRUE; - nsCOMPtr<nsIPrefBranch> prefBranch - (do_GetService (NS_PREFSERVICE_CONTRACTID)); - if (prefBranch && aPrefName) - { - rv = prefBranch->GetBoolPref (aPrefName, &show); - if (NS_FAILED(rv)) show = PR_TRUE; - } - - char *showOncePref = NULL; - PRBool showOnce = PR_FALSE; - if (!show && prefBranch && aPrefName) - { - showOncePref = g_strconcat (aPrefName, ".show_once", (char *) NULL); - rv = prefBranch->GetBoolPref (showOncePref, &showOnce); - if (NS_FAILED (rv)) showOnce = PR_FALSE; - } - - if (!show && !showOnce) - { - g_free (showOncePref); - *_retval = PR_TRUE; - return; - } - - /* On 1.8.0, domWin will be always nsnull, because of - * https://bugzilla.mozilla.org/show_bug.cgi?id=277587 - */ - nsCOMPtr<nsIDOMWindow> domWin (do_GetInterface (aContext)); - - AutoModalDialog modalDialog (domWin, PR_FALSE); - if (!modalDialog.ShouldShow ()) - { - *_retval = PR_FALSE; - return; - } - - GtkWindow *parent = modalDialog.GetParent (); - - GtkWidget *dialog = gtk_message_dialog_new (parent, - GTK_DIALOG_MODAL, aType, - aButtons, "%s", aPrimary); - - if (parent && parent->group) - { - gtk_window_group_add_window (parent->group, - GTK_WINDOW (dialog)); - } - - if (aSecondary) - { - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dialog), "%s", aSecondary); - } - - if (aButtonText) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), aButtonText, - GTK_RESPONSE_ACCEPT); - } - - gtk_dialog_set_default_response (GTK_DIALOG (dialog), aDefaultResponse); - - gtk_window_set_title (GTK_WINDOW (dialog), aTitle); - gtk_window_set_icon_name (GTK_WINDOW (dialog), EPHY_STOCK_EPHY); - - int response = modalDialog.Run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - - *_retval = (response == GTK_RESPONSE_ACCEPT || response == GTK_RESPONSE_OK); - - if (prefBranch && showOncePref && showOnce && *_retval) - { - prefBranch->SetBoolPref (showOncePref, PR_FALSE); - } - - g_free (showOncePref); -} diff --git a/embed/mozilla/GtkNSSSecurityWarningDialogs.h b/embed/mozilla/GtkNSSSecurityWarningDialogs.h deleted file mode 100644 index a84ea6585..000000000 --- a/embed/mozilla/GtkNSSSecurityWarningDialogs.h +++ /dev/null @@ -1,83 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Terry Hayes <thayes@netscape.com> - * Javier Delgadillo <javi@netscape.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * Copyright © 2005 Christian Persch - * - * $Id$ - */ - -#ifndef GTK_NSSSECURITYDIALOGS_H -#define GTK_NSSSECURITYDIALOGS_H - -#include <gtk/gtkmessagedialog.h> - -#include <nsISecurityWarningDialogs.h> - -#define GTK_NSSSECURITYWARNINGDIALOGS_CLASSNAME "Epiphany Security Warning Dialogs Class" -#define GTK_NSSSECURITYWARNINGDIALOGS_CID \ -{ \ - /* 1f5eac0a-d7e3-4f8e-b4d5-7240f7cba269 */ \ - 0x1f5eac0a, \ - 0xd7e3, \ - 0x4f8e, \ - { 0xb4, 0xd5, 0x72, 0x40, 0xf7, 0xcb, 0xa2, 0x69 } \ -} - -class GtkNSSSecurityWarningDialogs : public nsISecurityWarningDialogs -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSISECURITYWARNINGDIALOGS - - GtkNSSSecurityWarningDialogs(); - virtual ~GtkNSSSecurityWarningDialogs(); - -protected: - void DoDialog (nsIInterfaceRequestor *aContext, - const char *aPrefName, - GtkMessageType aType, - GtkButtonsType aButtons, - int aDefaultResponse, - const char *aTitle, - const char *aPrimary, - const char *aSecondary, - const char *aButtonText, - PRBool *_retval); -}; - -#endif /* !GTK_NSSSECURITYDIALOGS_H */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am deleted file mode 100644 index c669d399a..000000000 --- a/embed/mozilla/Makefile.am +++ /dev/null @@ -1,176 +0,0 @@ -noinst_LTLIBRARIES = libephymozillaembed.la - -libephymozillaembed_la_SOURCES = \ - AutoJSContextStack.cpp \ - AutoJSContextStack.h \ - AutoModalDialog.cpp \ - AutoModalDialog.h \ - AutoWindowModalState.cpp \ - AutoWindowModalState.h \ - ContentHandler.cpp \ - ContentHandler.h \ - EphyAboutModule.cpp \ - EphyAboutModule.h \ - EphyContentPolicy.cpp \ - EphyContentPolicy.h \ - EphyHeaderSniffer.cpp \ - EphyHeaderSniffer.h \ - EphyBrowser.cpp \ - EphyBrowser.h \ - EphyFind.cpp \ - EphyFind.h \ - EphyHistoryListener.cpp \ - EphyHistoryListener.h \ - EphyPromptService.cpp \ - EphyPromptService.h \ - EphyRedirectChannel.cpp \ - EphyRedirectChannel.h \ - EphySidebar.cpp \ - EphySidebar.h \ - EphySingle.cpp \ - EphySingle.h \ - EphyUtils.cpp \ - EphyUtils.h \ - EventContext.cpp \ - EventContext.h \ - GeckoCookiePromptService.cpp \ - GeckoCookiePromptService.h \ - GeckoFormSigningDialog.cpp \ - GeckoFormSigningDialog.h \ - GeckoPrintService.cpp \ - GeckoPrintService.h \ - GeckoPrintSession.cpp \ - GeckoPrintSession.h \ - GlobalHistory.cpp \ - GlobalHistory.h \ - MozDownload.cpp \ - MozDownload.h \ - MozRegisterComponents.cpp \ - MozRegisterComponents.h \ - mozilla-download.cpp \ - mozilla-download.h \ - mozilla-embed.cpp \ - mozilla-embed.h \ - mozilla-embed-event.cpp \ - mozilla-embed-event.h \ - mozilla-embed-find.cpp \ - mozilla-embed-find.h \ - mozilla-embed-persist.cpp \ - mozilla-embed-persist.h \ - mozilla-embed-single.cpp \ - mozilla-embed-single.h \ - mozilla-history-item.cpp \ - mozilla-history-item.h \ - mozilla-notifiers.cpp \ - mozilla-notifiers.h - -if !HAVE_GECKO_1_9 -libephymozillaembed_la_SOURCES += \ - EphyBadCertRejector.cpp \ - EphyBadCertRejector.h \ - EphyDirectoryProvider.cpp \ - EphyDirectoryProvider.h \ - $(NULL) -endif - -if ENABLE_FILEPICKER -libephymozillaembed_la_SOURCES += \ - FilePicker.cpp \ - FilePicker.h -endif - -if HAVE_MOZILLA_PSM -libephymozillaembed_la_SOURCES += \ - GtkNSSClientAuthDialogs.cpp \ - GtkNSSClientAuthDialogs.h \ - GtkNSSDialogs.cpp \ - GtkNSSDialogs.h \ - GtkNSSKeyPairDialogs.cpp \ - GtkNSSKeyPairDialogs.h \ - GtkNSSSecurityWarningDialogs.cpp\ - GtkNSSSecurityWarningDialogs.h -endif - - -if ENABLE_SPELLCHECKER -libephymozillaembed_la_SOURCES += \ - GeckoSpellCheckEngine.cpp \ - GeckoSpellCheckEngine.h -endif - -mozilla_include_subdirs = \ - . \ - caps \ - chardet \ - chrome \ - commandhandler \ - content \ - cookie \ - docshell \ - dom \ - exthandler \ - fastfind \ - helperAppDlg \ - find \ - gfx \ - gtkembedmoz \ - history \ - js \ - layout \ - locale \ - mimetype \ - necko \ - nkcache \ - passwordmgr \ - pipboot \ - pipnss \ - pref \ - shistory \ - string \ - sidebar \ - spellchecker \ - uriloader \ - uconv \ - wallet \ - webbrowserpersist \ - webbrwsr \ - widget \ - windowwatcher \ - xmlextras \ - xpcom \ - xpconnect - -libephymozillaembed_la_CPPFLAGS = \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/embed \ - -I$(top_srcdir) \ - $(addprefix -I$(GECKO_INCLUDE_ROOT)/,$(mozilla_include_subdirs)) \ - -DSHARE_DIR=\"$(pkgdatadir)\" \ - -DPLUGINDIR=\"$(libdir)/epiphany/$(EPIPHANY_MAJOR)/plugins\" \ - -DMOZILLA_HOME=\"$(GECKO_HOME)\" \ - -DMOZILLA_PREFIX=\"$(GECKO_PREFIX)\" \ - -DMOZILLA_NATIVE_PLUGINSDIR=\"$(libdir)/mozilla/plugins\" \ - -DUA_VERSION=\"$(EPIPHANY_UA_VERSION)\" \ - -DALLOW_PRIVATE_API \ - $(AM_CPPFLAGS) - -if HAVE_GECKO_1_9 -if HAVE_GECKO_XPCOM_GLUE -libephymozillaembed_la_CPPFLAGS += \ - -DXPCOM_GLUE_USE_NSPR -endif -endif - -libephymozillaembed_la_CXXFLAGS = \ - $(GECKO_CFLAGS) \ - $(DEPENDENCIES_CFLAGS) \ - $(AM_CXXFLAGS) - -if HAVE_GECKO_1_9 -xptdir = $(pkgdatadir)/components -xpt_DATA = epiphany.xpt - -noinst_DATA = \ - ephyIAddCertExceptionParams.idl \ - ephyIAddCertExceptionParams.h -endif diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp deleted file mode 100644 index 943da0ff8..000000000 --- a/embed/mozilla/MozDownload.cpp +++ /dev/null @@ -1,844 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen <ccarlen@netscape.com> - * - * Adapted for epiphany by Marco Pesenti Gritti <marco@gnome.org> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <stdlib.h> - -#include <glib/gi18n.h> -#include <gio/gdesktopappinfo.h> -#include <gio/gio.h> - -#include <nsStringAPI.h> - -#include <nsComponentManagerUtils.h> -#include <nsICancelable.h> -#include <nsIChannel.h> -#include <nsIDOMDocument.h> -#include <nsIFileURL.h> -#include <nsIIOService.h> -#include <nsILocalFile.h> -#include <nsIMIMEInfo.h> -#include <nsIMIMEService.h> -#include <nsIObserver.h> -#include <nsIRequest.h> -#include <nsIURI.h> -#include <nsIWritablePropertyBag2.h> -#include <nsIWebBrowserPersist.h> - -#include <nsMemory.h> -#include <nsNetError.h> -#include <nsServiceManagerUtils.h> - -#ifndef HAVE_GECKO_1_9 -#include "EphyBadCertRejector.h" -#endif - -#include "EphyUtils.h" - -#include "eel-gconf-extensions.h" -#include "ephy-debug.h" -#include "ephy-file-helpers.h" -#include "ephy-prefs.h" -#include "mozilla-download.h" - -#include "MozDownload.h" - -/* Minimum time between progress updates */ -#define PROGRESS_RATE 500000 /* microsec */ - -const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; - -MozDownload::MozDownload() : - mTotalProgress(-1), - mCurrentProgress(0), - mMaxSize(-1), - mAddToRecent(PR_TRUE), - mStatus(NS_OK), - mEmbedPersist(nsnull), - mDownloadState(EPHY_DOWNLOAD_INITIALISING) -{ - LOG ("MozDownload ctor (%p)", (void *) this); -} - -MozDownload::~MozDownload() -{ - LOG ("MozDownload dtor (%p)", (void *) this); - - NS_ASSERTION (!mEphyDownload, "MozillaDownload still alive!"); -} - -NS_IMPL_ISUPPORTS4 (MozDownload, - nsIWebProgressListener, - nsIWebProgressListener2, - nsITransfer, - nsIInterfaceRequestor) - -nsresult -MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const nsAString &aDisplayName, - nsIMIMEInfo *aMIMEInfo, PRTime aStartTime, nsILocalFile *aTempFile, - nsICancelable *aCancelable, MozillaEmbedPersist *aEmbedPersist, - PRInt64 aMaxSize) -{ - mEmbedPersist = aEmbedPersist; - mMaxSize = aMaxSize; - return Init (aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, aTempFile, aCancelable); -} - -/* void init (in nsIURI aSource, in nsIURI aTarget, in AString aDisplayName, in nsIMIMEInfo aMIMEInfo, in PRTime startTime, in nsILocalFile aTempFile, in nsICancelable aCancelable); */ -NS_IMETHODIMP -MozDownload::Init (nsIURI *aSource, - nsIURI *aTarget, - const nsAString &aDisplayName, - nsIMIMEInfo *aMIMEInfo, - PRTime aStartTime, - nsILocalFile *aTempFile, - nsICancelable *aCancelable) -{ - PRBool addToView = PR_TRUE; - - if (mEmbedPersist) - { - EphyEmbedPersistFlags flags; - - flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); - - addToView = !(flags & EPHY_EMBED_PERSIST_NO_VIEW); - } - - mSource = aSource; - mDestination = aTarget; - mStartTime = aStartTime; - mTotalProgress = 0; - mCurrentProgress = 0; - mPercentComplete = 0; - mInterval = PROGRESS_RATE; - mLastUpdate = mStartTime; - mMIMEInfo = aMIMEInfo; - mAddToRecent = addToView; - - /* This will create a refcount cycle, which needs to be broken in ::OnStateChange */ - mCancelable = aCancelable; - - if (addToView) - { - DownloaderView *dview; - EphyDownload **cache_ptr; - dview = EPHY_DOWNLOADER_VIEW - (ephy_embed_shell_get_downloader_view (embed_shell)); - mEphyDownload = mozilla_download_new (this); - cache_ptr = &mEphyDownload; - g_object_add_weak_pointer (G_OBJECT (mEphyDownload), - (gpointer *) cache_ptr); - downloader_view_add_download (dview, mEphyDownload); - g_object_unref (mEphyDownload); - } - else - { - mEphyDownload = nsnull; - } - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetSource(nsIURI **aSource) -{ - NS_ENSURE_ARG_POINTER(aSource); - NS_IF_ADDREF(*aSource = mSource); - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetTargetFile (nsILocalFile** aTargetFile) -{ - nsresult rv; - - nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mDestination, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr<nsIFile> file; - rv = fileURL->GetFile(getter_AddRefs(file)); - if (NS_SUCCEEDED(rv)) - rv = CallQueryInterface(file, aTargetFile); - return rv; -} - -NS_IMETHODIMP -MozDownload::GetPercentComplete(PRInt32 *aPercentComplete) -{ - NS_ENSURE_ARG_POINTER(aPercentComplete); - *aPercentComplete = mPercentComplete; - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetTotalProgress(PRInt64 *aTotalProgress) -{ - NS_ENSURE_ARG_POINTER(aTotalProgress); - *aTotalProgress = mTotalProgress; - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetCurrentProgress(PRInt64 *aCurrentProgress) -{ - NS_ENSURE_ARG_POINTER(aCurrentProgress); - *aCurrentProgress = mCurrentProgress; - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetState(EphyDownloadState *aDownloadState) -{ - NS_ENSURE_ARG_POINTER(aDownloadState); - *aDownloadState = mDownloadState; - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetElapsedTime(PRInt64 *aElapsedTime) -{ - NS_ENSURE_ARG_POINTER(aElapsedTime); - *aElapsedTime = PR_Now() - mStartTime; - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::GetMIMEInfo(nsIMIMEInfo **aMIMEInfo) -{ - NS_ENSURE_ARG_POINTER(aMIMEInfo); - NS_IF_ADDREF(*aMIMEInfo = mMIMEInfo); - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, - PRUint32 aStateFlags, nsresult aStatus) -{ - nsresult rv; - - if (NS_FAILED(aStatus) && NS_SUCCEEDED(mStatus)) - mStatus = aStatus; - - if (aStateFlags & STATE_START) - { - mDownloadState = EPHY_DOWNLOAD_DOWNLOADING; - - if (mEphyDownload) - { - g_signal_emit_by_name (mEphyDownload, "changed"); - } - } - - /* We will get this even in the event of a cancel */ - /* Due to a mozilla bug [https://bugzilla.mozilla.org/show_bug.cgi?id=304353], - * we'll only get STATE_STOP if we're driven from external app handler; elsewhere - * we get STATE_STOP | STATE_IS_NETWORK | STATE_IS_REQUEST. So check first if - * STATE_IS_REQUEST is set. - */ - /* Be careful that download is only completed when STATE_IS_NETWORK is set - * and many lonely STOP events may be triggered before. - */ -#ifdef GNOME_ENABLE_DEBUG -{ - nsCString spec; - if (mSource) mSource->GetSpec(spec); - - LOG ("url %s, status %x, state %x (is-stop:%s, is-network:%s, is-request:%s)", - spec.get(), aStatus, aStateFlags, - aStateFlags & STATE_STOP ? "t" : "f", - aStateFlags & STATE_IS_NETWORK ? "t" : "f", - aStateFlags & STATE_IS_REQUEST ? "t" : "f"); -} -#endif - - if (((aStateFlags & STATE_IS_REQUEST) && - (aStateFlags & STATE_IS_NETWORK) && - (aStateFlags & STATE_STOP)) || - aStateFlags == STATE_STOP) - { - LOG ("STATE_STOP"); - - /* Keep us alive */ - nsCOMPtr<nsITransfer> kungFuDeathGrip(this); - - mDownloadState = NS_SUCCEEDED (aStatus) ? EPHY_DOWNLOAD_COMPLETED : EPHY_DOWNLOAD_FAILED; - if (mEphyDownload) - { - g_signal_emit_by_name (mEphyDownload, "changed"); - } - - /* break refcount cycle */ - mCancelable = nsnull; - - nsCString destSpec; - nsCString mimeType; - - mDestination->GetSpec (destSpec); - - if (NS_SUCCEEDED (aStatus) && mMIMEInfo) - { - rv = mMIMEInfo->GetMIMEType (mimeType); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - } - - if (mAddToRecent) - { - ephy_file_add_recent_item (destSpec.get(), mimeType.get()); - } - - if (mEmbedPersist) - { - if (NS_SUCCEEDED (aStatus)) - { - mozilla_embed_persist_completed (mEmbedPersist); - } - else - { - mozilla_embed_persist_cancelled (mEmbedPersist); - } - } - else if (NS_SUCCEEDED (aStatus)) - { - NS_ENSURE_TRUE (mMIMEInfo, NS_ERROR_FAILURE); -#ifdef HAVE_GECKO_1_9 - nsHandlerInfoAction action; - mMIMEInfo->GetPreferredAction(&action); - - if (action == EPHY_ACTION_BROWSE_TO_FILE) { - nsCString destSpec; - rv = mDestination->GetSpec (destSpec); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - GFile *dest; - dest = g_file_new_for_uri (destSpec.get ()); - ephy_file_browse_to (dest, 0 /* FIXME BUG BUG BUG */); - g_object_unref (dest); - } - /* All other values are handled by gecko itself */ - - return NS_OK; -#else - GDesktopAppInfo *helperApp; - - nsString description; - mMIMEInfo->GetApplicationDescription (description); - - nsCString cDesc; - NS_UTF16ToCString (description, NS_CSTRING_ENCODING_UTF8, cDesc); - - /* HACK we use the application description to decide - if we have to open the saved file */ - if (g_str_has_prefix (cDesc.get(), "gnome-default:")) - { - /* Format gnome-default:<usertime>:<helperapp id> */ - char **str = g_strsplit (cDesc.get(), ":", -1); - g_return_val_if_fail (g_strv_length (str) == 3, NS_ERROR_FAILURE); - - char *end; - guint32 user_time = strtoul (str[1], &end, 0); - - helperApp = g_desktop_app_info_new (str[2]); - if (!helperApp) return NS_ERROR_FAILURE; - - nsCString aDest; - rv = mDestination->GetSpec (aDest); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - GFile* file; - GList* list = NULL; - - file = g_file_new_for_uri (destSpec.get ()); - list = g_list_append (list, file); - ephy_file_launch_application (G_APP_INFO (helperApp), list, user_time, NULL); - - g_list_free (list); - g_object_unref (file); - g_strfreev (str); - } - else if (g_str_has_prefix (cDesc.get(), "gnome-browse-to-file:")) - { - /* Format gnome-browse-to-file:<usertime> */ - char **str = g_strsplit (cDesc.get(), ":", -1); - g_return_val_if_fail (g_strv_length (str) == 2, NS_ERROR_FAILURE); - - char *end; - guint32 user_time = strtoul (str[1], &end, 0); - - nsCString aDest; - rv = mDestination->GetSpec (aDest); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - - GFile *dest; - dest = g_file_new_for_uri (aDest.get ()); - ephy_file_browse_to (dest, user_time); - - g_object_unref (dest); - g_strfreev (str); - } -#endif /* HAVE_GECKO_1_9 */ - } - } - - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::OnProgressChange (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt32 aCurSelfProgress, - PRInt32 aMaxSelfProgress, - PRInt32 aCurTotalProgress, - PRInt32 aMaxTotalProgress) -{ - return OnProgressChange64 (aWebProgress, aRequest, - aCurSelfProgress, aMaxSelfProgress, - aCurTotalProgress, aMaxTotalProgress); -} - -/* void onProgressChange64 (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long long aCurSelfProgress, in long long aMaxSelfProgress, in long long aCurTotalProgress, - in long long aMaxTotalProgress); */ -NS_IMETHODIMP -MozDownload::OnProgressChange64 (nsIWebProgress *aWebProgress, - nsIRequest *aRequest, - PRInt64 aCurSelfProgress, - PRInt64 aMaxSelfProgress, - PRInt64 aCurTotalProgress, - PRInt64 aMaxTotalProgress) -{ - if (mMaxSize >= 0 && - ((aMaxTotalProgress > 0 && mMaxSize < aMaxTotalProgress) || - mMaxSize < aCurTotalProgress)) - { - Cancel (); - } - - if (!mRequest) - mRequest = aRequest; - - PRInt64 now = PR_Now (); - - if ((now - mLastUpdate < mInterval) && - (aMaxTotalProgress == -1 || aCurTotalProgress < aMaxTotalProgress)) - return NS_OK; - - mLastUpdate = now; - - if (aMaxTotalProgress <= 0) - { - mPercentComplete = -1; - } - else - { - /* Make sure not to round up, so we don't display 100% unless - * it's really finished! - */ - mPercentComplete = (PRInt32)(((float)aCurTotalProgress / (float)aMaxTotalProgress) * 100.0); - } - - mTotalProgress = aMaxTotalProgress; - mCurrentProgress = aCurTotalProgress; - - if (mEphyDownload) - { - g_signal_emit_by_name (mEphyDownload, "changed"); - } - - return NS_OK; -} - -#ifdef HAVE_GECKO_1_9 -/* boolean onRefreshAttempted (in nsIWebProgress aWebProgress, in nsIURI aRefreshURI, in long aDelay, in boolean aSameURI); */ -NS_IMETHODIMP -MozDownload::OnRefreshAttempted(nsIWebProgress *aWebProgress, - nsIURI *aUri, - PRInt32 aDelay, - PRBool aSameUri, - PRBool *allowRefresh) -{ - *allowRefresh = PR_TRUE; - return NS_OK; -} -#endif - -NS_IMETHODIMP -MozDownload::OnLocationChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location) -{ - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::OnStatusChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, - nsresult aStatus, const PRUnichar *aMessage) -{ - return NS_OK; -} - -NS_IMETHODIMP -MozDownload::OnSecurityChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state) -{ - return NS_OK; -} - -/* void getInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */ -NS_IMETHODIMP -MozDownload::GetInterface(const nsIID & uuid, void * *result) -{ -#ifndef HAVE_GECKO_1_9 - if (uuid.Equals (NS_GET_IID (nsIBadCertListener)) && - mEmbedPersist) - { - EphyEmbedPersistFlags flags; - - g_object_get (mEmbedPersist, "flags", &flags, (char *) NULL); - - if (flags & EPHY_EMBED_PERSIST_NO_CERTDIALOGS) - { - nsIBadCertListener *badCertRejector = new EphyBadCertRejector (); - if (!badCertRejector) return NS_ERROR_OUT_OF_MEMORY; - - *result = badCertRejector; - NS_ADDREF (badCertRejector); - - return NS_OK; - } - } -#endif - return NS_ERROR_NO_INTERFACE; -} - -void -MozDownload::Cancel() -{ - if (mDownloadState != EPHY_DOWNLOAD_DOWNLOADING && - mDownloadState != EPHY_DOWNLOAD_PAUSED) - { - return; - } - - if (mCancelable) - { - /* FIXME: error code? */ - mCancelable->Cancel (NS_BINDING_ABORTED); - } -} - -void -MozDownload::Pause() -{ - if (mRequest) - { - mRequest->Suspend (); - mDownloadState = EPHY_DOWNLOAD_PAUSED; - } -} - -void -MozDownload::Resume() -{ - if (mRequest) - { - mRequest->Resume (); - mDownloadState = EPHY_DOWNLOAD_DOWNLOADING; - } -} - -nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI, - nsILocalFile* inDestFile, const char *contentType, - nsIURI* inOriginalURI, MozillaEmbedPersist *embedPersist, - nsIInputStream *postData, nsISupports *aCacheKey, - PRInt64 aMaxSize) -{ - nsresult rv = NS_OK; - - EphyEmbedPersistFlags ephy_flags; - ephy_flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (embedPersist)); - - if (!ephy_embed_persist_get_dest (EPHY_EMBED_PERSIST (embedPersist))) - { - nsCString cPath; - inDestFile->GetNativePath (cPath); - - ephy_embed_persist_set_dest (EPHY_EMBED_PERSIST (embedPersist), - cPath.get()); - } - - nsCOMPtr<nsIMIMEService> mimeService (do_GetService ("@mozilla.org/mime;1")); - nsCOMPtr<nsIMIMEInfo> mimeInfo; - if (mimeService) - { - mimeService->GetFromTypeAndExtension (nsCString(contentType), - nsCString(), - getter_AddRefs (mimeInfo)); - } - - PRBool isHTML = (contentType && - (strcmp (contentType, "text/html") == 0 || - strcmp (contentType, "text/xml") == 0 || - strcmp (contentType, "application/xhtml+xml") == 0)); - - nsCOMPtr<nsIWebBrowserPersist> webPersist (do_CreateInstance(persistContractID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - PRInt64 timeNow = PR_Now(); - - nsString fileDisplayName; - inDestFile->GetLeafName(fileDisplayName); - - nsCOMPtr<nsIIOService> ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIURI> destURI; - ioService->NewFileURI (inDestFile, getter_AddRefs(destURI)); - - MozDownload *downloader = new MozDownload (); - /* dlListener attaches to its progress dialog here, which gains ownership */ - /* FIXME is that still true? */ - rv = downloader->InitForEmbed (inOriginalURI, destURI, fileDisplayName, - mimeInfo, timeNow, nsnull, webPersist, embedPersist, aMaxSize); - NS_ENSURE_SUCCESS (rv, rv); - - rv = webPersist->SetProgressListener (downloader); - NS_ENSURE_SUCCESS (rv, rv); - - PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES; - - if (!domDocument && !isHTML && !(ephy_flags & EPHY_EMBED_PERSIST_COPY_PAGE) && - !(ephy_flags & EPHY_EMBED_PERSIST_DO_CONVERSION)) - { - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION; - } - if (ephy_flags & EPHY_EMBED_PERSIST_COPY_PAGE) - { - flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE; - } - webPersist->SetPersistFlags(flags); - - /* Create a new tagged channel if we need to block cookies from server */ - if (ephy_flags & EPHY_EMBED_PERSIST_NO_COOKIES) - { - nsCOMPtr<nsIChannel> tmpChannel; - rv = ioService->NewChannelFromURI (sourceURI, getter_AddRefs (tmpChannel)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr<nsIWritablePropertyBag2> props = do_QueryInterface(tmpChannel); - rv = props->SetPropertyAsBool (NS_LITERAL_STRING("epiphany-blocking-cookies"), PR_TRUE); - NS_ENSURE_SUCCESS (rv, rv); - - rv = webPersist->SaveChannel (tmpChannel, inDestFile); - } - else if (!domDocument || !isHTML || ephy_flags & EPHY_EMBED_PERSIST_COPY_PAGE) - { - rv = webPersist->SaveURI (sourceURI, aCacheKey, nsnull, - postData, nsnull, inDestFile); - } - else - { - PRInt32 encodingFlags = 0; - nsCOMPtr<nsILocalFile> filesFolder; - - /** - * Construct a directory path to hold the associated files; mozilla - * will create the directory as needed. - */ - - nsCString cPath; - inDestFile->GetNativePath (cPath); - - char *basename = g_path_get_basename (cPath.get()); - char *dirname = g_path_get_dirname (cPath.get()); - char *dot_pos = strchr (basename, '.'); - if (dot_pos) - { - *dot_pos = 0; - } - /* translators: this is the directory name to store auxilary files when saving html files */ - char *new_basename = g_strdup_printf (_("%s Files"), basename); - char *new_path = g_build_filename (dirname, new_basename, NULL); - g_free (new_basename); - g_free (basename); - g_free (dirname); - - filesFolder = do_CreateInstance ("@mozilla.org/file/local;1"); - filesFolder->InitWithNativePath (nsCString(new_path)); - - g_free (new_path); - - rv = webPersist->SaveDocument (domDocument, inDestFile, filesFolder, - contentType, encodingFlags, 80); - } - - return rv; -} - -static char* -GetFilePath (const char *filename) -{ - const char *home_dir; - char *download_dir, *path; - - download_dir = ephy_file_get_downloads_dir (); - - if (ephy_ensure_dir_exists (download_dir, NULL)) - { - path = g_build_filename (download_dir, filename, (char *) NULL); - } - else - { - home_dir = g_get_home_dir (); - path = g_build_filename (home_dir ? home_dir : "/", filename, (char *) NULL); - } - g_free (download_dir); - - return path; -} - -static const char* -file_is_compressed (const char *filename) -{ - int i; - static const char * const compression[] = {".gz", ".bz2", ".Z", ".lz", NULL}; - - for (i = 0; compression[i] != NULL; i++) - { - if (g_str_has_suffix (filename, compression[i])) - return compression[i]; - } - - return NULL; -} - -static const char* -parse_extension (const char *filename) -{ - const char *compression; - - compression = file_is_compressed (filename); - - /* If the file is compressed we might have a double extension */ - if (compression != NULL) - { - int i; - static const char * const extensions[] = {"tar", "ps", "xcf", "dvi", "txt", "text", NULL}; - - for (i = 0; extensions[i] != NULL; i++) - { - char *suffix; - suffix = g_strdup_printf (".%s%s", extensions[i], - compression); - - if (g_str_has_suffix (filename, suffix)) - { - char *p; - - p = g_strrstr (filename, suffix); - g_free (suffix); - - return p; - } - - g_free (suffix); - } - } - - /* default case */ - return g_strrstr (filename, "."); -} - -nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval) -{ - char *path; - - path = GetFilePath (defaultFileName); - - if (g_file_test (path, G_FILE_TEST_EXISTS)) - { - int i = 1; - const char *dot_pos; - char *serial = NULL; - GString *tmp_path; - gssize position; - - dot_pos = parse_extension (defaultFileName); - if (dot_pos) - { - position = dot_pos - defaultFileName; - } - else - { - position = strlen (defaultFileName); - } - tmp_path = g_string_new (NULL); - - do { - g_free (path); - g_string_assign (tmp_path, defaultFileName); - serial = g_strdup_printf ("(%d)", i++); - g_string_insert (tmp_path, position, serial); - g_free (serial); - path = GetFilePath (tmp_path->str); - - } while (g_file_test (path, G_FILE_TEST_EXISTS)); - - g_string_free (tmp_path, TRUE); - } - - nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - NS_ENSURE_TRUE (destFile, NS_ERROR_FAILURE); - - destFile->InitWithNativePath (nsCString (path)); - g_free (path); - - NS_IF_ADDREF (*_retval = destFile); - return NS_OK; -} diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h deleted file mode 100644 index fe3219033..000000000 --- a/embed/mozilla/MozDownload.h +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright © 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Conrad Carlen <ccarlen@netscape.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** - * - * $Id$ - */ - -#ifndef MozDownload_h__ -#define MozDownload_h__ - -#include <nsCOMPtr.h> -#include <nsIInterfaceRequestor.h> -#include <nsITransfer.h> -#include <nsIWebProgressListener.h> - -#include "mozilla-embed-persist.h" -#include "downloader-view.h" -#include "ephy-download.h" -#include "ephy-embed-shell.h" - -class nsICancelable; -class nsIDOMDocument; -class nsIInputStream; -class nsILocalFile; -class nsIMIMEInfo; -class nsIObserver; -class nsIRequest; -class nsIURI; -class nsIWebBrowserPersist; - -/* MozDownload - Holds information used to display a single download in the UI. This object is - created in one of two ways: - (1) By nsExternalHelperAppHandler when Gecko encounters a MIME type which - it doesn't itself handle. In this case, the notifications sent to - nsIDownload are controlled by nsExternalHelperAppHandler. - (2) By the embedding app's file saving code when saving a web page or a link - target. See CHeaderSniffer.cpp. In this case, the notifications sent to - nsIDownload are controlled by the implementation of nsIWebBrowserPersist. -*/ - -#define MOZ_DOWNLOAD_CID \ -{ /* d2a2f743-f126-4f1f-1234-d4e50490f112 */ \ - 0xd2a2f743, \ - 0xf126, \ - 0x4f1f, \ - {0x12, 0x34, 0xd4, 0xe5, 0x04, 0x90, 0xf1, 0x12} \ -} - -#define MOZ_DOWNLOAD_CLASSNAME "Ephy's Download Progress Dialog" - -#define EPHY_ACTION_BROWSE_TO_FILE (1024) - -nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceUri, - nsILocalFile* inDestFile, const char *contentType, - nsIURI* inOriginalURI, MozillaEmbedPersist *embedPersist, - nsIInputStream *postData, nsISupports *aCacheKey, - PRInt64 aMaxSize); -nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval); - -class MozDownload : public nsITransfer, - public nsIInterfaceRequestor -{ -public: - MozDownload(); - virtual ~MozDownload(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSIWEBPROGRESSLISTENER2 - NS_DECL_NSITRANSFER - NS_DECL_NSIINTERFACEREQUESTOR - - nsresult GetMIMEInfo (nsIMIMEInfo **aMIMEInfo); - nsresult GetTargetFile (nsILocalFile **aFile); - nsresult GetSource(nsIURI * *aSource); - nsresult GetPercentComplete(PRInt32 *aPercentComplete); - - virtual void Cancel(); - virtual void Pause(); - virtual void Resume(); - - nsresult GetState (EphyDownloadState *aDownloadState); - nsresult GetCurrentProgress (PRInt64 *aCurrentProgress); - nsresult GetTotalProgress (PRInt64 *aTProgress); - nsresult GetElapsedTime (PRInt64 *aTProgress); - - nsresult InitForEmbed (nsIURI *aSource, nsIURI *aTarget, - const nsAString &aDisplayName, nsIMIMEInfo *aMIMEInfo, - PRTime aStartTime, nsILocalFile *aTempFile, - nsICancelable *aCancelable, MozillaEmbedPersist *aEmbedPersist, - PRInt64 aMaxSize); - -protected: - nsCOMPtr<nsIURI> mSource; - nsCOMPtr<nsIURI> mDestination; - - nsCOMPtr<nsIMIMEInfo> mMIMEInfo; - PRTime mStartTime; - PRTime mLastUpdate; - PRInt64 mElapsed; - PRInt32 mInterval; - PRInt32 mPercentComplete; - PRInt64 mTotalProgress; - PRInt64 mCurrentProgress; - PRInt64 mMaxSize; - PRBool mAddToRecent; - - nsresult mStatus; - - nsCOMPtr<nsICancelable> mCancelable; - nsCOMPtr<nsIRequest> mRequest; - EphyDownload *mEphyDownload; - DownloaderView *mDownloaderView; - MozillaEmbedPersist *mEmbedPersist; - EphyDownloadState mDownloadState; -}; - -#endif // MozDownload_h__ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp deleted file mode 100644 index 3960052bf..000000000 --- a/embed/mozilla/MozRegisterComponents.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright © 2001,2002,2003 Philip Langdale - * Copyright © 2003 Marco Pesenti Gritti - * Copyright © 2004, 2005, 2006 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/gmessages.h> - -#include <nsStringAPI.h> - -#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> -#include <nsServiceManagerUtils.h> - -#ifdef HAVE_GECKO_1_9 -#include <nsIClassInfoImpl.h> -#endif - -#ifdef HAVE_MOZILLA_PSM -#include <nsISecureBrowserUI.h> -#endif - -#include "ContentHandler.h" -#include "EphyAboutModule.h" -#include "EphyContentPolicy.h" -#include "EphyPromptService.h" -#include "EphySidebar.h" -#include "GeckoCookiePromptService.h" -#include "GeckoPrintService.h" -#include "GeckoPrintSession.h" -#include "GlobalHistory.h" -#include "MozDownload.h" - -#ifdef ENABLE_FILEPICKER -#include "FilePicker.h" -#endif - -#ifdef ENABLE_SPELLCHECKER -#include "GeckoSpellCheckEngine.h" -#endif - -#ifdef HAVE_MOZILLA_PSM -#include "GtkNSSClientAuthDialogs.h" -#include "GtkNSSDialogs.h" -#include "GtkNSSKeyPairDialogs.h" -#include "GtkNSSSecurityWarningDialogs.h" -#include "GeckoFormSigningDialog.h" -#endif - -NS_GENERIC_FACTORY_CONSTRUCTOR(EphyAboutModule) -NS_GENERIC_FACTORY_CONSTRUCTOR(EphyContentPolicy) -NS_GENERIC_FACTORY_CONSTRUCTOR(EphyPromptService) -NS_GENERIC_FACTORY_CONSTRUCTOR(EphySidebar) -NS_GENERIC_FACTORY_CONSTRUCTOR(GContentHandler) -NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoCookiePromptService) -NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintService) -NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoPrintSession) -NS_GENERIC_FACTORY_CONSTRUCTOR(MozDownload) -NS_GENERIC_FACTORY_CONSTRUCTOR(MozGlobalHistory) - -#ifdef ENABLE_FILEPICKER -NS_GENERIC_FACTORY_CONSTRUCTOR(GFilePicker) -#endif - -#ifdef ENABLE_SPELLCHECKER -NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoSpellCheckEngine) -#endif - -#ifdef HAVE_MOZILLA_PSM -NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSClientAuthDialogs) -NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSDialogs) -NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSKeyPairDialogs) -NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSSecurityWarningDialogs) -NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoFormSigningDialog) -#endif - -#define XPINSTALL_CONTRACTID NS_CONTENT_HANDLER_CONTRACTID_PREFIX "application/x-xpinstall" - -/* class information */ -NS_DECL_CLASSINFO(EphySidebar) - -/* FIXME: uninstall XPI handler */ - -static const nsModuleComponentInfo sAppComps[] = { - { - MOZ_DOWNLOAD_CLASSNAME, - MOZ_DOWNLOAD_CID, -#ifdef NS_TRANSFER_CONTRACTID - NS_TRANSFER_CONTRACTID, -#else - NS_DOWNLOAD_CONTRACTID, -#endif - MozDownloadConstructor - }, -#ifdef ENABLE_FILEPICKER - { - G_FILEPICKER_CLASSNAME, - G_FILEPICKER_CID, - G_FILEPICKER_CONTRACTID, - GFilePickerConstructor - }, -#endif -#ifdef HAVE_MOZILLA_PSM - { - GTK_NSSCLIENTAUTHDIALOGS_CLASSNAME, - GTK_NSSCLIENTAUTHDIALOGS_CID, - NS_CLIENTAUTHDIALOGS_CONTRACTID, - GtkNSSClientAuthDialogsConstructor - }, -#ifndef HAVE_GECKO_1_9 - { - GTK_NSSDIALOGS_CLASSNAME, - GTK_NSSDIALOGS_CID, - NS_BADCERTLISTENER_CONTRACTID, - GtkNSSDialogsConstructor - }, -#endif - { - GTK_NSSDIALOGS_CLASSNAME, - GTK_NSSDIALOGS_CID, - NS_CERTIFICATEDIALOGS_CONTRACTID, - GtkNSSDialogsConstructor - }, - { - GTK_NSSDIALOGS_CLASSNAME, - GTK_NSSDIALOGS_CID, - NS_DOMCRYPTODIALOGS_CONTRACTID, - GtkNSSDialogsConstructor - }, - { - GTK_NSSDIALOGS_CLASSNAME, - GTK_NSSDIALOGS_CID, - NS_TOKENDIALOGS_CONTRACTID, - GtkNSSDialogsConstructor - }, - { - GTK_NSSDIALOGS_CLASSNAME, - GTK_NSSDIALOGS_CID, - NS_TOKENPASSWORDSDIALOG_CONTRACTID, - GtkNSSDialogsConstructor - }, - { - GTK_NSSKEYPAIRDIALOGS_CLASSNAME, - GTK_NSSKEYPAIRDIALOGS_CID, - NS_GENERATINGKEYPAIRINFODIALOGS_CONTRACTID, - GtkNSSKeyPairDialogsConstructor - }, - { - GTK_NSSSECURITYWARNINGDIALOGS_CLASSNAME, - GTK_NSSSECURITYWARNINGDIALOGS_CID, - NS_SECURITYWARNINGDIALOGS_CONTRACTID, - GtkNSSSecurityWarningDialogsConstructor - }, - { - GECKO_FORMSIGNINGDIALOGS_CLASSNAME, - GECKO_FORMSIGNINGDIALOGS_CID, - NS_FORMSIGNINGDIALOG_CONTRACTID, - GeckoFormSigningDialogConstructor - }, -#endif /* HAVE_MOZILLA_PSM */ - { - NS_IHELPERAPPLAUNCHERDLG_CLASSNAME, - G_CONTENTHANDLER_CID, - NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, - GContentHandlerConstructor - }, - { - EPHY_GLOBALHISTORY_CLASSNAME, - EPHY_GLOBALHISTORY_CID, - NS_GLOBALHISTORY2_CONTRACTID, - MozGlobalHistoryConstructor - }, - { - 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, - EphyContentPolicy::Register, - EphyContentPolicy::Unregister - }, - { - EPHY_SIDEBAR_CLASSNAME, - EPHY_SIDEBAR_CID, - NS_SIDEBAR_CONTRACTID, - EphySidebarConstructor, - EphySidebar::Register, - EphySidebar::Unregister, - nsnull /* no factory destructor */, - NS_CI_INTERFACE_GETTER_NAME(EphySidebar), - nsnull /* no language helper */, - &NS_CLASSINFO_NAME(EphySidebar), - nsIClassInfo::DOM_OBJECT - }, - { - EPHY_ABOUT_EPIPHANY_CLASSNAME, - EPHY_ABOUT_MODULE_CID, - EPHY_ABOUT_EPIPHANY_CONTRACTID, - EphyAboutModuleConstructor - }, - { - EPHY_ABOUT_RECOVER_CLASSNAME, - EPHY_ABOUT_MODULE_CID, - EPHY_ABOUT_RECOVER_CONTRACTID, - EphyAboutModuleConstructor - }, - { - EPHY_ABOUT_NETERROR_CLASSNAME, - EPHY_ABOUT_MODULE_CID, - EPHY_ABOUT_NETERROR_CONTRACTID, - EphyAboutModuleConstructor - }, - { - EPHY_PROMPT_SERVICE_CLASSNAME, - EPHY_PROMPT_SERVICE_IID, - "@mozilla.org/embedcomp/prompt-service;1", - EphyPromptServiceConstructor - }, -#ifdef HAVE_NSINONBLOCKINGALERTSERVICE_H - { - EPHY_PROMPT_SERVICE_CLASSNAME, - EPHY_PROMPT_SERVICE_IID, - "@mozilla.org/embedcomp/nbalert-service;1", - EphyPromptServiceConstructor - }, -#endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */ -#ifdef ENABLE_SPELLCHECKER - { - GECKO_SPELL_CHECK_ENGINE_CLASSNAME, - GECKO_SPELL_CHECK_ENGINE_IID, - GECKO_SPELL_CHECK_ENGINE_CONTRACTID, - GeckoSpellCheckEngineConstructor - }, -#endif /* ENABLE_SPELLCHECK */ - { - EPHY_COOKIEPROMPTSERVICE_CLASSNAME, - EPHY_COOKIEPROMPTSERVICE_CID, - EPHY_COOKIEPROMPTSERVICE_CONTRACTID, - GeckoCookiePromptServiceConstructor - } -}; - -gboolean -mozilla_register_components (void) -{ - gboolean ret = TRUE; - nsresult rv; - - nsCOMPtr<nsIComponentRegistrar> cr; - NS_GetComponentRegistrar(getter_AddRefs(cr)); - NS_ENSURE_TRUE (cr, FALSE); - - nsCOMPtr<nsIComponentManager> cm; - NS_GetComponentManager (getter_AddRefs (cm)); - NS_ENSURE_TRUE (cm, FALSE); - - for (guint i = 0; i < G_N_ELEMENTS (sAppComps); i++) - { - nsCOMPtr<nsIGenericFactory> componentFactory; - componentFactory = do_CreateInstance(NS_GENERICFACTORY_CONTRACTID); - if(!componentFactory) - { - g_warning ("Failed to create a generic factory for %s\n", sAppComps[i].mDescription); - ret = FALSE; - continue; - } - rv = componentFactory->SetComponentInfo(&(sAppComps[i])); - if (NS_FAILED(rv)) - { - g_warning ("Failed to make a factory for %s\n", sAppComps[i].mDescription); - - ret = FALSE; - continue; // don't abort registering other components - } - - rv = cr->RegisterFactory(sAppComps[i].mCID, - sAppComps[i].mDescription, - sAppComps[i].mContractID, - componentFactory); - if (NS_FAILED(rv)) - { - g_warning ("Failed to register %s\n", sAppComps[i].mDescription); - - ret = FALSE; - } - - if (sAppComps[i].mRegisterSelfProc) - { - rv = sAppComps[i].mRegisterSelfProc (cm, nsnull, nsnull, nsnull, &sAppComps[i]); - - if (NS_FAILED (rv)) - { - g_warning ("Failed to register-self for %s\n", sAppComps[i].mDescription); - ret = FALSE; - } - } - } - - return ret; -} diff --git a/embed/mozilla/MozRegisterComponents.h b/embed/mozilla/MozRegisterComponents.h deleted file mode 100644 index e8e086f3b..000000000 --- a/embed/mozilla/MozRegisterComponents.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2001 Philip Langdale - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZREGISTERCOMPONENTS_H -#define MOZREGISTERCOMPONENTS_H - -#include <glib.h> - -gboolean mozilla_register_components (void); - -#endif /* MOZREGISTERCOMPONENTS_H */ diff --git a/embed/mozilla/ephyIAddCertExceptionParams.h b/embed/mozilla/ephyIAddCertExceptionParams.h deleted file mode 100644 index 01f6b953b..000000000 --- a/embed/mozilla/ephyIAddCertExceptionParams.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * DO NOT EDIT. THIS FILE IS GENERATED FROM ephyIAddCertExceptionParams.idl - */ - -#ifndef __gen_ephyIAddCertExceptionParams_h__ -#define __gen_ephyIAddCertExceptionParams_h__ - - -#ifndef __gen_nsISupports_h__ -#include "nsISupports.h" -#endif - -/* For IDL files that don't want to include root IDL files. */ -#ifndef NS_NO_VTABLE -#define NS_NO_VTABLE -#endif - -/* starting interface: ephyIAddCertExceptionParams */ -#define EPHYIADDCERTEXCEPTIONPARAMS_IID_STR "2bac2eb2-cd10-4e3f-802e-dade8096d6c5" - -#define EPHYIADDCERTEXCEPTIONPARAMS_IID \ - {0x2bac2eb2, 0xcd10, 0x4e3f, \ - { 0x80, 0x2e, 0xda, 0xde, 0x80, 0x96, 0xd6, 0xc5 }} - -class NS_NO_VTABLE ephyIAddCertExceptionParams : public nsISupports { - public: - - NS_DECLARE_STATIC_IID_ACCESSOR(EPHYIADDCERTEXCEPTIONPARAMS_IID) - - /* readonly attribute boolean prefetchCert; */ - NS_IMETHOD GetPrefetchCert(PRBool *aPrefetchCert) = 0; - - /* readonly attribute AString location; */ - NS_IMETHOD GetLocation(nsAString & aLocation) = 0; - - /* attribute boolean exceptionAdded; */ - NS_IMETHOD GetExceptionAdded(PRBool *aExceptionAdded) = 0; - NS_IMETHOD SetExceptionAdded(PRBool aExceptionAdded) = 0; - -}; - - NS_DEFINE_STATIC_IID_ACCESSOR(ephyIAddCertExceptionParams, EPHYIADDCERTEXCEPTIONPARAMS_IID) - -/* Use this macro when declaring classes that implement this interface. */ -#define NS_DECL_EPHYIADDCERTEXCEPTIONPARAMS \ - NS_IMETHOD GetPrefetchCert(PRBool *aPrefetchCert); \ - NS_IMETHOD GetLocation(nsAString & aLocation); \ - NS_IMETHOD GetExceptionAdded(PRBool *aExceptionAdded); \ - NS_IMETHOD SetExceptionAdded(PRBool aExceptionAdded); - -/* Use this macro to declare functions that forward the behavior of this interface to another object. */ -#define NS_FORWARD_EPHYIADDCERTEXCEPTIONPARAMS(_to) \ - NS_IMETHOD GetPrefetchCert(PRBool *aPrefetchCert) { return _to GetPrefetchCert(aPrefetchCert); } \ - NS_IMETHOD GetLocation(nsAString & aLocation) { return _to GetLocation(aLocation); } \ - NS_IMETHOD GetExceptionAdded(PRBool *aExceptionAdded) { return _to GetExceptionAdded(aExceptionAdded); } \ - NS_IMETHOD SetExceptionAdded(PRBool aExceptionAdded) { return _to SetExceptionAdded(aExceptionAdded); } - -/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */ -#define NS_FORWARD_SAFE_EPHYIADDCERTEXCEPTIONPARAMS(_to) \ - NS_IMETHOD GetPrefetchCert(PRBool *aPrefetchCert) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetPrefetchCert(aPrefetchCert); } \ - NS_IMETHOD GetLocation(nsAString & aLocation) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetLocation(aLocation); } \ - NS_IMETHOD GetExceptionAdded(PRBool *aExceptionAdded) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetExceptionAdded(aExceptionAdded); } \ - NS_IMETHOD SetExceptionAdded(PRBool aExceptionAdded) { return !_to ? NS_ERROR_NULL_POINTER : _to->SetExceptionAdded(aExceptionAdded); } - -#if 0 -/* Use the code below as a template for the implementation class for this interface. */ - -/* Header file */ -class _MYCLASS_ : public ephyIAddCertExceptionParams -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_EPHYIADDCERTEXCEPTIONPARAMS - - _MYCLASS_(); - -private: - ~_MYCLASS_(); - -protected: - /* additional members */ -}; - -/* Implementation file */ -NS_IMPL_ISUPPORTS1(_MYCLASS_, ephyIAddCertExceptionParams) - -_MYCLASS_::_MYCLASS_() -{ - /* member initializers and constructor code */ -} - -_MYCLASS_::~_MYCLASS_() -{ - /* destructor code */ -} - -/* readonly attribute boolean prefetchCert; */ -NS_IMETHODIMP _MYCLASS_::GetPrefetchCert(PRBool *aPrefetchCert) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* readonly attribute AString location; */ -NS_IMETHODIMP _MYCLASS_::GetLocation(nsAString & aLocation) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* attribute boolean exceptionAdded; */ -NS_IMETHODIMP _MYCLASS_::GetExceptionAdded(PRBool *aExceptionAdded) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP _MYCLASS_::SetExceptionAdded(PRBool aExceptionAdded) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* End of implementation class template. */ -#endif - - -#endif /* __gen_ephyIAddCertExceptionParams_h__ */ diff --git a/embed/mozilla/ephyIAddCertExceptionParams.idl b/embed/mozilla/ephyIAddCertExceptionParams.idl deleted file mode 100644 index 60ee11423..000000000 --- a/embed/mozilla/ephyIAddCertExceptionParams.idl +++ /dev/null @@ -1,8 +0,0 @@ -#include "nsISupports.idl" - -[scriptable,uuid(2bac2eb2-cd10-4e3f-802e-dade8096d6c5)] -interface ephyIAddCertExceptionParams : nsISupports { - readonly attribute boolean prefetchCert; - readonly attribute AString location; - attribute boolean exceptionAdded; -}; diff --git a/embed/mozilla/epiphany.xpt b/embed/mozilla/epiphany.xpt Binary files differdeleted file mode 100644 index ee2a81154..000000000 --- a/embed/mozilla/epiphany.xpt +++ /dev/null diff --git a/embed/mozilla/mozilla-download.cpp b/embed/mozilla/mozilla-download.cpp deleted file mode 100644 index 3d261ec2f..000000000 --- a/embed/mozilla/mozilla-download.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright © 2003 Xan Lopez - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <nsILocalFile.h> -#include <nsIMIMEInfo.h> -#include <nsIURI.h> -#include <nsMemory.h> - -#include "ephy-debug.h" - -#include "MozDownload.h" - -#include "mozilla-download.h" - -static void mozilla_download_class_init (MozillaDownloadClass *klass); -static void mozilla_download_init (MozillaDownload *ges); -static void mozilla_download_finalize (GObject *object); - -enum -{ - PROP_0, - PROP_MOZDOWNLOAD -}; - -struct _MozillaDownloadPrivate -{ - MozDownload *moz_download; -}; - -#define MOZILLA_DOWNLOAD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadPrivate)) - -G_DEFINE_TYPE (MozillaDownload, mozilla_download, EPHY_TYPE_DOWNLOAD) - -static char * -impl_get_target (EphyDownload *download) -{ - nsCOMPtr<nsILocalFile> targetFile; - MozDownload *mozDownload; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetTargetFile (getter_AddRefs (targetFile)); - - nsCString tempPathStr; - targetFile->GetNativePath (tempPathStr); - - return g_strdup (tempPathStr.get ()); -} - -static char * -impl_get_source (EphyDownload *download) -{ - nsCOMPtr<nsIURI> uri; - MozDownload *mozDownload; - nsCString spec; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetSource (getter_AddRefs (uri)); - uri->GetSpec (spec); - - return g_strdup (spec.get()); -} - -static gint64 -impl_get_current_progress (EphyDownload *download) -{ - MozDownload *mozDownload; - PRInt64 progress; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetCurrentProgress (&progress); - - return progress; -} - -static EphyDownloadState -impl_get_state (EphyDownload *download) -{ - MozDownload *mozDownload; - EphyDownloadState state; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetState (&state); - - return state; -} - -static gint64 -impl_get_total_progress (EphyDownload *download) -{ - MozDownload *mozDownload; - PRInt64 progress; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetTotalProgress (&progress); - - return progress; -} - -static int -impl_get_percent (EphyDownload *download) -{ - MozDownload *mozDownload; - PRInt32 percent; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetPercentComplete (&percent); - - return percent; -} - -static gint64 -impl_get_elapsed_time (EphyDownload *download) -{ - MozDownload *mozDownload; - PRInt64 elapsed; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetElapsedTime (&elapsed); - - return elapsed / 1000000; -} - -static char* -impl_get_mime (EphyDownload *download) -{ - MozDownload *mozDownload; - nsCOMPtr<nsIMIMEInfo> mime; - nsCString mimeType; - - mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; - - mozDownload->GetMIMEInfo (getter_AddRefs(mime)); - if (!mime) return g_strdup ("application/octet-stream"); - - mime->GetMIMEType(mimeType); - - return g_strdup (mimeType.get()); -} - -static void -impl_cancel (EphyDownload *download) -{ - MOZILLA_DOWNLOAD (download)->priv->moz_download->Cancel (); -} - -static void -impl_pause (EphyDownload *download) -{ - MOZILLA_DOWNLOAD (download)->priv->moz_download->Pause (); -} - -static void -impl_resume (EphyDownload *download) -{ - MOZILLA_DOWNLOAD (download)->priv->moz_download->Resume (); -} - -static void -mozilla_download_finalize (GObject *object) -{ - MozillaDownload *download = MOZILLA_DOWNLOAD (object); - - NS_RELEASE (download->priv->moz_download); - - LOG ("MozillaDownload %p finalised", object); - - G_OBJECT_CLASS (mozilla_download_parent_class)->finalize (object); -} - -static void -mozilla_download_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MozillaDownload *download = MOZILLA_DOWNLOAD (object); - - switch (prop_id) - { - case PROP_MOZDOWNLOAD: - MozDownload *moz_download; - - moz_download = (MozDownload *)g_value_get_pointer (value); - NS_ADDREF (moz_download); - download->priv->moz_download = moz_download; - break; - } -} - -static void -mozilla_download_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MozillaDownload *download = MOZILLA_DOWNLOAD (object); - - switch (prop_id) - { - case PROP_MOZDOWNLOAD: - g_value_set_pointer (value, download->priv->moz_download); - break; - } -} - -static void -mozilla_download_class_init (MozillaDownloadClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - EphyDownloadClass *download_class = EPHY_DOWNLOAD_CLASS (klass); - - object_class->finalize = mozilla_download_finalize; - object_class->set_property = mozilla_download_set_property; - object_class->get_property = mozilla_download_get_property; - - download_class->get_elapsed_time = impl_get_elapsed_time; - download_class->get_current_progress = impl_get_current_progress; - download_class->get_total_progress = impl_get_total_progress; - download_class->get_percent = impl_get_percent; - download_class->get_target = impl_get_target; - download_class->get_source = impl_get_source; - download_class->get_state = impl_get_state; - download_class->get_mime = impl_get_mime; - download_class->cancel = impl_cancel; - download_class->pause = impl_pause; - download_class->resume = impl_resume; - - g_type_class_add_private (klass, sizeof (MozillaDownloadPrivate)); - - g_object_class_install_property (object_class, - PROP_MOZDOWNLOAD, - g_param_spec_pointer ("mozilla-download", - "Mozilla Download", - "Mozilla Download", - (GParamFlags) - (G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | - G_PARAM_CONSTRUCT_ONLY))); -} - -static void -mozilla_download_init (MozillaDownload *download) -{ - LOG ("MozillaDownload %p initialising", download); - - download->priv = MOZILLA_DOWNLOAD_GET_PRIVATE (download); -} - -EphyDownload * -mozilla_download_new (MozDownload *download) -{ - return EPHY_DOWNLOAD (g_object_new (MOZILLA_TYPE_DOWNLOAD, - "mozilla-download", download, - NULL)); -} diff --git a/embed/mozilla/mozilla-download.h b/embed/mozilla/mozilla-download.h deleted file mode 100644 index 071ec31af..000000000 --- a/embed/mozilla/mozilla-download.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2000, 2001, 2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_DOWNLOAD_H -#define MOZILLA_DOWNLOAD_H - -#include <glib.h> -#include <glib-object.h> - -#include "ephy-download.h" - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_DOWNLOAD (mozilla_download_get_type ()) -#define MOZILLA_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_DOWNLOAD, MozillaDownload)) -#define MOZILLA_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadClass)) -#define MOZILLA_IS_DOWNLOAD(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_DOWNLOAD)) -#define MOZILLA_IS_DOWNLOAD_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_DOWNLOAD)) -#define MOZILLA_DOWNLOAD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadClass)) - -typedef struct _MozillaDownloadClass MozillaDownloadClass; -typedef struct _MozillaDownload MozillaDownload; -typedef struct _MozillaDownloadPrivate MozillaDownloadPrivate; - -class MozDownload; - -struct _MozillaDownload -{ - EphyDownload parent; - MozillaDownloadPrivate *priv; -}; - -struct _MozillaDownloadClass -{ - EphyDownloadClass parent_class; -}; - -GType mozilla_download_get_type (void); - -EphyDownload *mozilla_download_new (MozDownload *download); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-embed-event.cpp b/embed/mozilla/mozilla-embed-event.cpp deleted file mode 100644 index faaff0436..000000000 --- a/embed/mozilla/mozilla-embed-event.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <glib/ghash.h> - -#include <nsCOMPtr.h> -#include <nsIDOMEvent.h> - -#include "ephy-debug.h" - -#include "mozilla-embed-event.h" - -#define MOZILLA_EMBED_EVENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_EVENT, MozillaEmbedEventPrivate)) - -struct _MozillaEmbedEventPrivate -{ - nsIDOMEvent* dom_event; - GHashTable *props; -}; - -static void mozilla_embed_event_class_init (MozillaEmbedEventClass *klass); -static void mozilla_embed_event_init (MozillaEmbedEvent *event); -static void ephy_embed_event_iface_init (EphyEmbedEventIface *iface); - -G_DEFINE_TYPE_WITH_CODE (MozillaEmbedEvent, mozilla_embed_event, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_EMBED_EVENT, - ephy_embed_event_iface_init)) - -MozillaEmbedEvent * -mozilla_embed_event_new (gpointer dom_event) -{ - MozillaEmbedEvent *event; - - event = MOZILLA_EMBED_EVENT (g_object_new (MOZILLA_TYPE_EMBED_EVENT, NULL)); - - event->priv->dom_event = static_cast<nsIDOMEvent*>(dom_event); - NS_IF_ADDREF (event->priv->dom_event); - - return event; -} - -void -mozilla_embed_event_set_property (MozillaEmbedEvent *event, - const char *name, - GValue *value) -{ - char *value_content = g_strdup_value_contents (value); - LOG ("embed event %p set property \"%s\" to %s", event, name, value_content); - g_free (value_content); - - g_hash_table_insert (event->priv->props, - g_strdup (name), - value); -} - -static EphyEmbedEventContext -impl_get_context (EphyEmbedEvent *event) -{ - return (EphyEmbedEventContext) ((MozillaEmbedEvent *) event)->context; -} - -static guint -impl_get_button (EphyEmbedEvent *event) -{ - return ((MozillaEmbedEvent *) event)->button; -} - -static guint -impl_get_modifier (EphyEmbedEvent *event) -{ - return ((MozillaEmbedEvent *) event)->modifier; -} - -static void -impl_get_coordinates (EphyEmbedEvent *event, - guint *x, - guint *y) -{ - *x = ((MozillaEmbedEvent *) event)->x; - *y = ((MozillaEmbedEvent *) event)->y; -} - -static const GValue* -impl_get_property (EphyEmbedEvent *event, - const char *name) -{ - return (const GValue *) g_hash_table_lookup (((MozillaEmbedEvent *) event)->priv->props, name); -} - -static gboolean -impl_has_property (EphyEmbedEvent *event, - const char *name) -{ - gpointer tmp; - - tmp = g_hash_table_lookup (((MozillaEmbedEvent *) event)->priv->props, name); - - return tmp != NULL; -} - -static gpointer -impl_get_dom_event (EphyEmbedEvent *event) -{ - return static_cast<gpointer>(((MozillaEmbedEvent *) event)->priv->dom_event); -} - -static void -free_g_value (gpointer value) -{ - g_value_unset ((GValue *) value); - g_free (value); -} - -static void -mozilla_embed_event_init (MozillaEmbedEvent *event) -{ - event->priv = MOZILLA_EMBED_EVENT_GET_PRIVATE (event); - - LOG ("MozillaEmbedEvent %p initialising", event); - - event->priv->dom_event = nsnull; - event->priv->props = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, free_g_value); -} - -static void -mozilla_embed_event_finalize (GObject *object) -{ - MozillaEmbedEvent *event = MOZILLA_EMBED_EVENT (object); - - g_hash_table_destroy (event->priv->props); - - NS_IF_RELEASE (event->priv->dom_event); - event->priv->dom_event = nsnull; - - LOG ("MozillaEmbedEvent %p finalised", object); - - G_OBJECT_CLASS (mozilla_embed_event_parent_class)->finalize (object); -} - -static void -ephy_embed_event_iface_init (EphyEmbedEventIface *iface) -{ - iface->get_context = impl_get_context; - iface->get_button = impl_get_button; - iface->get_modifier = impl_get_modifier; - iface->get_coordinates = impl_get_coordinates; - iface->get_property = impl_get_property; - iface->has_property = impl_has_property; - iface->get_dom_event = impl_get_dom_event; -} - -static void -mozilla_embed_event_class_init (MozillaEmbedEventClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = mozilla_embed_event_finalize; - - g_type_class_add_private (object_class, sizeof (MozillaEmbedEventPrivate)); -} diff --git a/embed/mozilla/mozilla-embed-event.h b/embed/mozilla/mozilla-embed-event.h deleted file mode 100644 index 4306bef67..000000000 --- a/embed/mozilla/mozilla-embed-event.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti - * Copyright © 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_EMBED_EVENT_H -#define MOZILLA_EMBED_EVENT_H - -#include <glib.h> -#include <glib-object.h> - -#include "ephy-embed-event.h" - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_EMBED_EVENT (mozilla_embed_event_get_type ()) -#define MOZILLA_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_EMBED_EVENT, MozillaEmbedEvent)) -#define MOZILLA_EMBED_EVENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_EMBED_EVENT, MozillaEmbedEventClass)) -#define MOZILLA_IS_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_EMBED_EVENT)) -#define MOZILLA_IS_EMBED_EVENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_EMBED_EVENT)) -#define MOZILLA_EMBED_EVENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_EMBED_EVENT, MozillaEmbedEventClass)) - -typedef struct _MozillaEmbedEventClass MozillaEmbedEventClass; -typedef struct _MozillaEmbedEvent MozillaEmbedEvent; -typedef struct _MozillaEmbedEventPrivate MozillaEmbedEventPrivate; - -struct _MozillaEmbedEventClass -{ - GObjectClass parent_class; -}; - -struct _MozillaEmbedEvent -{ - GObject parent; - - /*< private >*/ - MozillaEmbedEventPrivate *priv; - - /*< private >*/ /* public to the embed implementation */ - guint button; - guint context; - guint modifier; - guint x; - guint y; - guint keycode; -}; - -GType mozilla_embed_event_get_type (void); - -MozillaEmbedEvent *mozilla_embed_event_new (gpointer dom_event); - -void mozilla_embed_event_set_property (MozillaEmbedEvent *event, - const char *name, - GValue *value); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-embed-find.cpp b/embed/mozilla/mozilla-embed-find.cpp deleted file mode 100644 index 99abee0b3..000000000 --- a/embed/mozilla/mozilla-embed-find.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include "ephy-debug.h" -#include "ephy-embed-find.h" -#include "ephy-embed-shell.h" - -#include "EphyFind.h" - -#include "mozilla-embed-find.h" - -static void mozilla_embed_find_class_init (MozillaEmbedFindClass *klass); -static void mozilla_embed_find_init (MozillaEmbedFind *self); -static void ephy_find_iface_init (EphyEmbedFindIface *iface); - -#define MOZILLA_EMBED_FIND_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_FIND, MozillaEmbedFindPrivate)) - -struct _MozillaEmbedFindPrivate -{ - EphyFind *find; -}; - -static void -impl_set_embed (EphyEmbedFind *efind, - EphyEmbed *embed) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - priv->find->SetEmbed (embed); -} - -G_DEFINE_TYPE_WITH_CODE (MozillaEmbedFind, mozilla_embed_find, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_EMBED_FIND, - ephy_find_iface_init)) - -static void -impl_set_properties (EphyEmbedFind *efind, - const char *find_string, - gboolean case_sensitive) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - priv->find->SetFindProperties (find_string, case_sensitive); -} - -static EphyEmbedFindResult -impl_find (EphyEmbedFind *efind, - const char *find_string, - gboolean links_only) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - return priv->find->Find (find_string, links_only); -} - -static EphyEmbedFindResult -impl_find_again (EphyEmbedFind *efind, - gboolean forward, - gboolean links_only) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - return priv->find->FindAgain (forward, links_only); -} - -static void -impl_set_selection (EphyEmbedFind *efind, - gboolean attention) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - priv->find->SetSelectionAttention (attention); -} - -static gboolean -impl_activate_link (EphyEmbedFind *efind, - GdkModifierType mask) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (efind); - MozillaEmbedFindPrivate *priv = find->priv; - - return priv->find->ActivateLink (mask); -} - -static void -ephy_find_iface_init (EphyEmbedFindIface *iface) -{ - iface->set_embed = impl_set_embed; - iface->set_properties = impl_set_properties; - iface->find = impl_find; - iface->find_again = impl_find_again; - iface->set_selection = impl_set_selection; - iface->activate_link = impl_activate_link; -} - -static void -mozilla_embed_find_init (MozillaEmbedFind *find) -{ - find->priv = MOZILLA_EMBED_FIND_GET_PRIVATE (find); - find->priv->find = new EphyFind (); -} - -static GObject * -mozilla_embed_find_constructor (GType type, guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - g_object_ref (embed_shell); - - /* we depend on single because of mozilla initialization */ - ephy_embed_shell_get_embed_single (embed_shell); - - return G_OBJECT_CLASS (mozilla_embed_find_parent_class)->constructor (type, - n_construct_properties, - construct_params); -} - -static void -mozilla_embed_find_finalize (GObject *object) -{ - MozillaEmbedFind *find = MOZILLA_EMBED_FIND (object); - - delete find->priv->find; - - G_OBJECT_CLASS (mozilla_embed_find_parent_class)->finalize (object); - - g_object_unref (embed_shell); -} - -static void -mozilla_embed_find_class_init (MozillaEmbedFindClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = mozilla_embed_find_constructor; - object_class->finalize = mozilla_embed_find_finalize; - - g_type_class_add_private (object_class, sizeof (MozillaEmbedFindPrivate)); -} - diff --git a/embed/mozilla/mozilla-embed-find.h b/embed/mozilla/mozilla-embed-find.h deleted file mode 100644 index 1291f3795..000000000 --- a/embed/mozilla/mozilla-embed-find.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2000-2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_EMBED_FIND_H -#define MOZILLA_EMBED_FIND_H - -#include <glib.h> -#include <glib-object.h> - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_EMBED_FIND (mozilla_embed_find_get_type ()) -#define MOZILLA_EMBED_FIND(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_EMBED_FIND, MozillaEmbedFind)) -#define MOZILLA_EMBED_FIND_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_EMBED_FIND, MozillaEmbedFindClass)) -#define MOZILLA_IS_EMBED_FIND(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_EMBED_FIND)) -#define MOZILLA_IS_EMBED_FIND_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_EMBED_FIND)) -#define MOZILLA_EMBED_FIND_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_EMBED_FIND, MozillaEmbedFindClass)) - -typedef struct _MozillaEmbedFindClass MozillaEmbedFindClass; -typedef struct _MozillaEmbedFind MozillaEmbedFind; -typedef struct _MozillaEmbedFindPrivate MozillaEmbedFindPrivate; - -struct _MozillaEmbedFind -{ - GObject parent_instance; - - /*< private >*/ - MozillaEmbedFindPrivate *priv; -}; - -struct _MozillaEmbedFindClass -{ - GObjectClass parent_class; -}; - -GType mozilla_embed_find_get_type (void); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp deleted file mode 100644 index 7149873e3..000000000 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright © 2000, 2001, 2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <stddef.h> - -#include <nsStringAPI.h> - -#include <nsCOMPtr.h> -#include <nsComponentManagerUtils.h> -#include <nsCWebBrowserPersist.h> -#include <nsICacheEntryDescriptor.h> -#include <nsICacheService.h> -#include <nsICacheSession.h> -#include <nsIDOMSerializer.h> -#include <nsIFile.h> -#include <nsIHistoryEntry.h> -#include <nsIInputStream.h> -#include <nsIIOService.h> -#include <nsILocalFile.h> -#include <nsISHEntry.h> -#include <nsIURI.h> -#include <nsIWebBrowserPersist.h> -#include <nsNetCID.h> -#include <nsNetError.h> -#include <nsServiceManagerUtils.h> -#include <nsXPCOM.h> - -#include "EphyBrowser.h" -#include "EphyHeaderSniffer.h" -#include "EphyUtils.h" -#include "MozDownload.h" - -#include "ephy-debug.h" -#include "ephy-embed-shell.h" -#include "ephy-file-helpers.h" -#include "mozilla-embed.h" - -#include "mozilla-embed-persist.h" - -static void -mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); -static void -mozilla_embed_persist_init (MozillaEmbedPersist *ges); -static void -mozilla_embed_persist_finalize (GObject *object); - -#define MOZILLA_EMBED_PERSIST_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_PERSIST, MozillaEmbedPersistPrivate)) - -struct MozillaEmbedPersistPrivate -{ - nsCOMPtr<nsIWebBrowserPersist> mPersist; -}; - -G_DEFINE_TYPE (MozillaEmbedPersist, mozilla_embed_persist, EPHY_TYPE_EMBED_PERSIST) - -static void -mozilla_embed_persist_init (MozillaEmbedPersist *persist) -{ - persist->priv = MOZILLA_EMBED_PERSIST_GET_PRIVATE (persist); - - persist->priv->mPersist = do_CreateInstance (NS_WEBBROWSERPERSIST_CONTRACTID); -} - -static void -mozilla_embed_persist_finalize (GObject *object) -{ - MozillaEmbedPersist *persist = MOZILLA_EMBED_PERSIST (object); - - persist->priv->mPersist = nsnull; - - G_OBJECT_CLASS (mozilla_embed_persist_parent_class)->finalize (object); -} - -void -mozilla_embed_persist_completed (MozillaEmbedPersist *persist) -{ - g_signal_emit_by_name (persist, "completed"); - g_object_unref (persist); -} - -void -mozilla_embed_persist_cancelled (MozillaEmbedPersist *persist) -{ - g_signal_emit_by_name (persist, "cancelled"); - g_object_unref (persist); -} - -static void -impl_cancel (EphyEmbedPersist *persist) -{ - nsCOMPtr<nsIWebBrowserPersist> bpersist = - MOZILLA_EMBED_PERSIST (persist)->priv->mPersist; - nsCOMPtr<nsICancelable> cancelable (do_QueryInterface (bpersist)); - if (cancelable) - { - cancelable->Cancel (NS_BINDING_ABORTED); - } - - g_object_unref (persist); -} - -static gboolean -impl_save (EphyEmbedPersist *persist) -{ - nsresult rv; - char *filename; - char *uri; - gint64 max_size; - EphyEmbed *embed; - EphyEmbedPersistFlags flags; - EphyEmbedSingle *single; - - single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); - - g_object_ref (persist); - - g_object_get (persist, - "source", &uri, - "dest", &filename, - "flags", &flags, - "embed", &embed, - "max_size", &max_size, - (char *) NULL); - - g_return_val_if_fail (!(flags & EPHY_EMBED_PERSIST_COPY_PAGE) - || embed != NULL, FALSE); - - EphyBrowser *browser = NULL; - if (embed) - { - browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed)); - - g_object_unref (embed); - - NS_ENSURE_TRUE (browser, FALSE); - } - /* we must have one of uri or browser */ - g_assert (browser != NULL || uri != NULL); - - /* Get the uri to save to */ - nsCOMPtr<nsIURI> inURI; - if (uri) - { - /* FIXME: origin charset!! */ - rv = EphyUtils::NewURI (getter_AddRefs(inURI), nsCString(uri)); - NS_ENSURE_SUCCESS (rv, FALSE); - } - else - { - rv = browser->GetDocumentURI (getter_AddRefs (inURI)); - NS_ENSURE_SUCCESS (rv, FALSE); - } - - /* Get post data */ - nsCOMPtr<nsIInputStream> postData; - /* FIXME: don't do this on COPY_PAGE to ensure we don't end up reposting? */ - if (browser) - { - PRInt32 sindex; - - nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(browser->mWebBrowser)); - nsCOMPtr<nsISHistory> sessionHistory; - webNav->GetSessionHistory(getter_AddRefs(sessionHistory)); - nsCOMPtr<nsIHistoryEntry> entry; - sessionHistory->GetIndex(&sindex); - sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry)); - nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(entry)); - if (shEntry) - { - shEntry->GetPostData(getter_AddRefs(postData)); - } - } - - /* Get the DOM document if a uri is not specified */ - nsCOMPtr<nsIDOMDocument> DOMDocument; - if (!uri) - { - if (flags & EPHY_EMBED_PERSIST_MAINDOC) - { - browser->GetDocument (getter_AddRefs(DOMDocument)); - } - else - { - browser->GetTargetDocument (getter_AddRefs(DOMDocument)); - } - NS_ENSURE_TRUE (DOMDocument, FALSE); - } - - - /* Get the current page descriptor */ - nsCOMPtr<nsISupports> cacheDescriptor; - if (browser) - { - browser->GetPageDescriptor(getter_AddRefs (cacheDescriptor)); - } - - /* Try to get a descriptor from the cache session */ - /* FIXME: what about https?? */ - PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; - if (!cacheDescriptor && - (flags & EPHY_EMBED_PERSIST_FROM_CACHE) && - inURI && - ((NS_SUCCEEDED (inURI->SchemeIs ("http", &isHttp)) && isHttp) || - (NS_SUCCEEDED (inURI->SchemeIs ("https", &isHttps)) && isHttps ))) - { - nsCOMPtr<nsICacheService> cacheService - (do_GetService(NS_CACHESERVICE_CONTRACTID)); - if (cacheService) - { - nsCOMPtr<nsICacheSession> cacheSession; - rv = cacheService->CreateSession ("HTTP", - nsICache::STORE_ANYWHERE, - PR_TRUE, - getter_AddRefs (cacheSession)); - if (NS_SUCCEEDED (rv) && cacheSession) - { - nsCOMPtr<nsICacheEntryDescriptor> descriptor; - - nsCString spec; - inURI->GetSpec (spec); - - rv = cacheSession->OpenCacheEntry - (spec, - nsICache::ACCESS_READ, - PR_FALSE, getter_AddRefs (descriptor)); - - cacheDescriptor = do_QueryInterface (descriptor); - - LOG ("Getting cache descriptor for '%s' rv=%x", spec.get(), rv); - } - } - } - - LOG ("Cache descriptor %p", cacheDescriptor.get()); - - /* if we have COPY_PAGE, we *need* to have a page descriptor, else we'll re-fetch - * the page, which will possibly give a different page than the original which we - * need for view source - */ - NS_ENSURE_TRUE (!(flags & EPHY_EMBED_PERSIST_COPY_PAGE) || cacheDescriptor, FALSE); - - if (filename == NULL || filename[0] == '\0') - { - /* Get a temp filename to save to */ - char *tmp_filename, *base; - base = g_build_filename (g_get_tmp_dir (), "sav-XXXXXX", (char *) NULL); - tmp_filename = ephy_file_tmp_filename (base, "html"); - g_free (base); - if (tmp_filename == NULL) return FALSE; - - nsCOMPtr<nsILocalFile> tmpFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - NS_ENSURE_TRUE (tmpFile, FALSE); - - tmpFile->InitWithNativePath (nsCString (tmp_filename)); - g_free (tmp_filename); - - /* Create an header sniffer and do the save */ - nsCOMPtr<nsIWebBrowserPersist> webPersist = - MOZILLA_EMBED_PERSIST (persist)->priv->mPersist; - NS_ENSURE_TRUE (webPersist, FALSE); - - EphyHeaderSniffer* sniffer = new EphyHeaderSniffer - (webPersist, MOZILLA_EMBED_PERSIST (persist), - tmpFile, inURI, DOMDocument, postData, single); - if (!sniffer) return FALSE; - - webPersist->SetProgressListener(sniffer); - rv = webPersist->SaveURI(inURI, cacheDescriptor, nsnull /* FIXME: Referrer */, nsnull, nsnull, tmpFile); - if (NS_FAILED (rv)) return FALSE; - } - else - { - /* Filename to save to */ - nsCOMPtr<nsILocalFile> destFile; - NS_NewNativeLocalFile (nsCString(filename), - PR_TRUE, getter_AddRefs(destFile)); - NS_ENSURE_TRUE (destFile, FALSE); - - rv = InitiateMozillaDownload (DOMDocument, inURI, destFile, - nsnull, inURI, MOZILLA_EMBED_PERSIST (persist), - postData, cacheDescriptor, max_size); - if (NS_FAILED (rv)) return FALSE; - } - - g_free (uri); - g_free (filename); - - return TRUE; -} - -static char * -impl_to_string (EphyEmbedPersist *persist) -{ - EphyEmbed *embed; - nsCOMPtr<nsIDOMDocument> DOMDocument; - EphyEmbedPersistFlags flags; - EphyBrowser *browser; - nsresult rv = NS_OK; - - g_object_ref (persist); - - g_object_get (persist, - "flags", &flags, - "embed", &embed, - (char *) NULL); - g_object_unref (persist); - g_return_val_if_fail (embed != NULL, NULL); - - browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed)); - g_return_val_if_fail (browser != NULL, NULL); - - if (flags & EPHY_EMBED_PERSIST_MAINDOC) - { - rv = browser->GetDocument (getter_AddRefs(DOMDocument)); - } - else - { - rv = browser->GetTargetDocument (getter_AddRefs(DOMDocument)); - } - - nsCString cOutString; - nsCOMPtr<nsIDOMNode> node = do_QueryInterface(DOMDocument); - if (node) - { - nsString outString; - nsCOMPtr<nsIDOMSerializer> serializer; - serializer = do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID, &rv); - if (serializer) - { - serializer->SerializeToString(node, outString); - - NS_UTF16ToCString (outString, NS_CSTRING_ENCODING_UTF8, cOutString); - } - } - - g_object_unref (embed); - - return g_strdup (cOutString.get()); -} - -static GObject * -mozilla_embed_persist_constructor (GType type, guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - /* this will ensure that mozilla is started up */ - ephy_embed_shell_get_embed_single (embed_shell); - - return G_OBJECT_CLASS (mozilla_embed_persist_parent_class)->constructor (type, - n_construct_properties, - construct_params); -} - -static void -mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - EphyEmbedPersistClass *persist_class = EPHY_EMBED_PERSIST_CLASS (klass); - - object_class->finalize = mozilla_embed_persist_finalize; - object_class->constructor = mozilla_embed_persist_constructor; - - persist_class->save = impl_save; - persist_class->cancel = impl_cancel; - persist_class->to_string = impl_to_string; - - g_type_class_add_private (object_class, sizeof(MozillaEmbedPersistPrivate)); -} diff --git a/embed/mozilla/mozilla-embed-persist.h b/embed/mozilla/mozilla-embed-persist.h deleted file mode 100644 index edcb1eb53..000000000 --- a/embed/mozilla/mozilla-embed-persist.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright © 2000-2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_EMBED_PERSIST_H -#define MOZILLA_EMBED_PERSIST_H - -#include <glib.h> -#include <glib-object.h> - -#include "ephy-embed-persist.h" - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_EMBED_PERSIST (mozilla_embed_persist_get_type ()) -#define MOZILLA_EMBED_PERSIST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_EMBED_PERSIST, MozillaEmbedPersist)) -#define MOZILLA_EMBED_PERSIST_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_EMBED_PERSIST, MozillaEmbedPersistClass)) -#define MOZILLA_IS_EMBED_PERSIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_EMBED_PERSIST)) -#define MOZILLA_IS_EMBED_PERSIST_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_EMBED_PERSIST)) -#define MOZILLA_EMBED_PERSIST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_EMBED_PERSIST, MozillaEmbedPersistClass)) - -typedef struct MozillaEmbedPersistClass MozillaEmbedPersistClass; -typedef struct MozillaEmbedPersist MozillaEmbedPersist; -typedef struct MozillaEmbedPersistPrivate MozillaEmbedPersistPrivate; - -struct MozillaEmbedPersist -{ - EphyEmbedPersist parent; - - /*< private >*/ - MozillaEmbedPersistPrivate *priv; -}; - -struct MozillaEmbedPersistClass -{ - EphyEmbedPersistClass parent_class; -}; - -GType mozilla_embed_persist_get_type (void); - -void mozilla_embed_persist_completed (MozillaEmbedPersist *persist); - -void mozilla_embed_persist_cancelled (MozillaEmbedPersist *persist); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp deleted file mode 100644 index 84657d3a4..000000000 --- a/embed/mozilla/mozilla-embed-single.cpp +++ /dev/null @@ -1,1454 +0,0 @@ -/* vim:set ts=8 noet sw=8: - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003 Robert Marcano - * Copyright © 2003, 2004, 2005, 2006 Christian Persch - * Copyright © 2005 Crispin Flowerday - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" - -#include "config.h" - -#include <stdlib.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -#include <nsStringAPI.h> - -#ifdef XPCOM_GLUE -#include <nsXPCOMGlue.h> -#include <gtkmozembed_glue.cpp> -#endif - -#include <gtkmozembed.h> -#include <gtkmozembed_internal.h> -#include <nsComponentManagerUtils.h> -#include <nsCOMPtr.h> -#include <nsCPasswordManager.h> -#include <nsICookie2.h> -#include <nsICookieManager.h> -#include <nsICookieManager.h> -#include <nsIFile.h> -#include <nsIIOService.h> -#include <nsILocalFile.h> -#include <nsIPermission.h> -#include <nsIPermissionManager.h> -#include <nsIPrefService.h> -#include <nsIStyleSheetService.h> -#include <nsISupportsPrimitives.h> -#include <nsIURI.h> -#include <nsIWindowWatcher.h> -#include <nsMemory.h> -#include <nsServiceManagerUtils.h> - -#ifdef ALLOW_PRIVATE_API -#include <nsICacheService.h> -#include <nsIFontEnumerator.h> -#include <nsIHttpAuthManager.h> -#include <nsIIDNService.h> -#include <nsNetCID.h> -#endif /* ALLOW_PRIVATE_API */ - -#ifdef HAVE_GECKO_1_9 -#include <nsILoginInfo.h> -#include <nsILoginManager.h> -#else -#include <nsIPassword.h> -#include <nsIPasswordManager.h> -#endif /* !HAVE_GECKO_1_9 */ - -#include "ephy-file-helpers.h" -#include "eel-gconf-extensions.h" -#include "ephy-cookie-manager.h" -#include "ephy-debug.h" -#include "ephy-embed-prefs.h" -#include "ephy-embed-shell.h" -#include "ephy-langs.h" -#include "ephy-password-manager.h" -#include "ephy-permission-manager.h" -#include "ephy-string.h" -#include "mozilla-embed.h" -#include "mozilla-notifiers.h" - -#include "EphyBrowser.h" -#include "EphySingle.h" -#include "EphyUtils.h" -#include "MozRegisterComponents.h" - -#include "mozilla-embed-single.h" - -#include "AutoJSContextStack.h" - -#define MOZILLA_PROFILE_DIR "/mozilla" -#define MOZILLA_PROFILE_NAME "epiphany" -#define MOZILLA_PROFILE_FILE "prefs.js" -#define DEFAULT_PROFILE_FILE SHARE_DIR"/default-prefs.js" - -#define USER_CSS_LOAD_DELAY 500 /* ms */ - -#define MOZILLA_EMBED_SINGLE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED_SINGLE, MozillaEmbedSinglePrivate)) - -#ifndef HAVE_GECKO_1_9 -#include "EphyDirectoryProvider.h" -#endif /* HAVE_GECKO_1_9 */ - -struct MozillaEmbedSinglePrivate -{ - char *user_prefs; - - EphySingle *mSingleObserver; - - char *user_css_file; - guint user_css_enabled_notifier_id; - GFileMonitor *user_css_file_monitor; - guint user_css_enabled : 1; -}; - -enum -{ - PROP_0, - PROP_NETWORK_STATUS -}; - -static void mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass); -static void ephy_embed_single_iface_init (EphyEmbedSingleIface *iface); -static void ephy_cookie_manager_iface_init (EphyCookieManagerIface *iface); -static void ephy_password_manager_iface_init (EphyPasswordManagerIface *iface); -static void ephy_permission_manager_iface_init (EphyPermissionManagerIface *iface); -static void mozilla_embed_single_init (MozillaEmbedSingle *ges); - -G_DEFINE_TYPE_WITH_CODE (MozillaEmbedSingle, mozilla_embed_single, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_EMBED_SINGLE, - ephy_embed_single_iface_init) - G_IMPLEMENT_INTERFACE (EPHY_TYPE_COOKIE_MANAGER, - ephy_cookie_manager_iface_init) - G_IMPLEMENT_INTERFACE (EPHY_TYPE_PASSWORD_MANAGER, - ephy_password_manager_iface_init) - G_IMPLEMENT_INTERFACE (EPHY_TYPE_PERMISSION_MANAGER, - ephy_permission_manager_iface_init)) - -static gboolean -mozilla_set_default_prefs (MozillaEmbedSingle *mes) -{ - nsCOMPtr<nsIPrefService> prefService; - - prefService = do_GetService (NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_TRUE (prefService, FALSE); - - /* read our predefined default prefs */ - nsresult rv; - nsCOMPtr<nsILocalFile> file; - NS_NewNativeLocalFile(nsCString(DEFAULT_PROFILE_FILE), - PR_TRUE, getter_AddRefs(file)); - if (!file) return FALSE; - - rv = prefService->ReadUserPrefs (file); - if (NS_FAILED(rv)) - { - g_warning ("failed to read default preferences, error: %x", rv); - return FALSE; - } - - nsCOMPtr<nsIPrefBranch> pref; - prefService->GetBranch ("", getter_AddRefs(pref)); - NS_ENSURE_TRUE (pref, FALSE); - - /* We do this before reading the user pref file so that the user - * still can overwrite this pref. - * We don't use the default-prefs.js file since that cannot be - * localised (see bug #144909). - */ - /* translators: this is the URL that searches from the location - * entry get directed to. The search terms will be _appended_ to it, - * in url-escaped UTF-8; that means that if you're choosing google, - * the 'q=' part needs to come last. - */ - pref->SetCharPref ("keyword.URL", _("http://www.google.com/search?ie=UTF-8&oe=UTF-8&q=")); - - /* Load the default user preferences as well. This also makes the - prefs to be saved in the user's prefs.js file, instead of messing up - our global defaults file. */ - rv = prefService->ReadUserPrefs (nsnull); - if (NS_FAILED(rv)) - { - g_warning ("failed to read user preferences, error: %x", rv); - } - - pref->SetCharPref ("general.useragent.extra.epiphany", "Epiphany/" UA_VERSION); - - /* Unset old prefs, otherwise they end up in the user agent string too */ - pref->ClearUserPref ("general.useragent.vendor"); - pref->ClearUserPref ("general.useragent.vendorSub"); - - /* Don't open ftp uris with an external handler if one is setup */ - pref->SetBoolPref ("network.protocol-handler.external.ftp", PR_FALSE); - - return TRUE; -} - -static void -mozilla_embed_single_new_window_orphan_cb (GtkMozEmbedSingle *moz_single, - GtkMozEmbed **newEmbed, - guint chrome_mask, - EphyEmbedSingle *single) -{ - GtkMozEmbedChromeFlags chrome = (GtkMozEmbedChromeFlags) chrome_mask; - EphyEmbed *new_embed = NULL; - EphyEmbedChrome mask; - - if (chrome_mask & GTK_MOZ_EMBED_FLAG_OPENASCHROME) - { - *newEmbed = _mozilla_embed_new_xul_dialog (); - return; - } - - mask = _mozilla_embed_translate_chrome (chrome); - - g_signal_emit_by_name (single, "new-window", NULL, mask, - &new_embed); - - /* it's okay not to have a new embed */ - if (new_embed != NULL) - { - gtk_moz_embed_set_chrome_mask (GTK_MOZ_EMBED (new_embed), chrome); - - *newEmbed = GTK_MOZ_EMBED (new_embed); - } -} - -static GList * -mozilla_init_plugin_add_unique_path (GList *list, - const char *path) -{ - GList *l; - char *canon; - - if (path == NULL) - return list; - - canon = ephy_string_canonicalize_pathname (path); - - for (l = list; l != NULL; l = l->next) { - if (g_str_equal (list->data, canon) != FALSE) { - /* The path is already in the list */ - g_free (canon); - return list; - } - } - return g_list_prepend (list, canon); -} - -static GList * -mozilla_init_plugin_add_unique_paths (GList *list, - const char *path) -{ - char **paths; - guint i; - - if (path == NULL) - return list; - - paths = g_strsplit (path, ":", -1); - if (paths == NULL) - return list; - for (i = 0; paths[i] != NULL; i++) { - list = mozilla_init_plugin_add_unique_path (list, paths[i]); - } - g_strfreev (paths); - return list; -} - -static void -mozilla_init_plugin_path () -{ - GList *list, *l; - GString *path; - - list = NULL; - list = mozilla_init_plugin_add_unique_paths (list, - g_getenv ("MOZ_PLUGIN_PATH")); - list = mozilla_init_plugin_add_unique_path (list, - MOZILLA_PREFIX "/lib/mozilla/plugins"); - list = mozilla_init_plugin_add_unique_path (list, - MOZILLA_HOME "/plugins"); - list = mozilla_init_plugin_add_unique_path (list, - MOZILLA_NATIVE_PLUGINSDIR); -#ifdef HAVE_PRIVATE_PLUGINS - list = mozilla_init_plugin_add_unique_path (list, PLUGINDIR); -#endif - - list = g_list_reverse (list); - path = g_string_new ((const char *) list->data); - g_free (list->data); - l = list->next; - for (; l != NULL; l = l->next) { - path = g_string_append_c (path, ':'); - path = g_string_append (path, (const char *) l->data); - g_free (l->data); - } - g_list_free (list); - - g_setenv ("MOZ_PLUGIN_PATH", path->str, TRUE); - g_string_free (path, TRUE); -} - -static void -mozilla_init_single (MozillaEmbedSingle *mes) -{ - GtkMozEmbedSingle *single; - - /* get single */ - single = gtk_moz_embed_single_get (); - if (single == NULL) - { - g_warning ("Failed to get singleton embed object!\n"); - } - - /* allow creation of orphan windows */ - g_signal_connect (G_OBJECT (single), "new_window_orphan", - G_CALLBACK (mozilla_embed_single_new_window_orphan_cb), - mes); -} - -void -mozilla_init_profile (void) -{ - char *profile_path; - profile_path = g_build_filename (ephy_dot_dir (), - MOZILLA_PROFILE_DIR, - (char *) NULL); - gtk_moz_embed_set_profile_path (profile_path, MOZILLA_PROFILE_NAME); - g_free (profile_path); -} - -#if defined(MOZ_NSIXULCHROMEREGISTRY_SELECTSKIN) || defined(HAVE_CHROME_NSICHROMEREGISTRYSEA_H) -static nsresult -getUILang (nsAString& aUILang) -{ - nsresult rv; - - nsCOMPtr<nsILocaleService> localeService = do_GetService (NS_LOCALESERVICE_CONTRACTID); - if (!localeService) - { - g_warning ("Could not get locale service!\n"); - return NS_ERROR_FAILURE; - } - - rv = localeService->GetLocaleComponentForUserAgent (aUILang); - - if (NS_FAILED (rv)) - { - g_warning ("Could not determine locale!\n"); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} -#endif - -static void -mozilla_init_observer (MozillaEmbedSingle *single) -{ - EphySingle *es; - - es = new EphySingle (); - NS_ADDREF (single->priv->mSingleObserver = es); - - nsresult rv; - rv = es->Init (EPHY_EMBED_SINGLE (single)); - if (NS_FAILED (rv)) - { - g_warning ("Failed to initialise EphySingle!\n"); - return; - } -} - -static void -mozilla_init_login_manager (MozillaEmbedSingle *single) -{ -#ifdef HAVE_GECKO_1_9 - nsCOMPtr<nsILoginManager> loginManager = - do_GetService (NS_LOGINMANAGER_CONTRACTID); - if (!loginManager) - g_warning ("Failed to instantiate LoginManager"); - else - g_debug ("LoginManager tapped"); -#endif /* HAVE_GECKO_1_9 */ -} - -static void -user_css_register (MozillaEmbedSingle *single) -{ - MozillaEmbedSinglePrivate *priv = single->priv; - - nsresult rv; - nsCOMPtr<nsILocalFile> file; - rv = NS_NewNativeLocalFile (nsDependentCString (priv->user_css_file), - PR_TRUE, getter_AddRefs (file)); - NS_ENSURE_SUCCESS (rv, ); - - PRBool exists = PR_FALSE; - rv = file->Exists (&exists); - if (NS_FAILED (rv) || !exists) return; - - nsCOMPtr<nsIURI> uri; - rv = EphyUtils::NewFileURI (getter_AddRefs (uri), file); - NS_ENSURE_SUCCESS (rv, ); - - nsCOMPtr<nsIStyleSheetService> service - (do_GetService ("@mozilla.org/content/style-sheet-service;1", &rv)); - NS_ENSURE_SUCCESS (rv, ); - - PRBool isRegistered = PR_FALSE; - rv = service->SheetRegistered (uri, nsIStyleSheetService::USER_SHEET, - &isRegistered); - if (NS_SUCCEEDED (rv) && isRegistered) - { - rv = service->UnregisterSheet (uri, nsIStyleSheetService::USER_SHEET); - } - - rv = service->LoadAndRegisterSheet (uri, nsIStyleSheetService::AGENT_SHEET); - if (NS_FAILED (rv)) - { - g_warning ("Registering the user stylesheet failed (rv=%x)!\n", rv); - } -} - -static void -user_css_unregister (MozillaEmbedSingle *single) -{ - MozillaEmbedSinglePrivate *priv = single->priv; - - nsresult rv; - nsCOMPtr<nsILocalFile> file; - rv = NS_NewNativeLocalFile (nsDependentCString (priv->user_css_file), - PR_TRUE, getter_AddRefs (file)); - NS_ENSURE_SUCCESS (rv, ); - - nsCOMPtr<nsIURI> uri; - rv = EphyUtils::NewFileURI (getter_AddRefs (uri), file); - NS_ENSURE_SUCCESS (rv, ); - - nsCOMPtr<nsIStyleSheetService> service - (do_GetService ("@mozilla.org/content/style-sheet-service;1", &rv)); - NS_ENSURE_SUCCESS (rv, ); - - PRBool isRegistered = PR_FALSE; - rv = service->SheetRegistered (uri, nsIStyleSheetService::USER_SHEET, - &isRegistered); - if (NS_SUCCEEDED (rv) && isRegistered) - { - rv = service->UnregisterSheet (uri, nsIStyleSheetService::USER_SHEET); - } - if (NS_FAILED (rv)) - { - g_warning ("Unregistering the user stylesheet failed (rv=%x)!\n", rv); - } -} - -static void -user_css_file_monitor_changed_cb (GFileMonitor *file_monitor, - GFile *file, - GFile *other_file, - gint event_type, - MozillaEmbedSingle *single) -{ - LOG ("Reregistering the user style sheet"); - - if (event_type == G_FILE_MONITOR_EVENT_DELETED) - { - user_css_unregister (single); - } - else - { - user_css_register (single); - } -} - -static void -user_css_enabled_notify (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - MozillaEmbedSingle *single) -{ - MozillaEmbedSinglePrivate *priv = single->priv; - guint enabled; - - enabled = eel_gconf_get_boolean (CONF_USER_CSS_ENABLED) != FALSE; - if (priv->user_css_enabled == enabled) return; - - LOG ("User stylesheet enabled: %s", enabled ? "t" : "f"); - - priv->user_css_enabled = enabled; - - if (enabled) - { - GFile *file; - - user_css_register (single); - - file = g_file_new_for_path (priv->user_css_file); - - g_assert (priv->user_css_file_monitor == NULL); - priv->user_css_file_monitor = - g_file_monitor_file (file, - G_FILE_MONITOR_NONE, - NULL, NULL); - g_file_monitor_set_rate_limit (priv->user_css_file_monitor, - USER_CSS_LOAD_DELAY); - g_signal_connect (priv->user_css_file_monitor, "changed", - G_CALLBACK (user_css_file_monitor_changed_cb), - single); - g_object_unref (file); - } - else - { - if (priv->user_css_file_monitor != NULL) - { - g_file_monitor_cancel (priv->user_css_file_monitor); - priv->user_css_file_monitor = NULL; - } - - user_css_unregister (single); - } -} - -static void -mozilla_stylesheet_init (MozillaEmbedSingle *single) -{ - MozillaEmbedSinglePrivate *priv = single->priv; - - priv->user_css_file = g_build_filename (ephy_dot_dir (), - USER_STYLESHEET_FILENAME, - (char *) NULL); - - user_css_enabled_notify (NULL, 0, NULL, single); - priv->user_css_enabled_notifier_id = - eel_gconf_notification_add - (CONF_USER_CSS_ENABLED, - (GConfClientNotifyFunc) user_css_enabled_notify, - single); -} - -static void -mozilla_stylesheet_shutdown (MozillaEmbedSingle *single) -{ - MozillaEmbedSinglePrivate *priv = single->priv; - - if (priv->user_css_enabled_notifier_id != 0) - { - eel_gconf_notification_remove (priv->user_css_enabled_notifier_id); - priv->user_css_enabled_notifier_id = 0; - } - - if (priv->user_css_file_monitor != NULL) - { - g_file_monitor_cancel (priv->user_css_file_monitor); - priv->user_css_file_monitor = NULL; - } - - if (priv->user_css_file != NULL) - { - g_free (priv->user_css_file); - priv->user_css_file = NULL; - } -} - -static gboolean -impl_init (EphyEmbedSingle *esingle) -{ - MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (esingle); - - g_setenv ("MOZILLA_POSTSCRIPT_ENABLED", "1", TRUE); - g_unsetenv ("MOZILLA_POSTSCRIPT_PRINTER_LIST"); - -#ifdef MOZ_ENABLE_XPRINT - /* XPrint? No, thanks! */ - g_unsetenv ("XPSERVERLIST"); -#endif - -#ifdef HAVE_GECKO_1_9 - NS_LogInit (); -#endif - - nsresult rv; -#ifdef XPCOM_GLUE - static const GREVersionRange greVersion = { - "1.9a", PR_TRUE, - "2", PR_TRUE - }; - char xpcomLocation[4096]; - rv = GRE_GetGREPathWithProperties(&greVersion, 1, nsnull, 0, xpcomLocation, 4096); - if (NS_FAILED (rv)) - { - g_warning ("Could not find a suitable GRE!\n"); - return FALSE; - } - - // Startup the XPCOM Glue that links us up with XPCOM. - rv = XPCOMGlueStartup(xpcomLocation); - if (NS_FAILED (rv)) - { - g_warning ("Could not startup XPCOM glue!\n"); - return FALSE; - } - - rv = GTKEmbedGlueStartup(); - if (NS_FAILED (rv)) - { - g_warning ("Could not startup embed glue!\n"); - return FALSE; - } - - rv = GTKEmbedGlueStartupInternal(); - if (NS_FAILED (rv)) - { - g_warning ("Could not startup internal glue!\n"); - return FALSE; - } - - char *lastSlash = strrchr(xpcomLocation, '/'); - if (lastSlash) - *lastSlash = '\0'; - - gtk_moz_embed_set_path(xpcomLocation); - gtk_moz_embed_set_comp_path (SHARE_DIR); -#else -#ifdef HAVE_GECKO_1_9 - gtk_moz_embed_set_path (MOZILLA_HOME); - gtk_moz_embed_set_comp_path (SHARE_DIR); -#else - gtk_moz_embed_set_comp_path (MOZILLA_HOME); -#endif -#endif // XPCOM_GLUE - - /* Pre initialization */ - mozilla_init_plugin_path (); - - mozilla_init_profile (); - -#ifndef HAVE_GECKO_1_9 - nsCOMPtr<nsIDirectoryServiceProvider> dp = new EphyDirectoryProvider (); - if (!dp) return FALSE; - - gtk_moz_embed_set_directory_service_provider (dp); -#endif - - /* Fire up the beast */ - gtk_moz_embed_push_startup (); - - /* FIXME check that it succeeded! */ - - mozilla_register_components (); - - mozilla_init_single (single); - - if (!mozilla_set_default_prefs (single)) - { - return FALSE; - } - - START_PROFILER ("Mozilla prefs notifiers") - mozilla_notifiers_init (); - STOP_PROFILER ("Mozilla prefs notifiers") - - mozilla_init_observer (single); - - mozilla_stylesheet_init (single); - - mozilla_init_login_manager (single); - - return TRUE; -} - -static void -prepare_close_cb (EphyEmbedShell *shell) -{ - GValue value = { 0, }; - - /* To avoid evil web sites posing an alert and thus inhibiting - * shutdown, we just turn off javascript! :) - */ - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, FALSE); - mozilla_pref_set ("javascript.enabled", &value); - g_value_unset (&value); -} - -static void -mozilla_embed_single_init (MozillaEmbedSingle *mes) -{ - mes->priv = MOZILLA_EMBED_SINGLE_GET_PRIVATE (mes); - - mes->priv->user_prefs = - g_build_filename (ephy_dot_dir (), - MOZILLA_PROFILE_DIR, - MOZILLA_PROFILE_NAME, - MOZILLA_PROFILE_FILE, - (char *) NULL); - - g_signal_connect_object (embed_shell, "prepare-close", - G_CALLBACK (prepare_close_cb), mes, - (GConnectFlags) 0); -} - -static void -mozilla_embed_single_dispose (GObject *object) -{ - MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (object); - MozillaEmbedSinglePrivate *priv = single->priv; - - mozilla_stylesheet_shutdown (single); - - if (priv->mSingleObserver) - { - priv->mSingleObserver->Detach (); - NS_RELEASE (priv->mSingleObserver); - priv->mSingleObserver = nsnull; - } - - G_OBJECT_CLASS (mozilla_embed_single_parent_class)->dispose (object); -} - -static void -mozilla_embed_single_finalize (GObject *object) -{ - MozillaEmbedSingle *mes = MOZILLA_EMBED_SINGLE (object); - - /* Destroy EphyEmbedSingle before because some - * services depend on xpcom */ - G_OBJECT_CLASS (mozilla_embed_single_parent_class)->finalize (object); - - mozilla_notifiers_shutdown (); - - gtk_moz_embed_pop_startup (); - -#ifdef HAVE_GECKO_1_9 - NS_LogTerm (); -#endif - - g_free (mes->priv->user_prefs); -} - -static void -impl_clear_cache (EphyEmbedSingle *shell) -{ - nsCOMPtr<nsICacheService> cacheService = - do_GetService (NS_CACHESERVICE_CONTRACTID); - if (!cacheService) return; - - cacheService->EvictEntries (nsICache::STORE_ANYWHERE); -} - -static void -impl_clear_auth_cache (EphyEmbedSingle *shell) -{ - nsCOMPtr<nsIHttpAuthManager> authManager = - do_GetService (NS_HTTPAUTHMANAGER_CONTRACTID); - if (!authManager) return; - - authManager->ClearAll(); -} - -static void -impl_set_network_status (EphyEmbedSingle *single, - gboolean online) -{ - nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID); - if (!io) return; - - io->SetOffline (!online); -} - -static gboolean -impl_get_network_status (EphyEmbedSingle *esingle) -{ - MozillaEmbedSingle *single = MOZILLA_EMBED_SINGLE (esingle); - MozillaEmbedSinglePrivate *priv = single->priv; - - NS_ENSURE_TRUE (priv->mSingleObserver, TRUE); - - nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID); - if (!io) return FALSE; /* no way to check the state, assume offline */ - - PRBool isOffline; - nsresult rv; - rv = io->GetOffline(&isOffline); - NS_ENSURE_SUCCESS (rv, FALSE); - - PRBool isOnline = !isOffline; - PRBool reallyOnline = priv->mSingleObserver->IsOnline (); - - g_return_val_if_fail (reallyOnline == isOnline, TRUE); - - return !isOffline; -} - -static const char* -impl_get_backend_name (EphyEmbedSingle *esingle) -{ - /* If you alter the return values here, remember to update - * the docs in ephy-embed-single.c */ -#if defined (HAVE_GECKO_1_10) -# error "Need to add version string for gecko 1.10" -#elif defined(HAVE_GECKO_1_9) - return "gecko-1.9"; -#elif defined(HAVE_GECKO_1_8) - return "gecko-1.8"; -#else -# error "Undefined/unsupported gecko version!" -#endif -} - -static GList * -impl_get_font_list (EphyEmbedSingle *shell, - const char *langGroup) -{ - nsresult rv; - PRUint32 fontCount; - PRUnichar **fontArray; - GList *l = NULL; - - nsCOMPtr<nsIFontEnumerator> mozFontEnumerator; - mozFontEnumerator = do_CreateInstance("@mozilla.org/gfx/fontenumerator;1"); - NS_ENSURE_TRUE (mozFontEnumerator, NULL); - - rv = mozFontEnumerator->EnumerateFonts (langGroup, nsnull, - &fontCount, &fontArray); - NS_ENSURE_SUCCESS (rv, NULL); - - for (PRUint32 i = 0; i < fontCount; i++) - { - char *gFontString; - - nsCString tmp; - NS_UTF16ToCString (nsString(fontArray[i]), - NS_CSTRING_ENCODING_UTF8, tmp); - gFontString = g_strdup (tmp.get()); - l = g_list_prepend (l, gFontString); - nsMemory::Free (fontArray[i]); - } - - nsMemory::Free (fontArray); - - return g_list_reverse (l); -} - -static GList * -impl_list_cookies (EphyCookieManager *manager) -{ - nsresult rv; - GList *cookies = NULL; - - nsCOMPtr<nsICookieManager> cookieManager = - do_GetService (NS_COOKIEMANAGER_CONTRACTID); - if (!cookieManager) return NULL; - - nsCOMPtr<nsISimpleEnumerator> cookieEnumerator; - cookieManager->GetEnumerator (getter_AddRefs(cookieEnumerator)); - NS_ENSURE_TRUE (cookieEnumerator, NULL); - - PRBool enumResult; - for (cookieEnumerator->HasMoreElements(&enumResult) ; - enumResult == PR_TRUE ; - cookieEnumerator->HasMoreElements(&enumResult)) - { - nsCOMPtr<nsICookie> keks; - rv = cookieEnumerator->GetNext (getter_AddRefs(keks)); - if (NS_FAILED (rv) || !keks) continue; - - EphyCookie *cookie = mozilla_cookie_to_ephy_cookie (keks); - if (!cookie) continue; - - cookies = g_list_prepend (cookies, cookie); - } - - return cookies; -} - -static void -impl_remove_cookie (EphyCookieManager *manager, - const EphyCookie *cookie) -{ - nsCOMPtr<nsICookieManager> cookieManager = - do_GetService (NS_COOKIEMANAGER_CONTRACTID); - if (!cookieManager) return; - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, ); - - nsresult rv; - nsCString host; - rv = idnService->ConvertUTF8toACE (nsCString(cookie->domain), host); - NS_ENSURE_SUCCESS (rv, ); - - cookieManager->Remove (host, - nsCString(cookie->name), - nsCString(cookie->path), - PR_FALSE /* block */); -} - -static void -impl_clear_cookies (EphyCookieManager *manager) -{ - nsCOMPtr<nsICookieManager> cookieManager = - do_GetService (NS_COOKIEMANAGER_CONTRACTID); - if (!cookieManager) return; - - cookieManager->RemoveAll (); -} - -static GList * -impl_list_passwords (EphyPasswordManager *manager) -{ - GList *passwords = NULL; - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, NULL); - -#ifdef HAVE_GECKO_1_9 - nsILoginInfo **logins = nsnull; - PRUint32 count,i; - nsresult rv; - - nsCOMPtr<nsILoginManager> loginManager = - do_GetService (NS_LOGINMANAGER_CONTRACTID); - NS_ENSURE_TRUE (loginManager, NULL); - - loginManager -> GetAllLogins(&count, &logins); - - for (i=0; i < count; i++) { - nsString transfer; - nsString unicodeName; - rv = logins[i]->GetHostname (transfer); - if (NS_FAILED (rv)) continue; - - nsCString host; - idnService->ConvertACEtoUTF8 (NS_ConvertUTF16toUTF8(transfer), host); - if(transfer.IsVoid()) host.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetHttpRealm (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString httpRealm; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, httpRealm); - if(unicodeName.IsVoid()) httpRealm.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetUsername (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString userName; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, userName); - if(unicodeName.IsVoid()) userName.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetUsernameField (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString usernameField; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, usernameField); - if(unicodeName.IsVoid()) usernameField.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetPassword (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString userPassword; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, userPassword); - if(unicodeName.IsVoid()) userPassword.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetPasswordField (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString passwordField; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, passwordField); - if(unicodeName.IsVoid()) passwordField.SetIsVoid(PR_TRUE); - - rv = logins[i]->GetFormSubmitURL (unicodeName); - if (NS_FAILED (rv)) continue; - nsCString formSubmitURL; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, formSubmitURL); - if(unicodeName.IsVoid()) formSubmitURL.SetIsVoid(PR_TRUE); - - - EphyPasswordInfo *p = g_new0 (EphyPasswordInfo, 1); - p->host = !userName.IsVoid() ? g_strdup (host.get()) : nsnull; - p->username = !userName.IsVoid() ? g_strdup (userName.get()) : nsnull; - p->password = !userPassword.IsVoid() ? g_strdup (userPassword.get()) : nsnull; - p->httpRealm = !httpRealm.IsVoid() ? g_strdup(httpRealm.get()) : nsnull; - p->usernameField = !usernameField.IsVoid() ? g_strdup(usernameField.get()) : nsnull; - p->passwordField = !passwordField.IsVoid() ? g_strdup(passwordField.get()) : nsnull; - p->formSubmitURL = !formSubmitURL.IsVoid() ? g_strdup(formSubmitURL.get()) : nsnull; - - passwords = g_list_prepend (passwords, p); - } - - NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY (count, logins); - -#else // HAVE_GECKO_1_9 - - nsresult rv; - nsCOMPtr<nsIPasswordManager> passwordManager = - do_GetService (NS_PASSWORDMANAGER_CONTRACTID); - if (!passwordManager) return NULL; - - nsCOMPtr<nsISimpleEnumerator> passwordEnumerator; - passwordManager->GetEnumerator (getter_AddRefs(passwordEnumerator)); - NS_ENSURE_TRUE (passwordEnumerator, NULL); - - PRBool enumResult; - for (passwordEnumerator->HasMoreElements(&enumResult) ; - enumResult == PR_TRUE ; - passwordEnumerator->HasMoreElements(&enumResult)) - { - nsCOMPtr<nsIPassword> nsPassword; - passwordEnumerator->GetNext (getter_AddRefs(nsPassword)); - if (!nsPassword) continue; - - nsCString transfer; - rv = nsPassword->GetHost (transfer); - if (NS_FAILED (rv)) continue; - - nsCString host; - idnService->ConvertACEtoUTF8 (transfer, host); - - nsString unicodeName; - rv = nsPassword->GetUser (unicodeName); - if (NS_FAILED (rv)) continue; - - nsCString userName; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, userName); - - rv = nsPassword->GetPassword (unicodeName); - if (NS_FAILED (rv)) continue; - - nsCString userPassword; - NS_UTF16ToCString (unicodeName, - NS_CSTRING_ENCODING_UTF8, userPassword); - - EphyPasswordInfo *p = g_new0 (EphyPasswordInfo, 1); - - p->host = g_strdup (host.get()); - p->username = g_strdup (userName.get()); - p->password = g_strdup (userPassword.get()); - - passwords = g_list_prepend (passwords, p); - } -#endif /* !HAVE_GECKO_1_9 */ - - return passwords; -} - -static void -impl_remove_password (EphyPasswordManager *manager, - EphyPasswordInfo *info) -{ - nsresult rv; - nsString host; - nsString userName; - nsString userNameField; - nsString password; - nsString passwordField; - nsString httpRealm; - nsString formSubmitURL; - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, ); - - if(info->formSubmitURL != nsnull) - g_debug("form submit url: %s", info->formSubmitURL); - else - g_debug("form submit url is NULL"); - - NS_CStringToUTF16 (nsCString(info->username), - NS_CSTRING_ENCODING_UTF8, userName); - NS_CStringToUTF16 (nsCString(info->usernameField), - NS_CSTRING_ENCODING_UTF8, userNameField); - NS_CStringToUTF16 (nsCString(info->host), - NS_CSTRING_ENCODING_UTF8, host); - NS_CStringToUTF16 (nsCString(info->httpRealm), - NS_CSTRING_ENCODING_UTF8, httpRealm); - NS_CStringToUTF16 (nsCString(info->password), - NS_CSTRING_ENCODING_UTF8, password); - NS_CStringToUTF16 (nsCString(info->passwordField), - NS_CSTRING_ENCODING_UTF8, passwordField); - NS_CStringToUTF16 (nsCString(info->formSubmitURL), - NS_CSTRING_ENCODING_UTF8, formSubmitURL); - -#ifdef HAVE_GECKO_1_9 - if(!info->username) userName.SetIsVoid(PR_TRUE); - if(!info->usernameField) userNameField.SetIsVoid(PR_TRUE); - if(!info->host) host.SetIsVoid(PR_TRUE); - if(!info->httpRealm) httpRealm.SetIsVoid(PR_TRUE); - if(!info->password) password.SetIsVoid(PR_TRUE); - if(!info->passwordField) passwordField.SetIsVoid(PR_TRUE); - if(!info->formSubmitURL) formSubmitURL.SetIsVoid(PR_TRUE); - - nsCOMPtr<nsILoginManager> loginManager = - do_GetService (NS_LOGINMANAGER_CONTRACTID); - NS_ENSURE_TRUE (loginManager, ); - - nsCOMPtr<nsILoginInfo> login - (do_CreateInstance(NS_LOGININFO_CONTRACTID)); - - login->SetUsername(userName); - login->SetUsernameField(userNameField); - login->SetHostname(host); - login->SetHttpRealm(httpRealm); - login->SetFormSubmitURL(formSubmitURL); - login->SetPassword(password); - login->SetPasswordField(passwordField); - - rv = loginManager->RemoveLogin(login); - -#else /* !HAVE_GECKO_1_9 */ - nsCOMPtr<nsIPasswordManager> pm = - do_GetService (NS_PASSWORDMANAGER_CONTRACTID); - if (!pm) return; - - pm->RemoveUser (nsCString(info->host), userName); -#endif /* HAVE_GECKO_1_9 */ -} - -static void -impl_remove_all_passwords (EphyPasswordManager *manager) -{ -#ifdef HAVE_GECKO_1_9 - nsCOMPtr<nsILoginManager> loginManager = - do_GetService (NS_LOGINMANAGER_CONTRACTID); - NS_ENSURE_TRUE (loginManager, ); - - loginManager->RemoveAllLogins(); - -#else /* HAVE_GECKO_1_9 */ - nsresult rv; - nsCOMPtr<nsIPasswordManager> passwordManager = - do_GetService (NS_PASSWORDMANAGER_CONTRACTID); - if (!passwordManager) return; - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, ); - - nsCOMPtr<nsISimpleEnumerator> passwordEnumerator; - passwordManager->GetEnumerator (getter_AddRefs(passwordEnumerator)); - NS_ENSURE_TRUE (passwordEnumerator, ); - - PRBool enumResult; - for (passwordEnumerator->HasMoreElements(&enumResult) ; - enumResult == PR_TRUE ; - passwordEnumerator->HasMoreElements(&enumResult)) - { - nsCOMPtr<nsIPassword> nsPassword; - passwordEnumerator->GetNext (getter_AddRefs(nsPassword)); - if (!nsPassword) continue; - - nsCString host; - rv = nsPassword->GetHost (host); - if (NS_FAILED (rv)) continue; - - nsString userName; - rv = nsPassword->GetUser (userName); - if (NS_FAILED (rv)) continue; - - passwordManager->RemoveUser (host, userName); - } -#endif /* !HAVE_GECKO_1_9 */ -} - -static void -impl_add_password (EphyPasswordManager *manager, - EphyPasswordInfo *info) -{ -#ifndef HAVE_GECKO_1_9 - nsCOMPtr<nsIPasswordManager> pm = - do_GetService (NS_PASSWORDMANAGER_CONTRACTID); - if (!pm) return; - - nsCOMPtr<nsIIDNService> idnService - (do_GetService ("@mozilla.org/network/idn-service;1")); - NS_ENSURE_TRUE (idnService, ); - - nsresult rv; - nsCString host; - rv = idnService->ConvertUTF8toACE (nsCString(info->host), host); - NS_ENSURE_SUCCESS (rv, ); - - nsString username; - NS_CStringToUTF16 (nsCString(info->username), - NS_CSTRING_ENCODING_UTF8, username); - - nsString password; - NS_CStringToUTF16 (nsCString(info->password), - NS_CSTRING_ENCODING_UTF8, password); - - pm->AddUser(host, username, password); -#endif /* !HAVE_GECKO_1_9 */ -} - -static void -impl_permission_manager_add (EphyPermissionManager *manager, - const char *host, - const char *type, - EphyPermission permission) -{ - /* can only set allow or deny */ - g_return_if_fail (permission != EPHY_PERMISSION_DEFAULT); - g_return_if_fail (type != NULL && type[0] != '\0'); - - nsCOMPtr<nsIPermissionManager> pm - (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); - if (!pm) return; - - nsCOMPtr<nsIURI> uri; - EphyUtils::NewURI(getter_AddRefs(uri), nsCString(host)); - if (!uri) return; - - gboolean allow = (permission == EPHY_PERMISSION_ALLOWED); - - pm->Add (uri, type, - allow ? (PRUint32) nsIPermissionManager::ALLOW_ACTION : - (PRUint32) nsIPermissionManager::DENY_ACTION); -} - -static void -impl_permission_manager_remove (EphyPermissionManager *manager, - const char *host, - const char *type) -{ - nsCOMPtr<nsIPermissionManager> pm - (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); - if (!pm) return; - - pm->Remove (nsCString (host), type); -} - -static void -impl_permission_manager_clear (EphyPermissionManager *manager) -{ - nsCOMPtr<nsIPermissionManager> pm - (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); - if (!pm) return; - - pm->RemoveAll (); -} - -EphyPermission -impl_permission_manager_test (EphyPermissionManager *manager, - const char *host, - const char *type) -{ - g_return_val_if_fail (type != NULL && type[0] != '\0', EPHY_PERMISSION_DEFAULT); - - nsCOMPtr<nsIPermissionManager> pm - (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); - if (!pm) return EPHY_PERMISSION_DEFAULT; - - nsCOMPtr<nsIURI> uri; - EphyUtils::NewURI(getter_AddRefs(uri), nsCString (host)); - if (!uri) return EPHY_PERMISSION_DEFAULT; - - nsresult rv; - PRUint32 action; - rv = pm->TestPermission (uri, type, &action); - NS_ENSURE_SUCCESS (rv, EPHY_PERMISSION_DEFAULT); - - EphyPermission permission; - - switch (action) - { - case nsIPermissionManager::ALLOW_ACTION: - permission = EPHY_PERMISSION_ALLOWED; - break; - case nsIPermissionManager::DENY_ACTION: - permission = EPHY_PERMISSION_DENIED; - break; - case nsIPermissionManager::UNKNOWN_ACTION: - default: - permission = EPHY_PERMISSION_DEFAULT; - break; - } - - return permission; -} - -GList * -impl_permission_manager_list (EphyPermissionManager *manager, - const char *type) -{ - GList *list = NULL; - - nsCOMPtr<nsIPermissionManager> pm - (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); - if (!pm) return NULL; - - nsCOMPtr<nsISimpleEnumerator> pe; - pm->GetEnumerator(getter_AddRefs(pe)); - NS_ENSURE_TRUE (pe, NULL); - - PRBool hasMore; - while (NS_SUCCEEDED (pe->HasMoreElements (&hasMore)) && hasMore) - { - nsCOMPtr<nsISupports> element; - pe->GetNext (getter_AddRefs (element)); - - nsCOMPtr<nsIPermission> perm (do_QueryInterface (element)); - if (!perm) continue; - - nsresult rv; - nsCString str; - rv = perm->GetType(str); - if (NS_FAILED (rv)) continue; - - if (strcmp (str.get(), type) == 0) - { - EphyPermissionInfo *info = - mozilla_permission_to_ephy_permission (perm); - - if (info != NULL) - { - list = g_list_prepend (list, info); - } - } - } - - return list; -} - -static GtkWidget * -impl_open_window (EphyEmbedSingle *single, - EphyEmbed *parent, - const char *address, - const char *name, - const char *features) -{ - nsresult rv; - AutoJSContextStack stack; - rv = stack.Init (); - if (NS_FAILED (rv)) return NULL; - - nsCOMPtr<nsIDOMWindow> domWindow; - if (parent) - { - EphyBrowser *browser; - - browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(parent)); - g_return_val_if_fail (browser != NULL, NULL); - - browser->GetDOMWindow (getter_AddRefs (domWindow)); - } - - nsCOMPtr<nsIWindowWatcher> wWatch(do_GetService ("@mozilla.org/embedcomp/window-watcher;1")); - nsCOMPtr<nsIDOMWindow> newWindow; - wWatch->OpenWindow (domWindow, address, name, features, nsnull, - getter_AddRefs (newWindow)); - - return EphyUtils::FindEmbed (newWindow); -} - -static void -mozilla_embed_single_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EphyEmbedSingle *single = EPHY_EMBED_SINGLE (object); - - switch (prop_id) - { - case PROP_NETWORK_STATUS: - g_value_set_boolean (value, ephy_embed_single_get_network_status (single)); - break; - } -} - -static void -mozilla_embed_single_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EphyEmbedSingle *single = EPHY_EMBED_SINGLE (object); - - switch (prop_id) - { - case PROP_NETWORK_STATUS: - ephy_embed_single_set_network_status (single, g_value_get_boolean (value)); - break; - } -} -static void -mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = mozilla_embed_single_dispose; - object_class->finalize = mozilla_embed_single_finalize; - object_class->get_property = mozilla_embed_single_get_property; - object_class->set_property = mozilla_embed_single_set_property; - - g_object_class_override_property (object_class, PROP_NETWORK_STATUS, "network-status"); - - g_type_class_add_private (object_class, sizeof (MozillaEmbedSinglePrivate)); -} - -static void -ephy_embed_single_iface_init (EphyEmbedSingleIface *iface) -{ - iface->init = impl_init; - iface->clear_cache = impl_clear_cache; - iface->clear_auth_cache = impl_clear_auth_cache; - iface->set_network_status = impl_set_network_status; - iface->get_network_status = impl_get_network_status; - iface->get_font_list = impl_get_font_list; - iface->open_window = impl_open_window; - iface->get_backend_name = impl_get_backend_name; -} - -static void -ephy_cookie_manager_iface_init (EphyCookieManagerIface *iface) -{ - iface->list = impl_list_cookies; - iface->remove = impl_remove_cookie; - iface->clear = impl_clear_cookies; -} - -static void -ephy_password_manager_iface_init (EphyPasswordManagerIface *iface) -{ - iface->add = impl_add_password; - iface->remove = impl_remove_password; - iface->remove_all = impl_remove_all_passwords; - iface->list = impl_list_passwords; -} - -static void -ephy_permission_manager_iface_init (EphyPermissionManagerIface *iface) -{ - iface->add = impl_permission_manager_add; - iface->remove = impl_permission_manager_remove; - iface->clear = impl_permission_manager_clear; - iface->test = impl_permission_manager_test; - iface->list = impl_permission_manager_list; -} diff --git a/embed/mozilla/mozilla-embed-single.h b/embed/mozilla/mozilla-embed-single.h deleted file mode 100644 index 960b6eb5b..000000000 --- a/embed/mozilla/mozilla-embed-single.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright © 2000-2003 Marco Pesenti Gritti - * Copyright © 2003 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_EMBED_SINGLE_H -#define MOZILLA_EMBED_SINGLE_H - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_EMBED_SINGLE (mozilla_embed_single_get_type ()) -#define MOZILLA_EMBED_SINGLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_EMBED_SINGLE, MozillaEmbedSingle)) -#define MOZILLA_EMBED_SINGLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_EMBED_SINGLE, MozillaEmbedSingleClass)) -#define MOZILLA_IS_EMBED_SINGLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_EMBED_SINGLE)) -#define MOZILLA_IS_EMBED_SINGLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_EMBED_SINGLE)) -#define MOZILLA_EMBED_SINGLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_EMBED_SINGLE, MozillaEmbedSingleClass)) - -typedef struct MozillaEmbedSingle MozillaEmbedSingle; -typedef struct MozillaEmbedSingleClass MozillaEmbedSingleClass; -typedef struct MozillaEmbedSinglePrivate MozillaEmbedSinglePrivate; - -struct MozillaEmbedSingle -{ - GObject parent; - - /*< private >*/ - MozillaEmbedSinglePrivate *priv; -}; - -struct MozillaEmbedSingleClass -{ - GObjectClass parent_class; -}; - -GType mozilla_embed_single_get_type (void); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp deleted file mode 100644 index dfa3c23a1..000000000 --- a/embed/mozilla/mozilla-embed.cpp +++ /dev/null @@ -1,1530 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "mozilla-config.h" -#include "config.h" - -#include <nsStringAPI.h> - -#include <gtkmozembed.h> -#include <nsIDOMKeyEvent.h> -#include <nsIDOMMouseEvent.h> -#include <nsIRequest.h> -#include <nsIURI.h> -#include <nsIWebNavigation.h> -#include <nsIWebProgressListener.h> -#include <nsMemory.h> - -#include <glib/gi18n.h> - -#include "EphyBrowser.h" -#include "EphyUtils.h" -#include "EventContext.h" - -#include "ephy-command-manager.h" -#include "ephy-debug.h" -#include "mozilla-embed.h" -#include "ephy-embed-container.h" -#include "ephy-embed-shell.h" -#include "ephy-embed-single.h" -#include "mozilla-embed-event.h" -#include "mozilla-history-item.h" - -static void mozilla_embed_class_init (MozillaEmbedClass *klass); -static void mozilla_embed_init (MozillaEmbed *gs); -static void mozilla_embed_destroy (GtkObject *object); -static void mozilla_embed_finalize (GObject *object); -static void ephy_embed_iface_init (EphyEmbedIface *iface); - -static void mozilla_embed_location_changed_cb (GtkMozEmbed *embed, - MozillaEmbed *membed); -static void mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, - const char *aURI, - gint state, - guint status, - MozillaEmbed *membed); -static gboolean mozilla_embed_dom_mouse_click_cb(GtkMozEmbed *embed, - gpointer dom_event, - MozillaEmbed *membed); -static gboolean mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, - gpointer dom_event, - MozillaEmbed *membed); -static gboolean mozilla_embed_dom_key_press_cb (GtkMozEmbed *embed, - gpointer dom_event, - MozillaEmbed *membed); -static void mozilla_embed_new_window_cb (GtkMozEmbed *embed, - GtkMozEmbed **newEmbed, - guint chrome_mask, - MozillaEmbed *membed); -static void mozilla_embed_security_change_cb (GtkMozEmbed *embed, - gpointer request, - PRUint32 state, - MozillaEmbed *membed); -static void mozilla_embed_title_change_cb (GtkMozEmbed *embed, - MozillaEmbed *membed); -static void mozilla_embed_link_message_cb (GtkMozEmbed *embed, - MozillaEmbed *membed); -static void mozilla_embed_visibility_cb (GtkMozEmbed *embed, - gboolean visibility, - MozillaEmbed *membed); -static gboolean mozilla_embed_open_uri_cb (GtkMozEmbed *embed, - const char *uri, - MozillaEmbed *membed); -static void mozilla_embed_size_to_cb (GtkMozEmbed *embed, - int width, - int height, - MozillaEmbed *membed); - -static EphyEmbedSecurityLevel mozilla_embed_security_level (PRUint32 state); - -#define MOZILLA_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_EMBED, MozillaEmbedPrivate)) - -typedef enum -{ - MOZILLA_EMBED_LOAD_STARTED, - MOZILLA_EMBED_LOAD_REDIRECTING, - MOZILLA_EMBED_LOAD_LOADING, - MOZILLA_EMBED_LOAD_STOPPED -} MozillaEmbedLoadState; - -struct MozillaEmbedPrivate -{ - EphyBrowser *browser; - GtkMozEmbed *moz_embed; - MozillaEmbedLoadState load_state; - - guint idle_resize_handler; -}; - -#define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" - -static void -impl_manager_do_command (EphyCommandManager *manager, - const char *command) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(manager)->priv; - - mpriv->browser->DoCommand (command); -} - -static gboolean -impl_manager_can_do_command (EphyCommandManager *manager, - const char *command) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(manager)->priv; - nsresult rv; - PRBool enabled; - - rv = mpriv->browser->GetCommandState (command, &enabled); - - return NS_SUCCEEDED (rv) ? enabled : FALSE; -} - -static void -ephy_command_manager_iface_init (EphyCommandManagerIface *iface) -{ - iface->do_command = impl_manager_do_command; - iface->can_do_command = impl_manager_can_do_command; -} - -G_DEFINE_TYPE_WITH_CODE (MozillaEmbed, mozilla_embed, EPHY_TYPE_BASE_EMBED, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_EMBED, - ephy_embed_iface_init) - G_IMPLEMENT_INTERFACE (EPHY_TYPE_COMMAND_MANAGER, - ephy_command_manager_iface_init)) - -static void -impl_close (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (embed)->priv; - - mpriv->browser->Close (); -} - -static void -mozilla_embed_realize (GtkWidget *widget) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (widget)->priv; - - GTK_WIDGET_CLASS (mozilla_embed_parent_class)->realize (widget); - - gtk_widget_realize (GTK_WIDGET (mpriv->moz_embed)); - /* Initialise our helper class */ - nsresult rv; - rv = mpriv->browser->Init (EPHY_EMBED (widget)); - if (NS_FAILED (rv)) - { - g_warning ("EphyBrowser initialization failed for %p\n", widget); - return; - } -} - -static GObject * -mozilla_embed_constructor (GType type, guint n_construct_properties, - GObjectConstructParam *construct_params) -{ - g_object_ref (embed_shell); - - /* we depend on single because of mozilla initialization */ - ephy_embed_shell_get_embed_single (embed_shell); - - return G_OBJECT_CLASS (mozilla_embed_parent_class)->constructor (type, n_construct_properties, - construct_params); -} - -static void -mozilla_embed_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkWidget *child; - GtkAllocation invalid = { -1, -1, 1, 1 }; - - widget->allocation = *allocation; - - child = GTK_BIN (widget)->child; - g_return_if_fail (child != NULL); - - /* only resize if we're mapped (bug #128191), - * or if this is the initial size-allocate (bug #156854). - */ - if (GTK_WIDGET_MAPPED (child) || - memcmp (&child->allocation, &invalid, sizeof (GtkAllocation)) == 0) - { - gtk_widget_size_allocate (child, allocation); - } -} - -static void -mozilla_embed_grab_focus (GtkWidget *widget) -{ - GtkWidget *child; - - /* What we want to focus here is the MozContainer inside the - * GtkMozEmbed, because the GtkMozEmbed itself does not gain focus. - */ - child = gtk_bin_get_child (GTK_BIN (MOZILLA_EMBED (widget)->priv->moz_embed)); - - if (child && GTK_WIDGET_REALIZED (child)) - gtk_widget_grab_focus (child); - else - g_warning ("Need to realize the embed before grabbing focus!\n"); -} - -static void -mozilla_embed_dispose (GObject *object) -{ - MozillaEmbedPrivate *priv = MOZILLA_EMBED (object)->priv; - - if (priv->idle_resize_handler != 0) - { - g_source_remove (priv->idle_resize_handler); - priv->idle_resize_handler = 0; - } - - G_OBJECT_CLASS (mozilla_embed_parent_class)->dispose (object); -} - -static void -mozilla_embed_class_init (MozillaEmbedClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->constructor = mozilla_embed_constructor; - object_class->finalize = mozilla_embed_finalize; - object_class->dispose = mozilla_embed_dispose; - - gtk_object_class->destroy = mozilla_embed_destroy; - - widget_class->realize = mozilla_embed_realize; - widget_class->size_allocate = mozilla_embed_size_allocate; - widget_class->grab_focus = mozilla_embed_grab_focus; - - g_type_class_add_private (object_class, sizeof(MozillaEmbedPrivate)); -} - -static void -mozilla_embed_init (MozillaEmbed *membed) -{ - MozillaEmbedPrivate *priv; - GtkWidget *embed; - - membed->priv = MOZILLA_EMBED_GET_PRIVATE (membed); - priv = membed->priv; - - embed = gtk_moz_embed_new (); - priv->moz_embed = GTK_MOZ_EMBED (embed); - gtk_container_add (GTK_CONTAINER (membed), embed); - gtk_widget_show (embed); - - priv->browser = new EphyBrowser (); - - g_signal_connect_object (embed, "location", - G_CALLBACK (mozilla_embed_location_changed_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "net_state_all", - G_CALLBACK (mozilla_embed_net_state_all_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "dom_mouse_click", - G_CALLBACK (mozilla_embed_dom_mouse_click_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "dom_mouse_down", - G_CALLBACK (mozilla_embed_dom_mouse_down_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "dom-key-press", - G_CALLBACK (mozilla_embed_dom_key_press_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "new_window", - G_CALLBACK (mozilla_embed_new_window_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "security_change", - G_CALLBACK (mozilla_embed_security_change_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "title", - G_CALLBACK (mozilla_embed_title_change_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "link_message", - G_CALLBACK (mozilla_embed_link_message_cb), - membed, (GConnectFlags)0); - g_signal_connect_object (embed, "open_uri", - G_CALLBACK (mozilla_embed_open_uri_cb), - membed,(GConnectFlags) 0); - g_signal_connect_object (embed, "visibility", - G_CALLBACK (mozilla_embed_visibility_cb), - membed, (GConnectFlags) 0); - g_signal_connect_object (embed, "size_to", - G_CALLBACK (mozilla_embed_size_to_cb), - membed, (GConnectFlags) 0); -} - -gpointer -_mozilla_embed_get_ephy_browser (MozillaEmbed *embed) -{ - g_return_val_if_fail (embed->priv->browser != NULL, NULL); - - return embed->priv->browser; -} - -static void -mozilla_embed_destroy (GtkObject *object) -{ - MozillaEmbed *embed = MOZILLA_EMBED (object); - - if (embed->priv->browser) - { - embed->priv->browser->Destroy(); - } - - GTK_OBJECT_CLASS (mozilla_embed_parent_class)->destroy (object); -} - -static void -mozilla_embed_finalize (GObject *object) -{ - MozillaEmbed *embed = MOZILLA_EMBED (object); - - if (embed->priv->browser) - { - delete embed->priv->browser; - embed->priv->browser = nsnull; - } - - G_OBJECT_CLASS (mozilla_embed_parent_class)->finalize (object); - - g_object_unref (embed_shell); -} - -static void -impl_load_url (EphyEmbed *embed, - const char *url) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - gtk_moz_embed_load_url (moz_embed, url); -} - -static char * impl_get_location (EphyEmbed *embed, gboolean toplevel); - -static void -impl_load (EphyEmbed *embed, - const char *url, - EphyEmbedLoadFlags flags, - EphyEmbed *preview_embed) -{ - EphyBrowser *browser; - - browser = MOZILLA_EMBED(embed)->priv->browser; - g_return_if_fail (browser != NULL); - - nsCOMPtr<nsIURI> uri; - if (preview_embed != NULL) - { - EphyBrowser *pbrowser; - - pbrowser = MOZILLA_EMBED(preview_embed)->priv->browser; - if (pbrowser != NULL) - { - pbrowser->GetDocumentURI (getter_AddRefs (uri)); - } - } - -#ifdef HAVE_GECKO_1_8_1 - if (flags & EPHY_EMBED_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) - { - browser->LoadURI (url, nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, uri); - } - else -#endif /* HAVE_GECKO_1_8_1 */ - { - browser->LoadURI (url, nsIWebNavigation::LOAD_FLAGS_NONE, uri); - } -} - -static void -impl_stop_load (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - gtk_moz_embed_stop_load (moz_embed); -} - -static gboolean -impl_can_go_back (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - return gtk_moz_embed_can_go_back (moz_embed); -} - -static gboolean -impl_can_go_forward (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - return gtk_moz_embed_can_go_forward (moz_embed); -} - -static gboolean -mozilla_embed_get_uri_parent (MozillaEmbed *membed, - const char *aUri, - nsCString &aParent) -{ - nsresult rv; - nsCString encoding; - rv = membed->priv->browser->GetEncoding (encoding); - if (NS_FAILED (rv)) return FALSE; - - /* Check for HTML anchors */ - nsCOMPtr<nsIURI> uri; - const char *anchor = strrchr (aUri, '#'); - if (anchor) - { - aParent.Assign (aUri); - aParent.SetLength (anchor - aUri); - - return TRUE; - } - - rv = EphyUtils::NewURI (getter_AddRefs(uri), nsCString(aUri), encoding.get()); - if (NS_FAILED(rv) || !uri) return FALSE; - - /* Don't support going 'up' with chrome url's, mozilla handily - * fixes them up for us, so it doesn't work properly, see - * rdf/chrome/src/nsChromeProtocolHandler.cpp::NewURI() - * (the Canonify() call) - */ - nsCString scheme; - rv = uri->GetScheme (scheme); - if (NS_FAILED(rv) || !scheme.Length()) return FALSE; - if (strcmp (scheme.get(), "chrome") == 0) return FALSE; - - nsCString path; - rv = uri->GetPath(path); - if (NS_FAILED(rv) || !path.Length()) return FALSE; - if (strcmp (path.get (), "/") == 0) return FALSE; - - const char *slash = strrchr (path.BeginReading(), '/'); - if (!slash) return FALSE; - - if (slash[1] == '\0') - { - /* ends with a slash - a directory, go to parent */ - rv = uri->Resolve (nsCString(".."), aParent); - } - else - { - /* it's a file, go to the directory */ - rv = uri->Resolve (nsCString("."), aParent); - } - - return NS_SUCCEEDED (rv); -} - -static gboolean -impl_can_go_up (EphyEmbed *embed) -{ - MozillaEmbed *membed = MOZILLA_EMBED (embed); - char *address; - gboolean result; - - address = ephy_embed_get_location (embed, TRUE); - if (address == NULL) return FALSE; - - nsCString parent; - result = mozilla_embed_get_uri_parent (membed, address, parent); - g_free (address); - - return result; -} - -static GSList * -impl_get_go_up_list (EphyEmbed *embed) -{ - MozillaEmbed *membed = MOZILLA_EMBED (embed); - GSList *l = NULL; - char *address, *s; - - address = ephy_embed_get_location (embed, TRUE); - if (address == NULL) return NULL; - - s = address; - nsCString parent; - while (mozilla_embed_get_uri_parent (membed, s, parent)) - { - s = g_strdup (parent.get()); - l = g_slist_prepend (l, s); - } - - g_free (address); - - return g_slist_reverse (l); -} - -static void -impl_go_back (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - gtk_moz_embed_go_back (moz_embed); -} - -static void -impl_go_forward (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - gtk_moz_embed_go_forward (moz_embed); -} - -static void -impl_go_up (EphyEmbed *embed) -{ - MozillaEmbed *membed = MOZILLA_EMBED (embed); - char *uri; - - uri = ephy_embed_get_location (embed, TRUE); - if (uri == NULL) return; - - gboolean rv; - nsCString parent_uri; - rv = mozilla_embed_get_uri_parent (membed, uri, parent_uri); - g_free (uri); - - g_return_if_fail (rv != FALSE); - - ephy_embed_load_url (embed, parent_uri.get ()); -} - -static char * -impl_get_js_status (EphyEmbed *embed) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - return gtk_moz_embed_get_js_status (moz_embed); -} - -static char * -impl_get_location (EphyEmbed *embed, - gboolean toplevel) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - - nsCOMPtr<nsIURI> uri; - if (toplevel) - { - rv = mpriv->browser->GetDocumentURI (getter_AddRefs (uri)); - } - else - { - rv = mpriv->browser->GetTargetDocumentURI (getter_AddRefs (uri)); - } - - if (NS_FAILED (rv)) return NULL; - - nsCOMPtr<nsIURI> furi; - rv = uri->Clone (getter_AddRefs (furi)); - /* Some nsIURI impls return NS_OK even though they didn't put anything in the outparam!! */ - if (NS_FAILED (rv) || !furi) furi.swap(uri); - - /* Hide password part */ - nsCString user; - furi->GetUsername (user); - furi->SetUserPass (user); - - nsCString url; - furi->GetSpec (url); - - return url.Length() ? g_strdup (url.get()) : NULL; -} - -static void -impl_reload (EphyEmbed *embed, - gboolean force) -{ - GtkMozEmbed *moz_embed = MOZILLA_EMBED (embed)->priv->moz_embed; - guint32 mflags = GTK_MOZ_EMBED_FLAG_RELOADNORMAL; - - if (force) - { - mflags = GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE; - } - - gtk_moz_embed_reload (moz_embed, mflags); -} - -static void -impl_set_zoom (EphyEmbed *embed, - float zoom) -{ - EphyBrowser *browser; - nsresult rv; - - g_return_if_fail (zoom > 0.0); - - browser = MOZILLA_EMBED(embed)->priv->browser; - g_return_if_fail (browser != NULL); - - rv = browser->SetZoom (zoom); - - if (NS_SUCCEEDED (rv)) - { - g_signal_emit_by_name (embed, "ge_zoom_change", zoom); - } -} - -static float -impl_get_zoom (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - float f; - - nsresult rv; - rv = mpriv->browser->GetZoom (&f); - - if (NS_SUCCEEDED (rv)) - { - return f; - } - - return 1.0; -} - -static void -impl_scroll_lines (EphyEmbed *embed, - int num_lines) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->ScrollLines (num_lines); -} - -static void -impl_scroll_pages (EphyEmbed *embed, - int num_pages) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->ScrollPages (num_pages); -} - -static void -impl_scroll_pixels (EphyEmbed *embed, - int dx, - int dy) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->ScrollPixels (dx, dy); -} - -static int -impl_shistory_n_items (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - int count, index; - - rv = mpriv->browser->GetSHInfo (&count, &index); - - return NS_SUCCEEDED(rv) ? count : 0; -} - -static int -impl_shistory_get_pos (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - int count, index; - - rv = mpriv->browser->GetSHInfo (&count, &index); - - return NS_SUCCEEDED(rv) ? index : 0; -} - -static void -impl_shistory_copy (EphyEmbed *source, - EphyEmbed *dest, - gboolean copy_back, - gboolean copy_forward, - gboolean copy_current) -{ - MozillaEmbedPrivate *spriv = MOZILLA_EMBED(source)->priv; - MozillaEmbedPrivate *dpriv = MOZILLA_EMBED(dest)->priv; - - spriv->browser->CopySHistory(dpriv->browser, copy_back, - copy_forward, copy_current); -} - -static void -impl_get_security_level (EphyEmbed *embed, - EphyEmbedSecurityLevel *level, - char **description) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (embed)->priv; - - if (level) *level = EPHY_EMBED_STATE_IS_UNKNOWN; - if (description) *description = NULL; - - nsresult rv; - PRUint32 state; - nsCString desc; - rv = mpriv->browser->GetSecurityInfo (&state, desc); - if (NS_FAILED (rv)) return; - - if (level) *level = mozilla_embed_security_level (state); - if (description) *description = g_strdup (desc.get()); -} - -static void -impl_show_page_certificate (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED (embed)->priv; - - mpriv->browser->ShowCertificate (); -} - -static void -impl_print (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->Print (); -} - -static void -impl_set_print_preview_mode (EphyEmbed *embed, gboolean preview_mode) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->SetPrintPreviewMode (preview_mode); -} - -static int -impl_print_preview_n_pages (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - int num; - - rv = mpriv->browser->PrintPreviewNumPages(&num); - - return NS_SUCCEEDED (rv) ? num : 0; -} - -static void -impl_print_preview_navigate (EphyEmbed *embed, - EphyEmbedPrintPreviewNavType type, - int page) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - - mpriv->browser->PrintPreviewNavigate(type, page); -} - -static void -impl_set_encoding (EphyEmbed *embed, - const char *encoding) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - nsCString currEnc; - - g_return_if_fail (encoding != NULL); - - rv = mpriv->browser->GetEncoding (currEnc); - if (NS_FAILED (rv)) return; - - if (strcmp (currEnc.get(), encoding) != 0 || - encoding[0] == '\0' && !ephy_embed_has_automatic_encoding (embed)) - { - rv = mpriv->browser->ForceEncoding (encoding); - if (NS_FAILED (rv)) return; - } - - gtk_moz_embed_reload (mpriv->moz_embed, - GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE); -} - -static char * -impl_get_encoding (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - nsCString encoding; - - rv = mpriv->browser->GetEncoding (encoding); - - if (NS_FAILED (rv) || !encoding.Length()) - { - return NULL; - } - - return g_strdup (encoding.get()); -} - -static gboolean -impl_has_automatic_encoding (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - nsCString encoding; - - rv = mpriv->browser->GetForcedEncoding (encoding); - - if (NS_FAILED (rv) || !encoding.Length()) - { - return TRUE; - } - - return FALSE; -} - -static gboolean -impl_has_modified_forms (EphyEmbed *embed) -{ - MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult rv; - - PRBool modified; - rv = mpriv->browser->GetHasModifiedForms (&modified); - - return NS_SUCCEEDED (rv) ? modified : FALSE; -} - -static EphyHistoryItem* -mozilla_get_nth_history_item (MozillaEmbed *embed, - gboolean is_relative, - int nth) -{ - EphyHistoryItem *item = NULL; - - if (is_relative) - { - nth += impl_shistory_get_pos (EPHY_EMBED (embed)); - } - - if (nth >= 0 && nth <= impl_shistory_n_items (EPHY_EMBED (embed))) - { - item = (EphyHistoryItem*)mozilla_history_item_new (embed, nth); - } - - return item; -} - -static GList* -mozilla_construct_history_list (MozillaEmbed *embed, int start, int end) -{ - GList *list = NULL; - EphyHistoryItem *item; - - while (start != end) - { - item = mozilla_get_nth_history_item (embed, FALSE, start); - list = g_list_prepend (list, item); - - if (start < end) - start++; - else - start--; - } - - return g_list_reverse (list); -} - -static GList* -impl_get_backward_history (EphyEmbed *embed) -{ - MozillaEmbed *membed = MOZILLA_EMBED (embed); - int start = impl_shistory_get_pos (embed) + -1; - - return mozilla_construct_history_list (membed, start, -1); -} - -static GList* -impl_get_forward_history (EphyEmbed *embed) -{ - MozillaEmbed *membed = MOZILLA_EMBED (embed); - int start = impl_shistory_get_pos (embed) + 1; - int end = impl_shistory_n_items (embed); - - return mozilla_construct_history_list (membed, start, end); -} - -static EphyHistoryItem* -impl_get_next_history_item (EphyEmbed *embed) -{ - return mozilla_get_nth_history_item (MOZILLA_EMBED (embed), - TRUE, - +1); -} - -static EphyHistoryItem* -impl_get_previous_history_item (EphyEmbed *embed) -{ - return mozilla_get_nth_history_item (MOZILLA_EMBED (embed), - TRUE, - -1); -} - -static void -impl_go_to_history_item (EphyEmbed *embed, EphyHistoryItem *item) -{ - MozillaHistoryItem *mitem = MOZILLA_HISTORY_ITEM (item); - - MOZILLA_EMBED (embed)->priv->browser->GoToHistoryIndex (mitem->nth); -} - -static void -mozilla_embed_location_changed_cb (GtkMozEmbed *embed, - MozillaEmbed *membed) -{ - char *location; - EphyBaseEmbed *bembed = EPHY_BASE_EMBED (membed); - - location = gtk_moz_embed_get_location (embed); - - ephy_base_embed_location_changed (bembed, location); - - g_free (location); -} - -static void -mozilla_embed_link_message_cb (GtkMozEmbed *embed, - MozillaEmbed *membed) -{ - char *link_message = gtk_moz_embed_get_link_message (embed); - ephy_base_embed_set_link_message (EPHY_BASE_EMBED (membed), link_message); - g_free (link_message); -} - -static void -update_load_state (MozillaEmbed *membed, gint state) -{ - MozillaEmbedPrivate *priv = membed->priv; - GtkMozEmbed *moz_embed = priv->moz_embed; - - if (state & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT && - state & (GTK_MOZ_EMBED_FLAG_START | GTK_MOZ_EMBED_FLAG_STOP)) - { - g_signal_emit_by_name (membed, "ge-document-type", - priv->browser->GetDocumentType ()); - } - - if (state & GTK_MOZ_EMBED_FLAG_RESTORING && - priv->load_state == MOZILLA_EMBED_LOAD_STARTED) - { - priv->load_state = MOZILLA_EMBED_LOAD_LOADING; - - char *address; - address = gtk_moz_embed_get_location (moz_embed); - g_signal_emit_by_name (membed, "new-document-now", address); - ephy_base_embed_popups_manager_reset (EPHY_BASE_EMBED (membed)); - ephy_base_embed_restore_zoom_level (EPHY_BASE_EMBED (membed), address); - g_free (address); - } - - if (state & GTK_MOZ_EMBED_FLAG_IS_NETWORK) - { - if (state & GTK_MOZ_EMBED_FLAG_START) - { - priv->load_state = MOZILLA_EMBED_LOAD_STARTED; - } - else if (state & GTK_MOZ_EMBED_FLAG_STOP) - { - priv->load_state = MOZILLA_EMBED_LOAD_STOPPED; - } - } - else if (state & GTK_MOZ_EMBED_FLAG_START && - state & GTK_MOZ_EMBED_FLAG_IS_REQUEST) - { - if (priv->load_state == MOZILLA_EMBED_LOAD_REDIRECTING) - { - priv->load_state = MOZILLA_EMBED_LOAD_STARTED; - } - else if (priv->load_state != MOZILLA_EMBED_LOAD_LOADING) - { - priv->load_state = MOZILLA_EMBED_LOAD_LOADING; - - char *address; - address = gtk_moz_embed_get_location (moz_embed); - ephy_base_embed_popups_manager_reset (EPHY_BASE_EMBED (membed)); - ephy_base_embed_restore_zoom_level (EPHY_BASE_EMBED (membed), address); - g_free (address); - } - } - else if (state & GTK_MOZ_EMBED_FLAG_REDIRECTING && - priv->load_state == MOZILLA_EMBED_LOAD_STARTED) - { - priv->load_state = MOZILLA_EMBED_LOAD_REDIRECTING; - } -} - -static void -mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, const char *aURI, - gint state, guint status, - MozillaEmbed *membed) -{ - EphyEmbedNetState estate = EPHY_EMBED_STATE_UNKNOWN; - int i; - - struct - { - guint state; - EphyEmbedNetState embed_state; - } - conversion_map [] = - { - { GTK_MOZ_EMBED_FLAG_START, EPHY_EMBED_STATE_START }, - { GTK_MOZ_EMBED_FLAG_STOP, EPHY_EMBED_STATE_STOP }, - { GTK_MOZ_EMBED_FLAG_REDIRECTING, EPHY_EMBED_STATE_REDIRECTING }, - { GTK_MOZ_EMBED_FLAG_TRANSFERRING, EPHY_EMBED_STATE_TRANSFERRING }, - { GTK_MOZ_EMBED_FLAG_NEGOTIATING, EPHY_EMBED_STATE_NEGOTIATING }, - { GTK_MOZ_EMBED_FLAG_IS_REQUEST, EPHY_EMBED_STATE_IS_REQUEST }, - { GTK_MOZ_EMBED_FLAG_IS_DOCUMENT, EPHY_EMBED_STATE_IS_DOCUMENT }, - { GTK_MOZ_EMBED_FLAG_IS_NETWORK, EPHY_EMBED_STATE_IS_NETWORK }, - { GTK_MOZ_EMBED_FLAG_RESTORING, EPHY_EMBED_STATE_RESTORING }, - { 0, EPHY_EMBED_STATE_UNKNOWN } - }; - - for (i = 0; conversion_map[i].state != 0; i++) - { - if (state & conversion_map[i].state) - { - estate = (EphyEmbedNetState) (estate | conversion_map[i].embed_state); - } - } - - update_load_state (membed, state); - ephy_base_embed_update_from_net_state (EPHY_BASE_EMBED (membed), aURI, (EphyEmbedNetState)estate); -} - -static gboolean -mozilla_embed_emit_mouse_signal (MozillaEmbed *embed, - gpointer dom_event, - const char *signal_name) -{ - MozillaEmbedPrivate *mpriv = embed->priv; - MozillaEmbedEvent *info; - EventContext event_context; - gint return_value = FALSE; - nsresult rv; - - if (dom_event == NULL) return FALSE; - - nsCOMPtr<nsIDOMMouseEvent> ev = static_cast<nsIDOMMouseEvent*>(dom_event); - NS_ENSURE_TRUE (ev, FALSE); - nsCOMPtr<nsIDOMEvent> dev = do_QueryInterface (ev); - NS_ENSURE_TRUE (dev, FALSE); - - info = mozilla_embed_event_new (static_cast<gpointer>(dev)); - - event_context.Init (mpriv->browser); - rv = event_context.GetMouseEventInfo (ev, MOZILLA_EMBED_EVENT (info)); - if (NS_FAILED (rv)) - { - g_object_unref (info); - return FALSE; - } - - nsCOMPtr<nsIDOMDocument> domDoc; - rv = event_context.GetTargetDocument (getter_AddRefs(domDoc)); - if (NS_SUCCEEDED (rv)) - { - mpriv->browser->PushTargetDocument (domDoc); - - g_signal_emit_by_name (embed, signal_name, - info, &return_value); - mpriv->browser->PopTargetDocument (); - } - - g_object_unref (info); - - return return_value; -} - -static gboolean -mozilla_embed_dom_mouse_click_cb (GtkMozEmbed *embed, - gpointer dom_event, - MozillaEmbed *membed) -{ - return mozilla_embed_emit_mouse_signal (membed, dom_event, - "ge_dom_mouse_click"); -} - -static gboolean -mozilla_embed_dom_mouse_down_cb (GtkMozEmbed *embed, gpointer dom_event, - MozillaEmbed *membed) -{ - return mozilla_embed_emit_mouse_signal (membed, dom_event, - "ge_dom_mouse_down"); -} - -static gint -mozilla_embed_dom_key_press_cb (GtkMozEmbed *embed, - gpointer dom_event, - MozillaEmbed *membed) -{ - gint retval = FALSE; - - if (dom_event == NULL) return FALSE; - - nsCOMPtr<nsIDOMKeyEvent> ev = static_cast<nsIDOMKeyEvent*>(dom_event); - NS_ENSURE_TRUE (ev, FALSE); - - if (!EventContext::CheckKeyPress (ev)) return FALSE; - - GdkEvent *event = gtk_get_current_event (); - if (event == NULL) return FALSE; /* shouldn't happen! */ - - g_return_val_if_fail (GDK_KEY_PRESS == event->type, FALSE); - - g_signal_emit_by_name (EPHY_EMBED (membed), - "ge-search-key-press", event, &retval); - - gdk_event_free (event); - - return retval; -} - -EphyEmbedChrome -_mozilla_embed_translate_chrome (GtkMozEmbedChromeFlags flags) -{ - static const struct - { - guint mozilla_flag; - guint ephy_flag; - } - conversion_map [] = - { - { GTK_MOZ_EMBED_FLAG_MENUBARON, EPHY_EMBED_CHROME_MENUBAR }, - { GTK_MOZ_EMBED_FLAG_TOOLBARON, EPHY_EMBED_CHROME_TOOLBAR }, - { GTK_MOZ_EMBED_FLAG_STATUSBARON, EPHY_EMBED_CHROME_STATUSBAR }, - { GTK_MOZ_EMBED_FLAG_PERSONALTOOLBARON, EPHY_EMBED_CHROME_BOOKMARKSBAR }, - }; - - guint mask = 0, i; - - for (i = 0; i < G_N_ELEMENTS (conversion_map); i++) - { - if (flags & conversion_map[i].mozilla_flag) - { - mask |= conversion_map[i].ephy_flag; - } - } - - return (EphyEmbedChrome) mask; -} - -static void -mozilla_embed_new_window_cb (GtkMozEmbed *embed, - GtkMozEmbed **newEmbed, - guint chrome_mask, - MozillaEmbed *membed) -{ - GtkMozEmbedChromeFlags chrome = (GtkMozEmbedChromeFlags) chrome_mask; - EphyEmbed *new_embed = NULL; - GObject *single; - EphyEmbedChrome mask; - - if (chrome & GTK_MOZ_EMBED_FLAG_OPENASCHROME) - { - *newEmbed = _mozilla_embed_new_xul_dialog (); - return; - } - - mask = _mozilla_embed_translate_chrome (chrome); - - single = ephy_embed_shell_get_embed_single (embed_shell); - g_signal_emit_by_name (single, "new-window", embed, mask, - &new_embed); - - g_assert (new_embed != NULL); - - gtk_moz_embed_set_chrome_mask (embed, chrome); - - g_signal_emit_by_name (membed, "ge-new-window", new_embed); - - *newEmbed = GTK_MOZ_EMBED (gtk_bin_get_child (GTK_BIN (new_embed))); -} - -static void -mozilla_embed_security_change_cb (GtkMozEmbed *embed, - gpointer requestptr, - PRUint32 state, - MozillaEmbed *membed) -{ - ephy_base_embed_set_security_level (EPHY_BASE_EMBED (membed), - mozilla_embed_security_level (state)); -} - -static void -mozilla_embed_title_change_cb (GtkMozEmbed *embed, - MozillaEmbed *membed) -{ - GObject *object = G_OBJECT (embed); - char *title; - - title = gtk_moz_embed_get_title (embed); - - g_object_freeze_notify (object); - - ephy_base_embed_set_title (EPHY_BASE_EMBED (membed), title); - ephy_base_embed_set_loading_title (EPHY_BASE_EMBED (membed), - title, FALSE); - - g_free (title); - - g_object_thaw_notify (object); -} - -static gboolean -mozilla_embed_open_uri_cb (GtkMozEmbed *embed, - const char *uri, - MozillaEmbed *membed) -{ - /* Set the address here if we have a blank page. - * See bug #147840. - */ - if (ephy_embed_get_is_blank (EPHY_EMBED (membed))) - { - EphyBaseEmbed *bembed = EPHY_BASE_EMBED (membed); - - - ephy_base_embed_set_address (bembed, uri); - ephy_base_embed_set_loading_title (bembed, uri, TRUE); - } - - /* allow load to proceed */ - return FALSE; -} - -static void -mozilla_embed_visibility_cb (GtkMozEmbed *embed, - gboolean visibility, - MozillaEmbed *membed) -{ - ephy_base_embed_set_visibility (EPHY_BASE_EMBED (membed), visibility); -} - -static gboolean -let_me_resize_hack (MozillaEmbed *embed) -{ - GtkWidget *window; - MozillaEmbedPrivate *priv = embed->priv; - - window = gtk_widget_get_toplevel (GTK_WIDGET (embed)); - - if (window && GTK_WIDGET_TOPLEVEL (window)) - gtk_window_set_resizable (GTK_WINDOW (window), TRUE); - - priv->idle_resize_handler = 0; - - return FALSE; -} - -static void -ephy_tab_set_size (MozillaEmbed *embed, - int width, - int height) -{ - MozillaEmbedPrivate *priv = embed->priv; - GtkWidget *widget = GTK_WIDGET (embed); - GtkAllocation allocation; - - gtk_widget_set_size_request (widget, width, height); - - /* HACK: When the web site changes both width and height, - * we will first get a width change, then a height change, - * without actually resizing the window in between (since - * that happens only on idle). - * If we don't set the allocation, GtkMozEmbed doesn't tell - * mozilla the new width, so the height change sets the width - * back to the old value! - */ - allocation.x = widget->allocation.x; - allocation.y = widget->allocation.y; - allocation.width = width; - allocation.height = height; - gtk_widget_size_allocate (widget, &allocation); - - /* HACK: reset widget requisition after the container - * has been resized. It appears to be the only way - * to have the window sized according to embed - * size correctly. - */ - if (priv->idle_resize_handler == 0) - { - priv->idle_resize_handler = - g_idle_add ((GSourceFunc) let_me_resize_hack, embed); - } -} - -static void -mozilla_embed_size_to_cb (GtkMozEmbed *embed, - int width, - int height, - MozillaEmbed *membed) -{ - GtkWidget *widget; - EphyEmbedContainer *container; - MozillaEmbedPrivate *priv = MOZILLA_EMBED (membed)->priv; - GtkWidget *embed_widget = GTK_WIDGET (membed); - GdkScreen *screen; - GdkRectangle rect; - int monitor; - int ww, wh, ew, eh, dw, dh; - - container = EPHY_EMBED_CONTAINER (gtk_widget_get_toplevel (GTK_WIDGET (embed))); - if (! container || !GTK_WIDGET_TOPLEVEL (container)) - return; - - /* FIXME: allow sizing also for non-popup single-tab windows? */ - if (EPHY_EMBED (membed) != ephy_embed_container_get_active_child (container) || - ! ephy_embed_container_get_is_popup (container)) - return; - - widget = GTK_WIDGET (container); - - LOG ("mozilla_embed_size_to_cb window %p embed %p width %d height %d", widget, embed, width, height); - - /* contrain size so that the window will be fully contained within the screen */ - screen = gtk_widget_get_screen (widget); - monitor = gdk_screen_get_monitor_at_window (screen, widget->window); - gdk_screen_get_monitor_geometry (screen, monitor, &rect); - /* FIXME: get and subtract the panel size */ - - gtk_window_get_size (GTK_WINDOW (widget), &ww, &wh); - - ew = embed_widget->allocation.width; - eh = embed_widget->allocation.height; - - /* This should approximate the chrome extent */ - dw = ww - ew; dw = MAX (dw, 0); dw = MIN (dw, rect.width - 1); - dh = wh - eh; dh = MAX (dh, 0); dh = MIN (dh, rect.height - 1); - - width = MIN (rect.width - dw, width); - height = MIN (rect.height - dh, height); - - /* FIXME: move window if this will place it partially outside the screen rect? */ - - gtk_window_set_resizable (GTK_WINDOW (widget), FALSE); - ephy_tab_set_size (membed, width, height); - - if (priv->idle_resize_handler == 0) - { - priv->idle_resize_handler = - g_idle_add ((GSourceFunc) let_me_resize_hack, membed); - } -} - -static EphyEmbedSecurityLevel -mozilla_embed_security_level (PRUint32 state) -{ - EphyEmbedSecurityLevel level; - - switch (state) - { - case nsIWebProgressListener::STATE_IS_INSECURE: - level = EPHY_EMBED_STATE_IS_INSECURE; - break; - case nsIWebProgressListener::STATE_IS_BROKEN: - level = EPHY_EMBED_STATE_IS_BROKEN; - break; - case nsIWebProgressListener::STATE_IS_SECURE| - nsIWebProgressListener::STATE_SECURE_HIGH: - level = EPHY_EMBED_STATE_IS_SECURE_HIGH; - break; - case nsIWebProgressListener::STATE_IS_SECURE| - nsIWebProgressListener::STATE_SECURE_MED: - level = EPHY_EMBED_STATE_IS_SECURE_MED; - break; - case nsIWebProgressListener::STATE_IS_SECURE| - nsIWebProgressListener::STATE_SECURE_LOW: - level = EPHY_EMBED_STATE_IS_SECURE_LOW; - break; - default: - level = EPHY_EMBED_STATE_IS_UNKNOWN; - break; - } - return level; -} - -static void -ephy_embed_iface_init (EphyEmbedIface *iface) -{ - iface->load_url = impl_load_url; - iface->load = impl_load; - iface->stop_load = impl_stop_load; - iface->can_go_back = impl_can_go_back; - iface->can_go_forward =impl_can_go_forward; - iface->can_go_up = impl_can_go_up; - iface->get_go_up_list = impl_get_go_up_list; - iface->go_back = impl_go_back; - iface->go_forward = impl_go_forward; - iface->go_up = impl_go_up; - iface->get_location = impl_get_location; - iface->get_js_status = impl_get_js_status; - iface->reload = impl_reload; - iface->set_zoom = impl_set_zoom; - iface->get_zoom = impl_get_zoom; - iface->scroll_lines = impl_scroll_lines; - iface->scroll_pages = impl_scroll_pages; - iface->scroll_pixels = impl_scroll_pixels; - iface->shistory_copy = impl_shistory_copy; - iface->show_page_certificate = impl_show_page_certificate; - iface->close = impl_close; - iface->set_encoding = impl_set_encoding; - iface->get_encoding = impl_get_encoding; - iface->has_automatic_encoding = impl_has_automatic_encoding; - iface->print = impl_print; - iface->set_print_preview_mode = impl_set_print_preview_mode; - iface->print_preview_n_pages = impl_print_preview_n_pages; - iface->print_preview_navigate = impl_print_preview_navigate; - iface->has_modified_forms = impl_has_modified_forms; - iface->get_security_level = impl_get_security_level; - iface->get_backward_history = impl_get_backward_history; - iface->get_forward_history = impl_get_forward_history; - iface->get_next_history_item = impl_get_next_history_item; - iface->get_previous_history_item = impl_get_previous_history_item; - iface->go_to_history_item = impl_go_to_history_item; -} - -static void -xul_visibility_cb (GtkWidget *embed, gboolean visibility, GtkWidget *window) -{ - if (visibility) - { - gtk_widget_show (window); - } - else - { - gtk_widget_hide (window); - } -} - -static void -xul_size_to_cb (GtkWidget *embed, gint width, gint height, gpointer dummy) -{ - gtk_widget_set_size_request (embed, width, height); -} - -static void -xul_new_window_cb (GtkMozEmbed *embed, - GtkMozEmbed **retval, - guint chrome_mask, - gpointer dummy) -{ - g_assert (chrome_mask & GTK_MOZ_EMBED_FLAG_OPENASCHROME); - - *retval = _mozilla_embed_new_xul_dialog (); -} - -static void -xul_title_cb (GtkMozEmbed *embed, - GtkWindow *window) -{ - char *title; - - title = gtk_moz_embed_get_title (embed); - gtk_window_set_title (window, title); - g_free (title); -} - -GtkMozEmbed * -_mozilla_embed_new_xul_dialog (void) -{ - GtkWidget *window, *embed; - - g_object_ref (embed_shell); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_object_set_data_full (G_OBJECT (window), "EmbedShellRef", - embed_shell, - (GDestroyNotify) g_object_unref); - g_signal_connect_object (embed_shell, "prepare_close", - G_CALLBACK (gtk_widget_destroy), window, - (GConnectFlags) G_CONNECT_SWAPPED); - - embed = gtk_moz_embed_new (); - gtk_widget_show (embed); - gtk_container_add (GTK_CONTAINER (window), embed); - - g_signal_connect_object (embed, "destroy_browser", - G_CALLBACK (gtk_widget_destroy), - window, G_CONNECT_SWAPPED); - g_signal_connect_object (embed, "visibility", - G_CALLBACK (xul_visibility_cb), - window, (GConnectFlags) 0); - g_signal_connect_object (embed, "size_to", - G_CALLBACK (xul_size_to_cb), - NULL, (GConnectFlags) 0); - g_signal_connect_object (embed, "new_window", - G_CALLBACK (xul_new_window_cb), - NULL, (GConnectFlags) 0); - g_signal_connect_object (embed, "title", - G_CALLBACK (xul_title_cb), - window, (GConnectFlags) 0); - - return GTK_MOZ_EMBED (embed); -} - -EphyBrowser* -_mozilla_embed_get_browser (MozillaEmbed *embed) -{ - g_return_val_if_fail (MOZILLA_IS_EMBED (embed), NULL); - - return embed->priv->browser; -} diff --git a/embed/mozilla/mozilla-embed.h b/embed/mozilla/mozilla-embed.h deleted file mode 100644 index 28fcecb41..000000000 --- a/embed/mozilla/mozilla-embed.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2000-2004 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_EMBED_H -#define MOZILLA_EMBED_H - -#include <glib.h> -#include <glib-object.h> - -#include <gtkmozembed.h> - -#include "ephy-embed.h" -#include "ephy-base-embed.h" - -#ifdef __cplusplus -#include "EphyBrowser.h" -#else -/* can't include C++ headers from outside embed/mozilla */ -typedef struct _EphyBrowser EphyBrowser; -#endif - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_EMBED (mozilla_embed_get_type ()) -#define MOZILLA_EMBED(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MOZILLA_TYPE_EMBED, MozillaEmbed)) -#define MOZILLA_EMBED_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), MOZILLA_TYPE_EMBED, MozillaEmbedClass)) -#define MOZILLA_IS_EMBED(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), MOZILLA_TYPE_EMBED)) -#define MOZILLA_IS_EMBED_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), MOZILLA_TYPE_EMBED)) -#define MOZILLA_EMBED_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), MOZILLA_TYPE_EMBED, MozillaEmbedClass)) - -typedef struct MozillaEmbedClass MozillaEmbedClass; -typedef struct MozillaEmbed MozillaEmbed; -typedef struct MozillaEmbedPrivate MozillaEmbedPrivate; - -struct MozillaEmbed -{ - EphyBaseEmbed parent_instance; - - /*< private >*/ - MozillaEmbedPrivate *priv; -}; - -struct MozillaEmbedClass -{ - EphyBaseEmbedClass parent_class; -}; - -GType mozilla_embed_get_type (void); - -/* The following are private to the embed implementation */ - -gpointer _mozilla_embed_get_ephy_browser (MozillaEmbed *embed); - -GtkMozEmbed *_mozilla_embed_new_xul_dialog (void); - -EphyEmbedChrome _mozilla_embed_translate_chrome (GtkMozEmbedChromeFlags flags); - -EphyBrowser *_mozilla_embed_get_browser (MozillaEmbed *embed); - -G_END_DECLS - -#endif diff --git a/embed/mozilla/mozilla-history-item.cpp b/embed/mozilla/mozilla-history-item.cpp deleted file mode 100644 index b312fd912..000000000 --- a/embed/mozilla/mozilla-history-item.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ -/* - * Copyright © 2007 Xan Lopez - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "mozilla-config.h" -#include "config.h" - -#include "mozilla-history-item.h" -#include "ephy-history-item.h" -#include "EphyBrowser.h" - -#include <nsStringAPI.h> -#include <nsMemory.h> - -static void mozilla_history_item_finalize (GObject *object); - -static char* -impl_get_url (EphyHistoryItem *item) -{ - char *url = NULL; - nsresult rv; - nsCString nsUrl; - MozillaHistoryItem *mitem = MOZILLA_HISTORY_ITEM (item); - - if (!mitem->embed) - return NULL; - - EphyBrowser *browser = (EphyBrowser*)_mozilla_embed_get_browser (mitem->embed); - - rv = browser->GetSHUrlAtIndex(mitem->nth, nsUrl); - - if (NS_SUCCEEDED (rv) && nsUrl.Length()) { - url = g_strdup(nsUrl.get()); - } - - return url; -} - -static char* -impl_get_title (EphyHistoryItem *item) -{ - char *title = NULL; - nsresult rv; - PRUnichar *nsTitle; - - MozillaHistoryItem *mitem = MOZILLA_HISTORY_ITEM (item); - - if (!mitem->embed) - return NULL; - - EphyBrowser *browser = (EphyBrowser*)_mozilla_embed_get_browser (mitem->embed); - - rv = browser->GetSHTitleAtIndex(mitem->nth, &nsTitle); - - if (NS_SUCCEEDED (rv) && nsTitle) - { - nsCString cTitle; - NS_UTF16ToCString (nsString(nsTitle), - NS_CSTRING_ENCODING_UTF8, cTitle); - title = g_strdup (cTitle.get()); - nsMemory::Free (nsTitle); - } - - return title; -} - -static void -mozilla_history_item_iface_init (EphyHistoryItemIface *iface) -{ - iface->get_url = impl_get_url; - iface->get_title = impl_get_title; -} - -G_DEFINE_TYPE_WITH_CODE (MozillaHistoryItem, mozilla_history_item, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (EPHY_TYPE_HISTORY_ITEM, - mozilla_history_item_iface_init)) - -static void -mozilla_history_item_class_init (MozillaHistoryItemClass *klass) -{ - GObjectClass *gobject_class = (GObjectClass *)klass; - - gobject_class->finalize = mozilla_history_item_finalize; -} - -static void -mozilla_history_item_init (MozillaHistoryItem *self) -{ -} - -static void -mozilla_history_item_finalize (GObject *object) -{ - MozillaHistoryItem *item = MOZILLA_HISTORY_ITEM (object); - MozillaEmbed **ptr = &item->embed; - - g_object_remove_weak_pointer (G_OBJECT (item->embed), - (gpointer*)ptr); - - G_OBJECT_CLASS (mozilla_history_item_parent_class)->finalize (object); -} - -MozillaHistoryItem* -mozilla_history_item_new (MozillaEmbed *embed, int index) -{ - MozillaHistoryItem *item; - MozillaEmbed **ptr; - - item = (MozillaHistoryItem*) g_object_new (MOZILLA_TYPE_HISTORY_ITEM, NULL); - item->embed = embed; - ptr = &item->embed; - - g_object_add_weak_pointer (G_OBJECT (embed), (gpointer*)ptr); - item->nth = index; - - return item; -} diff --git a/embed/mozilla/mozilla-history-item.h b/embed/mozilla/mozilla-history-item.h deleted file mode 100644 index 0e26f155e..000000000 --- a/embed/mozilla/mozilla-history-item.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef __MOZILLA_HISTORY_ITEM_H__ -#define __MOZILLA_HISTORY_ITEM_H__ - -#include <glib.h> -#include <glib-object.h> - -#include "mozilla-embed.h" - -G_BEGIN_DECLS - -#define MOZILLA_TYPE_HISTORY_ITEM (mozilla_history_item_get_type()) -#define MOZILLA_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItem)) -#define MOZILLA_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItemClass)) -#define MOZILLA_IS_HISTORY_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOZILLA_TYPE_HISTORY_ITEM)) -#define MOZILLA_IS_HISTORY_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOZILLA_TYPE_HISTORY_ITEM)) -#define MOZILLA_HISTORY_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOZILLA_TYPE_HISTORY_ITEM, MozillaHistoryItemClass)) - -typedef struct _MozillaHistoryItem MozillaHistoryItem; -typedef struct _MozillaHistoryItemClass MozillaHistoryItemClass; - -struct _MozillaHistoryItemClass -{ - GObjectClass parent_class; -}; - -struct _MozillaHistoryItem -{ - GObject parent_instance; - - MozillaEmbed *embed; - int nth; -}; - -GType mozilla_history_item_get_type (void) G_GNUC_CONST; -MozillaHistoryItem *mozilla_history_item_new (MozillaEmbed *embed, int index) G_GNUC_MALLOC; - -G_END_DECLS - -#endif /* __MOZILLA_HISTORY_ITEM_H__ */ diff --git a/embed/mozilla/mozilla-notifiers.cpp b/embed/mozilla/mozilla-notifiers.cpp deleted file mode 100644 index 9901bdbe2..000000000 --- a/embed/mozilla/mozilla-notifiers.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -/* -* Copyright © 2000 Nate Case -* Copyright © 2000-2004 Marco Pesenti Gritti -* Copyright © 2003, 2004 Christian Persch -* -* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -* -* $Id$ -*/ - -#include "mozilla-config.h" -#include "config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <glib/gi18n.h> -#include <gdk/gdkx.h> -#include <gtk/gtksettings.h> - -#include <nsCOMPtr.h> -#include <nsIPrefService.h> -#include <nsIServiceManager.h> -#include <nsMemory.h> -#include <nsServiceManagerUtils.h> - -#include "eel-gconf-extensions.h" -#include "ephy-debug.h" -#include "ephy-embed-prefs.h" -#include "ephy-embed-shell.h" -#include "ephy-encodings.h" -#include "ephy-langs.h" -#include "ephy-node.h" -#include "ephy-prefs.h" - -#include "mozilla-notifiers.h" - -/* define to migrate epiphany 1.0 font preferences */ -#define MIGRATE_PIXEL_SIZE - -#define MAX_FONT_SIZE 128 - -/* Keeps the list of the notifiers we installed for mozilla prefs */ -/* to be able to remove them when exiting */ -static GList *notifiers = NULL; -static nsIPrefBranch *gPrefBranch; - -typedef struct -{ - char *gconf_key; - char *mozilla_pref; - PrefValueTransformFunc func; - gpointer user_data; - guint cnxn_id; -} PrefData; - -static void -free_pref_data (PrefData *data) -{ - g_free (data->gconf_key); - g_free (data->mozilla_pref); - - g_slice_free (PrefData, data); -} - -static gboolean -transform_accept_languages_list (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - GArray *array; - GSList *languages, *l; - char **langs; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_LIST || - gconf_value_get_list_type (gcvalue) != GCONF_VALUE_STRING) return FALSE; - - languages = gconf_value_get_list (gcvalue); - - array = g_array_new (TRUE, FALSE, sizeof (char *)); - - for (l = languages; l != NULL; l = l->next) - { - const char *lang; - - lang = gconf_value_get_string ((GConfValue *) l->data); - - if (lang != NULL && strcmp (lang, "system") == 0) - { - ephy_langs_append_languages (array); - } - else if (lang != NULL && lang[0] != '\0') - { - char *str; - str = g_ascii_strdown (lang, -1); - g_array_append_val (array, str); - } - } - - ephy_langs_sanitise (array); - - langs = (char **) g_array_free (array, FALSE); - - g_value_init (value, G_TYPE_STRING); - g_value_take_string (value, g_strjoinv (",", langs)); - - g_strfreev (langs); - - return TRUE; -} - -static gboolean -transform_cache_size (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_INT) return FALSE; - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, gconf_value_get_int (gcvalue) * 1024); - - return TRUE; -} - -static gboolean -transform_cookies_accept_mode (GConfEntry *gcentry, - GValue *value, - gpointer user_data) - -{ - GConfValue *gcvalue; - const char *mode; - int mozilla_mode = 0; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) return FALSE; - - mode = gconf_value_get_string (gcvalue); - if (mode == NULL) return FALSE; - - if (strcmp (mode, "anywhere") == 0) - { - mozilla_mode = 0; - } - else if (strcmp (mode, "current site") == 0) - { - mozilla_mode = 1; - } - else if (strcmp (mode, "nowhere") == 0) - { - mozilla_mode = 2; - } - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, mozilla_mode); - - return TRUE; -} - -static gboolean -transform_encoding (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - EphyEncodings *encodings; - EphyNode *node; - const char *code; - gboolean is_autodetector; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) return FALSE; - - code = gconf_value_get_string (gcvalue); - if (code == NULL) return FALSE; - - encodings = EPHY_ENCODINGS (ephy_embed_shell_get_encodings (embed_shell)); - node = ephy_encodings_get_node (encodings, code, FALSE); - if (node == NULL) return FALSE; - - is_autodetector = ephy_node_get_property_boolean (node, EPHY_NODE_ENCODING_PROP_IS_AUTODETECTOR); - if (is_autodetector != GPOINTER_TO_INT (user_data)) return FALSE; - - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, code); - - return TRUE; -} - -static gboolean -transform_image_animation_mode (GConfEntry *gcentry, - GValue *value, - gpointer user_data) - -{ - GConfValue *gcvalue; - const char *mode; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) return FALSE; - - mode = gconf_value_get_string (gcvalue); - if (mode == NULL) return FALSE; - - if (strcmp (mode, "disabled") == 0) - { - mode = "none"; - } - - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, mode); - - return TRUE; -} - -static gboolean -transform_proxy_ignore_list (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - GArray *array; - GSList *hosts, *l; - char **strings; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_LIST || - gconf_value_get_list_type (gcvalue) != GCONF_VALUE_STRING) return FALSE; - - hosts = gconf_value_get_list (gcvalue); - - array = g_array_new (TRUE, FALSE, sizeof (char *)); - - for (l = hosts; l != NULL; l = l->next) - { - const char *host; - - host = gconf_value_get_string ((GConfValue *) l->data); - - if (host != NULL && host[0] != '\0') - { - g_array_append_val (array, host); - } - } - - strings = (char **) g_array_free (array, FALSE); - - g_value_init (value, G_TYPE_STRING); - g_value_take_string (value, g_strjoinv (",", strings)); - - /* the strings themselves are const */ - g_free (strings); - - return TRUE; -} - -static gboolean -transform_proxy_mode (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - const char *mode; - int mozilla_mode = 0; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) return FALSE; - - mode = gconf_value_get_string (gcvalue); - if (mode == NULL) return FALSE; - - if (strcmp (mode, "manual") == 0) - { - mozilla_mode = 1; - } - else if (strcmp (mode, "auto") == 0) - { - mozilla_mode = 2; - } - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, mozilla_mode); - - return TRUE; -} - -static gboolean -transform_use_own_fonts (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_BOOL) return FALSE; - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, gconf_value_get_bool (gcvalue) ? 0 : 1); - - return TRUE; -} - -extern "C" gboolean -mozilla_notifier_transform_bool (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_BOOL) return FALSE; - - g_value_init (value, G_TYPE_BOOLEAN); - g_value_set_boolean (value, gconf_value_get_bool (gcvalue)); - - return TRUE; -} - -extern "C" gboolean -mozilla_notifier_transform_bool_invert (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_BOOL) return FALSE; - - g_value_init (value, G_TYPE_BOOLEAN); - g_value_set_boolean (value, !gconf_value_get_bool (gcvalue)); - - return TRUE; -} - -extern "C" gboolean -mozilla_notifier_transform_int (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_INT) return FALSE; - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, gconf_value_get_int (gcvalue)); - - return TRUE; -} - -extern "C" gboolean -mozilla_notifier_transform_string (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - GConfValue *gcvalue; - const char *str; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) return FALSE; - - str = gconf_value_get_string (gcvalue); - if (str == NULL) return FALSE; - - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, str); - - return TRUE; -} - -static const PrefData notifier_entries[] = -{ - { CONF_BROWSE_WITH_CARET, - "accessibility.browsewithcaret", - mozilla_notifier_transform_bool }, - { CONF_NETWORK_CACHE_SIZE, - "browser.cache.disk.capacity", - transform_cache_size }, - { CONF_RENDERING_USE_OWN_COLORS, - "browser.display.use_document_colors", - mozilla_notifier_transform_bool_invert }, - { CONF_RENDERING_USE_OWN_FONTS, - "browser.display.use_document_fonts", - transform_use_own_fonts }, - { CONF_SECURITY_ALLOW_POPUPS, - "dom.disable_open_during_load", - mozilla_notifier_transform_bool_invert }, - { CONF_DISPLAY_SMOOTHSCROLL, - "general.smoothScroll", - mozilla_notifier_transform_bool }, - { CONF_IMAGE_ANIMATION_MODE, - "image.animation_mode", - transform_image_animation_mode }, - { CONF_RENDERING_LANGUAGE, - "intl.accept_languages", - transform_accept_languages_list }, - { CONF_LANGUAGE_DEFAULT_ENCODING, - "intl.charset.default", - transform_encoding, - GINT_TO_POINTER (FALSE) }, - { CONF_LANGUAGE_AUTODETECT_ENCODING, - "intl.charset.detector", - transform_encoding, - GINT_TO_POINTER (TRUE) }, - { CONF_SECURITY_JAVA_ENABLED, - "security.enable_java", - mozilla_notifier_transform_bool }, - { CONF_SECURITY_JAVASCRIPT_ENABLED, - "javascript.enabled", - mozilla_notifier_transform_bool }, - { CONF_NETWORK_PROXY_AUTO_URL, - "network.proxy.autoconfig_url", - mozilla_notifier_transform_string }, - { CONF_NETWORK_HTTP_PROXY, - "network.proxy.http", - mozilla_notifier_transform_string }, - { CONF_NETWORK_HTTP_PROXY_PORT, - "network.proxy.http_port", - mozilla_notifier_transform_int }, - { CONF_NETWORK_FTP_PROXY, - "network.proxy.ftp", - mozilla_notifier_transform_string }, - { CONF_NETWORK_FTP_PROXY_PORT, - "network.proxy.ftp_port", - mozilla_notifier_transform_int }, - { CONF_NETWORK_SSL_PROXY, - "network.proxy.ssl", - mozilla_notifier_transform_string }, - { CONF_NETWORK_SSL_PROXY_PORT, - "network.proxy.ssl_port", - mozilla_notifier_transform_int }, - { CONF_NETWORK_SOCKS_PROXY, - "network.proxy.socks", - mozilla_notifier_transform_string }, - { CONF_NETWORK_SOCKS_PROXY_PORT, - "network.proxy.socks_port", - mozilla_notifier_transform_int }, - { CONF_NETWORK_PROXY_IGNORE_HOSTS, - "network.proxy.no_proxies_on", - transform_proxy_ignore_list }, - { CONF_NETWORK_PROXY_MODE, - "network.proxy.type", - transform_proxy_mode }, - { CONF_SECURITY_COOKIES_ACCEPT, - "network.cookie.cookieBehavior", - transform_cookies_accept_mode }, - { CONF_PRIVACY_REMEMBER_PASSWORDS, - "signon.rememberSignons", - mozilla_notifier_transform_bool } -}; - -gboolean -mozilla_pref_set (const char *pref, - const GValue *value) -{ - NS_ENSURE_TRUE (gPrefBranch, FALSE); - - g_return_val_if_fail (pref != NULL, FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - nsresult rv; - PRInt32 prefType; - rv = gPrefBranch->GetPrefType (pref, &prefType); - if (NS_FAILED (rv)) - { - /* probably just an unset pref */ - prefType = nsIPrefBranch::PREF_INVALID; - rv = NS_OK; - } - - switch (G_VALUE_TYPE (value)) - { - case G_TYPE_INT: - { - if (prefType != nsIPrefBranch::PREF_INT && - prefType != nsIPrefBranch::PREF_INVALID) - break; - - PRInt32 old_value = 0; - PRInt32 new_value = g_value_get_int (value); - rv = gPrefBranch->GetIntPref (pref, &old_value); - if (NS_FAILED (rv) || old_value != new_value) - { - rv = gPrefBranch->SetIntPref (pref, new_value); - } - break; - } - case G_TYPE_BOOLEAN: - { - if (prefType != nsIPrefBranch::PREF_BOOL && - prefType != nsIPrefBranch::PREF_INVALID) - break; - - PRBool old_value = PR_FALSE; - PRBool new_value = g_value_get_boolean (value); - rv = gPrefBranch->GetBoolPref (pref, &old_value); - if (NS_FAILED (rv) || old_value != new_value) - { - rv = gPrefBranch->SetBoolPref (pref, new_value); - } - break; - } - case G_TYPE_STRING: - { - if (prefType != nsIPrefBranch::PREF_STRING && - prefType != nsIPrefBranch::PREF_INVALID) - break; - - const char *new_value = g_value_get_string (value); - if (new_value == NULL) - { - rv = gPrefBranch->ClearUserPref (pref); - } - else - { - char *old_value = nsnull; - - rv = gPrefBranch->GetCharPref (pref, &old_value); - if (NS_FAILED (rv) || - old_value == nsnull || - strcmp (old_value, new_value) != 0) - { - rv = gPrefBranch->SetCharPref (pref, new_value); - } - - if (old_value) - { - nsMemory::Free (old_value); - } - } - break; - } - default: - g_return_val_if_reached (FALSE); - rv = NS_ERROR_FAILURE; - break; - } - - return NS_SUCCEEDED (rv) != PR_FALSE; -} - -static void -notify_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *gcentry, - PrefData *data) -{ - GValue value = { 0, }; - - g_return_if_fail (gcentry != NULL); - g_assert (data != NULL); - - if (data->func (gcentry, &value, data->user_data)) - { - mozilla_pref_set (data->mozilla_pref, &value); - g_value_unset (&value); - } - else - { - /* Reset the pref */ - NS_ENSURE_TRUE (gPrefBranch, ); - gPrefBranch->ClearUserPref (data->mozilla_pref); - } -} - -extern "C" guint -mozilla_notifier_add (const char *gconf_key, - const char *mozilla_pref, - PrefValueTransformFunc func, - gpointer user_data) -{ - GConfClient *client; - PrefData *data; - GError *error = NULL; - guint cnxn_id; - - g_return_val_if_fail (gconf_key != NULL, 0); - g_return_val_if_fail (mozilla_pref != NULL, 0); - g_return_val_if_fail (func, 0); - - client = eel_gconf_client_get_global (); - g_return_val_if_fail (client != NULL, 0); - - data = g_slice_new (PrefData); - data->gconf_key = g_strdup (gconf_key); - data->mozilla_pref = g_strdup (mozilla_pref); - data->func = func; - data->user_data = user_data; - - cnxn_id = gconf_client_notify_add (client, gconf_key, - (GConfClientNotifyFunc) notify_cb, - data, (GFreeFunc) free_pref_data, - &error); - if (eel_gconf_handle_error (&error)) - { - if (cnxn_id != EEL_GCONF_UNDEFINED_CONNECTION) - { - gconf_client_notify_remove (client, cnxn_id); - } - - return 0; - } - - data->cnxn_id = cnxn_id; - notifiers = g_list_prepend (notifiers, data); - - gconf_client_notify (client, gconf_key); - - return cnxn_id; -} - -static int -find_data (const PrefData *a, - gconstpointer idptr) -{ - return a->cnxn_id != GPOINTER_TO_UINT (idptr); -} - -extern "C" void -mozilla_notifier_remove (guint id) -{ - GList *l; - - g_return_if_fail (id != 0); - - l = g_list_find_custom (notifiers, GUINT_TO_POINTER (id), - (GCompareFunc) find_data); - g_return_if_fail (l != NULL); - - notifiers = g_list_delete_link (notifiers, l); - eel_gconf_notification_remove (id); -} - -#ifdef MIGRATE_PIXEL_SIZE - -#define INT_ROUND(a) gint((a) + 0.5f) - -/** -* This function gets the dpi in the same way that mozilla gets the dpi, -* this allows us to convert from pixels to points easily -*/ -static gint -mozilla_get_dpi () -{ - GtkSettings* settings = gtk_settings_get_default (); - gint dpi = 0; - - /* Use the gdk-xft-dpi setting if it is set */ - if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (settings)), - "gtk-xft-dpi")) - { - g_object_get (G_OBJECT (settings), "gtk-xft-dpi", &dpi, (char *) NULL); - if (dpi) return INT_ROUND (dpi / PANGO_SCALE); - } - - /* Fall back to what xft thinks it is */ - char *val = XGetDefault (GDK_DISPLAY (), "Xft", "dpi"); - if (val) - { - char *e; - double d = strtod(val, &e); - if (e != val) return INT_ROUND (d); - } - - /* Fall back to calculating manually from the gdk screen settings */ - float screenWidthIn = float (gdk_screen_width_mm()) / 25.4f; - return INT_ROUND (gdk_screen_width() / screenWidthIn); -} - -static void -migrate_font_gconf_key (const char *pixel_key, - const char *point_key) -{ - int size; - - size = eel_gconf_get_integer (pixel_key); - - if (size > 0) - { - /* Use doubles to get more accurate arithmetic */ - double dpi = (double) mozilla_get_dpi (); - double value = (double) eel_gconf_get_integer (pixel_key); - gint point = INT_ROUND ((value * 72) / dpi); - - eel_gconf_set_integer (point_key, point); - } -} - -#endif - -static gboolean -parse_pango_font (const char *font, - char **name, - int *size) -{ - PangoFontMask mask = (PangoFontMask) (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_SIZE); - - PangoFontDescription *desc = pango_font_description_from_string (font); - if (desc == NULL) return FALSE; - - if ((pango_font_description_get_set_fields (desc) & mask) != mask) - { - pango_font_description_free (desc); - return FALSE; - } - - *size = PANGO_PIXELS (pango_font_description_get_size (desc)); - *name = g_strdup (pango_font_description_get_family (desc)); - - pango_font_description_free (desc); - - LOG ("Parsed pango font description '%s' -> name:%s, size:%d", - font, *name ? *name : "-", *size); - - return *name != NULL && *size > 0; -} - -typedef struct -{ - guint cnxn_id; - char **font_name_prefs; - char **font_size_prefs; - char *font_name; - int font_size; -} DesktopFontData; - -static gboolean -transform_font_name (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - DesktopFontData *data = (DesktopFontData *) user_data; - GConfValue *gcvalue; - const char *font_name; - - gcvalue = gconf_entry_get_value (gcentry); - if (gconf_entry_get_is_default (gcentry) || - gcvalue == NULL || - gcvalue->type != GCONF_VALUE_STRING) - { - font_name = data->font_name; - } - else - { - font_name = gconf_value_get_string (gcvalue); - if ((font_name == NULL || font_name[0] == '\0')) - { - font_name = data->font_name; - } - } - - LOG ("%s value for key '%s'", - gconf_entry_get_is_default (gcentry) ? "default" : "NON-default", - gconf_entry_get_key (gcentry)); - - if (font_name == NULL) return FALSE; - - LOG ("Inferred font name '%s' for key '%s'", - font_name, gconf_entry_get_key (gcentry)); - - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, font_name); - - return TRUE; -} - -static gboolean -transform_font_size (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - DesktopFontData *data = (DesktopFontData *) user_data; - GConfValue *gcvalue; - int size = 0; - - gcvalue = gconf_entry_get_value (gcentry); - if (gconf_entry_get_is_default (gcentry) || - gcvalue == NULL || - gcvalue->type != GCONF_VALUE_INT) - { - size = data->font_size; - } - else - { - size = gconf_value_get_int (gcvalue); - } - - if (size <= 0 || size > MAX_FONT_SIZE) return FALSE; - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, size); - - return TRUE; -} - -static void -notify_desktop_font_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *gcentry, - DesktopFontData *data) -{ - GConfValue *gcvalue; - char *name = NULL; - int size = 0, i; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_STRING && - parse_pango_font (gconf_value_get_string (gcvalue), &name, &size)) - { - LOG ("Desktop font %s -> name=%s, size=%d", - gconf_entry_get_key (gcentry), name, size); - - g_free (data->font_name); - data->font_name = name; - data->font_size = size; - } - else - { - g_free (name); - - g_free (data->font_name); - data->font_name = NULL; - data->font_size = 0; - } - - for (i = 0; data->font_name_prefs[i] != NULL; ++i) - { - gconf_client_notify (client, data->font_name_prefs[i]); - } - for (i = 0; data->font_size_prefs[i] != NULL; ++i) - { - gconf_client_notify (client, data->font_size_prefs[i]); - } -} - -typedef struct -{ - guint cnxn_id; - char **prefs; - int size; -} MinimumFontSizeData; - -static gboolean -transform_minimum_font_size (GConfEntry *gcentry, - GValue *value, - gpointer user_data) -{ - MinimumFontSizeData *data = (MinimumFontSizeData *) user_data; - GConfValue *gcvalue; - int size = 0; - - gcvalue = gconf_entry_get_value (gcentry); - if (gcvalue == NULL || - gcvalue->type != GCONF_VALUE_INT) - { - size = data->size; - } - else - { - size = MAX (gconf_value_get_int (gcvalue), - data->size); - } - - if (size <= 0) return FALSE; - - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, size); - - return TRUE; -} - -static void -notify_minimum_size_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - MinimumFontSizeData *data) -{ - GConfValue *gcvalue; - int i; - - data->size = 0; - - gcvalue = gconf_entry_get_value (entry); - /* happens on initial notify if the key doesn't exist */ - if (gcvalue != NULL && - gcvalue->type == GCONF_VALUE_INT) - { - data->size = gconf_value_get_int (gcvalue); - data->size = MAX (data->size, 0); - } - - LOG ("Minimum font size now %d", data->size); - - for (i = 0; data->prefs[i] != NULL; ++i) - { - gconf_client_notify (client, data->prefs[i]); - } -} - -static DesktopFontData *desktop_font_data; -static MinimumFontSizeData *minimum_font_size_data; - -static void -mozilla_font_notifiers_init (void) -{ - static const char *types [] = { "variable", "monospace" }; - const EphyFontsLanguageInfo *font_languages; - guint n_font_languages, i; - - eel_gconf_monitor_add ("/desktop/gnome/interface"); - - font_languages = ephy_font_languages (); - n_font_languages = ephy_font_n_languages (); - - desktop_font_data = g_new0 (DesktopFontData, 2); - desktop_font_data[0].font_name_prefs = g_new0 (char*, n_font_languages + 1); - desktop_font_data[0].font_size_prefs = g_new0 (char*, n_font_languages + 1); - desktop_font_data[1].font_name_prefs = g_new0 (char*, n_font_languages + 1); - desktop_font_data[1].font_size_prefs = g_new0 (char*, n_font_languages + 1); - - desktop_font_data[0].cnxn_id = - eel_gconf_notification_add (CONF_DESKTOP_FONT_VARIABLE, - (GConfClientNotifyFunc) notify_desktop_font_cb, - &desktop_font_data[0]); - eel_gconf_notify (CONF_DESKTOP_FONT_VARIABLE); - - desktop_font_data[1].cnxn_id = - eel_gconf_notification_add (CONF_DESKTOP_FONT_MONOSPACE, - (GConfClientNotifyFunc) notify_desktop_font_cb, - &desktop_font_data[1]); - eel_gconf_notify (CONF_DESKTOP_FONT_MONOSPACE); - - minimum_font_size_data = g_new0 (MinimumFontSizeData, 1); - minimum_font_size_data->prefs = g_new0 (char*, n_font_languages + 1); - - minimum_font_size_data->cnxn_id = - eel_gconf_notification_add (CONF_RENDERING_FONT_MIN_SIZE, - (GConfClientNotifyFunc) notify_minimum_size_cb, - minimum_font_size_data); - eel_gconf_notify (CONF_RENDERING_FONT_MIN_SIZE); - -#ifdef MIGRATE_PIXEL_SIZE - gboolean migrate_size; - - migrate_size = (eel_gconf_get_integer (CONF_SCHEMA_VERSION) - < EPIPHANY_SCHEMA_VERSION); - if (migrate_size) - { - eel_gconf_set_integer (CONF_SCHEMA_VERSION, EPIPHANY_SCHEMA_VERSION); - } -#endif - - for (i=0; i < n_font_languages; i++) - { - const char *code = font_languages[i].code; - guint k; - char key[255], pref[255]; -#ifdef MIGRATE_PIXEL_SIZE - char old_key[255]; -#endif - - for (k = 0; k < G_N_ELEMENTS (types); k++) - { - g_snprintf (key, sizeof (key), "%s_%s_%s", - CONF_RENDERING_FONT, types[k], code); - g_snprintf (pref, sizeof (pref), "font.name.%s.%s", - types[k], code); - - desktop_font_data[k].font_name_prefs[i] = g_strdup (key); - - mozilla_notifier_add (key, pref, - transform_font_name, - &desktop_font_data[k]); - } - -#ifdef MIGRATE_PIXEL_SIZE - if (migrate_size) - { - char *type; - - type = eel_gconf_get_string (CONF_RENDERING_FONT_TYPE_OLD); - if (type && (strcmp (type, "serif") == 0 || - strcmp (type, "sans-serif") == 0)) - { - char *family; - - g_snprintf (old_key, sizeof (old_key), "%s_%s_%s", - CONF_RENDERING_FONT, type, code); - g_snprintf (key, sizeof (key), "%s_%s_%s", - CONF_RENDERING_FONT, "variable", code); - - family = eel_gconf_get_string (old_key); - if (family) - { - eel_gconf_set_string (key, family); - g_free (family); - } - } - - g_free (type); - } -#endif - - /* FIXME is it "minimum-size" or "min-size" !!? */ - g_snprintf (key, sizeof (key), "%s_%s", - CONF_RENDERING_FONT_MIN_SIZE, code); - g_snprintf (pref, sizeof (pref), "font.minimum-size.%s", code); - - minimum_font_size_data->prefs[i] = g_strdup (key); - - mozilla_notifier_add (key, pref, transform_minimum_font_size, - minimum_font_size_data); - -#ifdef MIGRATE_PIXEL_SIZE - if (migrate_size) - { - g_snprintf (old_key, sizeof (key), "%s_%s", - CONF_RENDERING_FONT_MIN_SIZE_OLD, code); - migrate_font_gconf_key (old_key, key); - } -#endif - - g_snprintf (key, sizeof (key), "%s_%s", - CONF_RENDERING_FONT_FIXED_SIZE, code); - g_snprintf (pref, sizeof (pref), "font.size.fixed.%s", code); - - desktop_font_data[1].font_size_prefs[i] = g_strdup (key); - mozilla_notifier_add (key, pref, transform_font_size, - &desktop_font_data[1]); - -#ifdef MIGRATE_PIXEL_SIZE - if (migrate_size) - { - g_snprintf (old_key, sizeof (old_key), "%s_%s", - CONF_RENDERING_FONT_FIXED_SIZE_OLD, code); - migrate_font_gconf_key (old_key, key); - } -#endif - - g_snprintf (key, sizeof (key), "%s_%s", - CONF_RENDERING_FONT_VAR_SIZE, code); - g_snprintf (pref, sizeof (pref), "font.size.variable.%s", code); - - desktop_font_data[0].font_size_prefs[i] = g_strdup (key); - mozilla_notifier_add (key, pref, transform_font_size, - &desktop_font_data[0]); - -#ifdef MIGRATE_PIXEL_SIZE - if (migrate_size) - { - g_snprintf (old_key, sizeof (old_key), "%s_%s", - CONF_RENDERING_FONT_VAR_SIZE_OLD, code); - migrate_font_gconf_key (old_key, key); - } -#endif - } -} - -static void -mozilla_font_notifiers_shutdown (void) -{ - eel_gconf_monitor_remove ("/desktop/gnome/interface"); - - eel_gconf_notification_remove (desktop_font_data[0].cnxn_id); - eel_gconf_notification_remove (desktop_font_data[1].cnxn_id); - eel_gconf_notification_remove (minimum_font_size_data->cnxn_id); - - g_free (desktop_font_data[0].font_name); - g_free (desktop_font_data[1].font_name); - - g_strfreev (desktop_font_data[0].font_name_prefs); - g_strfreev (desktop_font_data[0].font_size_prefs); - g_strfreev (desktop_font_data[1].font_name_prefs); - g_strfreev (desktop_font_data[1].font_size_prefs); - g_strfreev (minimum_font_size_data->prefs); - - g_free (desktop_font_data); - g_free (minimum_font_size_data); -} - -#if 0 -static void -notify_generic_cb (GConfClient *client, - guint cnxn_id, - GConfEntry *gcentry, - gpointer data) -{ - GConfValue *gcvalue; - const char *key, *pref; - static const gsize len = strlen ("/apps/epiphany/web/gecko_prefs/"); - GValue value = { 0, }; - - key = gconf_entry_get_key (gcentry); - if (!key || strlen (key) <= len) return; - - pref = key + len; - - gcvalue = gconf_entry_get_value (gcentry); - if (!gcvalue) return; - - switch (gcvalue->type) - { - case GCONF_VALUE_STRING: - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, gconf_value_get_string (gcvalue)); - break; - case GCONF_VALUE_INT: - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, gconf_value_get_int (gcvalue)); - break; - case GCONF_VALUE_BOOL: - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, gconf_value_get_bool (gcvalue)); - break; - /* case GCONF_VALUE_INVALID: */ - /* case GCONF_VALUE_FLOAT: */ - /* case GCONF_VALUE_SCHEMA: */ - /* case GCONF_VALUE_LIST: */ - /* case GCONF_VALUE_PAIR: */ - default: - g_warning ("Unsupported value type for key '%s'\n", key); - return; - } - - g_assert (G_IS_VALUE (&value)); - mozilla_pref_set (pref, &value); - g_value_unset (&value); -} - -static void -mozilla_generic_notifier_init (void) -{ - GConfClient *client; - GError *error = NULL; - guint cnxn_id; - PrefData *data; - GSList *list, *l; - - client = eel_gconf_client_get_global (); - - cnxn_id = gconf_client_notify_add (client, "/apps/epiphany/web/gecko_prefs", - (GConfClientNotifyFunc) notify_generic_cb, - NULL, NULL, &error); - if (eel_gconf_handle_error (&error)) - { - if (cnxn_id != EEL_GCONF_UNDEFINED_CONNECTION) - { - gconf_client_notify_remove (client, cnxn_id); - } - - return; - } - - data = g_slice_new0 (PrefData); - data->cnxn_id = cnxn_id; - notifiers = g_list_prepend (notifiers, data); - - list = gconf_client_all_entries (client, "/apps/epiphany/web/gecko_prefs", NULL); - for (l = list; l != NULL; l = l->next) - { - GConfEntry *gcentry = (GConfEntry *) l->data; - - notify_generic_cb (client, cnxn_id, gcentry, NULL); - gconf_entry_unref (gcentry); - } - g_slist_free (list); -} -#endif - -extern "C" gboolean -mozilla_notifiers_init (void) -{ - guint i; - - eel_gconf_monitor_add ("/apps/epiphany/web"); - eel_gconf_monitor_add ("/system/proxy"); - eel_gconf_monitor_add ("/system/http_proxy"); - - /* the pref service conveniently implements the root pref branch */ - gPrefBranch = nsnull; - nsresult rv = CallGetService (NS_PREFSERVICE_CONTRACTID, &gPrefBranch); - if (NS_FAILED (rv) || !gPrefBranch) - { - g_warning ("Failed to get the pref service!\n"); - return FALSE; - } - -#if 0 - /* First init the generic notifier, so our regular prefs override prefs set there */ - mozilla_generic_notifier_init (); -#endif - - for (i = 0; i < G_N_ELEMENTS (notifier_entries); i++) - { - mozilla_notifier_add (notifier_entries[i].gconf_key, - notifier_entries[i].mozilla_pref, - notifier_entries[i].func, - notifier_entries[i].user_data); - } - - mozilla_font_notifiers_init (); - - return TRUE; -} - -static void -remove_notification (PrefData *data) -{ - eel_gconf_notification_remove (data->cnxn_id); -} - -extern "C" void -mozilla_notifiers_shutdown (void) -{ - NS_IF_RELEASE (gPrefBranch); - gPrefBranch = nsnull; - - mozilla_font_notifiers_shutdown (); - - eel_gconf_monitor_remove ("/apps/epiphany/web"); - eel_gconf_monitor_remove ("/system/proxy"); - eel_gconf_monitor_remove ("/system/http_proxy"); - - g_list_foreach (notifiers, (GFunc) remove_notification, NULL); - g_list_free (notifiers); -} diff --git a/embed/mozilla/mozilla-notifiers.h b/embed/mozilla/mozilla-notifiers.h deleted file mode 100644 index d1fe6d7aa..000000000 --- a/embed/mozilla/mozilla-notifiers.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright © 2000 Nate Case - * Copyright © 2000-2004 Marco Pesenti Gritti - * Copyright © 2003, 2004 Christian Persch - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $Id$ - */ - -#ifndef MOZILLA_NOTIFIERS_H -#define MOZILLA_NOTIFIERS_H - -#include <glib.h> -#include <glib-object.h> -#include <gconf/gconf.h> - -G_BEGIN_DECLS - -typedef gboolean (* PrefValueTransformFunc) (GConfEntry*, GValue*, gpointer); - -gboolean mozilla_notifier_transform_bool (GConfEntry*, GValue*, gpointer); - -gboolean mozilla_notifier_transform_bool_invert (GConfEntry*, GValue*, gpointer); - -gboolean mozilla_notifier_transform_int (GConfEntry*, GValue*, gpointer); - -gboolean mozilla_notifier_transform_string (GConfEntry*, GValue*, gpointer); - -guint mozilla_notifier_add (const char *gconf_key, - const char *mozilla_pref, - PrefValueTransformFunc func, - gpointer user_data); - -void mozilla_notifier_remove (guint id); - -gboolean mozilla_pref_set (const char *pref, - const GValue *value); - -gboolean mozilla_notifiers_init (void); - -void mozilla_notifiers_shutdown (void); - -G_END_DECLS - -#endif |