| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. | 3 * Copyright (C) 2007-2009 Torch Mobile, Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // We don't have to use AtomicallyInitializedStatic here because | 109 // We don't have to use AtomicallyInitializedStatic here because |
| 110 // this function is called on the main thread for any page before | 110 // this function is called on the main thread for any page before |
| 111 // it is used in worker threads. | 111 // it is used in worker threads. |
| 112 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); | 112 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); |
| 113 return mutex; | 113 return mutex; |
| 114 } | 114 } |
| 115 | 115 |
| 116 static TextEncodingNameMap* textEncodingNameMap; | 116 static TextEncodingNameMap* textEncodingNameMap; |
| 117 static TextCodecMap* textCodecMap; | 117 static TextCodecMap* textCodecMap; |
| 118 static bool didExtendTextCodecMaps; | 118 static bool didExtendTextCodecMaps; |
| 119 static HashSet<const char*>* japaneseEncodings; | |
| 120 static HashSet<const char*>* nonBackslashEncodings; | |
| 121 | 119 |
| 122 static const char textEncodingNameBlacklist[][6] = { "UTF-7" }; | 120 static const char textEncodingNameBlacklist[][6] = { "UTF-7" }; |
| 123 | 121 |
| 124 #if ERROR_DISABLED | 122 #if ERROR_DISABLED |
| 125 | 123 |
| 126 static inline void checkExistingName(const char*, const char*) { } | 124 static inline void checkExistingName(const char*, const char*) { } |
| 127 | 125 |
| 128 #else | 126 #else |
| 129 | 127 |
| 130 static void checkExistingName(const char* alias, const char* atomicName) | 128 static void checkExistingName(const char* alias, const char* atomicName) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 TextCodecUTF8::registerEncodingNames(addToTextEncodingNameMap); | 212 TextCodecUTF8::registerEncodingNames(addToTextEncodingNameMap); |
| 215 TextCodecUTF8::registerCodecs(addToTextCodecMap); | 213 TextCodecUTF8::registerCodecs(addToTextCodecMap); |
| 216 | 214 |
| 217 TextCodecUTF16::registerEncodingNames(addToTextEncodingNameMap); | 215 TextCodecUTF16::registerEncodingNames(addToTextEncodingNameMap); |
| 218 TextCodecUTF16::registerCodecs(addToTextCodecMap); | 216 TextCodecUTF16::registerCodecs(addToTextCodecMap); |
| 219 | 217 |
| 220 TextCodecUserDefined::registerEncodingNames(addToTextEncodingNameMap); | 218 TextCodecUserDefined::registerEncodingNames(addToTextEncodingNameMap); |
| 221 TextCodecUserDefined::registerCodecs(addToTextCodecMap); | 219 TextCodecUserDefined::registerCodecs(addToTextCodecMap); |
| 222 } | 220 } |
| 223 | 221 |
| 224 static void addEncodingName(HashSet<const char*>* set, const char* name) | |
| 225 { | |
| 226 // We must not use atomicCanonicalTextEncodingName() because this function i
s called in it. | |
| 227 const char* atomicName = textEncodingNameMap->get(name); | |
| 228 if (atomicName) | |
| 229 set->add(atomicName); | |
| 230 } | |
| 231 | |
| 232 static void buildQuirksSets() | |
| 233 { | |
| 234 // FIXME: Having isJapaneseEncoding() and shouldShowBackslashAsCurrencySymbo
lIn() | |
| 235 // and initializing the sets for them in TextEncodingRegistry.cpp look stran
ge. | |
| 236 | |
| 237 ASSERT(!japaneseEncodings); | |
| 238 ASSERT(!nonBackslashEncodings); | |
| 239 | |
| 240 japaneseEncodings = new HashSet<const char*>; | |
| 241 addEncodingName(japaneseEncodings, "EUC-JP"); | |
| 242 addEncodingName(japaneseEncodings, "ISO-2022-JP"); | |
| 243 addEncodingName(japaneseEncodings, "ISO-2022-JP-1"); | |
| 244 addEncodingName(japaneseEncodings, "ISO-2022-JP-2"); | |
| 245 addEncodingName(japaneseEncodings, "ISO-2022-JP-3"); | |
| 246 addEncodingName(japaneseEncodings, "JIS_C6226-1978"); | |
| 247 addEncodingName(japaneseEncodings, "JIS_X0201"); | |
| 248 addEncodingName(japaneseEncodings, "JIS_X0208-1983"); | |
| 249 addEncodingName(japaneseEncodings, "JIS_X0208-1990"); | |
| 250 addEncodingName(japaneseEncodings, "JIS_X0212-1990"); | |
| 251 addEncodingName(japaneseEncodings, "Shift_JIS"); | |
| 252 addEncodingName(japaneseEncodings, "Shift_JIS_X0213-2000"); | |
| 253 addEncodingName(japaneseEncodings, "cp932"); | |
| 254 addEncodingName(japaneseEncodings, "x-mac-japanese"); | |
| 255 | |
| 256 nonBackslashEncodings = new HashSet<const char*>; | |
| 257 // The text encodings below treat backslash as a currency symbol for IE comp
atibility. | |
| 258 // See http://blogs.msdn.com/michkap/archive/2005/09/17/469941.aspx for more
information. | |
| 259 addEncodingName(nonBackslashEncodings, "x-mac-japanese"); | |
| 260 addEncodingName(nonBackslashEncodings, "ISO-2022-JP"); | |
| 261 addEncodingName(nonBackslashEncodings, "EUC-JP"); | |
| 262 // Shift_JIS_X0213-2000 is not the same encoding as Shift_JIS on Mac. We nee
d to register both of them. | |
| 263 addEncodingName(nonBackslashEncodings, "Shift_JIS"); | |
| 264 addEncodingName(nonBackslashEncodings, "Shift_JIS_X0213-2000"); | |
| 265 } | |
| 266 | |
| 267 bool isJapaneseEncoding(const char* canonicalEncodingName) | |
| 268 { | |
| 269 return canonicalEncodingName && japaneseEncodings && japaneseEncodings->cont
ains(canonicalEncodingName); | |
| 270 } | |
| 271 | |
| 272 bool isReplacementEncoding(const char* alias) | 222 bool isReplacementEncoding(const char* alias) |
| 273 { | 223 { |
| 274 return alias && !strcasecmp(alias, "replacement"); | 224 return alias && !strcasecmp(alias, "replacement"); |
| 275 } | 225 } |
| 276 | 226 |
| 277 bool isReplacementEncoding(const String& alias) | 227 bool isReplacementEncoding(const String& alias) |
| 278 { | 228 { |
| 279 return alias == "replacement"; | 229 return alias == "replacement"; |
| 280 } | 230 } |
| 281 | 231 |
| 282 bool shouldShowBackslashAsCurrencySymbolIn(const char* canonicalEncodingName) | |
| 283 { | |
| 284 return canonicalEncodingName && nonBackslashEncodings && nonBackslashEncodin
gs->contains(canonicalEncodingName); | |
| 285 } | |
| 286 | |
| 287 static void extendTextCodecMaps() | 232 static void extendTextCodecMaps() |
| 288 { | 233 { |
| 289 TextCodecReplacement::registerEncodingNames(addToTextEncodingNameMap); | 234 TextCodecReplacement::registerEncodingNames(addToTextEncodingNameMap); |
| 290 TextCodecReplacement::registerCodecs(addToTextCodecMap); | 235 TextCodecReplacement::registerCodecs(addToTextCodecMap); |
| 291 | 236 |
| 292 TextCodecICU::registerEncodingNames(addToTextEncodingNameMap); | 237 TextCodecICU::registerEncodingNames(addToTextEncodingNameMap); |
| 293 TextCodecICU::registerCodecs(addToTextCodecMap); | 238 TextCodecICU::registerCodecs(addToTextCodecMap); |
| 294 | 239 |
| 295 pruneBlacklistedCodecs(); | 240 pruneBlacklistedCodecs(); |
| 296 buildQuirksSets(); | |
| 297 } | 241 } |
| 298 | 242 |
| 299 PassOwnPtr<TextCodec> newTextCodec(const TextEncoding& encoding) | 243 PassOwnPtr<TextCodec> newTextCodec(const TextEncoding& encoding) |
| 300 { | 244 { |
| 301 MutexLocker lock(encodingRegistryMutex()); | 245 MutexLocker lock(encodingRegistryMutex()); |
| 302 | 246 |
| 303 ASSERT(textCodecMap); | 247 ASSERT(textCodecMap); |
| 304 TextCodecFactory factory = textCodecMap->get(encoding.name()); | 248 TextCodecFactory factory = textCodecMap->get(encoding.name()); |
| 305 ASSERT(factory.function); | 249 ASSERT(factory.function); |
| 306 return factory.function(encoding, factory.additionalData); | 250 return factory.function(encoding, factory.additionalData); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 MutexLocker lock(encodingRegistryMutex()); | 309 MutexLocker lock(encodingRegistryMutex()); |
| 366 | 310 |
| 367 TextEncodingNameMap::const_iterator it = textEncodingNameMap->begin(); | 311 TextEncodingNameMap::const_iterator it = textEncodingNameMap->begin(); |
| 368 TextEncodingNameMap::const_iterator end = textEncodingNameMap->end(); | 312 TextEncodingNameMap::const_iterator end = textEncodingNameMap->end(); |
| 369 for (; it != end; ++it) | 313 for (; it != end; ++it) |
| 370 fprintf(stderr, "'%s' => '%s'\n", it->key, it->value); | 314 fprintf(stderr, "'%s' => '%s'\n", it->key, it->value); |
| 371 } | 315 } |
| 372 #endif | 316 #endif |
| 373 | 317 |
| 374 } // namespace WTF | 318 } // namespace WTF |
| OLD | NEW |