Changeset 38333 in webkit


Ignore:
Timestamp:
Nov 12, 2008 2:51:27 AM (15 years ago)
Author:
vestbo@webkit.org
Message:

2008-11-10 Tor Arne Vestbø <tavestbo@trolltech.com>

Reviewed by Simon Hausmann.

Move _web_encodingForResource from WebKit into WebCore and change return type

This change is needed to implement NSAPI in WebCore for Mac, see:

https://bugs.webkit.org/show_bug.cgi?id=21427

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r38332 r38333  
     12008-11-10  Tor Arne Vestbø  <tavestbo@trolltech.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Move _web_encodingForResource from WebKit into WebCore and change return type
     6
     7        This change is needed to implement NSAPI in WebCore for Mac, see:
     8
     9        https://bugs.webkit.org/show_bug.cgi?id=21427
     10
     11        * WebCore.base.exp:
     12        * platform/mac/WebCoreNSStringExtras.h:
     13        * platform/mac/WebCoreNSStringExtras.mm:
     14        (stringEncodingForResource):
     15
    1162008-11-10  Tor Arne Vestbø  <tavestbo@trolltech.com>
    217
  • trunk/WebCore/WebCore.base.exp

    r38332 r38333  
    889889_hasCaseInsensitiveSubstring
    890890_hasCaseInsensitiveSuffix
     891_stringEncodingForResource
    891892_stringIsCaseInsensitiveEqualToString
    892893_suggestedFilenameWithMIMEType
  • trunk/WebCore/platform/mac/WebCoreNSStringExtras.h

    r38332 r38333  
    2727 */
    2828
    29 #import <Cocoa/Cocoa.h>
     29#include <ApplicationServices/ApplicationServices.h>
     30#include <objc/objc.h>
     31
     32#ifdef __OBJC__
     33#include <Foundation/Foundation.h>
     34@class NSString;
     35#else
     36typedef struct NSString NSString;
     37#endif
    3038
    3139#ifdef __cplusplus
     
    3745BOOL hasCaseInsensitiveSubstring(NSString *string, NSString *substring);
    3846NSString *filenameByFixingIllegalCharacters(NSString *string);
     47CFStringEncoding stringEncodingForResource(Handle resource);
    3948
    4049#ifdef __cplusplus
  • trunk/WebCore/platform/mac/WebCoreNSStringExtras.mm

    r38332 r38333  
    6666    return filename;
    6767}
     68
     69CFStringEncoding stringEncodingForResource(Handle resource)
     70{
     71    short resRef = HomeResFile(resource);
     72    if (ResError() != noErr) {
     73        return NSMacOSRomanStringEncoding;
     74    }
     75   
     76    // Get the FSRef for the current resource file
     77    FSRef fref;
     78    OSStatus error = FSGetForkCBInfo(resRef, 0, NULL, NULL, NULL, &fref, NULL);
     79    if (error != noErr) {
     80        return NSMacOSRomanStringEncoding;
     81    }
     82   
     83    CFURLRef URL = CFURLCreateFromFSRef(NULL, &fref);
     84    if (URL == NULL) {
     85        return NSMacOSRomanStringEncoding;
     86    }
     87   
     88    NSString *path = [(NSURL *)URL path];
     89    CFRelease(URL);
     90   
     91    // Get the lproj directory name
     92    path = [path stringByDeletingLastPathComponent];
     93    if (!stringIsCaseInsensitiveEqualToString([path pathExtension], @"lproj")) {
     94        return NSMacOSRomanStringEncoding;
     95    }
     96   
     97    NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
     98    CFStringRef locale = CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName);
     99    if (locale == NULL) {
     100        return NSMacOSRomanStringEncoding;
     101    }
     102           
     103    LangCode lang;
     104    RegionCode region;
     105    error = LocaleStringToLangAndRegionCodes([(NSString *)locale UTF8String], &lang, &region);
     106    CFRelease(locale);
     107    if (error != noErr) {
     108        return NSMacOSRomanStringEncoding;
     109    }
     110   
     111    TextEncoding encoding;
     112    error = UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, lang, region, NULL, &encoding);
     113    if (error != noErr) {
     114        return NSMacOSRomanStringEncoding;
     115    }
     116   
     117    return encoding;
     118}
     119
  • trunk/WebKit/mac/ChangeLog

    r38332 r38333  
     12008-11-10  Tor Arne Vestbø  <tavestbo@trolltech.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Move _web_encodingForResource from WebKit into WebCore and change return type
     6
     7        This change is needed to implement NSAPI in WebCore for Mac, see:
     8
     9        https://bugs.webkit.org/show_bug.cgi?id=21427
     10
     11
     12        * Misc/WebKitNSStringExtras.m:
     13        (+[NSString _web_encodingForResource:]):
     14
    1152008-11-10  Tor Arne Vestbø  <tavestbo@trolltech.com>
    216
  • trunk/WebKit/mac/Misc/WebKitNSStringExtras.m

    r38332 r38333  
    141141+ (NSStringEncoding)_web_encodingForResource:(Handle)resource
    142142{
    143     short resRef = HomeResFile(resource);
    144     if (ResError() != noErr) {
    145         return NSMacOSRomanStringEncoding;
    146     }
    147    
    148     // Get the FSRef for the current resource file
    149     FSRef fref;
    150     OSStatus error = FSGetForkCBInfo(resRef, 0, NULL, NULL, NULL, &fref, NULL);
    151     if (error != noErr) {
    152         return NSMacOSRomanStringEncoding;
    153     }
    154    
    155     CFURLRef URL = CFURLCreateFromFSRef(NULL, &fref);
    156     if (URL == NULL) {
    157         return NSMacOSRomanStringEncoding;
    158     }
    159    
    160     NSString *path = [(NSURL *)URL path];
    161     CFRelease(URL);
    162    
    163     // Get the lproj directory name
    164     path = [path stringByDeletingLastPathComponent];
    165     if (![[path pathExtension] _webkit_isCaseInsensitiveEqualToString:@"lproj"]) {
    166         return NSMacOSRomanStringEncoding;
    167     }
    168    
    169     NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
    170     CFStringRef locale = CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName);
    171     if (locale == NULL) {
    172         return NSMacOSRomanStringEncoding;
    173     }
    174            
    175     LangCode lang;
    176     RegionCode region;
    177     error = LocaleStringToLangAndRegionCodes([(NSString *)locale UTF8String], &lang, &region);
    178     CFRelease(locale);
    179     if (error != noErr) {
    180         return NSMacOSRomanStringEncoding;
    181     }
    182    
    183     TextEncoding encoding;
    184     error = UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, lang, region, NULL, &encoding);
    185     if (error != noErr) {
    186         return NSMacOSRomanStringEncoding;
    187     }
    188    
    189     return CFStringConvertEncodingToNSStringEncoding(encoding);
     143    return CFStringConvertEncodingToNSStringEncoding(stringEncodingForResource(resource));
    190144}
    191145
Note: See TracChangeset for help on using the changeset viewer.