Fixing bug 199489. Crash when changing iframe visibility from within the iframe. r=adamlock@netscape.com, sr=heikki@netscape.com.

This commit is contained in:
jst%netscape.com 2003-04-18 18:55:10 +00:00
Родитель 621aa81c2b
Коммит 0033534ef9
3 изменённых файлов: 64 добавлений и 60 удалений

Просмотреть файл

@ -2409,7 +2409,7 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
return NS_OK; // JS may not handle returning of an error code return NS_OK; // JS may not handle returning of an error code
} }
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsresult rv; nsresult rv = NS_OK;
// Create the fixup object if necessary // Create the fixup object if necessary
if (!mURIFixup) { if (!mURIFixup) {
mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID); mURIFixup = do_GetService(NS_URIFIXUP_CONTRACTID);
@ -5652,7 +5652,8 @@ nsresult nsDocShell::DoChannelLoad(nsIChannel * aChannel,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor, PRUint32 aLoadType, nscoord *cx, nscoord *cy) nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor,
PRUint32 aLoadType, nscoord *cx, nscoord *cy)
{ {
NS_ASSERTION(aURI, "null uri arg"); NS_ASSERTION(aURI, "null uri arg");
NS_ASSERTION(aWasAnchor, "null anchor arg"); NS_ASSERTION(aWasAnchor, "null anchor arg");
@ -5667,7 +5668,14 @@ nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor, PRUint32 aLoadTyp
return NS_OK; return NS_OK;
} }
nsresult rv = NS_OK; nsCOMPtr<nsIPresShell> shell;
nsresult rv = GetPresShell(getter_AddRefs(shell));
if (NS_FAILED(rv) || !shell) {
// If we failed to get the shell, or if there is no shell,
// nothing left to do here.
return rv;
}
// NOTE: we assume URIs are absolute for comparison purposes // NOTE: we assume URIs are absolute for comparison purposes
@ -5753,72 +5761,66 @@ nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor, PRUint32 aLoadTyp
GetCurScrollPos(ScrollOrientation_X, cx); GetCurScrollPos(ScrollOrientation_X, cx);
GetCurScrollPos(ScrollOrientation_Y, cy); GetCurScrollPos(ScrollOrientation_Y, cy);
nsCOMPtr<nsIPresShell> shell;
rv = GetPresShell(getter_AddRefs(shell));
if (NS_FAILED(rv))
return rv;
if (!sNewRef.IsEmpty()) { if (!sNewRef.IsEmpty()) {
if (shell) { *aWasAnchor = PR_TRUE;
*aWasAnchor = PR_TRUE;
// anchor is there, but if it's a load from history, // anchor is there, but if it's a load from history,
// we don't have any anchor jumping to do // we don't have any anchor jumping to do
PRBool scroll = aLoadType != LOAD_HISTORY && PRBool scroll = aLoadType != LOAD_HISTORY &&
aLoadType != LOAD_RELOAD_NORMAL; aLoadType != LOAD_RELOAD_NORMAL;
char *str = ToNewCString(sNewRef); char *str = ToNewCString(sNewRef);
// nsUnescape modifies the string that is passed into it. // nsUnescape modifies the string that is passed into it.
nsUnescape(str); nsUnescape(str);
// We assume that the bytes are in UTF-8, as it says in the spec: // We assume that the bytes are in UTF-8, as it says in the
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1 // spec:
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
// We try the UTF-8 string first, and then try the // We try the UTF-8 string first, and then try the document's
// document's charset (see below). // charset (see below). If the string is not UTF-8,
// If the string is not UTF-8, conversion will fail and give us // conversion will fail and give us an empty Unicode string.
// an empty Unicode string. In that case, we should just fall // In that case, we should just fall through to using the
// through to using the page's charset. // page's charset.
rv = NS_ERROR_FAILURE; rv = NS_ERROR_FAILURE;
NS_ConvertUTF8toUCS2 uStr(str); NS_ConvertUTF8toUCS2 uStr(str);
if (!uStr.IsEmpty()) { if (!uStr.IsEmpty()) {
rv = shell->GoToAnchor(NS_ConvertUTF8toUCS2(str), scroll); rv = shell->GoToAnchor(NS_ConvertUTF8toUCS2(str), scroll);
} }
nsMemory::Free(str); nsMemory::Free(str);
// Above will fail if the anchor name is not UTF-8. // Above will fail if the anchor name is not UTF-8. Need to
// Need to convert from document charset to unicode. // convert from document charset to unicode.
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
// Get a document charset // Get a document charset
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentViewer> nsCOMPtr<nsIDocumentViewer>
docv(do_QueryInterface(mContentViewer)); docv(do_QueryInterface(mContentViewer));
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIDocument> doc;
rv = docv->GetDocument(*getter_AddRefs(doc)); rv = docv->GetDocument(*getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsAutoString aCharset; nsAutoString aCharset;
rv = doc->GetDocumentCharacterSet(aCharset); rv = doc->GetDocumentCharacterSet(aCharset);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsCOMPtr<nsITextToSubURI> textToSubURI = nsCOMPtr<nsITextToSubURI> textToSubURI =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// Unescape and convert to unicode // Unescape and convert to unicode
nsXPIDLString uStr; nsXPIDLString uStr;
NS_LossyConvertUCS2toASCII charset(aCharset); NS_LossyConvertUCS2toASCII charset(aCharset);
rv = textToSubURI->UnEscapeAndConvert(charset.get(), rv = textToSubURI->UnEscapeAndConvert(charset.get(),
PromiseFlatCString(sNewRef).get(), PromiseFlatCString(sNewRef).get(),
getter_Copies(uStr)); getter_Copies(uStr));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
rv = shell->GoToAnchor(uStr, scroll); rv = shell->GoToAnchor(uStr, scroll);
}
} }
} }
else { else {

Просмотреть файл

@ -59,4 +59,4 @@ protected:
nsCOMArray<nsIClipboardDragDropHooks> mHookList; nsCOMArray<nsIClipboardDragDropHooks> mHookList;
}; };
#endif nsDocShellTransferableHooks_h__ #endif // nsDocShellTransferableHooks_h__

Просмотреть файл

@ -252,7 +252,10 @@ nsWebShell::EnsureCommandHandler()
if (!commandUpdater) return NS_ERROR_FAILURE; if (!commandUpdater) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor *, this)); nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor *, this));
nsresult rv = commandUpdater->Init(domWindow); #ifdef DEBUG
nsresult rv =
#endif
commandUpdater->Init(domWindow);
NS_ASSERTION(NS_SUCCEEDED(rv), "Initting command manager failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "Initting command manager failed");
} }
@ -569,7 +572,6 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent,
nsIDocShell** aDocShell, nsIDocShell** aDocShell,
nsIRequest** aRequest) nsIRequest** aRequest)
{ {
nsresult rv;
nsAutoString target(aTargetSpec); nsAutoString target(aTargetSpec);
// Initialize the DocShell / Request // Initialize the DocShell / Request