Back to index

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

#include <nsPolicyReference.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsPolicyReference ()
virtual ~nsPolicyReference ()
NS_DECL_NSIPOLICYREFERENCE
NS_DECL_NSIPOLICYTARGET
NS_IMETHOD 
HandleEvent (nsIDOMEvent *aEvent)
void initialize (in nsIURI aMainURI)
 Initialize the object with the document's URI.
void loadPolicyReferenceFileFor (in nsIURI aCurrentURI, in unsigned long aFlag)
 Call this method to locate the policy reference file for the current uri.
void finalize ()
 This method releases all the objects used for policy reference.
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.
void setupPolicyListener (in nsIPolicyListener aListener)
 Setup a listener that is to be notified when the policy location becomes available.

Public Attributes

const unsigned long IS_MAIN_URI = (1<<0)
 Main URI or a URI with the same host as the main URI.
const unsigned long IS_EMBEDDED_URI = (1<<1)
 URI with a domain different from the main URI.
const unsigned long IS_LINKED_URI = (1<<2)
 URI referenced via LINK tag.
const unsigned long POLICY_LOAD_SUCCESS = (1<<3)
 Signals a successful policy load.
const unsigned long POLICY_LOAD_FAILURE = (1<<4)
 Signals a policy load failure.
const unsigned long POLICY_LIFE_EXPIRED = (1<<5)
 Signals obsolete policy.
const unsigned long POLICY_SYNTAX_ERROR = (1<<6)
 Signals a syntax error ( Ex.

Protected Member Functions

nsresult Load (const nsACString &aURI)
nsresult ProcessPolicyReferenceFile (nsIDOMDocument *aDocument, char **aLocation)
nsresult ProcessPolicyRefElement (nsIDOMDocument *aDocument, nsIDOMNodeList *aNodeList, nsAString &aPolicyLocation)
nsresult ProcessPolicyRefChildren (nsIDOMNode *aNode)
nsresult ProcessExpiryElement (nsIDOMNodeList *aNodeList)

Protected Attributes

nsCOMPtr< nsIWeakReferencemListener
nsCOMPtr< nsIXMLHttpRequestmXMLHttpRequest
nsCOMPtr< nsIDOMDocumentmDocument
nsCOMPtr< nsIURImMainURI
nsCOMPtr< nsIURImCurrentURI
nsCOMPtr< nsIURImLinkedURI
PRUint32 mFlags
PRUint32 mError

Detailed Description

Definition at line 53 of file nsPolicyReference.h.


Constructor & Destructor Documentation

Definition at line 83 of file nsPolicyReference.cpp.

{
}

Member Function Documentation

This method releases all the objects used for policy reference.

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

Definition at line 112 of file nsPolicyReference.cpp.

{
  NS_ASSERTION(mXMLHttpRequest, "no xml http request");

  nsresult result = NS_OK;
  nsCOMPtr<nsIPolicyListener> listener(do_QueryReferent(mListener));
  NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);

  if (mXMLHttpRequest) {
    nsCOMPtr<nsIDOMDocument> document;
    if (mFlags & IS_MAIN_URI) {
      if (!mDocument) {
        mXMLHttpRequest->GetResponseXML(getter_AddRefs(mDocument));
        PRBool success;
        result = RequestSucceeded(mXMLHttpRequest, &success);
        if (NS_FAILED(result) || !success) {
          listener->NotifyPolicyLocation(0, POLICY_LOAD_FAILURE);
          return result;
        }
      }
      document = mDocument;
    }
    else {
      mXMLHttpRequest->GetResponseXML(getter_AddRefs(document));
      PRBool success;
      result = RequestSucceeded(mXMLHttpRequest, &success);
      if (NS_FAILED(result) || !success) {
        listener->NotifyPolicyLocation(0, POLICY_LOAD_FAILURE);
        return result;
      }
      if (mFlags & IS_LINKED_URI) {
        mDocument = document;
      }
    }
  
    nsXPIDLCString policyLocation;
    result = ProcessPolicyReferenceFile(document, getter_Copies(policyLocation));
      
    if (NS_SUCCEEDED(result)) {
      listener->NotifyPolicyLocation(policyLocation, mError);
    }
    else {
      listener->NotifyPolicyLocation(0, POLICY_LOAD_FAILURE);
    }
  }

  return result;
}

Here is the call graph for this function:

void nsIPolicyReference::initialize ( in nsIURI  aMainURI) [inherited]

Initialize the object with the document's URI.

Parameters:
aMailURI-> Current document's URI
nsresult nsPolicyReference::Load ( const nsACString &  aURI) [protected]

Definition at line 227 of file nsPolicyReference.cpp.

{
  NS_ASSERTION(aURI.Length(), "no uri to load");

  nsresult result = NS_OK;

  if (!mXMLHttpRequest) {
    mXMLHttpRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &result);
    NS_ENSURE_SUCCESS(result, result); 
    
    nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(mXMLHttpRequest, &result));
    NS_ENSURE_SUCCESS(result, result);

    target->AddEventListener(NS_LITERAL_STRING("load"), this, PR_FALSE);
  }

  const nsAString& empty = EmptyString();
  result = mXMLHttpRequest->OpenRequest(NS_LITERAL_CSTRING("GET"),
                                        aURI, PR_TRUE, empty, empty);
  NS_ENSURE_SUCCESS(result, result);
   
  mXMLHttpRequest->OverrideMimeType(NS_LITERAL_CSTRING("application/xml"));

  return mXMLHttpRequest->Send(nsnull);

}

Here is the call graph for this function:

void nsIPolicyReference::loadPolicyReferenceFileFor ( in nsIURI  aCurrentURI,
in unsigned long  aFlag 
) [inherited]

Call this method to locate the policy reference file for the current uri.

Parameters:
aCurrentURI-> URI that requests a privacy policy aFlag -> IS_SELECTED_URI | IS_EMBEDDED_URI | IS_LINKED_URI

Definition at line 373 of file nsPolicyReference.cpp.

{
  NS_ENSURE_ARG_POINTER(aNodeList);
  
  PRUint32 count;
  aNodeList->GetLength(&count);
  if (count > 0) {
    nsCOMPtr<nsIDOMNode> node;
    aNodeList->Item(0, getter_AddRefs(node)); // There ought to be only one EXPIRY element
    NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
    
    nsAutoString date;
    nsP3PUtils::GetAttributeValue(node, "date", date); // absdate
    if (!date.IsEmpty()) {
      char* cdate = ToNewCString(date);
      NS_ENSURE_TRUE(*cdate, NS_ERROR_OUT_OF_MEMORY);
       
      PRTime prdate;
      if (PR_ParseTimeString(cdate, PR_TRUE, &prdate) == PR_SUCCESS) {
        if (prdate < PR_Now()) {
          mError = POLICY_LIFE_EXPIRED;
        }
      }
      nsMemory::Free(cdate);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 404 of file nsPolicyReference.cpp.

{
  NS_ENSURE_ARG_POINTER(aNode);

  nsresult result = NS_OK;
  // When INCLUDE elements are present in a POLICY-REF element, it means that
  // the policy specified in the about attribute of the POLICY-REF element applies to
  // all the URIs at the requested host corresponding to the local-URI(s) matched by
  // any of the INCLUDES, but not matched by an EXCLUDE. It is legal, but pointles,
  // to supply the EXCLUDE element without any INCLUDE lements; in that case, the
  // EXCLUDE element MUST be ignored.

  nsAutoVoidArray elements;
  nsXPIDLCString path;
  mCurrentURI->GetPath(path);

  nsP3PUtils::GetElementsByTagName(aNode, NS_LITERAL_STRING("INCLUDE"), elements);
  CLEAN_ARRAY_AND_RETURN_IF_FAILED(result, elements);

  if (elements.Count() == 0) {
    mError = POLICY_LOAD_FAILURE;
    return NS_OK; // INCLUDE elements not found so no need to check for EXCLUDE
  }

  PRBool pathIncluded = PR_FALSE;
  result = nsP3PUtils::DeterminePolicyScope(elements, path, &pathIncluded);
  CLEAN_ARRAY_AND_RETURN_IF_FAILED(result, elements);

  mError = pathIncluded ? POLICY_LOAD_SUCCESS : POLICY_LOAD_FAILURE;
  if (mError == POLICY_LOAD_SUCCESS) {
    result = 
      nsP3PUtils::GetElementsByTagName(aNode, NS_LITERAL_STRING("EXCLUDE"), elements);
    CLEAN_ARRAY_AND_RETURN_IF_FAILED(result, elements);

    PRBool pathExcluded = PR_FALSE;
    result = nsP3PUtils::DeterminePolicyScope(elements, path, &pathExcluded);
    mError = pathExcluded ? POLICY_LOAD_FAILURE : POLICY_LOAD_SUCCESS;
  }
  nsP3PUtils::CleanArray(elements);
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsPolicyReference::ProcessPolicyRefElement ( nsIDOMDocument aDocument,
nsIDOMNodeList aNodeList,
nsAString &  aPolicyLocation 
) [protected]

Definition at line 345 of file nsPolicyReference.cpp.

{
  NS_ENSURE_ARG_POINTER(aDocument);
  NS_ENSURE_ARG_POINTER(aNodeList);

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

  nsAutoString element;
  for (PRUint32 i = 0; i < count; i++) {
    nsCOMPtr<nsIDOMNode> node;
    aNodeList->Item(i, getter_AddRefs(node));
    NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
    
    nsresult result = ProcessPolicyRefChildren(node);
    NS_ENSURE_SUCCESS(result, result);

    if (mError == POLICY_LOAD_SUCCESS) {
      return nsP3PUtils::GetAttributeValue(node, "about", aPolicyLocation);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsPolicyReference::ProcessPolicyReferenceFile ( nsIDOMDocument aDocument,
char **  aLocation 
) [protected]

Definition at line 255 of file nsPolicyReference.cpp.

{

  NS_ENSURE_ARG_POINTER(aDocument);
  NS_ENSURE_ARG_POINTER(aPolicyLocation);
    
  nsCOMPtr<nsIDOMElement> domElement;
  aDocument->GetDocumentElement(getter_AddRefs(domElement));

  nsCOMPtr<nsIDOMNode> root(do_QueryInterface(domElement));
  NS_ENSURE_TRUE(root, NS_ERROR_UNEXPECTED);

  nsAutoString name;
  root->GetNodeName(name);

  nsresult result = NS_OK;
  
  // The root element MUST be META
  mError = name.EqualsLiteral("META") 
    ? POLICY_LOAD_SUCCESS : POLICY_SYNTAX_ERROR;
 
  if (mError != POLICY_LOAD_SUCCESS)
    return result;
  
  nsCOMPtr<nsIDOMNodeList> policyReferencesElement;
  aDocument->GetElementsByTagName(NS_LITERAL_STRING("POLICY-REFERENCES"), 
                                  getter_AddRefs(policyReferencesElement));
  NS_ENSURE_TRUE(policyReferencesElement, NS_ERROR_UNEXPECTED);

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

  // There MUST be exactly |one| POLICY-REFERENCES element
  mError = (count == 1) ? POLICY_LOAD_SUCCESS : POLICY_SYNTAX_ERROR;

  if (mError != POLICY_LOAD_SUCCESS)
    return result;

  nsCOMPtr<nsIDOMNodeList> expiryElement;
  aDocument->GetElementsByTagName(NS_LITERAL_STRING("EXPIRY"), 
                                  getter_AddRefs(expiryElement));

  result = ProcessExpiryElement(expiryElement);
  NS_ENSURE_SUCCESS(result, result);

  if (mError != POLICY_LOAD_SUCCESS)
    return result;

  nsCOMPtr<nsIDOMNodeList> policyRefElement;
  aDocument->GetElementsByTagName(NS_LITERAL_STRING("POLICY-REF"), 
                                  getter_AddRefs(policyRefElement));

  nsAutoString policyLocation;
  result = ProcessPolicyRefElement(aDocument, policyRefElement, policyLocation);
  NS_ENSURE_SUCCESS(result, result);
      
  if (mError != POLICY_LOAD_SUCCESS || policyLocation.IsEmpty())
      return result;

  nsAutoString absURI;
  if (mFlags & IS_LINKED_URI) {
    result = NS_MakeAbsoluteURI(absURI, policyLocation,  mLinkedURI);
    NS_ENSURE_SUCCESS(result, result);
  }
  else {
    // Make sure that the fragment identifier belongs to the current host.
    if (policyLocation.First() == '#') {
      policyLocation = PromiseFlatString(NS_LITERAL_STRING("p3p.xml") + policyLocation);
    }
    if (mFlags & IS_MAIN_URI) {
      nsCOMPtr<nsIURI> tmpURI= mMainURI;
      tmpURI->SetPath(NS_LITERAL_CSTRING(kW3C));
      result = NS_MakeAbsoluteURI(absURI, policyLocation,  tmpURI);
      NS_ENSURE_SUCCESS(result, result);
    }
    else {
      // it is ok to do this because we won't be needing current uri beyond this.
      mCurrentURI->SetPath(NS_LITERAL_CSTRING(kW3C));
      result = NS_MakeAbsoluteURI(absURI, policyLocation,  mCurrentURI);
      NS_ENSURE_SUCCESS(result, result);
    }
  }
  *aPolicyLocation = ToNewCString(absURI);
  NS_ENSURE_TRUE(*aPolicyLocation, NS_ERROR_OUT_OF_MEMORY);
 
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Setup a listener that is to be notified when the policy location becomes available.

Parameters:
aListener->

Member Data Documentation

const unsigned long nsIPolicyReference::IS_EMBEDDED_URI = (1<<1) [inherited]

URI with a domain different from the main URI.

Definition at line 51 of file nsIPolicyReference.idl.

const unsigned long nsIPolicyReference::IS_LINKED_URI = (1<<2) [inherited]

URI referenced via LINK tag.

Definition at line 55 of file nsIPolicyReference.idl.

const unsigned long nsIPolicyReference::IS_MAIN_URI = (1<<0) [inherited]

Main URI or a URI with the same host as the main URI.

Definition at line 47 of file nsIPolicyReference.idl.

Definition at line 83 of file nsPolicyReference.h.

Definition at line 81 of file nsPolicyReference.h.

Definition at line 86 of file nsPolicyReference.h.

Definition at line 85 of file nsPolicyReference.h.

Definition at line 84 of file nsPolicyReference.h.

Definition at line 79 of file nsPolicyReference.h.

Definition at line 82 of file nsPolicyReference.h.

Definition at line 80 of file nsPolicyReference.h.

const unsigned long nsIPolicyReference::POLICY_LIFE_EXPIRED = (1<<5) [inherited]

Signals obsolete policy.

Definition at line 67 of file nsIPolicyReference.idl.

const unsigned long nsIPolicyReference::POLICY_LOAD_FAILURE = (1<<4) [inherited]

Signals a policy load failure.

Definition at line 63 of file nsIPolicyReference.idl.

const unsigned long nsIPolicyReference::POLICY_LOAD_SUCCESS = (1<<3) [inherited]

Signals a successful policy load.

Definition at line 59 of file nsIPolicyReference.idl.

const unsigned long nsIPolicyReference::POLICY_SYNTAX_ERROR = (1<<6) [inherited]

Signals a syntax error ( Ex.

xml error ) in the policy.

Definition at line 71 of file nsIPolicyReference.idl.


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