diff options
author | Marco Pesenti Gritti <marco@src.gnome.org> | 2004-06-04 02:51:32 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2004-06-04 02:51:32 +0800 |
commit | b774b547788b74884b9eb690c548a6016e714023 (patch) | |
tree | 72b9df09c0fc257169b3e9b9cbdc349e56a63101 /embed | |
parent | b699b40d663955560655271f7645ae277e6076c8 (diff) | |
download | gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.gz gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.bz2 gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.lz gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.xz gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.tar.zst gsoc2013-epiphany-b774b547788b74884b9eb690c548a6016e714023.zip |
merge mozilla-embed-strings branch
Diffstat (limited to 'embed')
31 files changed, 1023 insertions, 931 deletions
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index 7e55ac7b3..f3fa3bc57 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -249,6 +249,25 @@ ephy_embed_base_init (gpointer g_class) G_TYPE_NONE, 1, G_TYPE_FLOAT); +/** + * EphyEmbed::ge-content-change: + * @embed: + * @uri: URI of the new content + * + * The ::ge_content_change signal is emitted when a new page content + * is being loadedinto the browser. It's a good place to do view + * related changes, for example to restore the zoom level of a page + * or to set an user style sheet. + **/ + g_signal_new ("ge_content_change", + EPHY_TYPE_EMBED, + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyEmbedIface, content_change), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); initialized = TRUE; } @@ -476,7 +495,6 @@ ephy_embed_reload (EphyEmbed *embed, * ephy_embed_set_zoom: * @embed: an #EphyEmbed * @zoom: the new zoom level - * @reflow: %TRUE to reload the page * * Sets the zoom level for a web page. * @@ -486,11 +504,10 @@ ephy_embed_reload (EphyEmbed *embed, **/ void ephy_embed_set_zoom (EphyEmbed *embed, - float zoom, - gboolean reflow) + float zoom) { EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - iface->set_zoom (embed, zoom, reflow); + iface->set_zoom (embed, zoom); } /** diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 9e8f26d6f..b890222b7 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -171,6 +171,8 @@ struct _EphyEmbedIface EmbedSecurityLevel level); void (* zoom_change) (EphyEmbed *embed, float new_zoom); + void (* content_change) (EphyEmbed *embed, + const char *uri); /* Methods */ void (* load_url) (EphyEmbed *embed, @@ -204,8 +206,7 @@ struct _EphyEmbedIface EmbedSecurityLevel *level, char **description); void (* set_zoom) (EphyEmbed *embed, - float zoom, - gboolean reflow); + float zoom); float (* get_zoom) (EphyEmbed *embed); void (* find_set_properties) (EphyEmbed *embed, const char *search_string, @@ -284,8 +285,7 @@ void ephy_embed_get_security_level (EphyEmbed *embed, /* Zoom */ void ephy_embed_set_zoom (EphyEmbed *embed, - float zoom, - gboolean reflow); + float zoom); float ephy_embed_get_zoom (EphyEmbed *embed); diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 8a6a6a6d3..8f7555a66 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -35,11 +35,12 @@ #include <libgnomevfs/gnome-vfs-utils.h> #include <glib/gi18n.h> +#include <nsMemory.h> #include <nsIURL.h> #include <nsILocalFile.h> #include <nsIMIMEInfo.h> #include <nsIInterfaceRequestorUtils.h> -#include "nsCExternalHandlerService.h" +#include <nsCExternalHandlerService.h> #include "ephy-prefs.h" #include "ephy-embed-single.h" @@ -57,13 +58,13 @@ class GContentHandler; NS_IMPL_ISUPPORTS1(GContentHandler, nsIHelperAppLauncherDialog) -#if MOZILLA_SNAPSHOT < 18 -GContentHandler::GContentHandler() : mMimeType(nsnull) +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) +GContentHandler::GContentHandler() { LOG ("GContentHandler ctor (%p)", this) } #else -GContentHandler::GContentHandler() +GContentHandler::GContentHandler() : mMimeType(nsnull) { LOG ("GContentHandler ctor (%p)", this) } @@ -73,7 +74,7 @@ GContentHandler::~GContentHandler() { LOG ("GContentHandler dtor (%p)", this) -#if MOZILLA_SNAPSHOT < 18 +#if !MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) nsMemory::Free (mMimeType); #endif } @@ -97,11 +98,11 @@ NS_IMETHODIMP GContentHandler::Show(nsIHelperAppLauncher *aLauncher, NS_ENSURE_SUCCESS (rv, rv); single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (embed_shell)); -#if MOZILLA_SNAPSHOT < 18 - g_signal_emit_by_name (single, "handle_content", mMimeType, +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + g_signal_emit_by_name (single, "handle_content", mMimeType.get(), mUrl.get(), &handled); #else - g_signal_emit_by_name (single, "handle_content", mMimeType.get(), + g_signal_emit_by_name (single, "handle_content", mMimeType, mUrl.get(), &handled); #endif @@ -128,11 +129,14 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( EphyFileChooser *dialog; gint response; char *filename; + nsEmbedCString defaultFile; + + NS_UTF16ToCString (nsEmbedString (aDefaultFile), + NS_CSTRING_ENCODING_UTF8, defaultFile); if (mAction != CONTENT_ACTION_SAVEAS) { - return BuildDownloadPath (NS_ConvertUTF16toUTF8 (aDefaultFile).get(), - _retval); + return BuildDownloadPath (defaultFile.get(), _retval); } nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface (aWindowContext); @@ -142,8 +146,7 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( GTK_FILE_CHOOSER_ACTION_SAVE, CONF_STATE_SAVE_DIR, EPHY_FILE_FILTER_ALL); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), - NS_ConvertUTF16toUTF8 (aDefaultFile).get()); + gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), defaultFile.get()); response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_ACCEPT) @@ -151,7 +154,7 @@ NS_IMETHODIMP GContentHandler::PromptForSaveToFile( filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - destFile->InitWithNativePath (nsDependentCString (filename)); + destFile->InitWithNativePath (nsEmbedCString (filename)); g_free (filename); NS_IF_ADDREF (*_retval = destFile); @@ -208,7 +211,7 @@ NS_METHOD GContentHandler::CheckAppSupportScheme (void) { char *uri_scheme = (char *)l->data; - if (mScheme.Equals (uri_scheme)) + if (strcmp (mScheme.get(), uri_scheme) == 0) { mAppSupportScheme = PR_TRUE; } @@ -227,10 +230,10 @@ NS_METHOD GContentHandler::Init (void) mLauncher->GetMIMEInfo (getter_AddRefs(MIMEInfo)); NS_ENSURE_TRUE (MIMEInfo, NS_ERROR_FAILURE); -#if MOZILLA_SNAPSHOT < 18 - rv = MIMEInfo->GetMIMEType (&mMimeType); -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) rv = MIMEInfo->GetMIMEType (mMimeType); +#else + rv = MIMEInfo->GetMIMEType (&mMimeType); #endif mLauncher->GetTargetFile (getter_AddRefs(mTempFile)); @@ -345,19 +348,16 @@ NS_METHOD GContentHandler::MIMEDoAction (void) auto_downloads = eel_gconf_get_boolean (CONF_AUTO_DOWNLOADS); -#if MOZILLA_SNAPSHOT < 18 - mHelperApp = gnome_vfs_mime_get_default_application (mMimeType); -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) mHelperApp = gnome_vfs_mime_get_default_application (mMimeType.get()); -#endif - CheckAppSupportScheme (); - -#if MOZILLA_SNAPSHOT < 18 - mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType); -#else mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType.get()); +#else + mHelperApp = gnome_vfs_mime_get_default_application (mMimeType); + mPermission = ephy_embed_shell_check_mime (embed_shell, mMimeType); #endif + CheckAppSupportScheme (); + if (auto_downloads) { mAction = CONTENT_ACTION_OPEN; @@ -383,23 +383,26 @@ NS_METHOD GContentHandler::MIMEDoAction (void) if (mAction == CONTENT_ACTION_OPEN) { + nsEmbedString desc; + + NS_CStringToUTF16 (nsEmbedCString ("gnome-default"), + NS_CSTRING_ENCODING_UTF8, desc); + /* HACK we use the application description to ask MozDownload to open the file when download is finished */ -#if MOZILLA_SNAPSHOT < 18 - mimeInfo->SetApplicationDescription - (NS_LITERAL_STRING ("gnome-default").get()); +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + mimeInfo->SetApplicationDescription (desc); #else - mimeInfo->SetApplicationDescription - (NS_LITERAL_STRING ("gnome-default")); + mimeInfo->SetApplicationDescription (desc.get()); #endif } else { -#if MOZILLA_SNAPSHOT < 18 - mimeInfo->SetApplicationDescription (nsnull); +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + mimeInfo->SetApplicationDescription (nsEmbedString ()); #else - mimeInfo->SetApplicationDescription (NS_LITERAL_STRING ("")); + mimeInfo->SetApplicationDescription (nsnull); #endif } diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index a66f36b49..df77559d4 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -25,6 +25,7 @@ #include "config.h" #endif +#include "mozilla-version.h" #include "ephy-embed-shell.h" #include <libgnomevfs/gnome-vfs-mime-handlers.h> @@ -33,13 +34,9 @@ #include <nsISupports.h> #include <nsIURI.h> #include <nsIFile.h> - +#include <nsEmbedString.h> #include <nsIHelperAppLauncherDialog.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif - typedef enum { CONTENT_ACTION_OPEN, @@ -57,8 +54,6 @@ typedef enum {0x9b, 0xeb, 0x93, 0x35, 0xc0, 0x6b, 0xbe, 0xae} \ } -class nsIFactory; - class GContentHandler : public nsIHelperAppLauncherDialog { public: @@ -82,18 +77,18 @@ class GContentHandler : public nsIHelperAppLauncherDialog nsCOMPtr<nsIFile> mTempFile; nsCOMPtr<nsISupports> mContext; -#if MOZILLA_SNAPSHOT < 18 - char *mMimeType; -#else - nsCString mMimeType; -#endif PRBool mAppSupportScheme; GnomeVFSMimeApplication *mHelperApp; ContentAction mAction; EphyMimePermission mPermission; - nsCString mUrl; - nsCString mScheme; + nsEmbedCString mUrl; + nsEmbedCString mScheme; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + nsEmbedCString mMimeType; +#else + char *mMimeType; +#endif }; -#endif +#endif /* __ContentHandler_h */ diff --git a/embed/mozilla/EphyAboutRedirector.cpp b/embed/mozilla/EphyAboutRedirector.cpp index a7f9fbffe..3a5f49913 100644 --- a/embed/mozilla/EphyAboutRedirector.cpp +++ b/embed/mozilla/EphyAboutRedirector.cpp @@ -50,10 +50,7 @@ #include <nsIServiceManager.h> #include <nsCOMPtr.h> #include <nsIURI.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif +#include <nsEmbedString.h> static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); @@ -75,7 +72,7 @@ NS_IMETHODIMP EphyAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) { NS_ENSURE_ARG(aURI); - nsCAutoString path; + nsEmbedCString path; (void)aURI->GetPath(path); nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID)); @@ -86,7 +83,7 @@ EphyAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) if (strcmp(path.get(), kRedirMap[i].id) == 0) { nsCOMPtr<nsIChannel> tempChannel; - ioService->NewChannel(nsDependentCString(kRedirMap[i].url), + ioService->NewChannel(nsEmbedCString(kRedirMap[i].url), nsnull, nsnull, getter_AddRefs(tempChannel)); NS_ENSURE_TRUE (tempChannel, NS_ERROR_FAILURE); diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 7500058c0..0205d376e 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -23,8 +23,7 @@ #endif #include "EphyBrowser.h" -#include "GlobalHistory.h" -#include "ContentHandler.h" +#include "EphyUtils.h" #include "ephy-embed.h" #include "ephy-string.h" #include "ephy-debug.h" @@ -37,15 +36,14 @@ #include "nsISimpleEnumerator.h" #include "nsIContentViewer.h" -#include "nsIGlobalHistory.h" #include "nsIWebBrowserFind.h" #include "nsIWebBrowserFocus.h" #include "nsICommandManager.h" #include "nsIWebBrowserPrint.h" +#include "nsIDocCharset.h" #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeOwner.h" -#include "nsIDocumentCharsetInfo.h" #include "nsIWebPageDescriptor.h" #include "nsISHEntry.h" #include "nsIHistoryEntry.h" @@ -56,25 +54,21 @@ #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLTextAreaElement.h" #include "nsIDOMDocument.h" +#include "nsIDOM3Document.h" #include "nsIDOMEvent.h" #include "nsIDOMEventTarget.h" #include "nsIDOMNode.h" #include "nsIDOMElement.h" +#include "nsIDOMWindow2.h" +#include "nsEmbedString.h" +#include "nsMemory.h" #ifdef ALLOW_PRIVATE_API -#include "nsPIDOMWindow.h" #include "nsIMarkupDocumentViewer.h" -#include "nsIChromeEventHandler.h" -#include "nsIDOMWindowInternal.h" #endif -#ifdef ALLOW_PRIVATE_STRINGS -#include "nsReadableUtils.h" -#include "nsIDocument.h" -#include "nsIDeviceContext.h" -#include "nsIPresContext.h" -#include "nsIAtom.h" -#endif +static PRUnichar DOMLinkAdded[] = { 'D', 'O', 'M', 'L', 'i', 'n', 'k', + 'A', 'd', 'd', 'e', 'd', '\0' }; EphyEventListener::EphyEventListener(void) : mOwner(nsnull) @@ -105,37 +99,41 @@ EphyFaviconEventListener::HandleFaviconLink (nsIDOMNode *node) linkElement = do_QueryInterface (node); if (!linkElement) return NS_ERROR_FAILURE; - NS_NAMED_LITERAL_STRING(attr_rel, "rel"); - nsAutoString value; - result = linkElement->GetAttribute (attr_rel, value); + PRUnichar relAttr[] = { 'r', 'e', 'l', '\0' }; + nsEmbedString value; + result = linkElement->GetAttribute (nsEmbedString(relAttr), value); if (NS_FAILED (result)) return NS_ERROR_FAILURE; - if (value.EqualsIgnoreCase("SHORTCUT ICON") || - value.EqualsIgnoreCase("ICON")) + nsEmbedCString 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) { - NS_NAMED_LITERAL_STRING(attr_href, "href"); - nsAutoString value; - result = linkElement->GetAttribute (attr_href, value); - if (NS_FAILED (result) || value.IsEmpty()) return NS_ERROR_FAILURE; + PRUnichar hrefAttr[] = { 'h', 'r', 'e', 'f', '\0' }; + nsEmbedString value; + result = linkElement->GetAttribute (nsEmbedString (hrefAttr), value); + if (NS_FAILED (result) || !value.Length()) return NS_ERROR_FAILURE; + + nsEmbedCString link; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, link); nsCOMPtr<nsIDOMDocument> domDoc; node->GetOwnerDocument(getter_AddRefs(domDoc)); NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); - nsCOMPtr<nsIDocument> doc = do_QueryInterface (domDoc); + nsCOMPtr<nsIDOM3Document> doc = do_QueryInterface (domDoc); NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); -#if MOZILLA_SNAPSHOT > 13 - nsIURI *uri; - uri = doc->GetDocumentURI (); -#elif MOZILLA_SNAPSHOT > 11 - nsIURI *uri; - uri = doc->GetDocumentURL (); -#endif - if (!uri) return NS_ERROR_FAILURE; + nsEmbedString spec; + result = doc->GetDocumentURI (spec); + NS_ENSURE_SUCCESS (result, result); - const nsACString &link = NS_ConvertUTF16toUTF8(value); - nsCAutoString favicon_url; + nsCOMPtr<nsIURI> uri; + result = EphyUtils::NewURI (getter_AddRefs(uri), spec); + NS_ENSURE_SUCCESS (result, result); + + nsEmbedCString favicon_url; result = uri->Resolve (link, favicon_url); if (NS_FAILED (result)) return NS_ERROR_FAILURE; @@ -210,23 +208,15 @@ EphyBrowser::GetListener (void) if (mEventReceiver) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMWindow> domWindowExternal; - mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindowExternal)); + mWebBrowser->GetContentDOMWindow (getter_AddRefs(domWindowExternal)); - nsCOMPtr<nsIDOMWindowInternal> domWindow; - domWindow = do_QueryInterface(domWindowExternal); + nsCOMPtr<nsIDOMWindow2> domWindow (do_QueryInterface (domWindowExternal)); + NS_ENSURE_TRUE (domWindow, NS_ERROR_FAILURE); - nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(domWindow)); - NS_ENSURE_TRUE (piWin, NS_ERROR_FAILURE); - -#if MOZILLA_SNAPSHOT >= 18 - nsIChromeEventHandler* chromeHandler; - chromeHandler = piWin->GetChromeEventHandler(); -#else - nsCOMPtr<nsIChromeEventHandler> chromeHandler; - piWin->GetChromeEventHandler(getter_AddRefs(chromeHandler)); -#endif + nsCOMPtr<nsIDOMEventTarget> rootWindow; + domWindow->GetWindowRoot (getter_AddRefs(rootWindow)); - mEventReceiver = do_QueryInterface(chromeHandler); + mEventReceiver = do_QueryInterface (rootWindow); NS_ENSURE_TRUE (mEventReceiver, NS_ERROR_FAILURE); return NS_OK; @@ -242,7 +232,7 @@ EphyBrowser::AttachListeners(void) nsCOMPtr<nsIDOMEventTarget> target; target = do_QueryInterface (mEventReceiver); - rv = target->AddEventListener(NS_LITERAL_STRING("DOMLinkAdded"), + rv = target->AddEventListener(nsEmbedString(DOMLinkAdded), mFaviconEventListener, PR_FALSE); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); @@ -260,7 +250,7 @@ EphyBrowser::DetachListeners(void) target = do_QueryInterface (mEventReceiver); NS_ENSURE_TRUE (target, NS_ERROR_FAILURE); - rv = target->RemoveEventListener(NS_LITERAL_STRING("DOMLinkAdded"), + rv = target->RemoveEventListener(nsEmbedString(DOMLinkAdded), mFaviconEventListener, PR_FALSE); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); @@ -381,68 +371,18 @@ nsresult EphyBrowser::GoToHistoryIndex (PRInt16 index) return ContentNav->GotoIndex (index); } -nsresult EphyBrowser::SetZoom (float aZoom, PRBool reflow) +nsresult EphyBrowser::SetZoom (float aZoom) { NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - if (reflow) - { - 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); - } - else - { - nsCOMPtr<nsIDocShell> DocShell; - DocShell = do_GetInterface (mWebBrowser); - NS_ENSURE_TRUE (DocShell, NS_ERROR_FAILURE); - - SetZoomOnDocshell (aZoom, DocShell); - - nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryInterface(DocShell)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr<nsIDocShellTreeItem> child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child)); - if (childAsShell) - { - return SetZoomOnDocshell (aZoom, childAsShell); - } - } - } - } - - return NS_OK; -} - -nsresult EphyBrowser::SetZoomOnDocshell (float aZoom, nsIDocShell *DocShell) -{ - nsCOMPtr<nsIPresContext> PresContext; - DocShell->GetPresContext (getter_AddRefs(PresContext)); - NS_ENSURE_TRUE (PresContext, NS_ERROR_FAILURE); + nsCOMPtr<nsIContentViewer> contentViewer; + GetContentViewer (getter_AddRefs(contentViewer)); + NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); -#if MOZILLA_SNAPSHOT > 13 - nsIDeviceContext *DeviceContext; - DeviceContext = PresContext->DeviceContext(); - NS_ENSURE_TRUE (DeviceContext, NS_ERROR_FAILURE); -#else - nsCOMPtr<nsIDeviceContext> DeviceContext; - PresContext->GetDeviceContext (getter_AddRefs(DeviceContext)); - NS_ENSURE_TRUE (DeviceContext, NS_ERROR_FAILURE); -#endif + nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); + NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - return DeviceContext->SetTextZoom (aZoom); + return mdv->SetTextZoom (aZoom); } nsresult EphyBrowser::GetContentViewer (nsIContentViewer **aViewer) @@ -540,7 +480,7 @@ nsresult EphyBrowser::GetSHTitleAtIndex (PRInt32 index, PRUnichar **title) return NS_OK; } -nsresult EphyBrowser::GetSHUrlAtIndex (PRInt32 index, nsCString &url) +nsresult EphyBrowser::GetSHUrlAtIndex (PRInt32 index, nsACString &url) { NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); @@ -559,7 +499,7 @@ nsresult EphyBrowser::GetSHUrlAtIndex (PRInt32 index, nsCString &url) nsresult result; result = uri->GetSpec(url); - NS_ENSURE_TRUE (NS_SUCCEEDED (result) && !url.IsEmpty(), NS_ERROR_FAILURE); + NS_ENSURE_TRUE (NS_SUCCEEDED (result) && url.Length(), NS_ERROR_FAILURE); return NS_OK; } @@ -608,50 +548,48 @@ nsresult EphyBrowser::GetPageDescriptor(nsISupports **aPageDescriptor) return NS_OK; } -nsresult EphyBrowser::GetDocumentUrl (nsCString &url) +nsresult EphyBrowser::GetDocumentUrl (nsACString &url) { + nsresult rv; + NS_ENSURE_TRUE (mDOMWindow, NS_ERROR_FAILURE); nsCOMPtr<nsIDOMDocument> DOMDocument; mDOMWindow->GetDocument (getter_AddRefs(DOMDocument)); NS_ENSURE_TRUE (DOMDocument, NS_ERROR_FAILURE); - nsCOMPtr<nsIDocument> doc = do_QueryInterface(DOMDocument); + nsCOMPtr<nsIDOM3Document> doc = do_QueryInterface(DOMDocument); NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); -#if MOZILLA_SNAPSHOT > 13 - nsIURI *uri; - uri = doc->GetDocumentURI (); -#elif MOZILLA_SNAPSHOT > 11 - nsIURI *uri; - uri = doc->GetDocumentURL (); -#endif - NS_ENSURE_TRUE (uri, NS_ERROR_FAILURE); + nsEmbedString docURI; + rv = doc->GetDocumentURI (docURI); + NS_ENSURE_SUCCESS (rv, rv); - return uri->GetSpec (url); + NS_UTF16ToCString (docURI, NS_CSTRING_ENCODING_UTF8, url); + + return NS_OK; } -nsresult EphyBrowser::GetTargetDocumentUrl (nsCString &url) +nsresult EphyBrowser::GetTargetDocumentUrl (nsACString &url) { + nsresult rv; + NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); nsCOMPtr<nsIDOMDocument> DOMDocument; GetTargetDocument (getter_AddRefs(DOMDocument)); NS_ENSURE_TRUE (DOMDocument, NS_ERROR_FAILURE); - nsCOMPtr<nsIDocument> doc = do_QueryInterface(DOMDocument); + nsCOMPtr<nsIDOM3Document> doc = do_QueryInterface(DOMDocument); NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); -#if MOZILLA_SNAPSHOT > 13 - nsIURI *uri; - uri = doc->GetDocumentURI (); -#elif MOZILLA_SNAPSHOT > 11 - nsIURI *uri; - uri = doc->GetDocumentURL (); -#endif - NS_ENSURE_TRUE (uri, NS_ERROR_FAILURE); + nsEmbedString docURI; + rv = doc->GetDocumentURI (docURI); + NS_ENSURE_SUCCESS (rv, rv); - return uri->GetSpec (url); + NS_UTF16ToCString (docURI, NS_CSTRING_ENCODING_UTF8, url); + + return NS_OK; } nsresult EphyBrowser::ForceEncoding (const char *encoding) @@ -665,22 +603,20 @@ nsresult EphyBrowser::ForceEncoding (const char *encoding) nsCOMPtr<nsIMarkupDocumentViewer> mdv = do_QueryInterface(contentViewer); NS_ENSURE_TRUE (mdv, NS_ERROR_FAILURE); - return mdv->SetForceCharacterSet (nsDependentCString(encoding)); + return mdv->SetForceCharacterSet (nsEmbedCString(encoding)); } nsresult EphyBrowser::GetEncoding (nsACString &encoding) { NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - nsCOMPtr<nsIDOMDocument> domDoc; - GetTargetDocument (getter_AddRefs(domDoc)); - NS_ENSURE_TRUE (domDoc, NS_ERROR_FAILURE); - - nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); - NS_ENSURE_TRUE (doc, NS_ERROR_FAILURE); + nsCOMPtr<nsIDocCharset> docCharset = do_GetInterface (mWebBrowser); + NS_ENSURE_TRUE (docCharset, NS_ERROR_FAILURE); - encoding = doc->GetDocumentCharacterSet (); - NS_ENSURE_TRUE (!encoding.IsEmpty(), NS_ERROR_FAILURE); + char *charset; + docCharset->GetCharset (&charset); + encoding = charset; + nsMemory::Free (charset); return NS_OK; } @@ -740,6 +676,29 @@ nsresult EphyBrowser::GetCommandState (const char *command, PRBool *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); @@ -780,14 +739,11 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi nsCOMPtr<nsIDOMHTMLTextAreaElement> areaElement = do_QueryInterface (domNode); if (areaElement) { - nsAutoString default_text, user_text; - areaElement->GetDefaultValue (default_text); - areaElement->GetValue (user_text); + nsEmbedString defaultText, userText; + areaElement->GetDefaultValue (defaultText); + areaElement->GetValue (userText); - /* Mozilla Bug 218277, 195946 and others */ - default_text.ReplaceChar(0xa0, ' '); - - if (!user_text.Equals (default_text)) + if (!CompareFormsText (defaultText, userText)) { *aHasTextArea = PR_TRUE; return NS_OK; @@ -799,31 +755,31 @@ nsresult EphyBrowser::GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUi nsCOMPtr<nsIDOMHTMLInputElement> inputElement = do_QueryInterface(domNode); if (!inputElement) continue; - nsAutoString type; + nsEmbedString type; inputElement->GetType(type); - if (type.EqualsIgnoreCase("text")) + nsEmbedCString cType; + NS_UTF16ToCString (type, NS_CSTRING_ENCODING_UTF8, cType); + + if (g_ascii_strcasecmp (cType.get(), "text") == 0) { - nsAutoString default_text, user_text; + nsEmbedString defaultText, userText; PRInt32 max_length; - inputElement->GetDefaultValue (default_text); - inputElement->GetValue (user_text); + inputElement->GetDefaultValue (defaultText); + inputElement->GetValue (userText); inputElement->GetMaxLength (&max_length); /* Guard against arguably broken forms where - * default_text is longer than maxlength - * (user_text is cropped, default_text is not) + * defaultText is longer than maxlength + * (userText is cropped, defaultText is not) * Mozilla bug 232057 */ - if (default_text.Length() > (PRUint32)max_length) + if (defaultText.Length() > (PRUint32)max_length) { - default_text.Truncate (max_length); + defaultText.Cut (max_length, PR_UINT32_MAX); } - /* Mozilla Bug 218277, 195946 and others */ - default_text.ReplaceChar(0xa0, ' '); - - if (!user_text.Equals (default_text)) + if (!CompareFormsText (defaultText, userText)) { (*aNumTextFields)++; if (*aNumTextFields >= NUM_MODIFIED_TEXTFIELDS_REQUIRED) diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h index f244fc60b..d8a6300bb 100644 --- a/embed/mozilla/EphyBrowser.h +++ b/embed/mozilla/EphyBrowser.h @@ -34,10 +34,6 @@ #include <nsIDOMWindow.h> #include <nsIPrintSettings.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include "nsString.h" -#endif - #ifdef ALLOW_PRIVATE_API #include <nsIDocShell.h> #include <nsIDOMEventReceiver.h> @@ -82,7 +78,7 @@ public: nsresult DoCommand (const char *command); nsresult GetCommandState (const char *command, PRBool *enabled); - nsresult SetZoom (float aTextZoom, PRBool reflow); + nsresult SetZoom (float aTextZoom); nsresult GetZoom (float *aTextZoom); nsresult Print (nsIPrintSettings *options, PRBool preview); @@ -101,7 +97,7 @@ public: nsresult GetSHInfo (PRInt32 *count, PRInt32 *index); nsresult GetSHTitleAtIndex (PRInt32 index, PRUnichar **title); - nsresult GetSHUrlAtIndex (PRInt32 index, nsCString &url); + nsresult GetSHUrlAtIndex (PRInt32 index, nsACString &url); nsresult GoToHistoryIndex (PRInt16 index); nsresult ForceEncoding (const char *encoding); @@ -113,8 +109,8 @@ public: nsresult GetDocument (nsIDOMDocument **aDOMDocument); nsresult GetTargetDocument (nsIDOMDocument **aDOMDocument); - nsresult GetDocumentUrl (nsCString &url); - nsresult GetTargetDocumentUrl (nsCString &url); + nsresult GetDocumentUrl (nsACString &url); + nsresult GetTargetDocumentUrl (nsACString &url); nsresult GetHasModifiedForms (PRBool *modified); @@ -130,10 +126,10 @@ private: nsresult GetListener (void); nsresult AttachListeners (void); nsresult DetachListeners (void); - nsresult SetZoomOnDocshell (float aZoom, nsIDocShell *DocShell); nsresult GetSHistory (nsISHistory **aSHistory); nsresult GetContentViewer (nsIContentViewer **aViewer); nsresult GetDocumentHasModifiedForms (nsIDOMDocument *aDomDoc, PRUint32 *aNumTextFields, PRBool *aHasTextArea); + PRBool CompareFormsText (nsAString &aDefaultText, nsAString &aUserText); }; #endif diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp index 31d4610bf..b4dbfe632 100644 --- a/embed/mozilla/EphyContentPolicy.cpp +++ b/embed/mozilla/EphyContentPolicy.cpp @@ -25,15 +25,14 @@ #include "EphyContentPolicy.h" +#include "mozilla-version.h" + #include "eel-gconf-extensions.h" #include "ephy-debug.h" #include <nsCOMPtr.h> #include <nsIURI.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif +#include <nsEmbedString.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" @@ -60,7 +59,7 @@ EphyContentPolicy::~EphyContentPolicy() g_slist_free (mSafeProtocols); } -#if MOZILLA_SNAPSHOT >= 18 +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRUint32 aContentType, nsIURI *aContentLocation, @@ -78,10 +77,10 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, NS_ENSURE_TRUE (aContentLocation, NS_ERROR_FAILURE); - nsCAutoString scheme; + nsEmbedCString scheme; aContentLocation->GetScheme (scheme); - nsCAutoString spec; + nsEmbedCString spec; aContentLocation->GetSpec (spec); LOG ("ShouldLoad type=%d location=%s (scheme %s)", aContentType, spec.get(), scheme.get()) @@ -90,7 +89,7 @@ EphyContentPolicy::ShouldLoad(PRUint32 aContentType, /* Allow the load if the protocol is in safe list, or it's about:blank */ if (g_slist_find_custom (mSafeProtocols, scheme.get(), (GCompareFunc) strcmp) - || spec.Equals ("about:blank")) + || strcmp (spec.get(), "about:blank") == 0) { *aDecision = nsIContentPolicy::ACCEPT; } @@ -128,17 +127,17 @@ NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 contentType, return NS_OK; } - nsCAutoString scheme; + nsEmbedCString scheme; contentLocation->GetScheme (scheme); - nsCAutoString spec; + nsEmbedCString spec; contentLocation->GetSpec (spec); *_retval = PR_FALSE; /* Allow the load if the protocol is in safe list, or it's about:blank */ if (g_slist_find_custom (mSafeProtocols, scheme.get(), (GCompareFunc) strcmp) - || spec.Equals ("about:blank")) + || strcmp (spec.get(), "about:blank") == 0) { *_retval = PR_TRUE; } @@ -159,4 +158,5 @@ NS_IMETHODIMP EphyContentPolicy::ShouldProcess(PRInt32 contentType, *_retval = PR_TRUE; return NS_OK; } -#endif /* MOZILLA_SNAPSHOT >= 18 */ +#endif /* MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) */ + diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index c4be6e98f..e455f80b9 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -69,10 +69,6 @@ #include <nsIMIMEHeaderParam.h> #include <nsIWindowWatcher.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsReadableUtils.h> -#endif - EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist, nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData) : mPersist(aPersist) @@ -104,7 +100,7 @@ EphyHeaderSniffer::HandleContent () { EphyEmbedSingle *single; gboolean handled = FALSE; - nsCString uriSpec; + nsEmbedCString uriSpec; if (mPostData) return NS_ERROR_FAILURE; @@ -138,7 +134,7 @@ EphyHeaderSniffer::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aReq nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); if (httpChannel) { - httpChannel->GetResponseHeader(nsCAutoString("content-disposition"), + httpChannel->GetResponseHeader(nsEmbedCString("content-disposition"), mContentDisposition); } @@ -218,7 +214,7 @@ filechooser_response_cb (EphyFileChooser *dialog, gint response, EphyHeaderSniff nsCOMPtr<nsILocalFile> destFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); if (destFile) { - destFile->InitWithNativePath (nsDependentCString (filename)); + destFile->InitWithNativePath (nsEmbedCString (filename)); sniffer->InitiateDownload (destFile); } @@ -242,9 +238,9 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); askDownloadDest = flags & EMBED_PERSIST_ASK_DESTINATION; - nsAutoString defaultFileName; + nsEmbedString defaultFileName; - if (defaultFileName.IsEmpty() && !mContentDisposition.IsEmpty()) + if (!defaultFileName.Length() && mContentDisposition.Length()) { /* 1 Use the HTTP header suggestion. */ nsCOMPtr<nsIMIMEHeaderParam> mimehdrpar = @@ -252,45 +248,46 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) if (mimehdrpar) { - nsCAutoString fallbackCharset; + nsEmbedCString fallbackCharset; if (mURL) { mURL->GetOriginCharset(fallbackCharset); } - nsAutoString fileName; + nsEmbedString fileName; rv = mimehdrpar->GetParameter (mContentDisposition, "filename", fallbackCharset, PR_TRUE, nsnull, fileName); - if (NS_FAILED(rv) || fileName.IsEmpty()) + if (NS_FAILED(rv) || !fileName.Length()) { rv = mimehdrpar->GetParameter (mContentDisposition, "name", fallbackCharset, PR_TRUE, nsnull, fileName); } - if (NS_SUCCEEDED(rv) && !fileName.IsEmpty()) + if (NS_SUCCEEDED(rv) && fileName.Length()) { defaultFileName = fileName; } } } - if (defaultFileName.IsEmpty()) + if (!defaultFileName.Length()) { /* 2 For file URLs, use the file name. */ nsCOMPtr<nsIURL> url(do_QueryInterface(mURL)); if (url) { - nsCAutoString fileNameCString; + nsEmbedCString fileNameCString; url->GetFileName(fileNameCString); - CopyUTF8toUTF16 (fileNameCString, defaultFileName); + NS_CStringToUTF16 (fileNameCString, NS_CSTRING_ENCODING_UTF8, + defaultFileName); } } - if (defaultFileName.IsEmpty() && mDocument) + if (!defaultFileName.Length() && mDocument) { /* 3 Use the title of the document. */ @@ -301,22 +298,27 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) } } - if (defaultFileName.IsEmpty() && mURL) + if (!defaultFileName.Length() && mURL) { /* 4 Use the host. */ - nsCAutoString hostName; + nsEmbedCString hostName; mURL->GetHost(hostName); - CopyUTF8toUTF16 (hostName, defaultFileName); + NS_CStringToUTF16 (hostName, NS_CSTRING_ENCODING_UTF8, + defaultFileName); } /* 5 One last case to handle about:blank and other untitled pages. */ - if (defaultFileName.IsEmpty()) + if (!defaultFileName.Length()) { - CopyUTF8toUTF16 (_("Untitled"), defaultFileName); + NS_CStringToUTF16 (nsEmbedCString(_("Untitled")), + NS_CSTRING_ENCODING_UTF8, defaultFileName); } /* Validate the file name to ensure legality. */ - char *default_name = g_strdup (NS_ConvertUTF16toUTF8 (defaultFileName).get()); + nsEmbedCString 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; diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h index 5cef29168..4aa7d1fa8 100644 --- a/embed/mozilla/EphyHeaderSniffer.h +++ b/embed/mozilla/EphyHeaderSniffer.h @@ -49,10 +49,7 @@ #include <nsIDOMDocument.h> #include <nsIAuthPrompt.h> #include <nsIPromptService.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif +#include <nsEmbedString.h> class EphyHeaderSniffer : public nsIWebProgressListener, public nsIAuthPrompt @@ -81,8 +78,8 @@ private: nsCOMPtr<nsIURI> mOriginalURI; nsCOMPtr<nsIDOMDocument> mDocument; nsCOMPtr<nsIInputStream> mPostData; - nsCString mContentType; - nsCString mContentDisposition; + nsEmbedCString mContentType; + nsEmbedCString mContentDisposition; nsCOMPtr<nsIAuthPrompt> mAuthPrompt; }; diff --git a/embed/mozilla/EphySingle.cpp b/embed/mozilla/EphySingle.cpp index 939cc2fd9..1a3791b43 100644 --- a/embed/mozilla/EphySingle.cpp +++ b/embed/mozilla/EphySingle.cpp @@ -27,16 +27,13 @@ #include "ephy-debug.h" +#include <nsEmbedString.h> #include <nsIURI.h> #include <nsIPermissionManager.h> #include <nsICookieManager.h> #include <nsIServiceManager.h> #include <nsICookie2.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif - NS_IMPL_ISUPPORTS1(EphySingle, nsIObserver) EphySingle::EphySingle() @@ -165,7 +162,7 @@ NS_IMETHODIMP EphySingle::Observe(nsISupports *aSubject, nsCOMPtr<nsIURI> uri = do_QueryInterface (aSubject); if (uri) { - nsCAutoString spec; + nsEmbedCString spec; uri->GetSpec (spec); g_signal_emit_by_name (EPHY_COOKIE_MANAGER (mOwner), "cookie-rejected", spec.get()); @@ -219,7 +216,7 @@ mozilla_cookie_to_ephy_cookie (nsICookie *cookie) { EphyCookie *info = ephy_cookie_new (); - nsCAutoString transfer; + nsEmbedCString transfer; cookie->GetHost (transfer); info->domain = g_strdup (transfer.get()); @@ -269,19 +266,19 @@ mozilla_permission_to_ephy_permission (nsIPermission *perm) EphyPermissionType type = (EphyPermissionType) 0; nsresult result; - nsCAutoString str; + nsEmbedCString str; result = perm->GetType(str); NS_ENSURE_SUCCESS (result, NULL); - if (str.Equals ("cookie")) + if (strcmp (str.get(), "cookie") == 0) { type = EPT_COOKIE; } - else if (str.Equals ("image")) + else if (strcmp (str.get(), "image")) { type = EPT_IMAGE; } - else if (str.Equals ("popup")) + else if (strcmp (str.get(), "popup")) { type = EPT_POPUP; } @@ -303,7 +300,7 @@ mozilla_permission_to_ephy_permission (nsIPermission *perm) break; } - nsCString host; + nsEmbedCString host; perm->GetHost(host); return ephy_permission_info_new (host.get(), type, permission); diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp new file mode 100644 index 000000000..aae874091 --- /dev/null +++ b/embed/mozilla/EphyUtils.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#include "EphyUtils.h" + +#include <nsIServiceManager.h> +#include <nsEmbedString.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) +{ + nsEmbedCString cSpec; + NS_UTF16ToCString (spec, NS_CSTRING_ENCODING_UTF8, cSpec); + + return NewURI (result, cSpec); +} + +nsresult EphyUtils::NewURI (nsIURI **result, const nsACString &spec) +{ + nsresult rv; + + nsCOMPtr<nsIIOService> ioService; + rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); + NS_ENSURE_SUCCESS (rv, rv); + + rv = ioService->NewURI (spec, nsnull, nsnull, result); + + return rv; +} diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h new file mode 100644 index 000000000..0fcbe488a --- /dev/null +++ b/embed/mozilla/EphyUtils.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef EPHY_UTILS_H +#define EPHY_UTILS_H + +#include <nsIIOService.h> +#include <nsIURI.h> + +namespace EphyUtils +{ + nsresult GetIOService (nsIIOService **ioService); + + nsresult NewURI (nsIURI **result, const nsAString &spec); + + nsresult NewURI (nsIURI **result, const nsACString &spec); +} + +#endif diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp index d62039f31..1ad257010 100644 --- a/embed/mozilla/EventContext.cpp +++ b/embed/mozilla/EventContext.cpp @@ -24,10 +24,12 @@ #endif #include "EventContext.h" +#include "EphyUtils.h" #include <gdk/gdkkeysyms.h> #include <nsIInterfaceRequestor.h> +#include <nsEmbedString.h> #include <nsIDOMEventTarget.h> #include <nsIDOMHTMLInputElement.h> #include <nsIDOMHTMLObjectElement.h> @@ -41,6 +43,8 @@ #include <nsIDOMHTMLTextAreaElement.h> #include <nsIDOMElementCSSInlineStyle.h> #include <nsIDOMCSSStyleDeclaration.h> +#include <nsIDOM3Node.h> +#include <nsIDOMCSSPrimitiveValue.h> #ifdef ALLOW_PRIVATE_API #include <nsIDOMXULDocument.h> @@ -48,13 +52,6 @@ #include <nsIDOMNSHTMLElement.h> #endif -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsIDocument.h> -#include <nsReadableUtils.h> -#include <nsNetUtil.h> -#endif - - #define KEY_CODE 256 EventContext::EventContext () @@ -73,9 +70,9 @@ nsresult EventContext::Init (EphyBrowser *browser) return NS_OK; } -nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsString& aResult) +nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult) { - nsAutoString text; + nsEmbedString text; nsCOMPtr<nsIDOMNode> node; aNode->GetFirstChild(getter_AddRefs(node)); PRUint32 depth = 1; @@ -89,8 +86,8 @@ nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsString& aResult) if (charData && nodeType == nsIDOMNode::TEXT_NODE) { /* Add this text to our collection. */ - text += NS_LITERAL_STRING(" "); - nsAutoString data; + text += ' '; + nsEmbedString data; charData->GetData(data); text += data; } @@ -99,9 +96,9 @@ nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsString& aResult) nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node)); if (img) { - nsAutoString altText; + nsEmbedString altText; img->GetAlt(altText); - if (!altText.IsEmpty()) + if (altText.Length()) { text = altText; break; @@ -145,40 +142,29 @@ nsresult EventContext::GatherTextUnder (nsIDOMNode* aNode, nsString& aResult) } } - text.CompressWhitespace(); + /* FIXME we should trim spaces here */ + aResult = text; return NS_OK; } -nsresult EventContext::ResolveBaseURL (nsIDocument *doc, const nsAString &relurl, nsACString &url) +nsresult EventContext::ResolveBaseURL (const nsAString &relurl, nsACString &url) { -#if MOZILLA_SNAPSHOT > 13 - nsIURI *base; - base = doc->GetBaseURI (); - if (!base) return NS_ERROR_FAILURE; -#elif MOZILLA_SNAPSHOT > 11 - nsIURI *base; - base = doc->GetBaseURL (); - if (!base) return NS_ERROR_FAILURE; -#endif + nsresult rv; - return base->Resolve (NS_ConvertUTF16toUTF8(relurl), url); -} + nsCOMPtr<nsIDOM3Node> node(do_QueryInterface (mDOMDocument)); + nsEmbedString spec; + node->GetBaseURI (spec); -nsresult EventContext::ResolveDocumentURL (nsIDocument *doc, const nsAString &relurl, nsACString &url) -{ -#if MOZILLA_SNAPSHOT > 13 - nsIURI *uri; - uri = doc->GetDocumentURI (); - if (!uri) return NS_ERROR_FAILURE; -#elif MOZILLA_SNAPSHOT > 11 - nsIURI *uri; - uri = doc->GetDocumentURL (); - if (!uri) return NS_ERROR_FAILURE; -#endif + nsCOMPtr<nsIURI> base; + rv = EphyUtils::NewURI (getter_AddRefs(base), spec); + if (!base) return NS_ERROR_FAILURE; + + nsEmbedCString cRelURL; + NS_UTF16ToCString (relurl, NS_CSTRING_ENCODING_UTF8, cRelURL); - return uri->Resolve (NS_ConvertUTF16toUTF8(relurl), url); + return base->Resolve (cRelURL, url); } nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, @@ -186,6 +172,15 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, { nsresult rv; + const PRUnichar bgLiteral[] = {'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', + 'n', 'd', '\0'}; + const PRUnichar hrefLiteral[] = {'h', 'r', 'e', 'f', '\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'}; + mEmbedEvent = info; info->context = EMBED_CONTEXT_DOCUMENT; @@ -205,9 +200,6 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, mDOMDocument = domDoc; - nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv); - if (NS_FAILED(rv) || !doc) return NS_ERROR_FAILURE; - nsCOMPtr<nsIDOMXULDocument> xul_document = do_QueryInterface(domDoc); if (xul_document) { @@ -225,15 +217,18 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(node); if ((nsIDOMNode::ELEMENT_NODE == type) && element) { - nsAutoString tag; - rv = element->GetTagName(tag); + nsEmbedString uTag; + rv = element->GetTagName(uTag); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - if (tag.EqualsIgnoreCase("img")) + nsEmbedCString tag; + NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag); + + if (g_ascii_strcasecmp (tag.get(), "img") == 0) { info->context |= EMBED_CONTEXT_IMAGE; - nsAutoString img; + nsEmbedString img; nsCOMPtr <nsIDOMHTMLImageElement> image = do_QueryInterface(node, &rv); if (NS_FAILED(rv) || !image) return NS_ERROR_FAILURE; @@ -241,98 +236,73 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, rv = image->GetSrc (img); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; SetStringProperty ("image", img); - - rv = image->GetAlt (img); - if (NS_SUCCEEDED(rv)) - { - SetStringProperty ("image_alt", img); - } - - rv = image->GetLongDesc (img); - if (NS_SUCCEEDED(rv) && !img.IsEmpty()) - { - nsCAutoString imglongdesc; - rv = ResolveDocumentURL (doc, img, imglongdesc); - - SetStringProperty ("image_long_desc", - NS_ConvertUTF8toUTF16(imglongdesc)); - } - - int imgwidth, imgheight; - rv = image->GetWidth (&imgwidth); - rv = image->GetHeight (&imgheight); - SetIntProperty ("image_width", imgwidth); - SetIntProperty ("image_height", imgheight); - - rv = element->GetTitle (img); - if (NS_SUCCEEDED(rv)) - { - SetStringProperty ("image_title", - img); - } } - else if (tag.EqualsIgnoreCase("input")) + else if (g_ascii_strcasecmp (tag.get(), "input") == 0) { nsCOMPtr<nsIDOMElement> element; element = do_QueryInterface (node); if (!element) return NS_ERROR_FAILURE; - NS_NAMED_LITERAL_STRING(attr, "type"); - nsAutoString value; - element->GetAttribute (attr, value); + nsEmbedString uValue; + element->GetAttribute (nsEmbedString(typeLiteral), uValue); + + nsEmbedCString value; + NS_UTF16ToCString (uValue, NS_CSTRING_ENCODING_UTF8, value); - if (value.EqualsIgnoreCase("image")) + if (g_ascii_strcasecmp (value.get(), "image") == 0) { info->context |= EMBED_CONTEXT_IMAGE; nsCOMPtr<nsIDOMHTMLInputElement> input; input = do_QueryInterface (node); if (!input) return NS_ERROR_FAILURE; - nsAutoString img; + nsEmbedString img; rv = input->GetSrc (img); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - nsCAutoString cImg; - rv = ResolveDocumentURL (doc, img, cImg); + nsEmbedCString cImg; + rv = ResolveBaseURL (img, cImg); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - SetStringProperty ("image", - NS_ConvertUTF8toUTF16(cImg)); + SetStringProperty ("image", cImg.get()); } - else if (!value.EqualsIgnoreCase("radio") && - !value.EqualsIgnoreCase("submit") && - !value.EqualsIgnoreCase("reset") && - !value.EqualsIgnoreCase("hidden") && - !value.EqualsIgnoreCase("button") && - !value.EqualsIgnoreCase("checkbox")) + 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) { info->context |= EMBED_CONTEXT_INPUT; } } - else if (tag.EqualsIgnoreCase("textarea")) + else if (g_ascii_strcasecmp (tag.get(), "textarea") == 0) { info->context |= EMBED_CONTEXT_INPUT; } - else if (tag.EqualsIgnoreCase("object")) + else if (g_ascii_strcasecmp (tag.get(), "object") == 0) { nsCOMPtr<nsIDOMHTMLObjectElement> object; object = do_QueryInterface (node); if (!element) return NS_ERROR_FAILURE; - nsAutoString value; + nsEmbedString value; object->GetType(value); + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); + // MIME types are always lower case - if (Substring (value, 0, 6).Equals(NS_LITERAL_STRING("image/"))) + if (g_str_has_prefix (cValue.get(), "image/")) { info->context |= EMBED_CONTEXT_IMAGE; - nsAutoString img; + nsEmbedString img; rv = object->GetData (img); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - nsCAutoString cImg; - rv = ResolveDocumentURL (doc, img, cImg); + nsEmbedCString cImg; + rv = ResolveBaseURL (img, cImg); if (NS_FAILED (rv)) return NS_ERROR_FAILURE; SetStringProperty ("image", cImg.get()); @@ -356,17 +326,18 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, nsCOMPtr <nsIDOMElement> dom_elem = do_QueryInterface(node); if (dom_elem) { - NS_NAMED_LITERAL_STRING(nspace, "http://www.w3.org/1999/xlink"); - NS_NAMED_LITERAL_STRING(localname_type, "type"); + nsEmbedString value; + dom_elem->GetAttributeNS (nsEmbedString(xlinknsLiteral), + nsEmbedString(typeLiteral), value); - nsAutoString value; - dom_elem->GetAttributeNS (nspace, localname_type, value); + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); - if (value.EqualsIgnoreCase("simple")) + if (g_ascii_strcasecmp (cValue.get(), "simple") == 0) { info->context |= EMBED_CONTEXT_LINK; - NS_NAMED_LITERAL_STRING (localname_href, "href"); - dom_elem->GetAttributeNS (nspace, localname_href, value); + dom_elem->GetAttributeNS (nsEmbedString(xlinknsLiteral), + nsEmbedString(hrefLiteral), value); SetStringProperty ("link", value); CheckLinkScheme (value); @@ -380,15 +351,17 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, element = do_QueryInterface(node); if ((nsIDOMNode::ELEMENT_NODE == type) && element) { - nsAutoString tag; - rv = element->GetTagName(tag); + nsEmbedString uTag; + rv = element->GetTagName(uTag); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + nsEmbedCString tag; + NS_UTF16ToCString (uTag, NS_CSTRING_ENCODING_UTF8, tag); + /* Link */ - if (tag.EqualsIgnoreCase("a")) + if (g_ascii_strcasecmp (tag.get(), "a") == 0) { - nsAutoString tmp; - nsAutoString substr; + nsEmbedString tmp; rv = GatherTextUnder (node, tmp); if (NS_SUCCEEDED(rv)) @@ -397,16 +370,18 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, nsCOMPtr <nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(node); + nsEmbedCString href; anchor->GetHref (tmp); - substr.Assign (Substring (tmp, 0, 7)); - if (substr.EqualsIgnoreCase("mailto:")) + NS_UTF16ToCString (tmp, NS_CSTRING_ENCODING_UTF8, href); + + if (g_str_has_prefix (href.get(), "mailto:")) { info->context |= EMBED_CONTEXT_EMAIL_LINK; - const nsAString &address = Substring(tmp, 7, tmp.Length()-7); - SetStringProperty ("email", address); + href.Cut (0, 7); + SetStringProperty ("email", href.get()); } - if (anchor && !tmp.IsEmpty()) + if (anchor && tmp.Length()) { info->context |= EMBED_CONTEXT_LINK; @@ -431,7 +406,10 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (NS_SUCCEEDED(rv)) SetStringProperty ("link_type", tmp); - if (tmp.EqualsIgnoreCase("text/smartbookmark")) + nsEmbedCString linkType; + NS_UTF16ToCString (tmp, NS_CSTRING_ENCODING_UTF8, linkType); + + if (g_ascii_strcasecmp (linkType.get(), "text/smartbookmark") == 0) { SetIntProperty ("link_is_smart", TRUE); @@ -444,7 +422,7 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (image) { - nsAutoString img; + nsEmbedString img; rv = image->GetSrc (img); if (!NS_FAILED(rv)) { @@ -460,19 +438,19 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, } } - else if (tag.EqualsIgnoreCase("option")) + else if (g_ascii_strcasecmp (tag.get(), "option") == 0) { info->context = EMBED_CONTEXT_NONE; return NS_OK; } - if (tag.EqualsIgnoreCase("area")) + if (g_ascii_strcasecmp (tag.get(), "area") == 0) { info->context |= EMBED_CONTEXT_LINK; nsCOMPtr <nsIDOMHTMLAreaElement> area = do_QueryInterface(node, &rv); if (NS_SUCCEEDED(rv) && area) { - nsAutoString href; + nsEmbedString href; rv = area->GetHref (href); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; @@ -481,8 +459,8 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, CheckLinkScheme (href); } } - else if (tag.EqualsIgnoreCase("textarea") || - tag.EqualsIgnoreCase("input")) + else if (g_ascii_strcasecmp (tag.get(), "textarea") == 0 || + g_ascii_strcasecmp (tag.get(), "input") == 0) { info->context |= EMBED_CONTEXT_INPUT; } @@ -493,15 +471,14 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, PRBool has_background = PR_FALSE; - NS_NAMED_LITERAL_STRING(attr, "background"); - nsAutoString value; - domelement->GetAttribute (attr, value); + nsEmbedString value; + domelement->GetAttribute (nsEmbedString(bgLiteral), value); - if (!value.IsEmpty()) + if (value.Length()) { - nsCAutoString bgimg; + nsEmbedCString bgimg; - rv = ResolveDocumentURL (doc, value, bgimg); + rv = ResolveBaseURL (value, bgimg); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; SetStringProperty ("background_image", bgimg.get()); @@ -512,14 +489,14 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, bgelement = do_QueryInterface (node); if (bgelement) { - nsAutoString value; + nsEmbedString value; bgelement->GetBackground (value); - if (!value.IsEmpty()) + if (value.Length()) { - nsCAutoString bgimg; + nsEmbedCString bgimg; - rv = ResolveBaseURL (doc, value, bgimg); + rv = ResolveBaseURL (value, bgimg); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; @@ -532,13 +509,13 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (!has_background) { - nsAutoString cssurl; + nsEmbedString cssurl; rv = GetCSSBackground (node, cssurl); if (NS_SUCCEEDED (rv)) { - nsCAutoString bgimg; + nsEmbedCString bgimg; - rv = ResolveBaseURL (doc, cssurl, bgimg); + rv = ResolveBaseURL (cssurl, bgimg); if (NS_FAILED (rv)) return NS_ERROR_FAILURE; SetStringProperty ("background_image", @@ -557,10 +534,13 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, return NS_OK; } -nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAutoString& url) +nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAString& url) { nsresult result; + const PRUnichar bgimage[] = {'b', 'a', 'c', 'k', 'g', 'r', 'o', 'u', 'n', 'd', + '-', 'i', 'm', 'a', 'g', 'e', '\0'}; + nsCOMPtr<nsIDOMElementCSSInlineStyle> style; style = do_QueryInterface (node); if (!style) return NS_ERROR_FAILURE; @@ -569,36 +549,15 @@ nsresult EventContext::GetCSSBackground (nsIDOMNode *node, nsAutoString& url) result = style->GetStyle (getter_AddRefs(decl)); if (NS_FAILED(result)) return NS_ERROR_FAILURE; - nsAutoString value; - NS_NAMED_LITERAL_STRING(prop_bgi, "background-image"); - decl->GetPropertyValue (prop_bgi, value); - - if (value.IsEmpty()) - { - NS_NAMED_LITERAL_STRING(prop_bg, "background"); - decl->GetPropertyValue (prop_bg, value); - if (value.IsEmpty()) - { - NS_NAMED_LITERAL_STRING(prop_bgr, "background-repeat"); - decl->GetPropertyValue (prop_bgr, value); - if (value.IsEmpty()) - return NS_ERROR_FAILURE; - } - } + nsCOMPtr<nsIDOMCSSValue> cssValue; + decl->GetPropertyCSSValue (nsEmbedString(bgimage), + getter_AddRefs(cssValue)); + nsCOMPtr<nsIDOMCSSPrimitiveValue> primitiveValue; - PRInt32 start, end; - nsAutoString cssurl; + primitiveValue = do_QueryInterface(cssValue); + if (!primitiveValue) return NS_ERROR_FAILURE; - NS_NAMED_LITERAL_STRING(startsub, "url("); - NS_NAMED_LITERAL_STRING(endsub, ")"); - - start = value.Find (startsub) + 4; - end = value.Find (endsub); - - if (start == -1 || end == -1) - return NS_ERROR_FAILURE; - - url.Assign(Substring (value, start, end - start)); + primitiveValue->GetStringValue(url); return NS_OK; } @@ -643,14 +602,16 @@ nsresult EventContext::GetMouseEventInfo (nsIDOMMouseEvent *aMouseEvent, Mozilla nsCOMPtr<nsIDOMNode> OriginalNode = do_QueryInterface(OriginalTarget); if (!OriginalNode) return NS_ERROR_FAILURE; - nsAutoString nodename; + nsEmbedString nodename; OriginalNode->GetNodeName(nodename); - - if (nodename.EqualsIgnoreCase("xul:scrollbarbutton") || - nodename.EqualsIgnoreCase("xul:thumb") || - nodename.EqualsIgnoreCase("xul:vbox") || - nodename.EqualsIgnoreCase("xul:spacer") || - nodename.EqualsIgnoreCase("xul:slider")) + nsEmbedCString 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; @@ -772,22 +733,22 @@ nsresult EventContext::GetTargetDocument (nsIDOMDocument **domDoc) nsresult EventContext::CheckLinkScheme (const nsAString &link) { nsCOMPtr<nsIURI> uri; - NS_NewURI (getter_AddRefs (uri), link); + EphyUtils::NewURI (getter_AddRefs (uri), link); if (!uri) return NS_ERROR_FAILURE; nsresult rv; - nsCAutoString scheme; + nsEmbedCString scheme; rv = uri->GetScheme (scheme); if (NS_FAILED (rv)) return NS_ERROR_FAILURE; - if (scheme.EqualsIgnoreCase ("http") || - scheme.EqualsIgnoreCase ("https") || - scheme.EqualsIgnoreCase ("ftp") || - scheme.EqualsIgnoreCase ("file") || - scheme.EqualsIgnoreCase ("data") || - scheme.EqualsIgnoreCase ("resource") || - scheme.EqualsIgnoreCase ("about") || - scheme.EqualsIgnoreCase ("gopher")) + if (g_ascii_strcasecmp (scheme.get(), "http") || + g_ascii_strcasecmp (scheme.get(), "https") || + g_ascii_strcasecmp (scheme.get(), "ftp") || + g_ascii_strcasecmp (scheme.get(), "file") || + g_ascii_strcasecmp (scheme.get(), "data") || + g_ascii_strcasecmp (scheme.get(), "resource") || + g_ascii_strcasecmp (scheme.get(), "about") || + g_ascii_strcasecmp (scheme.get(), "gopher")) { SetIntProperty ("link-has-web-scheme", TRUE); } @@ -824,5 +785,7 @@ nsresult EventContext::SetStringProperty (const char *name, const char *value) nsresult EventContext::SetStringProperty (const char *name, const nsAString &value) { - return SetStringProperty (name, NS_ConvertUTF16toUTF8(value).get()); + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); + return SetStringProperty (name, cValue.get()); } diff --git a/embed/mozilla/EventContext.h b/embed/mozilla/EventContext.h index 41fc1dfcb..efc05322b 100644 --- a/embed/mozilla/EventContext.h +++ b/embed/mozilla/EventContext.h @@ -35,39 +35,32 @@ #include <nsIDOMHTMLBodyElement.h> #include <nsIDOMDocument.h> -#ifdef ALLOW_PRIVATE_API -#include <nsIDocument.h> -#include <nsString.h> -#endif - class EventContext { public: EventContext(); ~EventContext(); - nsresult Init (EphyBrowser *wrapper); - + nsresult Init (EphyBrowser *wrapper); nsresult GetMouseEventInfo (nsIDOMMouseEvent *event, MozillaEmbedEvent *info); - nsresult GetKeyEventInfo (nsIDOMKeyEvent *event, MozillaEmbedEvent *info); + nsresult GetKeyEventInfo (nsIDOMKeyEvent *event, MozillaEmbedEvent *info); nsresult GetTargetDocument (nsIDOMDocument **domDoc); private: EphyBrowser *mBrowser; + MozillaEmbedEvent *mEmbedEvent; nsCOMPtr<nsIDOMDocument> mDOMDocument; - nsresult GatherTextUnder (nsIDOMNode* aNode, nsString& aResult); - nsresult ResolveBaseURL (nsIDocument *doc, const nsAString &relurl, nsACString &url); - nsresult ResolveDocumentURL (nsIDocument *doc, const nsAString &relurl, nsACString &url); - nsresult GetEventContext (nsIDOMEventTarget *EventTarget, - MozillaEmbedEvent *info); - nsresult GetCSSBackground (nsIDOMNode *node, nsAutoString& url); - nsresult IsPageFramed (nsIDOMNode *node, PRBool *Framed); - 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); - MozillaEmbedEvent *mEmbedEvent; + nsresult GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult); + nsresult ResolveBaseURL (const nsAString &relurl, nsACString &url); + nsresult GetEventContext (nsIDOMEventTarget *EventTarget, + MozillaEmbedEvent *info); + nsresult GetCSSBackground (nsIDOMNode *node, nsAString& url); + nsresult IsPageFramed (nsIDOMNode *node, PRBool *Framed); + 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); }; #endif diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index 29756b15b..4771c910c 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -26,7 +26,10 @@ #include "FilePicker.h" #include "MozillaPrivate.h" +#include "mozilla-version.h" + #include <nsCOMPtr.h> +#include <nsEmbedString.h> #include <nsIServiceManager.h> #include <nsIURI.h> #include <nsIFileURL.h> @@ -35,12 +38,7 @@ #include <nsIDOMWindow.h> #include <nsNetCID.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#include <nsReadableUtils.h> -#endif - -#if MOZILLA_SNAPSHOT < 18 +#if !MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) #include <nsIDOMWindowInternal.h> #endif @@ -82,10 +80,10 @@ GFilePicker::~GFilePicker() } /* void init (in nsIDOMWindow parent, in AString title, in short mode); */ -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *title, PRInt16 mode) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::Init(nsIDOMWindow *parent, const nsAString& title, PRInt16 mode) +#else +NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *title, PRInt16 mode) #endif { LOG ("GFilePicker::Init") @@ -97,11 +95,13 @@ NS_IMETHODIMP GFilePicker::Init(nsIDOMWindow *parent, const nsAString& title, PR gtk_window_set_transient_for (GTK_WINDOW (mDialog), GTK_WINDOW (pwin)); } -#if MOZILLA_SNAPSHOT < 18 - gtk_window_set_title (GTK_WINDOW (mDialog), NS_ConvertUTF16toUTF8 (title).get()); + nsEmbedCString cTitle; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + NS_UTF16ToCString (title, NS_CSTRING_ENCODING_UTF8, cTitle); #else - gtk_window_set_title (GTK_WINDOW (mDialog), NS_ConvertUCS2toUTF8(title).get()); + NS_UTF16ToCString (nsEmbedString(title), NS_CSTRING_ENCODING_UTF8, cTitle); #endif + gtk_window_set_title (GTK_WINDOW (mDialog), cTitle.get()); mMode = mode; @@ -200,20 +200,24 @@ NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 filterMask) } /* void appendFilter (in AString title, in AString filter); */ -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *title, const PRUnichar *filter) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::AppendFilter(const nsAString& title, const nsAString& filter) +#else +NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *title, const PRUnichar *filter) #endif { - LOG ("GFilePicker::AppendFilter title '%s' for '%s'", - NS_ConvertUTF16toUTF8 (title).get(), - NS_ConvertUTF16toUTF8 (filter).get()) - - NS_ConvertUTF16toUTF8 pattern(filter); +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + if (!filter.Length()) return NS_ERROR_FAILURE; +#else + if (!filter) return NS_ERROR_FAILURE; +#endif - pattern.StripWhitespace(); - if (pattern.IsEmpty()) return NS_ERROR_FAILURE; + nsEmbedCString pattern; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + NS_UTF16ToCString (filter, NS_CSTRING_ENCODING_UTF8, pattern); +#else + NS_UTF16ToCString (nsEmbedString(filter), NS_CSTRING_ENCODING_UTF8, pattern); +#endif char **patterns; patterns = g_strsplit (pattern.get(), ";", -1); @@ -224,10 +228,17 @@ NS_IMETHODIMP GFilePicker::AppendFilter(const nsAString& title, const nsAString& for (int i = 0; patterns[i] != NULL; i++) { - gtk_file_filter_add_pattern (filth, patterns[i]); + gtk_file_filter_add_pattern (filth, g_strstrip (patterns[i])); } - gtk_file_filter_set_name (filth, NS_ConvertUTF16toUTF8 (title).get()); + nsEmbedCString cTitle; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + NS_UTF16ToCString (title, NS_CSTRING_ENCODING_UTF8, cTitle); +#else + NS_UTF16ToCString (nsEmbedString(title), NS_CSTRING_ENCODING_UTF8, cTitle); +#endif + + gtk_file_filter_set_name (filth, cTitle.get()); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (mDialog), filth); @@ -237,10 +248,10 @@ NS_IMETHODIMP GFilePicker::AppendFilter(const nsAString& title, const nsAString& } /* attribute AString defaultString; */ -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::GetDefaultString(nsAString& aDefaultString) +#else +NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString) #endif { char *filename, *converted; @@ -252,10 +263,14 @@ NS_IMETHODIMP GFilePicker::GetDefaultString(nsAString& aDefaultString) { converted = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); -#if MOZILLA_SNAPSHOT < 18 - *aDefaultString = ToNewUnicode (NS_ConvertUTF8toUTF16 (converted)); + nsEmbedString defaultString; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + NS_CStringToUTF16 (nsEmbedCString(converted), + NS_CSTRING_ENCODING_UTF8, aDefaultString); #else - CopyUTF8toUTF16 (converted, aDefaultString); + NS_CStringToUTF16 (nsEmbedCString(converted), + NS_CSTRING_ENCODING_UTF8, defaultString); + *aDefaultString = NS_StringCloneData (defaultString); #endif g_free (filename); @@ -265,40 +280,39 @@ NS_IMETHODIMP GFilePicker::GetDefaultString(nsAString& aDefaultString) return NS_OK; } -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::SetDefaultString(const nsAString& aDefaultString) +#else +NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString) #endif { -#if MOZILLA_SNAPSHOT < 18 - LOG ("GFilePicker::SetDefaultString to %s", - NS_ConvertUTF16toUTF8 (aDefaultString).get()) +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + if (aDefaultString.Length()) #else - LOG ("GFilePicker::SetDefaultString to %s", - NS_ConvertUCS2toUTF8 (aDefaultString).get()) -#endif - -#if MOZILLA_SNAPSHOT < 18 if (aDefaultString) -#else - if (aDefaultString.Length()) #endif { + nsEmbedCString defaultString; +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + NS_UTF16ToCString (aDefaultString, NS_CSTRING_ENCODING_UTF8, + defaultString); +#else + NS_UTF16ToCString (nsEmbedString(aDefaultString), + NS_CSTRING_ENCODING_UTF8, defaultString); +#endif /* set_current_name takes UTF-8, not a filename */ gtk_file_chooser_set_current_name - (GTK_FILE_CHOOSER (mDialog), - NS_ConvertUTF16toUTF8 (aDefaultString).get()); + (GTK_FILE_CHOOSER (mDialog), defaultString.get()); } return NS_OK; } /* attribute AString defaultExtension; */ -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar **aDefaultExtension) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::GetDefaultExtension(nsAString& aDefaultExtension) +#else +NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar **aDefaultExtension) #endif { LOG ("GFilePicker::GetDefaultExtension") @@ -306,15 +320,12 @@ NS_IMETHODIMP GFilePicker::GetDefaultExtension(nsAString& aDefaultExtension) return NS_ERROR_NOT_IMPLEMENTED; } -#if MOZILLA_SNAPSHOT < 18 -NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension) -#else +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) NS_IMETHODIMP GFilePicker::SetDefaultExtension(const nsAString& aDefaultExtension) +#else +NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension) #endif { - LOG ("GFilePicker::SetDefaultExtension to %s", - NS_ConvertUTF16toUTF8(aDefaultExtension).get()) - return NS_ERROR_NOT_IMPLEMENTED; } @@ -345,7 +356,7 @@ NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory) if (dir != NULL) { nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - file->InitWithNativePath (nsDependentCString (dir)); + file->InitWithNativePath (nsEmbedCString (dir)); NS_IF_ADDREF (*aDisplayDirectory = file); g_free (dir); @@ -356,7 +367,7 @@ NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory) NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory) { - nsCAutoString dir; + nsEmbedCString dir; aDisplayDirectory->GetNativePath (dir); LOG ("GFilePicker::SetDisplayDirectory to %s", dir.get()) @@ -379,7 +390,7 @@ NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile **aFile) if (filename != NULL) { nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - file->InitWithNativePath (nsDependentCString (filename)); + file->InitWithNativePath (nsEmbedCString (filename)); NS_IF_ADDREF (*aFile = file); g_free (filename); diff --git a/embed/mozilla/GlobalHistory.cpp b/embed/mozilla/GlobalHistory.cpp index 4e65161ff..d96417a69 100644 --- a/embed/mozilla/GlobalHistory.cpp +++ b/embed/mozilla/GlobalHistory.cpp @@ -28,16 +28,9 @@ #include "GlobalHistory.h" #include <nsIURI.h> +#include <nsEmbedString.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif - -#if MOZILLA_SNAPSHOT > 13 NS_IMPL_ISUPPORTS2(MozGlobalHistory, nsIGlobalHistory2, nsIBrowserHistory) -#else -NS_IMPL_ISUPPORTS2(MozGlobalHistory, nsIGlobalHistory, nsIBrowserHistory) -#endif MozGlobalHistory::MozGlobalHistory () { @@ -48,13 +41,54 @@ MozGlobalHistory::~MozGlobalHistory () { } -#if MOZILLA_SNAPSHOT > 13 - /* void addURI (in nsIURI aURI, in boolean aRedirect, in boolean aToplevel); */ NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aToplevel) { - nsCAutoString spec; - aURI->GetSpec(spec); + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + PRBool isJavascript; + rv = aURI->SchemeIs("javascript", &isJavascript); + NS_ENSURE_SUCCESS(rv, rv); + + if (isJavascript || aRedirect || !aToplevel) + { + return NS_OK; + } + + // 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; + PRBool isHTTPS = PR_FALSE; + + rv = aURI->SchemeIs("http", &isHTTP); + rv |= aURI->SchemeIs("https", &isHTTPS); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + if (!isHTTP && !isHTTPS) + { + PRBool isAbout, isViewSource, isChrome, isData; + + rv = aURI->SchemeIs("about", &isAbout); + rv |= aURI->SchemeIs("view-source", &isViewSource); + rv |= aURI->SchemeIs("chrome", &isChrome); + rv |= aURI->SchemeIs("data", &isData); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + if (isAbout || isViewSource || isChrome || isData) + { + return NS_OK; + } + } + + nsEmbedCString spec; + rv = aURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); ephy_history_add_page (mGlobalHistory, spec.get()); @@ -64,7 +98,7 @@ NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aT /* boolean isVisited (in nsIURI aURI); */ NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval) { - nsCAutoString spec; + nsEmbedCString spec; aURI->GetSpec(spec); *_retval = ephy_history_is_page_visited (mGlobalHistory, spec.get()); @@ -75,13 +109,14 @@ NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval) /* void setPageTitle (in nsIURI aURI, in AString aTitle); */ NS_IMETHODIMP MozGlobalHistory::SetPageTitle(nsIURI *aURI, const nsAString & aTitle) { - const nsACString &title = NS_ConvertUTF16toUTF8(aTitle); + nsEmbedCString title; + NS_UTF16ToCString (nsEmbedString (aTitle), + NS_CSTRING_ENCODING_UTF8, title); - nsCAutoString spec; + nsEmbedCString spec; aURI->GetSpec(spec); - ephy_history_set_page_title (mGlobalHistory, spec.get(), - PromiseFlatCString(title).get()); + ephy_history_set_page_title (mGlobalHistory, spec.get(), title.get()); return NS_OK; } @@ -92,43 +127,6 @@ NS_IMETHODIMP MozGlobalHistory::HidePage(nsIURI *url) return NS_ERROR_NOT_IMPLEMENTED; } -#else - -/* void addPage (in string aURL); */ -NS_IMETHODIMP MozGlobalHistory::AddPage (const char *aURL) -{ - ephy_history_add_page (mGlobalHistory, aURL); - - return NS_OK; -} - -/* boolean isVisited (in string aURL); */ -NS_IMETHODIMP MozGlobalHistory::IsVisited (const char *aURL, PRBool *_retval) -{ - *_retval = ephy_history_is_page_visited (mGlobalHistory, aURL); - - return NS_OK; -} - -/* void setPageTitle (in string aURL, in wstring aTitle); */ -NS_IMETHODIMP MozGlobalHistory::SetPageTitle (const char *aURL, - const PRUnichar *aTitle) -{ - const nsACString &title = NS_ConvertUTF16toUTF8 (aTitle); - - ephy_history_set_page_title (mGlobalHistory, aURL, PromiseFlatCString(title).get()); - - /* done */ - return NS_OK; -} - -NS_IMETHODIMP MozGlobalHistory::HidePage(const char *url) -{ - return NS_ERROR_NOT_IMPLEMENTED; - -} -#endif /* MOZILLA_SNAPSHOT > 13 */ - /* void removePage (in string aURL); */ NS_IMETHODIMP MozGlobalHistory::RemovePage(const char *aURL) { @@ -148,26 +146,11 @@ NS_IMETHODIMP MozGlobalHistory::RemoveAllPages() return NS_ERROR_NOT_IMPLEMENTED; } -#if MOZILLA_SNAPSHOT > 14 /* readonly attribute AUTF8String lastPageVisited; */ NS_IMETHODIMP MozGlobalHistory::GetLastPageVisited(nsACString & aLastPageVisited) { return NS_ERROR_NOT_IMPLEMENTED; } -#else -/* readonly attribute string lastPageVisited; */ -NS_IMETHODIMP MozGlobalHistory::GetLastPageVisited(char **aLastPageVisited) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -#endif - -#if MOZILLA_SNAPSHOT < 14 -NS_IMETHODIMP MozGlobalHistory::SetLastPageVisited(const char *aLastPageVisited) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -#endif /* readonly attribute PRUint32 count; */ NS_IMETHODIMP MozGlobalHistory::GetCount(PRUint32 *aCount) diff --git a/embed/mozilla/GlobalHistory.h b/embed/mozilla/GlobalHistory.h index 3b0bab389..883b9e8db 100644 --- a/embed/mozilla/GlobalHistory.h +++ b/embed/mozilla/GlobalHistory.h @@ -29,11 +29,7 @@ #include "ephy-history.h" #include <nsIBrowserHistory.h> -#if MOZILLA_SNAPSHOT > 13 #include <nsIGlobalHistory2.h> -#else -#include <nsIGlobalHistory.h> -#endif #define EPHY_GLOBALHISTORY_CLASSNAME "Epiphany Global History Implementation" @@ -44,22 +40,14 @@ { 0xb7, 0x9e, 0xf7, 0xaa, 0x49, 0xeb, 0x6a, 0x15} \ } -class MozGlobalHistory: -#if MOZILLA_SNAPSHOT <= 13 - public nsIGlobalHistory, -#endif - public nsIBrowserHistory +class MozGlobalHistory: public nsIBrowserHistory { public: MozGlobalHistory (); virtual ~MozGlobalHistory(); NS_DECL_ISUPPORTS -#if MOZILLA_SNAPSHOT > 13 NS_DECL_NSIGLOBALHISTORY2 -#else - NS_DECL_NSIGLOBALHISTORY -#endif NS_DECL_NSIBROWSERHISTORY private: diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp index ca258edaf..1ff07e953 100644 --- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp +++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp @@ -31,9 +31,7 @@ #include <nsIServiceManager.h> #include <nsIInterfaceRequestor.h> #include <nsIInterfaceRequestorUtils.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#endif +#include <nsEmbedString.h> #include <gtk/gtkdialog.h> #include <gtk/gtkimage.h> @@ -188,9 +186,10 @@ GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - const nsACString &utf8_cn = NS_ConvertUTF16toUTF8(cn); - tt_cn = g_strdup_printf ("\"<tt>%s</tt>\"", - PromiseFlatCString(utf8_cn).get()); + nsEmbedCString utf8_cn; + NS_UTF16ToCString (nsEmbedString (cn), + NS_CSTRING_ENCODING_UTF8, utf8_cn); + tt_cn = g_strdup_printf ("\"<tt>%s</tt>\"", utf8_cn.get()); msg = g_strdup_printf (_("Choose a certificate to present as identification to %s."), tt_cn); @@ -206,13 +205,18 @@ GtkNSSClientAuthDialogs::ChooseCertificate (nsIInterfaceRequestor *ctx, store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); for (i = 0; i < count; i++) { - const nsACString &certnick = NS_ConvertUTF16toUTF8(certNickList[i]); - const nsACString &certdetail = NS_ConvertUTF16toUTF8(certDetailsList[i]); + nsEmbedCString certnick; + nsEmbedCString certdetail; + + NS_UTF16ToCString (nsEmbedString (certNickList[i]), + NS_CSTRING_ENCODING_UTF8, certnick); + NS_UTF16ToCString (nsEmbedString (certDetailsList[i]), + NS_CSTRING_ENCODING_UTF8, certdetail); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, - 0, PromiseFlatCString(certnick).get(), - 1, PromiseFlatCString(certdetail).get(), + 0, certnick.get(), + 1, certdetail.get(), -1); } diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp index b127be568..1bd1a88e6 100644 --- a/embed/mozilla/GtkNSSDialogs.cpp +++ b/embed/mozilla/GtkNSSDialogs.cpp @@ -35,6 +35,7 @@ #include "MozillaPrivate.h" #include <nsCOMPtr.h> +#include <nsMemory.h> #include <nsIServiceManager.h> #include <nsIInterfaceRequestor.h> #include <nsIInterfaceRequestorUtils.h> @@ -46,11 +47,7 @@ #include <nsICRLInfo.h> #include <nsISimpleEnumerator.h> #include <nsIArray.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsReadableUtils.h> -#include <nsString.h> -#endif +#include <nsEmbedString.h> #include <gconf/gconf-client.h> #include <gtk/gtkdialog.h> @@ -284,17 +281,20 @@ GtkNSSDialogs::ConfirmMismatchDomain (nsIInterfaceRequestor *ctx, const nsACString &targetURL, nsIX509Cert *cert, PRBool *_retval) { - nsAutoString commonName; char *ttTargetUrl, *ttCommonName, *first, *second, *msg; int res; + nsEmbedString commonName; cert->GetCommonName (commonName); + nsEmbedCString cCommonName; + NS_UTF16ToCString (commonName, + NS_CSTRING_ENCODING_UTF8, cCommonName); + ttTargetUrl = g_strdup_printf ("\"<tt>%s</tt>\"", - PromiseFlatCString(targetURL).get()); + nsEmbedCString(targetURL).get()); - ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", - NS_ConvertUTF16toUTF8(commonName).get()); + ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", cCommonName.get()); first = g_strdup_printf (_("The site %s returned security information for " "%s. It is possible that someone is intercepting " @@ -329,14 +329,17 @@ GtkNSSDialogs::ConfirmUnknownIssuer (nsIInterfaceRequestor *ctx, PRBool *_retval) { gboolean accept_perm = FALSE; - nsAutoString commonName; char *ttCommonName, *secondary, *tertiary, *msg; int res; + nsEmbedString commonName; cert->GetCommonName (commonName); - ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", - NS_ConvertUTF16toUTF8(commonName).get()); + nsEmbedCString cCommonName; + NS_UTF16ToCString (commonName, + NS_CSTRING_ENCODING_UTF8, cCommonName); + + ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", cCommonName.get()); secondary = g_strdup_printf (_("Your browser was unable to trust %s. " @@ -394,7 +397,6 @@ GtkNSSDialogs::ConfirmCertExpired (nsIInterfaceRequestor *ctx, PRTime now = PR_Now(); PRTime notAfter, notBefore, timeToUse; PRInt64 normalizedTime; - nsAutoString commonName; time_t t; struct tm tm; char formattedDate[128]; @@ -428,8 +430,13 @@ GtkNSSDialogs::ConfirmCertExpired (nsIInterfaceRequestor *ctx, timeToUse = notBefore; } + nsEmbedString commonName; cert->GetCommonName (commonName); + nsEmbedCString cCommonName; + NS_UTF16ToCString (commonName, + NS_CSTRING_ENCODING_UTF8, cCommonName); + LL_DIV (normalizedTime, timeToUse, PR_USEC_PER_SEC); LL_L2UI (t, normalizedTime); /* To translators: this a time format that is used while displaying the @@ -439,8 +446,7 @@ GtkNSSDialogs::ConfirmCertExpired (nsIInterfaceRequestor *ctx, localtime_r (&t, &tm)); fdate = g_locale_to_utf8 (formattedDate, -1, NULL, NULL, NULL); - ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", - NS_ConvertUTF16toUTF8(commonName).get()); + ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", cCommonName.get()); secondary = g_strdup_printf (text, ttCommonName, fdate); @@ -468,7 +474,6 @@ GtkNSSDialogs::NotifyCrlNextupdate (nsIInterfaceRequestor *ctx, { GtkWidget *dialog, *label; char *ttCommonName, *ttTargetUrl, *msg, *primary, *secondary; - nsAutoString commonName; nsCOMPtr<nsIDOMWindow> parent = do_GetInterface (ctx); GtkWidget *gparent = MozillaFindGtkParent (parent); @@ -483,13 +488,17 @@ GtkNSSDialogs::NotifyCrlNextupdate (nsIInterfaceRequestor *ctx, higgy_setup_dialog (GTK_DIALOG (dialog), GTK_STOCK_DIALOG_ERROR, &label, NULL); + nsEmbedString commonName; cert->GetCommonName (commonName); - ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", - NS_ConvertUTF16toUTF8(commonName).get()); + nsEmbedCString cCommonName; + NS_UTF16ToCString (commonName, + NS_CSTRING_ENCODING_UTF8, cCommonName); + + ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", cCommonName.get()); - ttTargetUrl = g_strdup_printf ("\"<tt>%s</tt>\"", - PromiseFlatCString(targetURL).get()); + ttTargetUrl = g_strdup_printf ("\"<tt>%s</tt>\"", + nsEmbedCString(targetURL).get()); primary = g_strdup_printf (_("Cannot establish connection to %s."), ttTargetUrl); @@ -545,12 +554,16 @@ GtkNSSDialogs::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx, &label, &content_vbox); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT); - nsAutoString commonName; + nsEmbedString commonName; cert->GetCommonName (commonName); - ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", - NS_ConvertUTF16toUTF8(commonName).get()); - tertiary = g_strdup_printf (_("Trust %s to identify:"), ttCommonName ); + nsEmbedCString cCommonName; + NS_UTF16ToCString (commonName, + NS_CSTRING_ENCODING_UTF8, cCommonName); + + ttCommonName = g_strdup_printf ("\"<tt>%s</tt>\"", cCommonName.get()); + + tertiary = g_strdup_printf (_("Trust %s to identify:"), ttCommonName); g_free (ttCommonName); msg = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s\n\n%s", @@ -835,8 +848,9 @@ GtkNSSDialogs::SetPKCS12FilePassword(nsIInterfaceRequestor *ctx, } else { - gchar * text = gtk_editable_get_chars (GTK_EDITABLE (entry1), 0, -1); - CopyUTF8toUTF16 (text, _password); + gchar *text = gtk_editable_get_chars (GTK_EDITABLE (entry1), 0, -1); + NS_CStringToUTF16 (nsEmbedCString (text), + NS_CSTRING_ENCODING_UTF8, _password); g_free (text); *_retval = PR_TRUE; } @@ -896,7 +910,8 @@ GtkNSSDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx, else { gchar * text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); - CopyUTF8toUTF16 (text, _password); + NS_CStringToUTF16 (nsEmbedCString (text), + NS_CSTRING_ENCODING_UTF8, _password); g_free (text); *_retval = PR_TRUE; } @@ -955,7 +970,7 @@ GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl gtk_table_set_row_spacings (GTK_TABLE (table), 6); gtk_table_set_col_spacings (GTK_TABLE (table), 6); - nsAutoString org, orgUnit, nextUpdate; + nsEmbedString org, orgUnit, nextUpdate; rv = crl->GetOrganization (org); if (NS_FAILED(rv)) return rv; @@ -965,13 +980,19 @@ GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl rv = crl->GetNextUpdateLocale (nextUpdate); if (NS_FAILED(rv)) return rv; - label = gtk_label_new (NS_ConvertUTF16toUTF8(org).get()); + nsEmbedCString cOrg; + NS_UTF16ToCString (org, NS_CSTRING_ENCODING_UTF8, cOrg); + label = gtk_label_new (cOrg.get()); set_table_row (table, 0, _("Organization:"), label); - label = gtk_label_new (NS_ConvertUTF16toUTF8(orgUnit).get()); + nsEmbedCString cOrgUnit; + NS_UTF16ToCString (orgUnit, NS_CSTRING_ENCODING_UTF8, cOrgUnit); + label = gtk_label_new (cOrgUnit.get()); set_table_row (table, 1, _("Unit:"), label); - label = gtk_label_new (NS_ConvertUTF16toUTF8(nextUpdate).get()); + nsEmbedCString cNextUpdate; + NS_UTF16ToCString (nextUpdate, NS_CSTRING_ENCODING_UTF8, cNextUpdate); + label = gtk_label_new (cNextUpdate.get()); set_table_row (table, 2, _("Next Update:"), label); gtk_box_pack_start (GTK_BOX (vbox), higgy_indent_widget (table), FALSE, FALSE, 0); @@ -989,14 +1010,14 @@ GtkNSSDialogs::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl * Help function to fill in the labels on the General tab */ static void -set_label_cert_attribute (GladeXML* gxml, const char* label_id, nsAutoString &value) +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.IsEmpty()) { + if (!value.Length()) { gtk_label_set_use_markup (GTK_LABEL (label), TRUE); char *msg = g_strdup_printf ("<i><%s></i>", _("Not part of certificate")); @@ -1005,9 +1026,10 @@ set_label_cert_attribute (GladeXML* gxml, const char* label_id, nsAutoString &va } else { + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); gtk_label_set_use_markup (GTK_LABEL (label), FALSE); - gtk_label_set_text (GTK_LABEL (label), - NS_ConvertUTF16toUTF8(value).get()); + gtk_label_set_text (GTK_LABEL (label), cValue.get()); } } @@ -1037,15 +1059,18 @@ fill_cert_chain_tree (GtkTreeView *treeview, nsIArray *certChain) gtk_tree_store_append (GTK_TREE_STORE (model), &iter, (i == (int)numCerts-1) ? NULL : &parent); - nsAutoString value; + nsEmbedString value; rv = nsCert->GetCommonName (value); if (NS_FAILED(rv)) return FALSE; + nsEmbedCString cValue; + NS_UTF16ToCString (value, NS_CSTRING_ENCODING_UTF8, cValue); + nsIX509Cert *nsCertP = nsCert; - if (!value.IsEmpty()) + if (value.Length()) { gtk_tree_store_set (GTK_TREE_STORE(model), &iter, - 0, NS_ConvertUTF16toUTF8(value).get(), + 0, cValue.get(), 1, nsCertP, -1); } @@ -1079,14 +1104,17 @@ fill_cert_chain_tree (GtkTreeView *treeview, nsIArray *certChain) static void add_asn1_object_to_tree(GtkTreeModel *model, nsIASN1Object *object, GtkTreeIter *parent) { - nsAutoString dispNameU; + nsEmbedString dispNameU; object->GetDisplayName(dispNameU); + nsEmbedCString cDispNameU; + NS_UTF16ToCString (dispNameU, NS_CSTRING_ENCODING_UTF8, cDispNameU); + 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(), + 0, cDispNameU.get(), 1, object, -1); @@ -1155,14 +1183,16 @@ field_tree_view_selection_changed_cb (GtkTreeSelection *selection, if (gtk_tree_selection_get_selected (selection, &model, &iter)) { nsIASN1Object *object; - nsAutoString dispValU; gtk_tree_model_get (model, &iter, 1, &object, -1); + nsEmbedString dispValU; object->GetDisplayValue(dispValU); - gtk_text_buffer_set_text (text_buffer, - NS_ConvertUTF16toUTF8(dispValU).get(), - -1); + + nsEmbedCString cDispValU; + NS_UTF16ToCString (dispValU, NS_CSTRING_ENCODING_UTF8, cDispValU); + + gtk_text_buffer_set_text (text_buffer, cDispValU.get(), -1); } else { @@ -1252,7 +1282,7 @@ GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, { GtkWidget *dialog, *widget; GladeXML *gxml; - nsAutoString value; + nsEmbedString value; nsresult rv; PRUint32 verifystate, count; PRUnichar ** usage; @@ -1327,8 +1357,11 @@ GtkNSSDialogs::ViewCert(nsIInterfaceRequestor *ctx, GtkWidget *indent; for (PRUint32 i = 0 ; i < count ; i++) { - const nsACString &msg = NS_ConvertUTF16toUTF8 (usage[i]); - GtkWidget *label = gtk_label_new(PromiseFlatCString(msg).get()); + nsEmbedCString msg; + NS_UTF16ToCString (nsEmbedString(usage[i]), + NS_CSTRING_ENCODING_UTF8, msg); + + GtkWidget *label = gtk_label_new(msg.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]); diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp index b32f8bd0d..2b1b0e113 100644 --- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp +++ b/embed/mozilla/GtkNSSKeyPairDialogs.cpp @@ -41,6 +41,8 @@ #ifdef HAVE_MOZILLA_PSM +#include "mozilla-version.h" + #include "MozillaPrivate.h" #include <nsIServiceManager.h> @@ -91,7 +93,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIDOMWINDOWINTERNAL NS_DECL_NSIDOMWINDOW -#if MOZILLA_SNAPSHOT >= 19 +#if (MOZILLA_CHECK_VERSION4 (1, 7, MOZILLA_RC, 3) && !MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)) || MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 2) NS_DECL_NSIDOMWINDOW2 #endif @@ -101,7 +103,7 @@ public: gboolean close_called; }; -#if MOZILLA_SNAPSHOT >= 19 +#if (MOZILLA_CHECK_VERSION4 (1, 7, MOZILLA_RC, 3) && !MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)) || MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 2) NS_IMPL_ISUPPORTS3(KeyPairHelperWindow, nsIDOMWindowInternal, nsIDOMWindow, nsIDOMWindow2) #else NS_IMPL_ISUPPORTS2(KeyPairHelperWindow, nsIDOMWindowInternal, nsIDOMWindow) @@ -249,13 +251,6 @@ NS_IMETHODIMP KeyPairHelperWindow::GetWindow(nsIDOMWindowInternal * *aWindow) MOZ_NOT_IMPLEMENTED } -#if MOZILLA_SNAPSHOT >= 19 -NS_IMETHODIMP KeyPairHelperWindow::GetWindowRoot(nsIDOMEventTarget * *aEvent) -{ - MOZ_NOT_IMPLEMENTED -} -#endif - /* readonly attribute nsIDOMWindowInternal self; */ NS_IMETHODIMP KeyPairHelperWindow::GetSelf(nsIDOMWindowInternal * *aSelf) { @@ -719,4 +714,13 @@ NS_IMETHODIMP KeyPairHelperWindow::SizeToContent() MOZ_NOT_IMPLEMENTED } +#if (MOZILLA_CHECK_VERSION4 (1, 7, MOZILLA_RC, 3) && !MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)) || MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 2) + +NS_IMETHODIMP KeyPairHelperWindow::GetWindowRoot(nsIDOMEventTarget * *aWindowRoot) +{ + MOZ_NOT_IMPLEMENTED +} + +#endif + #endif diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 249b5feaf..17824d88a 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -5,14 +5,12 @@ INCLUDES = \ $(MOZILLA_COMPONENT_CFLAGS) \ -I$(MOZILLA_INCLUDE_ROOT) \ -I$(MOZILLA_INCLUDE_ROOT)/chardet \ - -I$(MOZILLA_INCLUDE_ROOT)/chrome \ + -I$(MOZILLA_INCLUDE_ROOT)/commandhandler \ -I$(MOZILLA_INCLUDE_ROOT)/content \ -I$(MOZILLA_INCLUDE_ROOT)/cookie \ - -I$(MOZILLA_INCLUDE_ROOT)/commandhandler \ -I$(MOZILLA_INCLUDE_ROOT)/docshell \ -I$(MOZILLA_INCLUDE_ROOT)/dom \ -I$(MOZILLA_INCLUDE_ROOT)/exthandler \ - -I$(MOZILLA_INCLUDE_ROOT)/find \ -I$(MOZILLA_INCLUDE_ROOT)/gfx \ -I$(MOZILLA_INCLUDE_ROOT)/helperAppDlg \ -I$(MOZILLA_INCLUDE_ROOT)/history \ @@ -22,23 +20,16 @@ INCLUDES = \ -I$(MOZILLA_INCLUDE_ROOT)/necko \ -I$(MOZILLA_INCLUDE_ROOT)/nkcache \ -I$(MOZILLA_INCLUDE_ROOT)/pipnss \ - -I$(MOZILLA_INCLUDE_ROOT)/pref \ - -I$(MOZILLA_INCLUDE_ROOT)/progressDlg \ -I$(MOZILLA_INCLUDE_ROOT)/shistory \ - -I$(MOZILLA_INCLUDE_ROOT)/string \ - -I$(MOZILLA_INCLUDE_ROOT)/unicharutil \ -I$(MOZILLA_INCLUDE_ROOT)/uriloader \ - -I$(MOZILLA_INCLUDE_ROOT)/wallet \ -I$(MOZILLA_INCLUDE_ROOT)/webbrowserpersist \ -I$(MOZILLA_INCLUDE_ROOT)/webbrwsr \ - -I$(MOZILLA_INCLUDE_ROOT)/webshell \ -I$(MOZILLA_INCLUDE_ROOT)/widget \ -I$(MOZILLA_INCLUDE_ROOT)/windowwatcher \ - -I$(MOZILLA_INCLUDE_ROOT)/xpcom \ + -I$(MOZILLA_INCLUDE_ROOT)/xmlextras \ $(EPIPHANY_DEPENDENCY_CFLAGS) \ -DSHARE_DIR=\"$(pkgdatadir)\" \ -DALLOW_PRIVATE_API \ - -DALLOW_PRIVATE_STRINGS \ -include $(MOZILLA_INCLUDE_ROOT)/mozilla-config.h if MAINTAINER_MODE @@ -61,6 +52,8 @@ libephymozillaembed_la_SOURCES = \ EphyBrowser.h \ EphySingle.cpp \ EphySingle.h \ + EphyUtils.cpp \ + EphyUtils.h \ EventContext.cpp \ EventContext.h \ FilePicker.cpp \ @@ -92,4 +85,5 @@ libephymozillaembed_la_SOURCES = \ mozilla-embed-single.cpp \ mozilla-embed-single.h \ mozilla-notifiers.cpp \ - mozilla-notifiers.h + mozilla-notifiers.h \ + mozilla-version.h diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index b50161c38..cd836599b 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -45,21 +45,21 @@ #include "config.h" #endif -#include "MozDownload.h" +#include "mozilla-version.h" + #include "mozilla-download.h" #include "eel-gconf-extensions.h" #include "ephy-prefs.h" #include "ephy-file-helpers.h" #include "ephy-debug.h" +#include "MozDownload.h" +#include "EphyUtils.h" #include <libgnomevfs/gnome-vfs-utils.h> #include <glib/gi18n.h> #include <nsIFileURL.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include "nsNetUtil.h" -#endif +#include <nsEmbedString.h> const char* const persistContractID = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; @@ -79,18 +79,10 @@ MozDownload::~MozDownload() NS_ASSERTION (!mEphyDownload, "MozillaDownload still alive!"); } -#if MOZILLA_SNAPSHOT < 16 -NS_IMPL_ISUPPORTS2(MozDownload, nsIDownload, nsIWebProgressListener) -#else NS_IMPL_ISUPPORTS3(MozDownload, nsIDownload, nsITransfer, nsIWebProgressListener) -#endif NS_IMETHODIMP -#if MOZILLA_SNAPSHOT < 16 -MozDownload::InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, -#else MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName, -#endif nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist, MozillaEmbedPersist *aEmbedPersist, PRInt32 aMaxSize) { @@ -100,15 +92,9 @@ MozDownload::InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aD } /* void init (in nsIURI aSource, in nsIURI aTarget, in wstring aDisplayName, in nsIMIMEInfo aMIMEInfo, in long long startTime, in nsIWebBrowserPersist aPersist); */ -#if MOZILLA_SNAPSHOT < 16 -NS_IMETHODIMP -MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisplayName, - nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist) -#else NS_IMETHODIMP MozDownload::Init(nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist) -#endif { PRBool addToView = PR_TRUE; @@ -165,13 +151,8 @@ MozDownload::GetSource(nsIURI **aSource) return NS_OK; } -#if MOZILLA_SNAPSHOT < 16 -NS_IMETHODIMP -MozDownload::GetTarget(nsILocalFile **aTarget) -#else NS_IMETHODIMP MozDownload::GetTarget(nsIURI **aTarget) -#endif { NS_ENSURE_ARG_POINTER(aTarget); NS_IF_ADDREF(*aTarget = mDestination); @@ -179,7 +160,6 @@ MozDownload::GetTarget(nsIURI **aTarget) return NS_OK; } -#if MOZILLA_SNAPSHOT > 15 NS_IMETHODIMP MozDownload::GetTargetFile (nsILocalFile** aTargetFile) { @@ -194,7 +174,6 @@ MozDownload::GetTargetFile (nsILocalFile** aTargetFile) rv = CallQueryInterface(file, aTargetFile); return rv; } -#endif NS_IMETHODIMP MozDownload::GetPersist(nsIWebBrowserPersist **aPersist) @@ -347,45 +326,49 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, else if (NS_SUCCEEDED (aStatus)) { GnomeVFSMimeApplication *helperApp; -#if MOZILLA_SNAPSHOT < 18 - char *mimeType; - rv = mMIMEInfo->GetMIMEType (&mimeType); +#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) + nsEmbedCString mimeType; + rv = mMIMEInfo->GetMIMEType (mimeType); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - helperApp = gnome_vfs_mime_get_default_application (mimeType); + helperApp = gnome_vfs_mime_get_default_application (mimeType.get()); - PRUnichar *description; - mMIMEInfo->GetApplicationDescription (&description); + nsEmbedString description; + mMIMEInfo->GetApplicationDescription (description); + + nsEmbedCString 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 ((strcmp (NS_ConvertUTF16toUTF8 (description).get(), "gnome-default") == 0) && + if ((strcmp (cDesc.get(), "gnome-default") == 0) && helperApp) #else - nsCAutoString mimeType; - rv = mMIMEInfo->GetMIMEType (mimeType); + char *mimeType; + rv = mMIMEInfo->GetMIMEType (&mimeType); NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); - helperApp = gnome_vfs_mime_get_default_application (mimeType.get()); + helperApp = gnome_vfs_mime_get_default_application (mimeType); - nsAutoString description; - mMIMEInfo->GetApplicationDescription (description); + PRUnichar *description; + mMIMEInfo->GetApplicationDescription (&description); + + nsEmbedCString cDesc; + NS_UTF16ToCString (nsEmbedString(description), + NS_CSTRING_ENCODING_UTF8, cDesc); /* HACK we use the application description to decide if we have to open the saved file */ - if ((strcmp (NS_ConvertUCS2toUTF8 (description).get(), "gnome-default") == 0) && + if (strcmp (cDesc.get(), "gnome-default") == 0 && helperApp) #endif { GList *params = NULL; char *param; - nsCAutoString aDest; + nsEmbedCString aDest; -#if MOZILLA_SNAPSHOT < 16 - mDestination->GetNativePath (aDest); -#else mDestination->GetSpec (aDest); -#endif + param = gnome_vfs_make_uri_canonical (aDest.get ()); params = g_list_append (params, param); gnome_vfs_mime_application_launch (helperApp, params); @@ -393,10 +376,7 @@ MozDownload::OnStateChange (nsIWebProgress *aWebProgress, nsIRequest *aRequest, g_list_free (params); } -#if MOZILLA_SNAPSHOT < 16 - nsMemory::Free (mimeType); - nsMemory::Free (description); -#endif + gnome_vfs_mime_application_free (helperApp); } } @@ -528,21 +508,19 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI PRInt64 timeNow = PR_Now(); - nsAutoString fileDisplayName; + nsEmbedString fileDisplayName; inDestFile->GetLeafName(fileDisplayName); - #if MOZILLA_SNAPSHOT >= 16 + nsCOMPtr<nsIIOService> ioService; + rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); + NS_ENSURE_SUCCESS (rv, rv); + nsCOMPtr<nsIURI> destURI; - NS_NewFileURI (getter_AddRefs(destURI), inDestFile); - #endif + ioService->NewFileURI (inDestFile, getter_AddRefs(destURI)); MozDownload *downloader = new MozDownload (); /* dlListener attaches to its progress dialog here, which gains ownership */ - #if MOZILLA_SNAPSHOT < 16 - rv = downloader->InitForEmbed (inOriginalURI, inDestFile, fileDisplayName.get(), - #else rv = downloader->InitForEmbed (inOriginalURI, destURI, fileDisplayName.get(), - #endif nsnull, timeNow, webPersist, embedPersist, aMaxSize); NS_ENSURE_SUCCESS (rv, rv); @@ -573,24 +551,22 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI * will create the directory as needed. */ - filesFolder = do_CreateInstance("@mozilla.org/file/local;1"); - nsAutoString unicodePath; - inDestFile->GetPath(unicodePath); - filesFolder->InitWithPath(unicodePath); - - nsAutoString leafName; - filesFolder->GetLeafName(leafName); - nsAutoString nameMinusExt(leafName); - PRInt32 index = nameMinusExt.RFind("."); - if (index >= 0) + nsEmbedCString cPath; + inDestFile->GetNativePath (cPath); + + GString *path = g_string_new (cPath.get()); + char *dot_pos = strchr (path->str, '.'); + if (dot_pos) { - nameMinusExt.Left(nameMinusExt, index); + g_string_truncate (path, dot_pos - path->str); } + g_string_append (path, " "); + g_string_append (path, _("Files")); + + filesFolder = do_CreateInstance ("@mozilla.org/file/local;1"); + filesFolder->InitWithNativePath (nsEmbedCString(path->str)); - nameMinusExt += NS_LITERAL_STRING (" "); - nameMinusExt += NS_ConvertUTF8toUTF16 (_("Files")); - - filesFolder->SetLeafName(nameMinusExt); + g_string_free (path, TRUE); rv = webPersist->SaveDocument (domDocument, inDestFile, filesFolder, contentType, encodingFlags, 80); @@ -684,7 +660,7 @@ nsresult BuildDownloadPath (const char *defaultFileName, nsILocalFile **_retval) } nsCOMPtr <nsILocalFile> destFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); - destFile->InitWithNativePath (nsDependentCString (path)); + destFile->InitWithNativePath (nsEmbedCString (path)); g_free (path); NS_IF_ADDREF (*_retval = destFile); diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h index 2f4042868..ed01d248e 100644 --- a/embed/mozilla/MozDownload.h +++ b/embed/mozilla/MozDownload.h @@ -61,10 +61,6 @@ #include <nsIRequest.h> #include <nsIMIMEInfo.h> -#ifdef ALLOW_PRIVATE_API -#include <nsString.h> -#endif - #include <libgnomevfs/gnome-vfs-mime-handlers.h> /* MozDownload @@ -103,9 +99,7 @@ public: virtual ~MozDownload(); NS_DECL_ISUPPORTS -#if MOZILLA_SNAPSHOT > 15 NS_DECL_NSITRANSFER -#endif NS_DECL_NSIDOWNLOAD NS_DECL_NSIWEBPROGRESSLISTENER @@ -117,25 +111,15 @@ public: nsresult GetCurrentProgress (PRInt32 *aCurrentProgress); nsresult GetTotalProgress (PRInt32 *aTProgress); nsresult GetElapsedTime (PRInt64 *aTProgress); -#if MOZILLA_SNAPSHOT < 16 - nsresult InitForEmbed (nsIURI *aSource, nsILocalFile *aTarget, - const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, - PRInt64 startTime, nsIWebBrowserPersist *aPersist, - MozillaEmbedPersist *aEmbedPersist, PRInt32 aMaxSize); -#else nsresult InitForEmbed (nsIURI *aSource, nsIURI *aTarget, const PRUnichar *aDisplayName, nsIMIMEInfo *aMIMEInfo, PRInt64 startTime, nsIWebBrowserPersist *aPersist, MozillaEmbedPersist *aEmbedPersist, PRInt32 aMaxSize); -#endif protected: nsCOMPtr<nsIURI> mSource; -#if MOZILLA_SNAPSHOT < 16 - nsCOMPtr<nsILocalFile> mDestination; -#else nsCOMPtr<nsIURI> mDestination; -#endif + nsCOMPtr<nsIMIMEInfo> mMIMEInfo; PRInt64 mLastUpdate; PRInt64 mStartTime; diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index a99f15b10..c3247e58a 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -37,9 +37,8 @@ #include "GtkNSSKeyPairDialogs.h" #endif -#if MOZILLA_SNAPSHOT > 13 +#include <nsMemory.h> #include <nsDocShellCID.h> -#endif #include <nsIGenericFactory.h> #include <nsIComponentRegistrar.h> #include <nsICategoryManager.h> @@ -72,11 +71,12 @@ RegisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile *aPath, do_GetService(NS_CATEGORYMANAGER_CONTRACTID); NS_ENSURE_TRUE (cm, NS_ERROR_FAILURE); - nsXPIDLCString oldval; + char *oldval; return cm->AddCategoryEntry("content-policy", EPHY_CONTENT_POLICY_CONTRACTID, EPHY_CONTENT_POLICY_CONTRACTID, - PR_TRUE, PR_TRUE, getter_Copies (oldval)); + PR_TRUE, PR_TRUE, &oldval); + nsMemory::Free (oldval); } static const nsModuleComponentInfo sAppComps[] = { @@ -127,11 +127,7 @@ static const nsModuleComponentInfo sAppComps[] = { { EPHY_GLOBALHISTORY_CLASSNAME, EPHY_GLOBALHISTORY_CID, -#if MOZILLA_SNAPSHOT > 13 NS_GLOBALHISTORY2_CONTRACTID, -#else - NS_GLOBALHISTORY_CONTRACTID, -#endif MozGlobalHistoryConstructor }, { diff --git a/embed/mozilla/MozillaPrivate.cpp b/embed/mozilla/MozillaPrivate.cpp index cfd69173e..3fd0e57ab 100644 --- a/embed/mozilla/MozillaPrivate.cpp +++ b/embed/mozilla/MozillaPrivate.cpp @@ -27,17 +27,13 @@ #include "MozillaPrivate.h" +#include <nsEmbedString.h> #include <nsIServiceManagerUtils.h> #include <nsIWindowWatcher.h> #include <nsIEmbeddingSiteWindow.h> #include <nsIWebBrowserChrome.h> #include <gtkmozembed.h> -#ifdef ALLOW_PRIVATE_STRINGS -#include "nsString.h" -#include "nsReadableUtils.h" -#endif - GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow) { if (!aDOMWindow) return nsnull; @@ -108,23 +104,44 @@ NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, options->SetMarginLeft (MM_TO_INCH (info->left_margin)); options->SetMarginRight (MM_TO_INCH (info->right_margin)); - options->SetPrinterName(NS_LITERAL_STRING("PostScript/default").get()); + PRUnichar postscript[] = { 'P', 'o', 's', 't', 's', 'c', 'r', 'i', + 'p', 't', '/', 'd', 'e', 'f', 'a', 'u', + 'l', 't', '\0' }; + options->SetPrinterName(postscript); - options->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(info->header_left_string).get()); + nsEmbedString tmp; - options->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(info->header_center_string).get()); + NS_CStringToUTF16 (nsEmbedCString(info->header_left_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrLeft (tmp.get()); - options->SetHeaderStrRight(NS_ConvertUTF8toUTF16(info->header_right_string).get()); + NS_CStringToUTF16 (nsEmbedCString(info->header_center_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrCenter (tmp.get()); - options->SetFooterStrLeft(NS_ConvertUTF8toUTF16(info->footer_left_string).get()); + NS_CStringToUTF16 (nsEmbedCString(info->header_right_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetHeaderStrRight (tmp.get()); - options->SetFooterStrCenter(NS_ConvertUTF8toUTF16(info->footer_center_string).get()); + NS_CStringToUTF16 (nsEmbedCString(info->footer_left_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetFooterStrLeft (tmp.get()); - options->SetFooterStrRight(NS_ConvertUTF8toUTF16(info->footer_right_string).get()); + NS_CStringToUTF16 (nsEmbedCString(info->footer_center_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetFooterStrCenter(tmp.get()); - options->SetToFileName (NS_ConvertUTF8toUTF16(info->file).get()); + NS_CStringToUTF16 (nsEmbedCString(info->footer_right_string), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetFooterStrRight(tmp.get()); - options->SetPrintCommand (NS_ConvertUTF8toUTF16(info->printer).get()); + NS_CStringToUTF16 (nsEmbedCString(info->file), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetToFileName (tmp.get()); + + NS_CStringToUTF16 (nsEmbedCString(info->printer), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetPrintCommand (tmp.get()); /** * Work around a mozilla bug where paper size & orientation are ignored @@ -143,7 +160,10 @@ NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, /* native paper size formats. Our dialog does not support custom yet */ options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData); - options->SetPaperName (NS_ConvertUTF8toUTF16(info->paper).get()); + + NS_CStringToUTF16 (nsEmbedCString(info->paper), + NS_CSTRING_ENCODING_UTF8, tmp); + options->SetPaperName (tmp.get()); options->SetPrintInColor (info->print_color); options->SetOrientation (info->orientation); diff --git a/embed/mozilla/mozilla-download.cpp b/embed/mozilla/mozilla-download.cpp index 455c875a1..0ad8dc2c6 100644 --- a/embed/mozilla/mozilla-download.cpp +++ b/embed/mozilla/mozilla-download.cpp @@ -87,11 +87,7 @@ impl_get_target (EphyDownload *download) mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; -#if MOZILLA_SNAPSHOT < 16 - mozDownload->GetTarget (getter_AddRefs (targetFile)); -#else mozDownload->GetTargetFile (getter_AddRefs (targetFile)); -#endif nsCAutoString tempPathStr; targetFile->GetNativePath (tempPathStr); diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 7b20ad197..b014fd97e 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -29,6 +29,7 @@ #include "EphyBrowser.h" #include "EphyHeaderSniffer.h" #include "MozDownload.h" +#include "EphyUtils.h" #include <stddef.h> @@ -36,13 +37,9 @@ #include <nsCWebBrowserPersist.h> #include <nsIHistoryEntry.h> #include <nsISHEntry.h> - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#include <nsNetUtil.h> -#include <nsIDocumentEncoder.h> -#include <nsIDocument.h> -#endif +#include <nsIDOMSerializer.h> +#include <nsIIOService.h> +#include <nsNetCID.h> static void mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); @@ -176,12 +173,12 @@ impl_save (EphyEmbedPersist *persist) if (tmp_filename == NULL) return FALSE; nsCOMPtr<nsILocalFile> tmpFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - tmpFile->InitWithNativePath (nsDependentCString (tmp_filename)); + tmpFile->InitWithNativePath (nsEmbedCString (tmp_filename)); g_free (tmp_filename); /* Get the uri to save to */ nsCOMPtr<nsIURI> inURI; - nsCAutoString sURI; + nsEmbedCString sURI; if (uri) { sURI.Assign (uri); @@ -191,8 +188,9 @@ impl_save (EphyEmbedPersist *persist) rv = browser->GetDocumentUrl (sURI); NS_ENSURE_SUCCESS (rv, FALSE); } - NS_NewURI(getter_AddRefs(inURI), sURI); - if (!inURI) return FALSE; + + rv = EphyUtils::NewURI (getter_AddRefs(inURI), sURI); + NS_ENSURE_SUCCESS (rv, FALSE); /* Get post data */ nsCOMPtr<nsIInputStream> postData; @@ -262,7 +260,7 @@ impl_save (EphyEmbedPersist *persist) { /* Filename to save to */ nsCOMPtr<nsILocalFile> destFile; - NS_NewNativeLocalFile (nsDependentCString(filename), + NS_NewNativeLocalFile (nsEmbedCString(filename), PR_TRUE, getter_AddRefs(destFile)); NS_ENSURE_TRUE (destFile, FALSE); @@ -309,19 +307,20 @@ impl_to_string (EphyEmbedPersist *persist) } if (NS_FAILED(rv) || !DOMDocument) return NULL; - nsCOMPtr<nsIDocument> doc = do_QueryInterface(DOMDocument); - if(!doc) return NULL; + nsCOMPtr<nsIDOMNode> node = do_QueryInterface(DOMDocument); + if (!node) return NULL; - nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html"); - NS_ENSURE_SUCCESS(rv, NULL); + nsCOMPtr<nsIDOMSerializer> serializer; + serializer = do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS (rv, FALSE); - rv = encoder->Init(doc, NS_LITERAL_STRING("text/html"), nsIDocumentEncoder::OutputAbsoluteLinks); - NS_ENSURE_SUCCESS(rv, NULL); + nsEmbedString outString; + serializer->SerializeToString(node, outString); - nsAutoString aOutputString; - encoder->EncodeToString(aOutputString); + nsEmbedCString cOutString; + NS_UTF16ToCString (outString, NS_CSTRING_ENCODING_UTF8, cOutString); - return g_strdup (NS_ConvertUTF16toUTF8(aOutputString).get()); + return g_strdup (cOutString.get()); } static GObject * diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 939ebd2bb..5e8fb8cb8 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -40,11 +40,14 @@ #include "ephy-embed-prefs.h" #include "MozRegisterComponents.h" #include "EphySingle.h" +#include "EphyUtils.h" #include <glib/gi18n.h> #include <libgnomevfs/gnome-vfs-utils.h> #include <nsCOMPtr.h> +#include <nsMemory.h> +#include <nsEmbedString.h> #include <nsIPrefService.h> #include <nsIServiceManager.h> #include <nsIIOService.h> @@ -71,12 +74,7 @@ #include <nsIHttpAuthManager.h> #include <nsICacheService.h> #include <nsIFontEnumerator.h> -#endif - -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsString.h> -#include <nsReadableUtils.h> -#include <nsNetUtil.h> +#include <nsNetCID.h> #endif #define MOZILLA_PROFILE_DIR "/mozilla" @@ -190,7 +188,7 @@ mozilla_set_default_prefs (MozillaEmbedSingle *mes) /* read our predefined default prefs */ nsresult rv; nsCOMPtr<nsILocalFile> file; - NS_NewNativeLocalFile(NS_LITERAL_CSTRING(DEFAULT_PROFILE_FILE), + NS_NewNativeLocalFile(nsEmbedCString(DEFAULT_PROFILE_FILE), PR_TRUE, getter_AddRefs(file)); if (!file) return FALSE; @@ -398,13 +396,13 @@ static nsresult mozilla_init_chrome (void) { nsresult result; - nsAutoString uiLang; + nsEmbedString uiLang; nsCOMPtr<nsIXULChromeRegistry> chromeRegistry = do_GetService (NS_CHROMEREGISTRY_CONTRACTID); NS_ENSURE_TRUE (chromeRegistry, NS_ERROR_FAILURE); // Set skin to 'classic' so we get native scrollbars. - result = chromeRegistry->SelectSkin (NS_LITERAL_CSTRING("classic/1.0"), PR_FALSE); + result = chromeRegistry->SelectSkin (nsEmbedCString("classic/1.0"), PR_FALSE); NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE); // set locale @@ -414,7 +412,10 @@ mozilla_init_chrome (void) result = getUILang(uiLang); NS_ENSURE_SUCCESS (result, NS_ERROR_FAILURE); - return chromeRegistry->SelectLocale (NS_ConvertUTF16toUTF8(uiLang), PR_FALSE); + nsEmbedCString cUILang; + NS_UTF16ToCString (uiLang, NS_CSTRING_ENCODING_UTF8, cUILang); + + return chromeRegistry->SelectLocale (cUILang, PR_FALSE); } static void @@ -582,7 +583,10 @@ impl_get_font_list (EphyEmbedSingle *shell, { char *gFontString; - gFontString = g_strdup (NS_ConvertUTF16toUTF8 (fontArray[i]).get()); + nsEmbedCString tmp; + NS_UTF16ToCString (nsEmbedString(fontArray[i]), + NS_CSTRING_ENCODING_UTF8, tmp); + gFontString = g_strdup (tmp.get()); l = g_list_prepend (l, gFontString); nsMemory::Free (fontArray[i]); } @@ -631,9 +635,9 @@ impl_remove_cookie (EphyCookieManager *manager, do_GetService (NS_COOKIEMANAGER_CONTRACTID); if (!cookieManager) return; - cookieManager->Remove (nsDependentCString(cookie->domain), - nsDependentCString(cookie->name), - nsDependentCString(cookie->path), + cookieManager->Remove (nsEmbedCString(cookie->domain), + nsEmbedCString(cookie->name), + nsEmbedCString(cookie->path), PR_FALSE /* block */); } @@ -672,18 +676,22 @@ impl_list_passwords (EphyPasswordManager *manager) passwordEnumerator->GetNext (getter_AddRefs(nsPassword)); if (!nsPassword) continue; - nsCAutoString transfer; + nsEmbedCString transfer; rv = nsPassword->GetHost (transfer); if (NS_FAILED (rv)) continue; - nsAutoString unicodeName; + nsEmbedString unicodeName; rv = nsPassword->GetUser (unicodeName); if (NS_FAILED (rv)) continue; + nsEmbedCString userName; + NS_UTF16ToCString (unicodeName, + NS_CSTRING_ENCODING_UTF8, userName); + EphyPasswordInfo *p = g_new0 (EphyPasswordInfo, 1); p->host = g_strdup (transfer.get()); - p->username = g_strdup(NS_ConvertUTF16toUTF8(unicodeName).get()); + p->username = g_strdup (userName.get()); p->password = NULL; passwords = g_list_prepend (passwords, p); @@ -701,8 +709,10 @@ impl_remove_password (EphyPasswordManager *manager, do_GetService (NS_PASSWORDMANAGER_CONTRACTID); if (!pm) return; - pm->RemoveUser (nsDependentCString(info->host), - NS_ConvertUTF8toUTF16(nsDependentCString(info->username))); + nsEmbedString userName; + NS_CStringToUTF16 (nsEmbedCString(info->username), + NS_CSTRING_ENCODING_UTF8, userName); + pm->RemoveUser (nsEmbedCString(info->host), userName); } static const char *permission_type_string [] = @@ -726,7 +736,7 @@ impl_permission_manager_add (EphyPermissionManager *manager, if (!pm) return; nsCOMPtr<nsIURI> uri; - NS_NewURI(getter_AddRefs(uri), host); + EphyUtils::NewURI(getter_AddRefs(uri), nsEmbedCString(host)); if (!uri) return; gboolean allow = (permission == EPHY_PERMISSION_ALLOWED); @@ -746,7 +756,7 @@ impl_permission_manager_remove (EphyPermissionManager *manager, (do_GetService (NS_PERMISSIONMANAGER_CONTRACTID)); if (!pm) return; - pm->Remove (nsDependentCString (host), permission_type_string [type]); + pm->Remove (nsEmbedCString (host), permission_type_string [type]); } void @@ -769,7 +779,7 @@ impl_permission_manager_test (EphyPermissionManager *manager, if (!pm) return EPHY_PERMISSION_DEFAULT; nsCOMPtr<nsIURI> uri; - NS_NewURI(getter_AddRefs(uri), host); + EphyUtils::NewURI(getter_AddRefs(uri), nsEmbedCString (host)); if (!uri) return EPHY_PERMISSION_DEFAULT; nsresult rv; @@ -818,11 +828,11 @@ impl_permission_manager_list (EphyPermissionManager *manager, if (!perm) continue; nsresult rv; - nsCAutoString str; + nsEmbedCString str; rv = perm->GetType(str); if (NS_FAILED (rv)) continue; - if (str.Equals(permission_type_string[type])) + if (strcmp (str.get(), permission_type_string[type]) == 0) { EphyPermissionInfo *info = mozilla_permission_to_ephy_permission (perm); diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index e5e14e98c..3f12f8e5e 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -32,13 +32,15 @@ #include "MozillaPrivate.h" #include "EphyBrowser.h" #include "EventContext.h" +#include "EphyUtils.h" #include <gtkmozembed.h> +#include <nsEmbedString.h> +#include <nsMemory.h> #include <nsIURI.h> -#include <nsIURL.h> +#include <nsIChannel.h> #include <nsIRequest.h> #include <nsIWebProgressListener.h> -#include <nsIPrintOptions.h> #include <nsGfxCIID.h> #ifdef ALLOW_PRIVATE_API @@ -46,18 +48,12 @@ #include <nsITransportSecurityInfo.h> #endif -#ifdef ALLOW_PRIVATE_STRINGS -#include <nsNetUtil.h> -#include <nsString.h> -#endif - 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_connect_signals (MozillaEmbed *membed); static void mozilla_embed_location_changed_cb (GtkMozEmbed *embed, MozillaEmbed *membed); static void mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, @@ -85,17 +81,24 @@ static EmbedSecurityLevel mozilla_embed_security_level (MozillaEmbed *membed); #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; nsCOMPtr<nsIRequest> request; gint security_state; + MozillaEmbedLoadState load_state; }; #define WINDOWWATCHER_CONTRACTID "@mozilla.org/embedcomp/window-watcher;1" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); - static GObjectClass *parent_class = NULL; static void @@ -203,9 +206,12 @@ impl_find_set_properties (EphyEmbed *embed, { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - mpriv->browser->FindSetProperties - ((NS_ConvertUTF8toUTF16(search_string)).get(), - case_sensitive, wrap_around); + nsEmbedString searchString; + NS_CStringToUTF16 (nsEmbedCString(search_string), + NS_CSTRING_ENCODING_UTF8, searchString); + + mpriv->browser->FindSetProperties (searchString.get(), case_sensitive, + wrap_around); } static void @@ -352,44 +358,24 @@ mozilla_embed_get_uri_parent (const char *aUri) nsresult rv; nsCOMPtr<nsIURI> uri; - rv = NS_NewURI (getter_AddRefs(uri), aUri); + rv = EphyUtils::NewURI (getter_AddRefs(uri), nsEmbedCString(aUri)); if (NS_FAILED(rv) || !uri) return NULL; - nsCOMPtr<nsIURL> url = do_QueryInterface(uri, &rv); - if (NS_FAILED(rv) || !url) return NULL; - - nsCAutoString dirPath; - rv = url->GetDirectory (dirPath); - if (NS_FAILED(rv) || !dirPath.Length()) return NULL; - - nsCAutoString filePath; - rv = url->GetFilePath (filePath); - if (NS_FAILED(rv) || !filePath.Length()) return NULL; - - PRInt32 pathLength = filePath.Length(); - PRInt32 trailingSlash = filePath.RFind("/"); - - if(pathLength < 2 || trailingSlash == -1) - { - return NULL; - } + nsEmbedCString path; + rv = uri->GetPath(path); + if (NS_FAILED(rv)) return NULL; - if(trailingSlash != (pathLength-1)) - { - uri->SetPath(dirPath); - } - else - { - PRInt32 nextSlash = filePath.RFind("/",PR_FALSE,trailingSlash-1); - nsCAutoString parentPath; - filePath.Left(parentPath, nextSlash); - uri->SetPath(parentPath); - } + if (!path.Length() || strcmp (path.get(), "/") == 0 || + !strchr (path.get(), '/')) + { + return NULL; + } - nsCAutoString spec; - uri->GetSpec(spec); + nsEmbedCString parent; + rv = uri->Resolve (nsEmbedCString(".."), parent); + if (NS_FAILED(rv)) return NULL; - return !spec.IsEmpty() ? g_strdup(spec.get()) : NULL; + return g_strdup (parent.get()); } static gboolean @@ -501,18 +487,18 @@ impl_get_location (EphyEmbed *embed, MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; char *l; nsresult rv; - nsCAutoString url; + nsEmbedCString url; if (toplevel) { rv = mpriv->browser->GetDocumentUrl (url); - l = (NS_SUCCEEDED (rv) && !url.IsEmpty()) ? + l = (NS_SUCCEEDED (rv) && url.Length()) ? g_strdup (url.get()) : NULL; } else { rv = mpriv->browser->GetTargetDocumentUrl (url); - l = (NS_SUCCEEDED (rv) && !url.IsEmpty()) ? + l = (NS_SUCCEEDED (rv) && url.Length()) ? g_strdup (url.get()) : NULL; } @@ -537,8 +523,7 @@ impl_reload (EphyEmbed *embed, static void impl_set_zoom (EphyEmbed *embed, - float zoom, - gboolean reflow) + float zoom) { EphyBrowser *browser; nsresult result; @@ -548,7 +533,7 @@ impl_set_zoom (EphyEmbed *embed, browser = MOZILLA_EMBED(embed)->priv->browser; g_return_if_fail (browser != NULL); - result = browser->SetZoom (zoom, reflow); + result = browser->SetZoom (zoom); if (NS_SUCCEEDED (result)) { @@ -592,7 +577,7 @@ impl_shistory_get_nth (EphyEmbed *embed, char **aTitle) { nsresult rv; - nsCAutoString url; + nsEmbedCString url; PRUnichar *title; MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; @@ -603,14 +588,16 @@ impl_shistory_get_nth (EphyEmbed *embed, rv = mpriv->browser->GetSHUrlAtIndex(nth, url); - *aUrl = (NS_SUCCEEDED (rv) && !url.IsEmpty()) ? g_strdup(url.get()) : NULL; + *aUrl = (NS_SUCCEEDED (rv) && url.Length()) ? g_strdup(url.get()) : NULL; rv = mpriv->browser->GetSHTitleAtIndex(nth, &title); if (title) { - *aTitle = g_strdup (NS_ConvertUTF16toUTF8(title).get()); - + nsEmbedCString cTitle; + NS_UTF16ToCString (nsEmbedString(title), + NS_CSTRING_ENCODING_UTF8, cTitle); + *aTitle = g_strdup (cTitle.get()); nsMemory::Free (title); } else @@ -666,13 +653,17 @@ impl_get_security_level (EphyEmbed *embed, nsCOMPtr<nsITransportSecurityInfo> secInfo(do_QueryInterface(info)); if (!secInfo) return; - nsXPIDLString tooltip; - result = secInfo->GetShortSecurityDescription(getter_Copies(tooltip)); + PRUnichar *tooltip; + result = secInfo->GetShortSecurityDescription(&tooltip); if (NS_FAILED (result)) return; if (tooltip) { - *description = g_strdup (NS_ConvertUTF16toUTF8(tooltip).get()); + nsEmbedCString cTooltip; + NS_UTF16ToCString (nsEmbedString(tooltip), + NS_CSTRING_ENCODING_UTF8, cTooltip); + *description = g_strdup (cTooltip.get()); + nsMemory::Free (tooltip); } } @@ -744,14 +735,14 @@ impl_set_encoding (EphyEmbed *embed, { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; nsresult result; - nsCAutoString currEnc; + nsEmbedCString currEnc; g_return_if_fail (encoding != NULL); result = mpriv->browser->GetEncoding (currEnc); if (NS_FAILED (result)) return; - if (!currEnc.Equals(encoding) || + if (strcmp (currEnc.get(), encoding) != 0 || encoding[0] == '\0' && !ephy_embed_has_automatic_encoding (embed)) { result = mpriv->browser->ForceEncoding (encoding); @@ -767,11 +758,11 @@ impl_get_encoding (EphyEmbed *embed) { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; nsresult result; - nsCAutoString encoding; + nsEmbedCString encoding; result = mpriv->browser->GetEncoding (encoding); - if (NS_FAILED (result) || encoding.IsEmpty()) + if (NS_FAILED (result) || !encoding.Length()) { return NULL; } @@ -784,11 +775,11 @@ impl_has_automatic_encoding (EphyEmbed *embed) { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; nsresult result; - nsCAutoString encoding; + nsEmbedCString encoding; result = mpriv->browser->GetForcedEncoding (encoding); - if (NS_FAILED (result) || encoding.IsEmpty()) + if (NS_FAILED (result) || !encoding.Length()) { return TRUE; } @@ -820,13 +811,53 @@ mozilla_embed_location_changed_cb (GtkMozEmbed *embed, } static void +update_load_state (MozillaEmbed *membed, gint state) +{ + MozillaEmbedPrivate *priv = membed->priv; + + 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 (GTK_MOZ_EMBED (membed)); + g_signal_emit_by_name (membed, "ge_content_change", 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) { EmbedState estate = EMBED_STATE_UNKNOWN; int i; - + struct { guint state; @@ -852,6 +883,8 @@ mozilla_embed_net_state_all_cb (GtkMozEmbed *embed, const char *aURI, estate = (EmbedState) (estate | conversion_map[i].embed_state); } } + + update_load_state (membed, state); g_signal_emit_by_name (membed, "ge_net_state", aURI, estate); } @@ -887,10 +920,8 @@ mozilla_embed_dom_key_down_cb (GtkMozEmbed *embed, gpointer dom_event, if ((info->keycode == nsIDOMKeyEvent::DOM_VK_F10 && (info->modifier == GDK_SHIFT_MASK || info->modifier == GDK_CONTROL_MASK)) -#if MOZILLA_SNAPSHOT > 14 || (info->keycode == nsIDOMKeyEvent::DOM_VK_CONTEXT_MENU && !info->modifier) -#endif ) { /* Translate relative coordinates to absolute values, and try diff --git a/embed/mozilla/mozilla-version.h b/embed/mozilla/mozilla-version.h new file mode 100644 index 000000000..d59f5e493 --- /dev/null +++ b/embed/mozilla/mozilla-version.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifndef MOZILLA_VERSION_H +#define MOZILLA_VERSION_H + +/** + * Create a version int from components + */ +#define VERSION4(a,b,c,d) ((a << 24) + (b << 16) + (c << 8) + d) + +/** + * Macros for comparing mozilla version numbers + */ +#define MOZILLA_ALPHA 1 +#define MOZILLA_BETA 2 +#define MOZILLA_RC 3 +#define MOZILLA_RELEASE 4 + +#define MOZILLA_CHECK_VERSION4(major, minor, type, micro) \ + (VERSION4(MOZILLA_MAJOR, MOZILLA_MINOR, MOZILLA_TYPE, MOZILLA_MICRO) >= \ + VERSION4(major, minor, type, micro)) + +#define MOZILLA_CHECK_VERSION3(a,b,c) MOZILLA_CHECK_VERSION4(a,b,MOZILLA_RELEASE,c) +#define MOZILLA_CHECK_VERSION2(a,b) MOZILLA_CHECK_VERSION3(a,b,0) + +/* Use the following: + * + * 1.4.1 -> MOZILLA_CHECK_VERSION3 (1,4,1) + * 1.7 -> MOZILLA_CHECK_VERSION2 (1,7) + * 1.8a1 -> MOZILLA_CHECK_VERSION4 (1,8,MOZILLA_ALPHA,1) + * 1.7a -> MOZILLA_CHECK_VERSION4 (1,7,MOZILLA_ALPHA,0) + * 1.7rc2 -> MOZILLA_CHECK_VERSION4 (1,7,MOZILLA_RC, 2) + */ + +#endif /* MOZILLA_VERSION_H */ |