jst%netscape.com 2006-04-20 03:37:17 +00:00
Родитель d225afedf0
Коммит f8f5541143
7 изменённых файлов: 132 добавлений и 190 удалений

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

@ -28,28 +28,6 @@ interface nsIHTTPChannel;
[scriptable, uuid(b7215e70-4157-11d4-9a42-000064657374)]
interface nsIXMLHttpRequest : nsISupports {
/**
* Native (non-script) mechanism for adding an event listener for
* either a load or error event.
*
* @param type The event the listener is added for - either
* "load" or "error".
* @param listener The listener to be added.
*/
[noscript] void addEventListener(in string type,
in nsIDOMEventListener listener);
/**
* Native (non-script) mechanism for removing an event listener for
* either a load or error event.
*
* @param type The event the listener is removed for - either
* "load" or "error".
* @param listener The listener instance to be removed.
*/
[noscript] void removeEventListener(in string type,
in nsIDOMEventListener listener);
/**
* Meant to be a script-only mechanism for setting a load event listener.
* The attribute is expected to be JavaScript function object. When

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

@ -39,6 +39,7 @@
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsICodebasePrincipal.h"
#include "nsIDOMClassInfo.h"
static const char* kLoadAsData = "loadAsData";
@ -260,7 +261,23 @@ nsDOMParser::~nsDOMParser()
{
}
NS_IMPL_ISUPPORTS2(nsDOMParser, nsIDOMParser, nsISecurityCheckedComponent)
// XPConnect interface list for nsDOMParser
NS_CLASSINFO_MAP_BEGIN(DOMParser)
NS_CLASSINFO_MAP_ENTRY(nsIDOMParser)
NS_CLASSINFO_MAP_END
// QueryInterface implementation for nsDOMParser
NS_INTERFACE_MAP_BEGIN(nsDOMParser)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMParser)
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(DOMParser)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMParser)
NS_IMPL_RELEASE(nsDOMParser)
static nsresult
ConvertWStringToStream(const PRUnichar* aStr,
@ -484,49 +501,3 @@ nsDOMParser::SetBaseURI(nsIURI *aBaseURI)
mBaseURI = aBaseURI;
return NS_OK;
}
static const char* kAllAccess = "AllAccess";
/* string canCreateWrapper (in nsIIDPtr iid); */
NS_IMETHODIMP
nsDOMParser::CanCreateWrapper(const nsIID * iid, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMParser))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
NS_IMETHODIMP
nsDOMParser::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMParser))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsDOMParser::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMParser))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsDOMParser::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMParser))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}

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

@ -29,8 +29,7 @@
#include "nsCOMPtr.h"
#include "nsIURI.h"
class nsDOMParser : public nsIDOMParser,
public nsISecurityCheckedComponent
class nsDOMParser : public nsIDOMParser
{
public:
nsDOMParser();
@ -41,8 +40,6 @@ public:
// nsIDOMParser
NS_DECL_NSIDOMPARSER
NS_DECL_NSISECURITYCHECKEDCOMPONENT
private:
nsCOMPtr<nsIURI> mBaseURI;
};

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

@ -23,6 +23,7 @@
#include "nsDOMSerializer.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIDOMClassInfo.h"
#include "nsIOutputStream.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
@ -43,7 +44,24 @@ nsDOMSerializer::~nsDOMSerializer()
{
}
NS_IMPL_ISUPPORTS2(nsDOMSerializer, nsIDOMSerializer, nsISecurityCheckedComponent)
// XPConnect interface list for nsDOMSerializer
NS_CLASSINFO_MAP_BEGIN(DOMSerializer)
NS_CLASSINFO_MAP_ENTRY(nsIDOMSerializer)
NS_CLASSINFO_MAP_END
// QueryInterface implementation for nsDOMSerializer
NS_INTERFACE_MAP_BEGIN(nsDOMSerializer)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMSerializer)
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(DOMSerializer)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMSerializer)
NS_IMPL_RELEASE(nsDOMSerializer)
static nsresult SetUpEncoder(nsIDOMNode *aRoot, const char* aCharset, nsIDocumentEncoder **aEncoder)
{
@ -140,50 +158,3 @@ nsDOMSerializer::SerializeToStream(nsIDOMNode *root,
return encoder->EncodeToStream(stream);
}
static const char* kAllAccess = "AllAccess";
/* string canCreateWrapper (in nsIIDPtr iid); */
NS_IMETHODIMP
nsDOMSerializer::CanCreateWrapper(const nsIID * iid, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMSerializer))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
NS_IMETHODIMP
nsDOMSerializer::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMSerializer))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsDOMSerializer::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMSerializer))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsDOMSerializer::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsIDOMSerializer))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}

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

@ -27,8 +27,7 @@
#include "nsISecurityCheckedComponent.h"
#include "nsISupportsUtils.h"
class nsDOMSerializer : public nsIDOMSerializer,
public nsISecurityCheckedComponent
class nsDOMSerializer : public nsIDOMSerializer
{
public:
nsDOMSerializer();
@ -41,8 +40,6 @@ public:
NS_IMETHOD SerializeToStream(nsIDOMNode *root,
nsIOutputStream *stream,
const char *charset);
NS_DECL_NSISECURITYCHECKEDCOMPONENT
};

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

@ -45,7 +45,6 @@
#include "nsICodebasePrincipal.h"
#include "nsWeakPtr.h"
#include "nsICharsetAlias.h"
#include "nsDOMPropEnums.h"
#ifdef IMPLEMENT_SYNC_LOAD
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
@ -55,10 +54,11 @@
#include "nsIEventQueueService.h"
#include "nsIInterfaceRequestor.h"
#endif
#include "nsIDOMClassInfo.h"
static const char* kLoadAsData = "loadAsData";
static const char* kLoadStr = "load";
static const char* kErrorStr = "error";
#define LOADSTR NS_LITERAL_STRING("load")
#define ERRORSTR NS_LITERAL_STRING("error")
// CIDs
static NS_DEFINE_CID(kIDOMDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
@ -72,13 +72,13 @@ GetSafeContext()
{
// Get the "safe" JSContext: our JSContext of last resort
nsresult rv;
NS_WITH_SERVICE(nsIJSContextStack, stack, "@mozilla.org/js/xpc/ContextStack;1",
&rv);
nsCOMPtr<nsIThreadJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
if (NS_FAILED(rv))
return nsnull;
nsCOMPtr<nsIThreadJSContextStack> tcs(do_QueryInterface(stack));
JSContext* cx;
if (NS_FAILED(tcs->GetSafeJSContext(&cx))) {
if (NS_FAILED(stack->GetSafeJSContext(&cx))) {
return nsnull;
}
return cx;
@ -124,7 +124,7 @@ nsXMLHttpRequestScriptListener::~nsXMLHttpRequestScriptListener()
NS_IMPL_ISUPPORTS2(nsXMLHttpRequestScriptListener, nsIDOMEventListener, nsIPrivateJSEventListener)
nsresult
NS_IMETHODIMP
nsXMLHttpRequestScriptListener::HandleEvent(nsIDOMEvent* aEvent)
{
JSContext* cx;
@ -174,13 +174,13 @@ public:
NS_DECL_ISUPPORTS
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
virtual nsresult Load(nsIDOMEvent* aEvent);
virtual nsresult Unload(nsIDOMEvent* aEvent);
virtual nsresult Abort(nsIDOMEvent* aEvent);
virtual nsresult Error(nsIDOMEvent* aEvent);
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
protected:
nsWeakPtr mParent;
@ -198,7 +198,7 @@ nsLoadListenerProxy::~nsLoadListenerProxy()
NS_IMPL_ISUPPORTS1(nsLoadListenerProxy, nsIDOMLoadListener)
nsresult
NS_IMETHODIMP
nsLoadListenerProxy::HandleEvent(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
@ -210,7 +210,7 @@ nsLoadListenerProxy::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
nsresult
NS_IMETHODIMP
nsLoadListenerProxy::Load(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
@ -222,7 +222,7 @@ nsLoadListenerProxy::Load(nsIDOMEvent* aEvent)
return NS_OK;
}
nsresult
NS_IMETHODIMP
nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
@ -234,7 +234,7 @@ nsLoadListenerProxy::Unload(nsIDOMEvent* aEvent)
return NS_OK;
}
nsresult
NS_IMETHODIMP
nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
@ -246,7 +246,7 @@ nsLoadListenerProxy::Abort(nsIDOMEvent* aEvent)
return NS_OK;
}
nsresult
NS_IMETHODIMP
nsLoadListenerProxy::Error(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMLoadListener> listener(do_QueryReferent(mParent));
@ -282,38 +282,51 @@ nsXMLHttpRequest::~nsXMLHttpRequest()
#endif
}
NS_IMPL_ADDREF(nsXMLHttpRequest)
NS_IMPL_RELEASE(nsXMLHttpRequest)
// XPConnect interface list for nsXMLHttpRequest
NS_CLASSINFO_MAP_BEGIN(XMLHttpRequest)
NS_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequest)
NS_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
NS_CLASSINFO_MAP_END
// QueryInterface implementation for nsXMLHttpRequest
NS_INTERFACE_MAP_BEGIN(nsXMLHttpRequest)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLHttpRequest)
NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequest)
NS_INTERFACE_MAP_ENTRY(nsIDOMLoadListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(XMLHttpRequest)
NS_INTERFACE_MAP_END
/* noscript void addEventListener (in string type, in nsIDOMEventListener listener); */
NS_IMPL_ADDREF(nsXMLHttpRequest)
NS_IMPL_RELEASE(nsXMLHttpRequest)
/* void addEventListener (in string type, in nsIDOMEventListener listener); */
NS_IMETHODIMP
nsXMLHttpRequest::AddEventListener(const char *type,
nsIDOMEventListener *listener)
nsXMLHttpRequest::AddEventListener(const nsAReadableString& type,
nsIDOMEventListener *listener,
PRBool useCapture)
{
NS_ENSURE_ARG(type);
NS_ENSURE_ARG(listener);
nsresult rv;
// I know, I know - strcmp's. But it's only for a couple of
// cases...and they are short strings. :-)
if (nsCRT::strcmp(type, kLoadStr) == 0) {
if (type.Equals(LOADSTR)) {
if (!mLoadEventListeners) {
rv = NS_NewISupportsArray(getter_AddRefs(mLoadEventListeners));
NS_ENSURE_SUCCESS(rv, rv);
}
mLoadEventListeners->AppendElement(listener);
}
else if (nsCRT::strcmp(type, kErrorStr) == 0) {
else if (type.Equals(ERRORSTR)) {
if (!mErrorEventListeners) {
rv = NS_NewISupportsArray(getter_AddRefs(mErrorEventListeners));
NS_ENSURE_SUCCESS(rv, rv);
@ -327,20 +340,20 @@ nsXMLHttpRequest::AddEventListener(const char *type,
return NS_OK;
}
/* noscript void removeEventListener (in string type, in nsIDOMEventListener listener); */
/* void removeEventListener (in string type, in nsIDOMEventListener listener); */
NS_IMETHODIMP
nsXMLHttpRequest::RemoveEventListener(const char *type,
nsIDOMEventListener *listener)
nsXMLHttpRequest::RemoveEventListener(const nsAReadableString & type,
nsIDOMEventListener *listener,
PRBool useCapture)
{
NS_ENSURE_ARG(type);
NS_ENSURE_ARG(listener);
if (nsCRT::strcmp(type, kLoadStr) == 0) {
if (type.Equals(LOADSTR)) {
if (mLoadEventListeners) {
mLoadEventListeners->RemoveElement(listener);
}
}
else if (nsCRT::strcmp(type, kErrorStr) == 0) {
else if (type.Equals(ERRORSTR)) {
if (mErrorEventListeners) {
mErrorEventListeners->RemoveElement(listener);
}
@ -352,6 +365,15 @@ nsXMLHttpRequest::RemoveEventListener(const char *type,
return NS_OK;
}
/* void dispatchEvent (in nsIDOMEvent evt); */
NS_IMETHODIMP
nsXMLHttpRequest::DispatchEvent(nsIDOMEvent *evt)
{
// Ignored
return NS_OK;
}
nsresult
nsXMLHttpRequest::MakeScriptEventListener(nsISupports* aObject,
nsIDOMEventListener** aListener)
@ -489,7 +511,7 @@ nsXMLHttpRequest::SetOnload(nsISupports * aOnLoad)
// we can only have one
if (mLoadEventListeners) {
GetScriptEventListener(mLoadEventListeners, getter_AddRefs(oldListener));
RemoveEventListener(kLoadStr, oldListener);
RemoveEventListener(LOADSTR, oldListener, PR_TRUE);
}
}
else {
@ -501,7 +523,7 @@ nsXMLHttpRequest::SetOnload(nsISupports * aOnLoad)
}
}
return AddEventListener(kLoadStr, listener);
return AddEventListener(LOADSTR, listener, PR_TRUE);
}
/* attribute nsIDOMEventListener onerror; */
@ -542,7 +564,7 @@ nsXMLHttpRequest::SetOnerror(nsISupports * aOnerror)
if (mErrorEventListeners) {
GetScriptEventListener(mErrorEventListeners,
getter_AddRefs(oldListener));
RemoveEventListener(kErrorStr, oldListener);
RemoveEventListener(ERRORSTR, oldListener, PR_TRUE);
}
}
else {
@ -554,7 +576,7 @@ nsXMLHttpRequest::SetOnerror(nsISupports * aOnerror)
}
}
return AddEventListener(kErrorStr, listener);
return AddEventListener(ERRORSTR, listener, PR_TRUE);
}
/* readonly attribute nsIHTTPChannel channel; */
@ -926,9 +948,10 @@ nsXMLHttpRequest::Open(const char *method, const char *url)
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
/*
rv = secMan->CheckScriptAccessToURL(cx, url, NS_DOM_PROP_XMLHTTPREQUEST_OPEN, PR_FALSE);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
*/
nsCOMPtr<nsIPrincipal> principal;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
if (NS_SUCCEEDED(rv)) {

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

@ -30,6 +30,7 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMDocument.h"
#include "nsISecurityCheckedComponent.h"
#include "nsIURI.h"
@ -53,6 +54,7 @@ enum {
class nsXMLHttpRequest : public nsIXMLHttpRequest,
public nsIDOMLoadListener,
public nsIDOMEventTarget,
public nsISecurityCheckedComponent,
public nsIStreamListener,
public nsSupportsWeakReference
@ -66,14 +68,17 @@ public:
// nsIXMLHttpRequest
NS_DECL_NSIXMLHTTPREQUEST
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
virtual nsresult Load(nsIDOMEvent* aEvent);
virtual nsresult Unload(nsIDOMEvent* aEvent);
virtual nsresult Abort(nsIDOMEvent* aEvent);
virtual nsresult Error(nsIDOMEvent* aEvent);
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
// nsISecurityCheckedComponent
NS_DECL_NSISECURITYCHECKEDCOMPONENT
@ -214,7 +219,7 @@ public:
NS_DECL_ISUPPORTS
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIPrivateJSEventListener
NS_IMETHOD GetFunctionObj(JSObject** aObj);