mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 12:55:46 +00:00
Fixing bug 292464. Use the documents principals to check if a document is a chrome document or not. r=smaug@welho.com, sr=peterv@propagandism.org, a=shaver@mozilla.org
This commit is contained in:
parent
b8b0d654a7
commit
4e48d2a634
@ -112,10 +112,10 @@ public:
|
||||
* @return PR_TRUE if aPossibleDescendant is a descendant of
|
||||
* aPossibleAncestor (or is aPossibleAncestor). PR_FALSE
|
||||
* otherwise.
|
||||
*/
|
||||
*/
|
||||
static PRBool ContentIsDescendantOf(nsIContent* aPossibleDescendant,
|
||||
nsIContent* aPossibleAncestor);
|
||||
|
||||
|
||||
/*
|
||||
* This method fills the |aArray| with all ancestor nodes of |aNode|
|
||||
* including |aNode| at the zero index.
|
||||
@ -132,7 +132,7 @@ public:
|
||||
* For each ancestor, there is a corresponding element in |aAncestorOffsets|
|
||||
* which is the IndexOf the child in relation to its parent.
|
||||
*
|
||||
* The elements of |aAncestorNodes| were |nsIContent*|s before casting to
|
||||
* The elements of |aAncestorNodes| were |nsIContent*|s before casting to
|
||||
* |void*| and must be cast back to |nsIContent*| on usage, or bad things
|
||||
* will happen.
|
||||
*
|
||||
@ -194,9 +194,9 @@ public:
|
||||
*/
|
||||
static PRUint16 ReverseDocumentPosition(PRUint16 aDocumentPosition);
|
||||
|
||||
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
|
||||
PRUint32 aSrcOffset,
|
||||
PRUnichar* aDest,
|
||||
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
|
||||
PRUint32 aSrcOffset,
|
||||
PRUnichar* aDest,
|
||||
PRUint32 aLength,
|
||||
PRBool& aLastCharCR);
|
||||
|
||||
@ -212,7 +212,7 @@ public:
|
||||
PRBool aTrimTrailing = PR_TRUE);
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether two nodes come from the same origin. aTrustedNode is
|
||||
* considered 'safe' in that a user can operate on it and that it isn't
|
||||
@ -247,7 +247,7 @@ public:
|
||||
static PRBool InProlog(nsIDOMNode *aNode);
|
||||
|
||||
static nsIParserService* GetParserServiceWeakRef();
|
||||
|
||||
|
||||
static nsINameSpaceManager* GetNSManagerWeakRef()
|
||||
{
|
||||
return sNameSpaceManager;
|
||||
@ -266,12 +266,12 @@ public:
|
||||
#ifdef MOZ_XTF
|
||||
static nsIXTFService* GetXTFServiceWeakRef();
|
||||
#endif
|
||||
|
||||
|
||||
static nsIScriptSecurityManager* GetSecurityManager()
|
||||
{
|
||||
return sSecurityManager;
|
||||
}
|
||||
|
||||
|
||||
static nsresult GenerateStateKey(nsIContent* aContent,
|
||||
nsIDocument* aDocument,
|
||||
nsIStatefulFrame::SpecialStateID aID,
|
||||
@ -297,7 +297,7 @@ public:
|
||||
*/
|
||||
static PRBool BelongsInForm(nsIDOMHTMLFormElement *aForm,
|
||||
nsIContent *aContent);
|
||||
|
||||
|
||||
static nsresult CheckQName(const nsAString& aQualifiedName,
|
||||
PRBool aNamespaceAware = PR_TRUE);
|
||||
|
||||
@ -424,7 +424,7 @@ public:
|
||||
* @return Null if aContent is not an XLink, the URI it points to otherwise
|
||||
*/
|
||||
static already_AddRefed<nsIURI> GetXLinkURI(nsIContent* aContent);
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method to create a new nodeinfo that differs only by name
|
||||
* from aNodeInfo.
|
||||
@ -534,6 +534,10 @@ public:
|
||||
static already_AddRefed<nsContentList>
|
||||
GetFormControlElements(nsIDocument *aDocument);
|
||||
|
||||
/**
|
||||
* Returns true if aDocument is a chrome document
|
||||
*/
|
||||
static PRBool IsChromeDoc(nsIDocument *aDocument);
|
||||
|
||||
private:
|
||||
static nsresult doReparentContentWrapper(nsIContent *aChild,
|
||||
|
@ -188,7 +188,7 @@ nsContentUtils::Init()
|
||||
// no image loading for us. Oh, well.
|
||||
sImgLoader = nsnull;
|
||||
}
|
||||
|
||||
|
||||
sInitialized = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
@ -488,7 +488,7 @@ nsContentUtils::GetDocumentAndPrincipal(nsIDOMNode* aNode,
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
*aPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal();
|
||||
if (!*aPrincipal) {
|
||||
// we can't get to the principal so we'll give up
|
||||
@ -502,7 +502,7 @@ nsContentUtils::GetDocumentAndPrincipal(nsIDOMNode* aNode,
|
||||
CallQueryInterface(domDoc, aDocument);
|
||||
if (!*aDocument) {
|
||||
NS_ERROR("QI to nsIDocument failed");
|
||||
|
||||
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
@ -564,9 +564,9 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode,
|
||||
|
||||
nsINodeInfo *ni = cont->GetNodeInfo();
|
||||
NS_ENSURE_TRUE(ni, NS_ERROR_UNEXPECTED);
|
||||
|
||||
|
||||
trustedPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal();
|
||||
|
||||
|
||||
if (!trustedPrincipal) {
|
||||
// Can't get principal of aTrustedNode so we can't check security
|
||||
// against it
|
||||
@ -1345,7 +1345,7 @@ static inline void KeyAppendString(const nsAString& aString, nsACString& aKey)
|
||||
static inline void KeyAppendString(const nsACString& aString, nsACString& aKey)
|
||||
{
|
||||
KeyAppendSep(aKey);
|
||||
|
||||
|
||||
// Could escape separator here if collisions happen. > is not a legal char
|
||||
// for a name or type attribute, so we should be safe avoiding that extra work.
|
||||
|
||||
@ -1487,7 +1487,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
|
||||
} else {
|
||||
|
||||
// If not in a form, add index of control in document
|
||||
// Less desirable than indexing by form info.
|
||||
// Less desirable than indexing by form info.
|
||||
|
||||
// Hash by index of control in doc (we are not in a form)
|
||||
// These are important as they are unique, and type/name may not be.
|
||||
@ -1597,7 +1597,7 @@ nsContentUtils::BelongsInForm(nsIDOMHTMLFormElement *aForm,
|
||||
// aForm return false here....
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
@ -1861,7 +1861,7 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument,
|
||||
// nothing we can do here
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroup = aLoadingDocument->GetDocumentLoadGroup();
|
||||
NS_WARN_IF_FALSE(loadGroup, "Could not get loadgroup; onload may fire too early");
|
||||
|
||||
@ -1891,28 +1891,28 @@ nsContentUtils::GetImageFromContent(nsIImageLoadingContent* aContent,
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(aContent, nsnull);
|
||||
|
||||
|
||||
nsCOMPtr<imgIRequest> imgRequest;
|
||||
aContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
||||
getter_AddRefs(imgRequest));
|
||||
if (!imgRequest) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<imgIContainer> imgContainer;
|
||||
imgRequest->GetImage(getter_AddRefs(imgContainer));
|
||||
|
||||
if (!imgContainer) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<gfxIImageFrame> imgFrame;
|
||||
imgContainer->GetFrameAt(0, getter_AddRefs(imgFrame));
|
||||
|
||||
if (!imgFrame) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(imgFrame);
|
||||
|
||||
if (!ir) {
|
||||
@ -1945,7 +1945,7 @@ nsContentUtils::IsDraggableImage(nsIContent* aContent)
|
||||
|
||||
// XXXbz It may be draggable even if the request resulted in an error. Why?
|
||||
// Not sure; that's what the old nsContentAreaDragDrop/nsFrame code did.
|
||||
return imgRequest != nsnull;
|
||||
return imgRequest != nsnull;
|
||||
}
|
||||
|
||||
// static
|
||||
@ -2320,3 +2320,17 @@ nsContentUtils::GetFormControlElements(nsIDocument *aDocument)
|
||||
NS_IF_ADDREF(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsContentUtils::IsChromeDoc(nsIDocument *aDocument)
|
||||
{
|
||||
nsIPrincipal *principal;
|
||||
if (!aDocument || !(principal = aDocument->GetPrincipal())) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
||||
sSecurityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
||||
|
||||
return principal == systemPrincipal;
|
||||
}
|
||||
|
@ -4028,14 +4028,8 @@ nsDocument::AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture)
|
||||
{
|
||||
PRBool permitUntrustedEvents = PR_FALSE;
|
||||
if (mDocumentURI) {
|
||||
PRBool isChrome = PR_TRUE;
|
||||
nsresult rv = mDocumentURI->SchemeIs("chrome", &isChrome);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
permitUntrustedEvents = !isChrome;
|
||||
}
|
||||
return AddEventListener(aType, aListener, aUseCapture, permitUntrustedEvents);
|
||||
return AddEventListener(aType, aListener, aUseCapture,
|
||||
!nsContentUtils::IsChromeDoc(this));
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -624,17 +624,9 @@ nsDOMEventRTTearoff::AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener *aListener,
|
||||
PRBool useCapture)
|
||||
{
|
||||
PRBool permitUntrustedEvents = PR_FALSE;
|
||||
nsIDocument *ownerDoc = mContent->GetOwnerDoc();
|
||||
nsIURI *docUri;
|
||||
if (ownerDoc && (docUri = ownerDoc->GetDocumentURI())) {
|
||||
PRBool isChrome = PR_TRUE;
|
||||
nsresult rv = docUri->SchemeIs("chrome", &isChrome);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
permitUntrustedEvents = !isChrome;
|
||||
}
|
||||
|
||||
return AddEventListener(aType, aListener, useCapture, permitUntrustedEvents);
|
||||
return
|
||||
AddEventListener(aType, aListener, useCapture,
|
||||
!nsContentUtils::IsChromeDoc(mContent->GetOwnerDoc()));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -3368,19 +3360,9 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
|
||||
if (manager) {
|
||||
nsIDocument *ownerDoc = GetOwnerDoc();
|
||||
|
||||
PRBool permitUntrustedEvents = PR_FALSE;
|
||||
|
||||
nsIURI *docUri;
|
||||
if (ownerDoc && (docUri = ownerDoc->GetDocumentURI())) {
|
||||
PRBool isChrome = PR_TRUE;
|
||||
rv = docUri->SchemeIs("chrome", &isChrome);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
permitUntrustedEvents = !isChrome;
|
||||
}
|
||||
|
||||
rv = manager->AddScriptEventListener(target, aAttribute, aValue, defer,
|
||||
permitUntrustedEvents);
|
||||
rv =
|
||||
manager->AddScriptEventListener(target, aAttribute, aValue, defer,
|
||||
!nsContentUtils::IsChromeDoc(ownerDoc));
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -232,17 +232,9 @@ nsSVGElement::SetAttr(PRInt32 aNamespaceID, nsIAtom* aName, nsIAtom* aPrefix,
|
||||
if (manager) {
|
||||
nsIDocument *ownerDoc = GetOwnerDoc();
|
||||
|
||||
PRBool permitUntrustedEvents = PR_FALSE;
|
||||
|
||||
nsIURI *docUri;
|
||||
if (ownerDoc && (docUri = ownerDoc->GetDocumentURI())) {
|
||||
PRBool isChrome = PR_TRUE;
|
||||
rv = docUri->SchemeIs("chrome", &isChrome);
|
||||
permitUntrustedEvents = NS_SUCCEEDED(rv) && !isChrome;
|
||||
}
|
||||
|
||||
manager->AddScriptEventListener(NS_STATIC_CAST(nsIContent*, this), aName,
|
||||
aValue, PR_TRUE, permitUntrustedEvents);
|
||||
aValue, PR_TRUE,
|
||||
!nsContentUtils::IsChromeDoc(ownerDoc));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -659,19 +659,8 @@ nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAString& aValue)
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIURI *uri = doc->GetDocumentURI();
|
||||
PRBool isChromeElement;
|
||||
|
||||
if (uri) {
|
||||
if (NS_FAILED(uri->SchemeIs("chrome", &isChromeElement))) {
|
||||
isChromeElement = PR_FALSE;
|
||||
}
|
||||
} else {
|
||||
isChromeElement = PR_FALSE;
|
||||
}
|
||||
|
||||
return manager->AddScriptEventListener(target, aName, aValue, defer,
|
||||
!isChromeElement);
|
||||
!nsContentUtils::IsChromeDoc(doc));
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -4084,16 +4084,10 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
|
||||
nsIDOMEventListener* aListener,
|
||||
PRBool aUseCapture)
|
||||
{
|
||||
PRBool permitUntrustedEvents = PR_FALSE;
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
|
||||
nsIURI *docUri;
|
||||
if (doc && (docUri = doc->GetDocumentURI())) {
|
||||
PRBool isChrome = PR_TRUE;
|
||||
nsresult rv = docUri->SchemeIs("chrome", &isChrome);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
permitUntrustedEvents = !isChrome;
|
||||
}
|
||||
return AddEventListener(aType, aListener, aUseCapture, permitUntrustedEvents);
|
||||
|
||||
return AddEventListener(aType, aListener, aUseCapture,
|
||||
!nsContentUtils::IsChromeDoc(doc));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -6383,7 +6377,8 @@ nsGlobalChromeWindow::SetCursor(const nsAString& aCursor)
|
||||
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
||||
|
||||
// Call esm and set cursor.
|
||||
rv = presContext->EventStateManager()->SetCursor(cursor, nsnull, widget, PR_TRUE);
|
||||
rv = presContext->EventStateManager()->SetCursor(cursor, nsnull, widget,
|
||||
PR_TRUE);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
Loading…
Reference in New Issue
Block a user