WebKit并不是完全开源的, Apple封装了一部代码在一个静态库(libWebKitSystemInterfaceXXXX.a)中,并没有提供源代码。而且不同版本的OS (包括iOS),会有特定的版本。
这就是我今天从分析中了解到的, 觉得过程比较有趣,记录一下。
1. 在WebKit中有这样一段源代码 (Laguage.mm):
static String httpStyleLanguageCode(NSString *languageCode) { ASSERT(isMainThread()); // Look up the language code using CFBundle. RetainPtr<CFStringRef> preferredLanguageCode(AdoptCF, wkCopyCFLocalizationPreferredName((CFStringRef)languageCode));
extern CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
(lldb) p wkCopyCFLocalizationPreferredName (CFStringRef (*)(CFStringRef)) $0 = 0x0000000100478a49 (WebKit2`WKCopyCFLocalizationPreferredName) (lldb) image lookup -s WKCopyCFLocalizationPreferredName 1 symbols match 'WKCopyCFLocalizationPreferredName' in /Volumes/Data/Project/Webkit/webkitSvn/Build/Products/Debug/WebKit2.framework/Versions/A/WebKit2: Address: WebKit2[0x0000000000464a49] (WebKit2.__TEXT.__text + 4600745) Summary: WebKit2`WKCopyCFLocalizationPreferredName 1 symbols match 'WKCopyCFLocalizationPreferredName' in /Volumes/Data/Project/Webkit/webkitSvn/Build/Products/Debug/WebKit.framework/Versions/A/WebKit: Address: WebKit[0x00000000001b8275] (WebKit.__TEXT.__text + 1795141) Summary: WebKit`WKCopyCFLocalizationPreferredName
nm -a libWebKitSystemInterfaceLion.a /XXXXXX/Build/Products/Debug/libWebKitSystemInterfaceLion.a(WebKitSystemInterface.o): 0000000000002591 t -[NSWindowGraphicsContext(WebKitSystemInterface) _WebKitSystemInterface_setGraphicsPort:] 0000000000008d98 s -[NSWindowGraphicsContext(WebKitSystemInterface) _WebKitSystemInterface_setGraphicsPort:].eh 00000000000090a8 S _WKCopyBundleURLForExecutableURL.eh 00000000000006c7 T _WKCopyCFLocalizationPreferredName 0000000000008200 S _WKCopyCFLocalizationPreferredName.eh
function _WKCopyCFLocalizationPreferredName { CFBundleGetLocalizationInfoForLocalization(arg_0, &var_32, &var_28, &var_24, &var_20); rax = CFBundleCopyLocalizationForLocalizationInfo(var_32, var_28, var_24, var_20); return rax; }
extern "C" { CF_EXPORT Boolean CFBundleGetLocalizationInfoForLocalization(CFStringRef localizationName, SInt32 *languageCode, SInt32 *regionCode, SInt32 *scriptCode, CFStringEncoding *stringEncoding); CF_EXPORT CFStringRef CFBundleCopyLocalizationForLocalizationInfo(SInt32 languageCode, SInt32 regionCode, SInt32 scriptCode, CFStringEncoding stringEncoding); }