Fix for bug 208912. DOMParser produces documents with about:blank uri.

r=heikki, sr=peterv
This commit is contained in:
varga%netscape.com 2006-04-20 03:38:27 +00:00
Родитель 8fcface92b
Коммит f44103de55
2 изменённых файлов: 38 добавлений и 16 удалений

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

@ -36,6 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "jsapi.h"
#include "nsDOMParser.h"
#include "nsIURI.h"
#include "nsIChannel.h"
@ -51,10 +52,13 @@
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMWindow.h"
#include "nsIPrivateDOMImplementation.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsICodebasePrincipal.h"
#include "nsIPrincipal.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMClassInfo.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
@ -438,10 +442,6 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
nsresult rv;
nsCOMPtr<nsIURI> baseURI;
nsCOMPtr<nsIPrincipal> principal;
// For now, we can only create XML documents.
if (nsCRT::strcmp(contentType, "text/xml") != 0 &&
nsCRT::strcmp(contentType, "application/xml") != 0 &&
@ -449,7 +449,17 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
return NS_ERROR_NOT_IMPLEMENTED;
}
// First try to find a base URI for the document we're creating
nsresult rv;
nsCOMPtr<nsIPrincipal> principal;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
secMan->GetSubjectPrincipal(getter_AddRefs(principal));
}
// Try to find a base URI for the document we're creating.
nsCOMPtr<nsIURI> baseURI;
nsCOMPtr<nsIXPCNativeCallContext> cc;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
if(NS_SUCCEEDED(rv)) {
@ -460,15 +470,24 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICodebasePrincipal> codebase(do_QueryInterface(principal));
if (codebase) {
codebase->GetURI(getter_AddRefs(baseURI));
nsISupports *supports =
(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
? NS_STATIC_CAST(nsISupports*, ::JS_GetContextPrivate(cx))
: nsnull;
nsCOMPtr<nsIScriptContext> scriptContext = do_QueryInterface(supports);
if (scriptContext) {
nsCOMPtr<nsIScriptGlobalObject> globalObject;
scriptContext->GetGlobalObject(getter_AddRefs(globalObject));
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(globalObject);
if (window) {
nsCOMPtr<nsIDOMDocument> domdoc;
window->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
if (doc) {
doc->GetBaseURL(*getter_AddRefs(baseURI));
}
}
}

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

@ -135,7 +135,10 @@ GetCurrentContext(nsIScriptContext **aScriptContext)
return;
}
nsISupports *priv = (nsISupports *)::JS_GetContextPrivate(cx);
nsISupports *priv =
(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
? NS_STATIC_CAST(nsISupports*, ::JS_GetContextPrivate(cx))
: nsnull;
if (!priv) {
return;