Changeset 84033 in webkit


Ignore:
Timestamp:
Apr 15, 2011 2:18:20 PM (13 years ago)
Author:
weinig@apple.com
Message:

2011-04-15 Sam Weinig <sam@webkit.org>

Reviewed by Adam Roben.

Implement localize strings for windows WebKit2
https://bugs.webkit.org/show_bug.cgi?id=58688

  • platform/win/LocalizedStringsWin.cpp: (WebCore::createWebKitBundle): (WebCore::webKitBundle): (WebCore::localizedString): Add implementation of localizedString for Windows.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84029 r84033  
     12011-04-15  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Adam Roben.
     4
     5        Implement localize strings for windows WebKit2
     6        https://bugs.webkit.org/show_bug.cgi?id=58688
     7
     8        * platform/win/LocalizedStringsWin.cpp:
     9        (WebCore::createWebKitBundle):
     10        (WebCore::webKitBundle):
     11        (WebCore::localizedString):
     12        Add implementation of localizedString for Windows.
     13
    1142011-04-15  Geoffrey Garen  <ggaren@apple.com>
    215
  • trunk/Source/WebCore/platform/win/LocalizedStringsWin.cpp

    r82465 r84033  
    2727#include "LocalizedStrings.h"
    2828
     29#include "WebCoreInstanceHandle.h"
     30#include <CoreFoundation/CFBundle.h>
     31#include <wtf/Assertions.h>
     32#include <wtf/RetainPtr.h>
     33#include <wtf/StdLibExtras.h>
     34#include <wtf/Threading.h>
    2935#include <wtf/text/WTFString.h>
    3036
    3137namespace WebCore {
    3238
     39static CFBundleRef createWebKitBundle()
     40{
     41    if (CFBundleRef existingBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"))) {
     42        CFRetain(existingBundle);
     43        return existingBundle;
     44    }
     45
     46    wchar_t dllPathBuffer[MAX_PATH];
     47    DWORD length = ::GetModuleFileNameW(instanceHandle(), dllPathBuffer, WTF_ARRAY_LENGTH(dllPathBuffer));
     48    ASSERT(length);
     49    ASSERT(length < WTF_ARRAY_LENGTH(dllPathBuffer));
     50
     51    RetainPtr<CFStringRef> dllPath(AdoptCF, CFStringCreateWithCharactersNoCopy(0, reinterpret_cast<const UniChar*>(dllPathBuffer), length, kCFAllocatorNull));
     52    RetainPtr<CFURLRef> dllURL(AdoptCF, CFURLCreateWithFileSystemPath(0, dllPath.get(), kCFURLWindowsPathStyle, false));
     53    RetainPtr<CFURLRef> dllDirectoryURL(AdoptCF, CFURLCreateCopyDeletingLastPathComponent(0, dllURL.get()));
     54    RetainPtr<CFURLRef> resourcesDirectoryURL(AdoptCF, CFURLCreateCopyAppendingPathComponent(0, dllDirectoryURL.get(), CFSTR("WebKit.resources"), true));
     55
     56    return CFBundleCreate(0, resourcesDirectoryURL.get());
     57}
     58
     59static CFBundleRef webKitBundle()
     60{
     61    static CFBundleRef bundle = createWebKitBundle();
     62    ASSERT(bundle);
     63    return bundle;
     64}
     65
    3366String localizedString(const char* key)
    3467{
    35     // FIXME: <rdar://problem/9119405> Win: WebKit2 needs to be made localizable
    36     return String::fromUTF8(key, strlen(key));
     68    ASSERT(isMainThread());
     69
     70    static CFStringRef notFound = CFSTR("localized string not found");
     71
     72    RetainPtr<CFStringRef> keyString(AdoptCF, CFStringCreateWithCStringNoCopy(NULL, key, kCFStringEncodingUTF8, kCFAllocatorNull));
     73    RetainPtr<CFStringRef> result(AdoptCF, CFCopyLocalizedStringWithDefaultValue(keyString.get(), 0, webKitBundle(), notFound, 0));
     74    ASSERT_WITH_MESSAGE(result.get() != notFound, "could not find localizable string %s in bundle", key);
     75
     76    return result.get();
    3777}
    3878
Note: See TracChangeset for help on using the changeset viewer.