diff --git a/mozilla/extensions/schema-validation/src/Makefile.in b/mozilla/extensions/schema-validation/src/Makefile.in index e77f67cabf3..f59630a86af 100644 --- a/mozilla/extensions/schema-validation/src/Makefile.in +++ b/mozilla/extensions/schema-validation/src/Makefile.in @@ -55,7 +55,6 @@ EXPORT_LIBRARY = 1 MODULE_NAME = schemavalidation endif GRE_MODULE = 1 -MOZILLA_INTERNAL_API = 1 REQUIRES = xpcom \ string \ @@ -80,12 +79,14 @@ CPPSRCS = \ nsSchemaValidatorUtils.cpp \ $(NULL) + EXTRA_DSO_LDOPTS = \ $(LIBS_DIR) \ - $(MOZ_COMPONENT_LIBS) \ + $(MOZ_COMPONENT_NSPR_LIBS) \ $(ZLIB_LIBS) \ $(MOZ_JS_LIBS) \ - $(MOZ_UNICHARUTIL_LIBS) \ + $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_external_s.$(LIB_SUFFIX) \ + $(XPCOM_GLUE_LDOPTS) \ $(NULL) EXTRA_COMPONENTS = nsSchemaValidatorRegexp.js diff --git a/mozilla/extensions/schema-validation/src/nsSchemaDuration.cpp b/mozilla/extensions/schema-validation/src/nsSchemaDuration.cpp index f452d11d509..7da67615475 100644 --- a/mozilla/extensions/schema-validation/src/nsSchemaDuration.cpp +++ b/mozilla/extensions/schema-validation/src/nsSchemaDuration.cpp @@ -39,8 +39,7 @@ #include "nsSchemaDuration.h" // string includes -#include "nsReadableUtils.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsUnicharUtils.h" // XPCOM includes diff --git a/mozilla/extensions/schema-validation/src/nsSchemaValidator.cpp b/mozilla/extensions/schema-validation/src/nsSchemaValidator.cpp index ab8d7efff03..b7beeed5bb3 100644 --- a/mozilla/extensions/schema-validation/src/nsSchemaValidator.cpp +++ b/mozilla/extensions/schema-validation/src/nsSchemaValidator.cpp @@ -53,8 +53,7 @@ #include "nsIAttribute.h" // string includes -#include "nsReadableUtils.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsUnicharUtils.h" // XPCOM includes @@ -78,6 +77,7 @@ #include "prtime.h" #include "plbase64.h" #include +#include "nsIAtomService.h" #define NS_SCHEMA_1999_NAMESPACE "http://www.w3.org/1999/XMLSchema" #define NS_SCHEMA_2001_NAMESPACE "http://www.w3.org/2001/XMLSchema" @@ -298,10 +298,15 @@ nsSchemaValidator::ValidateAgainstType(nsIDOMNode* aElement, nsCOMPtr content = do_QueryInterface(domNode3); NS_ENSURE_STATE(content); - // we have to be really carefull to set the destructor function correctly. + // we have to be really careful to set the destructor function correctly. // this also has to be a pointer to a variant - nsCOMPtr key = do_GetAtom("xsdtype"); - NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr atomServ = + do_GetService(NS_ATOMSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr key; + rv = atomServ->GetAtomUTF8("xsdtype", getter_AddRefs(key)); + NS_ENSURE_SUCCESS(rv, rv); nsIVariant *pVariant = holder; NS_IF_ADDREF(pVariant); @@ -1508,7 +1513,7 @@ nsSchemaValidator::ValidateListSimpletype(const nsAString & aNodeValue, if (facetsValid) { nsAutoString tmp; for (PRUint32 i=0; i < count; ++i) { - CopyUTF8toUTF16(stringArray[i]->get(), tmp); + CopyUTF8toUTF16(*stringArray[i], tmp); LOG((" Validating List Item (%d): %s", i, NS_ConvertUTF16toUTF8(tmp).get())); rv = ValidateSimpletype(tmp, listSimpleType, &isValid); @@ -1755,21 +1760,20 @@ nsSchemaValidator::IsValidSchemaGDay(const nsAString & aNodeValue, int dayInt; // iterate over the string and parse/validate - nsAString::const_iterator start, end; - aNodeValue.BeginReading(start); - aNodeValue.EndReading(end); + const PRUnichar *start, *end; + aNodeValue.BeginReading(&start, &end); nsAutoString nodeValue(aNodeValue); // validate the ---DD part - PRBool isValid = Substring(start.get(), start.get()+3).EqualsLiteral("---") && - IsValidSchemaGType(Substring(start.get()+3, start.get()+5), + PRBool isValid = Substring(start, start + 3).EqualsLiteral("---") && + IsValidSchemaGType(Substring(start + 3, start + 5), 1, 31, &dayInt); if (isValid) { tzSign = nodeValue.CharAt(5); if (strLength == 6) { isValid &= (tzSign == 'Z'); } else if (strLength == 11) { - const nsAString &tz = Substring(start.get()+6, end.get()); + const nsAString &tz = Substring(start + 6, end); isValid &= ((tzSign == '+' || tzSign == '-') && nsSchemaValidatorUtils::ParseSchemaTimeZone(tz, timezoneHour, @@ -1878,21 +1882,20 @@ nsSchemaValidator::IsValidSchemaGMonth(const nsAString & aNodeValue, PRUnichar tzSign = 0; int monthInt; - nsAString::const_iterator start, end; - aNodeValue.BeginReading(start); - aNodeValue.EndReading(end); + const PRUnichar *start, *end; + aNodeValue.BeginReading(&start, &end); nsAutoString nodeValue(aNodeValue); // validate the --MM part - PRBool isValid = Substring(start.get(), start.get()+2).EqualsLiteral("--") && - IsValidSchemaGType(Substring(start.get()+2, start.get()+4), + PRBool isValid = Substring(start, start + 2).EqualsLiteral("--") && + IsValidSchemaGType(Substring(start + 2, start + 4), 1, 12, &monthInt); if (isValid) { tzSign = nodeValue.CharAt(4); if (strLength == 5) { isValid &= (tzSign == 'Z'); } else if (strLength == 10) { - const nsAString &tz = Substring(start.get()+5, end.get()); + const nsAString &tz = Substring(start + 5, end); isValid &= ((tzSign == '+' || tzSign == '-') && nsSchemaValidatorUtils::ParseSchemaTimeZone(tz, timezoneHour, @@ -1983,10 +1986,9 @@ nsSchemaValidator::IsValidSchemaGYear(const nsAString & aNodeValue, char timezoneMinute[3] = ""; PRUnichar tzSign = 0; - nsAString::const_iterator start, end, buffStart; - aNodeValue.BeginReading(start); - aNodeValue.BeginReading(buffStart); - aNodeValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aNodeValue.BeginReading(&start, &end); + aNodeValue.BeginReading(&buffStart); PRUint32 state = 0; PRUint32 buffLength = 0, yearLength = 0; PRBool done = PR_FALSE; @@ -2142,10 +2144,9 @@ nsSchemaValidator::IsValidSchemaGYearMonth(const nsAString & aNodeValue, // GYearMonth looks like this: (-)CCYY-MM(Z|(+|-)hh:mm) PRBool isValid = PR_FALSE; - nsAString::const_iterator start, end, buffStart; - aNodeValue.BeginReading(start); - aNodeValue.BeginReading(buffStart); - aNodeValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aNodeValue.BeginReading(&start, &end); + aNodeValue.BeginReading(&buffStart); PRUint32 buffLength = 0; PRBool done = PR_FALSE; @@ -2265,10 +2266,9 @@ nsSchemaValidator::IsValidSchemaGMonthDay(const nsAString & aNodeValue, // GMonthDay looks like this: --MM-DD(Z|(+|-)hh:mm) PRBool isValid = PR_FALSE; - nsAString::const_iterator start, end, buffStart; - aNodeValue.BeginReading(start); - aNodeValue.BeginReading(buffStart); - aNodeValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aNodeValue.BeginReading(&start, &end); + aNodeValue.BeginReading(&buffStart); PRUint32 buffLength = 0; PRUint32 state = 0; PRBool done = PR_FALSE; @@ -2296,7 +2296,8 @@ nsSchemaValidator::IsValidSchemaGMonthDay(const nsAString & aNodeValue, nsAutoString month; month.AppendLiteral("--"); - month.Append(Substring(buffStart, start.advance(2))); + start += 2; + month.Append(Substring(buffStart, start)); isValid = IsValidSchemaGMonth(month, aMonthDay ? &aMonthDay->gMonth : nsnull); @@ -2425,12 +2426,18 @@ nsSchemaValidator::IsValidSchemaTime(const nsAString & aNodeValue, PRBool isValid = PR_FALSE; nsAutoString timeString(aNodeValue); + PRUint32 len = timeString.Length(); + PRUnichar end = 0; + if (len > 0) { + // length counts null terminator + end = timeString.CharAt(len - 1); + } // if no timezone ([+/-]hh:ss) or no timezone Z, add a Z to the end so that // nsSchemaValidatorUtils::ParseSchemaTime can parse it if ((timeString.FindChar('-') == kNotFound) && (timeString.FindChar('+') == kNotFound) && - timeString.Last() != 'Z'){ + end != 'Z') { timeString.Append('Z'); } @@ -3031,11 +3038,28 @@ nsSchemaValidator::IsValidSchemaFloat(const nsAString & aNodeValue, float *aResult) { PRBool isValid = PR_TRUE; - nsAutoString temp(aNodeValue); + nsresult rv = NS_ERROR_ILLEGAL_VALUE; + float floatValue = 0.0f; - PRInt32 errorCode; - float floatValue = temp.ToFloat(&errorCode); - if (NS_FAILED(errorCode)) { + // took most of this float conversion code from nsCString::ToFloat + // which isn't frozen so we can't use it directly + NS_LossyConvertUTF16toASCII convertedValue(aNodeValue); + const char *value = convertedValue.get(); + PRUint32 length = strlen(value); + if (length > 0) { + char *conv_stopped; + + floatValue = (float)PR_strtod(value, &conv_stopped); + if (conv_stopped == value+length) { + rv = NS_OK; + } else { + // the scan failed somewhere before completion + rv = NS_ERROR_ILLEGAL_VALUE; + floatValue = 0.0f; + } + } + + if (NS_FAILED(rv)) { // floats may be INF, -INF and NaN if (aNodeValue.EqualsLiteral("INF")) { floatValue = FLT_MAX; @@ -3046,9 +3070,7 @@ nsSchemaValidator::IsValidSchemaFloat(const nsAString & aNodeValue, } } - if (aResult) - *aResult = floatValue; - + *aResult = floatValue; return isValid; } @@ -3344,12 +3366,10 @@ nsSchemaValidator::CompareFractionStrings(const nsAString & aString1, compareString2.Assign(aString1); } - nsAString::const_iterator start1, end1, start2, end2; - compareString1.BeginReading(start1); - compareString1.EndReading(end1); + const PRUnichar *start1, *end1, *start2, *end2; + compareString1.BeginReading(&start1, &end1); - compareString2.BeginReading(start2); - compareString2.EndReading(end2); + compareString2.BeginReading(&start2, &end2); PRBool done = PR_FALSE; @@ -3545,7 +3565,7 @@ nsSchemaValidator::IsValidSchemaQName(const nsAString & aString) NS_ENSURE_SUCCESS(rv, PR_FALSE); const PRUnichar *colon; - const nsAFlatString& qName = PromiseFlatString(aString); + const nsString& qName = PromiseFlatString(aString); rv = parserService->CheckQName(qName, PR_TRUE, &colon); if (NS_SUCCEEDED(rv)) { isValid = PR_TRUE; @@ -3611,9 +3631,8 @@ nsSchemaValidator::IsValidSchemaHexBinary(const nsAString & aString) if (length % 2 != 0) return PR_FALSE; - nsAString::const_iterator start, end; - aString.BeginReading(start); - aString.EndReading(end); + const PRUnichar *start, *end; + aString.BeginReading(&start, &end); PRBool isValid = PR_TRUE; @@ -4290,13 +4309,12 @@ nsSchemaValidator::GetElementXsiType(nsIDOMNode* aNode, do_GetService("@mozilla.org/parser/parser-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); - const nsAFlatString& qName = PromiseFlatString(typeAttribute); + const nsString& qName = PromiseFlatString(typeAttribute); const PRUnichar *colon; rv = parserService->CheckQName(qName, PR_TRUE, &colon); NS_ENSURE_SUCCESS(rv, rv); - const PRUnichar* end; - qName.EndReading(end); + const PRUnichar* end = qName.EndReading(); nsAutoString schemaTypePrefix, schemaType, schemaTypeNamespace; if (!colon) { @@ -4793,8 +4811,13 @@ nsSchemaValidator::ValidateSchemaAttribute(nsIDOMNode* aNode, if (pAttribute) { // we have to be really careful to set the destructor function // correctly. this also has to be a pointer to a variant - nsCOMPtr key = do_GetAtom("xsdtype"); - NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr atomServ = + do_GetService(NS_ATOMSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr key; + rv = atomServ->GetAtomUTF8("xsdtype", getter_AddRefs(key)); + NS_ENSURE_SUCCESS(rv, rv); nsIVariant *pVariant = holder; NS_IF_ADDREF(pVariant); diff --git a/mozilla/extensions/schema-validation/src/nsSchemaValidator.h b/mozilla/extensions/schema-validation/src/nsSchemaValidator.h index 9206baed153..66e48e95be0 100644 --- a/mozilla/extensions/schema-validation/src/nsSchemaValidator.h +++ b/mozilla/extensions/schema-validation/src/nsSchemaValidator.h @@ -58,6 +58,8 @@ #define NS_ERROR_SCHEMAVALIDATOR_NO_TYPE_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_SCHEMA, 3) #define NS_ERROR_SCHEMAVALIDATOR_TYPE_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_SCHEMA, 4) +#define kNotFound -1 + class nsSchemaValidator : public nsISchemaValidator { public: diff --git a/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.cpp b/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.cpp index 31f3449397f..704ca40f007 100644 --- a/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.cpp +++ b/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.cpp @@ -38,8 +38,7 @@ * ***** END LICENSE BLOCK ***** */ // string includes -#include "nsReadableUtils.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsUnicharUtils.h" #include "nsISchema.h" @@ -47,6 +46,7 @@ #include "nsSchemaValidatorUtils.h" #include "nsISchemaValidatorRegexp.h" #include "nsSchemaDuration.h" +#include "nsServiceManagerUtils.h" #include #include @@ -193,10 +193,9 @@ nsSchemaValidatorUtils::ParseSchemaDate(const nsAString & aStrValue, (-)CCYY-MM-DDT */ - nsAString::const_iterator start, end, buffStart; - aStrValue.BeginReading(start); - aStrValue.BeginReading(buffStart); - aStrValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aStrValue.BeginReading(&start, &end); + aStrValue.BeginReading(&buffStart); PRUint32 state = 0; PRUint32 buffLength = 0; PRBool done = PR_FALSE; @@ -330,10 +329,9 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue, // we store the fraction seconds because PR_ExplodeTime seems to skip them. nsAutoString usec; - nsAString::const_iterator start, end, buffStart; - aStrValue.BeginReading(start); - aStrValue.BeginReading(buffStart); - aStrValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aStrValue.BeginReading(&start, &end); + aStrValue.BeginReading(&buffStart); PRUint32 state = 0; PRUint32 buffLength = 0; PRBool done = PR_FALSE; @@ -444,10 +442,10 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue, else done = PR_TRUE; tzSign = currentChar; - usec.Assign(Substring(buffStart.get(), start.get()-1)); + usec.Assign(Substring(buffStart, start - 1)); } else if ((currentChar == '+') || (currentChar == '-')) { // timezone exists - usec.Assign(Substring(buffStart.get(), start.get()-1)); + usec.Assign(Substring(buffStart, start - 1)); state = 4; buffLength = 0; buffStart = start; @@ -463,7 +461,7 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue, case 4: { // timezone hh:mm - if (buffStart.size_forward() == 5) + if (end-buffStart == 5) isValid = ParseSchemaTimeZone(Substring(buffStart, end), timezoneHour, timezoneMinute); @@ -509,10 +507,9 @@ nsSchemaValidatorUtils::ParseSchemaTimeZone(const nsAString & aStrValue, char timezoneHour[3] = ""; char timezoneMinute[3] = ""; - nsAString::const_iterator start, end, buffStart; - aStrValue.BeginReading(start); - aStrValue.BeginReading(buffStart); - aStrValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aStrValue.BeginReading(&start, &end); + aStrValue.BeginReading(&buffStart); PRUint32 state = 0; PRUint32 buffLength = 0; PRBool done = PR_FALSE; @@ -792,7 +789,7 @@ nsSchemaValidatorUtils::AddTimeZoneToDateTime(nsSchemaDateTime aDateTime, void nsSchemaValidatorUtils::GetMonthShorthand(PRUint8 aMonth, nsACString & aReturn) { - aReturn.AssignASCII(monthShortHand[aMonth - 1].shortHand); + aReturn.Assign(monthShortHand[aMonth - 1].shortHand); } /* @@ -857,10 +854,9 @@ nsSchemaValidatorUtils::ParseSchemaDuration(const nsAString & aStrValue, { PRBool isValid = PR_FALSE; - nsAString::const_iterator start, end, buffStart; - aStrValue.BeginReading(start); - aStrValue.BeginReading(buffStart); - aStrValue.EndReading(end); + const PRUnichar *start, *end, *buffStart; + aStrValue.BeginReading(&start, &end); + aStrValue.BeginReading(&buffStart); PRUint32 state = 0; PRUint32 buffLength = 0; PRBool done = PR_FALSE; @@ -870,7 +866,7 @@ nsSchemaValidatorUtils::ParseSchemaDuration(const nsAString & aStrValue, // make sure leading P is present. Take negative durations into consideration. if (*start == '-') { - start.advance(1); + ++start; if (*start != 'P') { return PR_FALSE; } else { @@ -1133,11 +1129,9 @@ nsSchemaValidatorUtils::CompareStrings(const nsAString & aString1, return 1; } - nsAString::const_iterator start1, start2, end1, end2; - aString1.BeginReading(start1); - aString1.EndReading(end1); - aString2.BeginReading(start2); - aString2.EndReading(end2); + const PRUnichar *start1, *start2, *end1, *end2; + aString1.BeginReading(&start1, &end1); + aString2.BeginReading(&start2, &end2); // skip negative sign if (isNegative1) @@ -1371,9 +1365,8 @@ nsSchemaValidatorUtils::IsValidSchemaNormalizedString(const nsAString &aStrValue nsAutoString string(aStrValue); // may not contain carriage return, line feed nor tab characters - if (string.FindCharInSet("\t\r\n") == kNotFound) + if (FindCharInSet(string, "\t\r\n") == kNotFound) isValid = PR_TRUE; - return isValid; } @@ -1387,10 +1380,10 @@ nsSchemaValidatorUtils::IsValidSchemaToken(const nsAString &aStrValue) // may not contain carriage return, line feed, tab characters. Also can // not contain leading/trailing whitespace and no internal sequences of // two or more spaces. - if ((string.FindCharInSet("\t\r\n") == kNotFound) && + if ((FindCharInSet(string, "\t\r\n") == kNotFound) && (string.Find(NS_LITERAL_STRING(" ")) == kNotFound) && (string.First() != ' ') && - (string.Last() != ' ')) + (string.CharAt(string.Length() - 1) != ' ')) isValid = PR_TRUE; return isValid; @@ -1502,11 +1495,10 @@ nsSchemaValidatorUtils::IsValidSchemaIDRefs(const nsAString &aStrValue) PRBool isValid = PR_FALSE; // Need to validate each IDREF - nsAString::const_iterator iter, end, tokenStart; + const PRUnichar *iter, *end, *tokenStart; nsAutoString idref; - aStrValue.BeginReading(iter); - aStrValue.BeginReading(tokenStart); - aStrValue.EndReading(end); + aStrValue.BeginReading(&iter, &end); + aStrValue.BeginReading(&tokenStart); while (iter != end) { for (;IsWhitespace(*iter) && iter != end; ++iter); tokenStart = iter; @@ -1563,11 +1555,10 @@ nsSchemaValidatorUtils::IsValidSchemaNMTokens(const nsAString &aStrValue) PRBool isValid = PR_FALSE; // Need to validate each NNTOKEN - nsAString::const_iterator iter, end, tokenStart; + const PRUnichar *iter, *end, *tokenStart; nsAutoString idref; - aStrValue.BeginReading(iter); - aStrValue.BeginReading(tokenStart); - aStrValue.EndReading(end); + aStrValue.BeginReading(&iter, &end); + aStrValue.BeginReading(&tokenStart); while (iter != end) { for (;IsWhitespace(*iter) && iter != end; ++iter); tokenStart = iter; @@ -1612,9 +1603,8 @@ nsSchemaValidatorUtils::HandleEnumeration(const nsAString &aStrValue, void nsSchemaValidatorUtils::RemoveLeadingZeros(nsAString & aString) { - nsAString::const_iterator start, end; - aString.BeginReading(start); - aString.EndReading(end); + const PRUnichar *start, *end; + aString.BeginReading(&start, &end); PRBool done = PR_FALSE; PRUint32 count = 0, indexstart = 0; @@ -1647,9 +1637,8 @@ nsSchemaValidatorUtils::RemoveLeadingZeros(nsAString & aString) void nsSchemaValidatorUtils::RemoveTrailingZeros(nsAString & aString) { - nsAString::const_iterator start, end; - aString.BeginReading(start); - aString.EndReading(end); + const PRUnichar *start, *end; + aString.BeginReading(&start, &end); PRUint32 length = aString.Length(); @@ -1941,3 +1930,31 @@ nsSchemaValidatorUtils::SetToNullOrElement(nsIDOMNode *aNode, } } +PRInt32 +nsSchemaValidatorUtils::FindCharInSet(const nsAString & aString, + const char *aSet, PRInt32 aOffset) +{ + if (aString.IsEmpty()) { + return kNotFound; + } + + if (aOffset < 0) { + aOffset = 0; + } else if (aOffset > (PRInt32)aString.Length()) { + return kNotFound; + } + + const PRUnichar *start, *end; + aString.BeginReading(&start, &end); + + for (; start != end; ++start) { + for (const char *temp = aSet; *temp; ++temp) { + if (*start == PRUnichar(*temp)) { + return (temp - aSet + aOffset) ; + } + } + } + + return kNotFound; +} + diff --git a/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.h b/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.h index 0cfbf102b65..7c25404e17b 100644 --- a/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.h +++ b/mozilla/extensions/schema-validation/src/nsSchemaValidatorUtils.h @@ -40,7 +40,7 @@ #define __nsSchemaValidatorUtils_h__ #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsISchema.h" #include "nsIDOMNode.h" #include "nsCOMArray.h" @@ -239,6 +239,8 @@ public: nsSchemaDerivedSimpleType *aDerivedSrc); static void SetToNullOrElement(nsIDOMNode *aNode, nsIDOMNode **aResultNode); + static PRInt32 FindCharInSet(const nsAString & aString, const char *aSet, + PRInt32 aOffset = 0); private: nsSchemaValidatorUtils(); ~nsSchemaValidatorUtils(); diff --git a/mozilla/extensions/xforms/Makefile.in b/mozilla/extensions/xforms/Makefile.in index 77d3d43271c..28337f4e926 100644 --- a/mozilla/extensions/xforms/Makefile.in +++ b/mozilla/extensions/xforms/Makefile.in @@ -57,7 +57,6 @@ else MODULE_NAME = xforms EXPORT_LIBRARY = 1 endif -MOZILLA_INTERNAL_API = 1 # Also build schema-validation DIRS = ../schema-validation \ @@ -112,6 +111,7 @@ REQUIRES = \ pref \ htmlparser \ exthandler \ + chardet \ $(NULL) # XForms IDLs @@ -220,7 +220,11 @@ CPPSRCS = \ $(NULL) # Standard Mozilla make rules -EXTRA_DSO_LDOPTS = $(MOZ_COMPONENT_LIBS) +EXTRA_DSO_LDOPTS = \ + $(MOZ_COMPONENT_NSPR_LIBS) \ + $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX) \ + $(XPCOM_GLUE_LDOPTS) \ + $(NULL) # Do not clean schema-validation on distclean, it should handle that itself distclean:: LOOP_OVER_DIRS= diff --git a/mozilla/extensions/xforms/nsXFormsAccessors.cpp b/mozilla/extensions/xforms/nsXFormsAccessors.cpp index 897f66a6d55..1c9bdfcebca 100644 --- a/mozilla/extensions/xforms/nsXFormsAccessors.cpp +++ b/mozilla/extensions/xforms/nsXFormsAccessors.cpp @@ -37,11 +37,10 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOMElement.h" #include "nsXFormsUtils.h" #include "nsXFormsAccessors.h" -#include "nsDOMString.h" #include "nsIEventStateManager.h" #include "nsIContent.h" #include "nsIXFormsControl.h" @@ -72,7 +71,7 @@ nsXFormsAccessors::GetValue(nsAString &aValue) if (mDelegate) { mDelegate->GetValue(aValue); } else { - SetDOMStringToNull(aValue); + aValue.SetIsVoid(PR_TRUE); } return NS_OK; } diff --git a/mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp b/mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp index 9f67a054057..ca9407b02ec 100644 --- a/mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp +++ b/mozilla/extensions/xforms/nsXFormsActionModuleBase.cpp @@ -43,7 +43,7 @@ #include "nsMemory.h" #include "nsIDOMNodeList.h" #include "nsXFormsModelElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOMElement.h" #include "nsIDOMNodeList.h" #include "nsIXTFElementWrapper.h" diff --git a/mozilla/extensions/xforms/nsXFormsAtoms.cpp b/mozilla/extensions/xforms/nsXFormsAtoms.cpp index cf494c4fab4..3e3c034aa32 100644 --- a/mozilla/extensions/xforms/nsXFormsAtoms.cpp +++ b/mozilla/extensions/xforms/nsXFormsAtoms.cpp @@ -36,6 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIAtomService.h" +#include "nsServiceManagerUtils.h" #include "nsXFormsAtoms.h" #include "nsMemory.h" @@ -74,7 +76,7 @@ nsIAtom* nsXFormsAtoms::itemset; nsIAtom* nsXFormsAtoms::select; nsIAtom* nsXFormsAtoms::select1; -const nsStaticAtom nsXFormsAtoms::Atoms_info[] = { +const nsXFormsStaticAtom nsXFormsAtoms::Atoms_info[] = { { "src", &nsXFormsAtoms::src }, { "bind", &nsXFormsAtoms::bind }, { "type", &nsXFormsAtoms::type }, @@ -114,5 +116,16 @@ const nsStaticAtom nsXFormsAtoms::Atoms_info[] = { void nsXFormsAtoms::InitAtoms() { - NS_RegisterStaticAtoms(Atoms_info, NS_ARRAY_LENGTH(Atoms_info)); + PRUint32 numAtoms = NS_ARRAY_LENGTH(Atoms_info); + + nsCOMPtr atomServ = + do_GetService(NS_ATOMSERVICE_CONTRACTID); + if (!atomServ) { + return; + } + + for (PRUint32 i = 0; i < numAtoms; ++i) { + atomServ->GetPermanentAtomUTF8(Atoms_info[i].mString, + Atoms_info[i].mAtom); + } } diff --git a/mozilla/extensions/xforms/nsXFormsAtoms.h b/mozilla/extensions/xforms/nsXFormsAtoms.h index 3397ad82333..8df96b79c97 100644 --- a/mozilla/extensions/xforms/nsXFormsAtoms.h +++ b/mozilla/extensions/xforms/nsXFormsAtoms.h @@ -39,7 +39,21 @@ #ifndef nsXFormsAtoms_h_ #define nsXFormsAtoms_h_ -#include "nsStaticAtom.h" +#include "nsIAtom.h" + +// stolen from nsStaticAtom.h. Not frozen though, so figured I should steal. +// Class for declaring a static list of atoms, for use with gperf +// Keep this VERY simple +// mString: the value of the atom - the policy is that this is only +// ASCII, in order to avoid unnecessary conversions if +// someone asks for this in unicode +// mAtom: a convienience pointer - if you want to store the value of +// the atom created by this structure somewhere, put its +// address here +struct nsXFormsStaticAtom { + const char* mString; + nsIAtom ** mAtom; +}; /** * Class for singleton XForms nsIAtom pointers @@ -86,7 +100,7 @@ class nsXFormsAtoms static NS_HIDDEN_(void) InitAtoms(); private: - static NS_HIDDEN_(const nsStaticAtom) Atoms_info[]; + static NS_HIDDEN_(const nsXFormsStaticAtom) Atoms_info[]; }; #endif diff --git a/mozilla/extensions/xforms/nsXFormsCaseElement.cpp b/mozilla/extensions/xforms/nsXFormsCaseElement.cpp index cf15c2a3946..2c857c65928 100644 --- a/mozilla/extensions/xforms/nsXFormsCaseElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsCaseElement.cpp @@ -44,7 +44,7 @@ #include "nsIXFormsSwitchElement.h" #include "nsCOMPtr.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIXTFElementWrapper.h" /** diff --git a/mozilla/extensions/xforms/nsXFormsChoicesElement.cpp b/mozilla/extensions/xforms/nsXFormsChoicesElement.cpp index e1f7ae38134..d194dffc8a0 100644 --- a/mozilla/extensions/xforms/nsXFormsChoicesElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsChoicesElement.cpp @@ -39,7 +39,7 @@ #include "nsIXFormsSelectChild.h" #include "nsXFormsStubElement.h" #include "nsIDOMHTMLOptGroupElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsCOMPtr.h" #include "nsIXTFElementWrapper.h" #include "nsIDOMDocument.h" diff --git a/mozilla/extensions/xforms/nsXFormsControlStub.cpp b/mozilla/extensions/xforms/nsXFormsControlStub.cpp index f20c22629a7..1f803b6f27c 100644 --- a/mozilla/extensions/xforms/nsXFormsControlStub.cpp +++ b/mozilla/extensions/xforms/nsXFormsControlStub.cpp @@ -517,7 +517,7 @@ nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent, nsAutoString type; aEvent->GetType(type); - if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Focus].name)) { + if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Focus].name)) { TryFocus(aHandled); } else if (type.Equals(NS_LITERAL_STRING("keypress"))) { nsCOMPtr keyEvent = do_QueryInterface(aEvent); @@ -551,8 +551,8 @@ nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent, } } } - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Next].name) || - type.EqualsASCII(sXFormsEventsEntries[eEvent_Previous].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Next].name) || + type.EqualsLiteral(sXFormsEventsEntries[eEvent_Previous].name)) { // only continue this processing if xforms-next or xforms-previous were // dispatched by the form and not as part of the 'tab' and 'shift+tab' @@ -577,12 +577,12 @@ nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent, nsIFocusController *focusController = doc->GetWindow()->GetRootFocusController(); if (focusController && - type.EqualsASCII(sXFormsEventsEntries[eEvent_Next].name)) { + type.EqualsLiteral(sXFormsEventsEntries[eEvent_Next].name)) { focusController->MoveFocus(PR_TRUE, nsnull); } else { focusController->MoveFocus(PR_FALSE, nsnull); } - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_BindingException].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_BindingException].name)) { // we threw up a popup during the nsXFormsUtils::DispatchEvent that sent // this error to this control *aHandled = PR_TRUE; diff --git a/mozilla/extensions/xforms/nsXFormsControlStub.h b/mozilla/extensions/xforms/nsXFormsControlStub.h index ea7eb14a52b..2e6f563e150 100644 --- a/mozilla/extensions/xforms/nsXFormsControlStub.h +++ b/mozilla/extensions/xforms/nsXFormsControlStub.h @@ -41,7 +41,7 @@ #define nsXFormsControlStub_h_ #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOMElement.h" #include "nsIDOMNode.h" diff --git a/mozilla/extensions/xforms/nsXFormsCopyElement.cpp b/mozilla/extensions/xforms/nsXFormsCopyElement.cpp index 63c6d778668..b1c479ccbea 100644 --- a/mozilla/extensions/xforms/nsXFormsCopyElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsCopyElement.cpp @@ -41,7 +41,7 @@ #include "nsIXTFElementWrapper.h" #include "nsXFormsUtils.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIXFormsItemElement.h" /** diff --git a/mozilla/extensions/xforms/nsXFormsDelegateStub.cpp b/mozilla/extensions/xforms/nsXFormsDelegateStub.cpp index f4c57360619..5f454fa912c 100644 --- a/mozilla/extensions/xforms/nsXFormsDelegateStub.cpp +++ b/mozilla/extensions/xforms/nsXFormsDelegateStub.cpp @@ -46,7 +46,6 @@ #include "nsIDOMDocumentView.h" #include "nsIDOMAbstractView.h" #include "nsIDOMDocumentEvent.h" -#include "nsDOMString.h" #include "nsIModelElementPrivate.h" #include "nsIXFormsUIWidget.h" #include "nsXFormsAtoms.h" @@ -142,7 +141,7 @@ nsXFormsDelegateStub::TryFocus(PRBool* aOK) NS_IMETHODIMP nsXFormsDelegateStub::GetValue(nsAString& aValue) { - SetDOMStringToNull(aValue); + aValue.SetIsVoid(PR_TRUE); if (mBoundNode) { nsXFormsUtils::GetNodeValue(mBoundNode, aValue); } @@ -174,7 +173,7 @@ nsXFormsDelegateStub::GetHasBoundNode(PRBool *aHasBoundNode) NS_IMETHODIMP nsXFormsDelegateStub::ReportError(const nsAString& aErrorMsg) { - const nsPromiseFlatString& flat = PromiseFlatString(aErrorMsg); + const nsString& flat = PromiseFlatString(aErrorMsg); nsXFormsUtils::ReportError(flat, mElement); return NS_OK; } @@ -182,7 +181,7 @@ nsXFormsDelegateStub::ReportError(const nsAString& aErrorMsg) NS_IMETHODIMP nsXFormsDelegateStub::ReportErrorMessage(const nsAString& aErrorMsg) { - const nsPromiseFlatString& flat = PromiseFlatString(aErrorMsg); + const nsString& flat = PromiseFlatString(aErrorMsg); nsXFormsUtils::ReportErrorMessage(flat, mElement); return NS_OK; } diff --git a/mozilla/extensions/xforms/nsXFormsDelegateStub.h b/mozilla/extensions/xforms/nsXFormsDelegateStub.h index cef71c8d82b..02131e132d2 100644 --- a/mozilla/extensions/xforms/nsXFormsDelegateStub.h +++ b/mozilla/extensions/xforms/nsXFormsDelegateStub.h @@ -42,7 +42,7 @@ #include "nsAutoPtr.h" #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOMElement.h" #include "nsIDelegateInternal.h" #include "nsXFormsControlStub.h" diff --git a/mozilla/extensions/xforms/nsXFormsDispatchElement.cpp b/mozilla/extensions/xforms/nsXFormsDispatchElement.cpp index ec8a2050cf4..0dcd8701f97 100644 --- a/mozilla/extensions/xforms/nsXFormsDispatchElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsDispatchElement.cpp @@ -42,7 +42,7 @@ #include "nsIDOMEvent.h" #include "nsIDOMElement.h" #include "nsIDOMEventTarget.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" class nsXFormsDispatchElement : public nsXFormsActionModuleBase diff --git a/mozilla/extensions/xforms/nsXFormsElementFactory.cpp b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp index c83a299c98e..ad8b0b695cb 100644 --- a/mozilla/extensions/xforms/nsXFormsElementFactory.cpp +++ b/mozilla/extensions/xforms/nsXFormsElementFactory.cpp @@ -41,7 +41,7 @@ #include "nsXFormsAtoms.h" #include "nsIDocument.h" #include "nsIDOMNode.h" -#include "nsString.h" +#include "nsStringAPI.h" // Form controls NS_HIDDEN_(nsresult) NS_NewXFormsInputElement(nsIXTFElement **aElement); diff --git a/mozilla/extensions/xforms/nsXFormsGroupElement.cpp b/mozilla/extensions/xforms/nsXFormsGroupElement.cpp index 46b6614ba23..193d53ea492 100644 --- a/mozilla/extensions/xforms/nsXFormsGroupElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsGroupElement.cpp @@ -37,7 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsAutoPtr.h" #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOM3Node.h" #include "nsIDOMElement.h" diff --git a/mozilla/extensions/xforms/nsXFormsInsertDeleteElement.cpp b/mozilla/extensions/xforms/nsXFormsInsertDeleteElement.cpp index c7049965cc6..efa9144f981 100644 --- a/mozilla/extensions/xforms/nsXFormsInsertDeleteElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsInsertDeleteElement.cpp @@ -47,7 +47,7 @@ #include "nsIXFormsRepeatElement.h" #include "nsIXFormsControl.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIInstanceElementPrivate.h" #include "nsXFormsActionModuleBase.h" diff --git a/mozilla/extensions/xforms/nsXFormsInstanceElement.cpp b/mozilla/extensions/xforms/nsXFormsInstanceElement.cpp index 63c15bbb79f..398c09fc554 100644 --- a/mozilla/extensions/xforms/nsXFormsInstanceElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsInstanceElement.cpp @@ -43,7 +43,7 @@ #include "nsIDOM3Node.h" #include "nsMemory.h" #include "nsXFormsAtoms.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDOMEventTarget.h" #include "nsIDOMDOMImplementation.h" #include "nsIXTFElementWrapper.h" @@ -582,7 +582,7 @@ nsXFormsInstanceElement::LoadExternalInstance(const nsAString &aSrc) if (doc->GetProperty(nsXFormsAtoms::isInstanceDocument)) { /// Property exists, which means we are an instance document trying /// to load an external instance document. We do not allow that. - const nsPromiseFlatString& flat = PromiseFlatString(aSrc); + const nsString& flat = PromiseFlatString(aSrc); const PRUnichar *strings[] = { flat.get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("instanceInstanceLoad"), strings, 1, mElement, mElement); @@ -592,8 +592,7 @@ nsXFormsInstanceElement::LoadExternalInstance(const nsAString &aSrc) nsCOMPtr newDoc = do_QueryInterface(mDocument); nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), aSrc, - doc->GetDocumentCharacterSet().get(), doc->GetDocumentURI()); + nsXFormsUtils::GetNewURI(doc, aSrc, getter_AddRefs(uri)); if (uri) { if (nsXFormsUtils::CheckConnectionAllowed(mElement, uri)) { nsCOMPtr loadGroup; diff --git a/mozilla/extensions/xforms/nsXFormsItemElement.cpp b/mozilla/extensions/xforms/nsXFormsItemElement.cpp index 27b1724d1dc..044938f5adb 100644 --- a/mozilla/extensions/xforms/nsXFormsItemElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsItemElement.cpp @@ -44,7 +44,7 @@ #include "nsIDOMDocument.h" #include "nsIDOMDocumentEvent.h" #include "nsIPrivateDOMEvent.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" #include "nsIXFormsValueElement.h" #include "nsVoidArray.h" @@ -290,7 +290,7 @@ nsXFormsItemElement::GetValue(nsAString &aValue) // if this item was built by an itemset and the itemset's template used // a copy element, then there is no value element to be had. No sense // continuing. - aValue.Truncate(0); + aValue.Truncate(); return NS_ERROR_FAILURE; } @@ -314,7 +314,7 @@ nsXFormsItemElement::GetValue(nsAString &aValue) } // No value children, so our value is empty - aValue.Truncate(0); + aValue.Truncate(); return NS_OK; } @@ -423,7 +423,7 @@ NS_IMETHODIMP nsXFormsItemElement::GetLabelText(nsAString& aValue) { NS_ENSURE_STATE(mElement); - aValue.Truncate(0); + aValue.Truncate(); nsCOMPtr children; mElement->GetChildNodes(getter_AddRefs(children)); diff --git a/mozilla/extensions/xforms/nsXFormsItemSetElement.cpp b/mozilla/extensions/xforms/nsXFormsItemSetElement.cpp index fd24ae64c16..fee25dce51b 100644 --- a/mozilla/extensions/xforms/nsXFormsItemSetElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsItemSetElement.cpp @@ -39,7 +39,7 @@ #include "nsIXFormsSelectChild.h" #include "nsXFormsStubElement.h" #include "nsIDOMHTMLOptGroupElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsCOMPtr.h" #include "nsIXTFElementWrapper.h" #include "nsIDOMNodeList.h" diff --git a/mozilla/extensions/xforms/nsXFormsLabelElement.cpp b/mozilla/extensions/xforms/nsXFormsLabelElement.cpp index 0a973317c22..7045e1c9375 100644 --- a/mozilla/extensions/xforms/nsXFormsLabelElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsLabelElement.cpp @@ -51,7 +51,7 @@ #include "nsIDOM3Node.h" #include "nsIDOMDocument.h" #include "nsIDOMText.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIXFormsUIWidget.h" #include "nsIDocument.h" #include "nsNetUtil.h" @@ -251,8 +251,7 @@ nsXFormsLabelElement::LoadExternalLabel(const nsAString& aSrc) nsCOMPtr doc(do_QueryInterface(domDoc)); if (doc) { nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), aSrc, doc->GetDocumentCharacterSet().get(), - doc->GetDocumentURI()); + nsXFormsUtils::GetNewURI(doc, aSrc, getter_AddRefs(uri)); if (uri) { if (nsXFormsUtils::CheckConnectionAllowed(mElement, uri)) { nsCOMPtr loadGroup; @@ -271,7 +270,7 @@ nsXFormsLabelElement::LoadExternalLabel(const nsAString& aSrc) // URI doesn't exist; report error. mChannel = nsnull; - const nsPromiseFlatString& flat = PromiseFlatString(aSrc); + const nsString& flat = PromiseFlatString(aSrc); const PRUnichar *strings[] = { flat.get(), NS_LITERAL_STRING("label").get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("externalLink1Error"), diff --git a/mozilla/extensions/xforms/nsXFormsMessageElement.cpp b/mozilla/extensions/xforms/nsXFormsMessageElement.cpp index f53cb391cf4..4160d4bd4bd 100644 --- a/mozilla/extensions/xforms/nsXFormsMessageElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsMessageElement.cpp @@ -690,8 +690,7 @@ nsXFormsMessageElement::HandleModalAndModelessMessage(nsIDOMDocument* aDoc, nsCOMPtr doc(do_QueryInterface(aDoc)); NS_ENSURE_STATE(doc); nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), src, doc->GetDocumentCharacterSet().get(), - doc->GetDocumentURI()); + nsXFormsUtils::GetNewURI(doc, src, getter_AddRefs(uri)); NS_ENSURE_STATE(uri); nsCAutoString uriSpec; uri->GetSpec(uriSpec); @@ -941,8 +940,7 @@ nsXFormsMessageElement::TestExternalFile() nsCOMPtr doc(do_QueryInterface(domDoc)); NS_ENSURE_STATE(doc); nsCOMPtr uri; - NS_NewURI(getter_AddRefs(uri), src, doc->GetDocumentCharacterSet().get(), - doc->GetDocumentURI()); + nsXFormsUtils::GetNewURI(doc, src, getter_AddRefs(uri)); NS_ENSURE_STATE(uri); if (!nsXFormsUtils::CheckConnectionAllowed(mElement, uri)) { diff --git a/mozilla/extensions/xforms/nsXFormsModelElement.cpp b/mozilla/extensions/xforms/nsXFormsModelElement.cpp index 0746b012ef9..afee5e9f812 100644 --- a/mozilla/extensions/xforms/nsXFormsModelElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsModelElement.cpp @@ -46,7 +46,7 @@ #include "nsIDOM3Node.h" #include "nsIDOMNodeList.h" #include "nsIVariant.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDocument.h" #include "nsXFormsAtoms.h" #include "nsINameSpaceManager.h" @@ -72,7 +72,6 @@ #include "nsXFormsUtils.h" #include "nsXFormsSchemaValidator.h" #include "nsIXFormsUIWidget.h" -#include "nsIAttribute.h" #include "nsISchemaLoader.h" #include "nsISchema.h" #include "nsAutoPtr.h" @@ -84,6 +83,8 @@ #include "nsIPrefBranch.h" #include "nsIEventStateManager.h" #include "nsStringEnumerator.h" +#include "nsIAtomService.h" +#include "nsIAttribute.h" #define XFORMS_LAZY_INSTANCE_BINDING \ "chrome://xforms/content/xforms.xml#xforms-lazy-instance" @@ -939,20 +940,20 @@ nsXFormsModelElement::HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled) aEvent->GetType(type); nsresult rv = NS_OK; - if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Refresh].name)) { + if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Refresh].name)) { rv = Refresh(); - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Revalidate].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Revalidate].name)) { rv = Revalidate(); - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Recalculate].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Recalculate].name)) { rv = Recalculate(); - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Rebuild].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Rebuild].name)) { rv = Rebuild(); - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_ModelConstructDone].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_ModelConstructDone].name)) { rv = ConstructDone(); mConstructDoneHandled = PR_TRUE; - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Reset].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_Reset].name)) { Reset(); - } else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_BindingException].name)) { + } else if (type.EqualsLiteral(sXFormsEventsEntries[eEvent_BindingException].name)) { // we threw up a popup during the nsXFormsUtils::DispatchEvent that sent // this error to the model *aHandled = PR_TRUE; @@ -1040,7 +1041,7 @@ nsXFormsModelElement::GetInstanceDocument(const nsAString& aInstanceID, return NS_OK; } - const nsPromiseFlatString& flat = PromiseFlatString(aInstanceID); + const nsString& flat = PromiseFlatString(aInstanceID); const PRUnichar *strings[] = { flat.get() }; nsXFormsUtils::ReportError(aInstanceID.IsEmpty() ? NS_LITERAL_STRING("defInstanceNotFound") : @@ -1830,12 +1831,17 @@ nsXFormsModelElement::GetTypeFromNode(nsIDOMNode *aInstanceData, // If there was no type information on the node itself, check for a type // bound to the node via \ + nsresult rv = NS_ERROR_FAILURE; if (!typeVal && !mNodeToType.Get(aInstanceData, &typeVal)) { // check if schema validation left us a nsISchemaType* - nsCOMPtr key = do_GetAtom("xsdtype"); - NS_ENSURE_TRUE(key, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr atomServ = + do_GetService(NS_ATOMSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr key; + rv = atomServ->GetAtomUTF8("xsdtype", getter_AddRefs(key)); + NS_ENSURE_SUCCESS(rv, rv); - nsresult rv = NS_ERROR_FAILURE; nsCOMPtr xsdType; // this is stored on the DOM3Node as a property called xsdtype nsCOMPtr pContent(do_QueryInterface(aInstanceData)); @@ -1895,12 +1901,11 @@ nsXFormsModelElement::GetTypeFromNode(nsIDOMNode *aInstanceData, } // get the namespace url from the prefix using instance data node - nsresult rv; nsCOMPtr domNode3 = do_QueryInterface(aInstanceData, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = domNode3->LookupNamespaceURI(prefix, aNSUri); - if (DOMStringIsNull(aNSUri)) { + if (aNSUri.IsVoid()) { // if not found using instance data node, use node nsCOMPtr instanceNode; rv = nsXFormsUtils::GetInstanceNodeForData(aInstanceData, @@ -3198,32 +3203,28 @@ nsXFormsModelElement::GetDerivedTypeList(const nsAString &aType, nsStringArray typeArray; nsresult rv = WalkTypeChainInternal(schemaType, PR_FALSE, nsnull, &typeArray); if (NS_SUCCEEDED(rv)) { - nsCOMPtr stringEnum; - rv = NS_NewStringEnumerator(getter_AddRefs(stringEnum), &typeArray); - if (NS_SUCCEEDED(rv)) { - nsAutoString constructorString; - PRBool hasMore = PR_FALSE; - rv = stringEnum->HasMore(&hasMore); - while (NS_SUCCEEDED(rv) && hasMore) { - nsAutoString tempString; - rv = stringEnum->GetNext(tempString); - if (NS_SUCCEEDED(rv)) { - constructorString.Append(tempString); - stringEnum->HasMore(&hasMore); - if (hasMore) { - constructorString.AppendLiteral(" "); - } - } + PRUint32 numStrings = typeArray.Count(); + nsAutoString constructorString; + for (PRUint32 i = 0; i < numStrings; ++i) { + nsAutoString tempString; + typeArray.StringAt(i, tempString); + constructorString.Append(tempString); + if (i != numStrings - 1) { + // if we aren't appending the last string, then stick in the space + // delimeter + constructorString.AppendLiteral(" "); } + } - if (NS_SUCCEEDED(rv)) { - aTypeList.Assign(constructorString); - } + if (numStrings) { + aTypeList.Assign(constructorString); + } else { + aTypeList.Truncate(); } } if (NS_FAILED(rv)) { - aTypeList.Assign(EmptyString()); + aTypeList.Truncate(); } typeArray.Clear(); @@ -3470,9 +3471,8 @@ nsXFormsModelElement::IsDuplicateSchema(nsIDOMElement *aSchemaElement) if (!schemaColl) return PR_FALSE; - const nsAFlatString& empty = EmptyString(); nsAutoString targetNamespace; - aSchemaElement->GetAttributeNS(empty, + aSchemaElement->GetAttributeNS(EmptyString(), NS_LITERAL_STRING("targetNamespace"), targetNamespace); targetNamespace.Trim(" \r\n\t"); @@ -3486,7 +3486,7 @@ nsXFormsModelElement::IsDuplicateSchema(nsIDOMElement *aSchemaElement) // schema collection and the first instance has already been processed. // Report an error to the JS console and dispatch the LinkError event, // but do not consider it a fatal error. - const nsPromiseFlatString& flat = PromiseFlatString(targetNamespace); + const nsString& flat = PromiseFlatString(targetNamespace); const PRUnichar *strings[] = { flat.get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("duplicateSchema"), strings, 1, aSchemaElement, aSchemaElement, diff --git a/mozilla/extensions/xforms/nsXFormsModule.cpp b/mozilla/extensions/xforms/nsXFormsModule.cpp index 3c4a0a9b51d..83c20ac3ac6 100644 --- a/mozilla/extensions/xforms/nsXFormsModule.cpp +++ b/mozilla/extensions/xforms/nsXFormsModule.cpp @@ -46,6 +46,7 @@ #include "nsIServiceManager.h" #include "nsIClassInfoImpl.h" #include "nsXFormsXPathFunctions.h" +#include "nsServiceManagerUtils.h" // bb0d9c8b-3096-4b66-92a0-6c1ddf80e65f #define NS_XFORMSUTILITYSERVICE_CID \ @@ -81,7 +82,7 @@ RegisterXFormsModule(nsIComponentManager *aCompMgr, if (!catman) return NS_ERROR_FAILURE; - nsXPIDLCString previous; + nsCString previous; nsresult rv = catman->AddCategoryEntry(NS_DOMNS_FEATURE_PREFIX "org.w3c.xforms.dom", "1.0", diff --git a/mozilla/extensions/xforms/nsXFormsOutputElement.cpp b/mozilla/extensions/xforms/nsXFormsOutputElement.cpp index 44e9f1624b3..b44a9158036 100755 --- a/mozilla/extensions/xforms/nsXFormsOutputElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsOutputElement.cpp @@ -44,8 +44,7 @@ #include "nsAutoPtr.h" #include "nsCOMPtr.h" #include "nsMemory.h" -#include "nsString.h" -#include "nsDOMString.h" +#include "nsStringAPI.h" #include "nsIDOM3Node.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" @@ -107,7 +106,7 @@ nsXFormsOutputElement::nsXFormsOutputElement() nsresult nsXFormsOutputElement::Bind(PRBool *aContextChanged) { - SetDOMStringToNull(mValue); + mValue.SetIsVoid(PR_TRUE); mUseValueAttribute = PR_FALSE; nsresult rv = nsXFormsDelegateStub::Bind(aContextChanged); diff --git a/mozilla/extensions/xforms/nsXFormsRangeAccessors.cpp b/mozilla/extensions/xforms/nsXFormsRangeAccessors.cpp index d821fb59dda..6c7baf5c7b3 100644 --- a/mozilla/extensions/xforms/nsXFormsRangeAccessors.cpp +++ b/mozilla/extensions/xforms/nsXFormsRangeAccessors.cpp @@ -37,9 +37,8 @@ * ***** END LICENSE BLOCK ***** */ #include "nsXFormsRangeAccessors.h" -#include "nsDOMString.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsRangeAccessors, @@ -56,7 +55,7 @@ nsXFormsRangeAccessors::AttributeGetter(const nsAString &aAttr, nsAString &aVal) mElement->GetAttribute(aAttr, val); } if (val.IsEmpty()) { - SetDOMStringToNull(aVal); + aVal.SetIsVoid(PR_TRUE); } else { aVal = val; } diff --git a/mozilla/extensions/xforms/nsXFormsRepeatElement.cpp b/mozilla/extensions/xforms/nsXFormsRepeatElement.cpp index 09c54d507d4..2bbb432430c 100644 --- a/mozilla/extensions/xforms/nsXFormsRepeatElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsRepeatElement.cpp @@ -42,8 +42,7 @@ #include "nsISchema.h" #include "nsIServiceManager.h" #include "nsMemory.h" -#include "nsString.h" -#include "nsSubstring.h" +#include "nsStringAPI.h" #include "nsIDOM3EventTarget.h" #include "nsIDOM3Node.h" @@ -1301,11 +1300,10 @@ nsXFormsRepeatElement::GetIntAttr(const nsAString &aName, return NS_ERROR_NOT_AVAILABLE; } - PRInt32 errCode; /// @todo ToInteger is extremely large, "xxx23xxx" will be parsed with no errors /// as "23"... (XXX) - *aVal = attrVal.ToInteger(&errCode); - NS_ENSURE_TRUE(errCode == 0, NS_ERROR_FAILURE); + *aVal = attrVal.ToInteger(&rv); + NS_ENSURE_SUCCESS(rv, rv); /// /// @todo Check maximum values? (XXX) diff --git a/mozilla/extensions/xforms/nsXFormsSchemaValidator.cpp b/mozilla/extensions/xforms/nsXFormsSchemaValidator.cpp index 144fff24fcf..6cc2dcb6ba5 100644 --- a/mozilla/extensions/xforms/nsXFormsSchemaValidator.cpp +++ b/mozilla/extensions/xforms/nsXFormsSchemaValidator.cpp @@ -38,7 +38,7 @@ // XPCOM includes #include "nsIServiceManager.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" #include "nsISchemaValidator.h" @@ -46,6 +46,7 @@ #include "nsXFormsSchemaValidator.h" #include "nsIDOM3Node.h" +#include "nsComponentManagerUtils.h" #define NS_SCHEMAVALIDATOR_CONTRACTID "@mozilla.org/schemavalidator;1" @@ -196,7 +197,7 @@ nsXFormsSchemaValidator::IsValidSchemaListItem(const nsAString & aValue) // like a string, but no whitespace nsAutoString string(aValue); - if (string.FindCharInSet(" \t\r\n") == kNotFound) { + if (nsXFormsUtils::FindCharInSet(string, " \t\r\n") == kNotFound) { mSchemaValidator->ValidateString(aValue, NS_LITERAL_STRING("string"), NS_LITERAL_STRING("http://www.w3.org/1999/XMLSchema"), &isValid); diff --git a/mozilla/extensions/xforms/nsXFormsSelect1Element.cpp b/mozilla/extensions/xforms/nsXFormsSelect1Element.cpp index aeb4db1c3b9..437d9f51480 100644 --- a/mozilla/extensions/xforms/nsXFormsSelect1Element.cpp +++ b/mozilla/extensions/xforms/nsXFormsSelect1Element.cpp @@ -50,7 +50,7 @@ #include "nsIDOM3Node.h" #include "nsIDOMDocument.h" #include "nsIDOMText.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIXFormsUIWidget.h" #include "nsIDocument.h" #include "nsNetUtil.h" diff --git a/mozilla/extensions/xforms/nsXFormsSelectElement.cpp b/mozilla/extensions/xforms/nsXFormsSelectElement.cpp index dda21032d81..097b21602f6 100644 --- a/mozilla/extensions/xforms/nsXFormsSelectElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsSelectElement.cpp @@ -47,7 +47,7 @@ #include "nsIDOM3Node.h" #include "nsIDOMDocument.h" #include "nsIDOMText.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIXFormsUIWidget.h" #include "nsIDocument.h" #include "nsNetUtil.h" diff --git a/mozilla/extensions/xforms/nsXFormsSendElement.cpp b/mozilla/extensions/xforms/nsXFormsSendElement.cpp index a981d50a16a..2a066bfcd16 100644 --- a/mozilla/extensions/xforms/nsXFormsSendElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsSendElement.cpp @@ -38,7 +38,7 @@ #include "nsXFormsActionModuleBase.h" #include "nsIDOMDocument.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsCOMPtr.h" class nsXFormsSendElement : public nsXFormsActionModuleBase diff --git a/mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp b/mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp index 57b8c25a0bb..d0bc8621e08 100644 --- a/mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsSetFocusElement.cpp @@ -39,7 +39,7 @@ #include "nsXFormsActionModuleBase.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsCOMPtr.h" class nsXFormsSetFocusElement : public nsXFormsActionModuleBase diff --git a/mozilla/extensions/xforms/nsXFormsSubmissionElement.cpp b/mozilla/extensions/xforms/nsXFormsSubmissionElement.cpp index 959eb34d114..7bf6412e479 100644 --- a/mozilla/extensions/xforms/nsXFormsSubmissionElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsSubmissionElement.cpp @@ -83,9 +83,7 @@ #include "nsIHttpChannel.h" #include "nsIScriptSecurityManager.h" #include "nsIPipe.h" -#include "nsLinebreakConverter.h" -#include "nsEscape.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsMemory.h" #include "nsCOMPtr.h" #include "nsNetUtil.h" @@ -96,8 +94,9 @@ #include "nsIPrefService.h" #include "nsIMIMEHeaderParam.h" #include "nsIExternalProtocolService.h" -#include "nsEscape.h" #include "nsAutoPtr.h" +#include "nsIDocCharset.h" +#include "nsPIDOMWindow.h" // namespace literals #define kXMLNSNameSpaceURI \ @@ -178,21 +177,20 @@ URLEncode(const nsString &buf, nsCString &result) // 2. normalize newlines to \r\n // 3. escape, converting ' ' to '+' - NS_ConvertUTF16toUTF8 utf8Buf(buf); + nsCString convertedString; + PRBool converted = nsXFormsUtils::ConvertLineBreaks(NS_ConvertUTF16toUTF8(buf), + convertedString); + NS_ENSURE_TRUE(converted, NS_ERROR_OUT_OF_MEMORY); + + nsCOMPtr netUtil = do_GetService(NS_NETUTIL_CONTRACTID); + if (!netUtil) { + return NS_ERROR_UNEXPECTED; + } - char *convertedBuf = - nsLinebreakConverter::ConvertLineBreaks(utf8Buf.get(), - nsLinebreakConverter::eLinebreakAny, - nsLinebreakConverter::eLinebreakNet); - NS_ENSURE_TRUE(convertedBuf, NS_ERROR_OUT_OF_MEMORY); - - char *escapedBuf = nsEscape(convertedBuf, url_XPAlphas); - nsMemory::Free(convertedBuf); - - NS_ENSURE_TRUE(escapedBuf, NS_ERROR_OUT_OF_MEMORY); - - result.Adopt(escapedBuf); - return NS_OK; + nsresult rv = netUtil->EscapeString(convertedString, + nsINetUtil::ESCAPE_XPALPHAS, + result); + return rv; } static void @@ -956,9 +954,11 @@ nsXFormsSubmissionElement::SerializeDataXML(nsIDOMDocument *data, CopyUTF16toUTF8(mediaType, contentType); } - nsCOMPtr storage; - NS_NewStorageStream(4096, PR_UINT32_MAX, getter_AddRefs(storage)); + nsCOMPtr storage = + do_CreateInstance("@mozilla.org/storagestream;1"); NS_ENSURE_TRUE(storage, NS_ERROR_OUT_OF_MEMORY); + + storage->Init(4096, PR_UINT32_MAX, nsnull); nsCOMPtr sink; storage->GetOutputStream(0, getter_AddRefs(sink)); @@ -1033,9 +1033,9 @@ nsXFormsSubmissionElement::CheckSameOrigin(nsIDocument *aBaseDocument, } nsresult -nsXFormsSubmissionElement::AddNameSpaces(nsIDOMElement *aTarget, - nsIDOMNode *aSource, - nsStringHashSet *aPrefixHash) +nsXFormsSubmissionElement::AddNameSpaces( + nsIDOMElement *aTarget, nsIDOMNode *aSource, + nsDataHashtable *aPrefixHash) { nsCOMPtr attrMap; nsCOMPtr attrNode; @@ -1056,7 +1056,7 @@ nsXFormsSubmissionElement::AddNameSpaces(nsIDOMElement *aTarget, attrNode->GetNodeValue(value); if (!localName.EqualsLiteral("xmlns")) { - if (!aPrefixHash || aPrefixHash->Contains(localName)) { + if (!aPrefixHash || aPrefixHash->Get(localName, nsnull)) { nsAutoString attrName(NS_LITERAL_STRING("xmlns:")); attrName.Append(localName); aTarget->SetAttributeNS(kXMLNSNameSpaceURI, attrName, value); @@ -1082,13 +1082,14 @@ nsXFormsSubmissionElement::AddNameSpaces(nsIDOMElement *aTarget, } nsresult -nsXFormsSubmissionElement::GetIncludeNSPrefixesAttr(nsStringHashSet** aHash) +nsXFormsSubmissionElement::GetIncludeNSPrefixesAttr( + nsDataHashtable** aHash) { NS_PRECONDITION(aHash, "null ptr"); if (!aHash) return NS_ERROR_NULL_POINTER; - *aHash = new nsStringHashSet(); + *aHash = new nsDataHashtable; if (!*aHash) return NS_ERROR_OUT_OF_MEMORY; (*aHash)->Init(5); @@ -1102,11 +1103,11 @@ nsXFormsSubmissionElement::GetIncludeNSPrefixesAttr(nsStringHashSet** aHash) PRInt32 length = prefixes.Length(); do { - end = prefixes.FindCharInSet(" \t\r\n", start); + end = nsXFormsUtils::FindCharInSet(prefixes, " \t\r\n", start); if (end != kNotFound) { if (start != end) { // this line handles consecutive space chars const nsAString& p = Substring(prefixes, start, end - start); - (*aHash)->Put(p); + (*aHash)->Put(p, 0); } start = end + 1; } @@ -1114,7 +1115,7 @@ nsXFormsSubmissionElement::GetIncludeNSPrefixesAttr(nsStringHashSet** aHash) if (start != length) { const nsAString& p = Substring(prefixes, start); - (*aHash)->Put(p); + (*aHash)->Put(p, 0); } } @@ -1171,7 +1172,7 @@ nsXFormsSubmissionElement::CreateSubmissionDoc(nsIDOMNode *aRoot, if (serialize) { // Handle "includenamespaceprefixes" attribute, if present - nsAutoPtr prefixHash; + nsAutoPtr< nsDataHashtable > prefixHash; PRBool hasPrefixAttr = PR_FALSE; mElement->HasAttribute(kIncludeNamespacePrefixes, &hasPrefixAttr); if (hasPrefixAttr) { @@ -1192,7 +1193,7 @@ nsXFormsSubmissionElement::CreateSubmissionDoc(nsIDOMNode *aRoot, XMLNSAttrValue); if (XMLNSAttrValue.IsEmpty() && (!prefixHash || - !prefixHash->Contains(NS_LITERAL_STRING("#default")))) { + !prefixHash->Get(NS_LITERAL_STRING("#default"), nsnull))) { submDocElm->RemoveAttributeNS(kXMLNSNameSpaceURI, NS_LITERAL_STRING("xmlns")); } @@ -1279,12 +1280,12 @@ nsXFormsSubmissionElement::CreatePurgedDoc(nsIDOMNode *source, encoding.AssignLiteral("UTF-8"); nsAutoString buf = - NS_LITERAL_STRING("version=\"1.0\" encoding=\"") + - encoding + - NS_LITERAL_STRING("\""); + NS_LITERAL_STRING("version=\"1.0\" encoding=\""); + buf += encoding; + buf.AppendLiteral("\""); if (GetBooleanAttr(NS_LITERAL_STRING("standalone"), PR_FALSE)) - buf += NS_LITERAL_STRING(" standalone=\"yes\""); + buf.AppendLiteral(" standalone=\"yes\""); nsCOMPtr pi; doc->CreateProcessingInstruction(NS_LITERAL_STRING("xml"), buf, @@ -1735,10 +1736,15 @@ nsXFormsSubmissionElement::SerializeDataURLEncoded(nsIDOMDocument *data, { nsCAutoString buf; AppendURLEncodedData(data, separator, buf); + *stream = nsnull; // make new stream - NS_NewCStringInputStream(stream, buf); - NS_ENSURE_STATE(*stream); + nsCOMPtrstringInput = + do_CreateInstance("@mozilla.org/io/string-input-stream;1"); + NS_ENSURE_TRUE(stringInput, NS_ERROR_OUT_OF_MEMORY); + nsresult rv = stringInput->SetData(buf.get(), buf.Length()); + NS_ENSURE_SUCCESS(rv, rv); + NS_ADDREF(*stream = stringInput); contentType.AssignLiteral("application/x-www-form-urlencoded"); } @@ -1811,7 +1817,10 @@ nsXFormsSubmissionElement::AppendURLEncodedData(nsIDOMNode *data, URLEncode(localName, encLocalName); URLEncode(value, encValue); - buf.Append(encLocalName + NS_LITERAL_CSTRING("=") + encValue + separator); + buf.Append(encLocalName); + buf += NS_LITERAL_CSTRING("="); + buf += encValue; + buf += separator; } else { @@ -1858,10 +1867,16 @@ nsXFormsSubmissionElement::SerializeDataMultipartRelated(nsIDOMDocument *data, // XXX we should output a 'charset=' with the 'Content-Type' header nsCString postDataChunk; - postDataChunk += NS_LITERAL_CSTRING("--") + boundary - + NS_LITERAL_CSTRING("\r\nContent-Type: ") + type - + NS_LITERAL_CSTRING("\r\nContent-ID: <") + start - + NS_LITERAL_CSTRING(">\r\n\r\n"); + postDataChunk += NS_LITERAL_CSTRING("--"); + postDataChunk += boundary; + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Type: "); + postDataChunk += type; + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-ID: <"); + postDataChunk += start; + postDataChunk += NS_LITERAL_CSTRING(">\r\n\r\n"); + + + rv = AppendPostDataChunk(postDataChunk, multiStream); NS_ENSURE_SUCCESS(rv, rv); @@ -1887,11 +1902,15 @@ nsXFormsSubmissionElement::SerializeDataMultipartRelated(nsIDOMDocument *data, type.AssignLiteral("application/octet-stream"); } - postDataChunk += NS_LITERAL_CSTRING("\r\n--") + boundary - + NS_LITERAL_CSTRING("\r\nContent-Type: ") + type - + NS_LITERAL_CSTRING("\r\nContent-Transfer-Encoding: binary") - + NS_LITERAL_CSTRING("\r\nContent-ID: <") + a->cid - + NS_LITERAL_CSTRING(">\r\n\r\n"); + postDataChunk += NS_LITERAL_CSTRING("\r\n--"); + postDataChunk += boundary; + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Type: "); + postDataChunk += type; + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Transfer-Encoding: binary"); + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-ID: <"); + postDataChunk += a->cid; + postDataChunk += NS_LITERAL_CSTRING(">\r\n\r\n"); + rv = AppendPostDataChunk(postDataChunk, multiStream); NS_ENSURE_SUCCESS(rv, rv); @@ -1900,16 +1919,19 @@ nsXFormsSubmissionElement::SerializeDataMultipartRelated(nsIDOMDocument *data, } // final boundary - postDataChunk += NS_LITERAL_CSTRING("\r\n--") + boundary - + NS_LITERAL_CSTRING("--\r\n"); + postDataChunk += NS_LITERAL_CSTRING("\r\n--"); + postDataChunk += boundary; + postDataChunk += NS_LITERAL_CSTRING("--\r\n"); rv = AppendPostDataChunk(postDataChunk, multiStream); NS_ENSURE_SUCCESS(rv, rv); - contentType = - NS_LITERAL_CSTRING("multipart/related; boundary=") + boundary + - NS_LITERAL_CSTRING("; type=\"") + type + - NS_LITERAL_CSTRING("\"; start=\"<") + start + - NS_LITERAL_CSTRING(">\""); + contentType = NS_LITERAL_CSTRING("multipart/related; boundary="); + contentType += boundary; + contentType += NS_LITERAL_CSTRING("; type=\""); + contentType += type; + contentType += NS_LITERAL_CSTRING("\"; start=\"<"); + contentType += start; + contentType += NS_LITERAL_CSTRING(">\""); NS_ADDREF(*stream = multiStream); return NS_OK; @@ -1950,12 +1972,14 @@ nsXFormsSubmissionElement::SerializeDataMultipartFormData(nsIDOMDocument *data, nsresult rv = AppendMultipartFormData(data, boundary, postDataChunk, multiStream); NS_ENSURE_SUCCESS(rv, rv); - postDataChunk += NS_LITERAL_CSTRING("--") + boundary - + NS_LITERAL_CSTRING("--\r\n\r\n"); + postDataChunk += NS_LITERAL_CSTRING("--"); + postDataChunk += boundary; + postDataChunk += NS_LITERAL_CSTRING("--\r\n\r\n"); rv = AppendPostDataChunk(postDataChunk, multiStream); NS_ENSURE_SUCCESS(rv, rv); - contentType = NS_LITERAL_CSTRING("multipart/form-data; boundary=") + boundary; + contentType = NS_LITERAL_CSTRING("multipart/form-data; boundary="); + contentType += boundary; NS_ADDREF(*stream = multiStream); return NS_OK; @@ -2001,14 +2025,16 @@ nsXFormsSubmissionElement::AppendMultipartFormData(nsIDOMNode *data, rv = GetElementEncodingType(data, &encType); NS_ENSURE_SUCCESS(rv, rv); - NS_ConvertUTF16toUTF8 encName(localName); - encName.Adopt(nsLinebreakConverter::ConvertLineBreaks(encName.get(), - nsLinebreakConverter::eLinebreakAny, - nsLinebreakConverter::eLinebreakNet)); + nsCString encName; + PRBool converted = nsXFormsUtils::ConvertLineBreaks( + NS_ConvertUTF16toUTF8(localName), encName); + NS_ENSURE_TRUE(converted, NS_ERROR_OUT_OF_MEMORY); - postDataChunk += NS_LITERAL_CSTRING("--") + boundary - + NS_LITERAL_CSTRING("\r\nContent-Disposition: form-data; name=\"") - + encName + NS_LITERAL_CSTRING("\""); + postDataChunk += NS_LITERAL_CSTRING("--"); + postDataChunk += boundary; + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Disposition: form-data; name=\""); + postDataChunk += encName; + postDataChunk += NS_LITERAL_CSTRING("\""); nsCAutoString contentType; nsCOMPtr fileStream; @@ -2043,9 +2069,9 @@ nsXFormsSubmissionElement::AppendMultipartFormData(nsIDOMNode *data, contentType.AssignLiteral("application/octet-stream"); } - postDataChunk += NS_LITERAL_CSTRING("; filename=\"") - + NS_ConvertUTF16toUTF8(leafName) - + NS_LITERAL_CSTRING("\""); + postDataChunk += NS_LITERAL_CSTRING("; filename=\""); + postDataChunk += NS_ConvertUTF16toUTF8(leafName); + postDataChunk += NS_LITERAL_CSTRING("\""); } else if (encType == ELEMENT_ENCTYPE_STRING) { @@ -2056,9 +2082,9 @@ nsXFormsSubmissionElement::AppendMultipartFormData(nsIDOMNode *data, contentType.AssignLiteral("application/octet-stream"); } - postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Type: ") - + contentType - + NS_LITERAL_CSTRING("\r\n\r\n"); + postDataChunk += NS_LITERAL_CSTRING("\r\nContent-Type: "); + postDataChunk += contentType; + postDataChunk += NS_LITERAL_CSTRING("\r\n\r\n"); if (encType == ELEMENT_ENCTYPE_URI) { @@ -2076,11 +2102,12 @@ nsXFormsSubmissionElement::AppendMultipartFormData(nsIDOMNode *data, // xforms spec. // XXX UTF-8 ok? - NS_ConvertUTF16toUTF8 encValue(value); - encValue.Adopt(nsLinebreakConverter::ConvertLineBreaks(encValue.get(), - nsLinebreakConverter::eLinebreakAny, - nsLinebreakConverter::eLinebreakNet)); - postDataChunk += encValue + NS_LITERAL_CSTRING("\r\n"); + nsCString encValue; + converted = nsXFormsUtils::ConvertLineBreaks(NS_ConvertUTF16toUTF8(value), + encValue); + NS_ENSURE_TRUE(converted, NS_ERROR_OUT_OF_MEMORY); + postDataChunk += encValue; + postDataChunk += NS_LITERAL_CSTRING("\r\n"); } } else @@ -2103,9 +2130,12 @@ nsresult nsXFormsSubmissionElement::AppendPostDataChunk(nsCString &postDataChunk, nsIMultiplexInputStream *multiStream) { - nsCOMPtr stream; - NS_NewCStringInputStream(getter_AddRefs(stream), postDataChunk); + // make new stream + nsCOMPtr stream = + do_CreateInstance("@mozilla.org/io/string-input-stream;1"); NS_ENSURE_TRUE(stream, NS_ERROR_OUT_OF_MEMORY); + nsresult rv = stream->SetData(postDataChunk.get(), postDataChunk.Length()); + NS_ENSURE_SUCCESS(rv, rv); multiStream->AppendStream(stream); @@ -2191,19 +2221,25 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec, nsCOMPtr currURI = doc->GetDocumentURI(); + nsCOMPtr window = doc->GetWindow(); + NS_ENSURE_STATE(window); + nsCOMPtr docCharset = do_QueryInterface(window->GetDocShell()); + NS_ENSURE_STATE(docCharset); + nsCString charset; + nsresult rv = docCharset->GetCharset(getter_Copies(charset)); + NS_ENSURE_SUCCESS(rv, rv); + // Any parameters appended to uriSpec are already ASCII-encoded per the rules // of section 11.6. Use our standard document charset based canonicalization // for any other non-ASCII bytes. (This might be important for compatibility // with legacy CGI processors.) nsCOMPtr uri; ios->NewURI(uriSpec, - doc->GetDocumentCharacterSet().get(), + charset.get(), currURI, getter_AddRefs(uri)); NS_ENSURE_STATE(uri); - nsresult rv; - // handle mailto: submission if (!mIsReplaceInstance) { PRBool isMailto; @@ -2252,9 +2288,12 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec, memset(buf, 0, len+1); // Read returns 0 if eos + nsCOMPtr netUtil = do_GetService(NS_NETUTIL_CONTRACTID); + NS_ENSURE_STATE(netUtil); while (numReadIn != 0) { numReadIn = stream->Read(buf, len, &read); - NS_EscapeURL(buf, read, esc_Query|esc_AlwaysCopy, mailtoUrl); + netUtil->EscapeURL(nsCString(buf, read), nsINetUtil::ESCAPE_URL_QUERY, + mailtoUrl); } delete [] buf; @@ -2414,11 +2453,15 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec, // // pipe's maximum size is unlimited (gasp!) - nsCOMPtr pipeOut; - rv = NS_NewPipe(getter_AddRefs(mPipeIn), getter_AddRefs(pipeOut), - 4096, PR_UINT32_MAX, PR_TRUE, PR_TRUE); + nsCOMPtr pipe = do_CreateInstance("@mozilla.org/pipe;1"); + NS_ENSURE_STATE(pipe); + rv = pipe->Init(PR_TRUE, PR_TRUE, 4096, PR_UINT32_MAX, nsnull); NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr pipeOut; + pipe->GetInputStream(getter_AddRefs(mPipeIn)); + pipe->GetOutputStream(getter_AddRefs(pipeOut)); + // use a simple stream listener to tee our data into the pipe, and // notify us when the channel starts and stops. diff --git a/mozilla/extensions/xforms/nsXFormsSubmissionElement.h b/mozilla/extensions/xforms/nsXFormsSubmissionElement.h index 591f448da84..d046a76b047 100644 --- a/mozilla/extensions/xforms/nsXFormsSubmissionElement.h +++ b/mozilla/extensions/xforms/nsXFormsSubmissionElement.h @@ -41,15 +41,15 @@ #include "nsXFormsStubElement.h" #include "nsIRequestObserver.h" -#include "nsIInputStream.h" +#include "nsIAsyncInputStream.h" #include "nsCOMPtr.h" #include "nsIModelElementPrivate.h" #include "nsIXFormsSubmitElement.h" #include "nsIXFormsSubmissionElement.h" #include "nsIChannelEventSink.h" #include "nsIInterfaceRequestor.h" -#include "nsHashSets.h" #include "nsIDocument.h" +#include "nsDataHashtable.h" class nsIMultiplexInputStream; @@ -154,16 +154,18 @@ private: nsCOMPtr mActivator; // input end of pipe, which contains response data. - nsCOMPtr mPipeIn; + nsCOMPtr mPipeIn; /** * @return true if aTestURI has the same origin as aBaseURI or if * there is no need for a same origin check. */ PRBool CheckSameOrigin(nsIDocument *aBaseDocument, nsIURI *aTestURI); - nsresult AddNameSpaces(nsIDOMElement* aTarget, nsIDOMNode* aSource, - nsStringHashSet* aPrefixHash); - nsresult GetIncludeNSPrefixesAttr(nsStringHashSet** aHash); + nsresult AddNameSpaces( + nsIDOMElement* aTarget, nsIDOMNode* aSource, + nsDataHashtable* aPrefixHash); + nsresult GetIncludeNSPrefixesAttr( + nsDataHashtable** aHash); /** * Send xforms-submit-done/-error, depending on |aSucceeded| diff --git a/mozilla/extensions/xforms/nsXFormsSwitchElement.cpp b/mozilla/extensions/xforms/nsXFormsSwitchElement.cpp index 6171c507fd3..ef567465b65 100644 --- a/mozilla/extensions/xforms/nsXFormsSwitchElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsSwitchElement.cpp @@ -39,7 +39,7 @@ #include "nsCOMPtr.h" #include "nsIDOMElement.h" #include "nsIDOMDocument.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsIDocument.h" #include "nsIDOMNodeList.h" diff --git a/mozilla/extensions/xforms/nsXFormsToggleElement.cpp b/mozilla/extensions/xforms/nsXFormsToggleElement.cpp index fea8b68736b..0eeb5c7d0cd 100644 --- a/mozilla/extensions/xforms/nsXFormsToggleElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsToggleElement.cpp @@ -40,7 +40,7 @@ #include "nsIDOMDocument.h" #include "nsIDOMEvent.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" #include "nsIXFormsSwitchElement.h" diff --git a/mozilla/extensions/xforms/nsXFormsTriggerElement.cpp b/mozilla/extensions/xforms/nsXFormsTriggerElement.cpp index 385986c29d5..7e73647d87d 100644 --- a/mozilla/extensions/xforms/nsXFormsTriggerElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsTriggerElement.cpp @@ -47,7 +47,7 @@ #include "nsIDOMDocumentView.h" #include "nsIDOMAbstractView.h" #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsAtoms.h" #include "nsXFormsUtils.h" #include "nsXFormsControlStub.h" diff --git a/mozilla/extensions/xforms/nsXFormsUploadElement.cpp b/mozilla/extensions/xforms/nsXFormsUploadElement.cpp index 9b392bcb8d1..1f9d03879d8 100644 --- a/mozilla/extensions/xforms/nsXFormsUploadElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsUploadElement.cpp @@ -156,12 +156,12 @@ nsXFormsUploadElement::PickFile() rv = bundleService->CreateBundle(NS_HTMLFORM_BUNDLE_URL, getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLString filepickerTitle; + nsString filepickerTitle; rv = bundle->GetStringFromName(NS_LITERAL_STRING("FileUpload").get(), getter_Copies(filepickerTitle)); if (NS_FAILED(rv)) { // fall back to English text - filepickerTitle.AssignASCII("File Upload"); + filepickerTitle.AssignLiteral("File Upload"); } // get nsIDOMWindowInternal @@ -191,15 +191,16 @@ nsXFormsUploadElement::PickFile() do_GetService("@mozilla.org/mime;1", &rv); NS_ENSURE_SUCCESS(rv, rv); - nsAString::const_iterator start, end, iter; - mediaType.BeginReading(start); - mediaType.BeginReading(iter); - mediaType.EndReading(end); + const PRUnichar *start = nsnull, *end = nsnull, *iter = nsnull; + mediaType.BeginReading(&start, &end); + mediaType.BeginReading(&iter); nsAutoString fileFilter; nsAutoString mimeType; while (iter != end) { - if (FindCharInReadable(' ', iter, end)) { + while (iter < end && *iter != ' ') + ++iter; + if (iter < end) { mimeType = Substring(start, iter); // Skip the space. ++iter; @@ -454,7 +455,7 @@ ReportEncodingMemoryError(nsIDOMElement* aElement, nsIFile *aFile, } nsAutoString size; - size.AppendInt((PRInt64)aFailedSize); + size.AppendInt(aFailedSize); const PRUnichar *strings[] = { filename.get(), size.get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("encodingMemoryError"), strings, 2, aElement, aElement); @@ -494,7 +495,7 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, PRUint16 aType, *aResult = nsnull; char *buffer = PL_Base64Encode(fileData.Elements(), bytesRead, nsnull); if (buffer) { - *aResult = ToNewUnicode(nsDependentCString(buffer)); + *aResult = ToNewUnicode(NS_ConvertASCIItoUTF16(buffer)); PR_Free(buffer); } if (!*aResult) { diff --git a/mozilla/extensions/xforms/nsXFormsUtils.cpp b/mozilla/extensions/xforms/nsXFormsUtils.cpp index 3c85aad3184..aeb379168e2 100644 --- a/mozilla/extensions/xforms/nsXFormsUtils.cpp +++ b/mozilla/extensions/xforms/nsXFormsUtils.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsXFormsUtils.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsAtoms.h" #include "nsIDOMElement.h" #include "nsIDOMNSHTMLElement.h" @@ -61,12 +61,9 @@ #include "nsIDOMLocation.h" #include "nsIDOMSerializer.h" #include "nsIContent.h" -#include "nsIAttribute.h" #include "nsXFormsAtoms.h" #include "nsIXFormsRepeatElement.h" #include "nsIContentPolicy.h" -#include "nsContentUtils.h" -#include "nsContentPolicyUtils.h" #include "nsIXFormsContextControl.h" #include "nsIDOMDocumentEvent.h" #include "nsIDOMEvent.h" @@ -81,7 +78,6 @@ #include "nsIScriptSecurityManager.h" #include "nsIPermissionManager.h" -#include "nsServiceManagerUtils.h" #include "nsIDOMAttr.h" #include "nsIDOM3Node.h" #include "nsIConsoleService.h" @@ -97,6 +93,7 @@ #include "nsXFormsSchemaValidator.h" #include "prdtoa.h" +#include "nsIPref.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsIDOMDocumentView.h" @@ -115,6 +112,11 @@ #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIPrompt.h" +#include "nsComponentManagerUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsIDocShell.h" +#include "nsIDocCharset.h" +#include "nsNetUtil.h" // For locale aware string methods #include "plstr.h" @@ -566,7 +568,7 @@ nsXFormsUtils::EvaluateXPath(const nsAString &aExpression, PRBool throwException = PR_FALSE; if (!expression) { - const nsPromiseFlatString& flat = PromiseFlatString(aExpression); + const nsString& flat = PromiseFlatString(aExpression); const PRUnichar *strings[] = { flat.get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("exprParseError"), strings, 1, aContextNode, nsnull); @@ -611,7 +613,7 @@ nsXFormsUtils::EvaluateXPath(const nsAString &aExpression, } if (rv == NS_ERROR_XFORMS_CALCULATION_EXCEPTION) { - const nsPromiseFlatString& flat = PromiseFlatString(aExpression); + const nsString& flat = PromiseFlatString(aExpression); const PRUnichar *strings[] = { flat.get() }; nsXFormsUtils::ReportError(NS_LITERAL_STRING("exprEvaluateError"), strings, 1, aContextNode, nsnull); @@ -782,7 +784,7 @@ nsXFormsUtils::EvaluateNodeBinding(nsIDOMElement *aElement, const PRUnichar* colon; rv = parserService->CheckQName(expr, PR_TRUE, &colon); if (NS_SUCCEEDED(rv)) { - nsAutoString namespaceURI(EmptyString()); + nsAutoString namespaceURI; // if we detect a namespace, we'll add it to the node, otherwise // we'll use the empty namespace. If we should have gotten a @@ -1572,7 +1574,7 @@ nsXFormsUtils::CheckSameOrigin(nsIDocument *aBaseDocument, // permitted to access sites from other domains. nsCOMPtr permMgr = - do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); + do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); NS_ENSURE_TRUE(permMgr, PR_FALSE); nsCOMPtr principalURI; @@ -1600,17 +1602,28 @@ nsXFormsUtils::CheckContentPolicy(nsIDOMElement *aElement, { NS_ASSERTION(aElement && aDoc && aURI, "Got null parameters?!"); + nsIURI *docURI = aDoc->GetDocumentURI(); + NS_ENSURE_TRUE(docURI, PR_FALSE); + + nsresult rv; + nsCOMPtr policy = + do_GetService("@mozilla.org/layout/content-policy;1", &rv); + if (NS_FAILED(rv) || !policy) { + return PR_FALSE; + } + PRInt16 decision = nsIContentPolicy::ACCEPT; - nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OTHER, - aURI, - aDoc->NodePrincipal(), - aElement, // context - EmptyCString(), // mime guess - nsnull, // extra - &decision); + rv = policy->ShouldLoad(nsIContentPolicy::TYPE_OTHER, + aURI, + docURI, + aElement, // context + EmptyCString(), // mime guess + nsnull, // extra + &decision); + NS_ENSURE_SUCCESS(rv, PR_FALSE); - return NS_CP_ACCEPTED(decision); + return (decision == nsIContentPolicy::ACCEPT); } /*static*/ PRBool @@ -1765,7 +1778,7 @@ nsXFormsUtils::ReportError(const nsAString& aMessage, const PRUnichar **aParams, nsCOMPtr bundle; bundleService->CreateBundle("chrome://xforms/locale/xforms.properties", getter_AddRefs(bundle)); - nsXPIDLString message; + nsString message; if (aParams) { bundle->FormatStringFromName(PromiseFlatString(aMessage).get(), aParams, aParamLength, getter_Copies(message)); @@ -2604,7 +2617,7 @@ nsXFormsUtils::GetMonths(const nsAString & aValue, PRInt32 * aMonths) *aMonths = 0; nsCOMPtr duration; - nsCOMPtr schemaValidator = + nsCOMPtr schemaValidator = do_CreateInstance("@mozilla.org/schemavalidator;1"); NS_ENSURE_TRUE(schemaValidator, NS_ERROR_FAILURE); @@ -2714,16 +2727,15 @@ nsXFormsUtils::GetSecondsFromDateTime(const nsAString & aValue, return NS_OK; } - const nsAString& fraction = Substring(aValue, findFractionalSeconds+1, + const nsAString& fraction = Substring(aValue, findFractionalSeconds + 1, aValue.Length()); PRBool done = PR_FALSE; PRUnichar currentChar; nsCAutoString fractionResult; - nsAString::const_iterator start, end, buffStart; - fraction.BeginReading(start); - fraction.BeginReading(buffStart); - fraction.EndReading(end); + const PRUnichar *start = nsnull, *end = nsnull, *buffStart = nsnull; + fraction.BeginReading(&start, &end); + fraction.BeginReading(&buffStart); while ((start != end) && !done) { currentChar = *start++; @@ -2735,8 +2747,9 @@ nsXFormsUtils::GetSecondsFromDateTime(const nsAString & aValue, if ((currentChar == 'Z') || (currentChar == '+') || (currentChar == '-') || (start == end)) { fractionResult.AssignLiteral("0."); - AppendUTF16toUTF8(Substring(buffStart.get(), start.get()-1), - fractionResult); + nsCAutoString tempCString = + NS_ConvertUTF16toUTF8(Substring(buffStart, start - 1)); + fractionResult.Append(tempCString); } else if ((currentChar > '9') || (currentChar < '0')) { // has to be a numerical character or else abort. This should have been // caught by the schemavalidator, but it is worth double checking. @@ -2883,7 +2896,7 @@ nsXFormsUtils::AskStopWaiting(nsIDOMElement *aElement) getter_AddRefs(bundle)); NS_ENSURE_TRUE(bundle, PR_TRUE); - nsXPIDLString title, msg, stopButton, waitButton; + nsString title, msg, stopButton, waitButton; nsresult rv; rv = bundle->GetStringFromName(NS_LITERAL_STRING("KillScriptTitle").get(), @@ -2895,9 +2908,7 @@ nsXFormsUtils::AskStopWaiting(nsIDOMElement *aElement) rv |= bundle->GetStringFromName(NS_LITERAL_STRING("KillScriptMessage").get(), getter_Copies(msg)); - - // GetStringFromName can return NS_OK and still give NULL string - if (NS_FAILED(rv) || !title || !msg || !stopButton || !waitButton) { + if (NS_FAILED(rv)) { NS_ERROR("Failed to get localized strings."); return PR_TRUE; } @@ -2907,7 +2918,8 @@ nsXFormsUtils::AskStopWaiting(nsIDOMElement *aElement) (nsIPrompt::BUTTON_POS_0 + nsIPrompt::BUTTON_POS_1)); // Open the dialog. - rv = prompt->ConfirmEx(title, msg, buttonFlags, stopButton, waitButton, + rv = prompt->ConfirmEx(title.get(), msg.get(), buttonFlags, + stopButton.get(), waitButton.get(), nsnull, nsnull, nsnull, &buttonPressed); if (NS_SUCCEEDED(rv) && (buttonPressed == 0)) { @@ -2925,3 +2937,141 @@ nsXFormsUtils::ExperimentalFeaturesEnabled() // 'not yet standardized' XForms work. return gExperimentalFeaturesEnabled; } + +/* static */ PRInt32 +nsXFormsUtils::FindCharInSet(const nsAString &aString, const char *aSet, + PRInt32 aOffset) +{ + if (aString.IsEmpty()) { + return kNotFound; + } + + if (aOffset < 0) { + aOffset = 0; + } else if (aOffset > (PRInt32)aString.Length()) { + return kNotFound; + } + + const PRUnichar *start = nsnull, *end = nsnull, *iter = nsnull; + aString.BeginReading(&start, &end); + iter = start + aOffset; + + // Starting at aOffset, compare each character in the string against each + // character in aSet. As soon as a character in aSet is found, we return + // the offset of that character in the original string. + for (; iter != end; ++iter) { + for (const char *temp = aSet; *temp; ++temp) { + if (*iter == PRUnichar(*temp)) { + return (iter - start); + } + } + } + + return kNotFound; +} + +/* static */ PRBool +nsXFormsUtils::ConvertLineBreaks(const nsCString &aSrc, nsCString &aDest) +{ + // Stole most of this code from the ConvertUnknownBreaks function inside + // xpcom\io\nsLinebreakConverter.cpp. Orig authored by sfraser%netscape.com. + + const char *src, *srcEnd; + aSrc.BeginReading(&src, &srcEnd); + + const PRInt32 destBreakLen = 2; //strlen of "\015\012", a CR LF equiv string + PRUint32 finalLen = 0; + + if (src == srcEnd) { + // I guess if there isn't anything to convert, we should return PR_TRUE + // since we didn't encounter an error. + return PR_TRUE; + } + + while (src < srcEnd) + { + if (*src == '\r') + { + if (src[1] == '\n') + { + // CRLF + finalLen += destBreakLen; + src++; + } + else + { + // Lone CR + finalLen += destBreakLen; + } + } + else if (*src == '\n') + { + // Lone LF + finalLen += destBreakLen; + } + else + { + finalLen++; + } + src++; + } + + char* dst = aDest.BeginWriting(finalLen); + if (!dst) return PR_FALSE; + + aSrc.BeginReading(&src); + + while (src < srcEnd) + { + if (*src == '\r') + { + if (src[1] == '\n') + { + // CRLF + *dst++ = '\015'; + *dst++ = '\012'; + src++; + } + else + { + // Lone CR + *dst++ = '\015'; + *dst++ = '\012'; + } + } + else if (*src == '\n') + { + // Lone LF + *dst++ = '\015'; + *dst++ = '\012'; + } + else + { + *dst++ = *src; + } + src++; + } + + return PR_TRUE; +} + +/* static */ nsresult +nsXFormsUtils::GetNewURI(nsIDocument* aDoc, const nsAString& aSrc, + nsIURI** aURI) +{ + NS_ENSURE_ARG_POINTER(aURI); + *aURI = nsnull; + + nsCOMPtr window = aDoc->GetWindow(); + NS_ENSURE_STATE(window); + nsCOMPtr docCharset = do_QueryInterface(window->GetDocShell()); + NS_ENSURE_STATE(docCharset); + nsCString charset; + nsresult rv = docCharset->GetCharset(getter_Copies(charset)); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr uri; + rv = NS_NewURI(getter_AddRefs(uri), aSrc, charset.get(), aDoc->GetDocumentURI()); + NS_ENSURE_SUCCESS(rv, rv); + NS_ADDREF(*aURI = uri); + return rv; +} diff --git a/mozilla/extensions/xforms/nsXFormsUtils.h b/mozilla/extensions/xforms/nsXFormsUtils.h index e122d34763b..6a106c63cc8 100644 --- a/mozilla/extensions/xforms/nsXFormsUtils.h +++ b/mozilla/extensions/xforms/nsXFormsUtils.h @@ -93,6 +93,8 @@ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3001) #define NS_ERROR_XFORMS_UNION_TYPE \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL, 3002) +#define kNotFound -1 + /** * XForms event types * @@ -753,6 +755,45 @@ public: */ static NS_HIDDEN_(PRBool) ExperimentalFeaturesEnabled(); + /** + * Same as FindCharInSet but safely uses frozen string APIs. Compares + * each character in aString against each character in aSet. If a match to + * one of the characters in aSet is found, the index of that character in + * aString is returned. + * + * @param aString The string to search + * @param aSet The list of characters to search for + * @param aOffset The position to start looking from inside + * aString + */ + static NS_HIDDEN_(PRInt32) FindCharInSet(const nsAString &aString, + const char *aSet, + PRInt32 aOffset = 0); + + /** + * Convert the line breaks in a string to CRLF. Returns PR_FALSE if an + * an error occurred, otherwise returns PR_TRUE. + * + * @param aSrc String whose line breaks need to be converted + * to CRLF + * @param aDest Result string containing the converted string + */ + static NS_HIDDEN_(PRBool) ConvertLineBreaks(const nsCString &aSrc, + nsCString &aDest); + + /** + * Get a new nsIURI object based on the character set of aDoc. + * + * @param aDoc The document which character set is used when creating aURI. + * @param aSrc The URI string + * @param aURI The URI object which was created. + * + * @note aDoc must be attached to the docshell tree. + */ + static NS_HIDDEN_(nsresult) GetNewURI(nsIDocument* aDoc, + const nsAString& aSrc, + nsIURI** aURI); + private: /** * Do same origin checks on aBaseDocument and aTestURI. Hosts can be @@ -783,7 +824,6 @@ private: static NS_HIDDEN_(PRBool) CheckContentPolicy(nsIDOMElement *aElement, nsIDocument *aDoc, nsIURI *aURI); - }; #endif diff --git a/mozilla/extensions/xforms/nsXFormsValueElement.cpp b/mozilla/extensions/xforms/nsXFormsValueElement.cpp index c8c725eab34..60d34c3b066 100644 --- a/mozilla/extensions/xforms/nsXFormsValueElement.cpp +++ b/mozilla/extensions/xforms/nsXFormsValueElement.cpp @@ -42,7 +42,7 @@ #include "nsIDOM3Node.h" #include "nsXFormsUtils.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" /** * Implementation of the XForms \ element. diff --git a/mozilla/extensions/xforms/nsXFormsXPathAnalyzer.h b/mozilla/extensions/xforms/nsXFormsXPathAnalyzer.h index bc918074d0f..891add0f553 100644 --- a/mozilla/extensions/xforms/nsXFormsXPathAnalyzer.h +++ b/mozilla/extensions/xforms/nsXFormsXPathAnalyzer.h @@ -46,7 +46,7 @@ #include "nsIDOMXPathNSResolver.h" #include "nsIDOMNode.h" #include "nsCOMPtr.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsVoidArray.h" #include "nsIXFormsXPathState.h" diff --git a/mozilla/extensions/xforms/nsXFormsXPathFunctions.cpp b/mozilla/extensions/xforms/nsXFormsXPathFunctions.cpp index 335c5f2b745..770b024e344 100644 --- a/mozilla/extensions/xforms/nsXFormsXPathFunctions.cpp +++ b/mozilla/extensions/xforms/nsXFormsXPathFunctions.cpp @@ -41,7 +41,7 @@ #include "nsComponentManagerUtils.h" #include "nsIDOMDocument.h" #include "nsIDOMElement.h" -#include "nsString.h" +#include "nsStringAPI.h" #include "nsXFormsUtils.h" #include "prprf.h" #include "txDouble.h" @@ -380,8 +380,8 @@ nsXFormsXPathFunctions::Now(nsAString & aResult) PR_FormatTime(ctime, sizeof(ctime), "%Y-%m-%dT%H:%M:%S\0", &time); - aResult.AssignASCII(ctime); - AppendASCIItoUTF16(zone_location, aResult); + aResult.AssignLiteral(ctime); + aResult.Append(NS_ConvertASCIItoUTF16(zone_location)); return NS_OK; } diff --git a/mozilla/extensions/xforms/nsXFormsXPathParser.cpp b/mozilla/extensions/xforms/nsXFormsXPathParser.cpp index 1e94d1cf7ca..236548484bd 100644 --- a/mozilla/extensions/xforms/nsXFormsXPathParser.cpp +++ b/mozilla/extensions/xforms/nsXFormsXPathParser.cpp @@ -39,6 +39,7 @@ #include "nsXFormsXPathParser.h" #include "nscore.h" +#include "stdio.h" /* * @todo GIANT hack. Without exceptions everything had to be rewritten, and diff --git a/mozilla/extensions/xforms/nsXFormsXPathScanner.h b/mozilla/extensions/xforms/nsXFormsXPathScanner.h index 747ae371a0d..85d5038f9b7 100644 --- a/mozilla/extensions/xforms/nsXFormsXPathScanner.h +++ b/mozilla/extensions/xforms/nsXFormsXPathScanner.h @@ -40,7 +40,7 @@ #ifndef __NSXFORMSXPATHSCANNER_H__ #define __NSXFORMSXPATHSCANNER_H__ -#include "nsString.h" +#include "nsStringAPI.h" /** * The XPath Expression scanner, used by nsXFormsXPathParser. diff --git a/mozilla/extensions/xforms/nsXFormsXPathXMLUtil.h b/mozilla/extensions/xforms/nsXFormsXPathXMLUtil.h index bdcf17c51a4..b21aa7613b8 100644 --- a/mozilla/extensions/xforms/nsXFormsXPathXMLUtil.h +++ b/mozilla/extensions/xforms/nsXFormsXPathXMLUtil.h @@ -37,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsString.h" +#include "nsStringAPI.h" /** * Miscellaneous utility functions for determining the class of a character, used by