Fixed 37702 and 47670. r=vidur

This commit is contained in:
mstoltz%netscape.com 2000-08-09 20:08:54 +00:00
Родитель f064495d03
Коммит 23306a4e04
3 изменённых файлов: 50 добавлений и 30 удалений

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

@ -2983,13 +2983,30 @@ NS_IMETHODIMP nsDocShell::GetCurrentDocumentOwner(nsISupports** aOwner)
{
nsresult rv;
*aOwner = nsnull;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
if (!docv) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
rv = docv->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv) || !doc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> document;
//-- Get the current document
if (mContentViewer)
{
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(mContentViewer));
if (!docViewer) return NS_ERROR_FAILURE;
rv = docViewer->GetDocument(*getter_AddRefs(document));
}
else //-- If there's no document loaded yet, look at the parent (frameset)
{
nsCOMPtr<nsIDocShellTreeItem> parentItem;
rv = GetSameTypeParent(getter_AddRefs(parentItem));
if (NS_FAILED(rv) || !parentItem) return rv;
nsCOMPtr<nsIDOMWindow> parentWindow(do_GetInterface(parentItem));
if (!parentWindow) return NS_OK;
nsCOMPtr<nsIDOMDocument> parentDomDoc;
rv = parentWindow->GetDocument(getter_AddRefs(parentDomDoc));
if (!parentDomDoc) return NS_OK;
document = do_QueryInterface(parentDomDoc);
}
//-- Get the document's principal
nsCOMPtr<nsIPrincipal> principal;
rv = doc->GetPrincipal(getter_AddRefs(principal));
rv = document->GetPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal) return NS_ERROR_FAILURE;
rv = principal->QueryInterface(NS_GET_IID(nsISupports),(void**)aOwner);
return rv;

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

@ -70,6 +70,7 @@ class LocationImpl;
class NavigatorImpl;
class ScreenImpl;
class HistoryImpl;
class nsIDocShellLoadInfo;
//*****************************************************************************
// GlobalWindowImpl: Global Object for Scripting
@ -361,7 +362,7 @@ protected:
PRBool aReplace);
nsresult GetSourceURL(JSContext* cx,
nsIURI** sourceURL);
nsresult CheckURL(nsIURI *url, nsIURI** aReferrer);
nsresult CheckURL(nsIURI *url, nsIDocShellLoadInfo** aLoadInfo);
nsIDocShell *mDocShell; // Weak Reference
void *mScriptObject;

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

@ -104,7 +104,7 @@ NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell)
}
nsresult
LocationImpl::CheckURL(nsIURI* aURL, nsIURI** aReferrer)
LocationImpl::CheckURL(nsIURI* aURL, nsIDocShellLoadInfo** aLoadInfo)
{
nsresult result;
// Get JSContext from stack.
@ -126,16 +126,29 @@ LocationImpl::CheckURL(nsIURI* aURL, nsIURI** aReferrer)
if (NS_FAILED(result = secMan->CheckLoadURIFromScript(cx, aURL)))
return result;
// Now get the referrer to use when loading the URI
nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))))
return NS_ERROR_FAILURE;
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
if (codebase) {
if (NS_FAILED(result = codebase->GetURI(aReferrer)))
return result;
}
// Create load info
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
// Now get the principal and referrer to use when loading the URI
nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) ||
!principal)
return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> owner = do_QueryInterface(principal);
loadInfo->SetOwner(owner);
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
if (!codebase) return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> referrer;
if (NS_FAILED(result = codebase->GetURI(getter_AddRefs(referrer))))
return result;
loadInfo->SetReferrer(referrer);
*aLoadInfo = loadInfo.get();
NS_ADDREF(*aLoadInfo);
return NS_OK;
}
@ -146,15 +159,9 @@ LocationImpl::SetURL(nsIURI* aURL)
if (mDocShell) {
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
nsCOMPtr<nsIURI> referrer;
if(NS_FAILED(CheckURL(aURL, getter_AddRefs(referrer))))
if(NS_FAILED(CheckURL(aURL, getter_AddRefs(loadInfo))))
return NS_ERROR_FAILURE;
loadInfo->SetReferrer(referrer);
return mDocShell->LoadURI(aURL, loadInfo);
}
else {
@ -371,14 +378,9 @@ LocationImpl::SetHrefWithBase(const nsString& aHref,
if ((NS_OK == result) && (mDocShell)) {
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
nsCOMPtr<nsIURI> referrer;
if(NS_FAILED(CheckURL(newUrl, getter_AddRefs(referrer))))
if(NS_FAILED(CheckURL(newUrl, getter_AddRefs(loadInfo))))
return NS_ERROR_FAILURE;
loadInfo->SetReferrer(referrer);
if (aReplace)
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);