зеркало из https://github.com/mozilla/gecko-dev.git
nsObjectFrame code cleanup. b=572985 r=jst
This commit is contained in:
Родитель
64c7c1423e
Коммит
085f1f3ffa
|
@ -2547,12 +2547,12 @@ nsPluginInstanceOwner::~nsPluginInstanceOwner()
|
|||
}
|
||||
|
||||
if (mCachedAttrParamNames) {
|
||||
PR_Free(mCachedAttrParamNames);
|
||||
NS_Free(mCachedAttrParamNames);
|
||||
mCachedAttrParamNames = nsnull;
|
||||
}
|
||||
|
||||
if (mCachedAttrParamValues) {
|
||||
PR_Free(mCachedAttrParamValues);
|
||||
NS_Free(mCachedAttrParamValues);
|
||||
mCachedAttrParamValues = nsnull;
|
||||
}
|
||||
|
||||
|
@ -2628,8 +2628,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetMode(PRInt32 *aMode)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP nsPluginInstanceOwner::GetAttributes(PRUint16& n,
|
||||
const char*const*& names,
|
||||
const char*const*& values)
|
||||
const char*const*& names,
|
||||
const char*const*& values)
|
||||
{
|
||||
nsresult rv = EnsureCachedAttrParamArrays();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -3271,86 +3271,68 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetUniqueID(PRUint32 *result)
|
|||
}
|
||||
|
||||
// Cache the attributes and/or parameters of our tag into a single set
|
||||
// of arrays to be compatible with 4.x. The attributes go first,
|
||||
// of arrays to be compatible with Netscape 4.x. The attributes go first,
|
||||
// followed by a PARAM/null and then any PARAM tags. Also, hold the
|
||||
// cached array around for the duration of the life of the instance
|
||||
// because 4.x did. See bug 111008.
|
||||
|
||||
// because Netscape 4.x did. See bug 111008.
|
||||
nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
||||
{
|
||||
if (mCachedAttrParamValues)
|
||||
return NS_OK;
|
||||
|
||||
NS_PRECONDITION(((mNumCachedAttrs + mNumCachedParams) == 0) &&
|
||||
!mCachedAttrParamNames,
|
||||
!mCachedAttrParamNames,
|
||||
"re-cache of attrs/params not implemented! use the DOM "
|
||||
"node directy instead");
|
||||
"node directy instead");
|
||||
NS_ENSURE_TRUE(mObjectFrame, NS_ERROR_NULL_POINTER);
|
||||
|
||||
// first, we need to find out how much we need to allocate for our
|
||||
// arrays count up attributes
|
||||
mNumCachedAttrs = 0;
|
||||
|
||||
// Convert to a 16-bit count. Subtract 2 in case we add an extra
|
||||
// "src" or "wmode" entry below.
|
||||
PRUint32 cattrs = mContent->GetAttrCount();
|
||||
|
||||
if (cattrs < 0x0000FFFF) {
|
||||
// unsigned 32 bits to unsigned 16 bits conversion
|
||||
if (cattrs < 0x0000FFFD) {
|
||||
mNumCachedAttrs = static_cast<PRUint16>(cattrs);
|
||||
} else {
|
||||
mNumCachedAttrs = 0xFFFE; // minus one in case we add an extra "src" entry below
|
||||
mNumCachedAttrs = 0xFFFD;
|
||||
}
|
||||
|
||||
// now, we need to find all the PARAM tags that are children of us
|
||||
// however, be carefull NOT to include any PARAMs that don't have us
|
||||
// however, be careful not to include any PARAMs that don't have us
|
||||
// as a direct parent. For nested object (or applet) tags, be sure
|
||||
// to only round up the param tags that coorespond with THIS
|
||||
// instance. And also, weed out any bogus tags that may get in the
|
||||
// way, see bug 39609. Then, with any param tag that meet our
|
||||
// qualification, temporarly cache them in an nsCOMArray until
|
||||
// we can figure out what size to make our fixed char* array.
|
||||
|
||||
mNumCachedParams = 0;
|
||||
nsCOMArray<nsIDOMElement> ourParams;
|
||||
|
||||
// use the DOM to get us ALL our dependent PARAM tags, even if not
|
||||
// ours
|
||||
// Get all dependent PARAM tags, even if they are not direct children.
|
||||
nsCOMPtr<nsIDOMElement> mydomElement = do_QueryInterface(mContent);
|
||||
NS_ENSURE_TRUE(mydomElement, NS_ERROR_NO_INTERFACE);
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> allParams;
|
||||
|
||||
// Making DOM method calls can cause our frame to go away, which
|
||||
// might kill us...
|
||||
// Making DOM method calls can cause our frame to go away.
|
||||
nsCOMPtr<nsIPluginInstanceOwner> kungFuDeathGrip(this);
|
||||
|
||||
NS_NAMED_LITERAL_STRING(xhtml_ns, "http://www.w3.org/1999/xhtml");
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> allParams;
|
||||
NS_NAMED_LITERAL_STRING(xhtml_ns, "http://www.w3.org/1999/xhtml");
|
||||
mydomElement->GetElementsByTagNameNS(xhtml_ns, NS_LITERAL_STRING("param"),
|
||||
getter_AddRefs(allParams));
|
||||
|
||||
if (allParams) {
|
||||
PRUint32 numAllParams;
|
||||
allParams->GetLength(&numAllParams);
|
||||
// loop through every so called dependent PARAM tag to check if it
|
||||
// "belongs" to us
|
||||
|
||||
for (PRUint32 i = 0; i < numAllParams; i++) {
|
||||
nsCOMPtr<nsIDOMNode> pnode;
|
||||
allParams->Item(i, getter_AddRefs(pnode));
|
||||
|
||||
nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(pnode);
|
||||
if (domelement) {
|
||||
// let's NOT count up param tags that don't have a name attribute
|
||||
// Ignore params without a name attribute.
|
||||
nsAutoString name;
|
||||
domelement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
if (!name.IsEmpty()) {
|
||||
// Find the first object or applet parent.
|
||||
nsCOMPtr<nsIDOMNode> parent;
|
||||
nsCOMPtr<nsIDOMHTMLObjectElement> domobject;
|
||||
nsCOMPtr<nsIDOMHTMLAppletElement> domapplet;
|
||||
pnode->GetParentNode(getter_AddRefs(parent));
|
||||
// walk up the parents of this PARAM until we find an object
|
||||
// (or applet) tag
|
||||
|
||||
while (!(domobject || domapplet) && parent) {
|
||||
domobject = do_QueryInterface(parent);
|
||||
domapplet = do_QueryInterface(parent);
|
||||
|
@ -3358,16 +3340,13 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|||
parent->GetParentNode(getter_AddRefs(temp));
|
||||
parent = temp;
|
||||
}
|
||||
|
||||
if (domapplet || domobject) {
|
||||
if (domapplet)
|
||||
if (domapplet) {
|
||||
parent = domapplet;
|
||||
else
|
||||
}
|
||||
else {
|
||||
parent = domobject;
|
||||
|
||||
// now check to see if this PARAM's parent is us. if so,
|
||||
// cache it for later
|
||||
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> mydomNode = do_QueryInterface(mydomElement);
|
||||
if (parent == mydomNode) {
|
||||
ourParams.AppendObject(domelement);
|
||||
|
@ -3378,41 +3357,42 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|||
}
|
||||
}
|
||||
|
||||
// We're done with DOM method calls now; make sure we still have a frame.
|
||||
// We're done with DOM method calls now. Make sure we still have a frame.
|
||||
NS_ENSURE_TRUE(mObjectFrame, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
PRUint32 cparams = ourParams.Count(); // unsigned 32 bits to unsigned 16 bits conversion
|
||||
if (cparams < 0x0000FFFF)
|
||||
// Convert to a 16-bit count.
|
||||
PRUint32 cparams = ourParams.Count();
|
||||
if (cparams < 0x0000FFFF) {
|
||||
mNumCachedParams = static_cast<PRUint16>(cparams);
|
||||
else
|
||||
} else {
|
||||
mNumCachedParams = 0xFFFF;
|
||||
}
|
||||
|
||||
PRUint16 numRealAttrs = mNumCachedAttrs;
|
||||
|
||||
// Some plugins were never written to understand the "data" attribute of the OBJECT tag.
|
||||
// Real and WMP will not play unless they find a "src" attribute, see bug 152334.
|
||||
// Nav 4.x would simply replace the "data" with "src". Because some plugins correctly
|
||||
// look for "data", lets instead copy the "data" attribute and add another entry
|
||||
// to the bottom of the array if there isn't already a "src" specified.
|
||||
PRInt16 numRealAttrs = mNumCachedAttrs;
|
||||
nsAutoString data;
|
||||
if (mContent->Tag() == nsGkAtoms::object
|
||||
&& !mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::src)
|
||||
&& mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, data)) {
|
||||
mNumCachedAttrs++;
|
||||
if (mContent->Tag() == nsGkAtoms::object &&
|
||||
!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
|
||||
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, data)) {
|
||||
mNumCachedAttrs++;
|
||||
}
|
||||
|
||||
// "plugins.force.wmode" preference is forcing wmode type for plugins
|
||||
// possible values - "opaque", "transparent", "windowed"
|
||||
nsAdoptingCString wmodeType = nsContentUtils::GetCharPref("plugins.force.wmode");
|
||||
if (!wmodeType.IsEmpty())
|
||||
if (!wmodeType.IsEmpty()) {
|
||||
mNumCachedAttrs++;
|
||||
// now lets make the arrays
|
||||
mCachedAttrParamNames = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);
|
||||
NS_ENSURE_TRUE(mCachedAttrParamNames, NS_ERROR_OUT_OF_MEMORY);
|
||||
mCachedAttrParamValues = (char **)PR_Calloc(sizeof(char *) * (mNumCachedAttrs + 1 + mNumCachedParams), 1);
|
||||
NS_ENSURE_TRUE(mCachedAttrParamValues, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
// let's fill in our attributes
|
||||
PRInt16 c = 0;
|
||||
mCachedAttrParamNames = (char**)NS_Alloc(sizeof(char*) * (mNumCachedAttrs + 1 + mNumCachedParams));
|
||||
NS_ENSURE_TRUE(mCachedAttrParamNames, NS_ERROR_OUT_OF_MEMORY);
|
||||
mCachedAttrParamValues = (char**)NS_Alloc(sizeof(char*) * (mNumCachedAttrs + 1 + mNumCachedParams));
|
||||
NS_ENSURE_TRUE(mCachedAttrParamValues, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Some plugins (eg Flash, see bug 234675.) are actually sensitive to the
|
||||
// attribute order. So we want to make sure we give the plugin the
|
||||
|
@ -3420,7 +3400,7 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|||
// other browsers. Now in HTML, the storage order is the reverse of the
|
||||
// source order, while in XML and XHTML it's the same as the source order
|
||||
// (see the AddAttributes functions in the HTML and XML content sinks).
|
||||
PRInt16 start, end, increment;
|
||||
PRInt32 start, end, increment;
|
||||
if (mContent->IsHTML() &&
|
||||
mContent->IsInHTMLDocument()) {
|
||||
// HTML. Walk attributes in reverse order.
|
||||
|
@ -3433,12 +3413,19 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|||
end = numRealAttrs;
|
||||
increment = 1;
|
||||
}
|
||||
|
||||
// Set to the next slot to fill in name and value cache arrays.
|
||||
PRUint32 nextAttrParamIndex = 0;
|
||||
|
||||
// Potentially add WMODE attribute.
|
||||
if (!wmodeType.IsEmpty()) {
|
||||
mCachedAttrParamNames [c] = ToNewUTF8String(NS_LITERAL_STRING("wmode"));
|
||||
mCachedAttrParamValues[c] = ToNewUTF8String(NS_ConvertUTF8toUTF16(wmodeType));
|
||||
c++;
|
||||
mCachedAttrParamNames [nextAttrParamIndex] = ToNewUTF8String(NS_LITERAL_STRING("wmode"));
|
||||
mCachedAttrParamValues[nextAttrParamIndex] = ToNewUTF8String(NS_ConvertUTF8toUTF16(wmodeType));
|
||||
nextAttrParamIndex++;
|
||||
}
|
||||
for (PRInt16 index = start; index != end; index += increment) {
|
||||
|
||||
// Add attribute name/value pairs.
|
||||
for (PRInt32 index = start; index != end; index += increment) {
|
||||
const nsAttrName* attrName = mContent->GetAttrNameAt(index);
|
||||
nsIAtom* atom = attrName->LocalName();
|
||||
nsAutoString value;
|
||||
|
@ -3448,49 +3435,52 @@ nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
|
|||
|
||||
FixUpURLS(name, value);
|
||||
|
||||
mCachedAttrParamNames [c] = ToNewUTF8String(name);
|
||||
mCachedAttrParamValues[c] = ToNewUTF8String(value);
|
||||
c++;
|
||||
mCachedAttrParamNames [nextAttrParamIndex] = ToNewUTF8String(name);
|
||||
mCachedAttrParamValues[nextAttrParamIndex] = ToNewUTF8String(value);
|
||||
nextAttrParamIndex++;
|
||||
}
|
||||
|
||||
// if the conditions above were met, copy the "data" attribute to a "src" array entry
|
||||
if (data.Length()) {
|
||||
mCachedAttrParamNames [mNumCachedAttrs-1] = ToNewUTF8String(NS_LITERAL_STRING("SRC"));
|
||||
mCachedAttrParamValues[mNumCachedAttrs-1] = ToNewUTF8String(data);
|
||||
// Potentially add SRC attribute.
|
||||
if (!data.IsEmpty()) {
|
||||
mCachedAttrParamNames [nextAttrParamIndex] = ToNewUTF8String(NS_LITERAL_STRING("SRC"));
|
||||
mCachedAttrParamValues[nextAttrParamIndex] = ToNewUTF8String(data);
|
||||
nextAttrParamIndex++;
|
||||
}
|
||||
|
||||
// add our PARAM and null separator
|
||||
mCachedAttrParamNames [mNumCachedAttrs] = ToNewUTF8String(NS_LITERAL_STRING("PARAM"));
|
||||
mCachedAttrParamValues[mNumCachedAttrs] = nsnull;
|
||||
// Add PARAM and null separator.
|
||||
mCachedAttrParamNames [nextAttrParamIndex] = ToNewUTF8String(NS_LITERAL_STRING("PARAM"));
|
||||
mCachedAttrParamValues[nextAttrParamIndex] = nsnull;
|
||||
nextAttrParamIndex++;
|
||||
|
||||
// now fill in the PARAM name/value pairs from the cached DOM nodes
|
||||
c = 0;
|
||||
for (PRInt16 idx = 0; idx < mNumCachedParams; idx++) {
|
||||
nsIDOMElement* param = ourParams.ObjectAt(idx);
|
||||
if (param) {
|
||||
nsAutoString name;
|
||||
nsAutoString value;
|
||||
param->GetAttribute(NS_LITERAL_STRING("name"), name); // check for empty done above
|
||||
param->GetAttribute(NS_LITERAL_STRING("value"), value);
|
||||
|
||||
FixUpURLS(name, value);
|
||||
|
||||
/*
|
||||
* According to the HTML 4.01 spec, at
|
||||
* http://www.w3.org/TR/html4/types.html#type-cdata
|
||||
* ''User agents may ignore leading and trailing
|
||||
* white space in CDATA attribute values (e.g., "
|
||||
* myval " may be interpreted as "myval"). Authors
|
||||
* should not declare attribute values with
|
||||
* leading or trailing white space.''
|
||||
* However, do not trim consecutive spaces as in bug 122119
|
||||
*/
|
||||
name.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);
|
||||
value.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);
|
||||
mCachedAttrParamNames [mNumCachedAttrs + 1 + c] = ToNewUTF8String(name);
|
||||
mCachedAttrParamValues[mNumCachedAttrs + 1 + c] = ToNewUTF8String(value);
|
||||
c++; // rules!
|
||||
// Add PARAM name/value pairs.
|
||||
for (PRUint16 i = 0; i < mNumCachedParams; i++) {
|
||||
nsIDOMElement* param = ourParams.ObjectAt(i);
|
||||
if (!param) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
nsAutoString value;
|
||||
param->GetAttribute(NS_LITERAL_STRING("name"), name); // check for empty done above
|
||||
param->GetAttribute(NS_LITERAL_STRING("value"), value);
|
||||
|
||||
FixUpURLS(name, value);
|
||||
|
||||
/*
|
||||
* According to the HTML 4.01 spec, at
|
||||
* http://www.w3.org/TR/html4/types.html#type-cdata
|
||||
* ''User agents may ignore leading and trailing
|
||||
* white space in CDATA attribute values (e.g., "
|
||||
* myval " may be interpreted as "myval"). Authors
|
||||
* should not declare attribute values with
|
||||
* leading or trailing white space.''
|
||||
* However, do not trim consecutive spaces as in bug 122119
|
||||
*/
|
||||
name.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);
|
||||
value.Trim(" \n\r\t\b", PR_TRUE, PR_TRUE, PR_FALSE);
|
||||
mCachedAttrParamNames [nextAttrParamIndex] = ToNewUTF8String(name);
|
||||
mCachedAttrParamValues[nextAttrParamIndex] = ToNewUTF8String(value);
|
||||
nextAttrParamIndex++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
Загрузка…
Ссылка в новой задаче