author | Henri Sivonen <hsivonen@iki.fi> |
Mon, 27 Feb 2012 13:57:48 +0200 | |
changeset 87836 | 5ccebf6862a93760927758553449b182fef4d8fa |
parent 87835 | fdd55a46661c761dcf681e5b74bec59f11c3a155 |
child 87837 | d40ba365b995634f5f1156c7b37c48b3333bc297 |
push id | 22160 |
push user | mbrubeck@mozilla.com |
push date | Tue, 28 Feb 2012 17:21:33 +0000 |
treeherder | mozilla-central@dde4e0089a18 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | smaug |
bugs | 650784 |
milestone | 13.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -1936,16 +1936,42 @@ public: * comma-separated list of URIs. Return true if the given URI's prepath is * in the list, and false otherwise. * * Comparisons are case-insensitive, and whitespace between elements of the * comma-separated list is ignored. */ static bool URIIsChromeOrInPref(nsIURI *aURI, const char *aPref); + /** + * This will parse aSource, to extract the value of the pseudo attribute + * with the name specified in aName. See + * http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification + * which is used to parse aSource. + * + * @param aSource the string to parse + * @param aName the name of the attribute to get the value for + * @param aValue [out] the value for the attribute with name specified in + * aAttribute. Empty if the attribute isn't present. + * @return true if the attribute exists and was successfully parsed. + * false if the attribute doesn't exist, or has a malformed + * value, such as an unknown or unterminated entity. + */ + static bool GetPseudoAttributeValue(const nsString& aSource, nsIAtom *aName, + nsAString& aValue); + + /** + * Returns true if the language name is a version of JavaScript and + * false otherwise + */ + static bool IsJavaScriptLanguage(const nsString& aName, PRUint32 *aVerFlags); + + static void SplitMimeType(const nsAString& aValue, nsString& aType, + nsString& aParams); + private: static bool InitializeEventTable(); static nsresult EnsureStringBundle(PropertiesFile aFile); static nsIDOMScriptObjectFactory *GetDOMScriptObjectFactory(); static nsresult HoldScriptObject(PRUint32 aLangID, void* aObject);
--- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -122,17 +122,16 @@ CPPSRCS = \ nsMappedAttributes.cpp \ nsNameSpaceManager.cpp \ nsNoDataProtocolContentPolicy.cpp \ nsNodeInfo.cpp \ nsNodeInfoManager.cpp \ nsNodeIterator.cpp \ nsNodeUtils.cpp \ nsObjectLoadingContent.cpp \ - nsParserUtils.cpp \ nsPlainTextSerializer.cpp \ nsPropertyTable.cpp \ nsRange.cpp \ nsReferencedElement.cpp \ nsScriptElement.cpp \ nsScriptLoader.cpp \ nsStubDocumentObserver.cpp \ nsStubImageDecoderObserver.cpp \
--- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -75,17 +75,16 @@ #include "nsIApplicationCacheContainer.h" #include "nsIApplicationCacheChannel.h" #include "nsIScriptSecurityManager.h" #include "nsIDOMLoadStatus.h" #include "nsICookieService.h" #include "nsIPrompt.h" #include "nsServiceManagerUtils.h" #include "nsContentUtils.h" -#include "nsParserUtils.h" #include "nsCRT.h" #include "nsEscape.h" #include "nsWeakReference.h" #include "nsUnicharUtils.h" #include "nsNodeInfoManager.h" #include "nsIAppShell.h" #include "nsIWidget.h" #include "nsWidgetsCID.h" @@ -707,17 +706,17 @@ nsContentSink::ProcessStyleLink(nsIConte { if (aAlternate && aTitle.IsEmpty()) { // alternates must have title return without error, for now return NS_OK; } nsAutoString mimeType; nsAutoString params; - nsParserUtils::SplitMimeType(aType, mimeType, params); + nsContentUtils::SplitMimeType(aType, mimeType, params); // see bug 18817 if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) { // Unknown stylesheet language return NS_OK; } nsCOMPtr<nsIURI> url;
--- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -175,16 +175,17 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_ #include "BasicLayers.h" #include "nsFocusManager.h" #include "nsTextEditorState.h" #include "nsIPluginHost.h" #include "nsICategoryManager.h" #include "nsIViewManager.h" #include "nsEventStateManager.h" #include "nsIDOMHTMLInputElement.h" +#include "nsParserConstants.h" #ifdef IBMBIDI #include "nsIBidiKeyboard.h" #endif #include "nsCycleCollectionParticipant.h" // for ReportToConsole #include "nsIStringBundle.h" @@ -715,16 +716,195 @@ nsContentUtils::URIIsChromeOrInPref(nsIU if (whitelistItem.Equals(prePath, nsCaseInsensitiveStringComparator())) { return true; } } return false; } +#define SKIP_WHITESPACE(iter, end_iter, end_res) \ + while ((iter) != (end_iter) && nsCRT::IsAsciiSpace(*(iter))) { \ + ++(iter); \ + } \ + if ((iter) == (end_iter)) { \ + return (end_res); \ + } + +#define SKIP_ATTR_NAME(iter, end_iter) \ + while ((iter) != (end_iter) && !nsCRT::IsAsciiSpace(*(iter)) && \ + *(iter) != '=') { \ + ++(iter); \ + } + +bool +nsContentUtils::GetPseudoAttributeValue(const nsString& aSource, nsIAtom *aName, + nsAString& aValue) +{ + aValue.Truncate(); + + const PRUnichar *start = aSource.get(); + const PRUnichar *end = start + aSource.Length(); + const PRUnichar *iter; + + while (start != end) { + SKIP_WHITESPACE(start, end, false) + iter = start; + SKIP_ATTR_NAME(iter, end) + + if (start == iter) { + return false; + } + + // Remember the attr name. + const nsDependentSubstring & attrName = Substring(start, iter); + + // Now check whether this is a valid name="value" pair. + start = iter; + SKIP_WHITESPACE(start, end, false) + if (*start != '=') { + // No '=', so this is not a name="value" pair. We don't know + // what it is, and we have no way to handle it. + return false; + } + + // Have to skip the value. + ++start; + SKIP_WHITESPACE(start, end, false) + PRUnichar q = *start; + if (q != kQuote && q != kApostrophe) { + // Not a valid quoted value, so bail. + return false; + } + + ++start; // Point to the first char of the value. + iter = start; + + while (iter != end && *iter != q) { + ++iter; + } + + if (iter == end) { + // Oops, unterminated quoted string. + return false; + } + + // At this point attrName holds the name of the "attribute" and + // the value is between start and iter. + + if (aName->Equals(attrName)) { + nsIParserService* parserService = nsContentUtils::GetParserService(); + NS_ENSURE_TRUE(parserService, false); + + // We'll accumulate as many characters as possible (until we hit either + // the end of the string or the beginning of an entity). Chunks will be + // delimited by start and chunkEnd. + const PRUnichar *chunkEnd = start; + while (chunkEnd != iter) { + if (*chunkEnd == kLessThan) { + aValue.Truncate(); + + return false; + } + + if (*chunkEnd == kAmpersand) { + aValue.Append(start, chunkEnd - start); + + // Point to first character after the ampersand. + ++chunkEnd; + + const PRUnichar *afterEntity; + PRUnichar result[2]; + PRUint32 count = + parserService->DecodeEntity(chunkEnd, iter, &afterEntity, result); + if (count == 0) { + aValue.Truncate(); + + return false; + } + + aValue.Append(result, count); + + // Advance to after the entity and begin a new chunk. + start = chunkEnd = afterEntity; + } + else { + ++chunkEnd; + } + } + + // Append remainder. + aValue.Append(start, iter - start); + + return true; + } + + // Resume scanning after the end of the attribute value (past the quote + // char). + start = iter + 1; + } + + return false; +} + +bool +nsContentUtils::IsJavaScriptLanguage(const nsString& aName, PRUint32 *aFlags) +{ + JSVersion version = JSVERSION_UNKNOWN; + + if (aName.LowerCaseEqualsLiteral("javascript") || + aName.LowerCaseEqualsLiteral("livescript") || + aName.LowerCaseEqualsLiteral("mocha")) { + version = JSVERSION_DEFAULT; + } else if (aName.LowerCaseEqualsLiteral("javascript1.0")) { + version = JSVERSION_1_0; + } else if (aName.LowerCaseEqualsLiteral("javascript1.1")) { + version = JSVERSION_1_1; + } else if (aName.LowerCaseEqualsLiteral("javascript1.2")) { + version = JSVERSION_1_2; + } else if (aName.LowerCaseEqualsLiteral("javascript1.3")) { + version = JSVERSION_1_3; + } else if (aName.LowerCaseEqualsLiteral("javascript1.4")) { + version = JSVERSION_1_4; + } else if (aName.LowerCaseEqualsLiteral("javascript1.5")) { + version = JSVERSION_1_5; + } else if (aName.LowerCaseEqualsLiteral("javascript1.6")) { + version = JSVERSION_1_6; + } else if (aName.LowerCaseEqualsLiteral("javascript1.7")) { + version = JSVERSION_1_7; + } else if (aName.LowerCaseEqualsLiteral("javascript1.8")) { + version = JSVERSION_1_8; + } + + if (version == JSVERSION_UNKNOWN) { + return false; + } + *aFlags = version; + return true; +} + +void +nsContentUtils::SplitMimeType(const nsAString& aValue, nsString& aType, + nsString& aParams) +{ + aType.Truncate(); + aParams.Truncate(); + PRInt32 semiIndex = aValue.FindChar(PRUnichar(';')); + if (-1 != semiIndex) { + aType = Substring(aValue, 0, semiIndex); + aParams = Substring(aValue, semiIndex + 1, + aValue.Length() - (semiIndex + 1)); + aParams.StripWhitespace(); + } + else { + aType = aValue; + } + aType.StripWhitespace(); +} + /** * Access a cached parser service. Don't addref. We need only one * reference to it and this class has that one. */ /* static */ nsIParserService* nsContentUtils::GetParserService() {
--- a/content/base/src/nsCrossSiteListenerProxy.cpp +++ b/content/base/src/nsCrossSiteListenerProxy.cpp @@ -43,17 +43,16 @@ #include "nsIScriptSecurityManager.h" #include "nsNetUtil.h" #include "nsIParser.h" #include "nsParserCIID.h" #include "nsICharsetAlias.h" #include "nsMimeTypes.h" #include "nsIStreamConverterService.h" #include "nsStringStream.h" -#include "nsParserUtils.h" #include "nsGkAtoms.h" #include "nsWhitespaceTokenizer.h" #include "nsIChannelEventSink.h" #include "nsIAsyncVerifyRedirectCallback.h" #include "nsCharSeparatedTokenizer.h" #include "nsAsyncRedirectVerifyHelper.h" #include "prclist.h" #include "prtime.h"
deleted file mode 100644 --- a/content/base/src/nsParserUtils.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * Namespace class for some static parsing-related methods. - */ - -#include "nsParserUtils.h" -#include "jsapi.h" -#include "nsReadableUtils.h" -#include "nsCRT.h" -#include "nsContentUtils.h" -#include "nsIParserService.h" -#include "nsParserConstants.h" - -#define SKIP_WHITESPACE(iter, end_iter, end_res) \ - while ((iter) != (end_iter) && nsCRT::IsAsciiSpace(*(iter))) { \ - ++(iter); \ - } \ - if ((iter) == (end_iter)) { \ - return (end_res); \ - } - -#define SKIP_ATTR_NAME(iter, end_iter) \ - while ((iter) != (end_iter) && !nsCRT::IsAsciiSpace(*(iter)) && \ - *(iter) != '=') { \ - ++(iter); \ - } - -bool -nsParserUtils::GetQuotedAttributeValue(const nsString& aSource, nsIAtom *aName, - nsAString& aValue) -{ - aValue.Truncate(); - - const PRUnichar *start = aSource.get(); - const PRUnichar *end = start + aSource.Length(); - const PRUnichar *iter; - - while (start != end) { - SKIP_WHITESPACE(start, end, false) - iter = start; - SKIP_ATTR_NAME(iter, end) - - if (start == iter) { - return false; - } - - // Remember the attr name. - const nsDependentSubstring & attrName = Substring(start, iter); - - // Now check whether this is a valid name="value" pair. - start = iter; - SKIP_WHITESPACE(start, end, false) - if (*start != '=') { - // No '=', so this is not a name="value" pair. We don't know - // what it is, and we have no way to handle it. - return false; - } - - // Have to skip the value. - ++start; - SKIP_WHITESPACE(start, end, false) - PRUnichar q = *start; - if (q != kQuote && q != kApostrophe) { - // Not a valid quoted value, so bail. - return false; - } - - ++start; // Point to the first char of the value. - iter = start; - - while (iter != end && *iter != q) { - ++iter; - } - - if (iter == end) { - // Oops, unterminated quoted string. - return false; - } - - // At this point attrName holds the name of the "attribute" and - // the value is between start and iter. - - if (aName->Equals(attrName)) { - nsIParserService* parserService = nsContentUtils::GetParserService(); - NS_ENSURE_TRUE(parserService, false); - - // We'll accumulate as many characters as possible (until we hit either - // the end of the string or the beginning of an entity). Chunks will be - // delimited by start and chunkEnd. - const PRUnichar *chunkEnd = start; - while (chunkEnd != iter) { - if (*chunkEnd == kLessThan) { - aValue.Truncate(); - - return false; - } - - if (*chunkEnd == kAmpersand) { - aValue.Append(start, chunkEnd - start); - - // Point to first character after the ampersand. - ++chunkEnd; - - const PRUnichar *afterEntity; - PRUnichar result[2]; - PRUint32 count = - parserService->DecodeEntity(chunkEnd, iter, &afterEntity, result); - if (count == 0) { - aValue.Truncate(); - - return false; - } - - aValue.Append(result, count); - - // Advance to after the entity and begin a new chunk. - start = chunkEnd = afterEntity; - } - else { - ++chunkEnd; - } - } - - // Append remainder. - aValue.Append(start, iter - start); - - return true; - } - - // Resume scanning after the end of the attribute value (past the quote - // char). - start = iter + 1; - } - - return false; -} - -// Returns true if the language name is a version of JavaScript and -// false otherwise -bool -nsParserUtils::IsJavaScriptLanguage(const nsString& aName, PRUint32 *aFlags) -{ - JSVersion version = JSVERSION_UNKNOWN; - - if (aName.LowerCaseEqualsLiteral("javascript") || - aName.LowerCaseEqualsLiteral("livescript") || - aName.LowerCaseEqualsLiteral("mocha")) { - version = JSVERSION_DEFAULT; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.0")) { - version = JSVERSION_1_0; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.1")) { - version = JSVERSION_1_1; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.2")) { - version = JSVERSION_1_2; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.3")) { - version = JSVERSION_1_3; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.4")) { - version = JSVERSION_1_4; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.5")) { - version = JSVERSION_1_5; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.6")) { - version = JSVERSION_1_6; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.7")) { - version = JSVERSION_1_7; - } - else if (aName.LowerCaseEqualsLiteral("javascript1.8")) { - version = JSVERSION_1_8; - } - if (version == JSVERSION_UNKNOWN) - return false; - *aFlags = version; - return true; -} - -void -nsParserUtils::SplitMimeType(const nsAString& aValue, nsString& aType, - nsString& aParams) -{ - aType.Truncate(); - aParams.Truncate(); - PRInt32 semiIndex = aValue.FindChar(PRUnichar(';')); - if (-1 != semiIndex) { - aType = Substring(aValue, 0, semiIndex); - aParams = Substring(aValue, semiIndex + 1, - aValue.Length() - (semiIndex + 1)); - aParams.StripWhitespace(); - } - else { - aType = aValue; - } - aType.StripWhitespace(); -}
deleted file mode 100644 --- a/content/base/src/nsParserUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * Namespace class for some static parsing-related methods. - */ - -#ifndef nsParserUtils_h__ -#define nsParserUtils_h__ - -#include "nsString.h" -class nsIAtom; - -class nsParserUtils { -public: - /** - * This will parse aSource, to extract the value of the pseudo attribute - * with the name specified in aName. See - * http://www.w3.org/TR/xml-stylesheet/#NT-StyleSheetPI for the specification - * which is used to parse aSource. - * - * @param aSource the string to parse - * @param aName the name of the attribute to get the value for - * @param aValue [out] the value for the attribute with name specified in - * aAttribute. Empty if the attribute isn't present. - * @return true if the attribute exists and was successfully parsed. - * false if the attribute doesn't exist, or has a malformed - * value, such as an unknown or unterminated entity. - */ - static bool - GetQuotedAttributeValue(const nsString& aSource, nsIAtom *aName, - nsAString& aValue); - - static bool - IsJavaScriptLanguage(const nsString& aName, PRUint32 *aVerFlags); - - static void - SplitMimeType(const nsAString& aValue, nsString& aType, - nsString& aParams); -}; - -#endif // nsParserUtils_h__ - - -
--- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -39,17 +39,16 @@ /* * A class that handles loading and evaluation of <script> elements. */ #include "jsapi.h" #include "jsfriendapi.h" #include "nsScriptLoader.h" -#include "nsParserUtils.h" #include "nsICharsetConverterManager.h" #include "nsIUnicodeDecoder.h" #include "nsIContent.h" #include "mozilla/dom/Element.h" #include "nsGkAtoms.h" #include "nsNetUtil.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" @@ -504,24 +503,24 @@ nsScriptLoader::ProcessScriptElement(nsI } } else { // no 'type=' element // "language" is a deprecated attribute of HTML, so we check it only for // HTML script elements. if (scriptContent->IsHTML()) { scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language); if (!language.IsEmpty()) { - if (nsParserUtils::IsJavaScriptLanguage(language, &version)) + if (nsContentUtils::IsJavaScriptLanguage(language, &version)) typeID = nsIProgrammingLanguage::JAVASCRIPT; else typeID = nsIProgrammingLanguage::UNKNOWN; // IE, Opera, etc. do not respect language version, so neither should // we at this late date in the browser wars saga. Note that this change // affects HTML but not XUL or SVG (but note also that XUL has its own - // code to check nsParserUtils::IsJavaScriptLanguage -- that's probably + // code to check nsContentUtils::IsJavaScriptLanguage -- that's probably // a separate bug, one we may not be able to fix short of XUL2). See // bug 255895 (https://bugzilla.mozilla.org/show_bug.cgi?id=255895). NS_ASSERTION(JSVERSION_DEFAULT == 0, "We rely on all languages having 0 as a version default"); version = 0; } } }
--- a/content/html/content/src/nsHTMLLinkElement.cpp +++ b/content/html/content/src/nsHTMLLinkElement.cpp @@ -47,17 +47,16 @@ #include "nsReadableUtils.h" #include "nsUnicharUtils.h" #include "nsIURL.h" #include "nsNetUtil.h" #include "nsIDocument.h" #include "nsIDOMEvent.h" #include "nsIPrivateDOMEvent.h" #include "nsIDOMEventTarget.h" -#include "nsParserUtils.h" #include "nsContentUtils.h" #include "nsPIDOMWindow.h" #include "nsAsyncDOMEvent.h" #include "Link.h" using namespace mozilla::dom; class nsHTMLLinkElement : public nsGenericHTMLElement, @@ -434,17 +433,17 @@ nsHTMLLinkElement::GetStyleSheetInfo(nsA } GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia); ToLowerCase(aMedia); // HTML4.0 spec is inconsistent, make it case INSENSITIVE nsAutoString mimeType; nsAutoString notUsed; GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType); - nsParserUtils::SplitMimeType(aType, mimeType, notUsed); + nsContentUtils::SplitMimeType(aType, mimeType, notUsed); if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) { return; } // If we get here we assume that we're loading a css file, so set the // type to 'text/css' aType.AssignLiteral("text/css");
--- a/content/html/content/src/nsHTMLStyleElement.cpp +++ b/content/html/content/src/nsHTMLStyleElement.cpp @@ -42,17 +42,16 @@ #include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsIDOMStyleSheet.h" #include "nsIStyleSheet.h" #include "nsStyleLinkElement.h" #include "nsNetUtil.h" #include "nsIDocument.h" #include "nsUnicharUtils.h" -#include "nsParserUtils.h" #include "nsThreadUtils.h" #include "nsContentUtils.h" class nsHTMLStyleElement : public nsGenericHTMLElement, public nsIDOMHTMLStyleElement, public nsStyleLinkElement, public nsStubMutationObserver { @@ -342,17 +341,17 @@ nsHTMLStyleElement::GetStyleSheetInfo(ns GetAttr(kNameSpaceID_None, nsGkAtoms::media, aMedia); ToLowerCase(aMedia); // HTML4.0 spec is inconsistent, make it case INSENSITIVE GetAttr(kNameSpaceID_None, nsGkAtoms::type, aType); nsAutoString mimeType; nsAutoString notUsed; - nsParserUtils::SplitMimeType(aType, mimeType, notUsed); + nsContentUtils::SplitMimeType(aType, mimeType, notUsed); if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) { return; } // If we get here we assume that we're loading a css file, so set the // type to 'text/css' aType.AssignLiteral("text/css"); }
--- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -45,17 +45,16 @@ #include "nsContentSink.h" #include "nsCOMPtr.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" #include "nsIHTMLContentSink.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIParser.h" -#include "nsParserUtils.h" #include "nsScriptLoader.h" #include "nsIURI.h" #include "nsNetUtil.h" #include "nsIContentViewer.h" #include "nsIMarkupDocumentViewer.h" #include "nsINodeInfo.h" #include "nsHTMLTokens.h" #include "nsIAppShell.h"
--- a/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -34,18 +34,18 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ #include "nsGenericElement.h" #include "nsGkAtoms.h" #include "nsUnicharUtils.h" #include "nsXMLProcessingInstruction.h" -#include "nsParserUtils.h" #include "nsContentCreatorFunctions.h" +#include "nsContentUtils.h" nsresult NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, nsNodeInfoManager *aNodeInfoManager, const nsAString& aTarget, const nsAString& aData) { NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); @@ -124,17 +124,17 @@ nsXMLProcessingInstruction::GetTarget(ns } bool nsXMLProcessingInstruction::GetAttrValue(nsIAtom *aName, nsAString& aValue) { nsAutoString data; GetData(data); - return nsParserUtils::GetQuotedAttributeValue(data, aName, aValue); + return nsContentUtils::GetPseudoAttributeValue(data, aName, aValue); } bool nsXMLProcessingInstruction::IsNodeOfType(PRUint32 aFlags) const { return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE)); }
--- a/content/xml/content/src/nsXMLStylesheetPI.cpp +++ b/content/xml/content/src/nsXMLStylesheetPI.cpp @@ -40,17 +40,16 @@ #include "nsIDOMStyleSheet.h" #include "nsIDocument.h" #include "nsIStyleSheet.h" #include "nsIURI.h" #include "nsStyleLinkElement.h" #include "nsNetUtil.h" #include "nsXMLProcessingInstruction.h" #include "nsUnicharUtils.h" -#include "nsParserUtils.h" #include "nsGkAtoms.h" #include "nsThreadUtils.h" #include "nsContentUtils.h" class nsXMLStylesheetPI : public nsXMLProcessingInstruction, public nsStyleLinkElement { public: @@ -204,37 +203,39 @@ nsXMLStylesheetPI::GetStyleSheetInfo(nsA // xml-stylesheet PI is special only in prolog if (!nsContentUtils::InProlog(this)) { return; } nsAutoString data; GetData(data); - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::title, aTitle); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::title, aTitle); nsAutoString alternate; - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::alternate, alternate); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::alternate, + alternate); // if alternate, does it have title? if (alternate.EqualsLiteral("yes")) { if (aTitle.IsEmpty()) { // alternates must have title return; } *aIsAlternate = true; } - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::media, aMedia); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::media, aMedia); nsAutoString type; - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::type, type); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type); nsAutoString mimeType, notUsed; - nsParserUtils::SplitMimeType(type, mimeType, notUsed); + nsContentUtils::SplitMimeType(type, mimeType, notUsed); if (!mimeType.IsEmpty() && !mimeType.LowerCaseEqualsLiteral("text/css")) { aType.Assign(type); return; } // If we get here we assume that we're loading a css file, so set the // type to 'text/css' aType.AssignLiteral("text/css");
--- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -63,17 +63,16 @@ #include "nsIScriptContext.h" #include "nsINameSpaceManager.h" #include "nsIServiceManager.h" #include "nsIScriptSecurityManager.h" #include "nsIContentViewer.h" #include "prtime.h" #include "prlog.h" #include "prmem.h" -#include "nsParserUtils.h" #include "nsRect.h" #include "nsGenericElement.h" #include "nsIWebNavigation.h" #include "nsIScriptElement.h" #include "nsScriptLoader.h" #include "nsStyleLinkElement.h" #include "nsIImageLoadingContent.h" #include "nsReadableUtils.h" @@ -260,37 +259,37 @@ CheckXSLTParamPI(nsIDOMProcessingInstruc { nsAutoString target, data; aPi->GetTarget(target); // Check for namespace declarations if (target.EqualsLiteral("xslt-param-namespace")) { aPi->GetData(data); nsAutoString prefix, namespaceAttr; - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::prefix, - prefix); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::prefix, + prefix); if (!prefix.IsEmpty() && - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::_namespace, - namespaceAttr)) { + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::_namespace, + namespaceAttr)) { aProcessor->AddXSLTParamNamespace(prefix, namespaceAttr); } } // Check for actual parameters else if (target.EqualsLiteral("xslt-param")) { aPi->GetData(data); nsAutoString name, namespaceAttr, select, value; - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::name, - name); - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::_namespace, - namespaceAttr); - if (!nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::select, select)) { + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::name, + name); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::_namespace, + namespaceAttr); + if (!nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::select, select)) { select.SetIsVoid(true); } - if (!nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::value, value)) { + if (!nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::value, value)) { value.SetIsVoid(true); } if (!name.IsEmpty()) { nsCOMPtr<nsIDOMNode> doc = do_QueryInterface(aDocument); aProcessor->AddXSLTParam(name, namespaceAttr, select, value, doc); } } } @@ -1335,17 +1334,17 @@ nsXMLContentSink::HandleProcessingInstru } return NS_OK; } } // If it's not a CSS stylesheet PI... nsAutoString type; - nsParserUtils::GetQuotedAttributeValue(data, nsGkAtoms::type, type); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::type, type); if (mState != eXMLContentSinkState_InProlog || !target.EqualsLiteral("xml-stylesheet") || type.IsEmpty() || type.LowerCaseEqualsLiteral("text/css")) { return DidProcessATokenImpl(); } @@ -1363,26 +1362,28 @@ nsXMLContentSink::HandleProcessingInstru /* static */ bool nsXMLContentSink::ParsePIData(const nsString &aData, nsString &aHref, nsString &aTitle, nsString &aMedia, bool &aIsAlternate) { // If there was no href, we can't do anything with this PI - if (!nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::href, aHref)) { + if (!nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::href, aHref)) { return false; } - nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::title, aTitle); + nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::title, aTitle); - nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::media, aMedia); + nsContentUtils::GetPseudoAttributeValue(aData, nsGkAtoms::media, aMedia); nsAutoString alternate; - nsParserUtils::GetQuotedAttributeValue(aData, nsGkAtoms::alternate, alternate); + nsContentUtils::GetPseudoAttributeValue(aData, + nsGkAtoms::alternate, + alternate); aIsAlternate = alternate.EqualsLiteral("yes"); return true; } NS_IMETHODIMP nsXMLContentSink::HandleXMLDeclaration(const PRUnichar *aVersion,
--- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -69,17 +69,16 @@ #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsIViewManager.h" #include "nsIXULDocument.h" #include "nsIScriptSecurityManager.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" #include "nsRDFCID.h" -#include "nsParserUtils.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsXULElement.h" #include "prlog.h" #include "prmem.h" #include "nsCRT.h" #include "nsXULPrototypeDocument.h" // XXXbe temporary @@ -1074,17 +1073,17 @@ XULContentSinkImpl::OpenScript(const PRU } } } else if (key.EqualsLiteral("language")) { // Language is deprecated, and the impl in nsScriptLoader ignores the // various version strings anyway. So we make no attempt to support // languages other than JS for language= nsAutoString lang(aAttributes[1]); - if (nsParserUtils::IsJavaScriptLanguage(lang, &version)) { + if (nsContentUtils::IsJavaScriptLanguage(lang, &version)) { langID = nsIProgrammingLanguage::JAVASCRIPT; // Even when JS version < 1.6 is specified, E4X is // turned on in XUL. version = js::VersionSetXML(JSVersion(version), true); } } aAttributes += 2;
--- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -79,17 +79,16 @@ #include "nsITimer.h" #include "nsIDocShell.h" #include "nsGkAtoms.h" #include "nsXMLContentSink.h" #include "nsXULContentSink.h" #include "nsXULContentUtils.h" #include "nsIXULOverlayProvider.h" #include "nsNetUtil.h" -#include "nsParserUtils.h" #include "nsParserCIID.h" #include "nsPIBoxObject.h" #include "nsRDFCID.h" #include "nsILocalStore.h" #include "nsXPIDLString.h" #include "nsPIDOMWindow.h" #include "nsPIWindowRoot.h" #include "nsXULCommandDispatcher.h" @@ -2540,19 +2539,19 @@ nsXULDocument::InsertXULOverlayPI(const if (NS_FAILED(rv)) return rv; // xul-overlay PI is special only in prolog if (!nsContentUtils::InProlog(aPINode)) { return NS_OK; } nsAutoString href; - nsParserUtils::GetQuotedAttributeValue(aProtoPI->mData, - nsGkAtoms::href, - href); + nsContentUtils::GetPseudoAttributeValue(aProtoPI->mData, + nsGkAtoms::href, + href); // If there was no href, we can't do anything with this PI if (href.IsEmpty()) { return NS_OK; } // Add the overlay to our list of overlays that need to be processed. nsCOMPtr<nsIURI> uri;
--- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -80,16 +80,17 @@ #include "nsIDOMNamedNodeMap.h" #include "nsIDOMNodeList.h" #include "nsIWebProgressListener.h" #include "nsIAuthPrompt.h" #include "nsIPrompt.h" #include "nsISHEntry.h" #include "nsIWebPageDescriptor.h" #include "nsIFormControl.h" +#include "nsContentUtils.h" #include "nsIDOMNodeFilter.h" #include "nsIDOMProcessingInstruction.h" #include "nsIDOMHTMLBodyElement.h" #include "nsIDOMHTMLTableElement.h" #include "nsIDOMHTMLTableRowElement.h" #include "nsIDOMHTMLTableCellElement.h" #include "nsIDOMHTMLAnchorElement.h" @@ -2599,108 +2600,54 @@ nsWebBrowserPersist::EnumCleanupUploadLi { channel->Cancel(NS_BINDING_ABORTED); } UploadData *data = (UploadData *) aData; delete data; // Delete data associated with key return true; } - -bool -nsWebBrowserPersist::GetQuotedAttributeValue( - const nsAString &aSource, const nsAString &aAttribute, nsAString &aValue) -{ - // NOTE: This code was lifted verbatim from nsParserUtils.cpp - aValue.Truncate(); - nsAString::const_iterator start, end; - aSource.BeginReading(start); - aSource.EndReading(end); - nsAString::const_iterator iter(end); - - while (start != end) { - if (FindInReadable(aAttribute, start, iter)) - { - // walk past any whitespace - while (iter != end && nsCRT::IsAsciiSpace(*iter)) - { - ++iter; - } - - if (iter == end) - break; - - // valid name="value" pair? - if (*iter != '=') - { - start = iter; - iter = end; - continue; - } - // move past the = - ++iter; - - while (iter != end && nsCRT::IsAsciiSpace(*iter)) - { - ++iter; - } - - if (iter == end) - break; - - PRUnichar q = *iter; - if (q != '"' && q != '\'') - { - start = iter; - iter = end; - continue; - } - - // point to the first char of the value - ++iter; - start = iter; - if (FindCharInReadable(q, iter, end)) - { - aValue = Substring(start, iter); - return true; - } - - // we've run out of string. Just return... - break; - } - } - return false; -} - nsresult nsWebBrowserPersist::FixupXMLStyleSheetLink(nsIDOMProcessingInstruction *aPI, const nsAString &aHref) { NS_ENSURE_ARG_POINTER(aPI); nsresult rv = NS_OK; nsAutoString data; rv = aPI->GetData(data); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); nsAutoString href; - GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), href); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::href, + href); // Construct and set a new data value for the xml-stylesheet if (!aHref.IsEmpty() && !href.IsEmpty()) { nsAutoString alternate; nsAutoString charset; nsAutoString title; nsAutoString type; nsAutoString media; - GetQuotedAttributeValue(data, NS_LITERAL_STRING("alternate"), alternate); - GetQuotedAttributeValue(data, NS_LITERAL_STRING("charset"), charset); - GetQuotedAttributeValue(data, NS_LITERAL_STRING("title"), title); - GetQuotedAttributeValue(data, NS_LITERAL_STRING("type"), type); - GetQuotedAttributeValue(data, NS_LITERAL_STRING("media"), media); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::alternate, + alternate); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::charset, + charset); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::title, + title); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::type, + type); + nsContentUtils::GetPseudoAttributeValue(data, + nsGkAtoms::media, + media); NS_NAMED_LITERAL_STRING(kCloseAttr, "\" "); nsAutoString newData; newData += NS_LITERAL_STRING("href=\"") + aHref + kCloseAttr; if (!title.IsEmpty()) { newData += NS_LITERAL_STRING("title=\"") + title + kCloseAttr; } @@ -2731,17 +2678,17 @@ nsresult nsWebBrowserPersist::GetXMLStyl { NS_ENSURE_ARG_POINTER(aPI); nsresult rv = NS_OK; nsAutoString data; rv = aPI->GetData(data); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); - GetQuotedAttributeValue(data, NS_LITERAL_STRING("href"), aHref); + nsContentUtils::GetPseudoAttributeValue(data, nsGkAtoms::href, aHref); return NS_OK; } nsresult nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode) { // Fixup xml-stylesheet processing instructions nsCOMPtr<nsIDOMProcessingInstruction> nodeAsPI = do_QueryInterface(aNode);
--- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h +++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.h @@ -147,18 +147,16 @@ private: URIData **aData = nsnull); nsresult StoreURIAttribute( nsIDOMNode *aNode, const char *aAttribute, bool aNeedsPersisting = true, URIData **aData = nsnull) { return StoreURIAttributeNS(aNode, "", aAttribute, aNeedsPersisting, aData); } - bool GetQuotedAttributeValue( - const nsAString &aSource, const nsAString &aAttribute, nsAString &aValue); bool DocumentEncoderExists(const PRUnichar *aContentType); nsresult GetNodeToFixup(nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut); nsresult FixupURI(nsAString &aURI); nsresult FixupNodeAttributeNS(nsIDOMNode *aNode, const char *aNamespaceURI, const char *aAttribute); nsresult FixupNodeAttribute(nsIDOMNode *aNode, const char *aAttribute) { return FixupNodeAttributeNS(aNode, "", aAttribute);