Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
nsWebScriptsAccess Class Reference

#include <nsWebScriptsAccess.h>

Inheritance diagram for nsWebScriptsAccess:
Inheritance graph
[legend]
Collaboration diagram for nsWebScriptsAccess:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsWebScriptsAccess ()
virtual ~nsWebScriptsAccess ()
boolean canAccess (in nsIURI aTransportURI, in AString aType)
 Call this method to check script access...
void invalidateCache (in string aTransportURI)
 This method will invalidate the cached entry for the transport uri.

Protected Member Functions

nsresult GetAccessInfoEntry (const char *aKey, AccessInfoEntry **aEntry)
nsresult GetDocument (const nsACString &aDeclFilePath, nsIDOMDocument **aDocument)
nsresult GetCodebaseURI (nsIURI **aCodebase)
nsresult CreateEntry (const char *aKey, const PRBool aIsDelegated, AccessInfoEntry **aEntry)
nsresult CreateEntry (nsIDOMDocument *aDocument, const PRBool aIsDelegated, AccessInfoEntry **aAccessInfoEntry)
nsresult CreateEntry (nsIDOMNodeList *aAllowList, AccessInfoEntry **aAccessInfoEntry)
nsresult CreateEntry (const PRInt32 aFlags, AccessInfoEntry **aAccessInfoEntry)
nsresult CreateDelegatedEntry (AccessInfoEntry **aAccessInfoEntry)
nsresult CheckAccess (AccessInfoEntry *aAccessInfoEntry, const nsAString &aRequestType, PRBool *aAccessGranted)
nsresult ValidateDocument (nsIDOMDocument *aDocument, PRBool *aIsValid)
 Validation is based on the following syntax:
nsresult IsPublicService (const char *aHost, PRBool *aReturn)

Protected Attributes

nsCOMPtr< nsIURImServiceURI
nsCOMPtr< nsIXMLHttpRequestmRequest
nsCOMPtr
< nsIScriptSecurityManager
mSecurityManager
nsStringArray mMasterServices
nsHashtable mAccessInfoTable
const nsLiteralString kNamespace2002
const nsLiteralString kWebScriptAccessTag
const nsLiteralString kDelegateTag
const nsLiteralString kAllowTag
const nsLiteralString kTypeAttr
const nsLiteralString kFromAttr
const nsLiteralString kAny
const nsLiteralString kIsServicePublic

Detailed Description

Definition at line 90 of file nsWebScriptsAccess.h.


Constructor & Destructor Documentation

Definition at line 94 of file nsWebScriptsAccess.cpp.

{
  mAccessInfoTable.Enumerate(FreeEntries, this);
}

Here is the call graph for this function:


Member Function Documentation

boolean nsIWebScriptsAccessService::canAccess ( in nsIURI  aTransportURI,
in AString  aType 
) [inherited]

Call this method to check script access...

aTransportURI - The web service URI. aType - Type requested by the script. return TRUE if access granted else FALSE

nsresult nsWebScriptsAccess::CheckAccess ( AccessInfoEntry aAccessInfoEntry,
const nsAString &  aRequestType,
PRBool aAccessGranted 
) [protected]

Definition at line 432 of file nsWebScriptsAccess.cpp.

{
#ifdef DEBUG
  static PRBool verified = PR_FALSE;
  if (!verified) {
    verified = PR_TRUE;
    nsWSAUtils::VerifyIsEqual();
  }
#endif

  *aAccessGranted = PR_FALSE;
  NS_ENSURE_ARG_POINTER(aEntry);

  nsresult rv = NS_OK;
  if (aEntry->mFlags & WSA_FILE_NOT_FOUND) {
    if (aEntry->mFlags & HAS_MASTER_SERVICE_DECISION) {
      if (aEntry->mFlags & SERVICE_LISTED_PUBLIC)
         *aAccessGranted = PR_TRUE;
      return rv;
    }
    nsCAutoString fqdn;
    rv = nsWSAUtils::GetOfficialHostName(mServiceURI, fqdn);
    if (NS_FAILED(rv) || fqdn.IsEmpty())
      return rv;
    
    PRBool isPublic = PR_FALSE;
    rv = IsPublicService(fqdn.get(), &isPublic);
    if (NS_SUCCEEDED(rv)) {
      if (isPublic) {
        aEntry->mFlags |= SERVICE_LISTED_PUBLIC;
        *aAccessGranted = PR_TRUE;
      }
      aEntry->mFlags |= HAS_MASTER_SERVICE_DECISION; 
    }
    return rv;
  }
 
  if (aEntry->mFlags & WSA_GRANT_ACCESS_TO_ALL) {
    *aAccessGranted = PR_TRUE;
    return NS_OK;
  }

  nsCOMPtr<nsIURI> codebase_uri;
  rv = GetCodebaseURI(getter_AddRefs(codebase_uri));
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLCString tmp;
  codebase_uri->GetSpec(tmp);
  const nsAString& codebase = NS_ConvertUTF8toUCS2(tmp);

  PRUint32 count = aEntry->mInfoArray.Count();
  PRUint32 index;
  for (index = 0; index < count; index++) {
    AccessInfo* access_info = 
      NS_REINTERPRET_CAST(AccessInfo*, aEntry->mInfoArray.ElementAt(index));
    NS_ASSERTION(access_info, "Entry is missing attribute information");
    
    if (!access_info->mType || kAny.Equals(access_info->mType) || 
        aRequestType.Equals(access_info->mType)) {
      if (!access_info->mFrom) {
        // If "from" is not specified, then all scripts will be  allowed 
        *aAccessGranted = PR_TRUE;
        break;
      }
      else {
        if (nsWSAUtils::IsEqual(nsDependentString(access_info->mFrom), 
                                codebase)) {
          *aAccessGranted = PR_TRUE;
          break;
        }
      }
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 413 of file nsWebScriptsAccess.cpp.

{
  NS_ENSURE_ARG_POINTER(aEntry);
  *aEntry = nsnull;
  
  nsresult rv;
  nsCOMPtr<nsIURL> url(do_QueryInterface(mServiceURI, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCAutoString path;
  url->GetPrePath(path);
  nsCAutoString directory;
  url->GetDirectory(directory);
  path += directory;

  return CreateEntry(path.get(), PR_TRUE, aEntry);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebScriptsAccess::CreateEntry ( const char *  aKey,
const PRBool  aIsDelegated,
AccessInfoEntry **  aEntry 
) [protected]

Definition at line 258 of file nsWebScriptsAccess.cpp.

{
  NS_ENSURE_ARG_POINTER(aEntry);
  *aEntry = nsnull;
  // create an entry by loading the declaration file (
  // web-scripts-access.xml ) and extracting access information from
  // it. Record the extracted info. for this session
  nsCOMPtr<nsIDOMDocument> document;
  nsresult rv = 
    GetDocument(nsDependentCString(aKey) +
                NS_LITERAL_CSTRING("web-scripts-access.xml"),
                getter_AddRefs(document));
  NS_ENSURE_SUCCESS(rv, rv);
  if (document) {
    // Create an entry by extracting access information from the document.
    rv = CreateEntry(document, aIsDelegated, aEntry);
    NS_ENSURE_SUCCESS(rv, rv);

    // If the document is invalid then an entry will not be created.
    if (!*aEntry)
      return NS_OK;
  }
  else {
    rv = CreateEntry(WSA_FILE_NOT_FOUND, aEntry);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  nsCStringKey key(aKey);
  mAccessInfoTable.Put(&key, *aEntry);

  NS_ASSERTION(*aEntry, "unexpected: access info entry is null!");
  if (*aEntry  && ((*aEntry)->mFlags & WSA_FILE_DELEGATED))
    rv = CreateDelegatedEntry(aEntry);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebScriptsAccess::CreateEntry ( nsIDOMDocument aDocument,
const PRBool  aIsDelegated,
AccessInfoEntry **  aAccessInfoEntry 
) [protected]

Definition at line 296 of file nsWebScriptsAccess.cpp.

{
  NS_ENSURE_ARG_POINTER(aDocument);
  NS_ENSURE_ARG_POINTER(aEntry);
  *aEntry = nsnull;
  
  PRBool valid;
  nsresult rv = ValidateDocument(aDocument, &valid);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!valid) {
    return NS_OK; // XXX should I return an error instead ?
  }

  if (!aIsDelegated) {
    nsCOMPtr<nsIDOMNodeList> delegateList; 
    rv = aDocument->GetElementsByTagNameNS(kNamespace2002, kDelegateTag, 
                                           getter_AddRefs(delegateList));
    NS_ENSURE_TRUE(delegateList, rv);
    nsCOMPtr<nsIDOMNode> node;
    delegateList->Item(0, getter_AddRefs(node));
    if (node)
      return CreateEntry(WSA_FILE_DELEGATED, aEntry);
  }

  nsCOMPtr<nsIDOMNodeList> allowList;
  rv = aDocument->GetElementsByTagNameNS(kNamespace2002, kAllowTag, 
                                         getter_AddRefs(allowList));
  NS_ENSURE_TRUE(allowList, rv);

  PRUint32 count;
  allowList->GetLength(&count);
  if (count) {
    rv = CreateEntry(allowList, aEntry);
  }
  else {
    // Since there are no ALLOW elements present grant access to all.
    rv = CreateEntry(WSA_GRANT_ACCESS_TO_ALL, aEntry);
  }

  return rv;
}

Here is the call graph for this function:

nsresult nsWebScriptsAccess::CreateEntry ( nsIDOMNodeList aAllowList,
AccessInfoEntry **  aAccessInfoEntry 
) [protected]

Definition at line 352 of file nsWebScriptsAccess.cpp.

{
  NS_ENSURE_ARG_POINTER(aAllowList);
  NS_ENSURE_ARG_POINTER(aEntry);
  *aEntry = nsnull;

  nsAutoPtr<AccessInfoEntry> entry(new AccessInfoEntry());
  NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);

  PRUint32 count;
  aAllowList->GetLength(&count);

  PRUint32 index; 
  nsCOMPtr<nsIDOMNode> node;
  nsAutoString type, from;
  for (index = 0; index < count; index++) {
    aAllowList->Item(index, getter_AddRefs(node));
    NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
     
    nsCOMPtr<nsIDOMElement> element(do_QueryInterface(node));
    element->GetAttribute(kTypeAttr, type);
    element->GetAttribute(kFromAttr, from);

    PRBool found_type = !type.IsEmpty();
    PRBool found_from = !from.IsEmpty();

    if (!found_type && !found_from) {
      // Minor optimization - If the "type" and "from"
      // attributes aren't present then no need to check
      // for attributes in other "allow" elements because
      // access will be granted to all regardless.
      entry->mFlags |= WSA_GRANT_ACCESS_TO_ALL;
      break;
    }

    nsAutoPtr<AccessInfo> access_info(new AccessInfo());
    NS_ENSURE_TRUE(access_info, NS_ERROR_OUT_OF_MEMORY);
    
    if (found_type) {
      access_info->mType = ToNewUnicode(type);
      NS_ENSURE_TRUE(access_info->mType, NS_ERROR_OUT_OF_MEMORY);
    }

    if (found_from) {
      access_info->mFrom = ToNewUnicode(from);
      NS_ENSURE_TRUE(access_info->mFrom, NS_ERROR_OUT_OF_MEMORY);
    }

    entry->mInfoArray.AppendElement(access_info.forget());
    
    type.Truncate();
    from.Truncate();
  }

  *aEntry = entry.forget();

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsWebScriptsAccess::CreateEntry ( const PRInt32  aFlags,
AccessInfoEntry **  aAccessInfoEntry 
) [protected]

Definition at line 342 of file nsWebScriptsAccess.cpp.

{
  *aEntry = new AccessInfoEntry(aFlags);
  NS_ENSURE_TRUE(*aEntry, NS_ERROR_OUT_OF_MEMORY);

  return NS_OK;
}
nsresult nsWebScriptsAccess::GetAccessInfoEntry ( const char *  aKey,
AccessInfoEntry **  aEntry 
) [protected]

Definition at line 179 of file nsWebScriptsAccess.cpp.

{
  nsCStringKey key(aKey);

  *aEntry = NS_REINTERPRET_CAST(AccessInfoEntry*, mAccessInfoTable.Get(&key));
  if (*aEntry  && ((*aEntry)->mFlags & WSA_FILE_DELEGATED)) {
    nsresult rv;
    nsCOMPtr<nsIURL> url(do_QueryInterface(mServiceURI, &rv));
    NS_ENSURE_SUCCESS(rv, rv);
  
    nsCAutoString path;
    url->GetPrePath(path);
    nsCAutoString directory;
    url->GetDirectory(directory);
    path += directory;

    return GetAccessInfoEntry(path.get(), aEntry);
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsWebScriptsAccess::GetCodebaseURI ( nsIURI **  aCodebase) [protected]

Definition at line 240 of file nsWebScriptsAccess.cpp.

{
  nsresult rv = NS_OK;
 
  if (!mSecurityManager) {
    mSecurityManager = 
      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsCOMPtr<nsIPrincipal> principal;
  rv = mSecurityManager->GetSubjectPrincipal(getter_AddRefs(principal));
  NS_ENSURE_SUCCESS(rv, rv);
  
  return principal->GetURI(aCodebase);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebScriptsAccess::GetDocument ( const nsACString &  aDeclFilePath,
nsIDOMDocument **  aDocument 
) [protected]

Definition at line 202 of file nsWebScriptsAccess.cpp.

{
  nsresult rv = NS_OK;
  
  if (!mRequest) {
    mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  const nsAString& empty = EmptyString();
  rv = mRequest->OpenRequest(NS_LITERAL_CSTRING("GET"), aDeclFilePath,
                             PR_FALSE, empty, empty);
  NS_ENSURE_SUCCESS(rv, rv);
    
  rv = mRequest->OverrideMimeType(NS_LITERAL_CSTRING("application/xml"));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mRequest->Send(0);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIChannel> channel;
  mRequest->GetChannel(getter_AddRefs(channel));
  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel, &rv));
  NS_ENSURE_TRUE(httpChannel, rv);

  PRBool succeeded;
  httpChannel->GetRequestSucceeded(&succeeded);
 
  if (succeeded) {
    rv = mRequest->GetResponseXML(aDocument);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

This method will invalidate the cached entry for the transport uri.

Also one can clear the entire cache by passing in a null string.

nsresult nsWebScriptsAccess::IsPublicService ( const char *  aHost,
PRBool aReturn 
) [protected]

Definition at line 661 of file nsWebScriptsAccess.cpp.

{
  *aReturn = PR_FALSE;
  nsresult rv = NS_OK;
  // Cache the master services included in the prefs.
  if (mMasterServices.Count() == 0) {
    nsCOMPtr<nsIPrefBranch> prefBranch = 
      do_GetService(NS_PREFSERVICE_CONTRACTID);
  
    if (!prefBranch)
      return rv;

    nsXPIDLCString value;
    rv = prefBranch->GetCharPref("xml.webservice.security.masterservices",
                                 getter_Copies(value));
    
    if (NS_FAILED(rv) || value.IsEmpty())
      return NS_OK;
      
    nsACString::const_iterator begin, end, curr;
    nsACString::const_iterator uri_begin, uri_end;
    value.BeginReading(begin);
    value.EndReading(end);
    
    // Parse the comma separated pref. value
    static const char* kWhitespace = " \n\r\t\b";
    while (begin != end) {
      curr = begin;
      // strip leading whitespaces
      while (IsCharInSet(kWhitespace, *curr) && ++curr != end);
      uri_begin = curr;
      // consume until the delimiter ( comma ).
      while (curr != end && *curr != ',')
        ++curr;
      uri_end = curr;
      // strip trailing whitespaces
      while (uri_end != uri_begin) {
        if (!IsCharInSet(kWhitespace, *(--uri_end))) {
          ++uri_end; // include the last non whitespace char.
          break;
        }
      }
      const nsAFlatString& transportURI =
        NS_ConvertUTF8toUCS2(Substring(uri_begin, uri_end));
      if (!transportURI.IsEmpty())
        mMasterServices.AppendString(transportURI);
      begin = (*curr == ',' && curr != end) ? ++curr : curr;
    }
  }

  // Do nothing if the pref value turns out to be 
  // strings with nothing but whitespaces.
  if (mMasterServices.Count() == 0)
    return rv;

  // Allocate param block.
  nsISOAPParameter** bodyBlocks = 
    NS_STATIC_CAST(nsISOAPParameter**,
                  nsMemory::Alloc(1 * sizeof(nsISOAPParameter*)));
  if (!bodyBlocks)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = 
    CallCreateInstance(NS_SOAPPARAMETER_CONTRACTID, &bodyBlocks[0]);
  
  if (NS_FAILED(rv)) {
    NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(0, bodyBlocks);
    return rv;
  }

  nsCOMPtr<nsISOAPBlock> block = do_QueryInterface(bodyBlocks[0], &rv);

  if (NS_FAILED(rv))
    return rv;

  block->SetName(NS_LITERAL_STRING("fqdn"));

  nsCOMPtr<nsIWritableVariant> variant =
    do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);

  if (NS_FAILED(rv))
    return rv;

  variant->SetAsString(aHost);

  block->SetValue(variant);

    // Create the call instance
  nsCOMPtr<nsISOAPCall> call = 
    do_CreateInstance(NS_SOAPCALL_CONTRACTID, &rv);
  
  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsISOAPEncoding> encoding =
    do_CreateInstance(NS_SOAPENCODING_CONTRACTID, &rv);
  
  if (NS_FAILED(rv))
    return rv;

  call->SetEncoding(encoding);
  
  // Since the SOAP request to the central server will be made
  // from the native code we can safely override cross-domain 
  // checks by pushing in a null jscontext on the context stack.
  nsCOMPtr<nsIJSContextStack> stack = 
    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
  if (stack)
    stack->Push(nsnull);

  nsCOMPtr<nsISOAPResponse> response;
  PRInt32 i, count = mMasterServices.Count();
  for (i = 0; i < count && !response; i++) {
    rv = 
      call->SetTransportURI(*mMasterServices.StringAt(i));
    
    if (NS_FAILED(rv))
      break;
    
    rv = call->Encode(nsISOAPMessage::VERSION_1_1,
                      kIsServicePublic, 
                      kNamespace2002, // The target URI
                      0, 0, 1, bodyBlocks);
    if (NS_FAILED(rv))
      break;
  
    call->Invoke(getter_AddRefs(response)); // XXX - How to handle time out and 404?
  }
  
  if (stack) {
    JSContext* cx;
    stack->Pop(&cx);
    NS_ASSERTION(!cx, "context should be null");
  }

  if (!response)
    return rv;
  
  nsCOMPtr<nsISOAPFault> fault;
  response->GetFault(getter_AddRefs(fault));
    
  if (fault) {
    nsAutoString faultNamespaceURI, faultCode, faultString;
    fault->GetFaultNamespaceURI(faultNamespaceURI);
    fault->GetFaultCode(faultCode);
    fault->GetFaultString(faultString);
    const PRUnichar *inputs[5]  = 
      { 
        kNamespace2002.get(),
        kIsServicePublic.get(),
        faultNamespaceURI.get(),
        faultCode.get(),
        faultString.get()
      };
    return nsWSAUtils::ReportError(
                        NS_LITERAL_STRING("SOAPFault").get(), 
                        inputs, 5);
  }
  else {
    PRUint32 bodyCount;
    rv = response->GetParameters(PR_FALSE, &bodyCount, &bodyBlocks);
    NS_ASSERTION(bodyBlocks, "insufficient information");

    if (!bodyBlocks || NS_FAILED(rv))
      return rv;
    
    NS_ASSERTION(bodyCount == 1, "body seems to contain unnecessary information.");
    block = do_QueryInterface(bodyBlocks[0], &rv);
    
    if (NS_FAILED(rv))
      return rv;
    
    nsCOMPtr<nsIVariant> value;
    rv = block->GetValue(getter_AddRefs(value));
    
    if (NS_FAILED(rv) || !value)
      return rv;
    
    rv = value->GetAsBool(aReturn);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsWebScriptsAccess::ValidateDocument ( nsIDOMDocument aDocument,
PRBool aIsValid 
) [protected]

Validation is based on the following syntax:

<!ELEMENT webScriptAccess (delegate?|allow*)> <!ELEMENT delegate EMPTY> <!ELEMENT allow EMPTY> <!ATTLIST allow type|from CDATA #IMPLIED>.

Definition at line 521 of file nsWebScriptsAccess.cpp.

{
  NS_ENSURE_ARG_POINTER(aDocument);

  *aIsValid = PR_FALSE;
  nsCOMPtr<nsIDOMElement> rootElement;
  aDocument->GetDocumentElement(getter_AddRefs(rootElement));
  
  nsAutoString ns;
  nsAutoString name;
  nsresult rv = rootElement->GetNamespaceURI(ns);
  if (NS_FAILED(rv))
    return rv;
  rootElement->GetLocalName(name);
  if (NS_FAILED(rv))
    return rv;
  
  if (!ns.Equals(kNamespace2002)) {
    const PRUnichar *inputs[1]  = { ns.get() };
    return nsWSAUtils::ReportError(
                         NS_LITERAL_STRING("UnsupportedNamespace").get(), 
                         inputs, 1);
  }
  if (!name.Equals(kWebScriptAccessTag)) {
    const PRUnichar *inputs[1]  = { name.get() };
    return nsWSAUtils::ReportError(
                         NS_LITERAL_STRING("UnknownRootElement").get(), 
                         inputs, 1);
  }

  nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));
  NS_ENSURE_TRUE(rootNode, NS_ERROR_UNEXPECTED);

  nsCOMPtr<nsIDOMNodeList> children;
  rootNode->GetChildNodes(getter_AddRefs(children));
  NS_ENSURE_TRUE(children, NS_ERROR_UNEXPECTED);

  PRUint32 length;
  children->GetLength(&length);

  PRBool hadDelegate = PR_FALSE;
  nsCOMPtr<nsIDOMNode> child, attr;
  nsCOMPtr<nsIDOMNamedNodeMap> attrs;
  PRUint32 i;
  for (i = 0; i < length; i++) {
    children->Item(i, getter_AddRefs(child));
    NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
  
    PRUint16 type;
    child->GetNodeType(&type);

    if (nsIDOMNode::ELEMENT_NODE == type) {
      rv = child->GetNamespaceURI(ns);
      if (NS_FAILED(rv))
        return rv;
      rv = child->GetLocalName(name);
      if (NS_FAILED(rv))
        return rv;
 
      if (!ns.Equals(kNamespace2002))
        continue; // ignore elements with different ns.

      PRBool hasChildNodes = PR_FALSE;
      if (name.Equals(kDelegateTag)) {
        // There can me no more than one delegate element.
        if (hadDelegate) {
          const PRUnichar *inputs[1] = { name.get() };
          return nsWSAUtils::ReportError(
                               NS_LITERAL_STRING("TooManyElements").get(), 
                               inputs, 1);
        }
        // Make sure that the delegate element is EMPTY.
        child->HasChildNodes(&hasChildNodes);
        if (hasChildNodes) {
          const PRUnichar *inputs[1] = { name.get() };
          return nsWSAUtils::ReportError(
                               NS_LITERAL_STRING("ElementNotEmpty").get(), 
                               inputs, 1);
        }
        hadDelegate = PR_TRUE;
      }
      else if (name.Equals(kAllowTag)) {
        // Make sure that the allow element is EMPTY.
        child->HasChildNodes(&hasChildNodes);
        if (hasChildNodes) {
          const PRUnichar *inputs[1] = { name.get() };
          return nsWSAUtils::ReportError(
                               NS_LITERAL_STRING("ElementNotEmpty").get(), 
                               inputs, 1);
        }
        rv = child->GetAttributes(getter_AddRefs(attrs));
        if (NS_FAILED(rv))
          return rv;
        
        PRUint32 count, i;
        attrs->GetLength(&count);
        for (i = 0; i < count; i++) {
          attrs->Item(i, getter_AddRefs(attr));
          if (attr) {
            rv = attr->GetLocalName(name);
            if (NS_FAILED(rv))
              return rv;
            if (!name.Equals(kTypeAttr) && !name.Equals(kFromAttr)) {
              const PRUnichar *inputs[1] = { name.get() };
              return nsWSAUtils::ReportError(
                                   NS_LITERAL_STRING("UnknownAttribute").get(), 
                                   inputs, 1);
            }
          }
        }
      }
      else {
        const PRUnichar *inputs[1] = { name.get() };
        return nsWSAUtils::ReportError(
                             NS_LITERAL_STRING("UnknownElement").get(), 
                             inputs, 1);
      }

    }
  }
  *aIsValid = PR_TRUE;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 128 of file nsWebScriptsAccess.h.

Definition at line 133 of file nsWebScriptsAccess.h.

Definition at line 127 of file nsWebScriptsAccess.h.

Definition at line 131 of file nsWebScriptsAccess.h.

Definition at line 135 of file nsWebScriptsAccess.h.

Definition at line 124 of file nsWebScriptsAccess.h.

Definition at line 130 of file nsWebScriptsAccess.h.

Definition at line 126 of file nsWebScriptsAccess.h.

nsHashtable nsWebScriptsAccess::mAccessInfoTable [protected]

Definition at line 122 of file nsWebScriptsAccess.h.

nsStringArray nsWebScriptsAccess::mMasterServices [protected]

Definition at line 121 of file nsWebScriptsAccess.h.

Definition at line 119 of file nsWebScriptsAccess.h.

Definition at line 120 of file nsWebScriptsAccess.h.

Definition at line 118 of file nsWebScriptsAccess.h.


The documentation for this class was generated from the following files: