Rename nsILink::GetHrefCString to GetHrefUTF8 to clarify prior change in semantics. Remove duplication of code to implement it. Fix some incorrect conversions that were still assuming it was ASCII. Remove vestigial |aOuter| parameter to nsGenericHTMLElement::HandleDOMEventForAnchors. b=209566 r+sr=jst

This commit is contained in:
dbaron%dbaron.org 2003-06-17 16:22:51 +00:00
Родитель 18112ff43b
Коммит cd4fb875a5
10 изменённых файлов: 85 добавлений и 172 удалений

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

@ -90,7 +90,7 @@ NS_IMETHODIMP nsHTMLLinkAccessibleWrap::GetURI(PRInt32 i, nsIURI **aURI)
nsCOMPtr<nsILink> link(do_QueryInterface(mLinkContent));
if (link) {
nsXPIDLCString hrefValue;
if (NS_SUCCEEDED(link->GetHrefCString(*getter_Copies(hrefValue)))) {
if (NS_SUCCEEDED(link->GetHrefUTF8(getter_Copies(hrefValue)))) {
return NS_NewURI(aURI, hrefValue, nsnull, nsnull);
}
}

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

@ -76,10 +76,10 @@ public:
NS_IMETHOD SetLinkState(nsLinkState aState) = 0;
/**
* Get a pointer to the canonical URL (i.e., fully resolved to the
* base URL) that this linkable element points to. The buffer
* returned has been allocated for and should be deleted by the
* caller.
* Get a pointer to the UTF-8 encoded canonical URL (i.e., fully
* resolved to the base URL) that this link element points to. The
* buffer returned has been allocated for and should be deleted by
* the caller.
*
* @param aBuf [out] A pointer to be filled in with a pointer to a
* null-terminated string containing the canonical URL.
@ -87,7 +87,7 @@ public:
* nsnull.
* @return NS_OK if the out pointer is filled in
*/
NS_IMETHOD GetHrefCString(char* &aBuf) = 0;
NS_IMETHOD GetHrefUTF8(char** aBuf) = 0;
};

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

@ -1403,14 +1403,15 @@ nsGenericHTMLElement::FindAndSetForm(nsIFormControl *aFormControl)
}
nsresult
nsGenericHTMLElement::HandleDOMEventForAnchors(nsIContent* aOuter,
nsIPresContext* aPresContext,
nsGenericHTMLElement::HandleDOMEventForAnchors(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
NS_PRECONDITION(nsCOMPtr<nsILink>(do_QueryInterface(this)),
"should be called only when |this| implements |nsILink|");
// Try script event handlers first
nsresult ret = nsGenericHTMLElement::HandleDOMEvent(aPresContext, aEvent,
@ -1462,16 +1463,12 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsIContent* aOuter,
aEvent->message == NS_MOUSE_EXIT_SYNTH))) &&
!(aFlags & NS_EVENT_FLAG_CAPTURE) && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT)) {
// If we're here, then aOuter should be an nsILink. We'll use the
// We'll use the equivalent of |GetHrefUTF8| on the
// nsILink interface to get a canonified URL that has been
// correctly escaped and URL-encoded for the document's charset.
nsCOMPtr<nsILink> link = do_QueryInterface(aOuter);
if (!link)
return NS_ERROR_UNEXPECTED;
nsXPIDLCString hrefCStr;
link->GetHrefCString(*getter_Copies(hrefCStr));
GetHrefUTF8ForAnchors(getter_Copies(hrefCStr));
// Only bother to handle the mouse event if there was an href
// specified.
@ -1600,6 +1597,45 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsIContent* aOuter,
return ret;
}
nsresult
nsGenericHTMLElement::GetHrefUTF8ForAnchors(char** aHref)
{
// This is used by the three nsILink implementations and
// nsHTMLStyleElement.
// Get href= attribute (relative URL).
nsAutoString relURLSpec;
if (NS_CONTENT_ATTR_HAS_VALUE ==
GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, relURLSpec)) {
// Clean up any leading or trailing whitespace
relURLSpec.Trim(" \t\n\r");
// Get base URL.
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
if (baseURL) {
// Get absolute URL.
nsCAutoString buf;
NS_MakeAbsoluteURIWithCharset(buf, relURLSpec, mDocument, baseURL,
nsHTMLUtils::IOService,
nsHTMLUtils::CharsetMgr);
*aHref = ToNewCString(buf);
}
else {
// Absolute URL is same as relative URL.
*aHref = ToNewUTF8String(relURLSpec);
}
}
else {
// Absolute URL is null to say we have no HREF.
*aHref = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP
nsGenericHTMLElement::GetNameSpaceID(PRInt32* aID) const
{

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

@ -206,14 +206,19 @@ public:
/**
* Standard anchor HandleDOMEvent, used by A, AREA and LINK (parameters
* are the same as HandleDOMEvent)
*
* Callers must hold a reference to nsHTMLUtils's global reference count.
*/
nsresult HandleDOMEventForAnchors(nsIContent* aOuter,
nsIPresContext* aPresContext,
nsresult HandleDOMEventForAnchors(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
// Used by A, AREA, LINK, and STYLE.
// Callers must hold a reference to nsHTMLUtils's global reference count.
nsresult GetHrefUTF8ForAnchors(char** aHref);
// Implementation for nsIHTMLContent
NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue,
PRBool aNotify);

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

@ -106,7 +106,7 @@ public:
// nsILink
NS_IMETHOD GetLinkState(nsLinkState &aState);
NS_IMETHOD SetLinkState(nsLinkState aState);
NS_IMETHOD GetHrefCString(char* &aBuf);
NS_IMETHOD GetHrefUTF8(char** aBuf);
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers);
@ -164,12 +164,12 @@ NS_NewHTMLAnchorElement(nsIHTMLContent** aInstancePtrResult,
nsHTMLAnchorElement::nsHTMLAnchorElement() : mLinkState(eLinkState_Unknown)
{
nsHTMLUtils::AddRef(); // for GetHrefCString
nsHTMLUtils::AddRef(); // for GetHrefUTF8
}
nsHTMLAnchorElement::~nsHTMLAnchorElement()
{
nsHTMLUtils::Release(); // for GetHrefCString
nsHTMLUtils::Release(); // for GetHrefUTF8
}
@ -350,7 +350,7 @@ nsHTMLAnchorElement::HandleDOMEvent(nsIPresContext* aPresContext,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
return HandleDOMEventForAnchors(this, aPresContext, aEvent, aDOMEvent,
return HandleDOMEventForAnchors(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}
@ -358,7 +358,7 @@ NS_IMETHODIMP
nsHTMLAnchorElement::GetHref(nsAString& aValue)
{
char *buf;
nsresult rv = GetHrefCString(buf);
nsresult rv = GetHrefUTF8(&buf);
if (NS_FAILED(rv)) return rv;
if (buf) {
aValue.Assign(NS_ConvertUTF8toUCS2(buf));
@ -661,39 +661,9 @@ nsHTMLAnchorElement::SetLinkState(nsLinkState aState)
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetHrefCString(char* &aBuf)
nsHTMLAnchorElement::GetHrefUTF8(char** aBuf)
{
// Get href= attribute (relative URL).
nsAutoString relURLSpec;
if (NS_CONTENT_ATTR_HAS_VALUE ==
GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, relURLSpec)) {
// Clean up any leading or trailing whitespace
relURLSpec.Trim(" \t\n\r");
// Get base URL.
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
if (baseURL) {
// Get absolute URL.
nsCAutoString buf;
NS_MakeAbsoluteURIWithCharset(buf, relURLSpec, mDocument, baseURL,
nsHTMLUtils::IOService,
nsHTMLUtils::CharsetMgr);
aBuf = ToNewCString(buf);
}
else {
// Absolute URL is same as relative URL.
aBuf = ToNewUTF8String(relURLSpec);
}
}
else {
// Absolute URL is null to say we have no HREF.
aBuf = nsnull;
}
return NS_OK;
return GetHrefUTF8ForAnchors(aBuf);
}
NS_IMETHODIMP

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

@ -83,7 +83,7 @@ public:
// nsILink
NS_IMETHOD GetLinkState(nsLinkState &aState);
NS_IMETHOD SetLinkState(nsLinkState aState);
NS_IMETHOD GetHrefCString(char* &aBuf);
NS_IMETHOD GetHrefUTF8(char** aBuf);
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
const nsAString& aValue,
@ -140,12 +140,12 @@ NS_NewHTMLAreaElement(nsIHTMLContent** aInstancePtrResult,
nsHTMLAreaElement::nsHTMLAreaElement()
: mLinkState(eLinkState_Unknown)
{
nsHTMLUtils::AddRef(); // for GetHrefCString
nsHTMLUtils::AddRef(); // for GetHrefUTF8
}
nsHTMLAreaElement::~nsHTMLAreaElement()
{
nsHTMLUtils::Release(); // for GetHrefCString
nsHTMLUtils::Release(); // for GetHrefUTF8
}
NS_IMPL_ADDREF_INHERITED(nsHTMLAreaElement, nsGenericElement)
@ -225,7 +225,7 @@ nsHTMLAreaElement::HandleDOMEvent(nsIPresContext* aPresContext,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
return HandleDOMEventForAnchors(this, aPresContext, aEvent, aDOMEvent,
return HandleDOMEventForAnchors(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}
@ -274,7 +274,7 @@ NS_IMETHODIMP
nsHTMLAreaElement::GetHref(nsAString& aValue)
{
char *buf;
nsresult rv = GetHrefCString(buf);
nsresult rv = GetHrefUTF8(&buf);
if (NS_FAILED(rv)) return rv;
if (buf) {
aValue.Assign(NS_ConvertASCIItoUCS2(buf));
@ -571,36 +571,7 @@ nsHTMLAreaElement::SetLinkState(nsLinkState aState)
}
NS_IMETHODIMP
nsHTMLAreaElement::GetHrefCString(char* &aBuf)
nsHTMLAreaElement::GetHrefUTF8(char** aBuf)
{
// Get href= attribute (relative URL).
nsAutoString relURLSpec;
if (GetAttr(kNameSpaceID_None, nsHTMLAtoms::href, relURLSpec) ==
NS_CONTENT_ATTR_HAS_VALUE) {
// Clean up any leading or trailing whitespace
relURLSpec.Trim(" \t\n\r");
// Get base URL.
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
if (baseURL) {
// Get absolute URL.
nsCAutoString buf;
NS_MakeAbsoluteURIWithCharset(buf, relURLSpec, mDocument, baseURL,
nsHTMLUtils::IOService, nsHTMLUtils::CharsetMgr);
aBuf = ToNewCString(buf);
}
else {
// Absolute URL is same as relative URL.
aBuf = ToNewUTF8String(relURLSpec);
}
}
else {
// Absolute URL is empty because we have no HREF.
aBuf = nsnull;
}
return NS_OK;
return GetHrefUTF8ForAnchors(aBuf);
}

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

@ -86,7 +86,7 @@ public:
// nsILink
NS_IMETHOD GetLinkState(nsLinkState &aState);
NS_IMETHOD SetLinkState(nsLinkState aState);
NS_IMETHOD GetHrefCString(char* &aBuf);
NS_IMETHOD GetHrefUTF8(char** aBuf);
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers) {
@ -226,12 +226,12 @@ NS_NewHTMLLinkElement(nsIHTMLContent** aInstancePtrResult,
nsHTMLLinkElement::nsHTMLLinkElement()
: mLinkState(eLinkState_Unknown)
{
nsHTMLUtils::AddRef(); // for GetHrefCString
nsHTMLUtils::AddRef(); // for GetHrefUTF8
}
nsHTMLLinkElement::~nsHTMLLinkElement()
{
nsHTMLUtils::Release(); // for GetHrefCString
nsHTMLUtils::Release(); // for GetHrefUTF8
}
@ -321,10 +321,10 @@ NS_IMETHODIMP
nsHTMLLinkElement::GetHref(nsAString& aValue)
{
char *buf;
nsresult rv = GetHrefCString(buf);
nsresult rv = GetHrefUTF8(&buf);
if (NS_FAILED(rv)) return rv;
if (buf) {
aValue.Assign(NS_ConvertASCIItoUCS2(buf));
aValue.Assign(NS_ConvertUTF8toUCS2(buf));
nsCRT::free(buf);
}
@ -356,7 +356,7 @@ nsHTMLLinkElement::HandleDOMEvent(nsIPresContext* aPresContext,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
return HandleDOMEventForAnchors(this, aPresContext, aEvent, aDOMEvent,
return HandleDOMEventForAnchors(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}
@ -375,40 +375,9 @@ nsHTMLLinkElement::SetLinkState(nsLinkState aState)
}
NS_IMETHODIMP
nsHTMLLinkElement::GetHrefCString(char* &aBuf)
nsHTMLLinkElement::GetHrefUTF8(char** aBuf)
{
// Get href= attribute (relative URL).
nsAutoString relURLSpec;
if (NS_CONTENT_ATTR_HAS_VALUE ==
nsGenericHTMLLeafElement::GetAttr(kNameSpaceID_None,
nsHTMLAtoms::href, relURLSpec)) {
// Clean up any leading or trailing whitespace
relURLSpec.Trim(" \t\n\r");
// Get base URL.
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
if (baseURL) {
// Get absolute URL.
nsCAutoString buf;
NS_MakeAbsoluteURIWithCharset(buf, relURLSpec, mDocument, baseURL,
nsHTMLUtils::IOService,
nsHTMLUtils::CharsetMgr);
aBuf = ToNewCString(buf);
}
else {
// Absolute URL is same as relative URL.
aBuf = ToNewUTF8String(relURLSpec);
}
}
else {
// Absolute URL is empty because we have no HREF.
aBuf = nsnull;
}
return NS_OK;
return GetHrefUTF8ForAnchors(aBuf);
}
void

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

@ -167,7 +167,6 @@ public:
nsresult SetInnerHTML(const nsAString& aInnerHTML);
protected:
nsresult GetHrefCString(char* &aBuf);
void GetStyleSheetURL(PRBool* aIsInline,
nsAString& aUrl);
void GetStyleSheetInfo(nsAString& aTitle,
@ -205,12 +204,12 @@ NS_NewHTMLStyleElement(nsIHTMLContent** aInstancePtrResult,
nsHTMLStyleElement::nsHTMLStyleElement()
{
nsHTMLUtils::AddRef(); // for GetHrefCString
nsHTMLUtils::AddRef(); // for GetHrefUTF8ForAnchors
}
nsHTMLStyleElement::~nsHTMLStyleElement()
{
nsHTMLUtils::Release(); // for GetHrefCString
nsHTMLUtils::Release(); // for GetHrefUTF8ForAnchors
}
@ -313,43 +312,6 @@ nsHTMLStyleElement::SetInnerHTML(const nsAString& aInnerHTML)
return rv;
}
nsresult
nsHTMLStyleElement::GetHrefCString(char* &aBuf)
{
// Get src= attribute (relative URL).
nsAutoString relURLSpec;
if (NS_CONTENT_ATTR_HAS_VALUE ==
nsGenericHTMLContainerElement::GetAttr(kNameSpaceID_None,
nsHTMLAtoms::src, relURLSpec)) {
// Clean up any leading or trailing whitespace
relURLSpec.Trim(" \t\n\r");
// Get base URL.
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
if (baseURL) {
// Get absolute URL.
nsCAutoString buf;
NS_MakeAbsoluteURIWithCharset(buf, relURLSpec, mDocument, baseURL,
nsHTMLUtils::IOService,
nsHTMLUtils::CharsetMgr);
aBuf = ToNewCString(buf);
}
else {
// Absolute URL is same as relative URL.
aBuf = ToNewUTF8String(relURLSpec);
}
}
else {
// Absolute URL is empty because we have no HREF.
aBuf = nsnull;
}
return NS_OK;
}
void
nsHTMLStyleElement::GetStyleSheetURL(PRBool* aIsInline,
nsAString& aUrl)
@ -367,9 +329,9 @@ nsHTMLStyleElement::GetStyleSheetURL(PRBool* aIsInline,
}
char *buf;
GetHrefCString(buf);
GetHrefUTF8ForAnchors(&buf);
if (buf) {
aUrl.Assign(NS_ConvertASCIItoUCS2(buf));
aUrl.Assign(NS_ConvertUTF8toUCS2(buf));
nsCRT::free(buf);
}
return;

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

@ -596,7 +596,7 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// bug=23209
nsXPIDLCString href;
link->GetHrefCString(*getter_Copies(href));
link->GetHrefUTF8(getter_Copies(href));
if (href) {
nsILinkHandler *linkHandler = nsnull;

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

@ -596,7 +596,7 @@ PRBool nsStyleUtil::IsHTMLLink(nsIContent *aContent, nsIAtom *aTag, nsIPresConte
// bug=23209
nsXPIDLCString href;
link->GetHrefCString(*getter_Copies(href));
link->GetHrefUTF8(getter_Copies(href));
if (href) {
nsILinkHandler *linkHandler = nsnull;