Rename GetNodePrincipal to NodePrincipal. Bug 327246, r+sr=sicking

This commit is contained in:
bzbarsky%mit.edu 2006-04-27 18:21:11 +00:00
Родитель 1a39e02ebd
Коммит 533eb3c678
42 изменённых файлов: 168 добавлений и 1432 удалений

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

@ -57,10 +57,10 @@ class nsIEventListenerManager;
class nsIPrincipal;
// IID for the nsINode interface
// ec67d9d2-be1e-41d8-b7d0-92f72a2667db
// f96eef82-43fc-4eee-9784-4259415e98a9
#define NS_INODE_IID \
{ 0x2ad78957, 0x52e8, 0x493a, \
{ 0x8b, 0x5a, 0xe6, 0x91, 0xdc, 0xe3, 0x36, 0xe7 } }
{ 0xf96eef82, 0x43fc, 0x4eee, \
{ 0x97, 0x84, 0x42, 0x59, 0x41, 0x5e, 0x98, 0xa9 } }
// hack to make egcs / gcc 2.95.2 happy
class nsINode_base : public nsIDOMGCParticipant {
@ -238,12 +238,11 @@ public:
nsresult *aStatus = nsnull);
/**
* Return the principal of this node. This may return null; in that case the
* caller should assume that all same-origin checks against this node fail
* and that this node has no permissions to do anything.
* Return the principal of this node. This is guaranteed to never be a null
* pointer.
*/
nsIPrincipal* GetNodePrincipal() const {
return mNodeInfo->NodeInfoManager()->GetDocumentPrincipal();
nsIPrincipal* NodePrincipal() const {
return mNodeInfo->NodeInfoManager()->DocumentPrincipal();
}
/**

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

@ -68,10 +68,10 @@ class nsIURI;
class nsIPrincipal;
// IID for the nsINodeInfo interface
// 37840f19-f65f-4185-baff-c475d9e2b3f2
// 35e53115-b884-4cfc-aa95-bdf0aa5152cf
#define NS_INODEINFO_IID \
{ 0x37840f19, 0xf65f, 0x4185, \
{ 0xba, 0xff, 0xc4, 0x75, 0xd9, 0xe2, 0xb3, 0xf2 } }
{ 0x35e53115, 0xb884, 0x4cfc, \
{ 0xaa, 0x95, 0xbd, 0xf0, 0xaa, 0x51, 0x52, 0xcf } }
class nsINodeInfo : public nsISupports
{
@ -286,11 +286,6 @@ public:
return mOwnerManager->GetDocument();
}
/*
* Retrieve a pointer to the principal for the document of this node info.
*/
virtual nsIPrincipal *GetDocumentPrincipal() const = 0;
protected:
virtual PRBool
QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const = 0;

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

@ -560,29 +560,28 @@ nsContentAreaDragDrop::DragDrop(nsIDOMEvent* inMouseEvent)
if (url.IsEmpty() || url.FindChar(' ') >= 0)
return NS_OK;
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), url);
if (!uri) {
// Not actually a URI
return NS_OK;
}
nsCOMPtr<nsIDOMDocument> sourceDocument;
session->GetSourceDocument(getter_AddRefs(sourceDocument));
nsCOMPtr<nsIDocument> sourceDoc(do_QueryInterface(sourceDocument));
if (sourceDoc && sourceDoc->GetNodePrincipal()) {
nsCOMPtr<nsIURI> sourceUri;
sourceDoc->GetNodePrincipal()->GetURI(getter_AddRefs(sourceUri));
if (sourceDoc) {
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIWithPrincipal(sourceDoc->NodePrincipal(), uri,
nsIScriptSecurityManager::STANDARD);
if (sourceUri) {
nsCAutoString sourceUriStr;
sourceUri->GetSpec(sourceUriStr);
if (NS_FAILED(rv)) {
// Security check failed, stop event propagation right here
// and return the error.
inMouseEvent->StopPropagation();
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIStr(sourceUriStr, NS_ConvertUTF16toUTF8(url),
nsIScriptSecurityManager::STANDARD);
if (NS_FAILED(rv)) {
// Security check failed, stop even propagation right here
// and return the error.
inMouseEvent->StopPropagation();
return rv;
}
return rv;
}
}

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

@ -332,15 +332,10 @@ nsContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
// We use the original codebase in case the codebase was changed
// by SetDomain
nsIPrincipal *docPrincipal = mDocument->GetNodePrincipal();
if (!docPrincipal) {
return NS_ERROR_FAILURE;
}
// Note that a non-codebase principal (eg the system principal) will return
// a null URI.
nsCOMPtr<nsIURI> codebaseURI;
rv = docPrincipal->GetURI(getter_AddRefs(codebaseURI));
rv = mDocument->NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
NS_ENSURE_TRUE(codebaseURI, rv);
nsCOMPtr<nsIPrompt> prompt;

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

@ -705,11 +705,8 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
// Make sure these are both real nodes
NS_ENSURE_TRUE(trustedNode && unTrustedNode, NS_ERROR_UNEXPECTED);
nsIPrincipal* trustedPrincipal = trustedNode->GetNodePrincipal();
nsIPrincipal* unTrustedPrincipal = unTrustedNode->GetNodePrincipal();
// Make sure we have both principals
NS_ENSURE_TRUE(trustedPrincipal && unTrustedPrincipal, NS_ERROR_UNEXPECTED);
nsIPrincipal* trustedPrincipal = trustedNode->NodePrincipal();
nsIPrincipal* unTrustedPrincipal = unTrustedNode->NodePrincipal();
if (trustedPrincipal == unTrustedPrincipal) {
return NS_OK;
@ -747,15 +744,8 @@ nsContentUtils::CanCallerAccess(nsIDOMNode *aNode)
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node, PR_FALSE);
nsIPrincipal* principal = node->GetNodePrincipal();
if (!principal) {
// We can't get hold of the principal for this node. No access allowed.
return PR_FALSE;
}
nsresult rv = sSecurityManager->CheckSameOriginPrincipal(subjectPrincipal,
principal);
nsresult rv = sSecurityManager->
CheckSameOriginPrincipal(subjectPrincipal, node->NodePrincipal());
if (NS_SUCCEEDED(rv)) {
return PR_TRUE;
}
@ -2004,7 +1994,7 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
// Editor apps get special treatment here, editors can load images
// from anywhere.
rv = sSecurityManager->
CheckLoadURIWithPrincipal(aLoadingDocument->GetNodePrincipal(), aURI,
CheckLoadURIWithPrincipal(aLoadingDocument->NodePrincipal(), aURI,
nsIScriptSecurityManager::ALLOW_CHROME);
if (NS_FAILED(rv)) {
if (aImageBlockingStatus) {
@ -2532,15 +2522,14 @@ nsContentUtils::GetFormControlElements(nsIDocument *aDocument)
PRBool
nsContentUtils::IsChromeDoc(nsIDocument *aDocument)
{
nsIPrincipal *principal;
if (!aDocument || !(principal = aDocument->GetNodePrincipal())) {
if (!aDocument) {
return PR_FALSE;
}
nsCOMPtr<nsIPrincipal> systemPrincipal;
sSecurityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
return principal == systemPrincipal;
return aDocument->NodePrincipal() == systemPrincipal;
}
void

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

@ -142,37 +142,32 @@ CheckSameOrigin(nsIDOMNode *aRoot)
return NS_ERROR_INVALID_POINTER;
}
nsIPrincipal *principal = node->GetNodePrincipal();
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (principal) {
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRBool ubrEnabled = PR_FALSE;
rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &ubrEnabled);
NS_ENSURE_SUCCESS(rv, rv);
PRBool ubrEnabled = PR_FALSE;
rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &ubrEnabled);
NS_ENSURE_SUCCESS(rv, rv);
if (ubrEnabled) {
// UniversalBrowserRead is enabled (or we're not called from
// script), permit access.
return NS_OK;
}
if (ubrEnabled) {
// UniversalBrowserRead is enabled (or we're not called from
// script), permit access.
return NS_OK;
}
nsCOMPtr<nsIPrincipal> subject;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrincipal> subject;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
// XXXbz can we happen to not have a subject principal here?
// nsScriptSecurityManager::IsCapabilityEnabled doesn't actually use
// GetSubjectPrincipal, so not sure...
// In any case, no subject principal means access is allowed.
if (subject) {
// Check if the caller is from the same origin that the root is from.
return secMan->CheckSameOriginPrincipal(subject, principal);
}
// XXXbz can we happen to not have a subject principal here?
// nsScriptSecurityManager::IsCapabilityEnabled doesn't actually use
// GetSubjectPrincipal, so not sure...
// In any case, no subject principal means access is allowed.
if (subject) {
// Check if the caller is from the same origin that the root is from.
return secMan->CheckSameOriginPrincipal(subject, node->NodePrincipal());
}
return NS_OK;

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

@ -1246,7 +1246,7 @@ nsDocument::GetLastModified(nsAString& aLastModified)
nsIPrincipal*
nsDocument::GetPrincipal()
{
return GetNodePrincipal();
return NodePrincipal();
}
void
@ -1286,13 +1286,8 @@ nsDocument::SetBaseURI(nsIURI* aURI)
nsresult rv = NS_OK;
if (aURI) {
nsIPrincipal* principal = GetNodePrincipal();
NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE);
nsIScriptSecurityManager* securityManager =
nsContentUtils::GetSecurityManager();
rv = securityManager->
CheckLoadURIWithPrincipal(principal, aURI,
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIWithPrincipal(NodePrincipal(), aURI,
nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mDocumentBaseURI = aURI;
@ -2498,7 +2493,7 @@ nsDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation)
NS_NewURI(getter_AddRefs(uri), "about:blank");
NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY);
*aImplementation = new nsDOMImplementation(uri, uri, GetNodePrincipal());
*aImplementation = new nsDOMImplementation(uri, uri, NodePrincipal());
if (!*aImplementation) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -4462,9 +4457,6 @@ nsDocument::IsScriptEnabled()
nsCOMPtr<nsIScriptSecurityManager> sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
NS_ENSURE_TRUE(sm, PR_TRUE);
nsIPrincipal* principal = GetNodePrincipal();
NS_ENSURE_TRUE(principal, PR_TRUE);
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, PR_TRUE);
@ -4475,7 +4467,7 @@ nsDocument::IsScriptEnabled()
NS_ENSURE_TRUE(cx, PR_TRUE);
PRBool enabled;
nsresult rv = sm->CanExecuteScripts(cx, principal, &enabled);
nsresult rv = sm->CanExecuteScripts(cx, NodePrincipal(), &enabled);
NS_ENSURE_SUCCESS(rv, PR_TRUE);
return enabled;
}

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

@ -164,14 +164,10 @@ nsFrameLoader::LoadURI(nsIURI* aURI)
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
// Get our principal
nsIPrincipal* principal = mOwnerContent->GetNodePrincipal();
NS_ASSERTION(principal == doc->GetNodePrincipal(),
nsIPrincipal* principal = mOwnerContent->NodePrincipal();
NS_ASSERTION(principal == doc->NodePrincipal(),
"Principal mismatch. Should not happen");
if (!principal) {
return NS_ERROR_FAILURE;
}
// Check if we are allowed to load absURL
rv = secMan->CheckLoadURIWithPrincipal(principal, aURI,
nsIScriptSecurityManager::STANDARD);

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

@ -2115,7 +2115,7 @@ nsGenericElement::GetBaseURI() const
if (NS_SUCCEEDED(rv)) {
// do a security check, almost the same as nsDocument::SetBaseURL()
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIWithPrincipal(GetNodePrincipal(), ourBase,
CheckLoadURIWithPrincipal(NodePrincipal(), ourBase,
nsIScriptSecurityManager::STANDARD);
}
@ -3168,11 +3168,6 @@ nsGenericElement::TriggerLink(nsPresContext* aPresContext,
nsILinkHandler *handler = aPresContext->GetLinkHandler();
if (!handler) return NS_OK;
nsIPrincipal* principal = GetNodePrincipal();
if (!principal) {
return NS_OK;
}
if (aClick) {
nsresult proceed = NS_OK;
// Check that this page is allowed to load this URI.
@ -3183,7 +3178,8 @@ nsGenericElement::TriggerLink(nsPresContext* aPresContext,
(PRUint32) nsIScriptSecurityManager::STANDARD :
(PRUint32) nsIScriptSecurityManager::DISALLOW_FROM_MAIL;
proceed =
securityManager->CheckLoadURIWithPrincipal(principal, aLinkURI, flag);
securityManager->CheckLoadURIWithPrincipal(NodePrincipal(), aLinkURI,
flag);
}
// Only pass off the click event if the script security manager

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

@ -69,11 +69,6 @@ public:
virtual PRBool
QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const;
nsIPrincipal *GetDocumentPrincipal() const
{
return mOwnerManager->GetDocumentPrincipal();
}
// nsNodeInfo
// Create objects with Create
public:

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

@ -313,6 +313,9 @@ nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal)
if (!aPrincipal) {
aPrincipal = mDefaultPrincipal;
}
NS_ASSERTION(aPrincipal, "Must have principal by this point!");
NS_ADDREF(mPrincipal = aPrincipal);
}

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

@ -116,7 +116,8 @@ public:
/**
* Gets the principal of the document this nodeinfo manager belongs to.
*/
nsIPrincipal *GetDocumentPrincipal() const {
nsIPrincipal *DocumentPrincipal() const {
NS_ASSERTION(mPrincipal, "How'd that happen?");
return mPrincipal;
}
@ -151,7 +152,7 @@ private:
PLHashTable *mNodeInfoHash;
nsIDocument *mDocument; // WEAK
nsIPrincipal *mPrincipal; // STRONG, but not nsCOMPtr to avoid include hell
// while inlining of GetPrincipal(). Never null
// while inlining DocumentPrincipal(). Never null
// after Init() succeeds.
nsCOMPtr<nsIPrincipal> mDefaultPrincipal; // Never null after Init() succeeds
nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership

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

@ -825,8 +825,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
NS_ASSERTION(secMan, "No security manager!?");
nsresult rv =
secMan->CheckLoadURIWithPrincipal(thisContent->GetNodePrincipal(),
aURI, 0);
secMan->CheckLoadURIWithPrincipal(thisContent->NodePrincipal(), aURI, 0);
if (NS_FAILED(rv)) {
Fallback(PR_FALSE);
return NS_OK;

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

@ -512,10 +512,8 @@ nsScriptLoader::DoProcessScriptElement(nsIScriptElement *aElement,
nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI();
if (scriptURI) {
// Check that the containing page is allowed to load this URI.
nsIPrincipal *docPrincipal = mDocument->GetNodePrincipal();
NS_ENSURE_TRUE(docPrincipal, NS_ERROR_UNEXPECTED);
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIWithPrincipal(docPrincipal, scriptURI,
CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), scriptURI,
nsIScriptSecurityManager::ALLOW_CHROME);
NS_ENSURE_SUCCESS(rv, rv);
@ -727,11 +725,6 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
return NS_ERROR_FAILURE;
}
nsIPrincipal *principal = mDocument->GetNodePrincipal();
// We can survive without a principal, but we really should
// have one.
NS_ASSERTION(principal, "principal required for document");
nsCAutoString url;
if (aRequest->mURI) {
@ -760,8 +753,9 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
PRBool isUndefined;
context->EvaluateString(aScript, globalObject->GetGlobalJSObject(),
principal, url.get(), aRequest->mLineNo,
aRequest->mJSVersion, nsnull, &isUndefined);
mDocument->NodePrincipal(), url.get(),
aRequest->mLineNo, aRequest->mJSVersion, nsnull,
&isUndefined);
// Put the old script back in case it wants to do anything else.
mCurrentScript = oldCurrent;
@ -1000,18 +994,10 @@ nsScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader,
nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(owner);
if (principal) {
nsIPrincipal *docPrincipal = mDocument->GetNodePrincipal();
if (docPrincipal) {
nsCOMPtr<nsIPrincipal> newPrincipal =
MaybeDowngradeToCodebase(docPrincipal, principal);
nsCOMPtr<nsIPrincipal> newPrincipal =
MaybeDowngradeToCodebase(mDocument->NodePrincipal(), principal);
mDocument->SetPrincipal(newPrincipal);
} else {
mPendingRequests.RemoveObject(request);
FireScriptAvailable(rv, request, EmptyString());
ProcessPendingReqests();
return NS_OK;
}
mDocument->SetPrincipal(newPrincipal);
}
}
}

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

@ -1244,7 +1244,7 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
nsIURI* uri = GetBaseURI();
nsIPrincipal* principal = nsnull;
if (doc) {
principal = doc->GetNodePrincipal();
principal = doc->NodePrincipal();
}
privImpl->Init(uri, uri, principal);
}

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

@ -581,12 +581,11 @@ nsCanvasRenderingContext2D::DoDrawImageSecurityCheck(nsIURI* aURI, PRBool forceW
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
nsCOMPtr<nsINode> elem = do_QueryInterface(mCanvasElement);
if (elem && ssm) {
nsIPrincipal* elemPrincipal = elem->GetNodePrincipal();
nsCOMPtr<nsIPrincipal> uriPrincipal;
ssm->GetCodebasePrincipal(aURI, getter_AddRefs(uriPrincipal));
if (uriPrincipal && elemPrincipal) {
nsresult rv =
ssm->CheckSameOriginPrincipal(elemPrincipal, uriPrincipal);
if (uriPrincipal) {
nsresult rv = ssm->CheckSameOriginPrincipal(elem->NodePrincipal(),
uriPrincipal);
if (NS_SUCCEEDED(rv)) {
// Same origin
return;

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

@ -1400,7 +1400,7 @@ nsHTMLFormElement::GetActionURL(nsIURI** aActionURL)
nsIScriptSecurityManager *securityManager =
nsContentUtils::GetSecurityManager();
rv = securityManager->
CheckLoadURIWithPrincipal(GetNodePrincipal(), actionURL,
CheckLoadURIWithPrincipal(NodePrincipal(), actionURL,
nsIScriptSecurityManager::STANDARD);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -1996,9 +1996,6 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
{
NS_ENSURE_TRUE(aDoc && aContainer, PR_TRUE);
nsIPrincipal *principal = aDoc->GetNodePrincipal();
NS_ENSURE_TRUE(principal, PR_TRUE);
nsCOMPtr<nsIScriptGlobalObject> globalObject = aDoc->GetScriptGlobalObject();
// Getting context is tricky if the document hasn't had it's
@ -2018,8 +2015,8 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
NS_ENSURE_TRUE(cx, PR_TRUE);
PRBool enabled = PR_TRUE;
nsContentUtils::GetSecurityManager()->CanExecuteScripts(cx, principal,
&enabled);
nsContentUtils::GetSecurityManager()->
CanExecuteScripts(cx, aDoc->NodePrincipal(), &enabled);
return enabled;
}
@ -3612,7 +3609,7 @@ HTMLContentSink::ProcessBASEElement(nsGenericHTMLElement* aElement)
nsContentUtils::GetSecurityManager();
rv = securityManager->
CheckLoadURIWithPrincipal(mDocument->GetNodePrincipal(), baseHrefURI,
CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), baseHrefURI,
nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mBaseHref = baseHrefURI;

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

@ -1547,11 +1547,7 @@ nsHTMLDocument::GetReferrer(nsAString& aReferrer)
void
nsHTMLDocument::GetDomainURI(nsIURI **aURI)
{
*aURI = nsnull;
nsIPrincipal *principal = GetNodePrincipal();
if (!principal)
return;
nsIPrincipal *principal = NodePrincipal();
principal->GetDomain(aURI);
if (!*aURI) {
@ -1632,15 +1628,11 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain)
if (NS_FAILED(NS_NewURI(getter_AddRefs(newURI), newURIString)))
return NS_ERROR_FAILURE;
nsresult rv = NS_ERROR_NOT_AVAILABLE;
nsIPrincipal* principal = GetNodePrincipal();
if (principal) {
rv = principal->SetDomain(newURI);
nsresult rv = NodePrincipal()->SetDomain(newURI);
// Bug 13871: Frameset spoofing - note that document.domain was set
if (NS_SUCCEEDED(rv)) {
mDomainWasSet = PR_TRUE;
}
// Bug 13871: Frameset spoofing - note that document.domain was set
if (NS_SUCCEEDED(rv)) {
mDomainWasSet = PR_TRUE;
}
return rv;
@ -1862,10 +1854,7 @@ nsHTMLDocument::GetCookie(nsAString& aCookie)
// Get a URI from the document principal. We use the original
// codebase in case the codebase was changed by SetDomain
nsCOMPtr<nsIURI> codebaseURI;
nsIPrincipal* principal = GetNodePrincipal();
if (principal) {
principal->GetURI(getter_AddRefs(codebaseURI));
}
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
if (!codebaseURI) {
// Document's principal is not a codebase (may be system), so
@ -1895,10 +1884,7 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie)
}
nsCOMPtr<nsIURI> codebaseURI;
nsIPrincipal* principal = GetNodePrincipal();
if (principal) {
principal->GetURI(getter_AddRefs(codebaseURI));
}
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
if (!codebaseURI) {
// Document's principal is not a codebase (may be system), so
@ -3660,17 +3646,12 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
// test if the above works if document.domain is set for Midas document
// (www.netscape.com --> netscape.com)
nsIPrincipal *principal = GetNodePrincipal();
if (!principal)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrincipal> subject;
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
if (subject) {
rv = secMan->CheckSameOriginPrincipal(subject, principal);
rv = secMan->CheckSameOriginPrincipal(subject, NodePrincipal());
NS_ENSURE_SUCCESS(rv, rv);
}

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

@ -312,11 +312,11 @@ nsHTMLFragmentContentSink::ProcessBaseTag(nsIContent* aContent)
nsIScriptSecurityManager *securityManager =
nsContentUtils::GetSecurityManager();
NS_ASSERTION(aContent->GetNodePrincipal() == mTargetDocument->GetNodePrincipal(),
NS_ASSERTION(aContent->NodePrincipal() == mTargetDocument->NodePrincipal(),
"How'd that happpen?");
rv = securityManager->
CheckLoadURIWithPrincipal(mTargetDocument->GetNodePrincipal(), baseHrefURI,
CheckLoadURIWithPrincipal(mTargetDocument->NodePrincipal(), baseHrefURI,
nsIScriptSecurityManager::STANDARD);
if (NS_SUCCEEDED(rv)) {
mBaseHref = baseHrefURI;

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

@ -1220,13 +1220,9 @@ nsXBLBinding::AllowScripts()
nsCOMPtr<nsIDocument> ourDocument;
mPrototypeBinding->XBLDocumentInfo()->GetDocument(getter_AddRefs(ourDocument));
nsIPrincipal* principal = ourDocument->GetNodePrincipal();
if (!principal) {
return PR_FALSE;
}
PRBool canExecute;
nsresult rv = mgr->CanExecuteScripts(cx, principal, &canExecute);
nsresult rv =
mgr->CanExecuteScripts(cx, ourDocument->NodePrincipal(), &canExecute);
return NS_SUCCEEDED(rv) && canExecute;
}

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

@ -725,20 +725,17 @@ nsXBLContentSink::ConstructImplementation(const PRUnichar **aAtts)
// our XBL document has UniversalXPConnect privileges. No principal
// means no privs!
nsIPrincipal* principal = mDocument->GetNodePrincipal();
if (principal) {
// XXX this api is so badly tied to JS it's not even funny. We don't
// have a concept of enabling capabilities on a per-principal basis,
// but only on a per-principal-and-JS-stackframe basis! So for now
// this is basically equivalent to testing that we have the system
// principal, since there is no JS stackframe in sight here...
PRBool hasUniversalXPConnect;
nsresult rv = principal->IsCapabilityEnabled("UniversalXPConnect",
nsnull,
&hasUniversalXPConnect);
if (NS_SUCCEEDED(rv) && hasUniversalXPConnect) {
mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1]));
}
// XXX this api is so badly tied to JS it's not even funny. We don't
// have a concept of enabling capabilities on a per-principal basis,
// but only on a per-principal-and-JS-stackframe basis! So for now
// this is basically equivalent to testing that we have the system
// principal, since there is no JS stackframe in sight here...
PRBool hasUniversalXPConnect;
nsresult rv = mDocument->NodePrincipal()->
IsCapabilityEnabled("UniversalXPConnect", nsnull,
&hasUniversalXPConnect);
if (NS_SUCCEEDED(rv) && hasUniversalXPConnect) {
mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1]));
}
}
}

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

@ -343,7 +343,7 @@ nsXBLDocGlobalObject::GetPrincipal()
rv = docInfo->GetDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, nsnull);
return document->GetNodePrincipal();
return document->NodePrincipal();
}
static PRBool IsChromeURI(nsIURI* aURI)

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

@ -543,10 +543,8 @@ nsXBLService::LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFl
// Not everything with a chrome URI has a system principal. See bug 160042.
if (NS_FAILED(rv) || !isChrome) {
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
rv = secMan->
CheckLoadURIWithPrincipal(document->GetNodePrincipal(), aURL,
rv = nsContentUtils::GetSecurityManager()->
CheckLoadURIWithPrincipal(document->NodePrincipal(), aURL,
nsIScriptSecurityManager::ALLOW_CHROME);
if (NS_FAILED(rv))
return rv;

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

@ -600,7 +600,7 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl)
}
return mXSLTProcessor->LoadStyleSheet(aUrl, loadGroup,
mDocument->GetNodePrincipal());
mDocument->NodePrincipal());
}
nsresult
@ -639,7 +639,7 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
// Do security check
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
rv = secMan->
CheckLoadURIWithPrincipal(mDocument->GetNodePrincipal(), url,
CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), url,
nsIScriptSecurityManager::ALLOW_CHROME);
NS_ENSURE_SUCCESS(rv, NS_OK);

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

@ -427,7 +427,7 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
// remain. This should be done before the security check is done to
// ensure that the document is reset even if the new document can't
// be loaded.
nsCOMPtr<nsIPrincipal> principal = GetNodePrincipal();
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
nsCOMPtr<nsIEventListenerManager> elm(mListenerManager);
ResetToURI(uri, nsnull);
@ -706,7 +706,7 @@ nsXMLDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
// Create an empty document
rv = NS_NewDOMDocument(getter_AddRefs(newDoc), EmptyString(), EmptyString(),
newDocType, nsIDocument::GetDocumentURI(),
nsIDocument::GetBaseURI(), GetNodePrincipal());
nsIDocument::GetBaseURI(), NodePrincipal());
if (NS_FAILED(rv)) return rv;
if (aDeep) {

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

@ -221,10 +221,7 @@ URIUtils::ResetWithSource(nsIDocument *aNewDoc, nsIDOMNode *aSourceNode)
return;
}
nsIPrincipal* sourcePrincipal = sourceDoc->GetNodePrincipal();
if (!sourcePrincipal) {
return;
}
nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
// Copy the channel and loadgroup from the source document.
nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();

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

@ -174,10 +174,7 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
// Reset and set up document
nsCOMPtr<nsIDocument> sourceDoc = do_QueryInterface(aSourceDocument);
nsIPrincipal* sourcePrincipal = sourceDoc->GetNodePrincipal();
if (!sourcePrincipal) {
return;
}
nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel();

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

@ -3080,12 +3080,6 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
return NS_ERROR_UNEXPECTED;
}
// Use the enclosing document's principal
// XXX is this right? or should we use the protodoc's?
nsIPrincipal *principal = aDocument->GetNodePrincipal();
if (!principal)
return NS_ERROR_FAILURE;
nsCAutoString urlspec;
aURI->GetSpec(urlspec);
@ -3110,7 +3104,10 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
rv = context->CompileScript(aText,
aTextLength,
nsnull,
principal,
// Use the enclosing document's principal
// XXX is this right? or should we use the
// protodoc's?
aDocument->NodePrincipal(),
urlspec.get(),
aLineNo,
mLangVersion,

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

@ -240,14 +240,10 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent)
// contextmenus.
nsCOMPtr<nsINode> node = do_QueryInterface(targetNode);
if (node) {
nsIPrincipal* prin = node->GetNodePrincipal();
nsIScriptSecurityManager *securityManager =
nsContentUtils::GetSecurityManager();
nsCOMPtr<nsIPrincipal> system;
securityManager->GetSystemPrincipal(getter_AddRefs(system));
if (prin != system) {
nsContentUtils::GetSecurityManager()->
GetSystemPrincipal(getter_AddRefs(system));
if (node->NodePrincipal() != system) {
// This isn't chrome. Cancel the preventDefault() and
// let the event go forth.
preventDefault = PR_FALSE;

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

@ -1259,7 +1259,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
if (NS_SUCCEEDED(rv)) {
rv = mSecMan->
CheckLoadURIWithPrincipal(doc->GetNodePrincipal(),
CheckLoadURIWithPrincipal(doc->NodePrincipal(),
script->mSrcURI,
nsIScriptSecurityManager::ALLOW_CHROME);
}

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

@ -972,11 +972,9 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
mCompDB->SetAllowNegativeAssertions(PR_FALSE);
// Grab the doc's principal...
nsIPrincipal *docPrincipal = doc->GetNodePrincipal();
if (!docPrincipal)
return NS_ERROR_FAILURE;
nsIPrincipal *docPrincipal = doc->NodePrincipal();
NS_ASSERTION(docPrincipal == mRoot->GetNodePrincipal(),
NS_ASSERTION(docPrincipal == mRoot->NodePrincipal(),
"Principal mismatch? Which one to use?");
PRBool isTrusted = PR_FALSE;

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

@ -808,13 +808,9 @@ nsXULTreeBuilder::SetTree(nsITreeBoxObject* aTree)
if (! mBoxObject)
return NS_OK;
// Get our root's principal
nsIPrincipal* rootPrincipal = mRoot->GetNodePrincipal();
if (!rootPrincipal)
return NS_ERROR_FAILURE;
// Is our root's principal trusted?
PRBool isTrusted = PR_FALSE;
nsresult rv = IsSystemPrincipal(rootPrincipal, &isTrusted);
nsresult rv = IsSystemPrincipal(mRoot->NodePrincipal(), &isTrusted);
if (NS_SUCCEEDED(rv) && isTrusted) {
// Get the datasource we intend to use to remember open state.
nsAutoString datasourceStr;

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

@ -1087,11 +1087,9 @@ nsDocShell::ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem,
nsCOMPtr<nsIDocument> targetDocument(do_QueryInterface(targetDOMDocument));
NS_ENSURE_TRUE(targetDocument, PR_TRUE);
nsIPrincipal *targetPrincipal = targetDocument->GetNodePrincipal();
NS_ENSURE_TRUE(targetPrincipal, PR_TRUE);
nsCOMPtr<nsIURI> targetPrincipalURI;
rv = targetPrincipal->GetURI(getter_AddRefs(targetPrincipalURI));
rv = targetDocument->
NodePrincipal()->GetURI(getter_AddRefs(targetPrincipalURI));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && targetPrincipalURI, PR_TRUE);
// Find out if document.domain was set for HTML documents
@ -6648,7 +6646,7 @@ nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner)
//-- Get the document's principal
if (document) {
*aOwner = document->GetNodePrincipal();
*aOwner = document->NodePrincipal();
}
NS_IF_ADDREF(*aOwner);

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

@ -487,7 +487,7 @@ nsGlobalWindow::FreeInnerObjects(JSContext *cx)
NS_ASSERTION(mDoc, "Why is mDoc null?");
// Remember the document's principal.
mDocumentPrincipal = mDoc->GetNodePrincipal();
mDocumentPrincipal = mDoc->NodePrincipal();
}
// Remove our reference to the document and the document principal.
@ -602,12 +602,6 @@ nsGlobalWindow::WouldReuseInnerWindow(nsIDocument *aNewDocument)
return PR_FALSE;
}
nsIPrincipal* newPrincipal = aNewDocument->GetNodePrincipal();
if (!newPrincipal) {
// This really should not be happening.... play it safe.
return PR_FALSE;
}
PRBool isAbout;
if (NS_FAILED(curURI->SchemeIs("about", &isAbout)) || !isAbout) {
return PR_FALSE;
@ -629,7 +623,7 @@ nsGlobalWindow::WouldReuseInnerWindow(nsIDocument *aNewDocument)
if (mOpenerScriptPrincipal && nsContentUtils::GetSecurityManager() &&
NS_SUCCEEDED(nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(mOpenerScriptPrincipal,
newPrincipal))) {
aNewDocument->NodePrincipal()))) {
// The origin is the same.
return PR_TRUE;
}
@ -940,20 +934,15 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
nsIPrincipal *oldPrincipal = nsnull;
if (oldDoc) {
oldPrincipal = oldDoc->GetNodePrincipal();
oldPrincipal = oldDoc->NodePrincipal();
}
// Drop our reference to the navigator object unless we're reusing
// the existing inner window or the new document is from the same
// origin as the old document.
if (!reUseInnerWindow && mNavigator && oldPrincipal) {
nsIPrincipal *newPrincipal = aDocument->GetNodePrincipal();
rv = NS_ERROR_FAILURE;
if (newPrincipal) {
rv = nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(oldPrincipal, newPrincipal);
}
rv = nsContentUtils::GetSecurityManager()->
CheckSameOriginPrincipal(oldPrincipal, aDocument->NodePrincipal());
if (NS_FAILED(rv)) {
// Different origins. Release the navigator object so it gets
@ -1333,7 +1322,7 @@ nsGlobalWindow::SetDocShell(nsIDocShell* aDocShell)
NS_ASSERTION(mDoc, "Must have doc!");
// Remember the document's principal.
mDocumentPrincipal = mDoc->GetNodePrincipal();
mDocumentPrincipal = mDoc->NodePrincipal();
// Release our document reference
mDocument = nsnull;
@ -1685,7 +1674,7 @@ nsGlobalWindow::GetPrincipal()
{
if (mDoc) {
// If we have a document, get the principal from the document
return mDoc->GetNodePrincipal();
return mDoc->NodePrincipal();
}
if (mDocumentPrincipal) {

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

@ -742,14 +742,12 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow,
secMan->IsCapabilityEnabled("UniversalXPConnect", &hasCap);
if (!hasCap) {
nsIPrincipal *principal = theDoc->GetNodePrincipal();
if (!principal)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIPrincipal> subject;
rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
NS_ENSURE_SUCCESS(rv, rv);
if (subject) {
rv = secMan->CheckSameOriginPrincipal(subject, principal);
rv = secMan->CheckSameOriginPrincipal(subject,
theDoc->NodePrincipal());
NS_ENSURE_SUCCESS(rv, rv);
}
}

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

@ -1179,29 +1179,27 @@ nsXFormsUtils::CheckSameOrigin(nsIDocument *aBaseDocument, nsIURI *aTestURI)
nsresult rv;
// get the base document's principal
nsIPrincipal *basePrincipal = aBaseDocument->GetNodePrincipal();
nsIPrincipal *basePrincipal = aBaseDocument->NodePrincipal();
if (basePrincipal) {
// check for the UniversalBrowserRead capability.
PRBool crossSiteAccessEnabled;
rv = basePrincipal->IsCapabilityEnabled("UniversalBrowserRead", nsnull,
&crossSiteAccessEnabled);
if (NS_SUCCEEDED(rv) && crossSiteAccessEnabled)
return PR_TRUE;
// check for the UniversalBrowserRead capability.
PRBool crossSiteAccessEnabled;
rv = basePrincipal->IsCapabilityEnabled("UniversalBrowserRead", nsnull,
&crossSiteAccessEnabled);
if (NS_SUCCEEDED(rv) && crossSiteAccessEnabled)
return PR_TRUE;
// check the security manager and do a same original check on the principal
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (secMan) {
// get a principal for the uri we are testing
nsCOMPtr<nsIPrincipal> testPrincipal;
rv = secMan->GetCodebasePrincipal(aTestURI, getter_AddRefs(testPrincipal));
// check the security manager and do a same original check on the principal
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (secMan) {
// get a principal for the uri we are testing
nsCOMPtr<nsIPrincipal> testPrincipal;
rv = secMan->GetCodebasePrincipal(aTestURI, getter_AddRefs(testPrincipal));
if (NS_SUCCEEDED(rv)) {
rv = secMan->CheckSameOriginPrincipal(basePrincipal, testPrincipal);
if (NS_SUCCEEDED(rv))
return PR_TRUE;
}
if (NS_SUCCEEDED(rv)) {
rv = secMan->CheckSameOriginPrincipal(basePrincipal, testPrincipal);
if (NS_SUCCEEDED(rv))
return PR_TRUE;
}
}

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

@ -1,737 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XMLterm.
*
* The Initial Developer of the Original Code is
* Ramalingam Saravanan.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// mozLineTerm.cpp: class implementing mozILineTerm/mozILineTermAux interfaces,
// providing an XPCOM/XPCONNECT wrapper for the LINETERM module
#include <stdio.h>
#include "nspr.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "plstr.h"
#include "nsReadableUtils.h"
#include "prlog.h"
#include "nsMemory.h"
#include "nsIServiceManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPrincipal.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "mozXMLT.h"
#include "mozXMLTermUtils.h"
#include "mozLineTerm.h"
#define MAXCOL 4096 // Maximum columns in line buffer
/////////////////////////////////////////////////////////////////////////
// mozLineTerm implementaion
/////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(mozLineTerm)
NS_IMPL_THREADSAFE_ISUPPORTS2(mozLineTerm,
mozILineTerm,
mozILineTermAux)
PRBool mozLineTerm::mLoggingEnabled = PR_FALSE;
PRBool mozLineTerm::mLoggingInitialized = PR_FALSE;
NS_METHOD
mozLineTerm::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (!mLoggingInitialized) {
// Initialize all LINETERM operations
// (This initialization needs to be done at factory creation time;
// trying to do it earlier, i.e., at registration time,
// does not work ... something to do with loading of static global
// variables.)
int messageLevel = 0;
char* debugStr = (char*) PR_GetEnv("LTERM_DEBUG");
if (debugStr && (strlen(debugStr) == 1)) {
messageLevel = 98;
debugStr = nsnull;
}
int result = lterm_init(0);
if (result == 0) {
tlog_set_level(LTERM_TLOG_MODULE, messageLevel, debugStr);
}
mLoggingInitialized = PR_TRUE;
char* logStr = (char*) PR_GetEnv("LTERM_LOG");
if (logStr && *logStr) {
// Enable LineTerm logging
mozLineTerm::mLoggingEnabled = PR_TRUE;
}
}
return mozLineTermConstructor( aOuter,
aIID,
aResult );
}
mozLineTerm::mozLineTerm() :
mCursorRow(0),
mCursorColumn(0),
mSuspended(PR_FALSE),
mEchoFlag(PR_TRUE),
mObserver(nsnull),
mCookie(EmptyString()),
mLastTime(LL_ZERO)
{
mLTerm = lterm_new();
}
mozLineTerm::~mozLineTerm()
{
lterm_delete(mLTerm);
mObserver = nsnull;
}
/** Checks if preference settings are secure for LineTerm creation and use
*/
NS_IMETHODIMP mozLineTerm::ArePrefsSecure(PRBool *_retval)
{
nsresult result;
XMLT_LOG(mozLineTerm::ArePrefsSecure,30,("\n"));
if (!_retval)
return NS_ERROR_FAILURE;
*_retval = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (!prefBranch)
return NS_ERROR_FAILURE;
// Check if Components JS object is secure
PRBool checkXPC;
result = prefBranch->GetBoolPref("security.checkxpconnect", &checkXPC);
if (NS_FAILED(result))
return NS_ERROR_FAILURE;
if (!checkXPC) {
XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
" pref(\"security.checkxpcconnect\",true);\n"
"to your preferences file (.mozilla/prefs.js)\n");
*_retval = PR_FALSE;
#if 0 // Temporarily commented out
return NS_OK;
#endif
}
nsCAutoString secString ("security.policy.");
/* Get global policy name. */
nsXPIDLCString policyStr;
result = prefBranch->GetCharPref("javascript.security_policy",
getter_Copies(policyStr));
if (NS_SUCCEEDED(result) && !policyStr.IsEmpty()) {
secString.Append(policyStr);
} else {
secString.Append("default");
}
secString.Append(".htmldocument.cookie");
XMLT_LOG(mozLineTerm::ArePrefsSecure,32, ("prefStr=%s\n", secString.get()));
nsXPIDLCString secLevelString;
result = prefBranch->GetCharPref(secString.get(), getter_Copies(secLevelString));
if (NS_FAILED(result))
return NS_ERROR_FAILURE;
XMLT_LOG(mozLineTerm::ArePrefsSecure,32,
("secLevelString=%s\n", secLevelString.get()));
*_retval = secLevelString.EqualsLiteral("sameOrigin");
if (!(*_retval)) {
XMLT_ERROR("mozLineTerm::ArePrefsSecure: Error - Please add the line\n"
" pref(\"security.policy.default.htmldocument.cookie\",\"sameOrigin\");\n"
"to your preferences file (.mozilla/prefs.js)\n");
}
return NS_OK;
}
/** Checks document principal to ensure it has LineTerm creation privileges.
* Returns the principal string if the principal is secure,
* and a (zero length) null string if the principal is insecure.
*/
NS_IMETHODIMP mozLineTerm::GetSecurePrincipal(nsIDOMDocument *domDoc,
char** aPrincipalStr)
{
XMLT_LOG(mozLineTerm::GetSecurePrincipal,30,("\n"));
if (!aPrincipalStr)
return NS_ERROR_FAILURE;
*aPrincipalStr = nsnull;
// Get principal string
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
if (!doc)
return NS_ERROR_FAILURE;
nsIPrincipal *principal = doc->GetNodePrincipal();
if (!principal)
return NS_ERROR_FAILURE;
#if 0 // Temporarily commented out, because |ToString()| is not implemented.
if (NS_FAILED(principal->ToString(aPrincipalStr)) || !*aPrincipalStr)
return NS_ERROR_FAILURE;
#else
const char temStr[] = "unknown";
PRInt32 temLen = strlen(temStr);
*aPrincipalStr = strncpy((char*) nsMemory::Alloc(temLen+1),
temStr, temLen+1);
#endif
XMLT_LOG(mozLineTerm::GetSecurePrincipal,32,("aPrincipalStr=%s\n",
*aPrincipalStr));
// Check if principal is secure
PRBool insecure = PR_FALSE;
if (insecure) {
// Return null string
XMLT_ERROR("mozLineTerm::GetSecurePrincipal: Error - "
"Insecure document principal %s\n", *aPrincipalStr);
nsMemory::Free(*aPrincipalStr);
*aPrincipalStr = (char*) nsMemory::Alloc(1);
**aPrincipalStr = '\0';
}
return NS_OK;
}
/** Open LineTerm without callback
*/
NS_IMETHODIMP mozLineTerm::Open(const PRUnichar *command,
const PRUnichar *initInput,
const PRUnichar *promptRegexp,
PRInt32 options, PRInt32 processType,
nsIDOMDocument *domDoc)
{
if (mSuspended) {
XMLT_ERROR("mozLineTerm::Open: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
nsAutoString aCookie;
return OpenAux(command, initInput, promptRegexp,
options, processType,
24, 80, 0, 0,
domDoc, nsnull, aCookie);
}
/** Open LineTerm, with an Observer for callback to process new input/output
*/
NS_IMETHODIMP mozLineTerm::OpenAux(const PRUnichar *command,
const PRUnichar *initInput,
const PRUnichar *promptRegexp,
PRInt32 options, PRInt32 processType,
PRInt32 nRows, PRInt32 nCols,
PRInt32 xPixels, PRInt32 yPixels,
nsIDOMDocument *domDoc,
nsIObserver* anObserver,
nsString& aCookie)
{
nsresult result;
XMLT_LOG(mozLineTerm::Open,20,("\n"));
// Ensure that preferences are secure for LineTerm creation and use
PRBool arePrefsSecure;
result = ArePrefsSecure(&arePrefsSecure);
#if 0 // Temporarily commented out
if (NS_FAILED(result) || !arePrefsSecure)
return NS_ERROR_FAILURE;
#endif
// Ensure that document principal is secure for LineTerm creation
char* securePrincipal;
result = GetSecurePrincipal(domDoc, &securePrincipal);
if (NS_FAILED(result))
return NS_ERROR_FAILURE;
if (!*securePrincipal) {
nsMemory::Free(securePrincipal);
XMLT_ERROR("mozLineTerm::OpenAux: Error - "
"Failed to create LineTerm for insecure document principal\n");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMHTMLDocument> domHTMLDoc = do_QueryInterface(domDoc);
if (!domHTMLDoc)
return NS_ERROR_FAILURE;
// Ensure that cookie attribute of document is defined
NS_NAMED_LITERAL_STRING(cookiePrefix, "xmlterm=");
nsAutoString cookieStr;
result = domHTMLDoc->GetCookie(cookieStr);
if (NS_SUCCEEDED(result) &&
(cookieStr.Length() > cookiePrefix.Length()) &&
StringBeginsWith(cookieStr, cookiePrefix)) {
// Cookie value already defined for document; simply copy it
mCookie = cookieStr;
} else {
// Create random session cookie
nsAutoString cookieValue;
result = mozXMLTermUtils::RandomCookie(cookieValue);
if (NS_FAILED(result))
return result;
mCookie = cookiePrefix;
mCookie += cookieValue;
// Set new cookie value
result = domHTMLDoc->SetCookie(mCookie);
if (NS_FAILED(result))
return result;
}
// Return copy of cookie to caller
aCookie = mCookie;
mObserver = anObserver; // non-owning reference
// Convert cookie to CString
char* cookieCStr = ToNewCString(mCookie);
XMLT_LOG(mozLineTerm::Open,22, ("mCookie=%s\n", cookieCStr));
// Convert initInput to CString
NS_LossyConvertUTF16toASCII initCStr(initInput); // XXX ASCII?
XMLT_LOG(mozLineTerm::Open,22, ("initInput=%s\n", initCStr.get()));
// List of prompt delimiters
static const PRInt32 PROMPT_DELIMS = 5;
UNICHAR prompt_regexp[PROMPT_DELIMS+1];
ucscopy(prompt_regexp, "#$%>?", PROMPT_DELIMS+1);
PR_ASSERT(ucslen(prompt_regexp) == PROMPT_DELIMS);
if (anObserver != nsnull) {
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.get(),
prompt_regexp, options, processType,
nRows, nCols, xPixels, yPixels,
mozLineTerm::Callback, (void *) this);
} else {
result = lterm_open(mLTerm, NULL, cookieCStr, initCStr.get(),
prompt_regexp, options, processType,
nRows, nCols, xPixels, yPixels,
NULL, NULL);
}
// Free cookie CString
nsMemory::Free(cookieCStr);
if (mLoggingEnabled) {
// Log time stamp for LineTerm open operation
nsAutoString timeStamp;
result = mozXMLTermUtils::TimeStamp(0, mLastTime, timeStamp);
if (NS_SUCCEEDED(result)) {
char* temStr = ToNewCString(timeStamp);
PR_LogPrint("<TS %s> LineTerm %d opened by principal %s\n",
temStr, mLTerm, securePrincipal);
nsMemory::Free(temStr);
}
}
if (result == 0) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
}
/** GTK-style callback funtion for mozLineTerm object
*/
void mozLineTerm::Callback(gpointer data,
gint source,
GdkInputCondition condition)
{
mozLineTerm* lineTerm = (mozLineTerm*) data;
//XMLT_LOG(mozLineTerm::Callback,50,("\n"));
PR_ASSERT(lineTerm != nsnull);
PR_ASSERT(lineTerm->mObserver != nsnull);
lineTerm->mObserver->Observe((nsISupports*) lineTerm, nsnull, nsnull);
return;
}
/** Suspends (or restores) LineTerm activity depending upon aSuspend
*/
NS_IMETHODIMP mozLineTerm::SuspendAux(PRBool aSuspend)
{
mSuspended = aSuspend;
return NS_OK;
}
/** Close LineTerm (a Finalize method)
*/
NS_IMETHODIMP mozLineTerm::Close(const PRUnichar* aCookie)
{
XMLT_LOG(mozLineTerm::Close,20, ("\n"));
if (!mCookie.Equals(aCookie)) {
XMLT_ERROR("mozLineTerm::Close: Error - Cookie mismatch\n");
return NS_ERROR_FAILURE;
}
if (mSuspended) {
XMLT_ERROR("mozLineTerm::Close: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
if (lterm_close(mLTerm) == 0) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
mObserver = nsnull;
}
/** Close LineTerm (a Finalize method)
*/
NS_IMETHODIMP mozLineTerm::CloseAux(void)
{
XMLT_LOG(mozLineTerm::CloseAux,20, ("\n"));
if (lterm_close(mLTerm) == 0) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
mObserver = nsnull;
}
/** Close all LineTerm instances
*/
NS_IMETHODIMP mozLineTerm::CloseAllAux(void)
{
lterm_close_all();
return NS_OK;
}
/** Resizes XMLterm to match a resized window.
* @param nRows number of rows
* @param nCols number of columns
*/
NS_IMETHODIMP mozLineTerm::ResizeAux(PRInt32 nRows, PRInt32 nCols)
{
int retCode;
XMLT_LOG(mozLineTerm::ResizeAux,30,("nRows=%d, nCols=%d\n", nRows, nCols));
// Resize LTERM
retCode = lterm_resize(mLTerm, (int) nRows, (int) nCols);
if (retCode < 0)
return NS_ERROR_FAILURE;
return NS_OK;
}
/** Writes a string to LTERM
*/
NS_IMETHODIMP mozLineTerm::Write(const PRUnichar *buf,
const PRUnichar* aCookie)
{
if (!mCookie.Equals(aCookie)) {
XMLT_ERROR("mozLineTerm::Write: Error - Cookie mismatch\n");
return NS_ERROR_FAILURE;
}
if (mSuspended) {
XMLT_ERROR("mozLineTerm::Write: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
XMLT_LOG(mozLineTerm::Write,30,("\n"));
nsresult result;
UNICHAR ubuf[MAXCOL];
int jLen, retCode;
PRBool newline = PR_FALSE;
jLen = 0;
while ((jLen < MAXCOL-1) && (buf[jLen] != 0)) {
if (buf[jLen] == U_LINEFEED)
newline = PR_TRUE;
ubuf[jLen] = (UNICHAR) buf[jLen];
if (ubuf[jLen] == U_PRIVATE0) {
// Hack to handle input of NUL characters in NUL-terminated strings
// See also: mozXMLTermKeyListener::KeyPress
ubuf[jLen] = U_NUL;
}
jLen++;
}
if (jLen >= MAXCOL-1) {
XMLT_ERROR("mozLineTerm::Write: Error - Buffer overflow\n");
return NS_ERROR_FAILURE;
}
if (mLoggingEnabled && (jLen > 0)) {
/* Log all input to STDERR */
ucsprint(stderr, ubuf, jLen);
nsAutoString timeStamp;
result = mozXMLTermUtils::TimeStamp(60, mLastTime, timeStamp);
if (NS_SUCCEEDED(result) && !timeStamp.IsEmpty()) {
char* temStr = ToNewCString(timeStamp);
PR_LogPrint("<TS %s>\n", temStr);
nsMemory::Free(temStr);
} else if (newline) {
PR_LogPrint("\n");
}
}
retCode = lterm_write(mLTerm, ubuf, jLen, LTERM_WRITE_PLAIN_INPUT);
if (retCode < 0)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::Read(PRInt32 *opcodes, PRInt32 *opvals,
PRInt32 *buf_row, PRInt32 *buf_col,
const PRUnichar* aCookie,
PRUnichar **_retval)
{
if (!mCookie.Equals(aCookie)) {
XMLT_ERROR("mozLineTerm::Read: Error - Cookie mismatch\n");
return NS_ERROR_FAILURE;
}
if (mSuspended) {
XMLT_ERROR("mozLineTerm::Read: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
return ReadAux(opcodes, opvals, buf_row, buf_col, _retval, nsnull);
}
/** Reads a line from LTERM and returns it as a string (may be null string)
*/
NS_IMETHODIMP mozLineTerm::ReadAux(PRInt32 *opcodes, PRInt32 *opvals,
PRInt32 *buf_row, PRInt32 *buf_col,
PRUnichar **_retval, PRUnichar **retstyle)
{
UNICHAR ubuf[MAXCOL];
UNISTYLE ustyle[MAXCOL];
int cursor_row, cursor_col;
int retCode, j;
XMLT_LOG(mozLineTerm::ReadAux,30,("\n"));
if (!_retval)
return NS_ERROR_NULL_POINTER;
retCode = lterm_read(mLTerm, 0, ubuf, MAXCOL-1,
ustyle, opcodes, opvals,
buf_row, buf_col, &cursor_row, &cursor_col);
if (retCode < 0)
return NS_ERROR_FAILURE;
if (*opcodes == 0) {
// Return null pointer(s)
*_retval = nsnull;
if (retstyle)
*retstyle = nsnull;
} else {
// Return output string
mCursorRow = cursor_row;
mCursorColumn = cursor_col;
XMLT_LOG(mozLineTerm::ReadAux,72,("cursor_col=%d\n", cursor_col));
int allocBytes = sizeof(PRUnichar)*(retCode + 1);
*_retval = (PRUnichar*) nsMemory::Alloc(allocBytes);
for (j=0; j<retCode; j++)
(*_retval)[j] = (PRUnichar) ubuf[j];
// Insert null string terminator
(*_retval)[retCode] = 0;
if (retstyle != nsnull) {
// Return style array as well
*retstyle = (PRUnichar*) nsMemory::Alloc(allocBytes);
for (j=0; j<retCode; j++)
(*retstyle)[j] = (PRUnichar) ustyle[j];
// Insert null string terminator
(*retstyle)[retCode] = 0;
}
}
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::GetCookie(nsString& aCookie)
{
aCookie = mCookie;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::GetCursorRow(PRInt32 *aCursorRow)
{
*aCursorRow = mCursorRow;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::SetCursorRow(PRInt32 aCursorRow)
{
int retCode;
if (mSuspended) {
XMLT_ERROR("mozLineTerm::SetCursorRow: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
retCode = lterm_setcursor(mLTerm, aCursorRow, mCursorColumn);
if (retCode < 0)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::GetCursorColumn(PRInt32 *aCursorColumn)
{
*aCursorColumn = mCursorColumn;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::SetCursorColumn(PRInt32 aCursorColumn)
{
int retCode;
if (mSuspended) {
XMLT_ERROR("mozLineTerm::SetCursorColumn: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
retCode = lterm_setcursor(mLTerm, mCursorRow, aCursorColumn);
if (retCode < 0)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::GetEchoFlag(PRBool *aEchoFlag)
{
*aEchoFlag = mEchoFlag;
return NS_OK;
}
NS_IMETHODIMP mozLineTerm::SetEchoFlag(PRBool aEchoFlag)
{
int result;
if (mSuspended) {
XMLT_ERROR("mozLineTerm::SetEchoFlag: Error - LineTerm %d is suspended\n",
mLTerm);
return NS_ERROR_FAILURE;
}
XMLT_LOG(mozLineTerm::SetEchoFlag,70,("aEchoFlag=0x%x\n", aEchoFlag));
if (aEchoFlag) {
result = lterm_setecho(mLTerm, 1);
} else {
result = lterm_setecho(mLTerm, 0);
}
if (result != 0)
return NS_ERROR_FAILURE;
mEchoFlag = aEchoFlag;
return NS_OK;
}

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

@ -1,394 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is XMLterm.
*
* The Initial Developer of the Original Code is
* Ramalingam Saravanan.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// mozXMLTermUtils.cpp: XMLTerm utilities implementation
#include "nscore.h"
#include "nspr.h"
#include "prlog.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsIDeviceContext.h"
#include "nsIPrincipal.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindowCollection.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMElement.h"
#include "nsIDocument.h"
#include "mozXMLT.h"
#include "mozXMLTermUtils.h"
/////////////////////////////////////////////////////////////////////////
/** Gets DOM window for doc shell
* @param aDocShell doc shell
* @param aDOMWindow returned DOM window (frame)
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::ConvertDocShellToDOMWindow(nsIDocShell* aDocShell,
nsIDOMWindowInternal** aDOMWindow)
{
XMLT_LOG(mozXMLTermUtils::ConvertDocShellToDOMWindow,30,("\n"));
if (!aDOMWindow)
return NS_ERROR_FAILURE;
*aDOMWindow = nsnull;
nsCOMPtr<nsIDOMWindowInternal> domWindow(do_GetInterface(aDocShell));
if (!domWindow)
return NS_ERROR_FAILURE;
domWindow.swap(*aDOMWindow);
return NS_OK;
}
/** Gets doc shell for DOM window
* @param aDOMWindow DOM window (frame)
* @param aDocShell returned doc shell
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::ConvertDOMWindowToDocShell(nsIDOMWindowInternal* aDOMWindow,
nsIDocShell** aDocShell)
{
XMLT_LOG(mozXMLTermUtils::ConvertDOMWindowToDocShell,30,("\n"));
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aDOMWindow);
if (!window)
return NS_ERROR_FAILURE;
*aDocShell = window->GetDocShell();
if (!*aDocShell)
return NS_ERROR_FAILURE;
NS_ADDREF(*aDocShell);
return NS_OK;
}
/** Locates named inner DOM window (frame) inside outer DOM window
* @param outerDOMWindow outer DOM window (frame)
* @param innerFrameName name of inner frame to be returned
* @param innerDOMWindow returned inner DOM window (frame)
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::GetInnerDOMWindow(nsIDOMWindowInternal* outerDOMWindow,
const nsString& innerFrameName,
nsIDOMWindowInternal** innerDOMWindow)
{
nsresult result;
XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,30,("\n"));
nsCOMPtr<nsIDOMWindowCollection> innerDOMWindowList;
result = outerDOMWindow->GetFrames(getter_AddRefs(innerDOMWindowList));
if (NS_FAILED(result) || !innerDOMWindowList)
return NS_ERROR_FAILURE;
PRUint32 frameCount = 0;
result = innerDOMWindowList->GetLength(&frameCount);
XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,31,("frameCount=%d\n",
frameCount));
result = innerDOMWindowList->NamedItem(innerFrameName, (nsIDOMWindow **)innerDOMWindow);
if (NS_FAILED(result) || !*innerDOMWindow)
return NS_ERROR_FAILURE;
return NS_OK;
}
/** Gets the scrollable view for presentation context
* @param aPresContext presentation context
* @param aScrollableView returned scrollable view
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::GetPresContextScrollableView(nsPresContext* aPresContext,
nsIScrollableView** aScrollableView)
{
XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));
if (!aScrollableView)
return NS_ERROR_FAILURE;
*aScrollableView = nsnull;
nsIPresShell *presShell = aPresContext->GetPresShell();
if (!presShell)
return NS_ERROR_FAILURE;
nsIViewManager* viewManager = presShell->GetViewManager();
if (!viewManager)
return NS_ERROR_FAILURE;
return viewManager->GetRootScrollableView(aScrollableView);
}
/** Gets the device context for presentation context
* @param aPresContext presentation context
* @param aDeviceContext returned device context
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::GetPresContextDeviceContext(nsPresContext* aPresContext,
nsIDeviceContext** aDeviceContext)
{
nsresult result;
XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));
if (!aDeviceContext)
return NS_ERROR_FAILURE;
*aDeviceContext = nsnull;
nsIViewManager* viewManager = aPresContext->GetViewManager();
if (!viewManager)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDeviceContext> deviceContext;
result = viewManager->GetDeviceContext(*getter_AddRefs(deviceContext));
if (NS_FAILED(result) || !deviceContext)
return NS_ERROR_FAILURE;
*aDeviceContext = deviceContext.get();
NS_ADDREF(*aDeviceContext);
return NS_OK;
}
/** Gets the script context for document
* @param aDOMDocument document providing context
* @param aScriptContext returned script context
* @return NS_OK on success
*/
NS_EXPORT nsresult
mozXMLTermUtils::GetScriptContext(nsIDOMDocument* aDOMDocument,
nsIScriptContext** aScriptContext)
{
XMLT_LOG(mozXMLTermUtils::GetScriptContext,20,("\n"));
nsCOMPtr<nsIDocument> doc ( do_QueryInterface(aDOMDocument) );
if (!doc)
return NS_ERROR_FAILURE;
nsIScriptGlobalObject *scriptGlobalObject = doc->GetScriptGlobalObject();
if (!scriptGlobalObject)
return NS_ERROR_FAILURE;
*aScriptContext = scriptGlobalObject->GetContext();
NS_IF_ADDREF(*aScriptContext);
return NS_OK;
}
/** Executes script in specified document's context.
* @param aDOMDocument document providing context for script execution
* @param aScript string to be executed
* @param aOutput output string produced by script execution
* @return NS_OK if script was valid and got executed properly
*/
NS_EXPORT nsresult
mozXMLTermUtils::ExecuteScript(nsIDOMDocument* aDOMDocument,
const nsString& aScript,
nsString& aOutput)
{
nsresult result;
XMLT_LOG(mozXMLTermUtils::ExecuteScript,20,("\n"));
// Get document principal
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDocument);
if (!doc)
return NS_ERROR_FAILURE;
nsIPrincipal *docPrincipal = doc->GetNodePrincipal();
if (!docPrincipal)
return NS_ERROR_FAILURE;
// Get document script context
nsCOMPtr<nsIScriptContext> scriptContext;
result = GetScriptContext(aDOMDocument, getter_AddRefs(scriptContext));
if (NS_FAILED(result) || !scriptContext)
return NS_ERROR_FAILURE;
// Execute script
PRBool isUndefined = PR_FALSE;
const char* URL = "";
result = scriptContext->EvaluateString(aScript, (void *) nsnull,
docPrincipal, URL, 0, nsnull,
&aOutput, &isUndefined);
XMLT_LOG(mozXMLTermUtils::ExecuteScript,21,("result=0x%x,isUndefined=0x%x\n",
result, isUndefined));
return result;
}
/** Returns the specified attribute value associated with a DOM node,
* or a null string if the attribute is not defined, or if the DOM node
* is not an element.
* @param aDOMNode node whose attribute is to be determined
* @param aAttName attribute to be determined. Must be ASCII.
* @param aAttValue output attribute value
* @return NS_OK if no errors occurred
*/
NS_EXPORT nsresult
mozXMLTermUtils::GetNodeAttribute(nsIDOMNode* aDOMNode,
const char* aAttName,
nsString& aAttValue)
{
XMLT_LOG(mozXMLTermUtils::GetNodeAttribute,20,("aAttName=%s\n", aAttName));
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(aDOMNode);
if (!domElement) {
aAttValue.SetLength(0);
return NS_OK;
}
nsAutoString attName;
attName.AssignASCII(aAttName);
return domElement->GetAttribute(attName, aAttValue);
}
/** Returns a timestamp string containing the local time, if at least
* deltaSec seconds have elapsed since the last timestamp. Otherwise,
* a null string is returned.
* @param deltaSec minimum elapsed seconds since last timestamp (>=0)
* @param lastTime in/out parameter containing time of last timestamp
* @param aTimeStamp returned timestamp string
* @return NS_OK on success
*/
NS_IMETHODIMP mozXMLTermUtils::TimeStamp(PRInt32 deltaSec, PRTime& lastTime,
nsString& aTimeStamp)
{
static const PRInt32 DATE_LEN = 19;
PRTime deltaTime ;
char dateStr[DATE_LEN+1];
PRTime curTime, difTime;
curTime = PR_Now();
LL_SUB(difTime, curTime, lastTime);
LL_I2L(deltaTime, deltaSec*1000000);
if (LL_CMP(difTime, <, deltaTime)) {
// Not enough time has elapsed for a new time stamp
aTimeStamp.SetLength(0);
return NS_OK;
}
lastTime = curTime;
// Current local time
PRExplodedTime localTime;
PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);
PRInt32 nWritten = PR_snprintf(dateStr, DATE_LEN+1,
"%02d:%02d:%02d %02d/%02d/%04d", // XXX i18n!
localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
localTime.tm_mday, localTime.tm_month+1, localTime.tm_year);
if (nWritten != DATE_LEN)
return NS_ERROR_FAILURE;
XMLT_LOG(mozXMLTermUtils::LocalTime,99,("localTime=%s\n", dateStr));
aTimeStamp.AssignASCII(dateStr);
return NS_OK;
}
/** Returns a string containing a 11-digit random cookie based upon the
* current local time and the elapsed execution of the program.
* @param aCookie returned cookie string
* @return NS_OK on success
*/
NS_IMETHODIMP mozXMLTermUtils::RandomCookie(nsString& aCookie)
{
// Current local time
PRExplodedTime localTime;
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);
PRInt32 randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;
PRIntervalTime randomNumberB = PR_IntervalNow();
XMLT_LOG(mozXMLTermUtils::RandomCookie,30,("ranA=0x%x, ranB=0x%x\n",
randomNumberA, randomNumberB));
PR_ASSERT(randomNumberA >= 0);
PR_ASSERT(randomNumberB >= 0);
static const char cookieDigits[17] = "0123456789abcdef";
char cookie[12];
int j;
for (j=0; j<6; j++) {
cookie[j] = cookieDigits[randomNumberA%16];
randomNumberA = randomNumberA/16;
}
for (j=6; j<11; j++) {
cookie[j] = cookieDigits[randomNumberB%16];
randomNumberB = randomNumberB/16;
}
cookie[11] = '\0';
aCookie.AssignASCII(cookie);
return NS_OK;
}

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

@ -1530,13 +1530,8 @@ nsImageFrame::TriggerLink(nsPresContext* aPresContext,
if (NS_FAILED(rv))
return;
nsIPrincipal* principal = aTriggerNode->GetNodePrincipal();
if (!principal) {
return;
}
rv = securityManager->
CheckLoadURIWithPrincipal(principal, aURI,
CheckLoadURIWithPrincipal(aTriggerNode->NodePrincipal(), aURI,
nsIScriptSecurityManager::STANDARD);
// Only pass off the click event if the script security manager

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

@ -3385,7 +3385,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbeddedPlugin(const char *aMimeType,
if (!doc)
return NS_ERROR_NULL_POINTER;
rv = secMan->CheckLoadURIWithPrincipal(doc->GetNodePrincipal(), aURL, 0);
rv = secMan->CheckLoadURIWithPrincipal(doc->NodePrincipal(), aURL, 0);
if (NS_FAILED(rv))
return rv;
@ -5758,7 +5758,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
if (doc)
{
// Set the owner of channel to the document principal...
channel->SetOwner(doc->GetNodePrincipal());
channel->SetOwner(doc->NodePrincipal());
}
// deal with headers and post data
@ -5840,7 +5840,7 @@ nsPluginHostImpl::DoURLLoadSecurityCheck(nsIPluginInstance *aInstance,
if (NS_FAILED(rv))
return rv;
return secMan->CheckLoadURIWithPrincipal(doc->GetNodePrincipal(), targetURL,
return secMan->CheckLoadURIWithPrincipal(doc->NodePrincipal(), targetURL,
nsIScriptSecurityManager::STANDARD);
}

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

@ -359,7 +359,7 @@ nsSecureBrowserUIImpl::Notify(nsIContent* formNode,
nsCOMPtr<nsIDocument> document = formNode->GetDocument();
if (!document) return NS_OK;
nsIPrincipal *principal = formNode->GetNodePrincipal();
nsIPrincipal *principal = formNode->NodePrincipal();
if (!principal)
{