Bug 516906: Remove XLink support from nsXMLElement. r/sr=jst

This commit is contained in:
Jonas Sicking 2009-10-24 21:33:47 -07:00
parent 17edc7e1dc
commit 1d81e23e8d
7 changed files with 20 additions and 299 deletions

View File

@ -45,57 +45,46 @@
#define NS_HTML_STYLE_PROPERTY_NOT_THERE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 2)
/** Error codes for MaybeTriggerAutoLink */
#define NS_XML_AUTOLINK_EMBED \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 3)
#define NS_XML_AUTOLINK_NEW \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 4)
#define NS_XML_AUTOLINK_REPLACE \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 5)
#define NS_XML_AUTOLINK_UNDEFINED \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 6)
/** Error codes for nsScriptLoader */
#define NS_CONTENT_SCRIPT_IS_EVENTHANDLER \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 7)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 3)
/** Error codes for image loading */
#define NS_ERROR_IMAGE_SRC_CHANGED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 8)
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 4)
#define NS_ERROR_IMAGE_BLOCKED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 9)
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 5)
/** Error codes for content policy blocking */
#define NS_ERROR_CONTENT_BLOCKED \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 10)
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 6)
#define NS_ERROR_CONTENT_BLOCKED_SHOW_ALT \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 11)
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 7)
/** Success variations of content policy blocking */
#define NS_CONTENT_BLOCKED \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 12)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 8)
#define NS_CONTENT_BLOCKED_SHOW_ALT \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 13)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 9)
#define NS_PROPTABLE_PROP_NOT_THERE \
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 14)
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_CONTENT, 10)
#define NS_PROPTABLE_PROP_OVERWRITTEN \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 15)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 11)
/* Error codes for FindBroadcaster in nsXULDocument.cpp */
#define NS_FINDBROADCASTER_NOT_FOUND \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 16)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 12)
#define NS_FINDBROADCASTER_FOUND \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 17)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 13)
#define NS_FINDBROADCASTER_AWAIT_OVERLAYS \
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 18)
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_CONTENT, 14)
#endif // nsContentErrors_h___

View File

@ -70,10 +70,10 @@ enum nsLinkState {
};
// IID for the nsIContent interface
// d510382f-f5eb-48bb-9ad9-b3dc4806faaf
// c726e716-a4be-4202-8a5e-32d0525903e8
#define NS_ICONTENT_IID \
{ 0xd510382f, 0xf5eb, 0x48bb, \
{ 0x9a, 0xd9, 0xb3, 0xdc, 0x48, 0x06, 0xfa, 0xaf } }
{ 0xc726e716, 0xa4be, 0x4202, \
{ 0x8a, 0x5e, 0x32, 0xd0, 0x52, 0x59, 0x03, 0xe8 } }
/**
* A node of content in a document's content model. This interface
@ -673,26 +673,6 @@ public:
return nsnull;
}
/**
* Give this element a chance to fire links that should be fired
* automatically when loaded. If the element was an autoloading link
* and it was successfully handled, we will throw special nsresult values.
*
* @param aShell the current doc shell (to possibly load the link on)
* @throws NS_OK if nothing happened
* @throws NS_XML_AUTOLINK_EMBED if the caller is loading the link embedded
* @throws NS_XML_AUTOLINK_NEW if the caller is loading the link in a new
* window
* @throws NS_XML_AUTOLINK_REPLACE if it is loading a link that will replace
* the current window (and thus the caller must stop parsing)
* @throws NS_XML_AUTOLINK_UNDEFINED if it is loading in any other way--in
* which case, the caller should stop parsing as well.
*/
virtual nsresult MaybeTriggerAutoLink(nsIDocShell *aShell)
{
return NS_OK;
}
/**
* This method is called when the parser finishes creating the element. This
* particularly means that it has done everything you would expect it to have

View File

@ -37,12 +37,6 @@
* ***** END LICENSE BLOCK ***** */
#include "nsXMLElement.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRefreshURI.h"
#include "nsPresContext.h"
#include "nsContentErrors.h"
#include "nsIDocument.h"
nsresult
NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
@ -57,12 +51,6 @@ NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
return NS_OK;
}
nsXMLElement::nsXMLElement(nsINodeInfo *aNodeInfo)
: nsGenericElement(aNodeInfo)
{
}
// QueryInterface implementation for nsXMLElement
NS_INTERFACE_TABLE_HEAD(nsXMLElement)
NS_NODE_OFFSET_AND_INTERFACE_TABLE_BEGIN(nsXMLElement)
@ -77,199 +65,4 @@ NS_ELEMENT_INTERFACE_MAP_END
NS_IMPL_ADDREF_INHERITED(nsXMLElement, nsGenericElement)
NS_IMPL_RELEASE_INHERITED(nsXMLElement, nsGenericElement)
static nsresult
DocShellToPresContext(nsIDocShell *aShell, nsPresContext **aPresContext)
{
*aPresContext = nsnull;
nsresult rv;
nsCOMPtr<nsIDocShell> ds = do_QueryInterface(aShell,&rv);
if (NS_FAILED(rv))
return rv;
return ds->GetPresContext(aPresContext);
}
nsresult
nsXMLElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
nsresult rv = nsGenericElement::PreHandleEvent(aVisitor);
NS_ENSURE_SUCCESS(rv, rv);
return PreHandleEventForLinks(aVisitor);
}
nsresult
nsXMLElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
{
return PostHandleEventForLinks(aVisitor);
}
nsresult
nsXMLElement::MaybeTriggerAutoLink(nsIDocShell *aShell)
{
NS_ENSURE_ARG_POINTER(aShell);
// We require an xlink:href, xlink:type="simple" and xlink:actuate="onLoad"
// XXX: as of XLink 1.1, elements will be links even without xlink:type set
if (!HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) ||
!AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
nsGkAtoms::simple, eCaseMatters) ||
!AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::actuate,
nsGkAtoms::onLoad, eCaseMatters)) {
return NS_OK;
}
// Disable in Mail/News for now. We may want a pref to control
// this at some point.
nsCOMPtr<nsIDocShellTreeItem> docShellItem = do_QueryInterface(aShell);
if (docShellItem) {
nsCOMPtr<nsIDocShellTreeItem> rootItem;
docShellItem->GetRootTreeItem(getter_AddRefs(rootItem));
nsCOMPtr<nsIDocShell> docshell = do_QueryInterface(rootItem);
if (docshell) {
PRUint32 appType;
if (NS_SUCCEEDED(docshell->GetAppType(&appType)) &&
appType == nsIDocShell::APP_TYPE_MAIL) {
return NS_OK;
}
}
}
// Get absolute URI
nsCOMPtr<nsIURI> absURI;
nsAutoString href;
GetAttr(kNameSpaceID_XLink, nsGkAtoms::href, href);
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(absURI), href,
GetOwnerDoc(), baseURI);
if (!absURI) {
return NS_OK;
}
// Check that the link's URI isn't the same as its document's URI, or else
// we'll recursively load the document forever (possibly in new windows!)
PRBool isDocURI;
absURI->Equals(GetOwnerDoc()->GetDocumentURI(), &isDocURI);
if (isDocURI) {
return NS_OK;
}
// Get target
nsAutoString target;
nsresult special_rv = GetLinkTargetAndAutoType(target);
// Ignore this link if xlink:show has a value we don't implement
if (NS_FAILED(special_rv)) return NS_OK;
// Attempt to load the URI
nsCOMPtr<nsPresContext> pc;
nsresult rv = DocShellToPresContext(aShell, getter_AddRefs(pc));
NS_ENSURE_SUCCESS(rv, rv);
if (pc) {
nsContentUtils::TriggerLink(this, pc, absURI, target, PR_TRUE, PR_FALSE);
}
return special_rv; // return GetLinkTargetAndAutoType's special rv!
}
PRBool
nsXMLElement::IsFocusable(PRInt32 *aTabIndex)
{
nsCOMPtr<nsIURI> absURI;
if (IsLink(getter_AddRefs(absURI))) {
if (aTabIndex) {
*aTabIndex = ((sTabFocusModel & eTabFocus_linksMask) == 0 ? -1 : 0);
}
return PR_TRUE;
}
if (aTabIndex) {
*aTabIndex = -1;
}
return PR_FALSE;
}
PRBool
nsXMLElement::IsLink(nsIURI** aURI) const
{
NS_PRECONDITION(aURI, "Must provide aURI out param");
// To be an XLink for styling and interaction purposes, we require:
//
// xlink:href - must be set
// xlink:type - must be set to "simple"
// xlink:_moz_target - must be set, OR
// xlink:show - must be unset or set to "", "new" or "replace"
// xlink:actuate - must be unset or set to "" or "onRequest"
//
// For any other values, we're either not a *clickable* XLink, or the end
// result is poorly specified. Either way, we return PR_FALSE.
static nsIContent::AttrValuesArray sShowVals[] =
{ &nsGkAtoms::_empty, &nsGkAtoms::_new, &nsGkAtoms::replace, nsnull };
static nsIContent::AttrValuesArray sActuateVals[] =
{ &nsGkAtoms::_empty, &nsGkAtoms::onRequest, nsnull };
// Optimization: check for href first for early return
const nsAttrValue* href = mAttrsAndChildren.GetAttr(nsGkAtoms::href,
kNameSpaceID_XLink);
if (href &&
AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
nsGkAtoms::simple, eCaseMatters) &&
(HasAttr(kNameSpaceID_XLink, nsGkAtoms::_moz_target) ||
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
sShowVals, eCaseMatters) !=
nsIContent::ATTR_VALUE_NO_MATCH) &&
FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate,
sActuateVals, eCaseMatters) !=
nsIContent::ATTR_VALUE_NO_MATCH) {
// Get absolute URI
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
nsContentUtils::NewURIWithDocumentCharset(aURI, href->GetStringValue(),
GetOwnerDoc(), baseURI);
return !!*aURI; // must promise out param is non-null if we return true
}
*aURI = nsnull;
return PR_FALSE;
}
void
nsXMLElement::GetLinkTarget(nsAString& aTarget)
{
GetLinkTargetAndAutoType(aTarget);
}
nsresult
nsXMLElement::GetLinkTargetAndAutoType(nsAString& aTarget)
{
// Mozilla extension xlink:_moz_target overrides xlink:show
if (GetAttr(kNameSpaceID_XLink, nsGkAtoms::_moz_target, aTarget)) {
return aTarget.IsEmpty() ? NS_XML_AUTOLINK_REPLACE : NS_OK;
}
// Try xlink:show if no xlink:_moz_target
GetAttr(kNameSpaceID_XLink, nsGkAtoms::show, aTarget);
if (aTarget.IsEmpty()) {
return NS_XML_AUTOLINK_UNDEFINED;
}
if (aTarget.EqualsLiteral("new")) {
aTarget.AssignLiteral("_blank");
return NS_XML_AUTOLINK_NEW;
}
if (aTarget.EqualsLiteral("replace")) {
aTarget.Truncate();
return NS_XML_AUTOLINK_REPLACE;
}
// xlink:show="embed" isn't handled by this code path
aTarget.Truncate();
return NS_ERROR_FAILURE;
}
NS_IMPL_ELEMENT_CLONE(nsXMLElement)

View File

@ -42,13 +42,14 @@
#include "nsIDOMElement.h"
#include "nsGenericElement.h"
class nsIDocShell;
class nsXMLElement : public nsGenericElement,
public nsIDOMElement
{
public:
nsXMLElement(nsINodeInfo *aNodeInfo);
nsXMLElement(nsINodeInfo *aNodeInfo)
: nsGenericElement(aNodeInfo)
{
}
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
@ -60,20 +61,7 @@ public:
NS_FORWARD_NSIDOMELEMENT(nsGenericElement::)
// nsINode interface methods
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
// nsIContent
virtual PRBool IsLink(nsIURI** aURI) const;
virtual nsresult MaybeTriggerAutoLink(nsIDocShell *aShell);
virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull);
// nsGenericElement specializations
virtual void GetLinkTarget(nsAString& aTarget);
// Get target plus a special rv for MaybeTriggerAutoLink's caller
nsresult GetLinkTargetAndAutoType(nsAString& aTarget);
};
#endif // nsXMLElement_h___

View File

@ -139,8 +139,7 @@ NS_NewXMLContentSink(nsIXMLContentSink** aResult,
nsXMLContentSink::nsXMLContentSink()
: mConstrainSize(PR_TRUE),
mPrettyPrintXML(PR_TRUE),
mAllowAutoXLinks(PR_TRUE)
mPrettyPrintXML(PR_TRUE)
{
}
@ -980,7 +979,6 @@ nsXMLContentSink::SetDocElement(PRInt32 aNameSpaceID,
if (mPrettyPrintXML) {
// In this case, disable script execution, stylesheet
// loading, and auto XLinks since we plan to prettyprint.
mAllowAutoXLinks = PR_FALSE;
mDocument->ScriptLoader()->SetEnabled(PR_FALSE);
if (mCSSLoader) {
mCSSLoader->SetEnabled(PR_FALSE);
@ -1539,17 +1537,6 @@ nsXMLContentSink::AddAttributes(const PRUnichar** aAtts,
aAtts += 2;
}
// Give autoloading links a chance to fire
if (mDocShell && mAllowAutoXLinks) {
nsresult rv = aContent->MaybeTriggerAutoLink(mDocShell);
if (rv == NS_XML_AUTOLINK_REPLACE ||
rv == NS_XML_AUTOLINK_UNDEFINED) {
// If we do not terminate the parse, we just keep generating link trigger
// events. We want to parse only up to the first replace link, and stop.
mParser->Terminate();
}
}
return NS_OK;
}

View File

@ -207,10 +207,8 @@ protected:
PRUint8 mPrettyPrintHasSpecialRoot : 1;
PRUint8 mPrettyPrintHasFactoredElements : 1;
PRUint8 mHasProcessedBase : 1;
PRUint8 mAllowAutoXLinks : 1;
PRUint8 mPrettyPrinting : 1; // True if we called PrettyPrint() and it
// decided we should in fact prettyprint.
PRUint8 unused : 1; // bits available if someone needs one
nsTArray<StackNode> mContentStack;

View File

@ -310,20 +310,6 @@ nsHtml5TreeBuilder::elementPushed(PRInt32 aNamespace, nsIAtom* aName, nsIContent
return;
}
}
#if 0
else {
nsIDocShell* docShell = parser->GetDocShell();
if (docShell) {
nsresult rv = aElement->MaybeTriggerAutoLink(docShell);
if (rv == NS_XML_AUTOLINK_REPLACE ||
rv == NS_XML_AUTOLINK_UNDEFINED) {
// If we do not terminate the parse, we just keep generating link trigger
// events. We want to parse only up to the first replace link, and stop.
parser->Terminate();
}
}
}
#endif
mExecutor->MaybeSuspend();
}