Skip to content
Snippets Groups Projects
Commit 66ab757c authored by vidur%netscape.com's avatar vidur%netscape.com
Browse files

Updated to the new version of nsIPrivateDOMImplementation. We now get a base...

Updated to the new version of nsIPrivateDOMImplementation. We now get a base URL for our own URL resolution from the subject codebase principal. This checkin is for code that is not part of the Seamonkey build.
parent f2f3d967
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "prprf.h" #include "prprf.h"
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsICodebasePrincipal.h"
static const char* kLoadAsData = "loadAsData"; static const char* kLoadAsData = "loadAsData";
static const char* kLoadStr = "load"; static const char* kLoadStr = "load";
...@@ -146,6 +148,7 @@ nsXMLHttpRequest::nsXMLHttpRequest() ...@@ -146,6 +148,7 @@ nsXMLHttpRequest::nsXMLHttpRequest()
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
mComplete = PR_FALSE; mComplete = PR_FALSE;
mAsync = PR_TRUE;
} }
nsXMLHttpRequest::~nsXMLHttpRequest() nsXMLHttpRequest::~nsXMLHttpRequest()
...@@ -527,7 +530,7 @@ nsXMLHttpRequest::OpenRequest(const char *method, ...@@ -527,7 +530,7 @@ nsXMLHttpRequest::OpenRequest(const char *method,
NS_ENSURE_ARG(url); NS_ENSURE_ARG(url);
nsresult rv; nsresult rv;
nsCOMPtr<nsIURI> uri, baseURI; nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
PRBool authp = PR_FALSE; PRBool authp = PR_FALSE;
...@@ -535,19 +538,18 @@ nsXMLHttpRequest::OpenRequest(const char *method, ...@@ -535,19 +538,18 @@ nsXMLHttpRequest::OpenRequest(const char *method,
// If we have a base document, use it for the base URL and loadgroup // If we have a base document, use it for the base URL and loadgroup
if (mBaseDocument) { if (mBaseDocument) {
baseURI = dont_AddRef(mBaseDocument->GetDocumentURL());
rv = mBaseDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); rv = mBaseDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
nsAutoString urlStr(url); nsAutoString urlStr(url);
rv = NS_NewURI(getter_AddRefs(uri), urlStr, baseURI); rv = NS_NewURI(getter_AddRefs(uri), urlStr, mBaseURI);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Only http URLs are allowed // Only http URLs are allowed
nsXPIDLCString protocol; nsXPIDLCString protocol;
uri->GetScheme(getter_Copies(protocol)); uri->GetScheme(getter_Copies(protocol));
if (nsCRT::strcmp("http", (const char*)protocol) != 0) { if (nsCRT::strncmp("http", (const char*)protocol, 4) != 0) {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
...@@ -572,11 +574,12 @@ nsXMLHttpRequest::OpenRequest(const char *method, ...@@ -572,11 +574,12 @@ nsXMLHttpRequest::OpenRequest(const char *method,
} }
mChannel->SetAuthTriedWithPrehost(authp); mChannel->SetAuthTriedWithPrehost(authp);
nsCOMPtr<nsIAtom> methodAtom = dont_AddRef(NS_NewAtom(method)); nsCOMPtr<nsIAtom> methodAtom = dont_AddRef(NS_NewAtom(method));
if (methodAtom) { if (methodAtom) {
rv = mChannel->SetRequestMethod(methodAtom); rv = mChannel->SetRequestMethod(methodAtom);
} }
return rv; return rv;
} }
...@@ -608,6 +611,19 @@ nsXMLHttpRequest::Open(const char *method, const PRUnichar *url) ...@@ -608,6 +611,19 @@ nsXMLHttpRequest::Open(const char *method, const PRUnichar *url)
rv = cc->GetJSContext(&cx); rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
NS_SCRIPTSECURITYMANAGER_PROGID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIPrincipal> principal;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICodebasePrincipal> codebase = do_QueryInterface(principal);
if (codebase) {
codebase->GetURI(getter_AddRefs(mBaseURI));
}
}
}
if (argc > 2) { if (argc > 2) {
JSBool bool; JSBool bool;
JS_ValueToBoolean(cx, argv[2], &bool); JS_ValueToBoolean(cx, argv[2], &bool);
...@@ -710,8 +726,6 @@ nsXMLHttpRequest::GetStreamForWString(const PRUnichar* aStr, ...@@ -710,8 +726,6 @@ nsXMLHttpRequest::GetStreamForWString(const PRUnichar* aStr,
NS_IMETHODIMP NS_IMETHODIMP
nsXMLHttpRequest::Send(nsISupports *body) nsXMLHttpRequest::Send(nsISupports *body)
{ {
NS_ENSURE_ARG(body);
nsresult rv; nsresult rv;
nsCOMPtr<nsIInputStream> postDataStream; nsCOMPtr<nsIInputStream> postDataStream;
...@@ -719,53 +733,55 @@ nsXMLHttpRequest::Send(nsISupports *body) ...@@ -719,53 +733,55 @@ nsXMLHttpRequest::Send(nsISupports *body)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
} }
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(body); if (body) {
if (doc) { nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(body);
// Get an XML serializer if (doc) {
nsCOMPtr<nsIDOMSerializer> serializer = do_CreateInstance(NS_XMLSERIALIZER_PROGID, &rv); // Get an XML serializer
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; nsCOMPtr<nsIDOMSerializer> serializer = do_CreateInstance(NS_XMLSERIALIZER_PROGID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// Serialize the current document to string
nsXPIDLString serial; // Serialize the current document to string
rv = serializer->SerializeToString(doc, getter_Copies(serial)); nsXPIDLString serial;
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; rv = serializer->SerializeToString(doc, getter_Copies(serial));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// Convert to a byte stream
rv = GetStreamForWString((const PRUnichar*)serial, // Convert to a byte stream
nsCRT::strlen((const PRUnichar*)serial), rv = GetStreamForWString((const PRUnichar*)serial,
getter_AddRefs(postDataStream)); nsCRT::strlen((const PRUnichar*)serial),
if (NS_FAILED(rv)) return rv; getter_AddRefs(postDataStream));
} if (NS_FAILED(rv)) return rv;
else {
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(body);
if (stream) {
postDataStream = stream;
} }
else { else {
nsCOMPtr<nsISupportsWString> wstr = do_QueryInterface(body); nsCOMPtr<nsIInputStream> stream = do_QueryInterface(body);
if (wstr) { if (stream) {
nsXPIDLString holder; postDataStream = stream;
wstr->GetData(getter_Copies(holder)); }
rv = GetStreamForWString((const PRUnichar*)holder, else {
nsCRT::strlen((const PRUnichar*)holder), nsCOMPtr<nsISupportsWString> wstr = do_QueryInterface(body);
getter_AddRefs(postDataStream)); if (wstr) {
if (NS_FAILED(rv)) return rv; nsXPIDLString holder;
wstr->GetData(getter_Copies(holder));
rv = GetStreamForWString((const PRUnichar*)holder,
nsCRT::strlen((const PRUnichar*)holder),
getter_AddRefs(postDataStream));
if (NS_FAILED(rv)) return rv;
}
} }
} }
}
if (postDataStream) { if (postDataStream) {
rv = mChannel->SetUploadStream(postDataStream); rv = mChannel->SetUploadStream(postDataStream);
}
} }
// Get and initialize a DOMImplementation // Get and initialize a DOMImplementation
nsCOMPtr<nsIDOMDOMImplementation> implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv); nsCOMPtr<nsIDOMDOMImplementation> implementation = do_CreateInstance(kIDOMDOMImplementationCID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (mBaseDocument) { if (mBaseURI) {
nsCOMPtr<nsIPrivateDOMImplementation> privImpl = do_QueryInterface(implementation); nsCOMPtr<nsIPrivateDOMImplementation> privImpl = do_QueryInterface(implementation);
if (privImpl) { if (privImpl) {
privImpl->Init(mBaseDocument); privImpl->Init(mBaseURI);
} }
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "nsString.h" #include "nsString.h"
#include "nsIDOMLoadListener.h" #include "nsIDOMLoadListener.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsIURI.h"
#include "nsIHTTPChannel.h" #include "nsIHTTPChannel.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
...@@ -69,6 +70,7 @@ protected: ...@@ -69,6 +70,7 @@ protected:
nsCOMPtr<nsIHTTPChannel> mChannel; nsCOMPtr<nsIHTTPChannel> mChannel;
nsCOMPtr<nsIDOMDocument> mDocument; nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIDocument> mBaseDocument; nsCOMPtr<nsIDocument> mBaseDocument;
nsCOMPtr<nsISupportsArray> mLoadEventListeners; nsCOMPtr<nsISupportsArray> mLoadEventListeners;
nsCOMPtr<nsISupportsArray> mErrorEventListeners; nsCOMPtr<nsISupportsArray> mErrorEventListeners;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment