OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. |
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
(...skipping 4189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4200 } | 4200 } |
4201 | 4201 |
4202 const UChar* characters = name.characters16(); | 4202 const UChar* characters = name.characters16(); |
4203 | 4203 |
4204 if (isValidNameASCII(characters, length)) | 4204 if (isValidNameASCII(characters, length)) |
4205 return true; | 4205 return true; |
4206 | 4206 |
4207 return isValidNameNonASCII(characters, length); | 4207 return isValidNameNonASCII(characters, length); |
4208 } | 4208 } |
4209 | 4209 |
4210 enum ParseQualifiedNameException { | |
fs
2014/09/11 09:17:48
Lots of "Exception" here, maybe it'd be possible t
| |
4211 PQNNoException, | |
4212 PQNMultipleColonsException, | |
4213 PQNInvalidStartCharException, | |
4214 PQNInvalidCharException, | |
4215 PQNEmptyPrefix, | |
4216 PQNEmptyLocalName | |
4217 }; | |
4218 | |
4219 struct ParseQualifiedNameResult { | |
4220 ParseQualifiedNameException result; | |
4221 UChar32 character; | |
4222 ParseQualifiedNameResult() { } | |
4223 ParseQualifiedNameResult(ParseQualifiedNameException result) : result(result ) { } | |
fs
2014/09/11 09:17:48
Coding-style dictates the use of explicit here. No
| |
4224 ParseQualifiedNameResult(ParseQualifiedNameException result, UChar32 charact er) : result(result), character(character) { } | |
4225 }; | |
4226 | |
4210 template<typename CharType> | 4227 template<typename CharType> |
4211 static bool parseQualifiedNameInternal(const AtomicString& qualifiedName, const CharType* characters, unsigned length, AtomicString& prefix, AtomicString& local Name, ExceptionState& exceptionState) | 4228 static ParseQualifiedNameResult parseQualifiedNameInternal(const AtomicString& q ualifiedName, const CharType* characters, unsigned length, AtomicString& prefix, AtomicString& localName) |
4212 { | 4229 { |
4213 bool nameStart = true; | 4230 bool nameStart = true; |
4214 bool sawColon = false; | 4231 bool sawColon = false; |
4215 int colonPos = 0; | 4232 int colonPos = 0; |
4216 | 4233 |
4217 for (unsigned i = 0; i < length;) { | 4234 for (unsigned i = 0; i < length;) { |
4218 UChar32 c; | 4235 UChar32 c; |
4219 U16_NEXT(characters, i, length, c) | 4236 U16_NEXT(characters, i, length, c) |
4220 if (c == ':') { | 4237 if (c == ':') { |
4221 if (sawColon) { | 4238 if (sawColon) |
4222 exceptionState.throwDOMException(NamespaceError, "The qualified name provided ('" + qualifiedName + "') contains multiple colons."); | 4239 return ParseQualifiedNameResult(PQNMultipleColonsException); |
4223 return false; // multiple colons: not allowed | |
4224 } | |
4225 nameStart = true; | 4240 nameStart = true; |
4226 sawColon = true; | 4241 sawColon = true; |
4227 colonPos = i - 1; | 4242 colonPos = i - 1; |
4228 } else if (nameStart) { | 4243 } else if (nameStart) { |
4229 if (!isValidNameStart(c)) { | 4244 if (!isValidNameStart(c)) |
4230 StringBuilder message; | 4245 return ParseQualifiedNameResult(PQNInvalidStartCharException, c) ; |
4231 message.appendLiteral("The qualified name provided ('"); | |
4232 message.append(qualifiedName); | |
4233 message.appendLiteral("') contains the invalid name-start charac ter '"); | |
4234 message.append(c); | |
4235 message.appendLiteral("'."); | |
4236 exceptionState.throwDOMException(InvalidCharacterError, message. toString()); | |
4237 return false; | |
4238 } | |
4239 nameStart = false; | 4246 nameStart = false; |
4240 } else { | 4247 } else { |
4241 if (!isValidNamePart(c)) { | 4248 if (!isValidNamePart(c)) |
4242 StringBuilder message; | 4249 return ParseQualifiedNameResult(PQNInvalidCharException, c); |
4243 message.appendLiteral("The qualified name provided ('"); | |
4244 message.append(qualifiedName); | |
4245 message.appendLiteral("') contains the invalid character '"); | |
4246 message.append(c); | |
4247 message.appendLiteral("'."); | |
4248 exceptionState.throwDOMException(InvalidCharacterError, message. toString()); | |
4249 return false; | |
4250 } | |
4251 } | 4250 } |
4252 } | 4251 } |
4253 | 4252 |
4254 if (!sawColon) { | 4253 if (!sawColon) { |
4255 prefix = nullAtom; | 4254 prefix = nullAtom; |
4256 localName = qualifiedName; | 4255 localName = qualifiedName; |
4257 } else { | 4256 } else { |
4258 prefix = AtomicString(characters, colonPos); | 4257 prefix = AtomicString(characters, colonPos); |
4259 if (prefix.isEmpty()) { | 4258 if (prefix.isEmpty()) |
4260 exceptionState.throwDOMException(NamespaceError, "The qualified name provided ('" + qualifiedName + "') has an empty namespace prefix."); | 4259 return ParseQualifiedNameResult(PQNEmptyPrefix); |
4261 return false; | |
4262 } | |
4263 int prefixStart = colonPos + 1; | 4260 int prefixStart = colonPos + 1; |
4264 localName = AtomicString(characters + prefixStart, length - prefixStart) ; | 4261 localName = AtomicString(characters + prefixStart, length - prefixStart) ; |
4265 } | 4262 } |
4266 | 4263 |
4267 if (localName.isEmpty()) { | 4264 if (localName.isEmpty()) |
4268 exceptionState.throwDOMException(NamespaceError, "The qualified name pro vided ('" + qualifiedName + "') has an empty local name."); | 4265 return ParseQualifiedNameResult(PQNEmptyLocalName); |
4269 return false; | |
4270 } | |
4271 | 4266 |
4272 return true; | 4267 return ParseQualifiedNameResult(PQNNoException); |
4273 } | 4268 } |
4274 | 4269 |
4275 bool Document::parseQualifiedName(const AtomicString& qualifiedName, AtomicStrin g& prefix, AtomicString& localName, ExceptionState& exceptionState) | 4270 bool Document::parseQualifiedName(const AtomicString& qualifiedName, AtomicStrin g& prefix, AtomicString& localName, ExceptionState& exceptionState) |
4276 { | 4271 { |
4277 unsigned length = qualifiedName.length(); | 4272 unsigned length = qualifiedName.length(); |
4278 | 4273 |
4279 if (!length) { | 4274 if (!length) { |
4280 exceptionState.throwDOMException(InvalidCharacterError, "The qualified n ame provided is empty."); | 4275 exceptionState.throwDOMException(InvalidCharacterError, "The qualified n ame provided is empty."); |
4281 return false; | 4276 return false; |
4282 } | 4277 } |
4283 | 4278 |
4279 ParseQualifiedNameResult returnValue; | |
4284 if (qualifiedName.is8Bit()) | 4280 if (qualifiedName.is8Bit()) |
4285 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, exceptionState); | 4281 returnValue = parseQualifiedNameInternal(qualifiedName, qualifiedName.ch aracters8(), length, prefix, localName); |
4286 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, exceptionState); | 4282 else |
4283 returnValue = parseQualifiedNameInternal(qualifiedName, qualifiedName.ch aracters16(), length, prefix, localName); | |
4284 if (returnValue.result == PQNNoException) | |
4285 return true; | |
4286 | |
4287 StringBuilder message; | |
4288 message.appendLiteral("The qualified name provided ('"); | |
4289 message.append(qualifiedName); | |
4290 message.appendLiteral("') "); | |
4291 | |
4292 if (returnValue.result == PQNMultipleColonsException) { | |
fs
2014/09/11 09:17:48
I suspect that using a switch here might give slig
| |
4293 message.appendLiteral("contains multiple colons."); | |
4294 } else if (returnValue.result == PQNInvalidStartCharException) { | |
4295 message.appendLiteral("contains the invalid name-start character '"); | |
4296 message.append(returnValue.character); | |
4297 message.appendLiteral("'."); | |
4298 } else if (returnValue.result == PQNInvalidCharException) { | |
4299 message.appendLiteral("contains the invalid character '"); | |
4300 message.append(returnValue.character); | |
4301 message.appendLiteral("'."); | |
4302 } else if (returnValue.result == PQNEmptyPrefix) { | |
4303 message.appendLiteral("has an empty namespace prefix."); | |
4304 } else { | |
4305 ASSERT(returnValue.result == PQNEmptyLocalName); | |
4306 message.appendLiteral("has an empty local name."); | |
4307 } | |
4308 | |
4309 if (returnValue.result == PQNInvalidStartCharException || returnValue.result == PQNInvalidCharException) | |
4310 exceptionState.throwDOMException(InvalidCharacterError, message.toString ()); | |
4311 else | |
4312 exceptionState.throwDOMException(NamespaceError, message.toString()); | |
4313 return false; | |
4287 } | 4314 } |
4288 | 4315 |
4289 void Document::setEncodingData(const DocumentEncodingData& newData) | 4316 void Document::setEncodingData(const DocumentEncodingData& newData) |
4290 { | 4317 { |
4291 // It's possible for the encoding of the document to change while we're deco ding | 4318 // It's possible for the encoding of the document to change while we're deco ding |
4292 // data. That can only occur while we're processing the <head> portion of th e | 4319 // data. That can only occur while we're processing the <head> portion of th e |
4293 // document. There isn't much user-visible content in the <head>, but there is | 4320 // document. There isn't much user-visible content in the <head>, but there is |
4294 // the <title> element. This function detects that situation and re-decodes the | 4321 // the <title> element. This function detects that situation and re-decodes the |
4295 // document's title so that the user doesn't see an incorrectly decoded titl e | 4322 // document's title so that the user doesn't see an incorrectly decoded titl e |
4296 // in the title bar. | 4323 // in the title bar. |
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5851 using namespace blink; | 5878 using namespace blink; |
5852 void showLiveDocumentInstances() | 5879 void showLiveDocumentInstances() |
5853 { | 5880 { |
5854 WeakDocumentSet& set = liveDocumentSet(); | 5881 WeakDocumentSet& set = liveDocumentSet(); |
5855 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 5882 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
5856 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { | 5883 for (WeakDocumentSet::const_iterator it = set.begin(); it != set.end(); ++it ) { |
5857 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); | 5884 fprintf(stderr, "- Document %p URL: %s\n", *it, (*it)->url().string().ut f8().data()); |
5858 } | 5885 } |
5859 } | 5886 } |
5860 #endif | 5887 #endif |
OLD | NEW |