Make some props absolute URIs resolved relative to other props (eg. codebase).

Bug 213701, patch by Florian Qu�ze <f.qu@queze.net>, r+sr=bzbarsky
This commit is contained in:
bzbarsky%mit.edu 2006-07-20 23:42:51 +00:00
Родитель ae8a224346
Коммит 1f454f5c02
5 изменённых файлов: 46 добавлений и 15 удалений

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

@ -2811,7 +2811,7 @@ nsGenericHTMLElement::SetIntAttr(nsIAtom* aAttr, PRInt32 aValue)
}
nsresult
nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsAString& aResult)
nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsAString& aResult)
{
nsAutoString attrValue;
if (!GetAttr(kNameSpaceID_None, aAttr, attrValue)) {
@ -2821,11 +2821,29 @@ nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsAString& aResult)
}
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsresult rv;
if (aBaseAttr) {
nsAutoString baseAttrValue;
if (GetAttr(kNameSpaceID_None, aBaseAttr, baseAttrValue)) {
nsCOMPtr<nsIURI> baseAttrURI;
rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(baseAttrURI),
baseAttrValue, GetOwnerDoc(),
baseURI);
if (NS_FAILED(rv)) {
// Just use the attr value as the result...
aResult = attrValue;
return NS_OK;
}
baseURI.swap(baseAttrURI);
}
}
nsCOMPtr<nsIURI> attrURI;
nsresult rv =
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(attrURI),
attrValue, GetOwnerDoc(),
baseURI);
rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(attrURI),
attrValue, GetOwnerDoc(),
baseURI);
if (NS_FAILED(rv)) {
// Just use the attr value as the result...
aResult = attrValue;

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

@ -718,10 +718,11 @@ protected:
* isn't a relative URI the value of the attribute is returned as is. Only
* works for attributes in null namespace.
*
* @param aAttr name of attribute.
* @param aResult result value [out]
* @param aAttr name of attribute.
* @param aBaseAttr name of base attribute.
* @param aResult result value [out]
*/
NS_HIDDEN_(nsresult) GetURIAttr(nsIAtom* aAttr, nsAString& aResult);
NS_HIDDEN_(nsresult) GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsAString& aResult);
/**
* This method works like GetURIAttr, except that it supports multiple
@ -982,7 +983,7 @@ NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
NS_IMETHODIMP \
_class::Get##_method(nsAString& aValue) \
{ \
return GetURIAttr(nsHTMLAtoms::_atom, aValue); \
return GetURIAttr(nsHTMLAtoms::_atom, nsnull, aValue); \
} \
NS_IMETHODIMP \
_class::Set##_method(const nsAString& aValue) \
@ -990,6 +991,18 @@ NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
return SetAttrHelper(nsHTMLAtoms::_atom, aValue); \
}
#define NS_IMPL_URI_ATTR_WITH_BASE(_class, _method, _atom, _base_atom) \
NS_IMETHODIMP \
_class::Get##_method(nsAString& aValue) \
{ \
return GetURIAttr(nsHTMLAtoms::_atom, nsHTMLAtoms::_base_atom, aValue); \
} \
NS_IMETHODIMP \
_class::Set##_method(const nsAString& aValue) \
{ \
return SetAttrHelper(nsHTMLAtoms::_atom, aValue); \
}
/**
* QueryInterface() implementation helper macros
*/

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

@ -595,7 +595,7 @@ nsHTMLFormElement::GetAction(nsAString& aValue)
// Avoid resolving action="" to the base uri, bug 297761.
return NS_OK;
}
return GetURIAttr(nsHTMLAtoms::action, aValue);
return GetURIAttr(nsHTMLAtoms::action, nsnull, aValue);
}
NS_IMETHODIMP

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

@ -307,10 +307,10 @@ nsHTMLObjectElement::SubmitNamesValues(nsIFormSubmission *aFormSubmission,
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Align, align)
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Archive, archive)
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Border, border)
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Code, code)
NS_IMPL_URI_ATTR_WITH_BASE(nsHTMLObjectElement, Code, code, codebase)
NS_IMPL_URI_ATTR(nsHTMLObjectElement, CodeBase, codebase)
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, CodeType, codetype)
NS_IMPL_URI_ATTR(nsHTMLObjectElement, Data, data)
NS_IMPL_URI_ATTR_WITH_BASE(nsHTMLObjectElement, Data, data, codebase)
NS_IMPL_BOOL_ATTR(nsHTMLObjectElement, Declare, declare)
NS_IMPL_STRING_ATTR(nsHTMLObjectElement, Height, height)
NS_IMPL_INT_ATTR(nsHTMLObjectElement, Hspace, hspace)

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

@ -302,13 +302,13 @@ nsHTMLSharedObjectElement::GetDesiredIMEState()
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Align, align)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Alt, alt)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Archive, archive)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Code, code)
NS_IMPL_URI_ATTR_WITH_BASE(nsHTMLSharedObjectElement, Code, code, codebase)
NS_IMPL_URI_ATTR(nsHTMLSharedObjectElement, CodeBase, codebase)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Height, height)
NS_IMPL_INT_ATTR(nsHTMLSharedObjectElement, Hspace, hspace)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Name, name)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Object, object)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Src, src)
NS_IMPL_URI_ATTR_WITH_BASE(nsHTMLSharedObjectElement, Object, object, codebase)
NS_IMPL_URI_ATTR(nsHTMLSharedObjectElement, Src, src)
NS_IMPL_INT_ATTR(nsHTMLSharedObjectElement, TabIndex, tabindex)
NS_IMPL_STRING_ATTR(nsHTMLSharedObjectElement, Type, type)
NS_IMPL_INT_ATTR(nsHTMLSharedObjectElement, Vspace, vspace)