diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 57 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 66 |
3 files changed, 87 insertions, 45 deletions
@@ -1,3 +1,12 @@ +2004-05-11 Christian Persch <chpe@cvs.gnome.org> + + * embed/mozilla/EphyBrowser.cpp: + * embed/mozilla/mozilla-embed.cpp: + + Destroy the EphyBrowser in destroy handler, but delete it only on + finalize. Make public EphyBrowser methods safe for calling after + Destroy. Part of bug #142184. + 2004-05-10 Christian Persch <chpe@cvs.gnome.org> * src/ephy-statusbar.c: (create_statusbar_security_icon), diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 25dda8900..5836fb2a3 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -272,7 +272,7 @@ nsresult EphyBrowser::Print (nsIPrintSettings *options, PRBool preview) { nsresult result; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); @@ -294,7 +294,7 @@ nsresult EphyBrowser::PrintPreviewClose (void) nsresult rv; PRBool isPreview = PR_FALSE; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); @@ -312,7 +312,7 @@ nsresult EphyBrowser::PrintPreviewClose (void) nsresult EphyBrowser::PrintPreviewNumPages (int *numPages) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); @@ -322,7 +322,7 @@ nsresult EphyBrowser::PrintPreviewNumPages (int *numPages) nsresult EphyBrowser::PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); @@ -332,7 +332,7 @@ nsresult EphyBrowser::PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum) nsresult EphyBrowser::GetPrintSettings (nsIPrintSettings **options) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); @@ -344,7 +344,7 @@ nsresult EphyBrowser::GetSHistory (nsISHistory **aSHistory) { nsresult result; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebNavigation> ContentNav = do_QueryInterface (mWebBrowser); NS_ENSURE_TRUE (ContentNav, NS_ERROR_FAILURE); @@ -364,13 +364,16 @@ nsresult EphyBrowser::Destroy () DetachListeners (); mWebBrowser = nsnull; - + mDOMWindow = nsnull; + + mInitialized = PR_FALSE; + return NS_OK; } nsresult EphyBrowser::GoToHistoryIndex (PRInt16 index) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebNavigation> ContentNav = do_QueryInterface (mWebBrowser); NS_ENSURE_TRUE (ContentNav, NS_ERROR_FAILURE); @@ -380,7 +383,7 @@ nsresult EphyBrowser::GoToHistoryIndex (PRInt16 index) nsresult EphyBrowser::SetZoom (float aZoom, PRBool reflow) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; if (reflow) { @@ -454,6 +457,8 @@ nsresult EphyBrowser::GetContentViewer (nsIContentViewer **aViewer) nsresult EphyBrowser::GetZoom (float *aZoom) { + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsIContentViewer> contentViewer; GetContentViewer (getter_AddRefs(contentViewer)); NS_ENSURE_TRUE (contentViewer, NS_ERROR_FAILURE); @@ -473,7 +478,7 @@ nsresult EphyBrowser::GetTargetDocument (nsIDOMDocument **aDOMDocument) { nsresult result; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; /* Use the current target document */ if (mTargetDocument) @@ -503,6 +508,8 @@ nsresult EphyBrowser::GetTargetDocument (nsIDOMDocument **aDOMDocument) nsresult EphyBrowser::GetSHInfo (PRInt32 *count, PRInt32 *index) { + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsISHistory> SessionHistory; GetSHistory (getter_AddRefs(SessionHistory)); NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); @@ -515,6 +522,8 @@ nsresult EphyBrowser::GetSHInfo (PRInt32 *count, PRInt32 *index) nsresult EphyBrowser::GetSHTitleAtIndex (PRInt32 index, PRUnichar **title) { + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsISHistory> SessionHistory; GetSHistory (getter_AddRefs(SessionHistory)); NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); @@ -533,6 +542,8 @@ nsresult EphyBrowser::GetSHTitleAtIndex (PRInt32 index, PRUnichar **title) nsresult EphyBrowser::GetSHUrlAtIndex (PRInt32 index, nsCString &url) { + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsISHistory> SessionHistory; GetSHistory (getter_AddRefs(SessionHistory)); NS_ENSURE_TRUE (SessionHistory, NS_ERROR_FAILURE); @@ -557,7 +568,7 @@ nsresult EphyBrowser::FindSetProperties (const PRUnichar *search_string, PRBool case_sensitive, PRBool wrap_around) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserFind> finder (do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (finder, NS_ERROR_FAILURE); @@ -572,7 +583,7 @@ nsresult EphyBrowser::FindSetProperties (const PRUnichar *search_string, nsresult EphyBrowser::Find (PRBool backwards, PRBool *didFind) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIWebBrowserFind> finder (do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (finder, NS_ERROR_FAILURE); @@ -584,7 +595,7 @@ nsresult EphyBrowser::Find (PRBool backwards, nsresult EphyBrowser::GetPageDescriptor(nsISupports **aPageDescriptor) { - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIDocShell> ds = do_GetInterface (mWebBrowser); @@ -622,6 +633,8 @@ nsresult EphyBrowser::GetDocumentUrl (nsCString &url) nsresult EphyBrowser::GetTargetDocumentUrl (nsCString &url) { + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsIDOMDocument> DOMDocument; GetTargetDocument (getter_AddRefs(DOMDocument)); NS_ENSURE_TRUE (DOMDocument, NS_ERROR_FAILURE); @@ -643,7 +656,7 @@ nsresult EphyBrowser::GetTargetDocumentUrl (nsCString &url) nsresult EphyBrowser::ForceEncoding (const char *encoding) { - NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIContentViewer> contentViewer; GetContentViewer (getter_AddRefs(contentViewer)); @@ -657,7 +670,7 @@ nsresult EphyBrowser::ForceEncoding (const char *encoding) nsresult EphyBrowser::GetEncoding (nsACString &encoding) { - NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMDocument> domDoc; GetTargetDocument (getter_AddRefs(domDoc)); @@ -674,7 +687,7 @@ nsresult EphyBrowser::GetEncoding (nsACString &encoding) nsresult EphyBrowser::GetForcedEncoding (nsACString &encoding) { - NS_ENSURE_TRUE (mInitialized, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; nsCOMPtr<nsIContentViewer> contentViewer; GetContentViewer (getter_AddRefs(contentViewer)); @@ -705,10 +718,9 @@ nsresult EphyBrowser::PopTargetDocument () nsresult EphyBrowser::DoCommand (const char *command) { - nsCOMPtr<nsICommandManager> cmdManager; - - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsICommandManager> cmdManager; cmdManager = do_GetInterface (mWebBrowser); NS_ENSURE_TRUE (cmdManager, NS_ERROR_FAILURE); @@ -717,10 +729,9 @@ nsresult EphyBrowser::DoCommand (const char *command) nsresult EphyBrowser::GetCommandState (const char *command, PRBool *enabled) { - nsCOMPtr<nsICommandManager> cmdManager; - - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsICommandManager> cmdManager; cmdManager = do_GetInterface (mWebBrowser); NS_ENSURE_TRUE (cmdManager, NS_ERROR_FAILURE); @@ -831,6 +842,8 @@ nsresult EphyBrowser::GetHasModifiedForms (PRBool *modified) { *modified = PR_FALSE; + if (!mWebBrowser) return NS_ERROR_FAILURE; + nsCOMPtr<nsIDocShell> rootDocShell = do_GetInterface (mWebBrowser); NS_ENSURE_TRUE (rootDocShell, NS_ERROR_FAILURE); diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index 4452fa334..e5e14e98c 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -54,6 +54,7 @@ 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); @@ -244,6 +245,7 @@ mozilla_embed_class_init (MozillaEmbedClass *klass) parent_class = (GObjectClass *) g_type_class_peek_parent (klass); object_class->constructor = mozilla_embed_constructor; + object_class->finalize = mozilla_embed_finalize; gtk_object_class->destroy = mozilla_embed_destroy; @@ -257,22 +259,8 @@ mozilla_embed_init (MozillaEmbed *embed) { embed->priv = MOZILLA_EMBED_GET_PRIVATE (embed); embed->priv->browser = new EphyBrowser (); - embed->priv->security_state = -1; + embed->priv->security_state = STATE_IS_UNKNOWN; - mozilla_embed_connect_signals (embed); -} - -gpointer -_mozilla_embed_get_ephy_browser (MozillaEmbed *embed) -{ - g_return_val_if_fail (embed->priv->browser != NULL, NULL); - - return embed->priv->browser; -} - -static void -mozilla_embed_connect_signals (MozillaEmbed *embed) -{ g_signal_connect_object (G_OBJECT (embed), "location", G_CALLBACK (mozilla_embed_location_changed_cb), embed, (GConnectFlags) 0); @@ -296,6 +284,14 @@ mozilla_embed_connect_signals (MozillaEmbed *embed) embed, (GConnectFlags) 0); } +gpointer +_mozilla_embed_get_ephy_browser (MozillaEmbed *embed) +{ + g_return_val_if_fail (embed->priv->browser != NULL, NULL); + + return embed->priv->browser; +} + static void mozilla_embed_destroy (GtkObject *object) { @@ -304,14 +300,28 @@ mozilla_embed_destroy (GtkObject *object) if (embed->priv->browser) { embed->priv->browser->Destroy(); - delete embed->priv->browser; - embed->priv->browser = NULL; } GTK_OBJECT_CLASS (parent_class)->destroy (object); } static void +mozilla_embed_finalize (GObject *object) +{ + MozillaEmbed *embed = MOZILLA_EMBED (object); + + if (embed->priv->browser) + { + delete embed->priv->browser; + embed->priv->browser = nsnull; + } + + embed->priv->request = nsnull; + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void impl_load_url (EphyEmbed *embed, const char *url) { @@ -451,7 +461,10 @@ impl_go_up (EphyEmbed *embed) char *parent_uri; uri = ephy_embed_get_location (embed, TRUE); - g_return_if_fail (uri != NULL); + if (uri == NULL) + { + return; + } parent_uri = mozilla_embed_get_uri_parent (uri); g_free (uri); @@ -519,8 +532,7 @@ impl_reload (EphyEmbed *embed, mflags = GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE; } - gtk_moz_embed_reload (GTK_MOZ_EMBED(embed), - mflags); + gtk_moz_embed_reload (GTK_MOZ_EMBED(embed), mflags); } static void @@ -595,9 +607,16 @@ impl_shistory_get_nth (EphyEmbed *embed, rv = mpriv->browser->GetSHTitleAtIndex(nth, &title); - *aTitle = g_strdup (NS_ConvertUTF16toUTF8(title).get()); + if (title) + { + *aTitle = g_strdup (NS_ConvertUTF16toUTF8(title).get()); - nsMemory::Free (title); + nsMemory::Free (title); + } + else + { + *aTitle = NULL; + } } static int @@ -628,7 +647,8 @@ impl_get_security_level (EphyEmbed *embed, { nsresult result; - g_return_if_fail (description != NULL || level != NULL); + g_return_if_fail (description != NULL && level != NULL); + *description = NULL; *level = STATE_IS_UNKNOWN; |