From 3579f6aecc1d43fcc253fe7120b9c0eba7004edb Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Fri, 21 Jun 2002 03:36:44 +0000 Subject: [PATCH] Do better error checking to prevent crashing trying to show a JS dialog when loading a tab in the background (bug 152945) --- camino/CHBrowserView.mm | 10 +++++----- camino/nsCocoaBrowserService.mm | 8 ++++++-- camino/src/embedding/CHBrowserService.mm | 8 ++++++-- camino/src/embedding/CHBrowserView.mm | 10 +++++----- chimera/CHBrowserView.mm | 10 +++++----- chimera/nsCocoaBrowserService.mm | 8 ++++++-- chimera/src/embedding/CHBrowserService.mm | 8 ++++++-- chimera/src/embedding/CHBrowserView.mm | 10 +++++----- 8 files changed, 44 insertions(+), 28 deletions(-) diff --git a/camino/CHBrowserView.mm b/camino/CHBrowserView.mm index f3659ca92a0..90f328f2ab9 100644 --- a/camino/CHBrowserView.mm +++ b/camino/CHBrowserView.mm @@ -541,7 +541,7 @@ NS_IMETHODIMP nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) { NS_ENSURE_ARG_POINTER(aSiteWindow); - + *aSiteWindow = nsnull; if (!mView) { return NS_ERROR_FAILURE; } @@ -715,7 +715,7 @@ private: NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) // Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, PRUint32 aStatus) @@ -1357,7 +1357,6 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq filterList: aFilterList]; } - -(IBAction)cut:(id)aSender { nsCOMPtr clipboard(do_GetInterface(_webBrowser)); @@ -1378,8 +1377,9 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq -(IBAction)delete:(id)aSender { - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectNone(); +// nsCOMPtr clipboard(do_GetInterface(_webBrowser)); +// clipboard->SelectNone(); + NSLog(@"delete not implemented\n"); } -(IBAction)selectAll:(id)aSender diff --git a/camino/nsCocoaBrowserService.mm b/camino/nsCocoaBrowserService.mm index 2ad00bd85fa..116628a3a78 100644 --- a/camino/nsCocoaBrowserService.mm +++ b/camino/nsCocoaBrowserService.mm @@ -205,7 +205,9 @@ GetNSWindowForDOMWindow(nsIDOMWindow* window) } NSWindow* nswin; - siteWindow->GetSiteWindow((void**)&nswin); + nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); + if (NS_FAILED(rv)) + return nsnull; return nswin; } @@ -224,6 +226,8 @@ nsCocoaBrowserService::Alert(nsIDOMWindow *parent, NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)]; NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)]; NSWindow* window = GetNSWindowForDOMWindow(parent); + if (!window) + return NS_ERROR_FAILURE; [controller alert:window title:titleStr text:textStr]; @@ -650,7 +654,7 @@ nsCocoaBrowserService::CertExpired(nsITransportSecurityInfo *socketInfo, // HACK: there is no way to get which window this is for from the API. The // security team in mozilla just cheats and assumes the frontmost window so // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller certExpired:[NSApp mainWindow]]; + *_retval = (PRBool)[controller expiredCert:[NSApp mainWindow]]; return NS_OK; } diff --git a/camino/src/embedding/CHBrowserService.mm b/camino/src/embedding/CHBrowserService.mm index 2ad00bd85fa..116628a3a78 100644 --- a/camino/src/embedding/CHBrowserService.mm +++ b/camino/src/embedding/CHBrowserService.mm @@ -205,7 +205,9 @@ GetNSWindowForDOMWindow(nsIDOMWindow* window) } NSWindow* nswin; - siteWindow->GetSiteWindow((void**)&nswin); + nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); + if (NS_FAILED(rv)) + return nsnull; return nswin; } @@ -224,6 +226,8 @@ nsCocoaBrowserService::Alert(nsIDOMWindow *parent, NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)]; NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)]; NSWindow* window = GetNSWindowForDOMWindow(parent); + if (!window) + return NS_ERROR_FAILURE; [controller alert:window title:titleStr text:textStr]; @@ -650,7 +654,7 @@ nsCocoaBrowserService::CertExpired(nsITransportSecurityInfo *socketInfo, // HACK: there is no way to get which window this is for from the API. The // security team in mozilla just cheats and assumes the frontmost window so // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller certExpired:[NSApp mainWindow]]; + *_retval = (PRBool)[controller expiredCert:[NSApp mainWindow]]; return NS_OK; } diff --git a/camino/src/embedding/CHBrowserView.mm b/camino/src/embedding/CHBrowserView.mm index f3659ca92a0..90f328f2ab9 100644 --- a/camino/src/embedding/CHBrowserView.mm +++ b/camino/src/embedding/CHBrowserView.mm @@ -541,7 +541,7 @@ NS_IMETHODIMP nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) { NS_ENSURE_ARG_POINTER(aSiteWindow); - + *aSiteWindow = nsnull; if (!mView) { return NS_ERROR_FAILURE; } @@ -715,7 +715,7 @@ private: NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) // Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, PRUint32 aStatus) @@ -1357,7 +1357,6 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq filterList: aFilterList]; } - -(IBAction)cut:(id)aSender { nsCOMPtr clipboard(do_GetInterface(_webBrowser)); @@ -1378,8 +1377,9 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq -(IBAction)delete:(id)aSender { - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectNone(); +// nsCOMPtr clipboard(do_GetInterface(_webBrowser)); +// clipboard->SelectNone(); + NSLog(@"delete not implemented\n"); } -(IBAction)selectAll:(id)aSender diff --git a/chimera/CHBrowserView.mm b/chimera/CHBrowserView.mm index f3659ca92a0..90f328f2ab9 100644 --- a/chimera/CHBrowserView.mm +++ b/chimera/CHBrowserView.mm @@ -541,7 +541,7 @@ NS_IMETHODIMP nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) { NS_ENSURE_ARG_POINTER(aSiteWindow); - + *aSiteWindow = nsnull; if (!mView) { return NS_ERROR_FAILURE; } @@ -715,7 +715,7 @@ private: NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) // Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, PRUint32 aStatus) @@ -1357,7 +1357,6 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq filterList: aFilterList]; } - -(IBAction)cut:(id)aSender { nsCOMPtr clipboard(do_GetInterface(_webBrowser)); @@ -1378,8 +1377,9 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq -(IBAction)delete:(id)aSender { - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectNone(); +// nsCOMPtr clipboard(do_GetInterface(_webBrowser)); +// clipboard->SelectNone(); + NSLog(@"delete not implemented\n"); } -(IBAction)selectAll:(id)aSender diff --git a/chimera/nsCocoaBrowserService.mm b/chimera/nsCocoaBrowserService.mm index 2ad00bd85fa..116628a3a78 100644 --- a/chimera/nsCocoaBrowserService.mm +++ b/chimera/nsCocoaBrowserService.mm @@ -205,7 +205,9 @@ GetNSWindowForDOMWindow(nsIDOMWindow* window) } NSWindow* nswin; - siteWindow->GetSiteWindow((void**)&nswin); + nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); + if (NS_FAILED(rv)) + return nsnull; return nswin; } @@ -224,6 +226,8 @@ nsCocoaBrowserService::Alert(nsIDOMWindow *parent, NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)]; NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)]; NSWindow* window = GetNSWindowForDOMWindow(parent); + if (!window) + return NS_ERROR_FAILURE; [controller alert:window title:titleStr text:textStr]; @@ -650,7 +654,7 @@ nsCocoaBrowserService::CertExpired(nsITransportSecurityInfo *socketInfo, // HACK: there is no way to get which window this is for from the API. The // security team in mozilla just cheats and assumes the frontmost window so // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller certExpired:[NSApp mainWindow]]; + *_retval = (PRBool)[controller expiredCert:[NSApp mainWindow]]; return NS_OK; } diff --git a/chimera/src/embedding/CHBrowserService.mm b/chimera/src/embedding/CHBrowserService.mm index 2ad00bd85fa..116628a3a78 100644 --- a/chimera/src/embedding/CHBrowserService.mm +++ b/chimera/src/embedding/CHBrowserService.mm @@ -205,7 +205,9 @@ GetNSWindowForDOMWindow(nsIDOMWindow* window) } NSWindow* nswin; - siteWindow->GetSiteWindow((void**)&nswin); + nsresult rv = siteWindow->GetSiteWindow((void**)&nswin); + if (NS_FAILED(rv)) + return nsnull; return nswin; } @@ -224,6 +226,8 @@ nsCocoaBrowserService::Alert(nsIDOMWindow *parent, NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)]; NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)]; NSWindow* window = GetNSWindowForDOMWindow(parent); + if (!window) + return NS_ERROR_FAILURE; [controller alert:window title:titleStr text:textStr]; @@ -650,7 +654,7 @@ nsCocoaBrowserService::CertExpired(nsITransportSecurityInfo *socketInfo, // HACK: there is no way to get which window this is for from the API. The // security team in mozilla just cheats and assumes the frontmost window so // that's what we'll do. Yes, it's wrong. Yes, it's skanky. Oh well. - *_retval = (PRBool)[controller certExpired:[NSApp mainWindow]]; + *_retval = (PRBool)[controller expiredCert:[NSApp mainWindow]]; return NS_OK; } diff --git a/chimera/src/embedding/CHBrowserView.mm b/chimera/src/embedding/CHBrowserView.mm index f3659ca92a0..90f328f2ab9 100644 --- a/chimera/src/embedding/CHBrowserView.mm +++ b/chimera/src/embedding/CHBrowserView.mm @@ -541,7 +541,7 @@ NS_IMETHODIMP nsCocoaBrowserListener::GetSiteWindow(void * *aSiteWindow) { NS_ENSURE_ARG_POINTER(aSiteWindow); - + *aSiteWindow = nsnull; if (!mView) { return NS_ERROR_FAILURE; } @@ -715,7 +715,7 @@ private: NS_IMPL_ISUPPORTS1(nsHeaderSniffer, nsIWebProgressListener) // Implementation of nsIWebProgressListener -/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in unsigned long aStatus); */ +/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long aStateFlags, in unsigned long aStatus); */ NS_IMETHODIMP nsHeaderSniffer::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, PRUint32 aStatus) @@ -1357,7 +1357,6 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq filterList: aFilterList]; } - -(IBAction)cut:(id)aSender { nsCOMPtr clipboard(do_GetInterface(_webBrowser)); @@ -1378,8 +1377,9 @@ nsHeaderSniffer::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aReq -(IBAction)delete:(id)aSender { - nsCOMPtr clipboard(do_GetInterface(_webBrowser)); - clipboard->SelectNone(); +// nsCOMPtr clipboard(do_GetInterface(_webBrowser)); +// clipboard->SelectNone(); + NSLog(@"delete not implemented\n"); } -(IBAction)selectAll:(id)aSender