[Win] Use WCharStringExtras functions in WebCore
authordon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Dec 2017 01:10:52 +0000 (01:10 +0000)
committerdon.olmstead@sony.com <don.olmstead@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Dec 2017 01:10:52 +0000 (01:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180963

Reviewed by Alex Christensen.

No new tests. No change in behavior.

* platform/graphics/win/FontCacheWin.cpp:
(WebCore::appendLinkedFonts):
(WebCore::getLinkedFonts):
(WebCore::FontCache::systemFallbackForCharacters):
(WebCore::FontCache::fontFromDescriptionAndLogFont):
* platform/graphics/win/FontCustomPlatformDataCairo.cpp:
(WebCore::FontCustomPlatformData::fontPlatformData):
* platform/graphics/win/IconWin.cpp:
(WebCore::Icon::createIconForFiles):
* platform/network/win/DownloadBundleWin.cpp:
(WebCore::DownloadBundle::appendResumeData):
(WebCore::DownloadBundle::extractResumeData):
* platform/text/win/LocaleWin.cpp:
(WebCore::LCIDFromLocaleInternal):
(WebCore::LCIDFromLocale):
* platform/win/ClipboardUtilitiesWin.cpp:
(WebCore::getWebLocData):
(WebCore::createGlobalData):
(WebCore::getFileDescriptorData):
(WebCore::getURL):
(WebCore::getCFData):
(WebCore::setCFData):
* platform/win/DragDataWin.cpp:
(WebCore::DragData::asFilenames const):
* platform/win/DragImageWin.cpp:
(WebCore::createDragImageIconForCachedImageFilename):
(WebCore::dragLabelFont):
* platform/win/FileSystemWin.cpp:
(WebCore::FileSystem::getFindData):
(WebCore::FileSystem::createSymbolicLink):
(WebCore::FileSystem::deleteFile):
(WebCore::FileSystem::deleteEmptyDirectory):
(WebCore::FileSystem::moveFile):
(WebCore::FileSystem::pathByAppendingComponent):
(WebCore::FileSystem::makeAllDirectories):
(WebCore::FileSystem::pathGetFileName):
(WebCore::FileSystem::openTemporaryFile):
(WebCore::FileSystem::openFile):
(WebCore::FileSystem::hardLinkOrCopyFile):
* platform/win/MIMETypeRegistryWin.cpp:
(WebCore::mimeTypeForExtension):
(WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::read):
(WebCore::createGlobalHDropContent):
* platform/win/PathWalker.cpp:
(WebCore::PathWalker::PathWalker):
* platform/win/SSLKeyGeneratorWin.cpp:
(WebCore::WebCore::signedPublicKeyAndChallengeString):
* platform/win/SharedBufferWin.cpp:
(WebCore::SharedBuffer::createFromReadingFile):
* rendering/RenderThemeWin.cpp:
(WebCore::fillFontDescription):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226205 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/FontCacheWin.cpp
Source/WebCore/platform/graphics/win/FontCustomPlatformDataCairo.cpp
Source/WebCore/platform/graphics/win/IconWin.cpp
Source/WebCore/platform/network/win/DownloadBundleWin.cpp
Source/WebCore/platform/text/win/LocaleWin.cpp
Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp
Source/WebCore/platform/win/DragDataWin.cpp
Source/WebCore/platform/win/DragImageWin.cpp
Source/WebCore/platform/win/FileSystemWin.cpp
Source/WebCore/platform/win/MIMETypeRegistryWin.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/platform/win/PathWalker.cpp
Source/WebCore/platform/win/SSLKeyGeneratorWin.cpp
Source/WebCore/platform/win/SharedBufferWin.cpp
Source/WebCore/rendering/RenderThemeWin.cpp

index bfc64c1..9902c7c 100644 (file)
@@ -1,3 +1,66 @@
+2017-12-20  Don Olmstead  <don.olmstead@sony.com>
+
+        [Win] Use WCharStringExtras functions in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=180963
+
+        Reviewed by Alex Christensen.
+
+        No new tests. No change in behavior.
+
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::appendLinkedFonts):
+        (WebCore::getLinkedFonts):
+        (WebCore::FontCache::systemFallbackForCharacters):
+        (WebCore::FontCache::fontFromDescriptionAndLogFont):
+        * platform/graphics/win/FontCustomPlatformDataCairo.cpp:
+        (WebCore::FontCustomPlatformData::fontPlatformData):
+        * platform/graphics/win/IconWin.cpp:
+        (WebCore::Icon::createIconForFiles):
+        * platform/network/win/DownloadBundleWin.cpp:
+        (WebCore::DownloadBundle::appendResumeData):
+        (WebCore::DownloadBundle::extractResumeData):
+        * platform/text/win/LocaleWin.cpp:
+        (WebCore::LCIDFromLocaleInternal):
+        (WebCore::LCIDFromLocale):
+        * platform/win/ClipboardUtilitiesWin.cpp:
+        (WebCore::getWebLocData):
+        (WebCore::createGlobalData):
+        (WebCore::getFileDescriptorData):
+        (WebCore::getURL):
+        (WebCore::getCFData):
+        (WebCore::setCFData):
+        * platform/win/DragDataWin.cpp:
+        (WebCore::DragData::asFilenames const):
+        * platform/win/DragImageWin.cpp:
+        (WebCore::createDragImageIconForCachedImageFilename):
+        (WebCore::dragLabelFont):
+        * platform/win/FileSystemWin.cpp:
+        (WebCore::FileSystem::getFindData):
+        (WebCore::FileSystem::createSymbolicLink):
+        (WebCore::FileSystem::deleteFile):
+        (WebCore::FileSystem::deleteEmptyDirectory):
+        (WebCore::FileSystem::moveFile):
+        (WebCore::FileSystem::pathByAppendingComponent):
+        (WebCore::FileSystem::makeAllDirectories):
+        (WebCore::FileSystem::pathGetFileName):
+        (WebCore::FileSystem::openTemporaryFile):
+        (WebCore::FileSystem::openFile):
+        (WebCore::FileSystem::hardLinkOrCopyFile):
+        * platform/win/MIMETypeRegistryWin.cpp:
+        (WebCore::mimeTypeForExtension):
+        (WebCore::MIMETypeRegistry::getPreferredExtensionForMIMEType):
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::read):
+        (WebCore::createGlobalHDropContent):
+        * platform/win/PathWalker.cpp:
+        (WebCore::PathWalker::PathWalker):
+        * platform/win/SSLKeyGeneratorWin.cpp:
+        (WebCore::WebCore::signedPublicKeyAndChallengeString):
+        * platform/win/SharedBufferWin.cpp:
+        (WebCore::SharedBuffer::createFromReadingFile):
+        * rendering/RenderThemeWin.cpp:
+        (WebCore::fillFontDescription):
+
 2017-12-20  Youenn Fablet  <youenn@apple.com>
 
         com.apple.WebKit.WebContent.Development crashed in com.apple.WebCore: WebCore::UserMediaRequest::stop + 126
index b861a5c..2b8a1c7 100644 (file)
@@ -39,6 +39,7 @@
 #include <wtf/text/CString.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/StringView.h>
+#include <wtf/text/win/WCharStringExtras.h>
 #include <wtf/win/GDIObject.h>
 
 #if USE(CG)
@@ -113,7 +114,7 @@ WEBCORE_EXPORT void appendLinkedFonts(WCHAR* linkedFonts, unsigned length, Vecto
         unsigned j = i;
         while (j < length && linkedFonts[j])
             j++;
-        result->append(String(linkedFonts + i, j - i));
+        result->append(wcharToString(linkedFonts + i, j - i));
         i = j + 1;
     }
 }
@@ -132,14 +133,14 @@ static const Vector<String>* getLinkedFonts(String& family)
         return result;
 
     DWORD linkedFontsBufferSize = 0;
-    if (::RegQueryValueEx(fontLinkKey, family.charactersWithNullTermination().data(), 0, nullptr, nullptr, &linkedFontsBufferSize) == ERROR_FILE_NOT_FOUND) {
+    if (::RegQueryValueEx(fontLinkKey, stringToNullTerminatedWChar(family).data(), 0, nullptr, nullptr, &linkedFontsBufferSize) == ERROR_FILE_NOT_FOUND) {
         WTFLogAlways("The font link key %s does not exist in the registry.", family.utf8().data());
         return result;
     }
 
     static const constexpr unsigned InitialBufferSize { 256 / sizeof(WCHAR) };
     Vector<WCHAR, InitialBufferSize> linkedFonts(roundUpToMultipleOf<sizeof(WCHAR)>(linkedFontsBufferSize) / sizeof(WCHAR));
-    if (::RegQueryValueEx(fontLinkKey, family.charactersWithNullTermination().data(), 0, nullptr, reinterpret_cast<BYTE*>(linkedFonts.data()), &linkedFontsBufferSize) == ERROR_SUCCESS) {
+    if (::RegQueryValueEx(fontLinkKey, stringToNullTerminatedWChar(family).data(), 0, nullptr, reinterpret_cast<BYTE*>(linkedFonts.data()), &linkedFontsBufferSize) == ERROR_SUCCESS) {
         unsigned length = linkedFontsBufferSize / sizeof(WCHAR);
         appendLinkedFonts(linkedFonts.data(), length, result);
     }
@@ -286,7 +287,7 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
         SelectObject(hdc, hfont);
         WCHAR name[LF_FACESIZE];
         GetTextFace(hdc, LF_FACESIZE, name);
-        familyName = name;
+        familyName = nullTerminatedWCharToString(name);
 
         if (containsCharacter || currentFontContainsCharacter(hdc, character))
             break;
@@ -331,7 +332,7 @@ Vector<String> FontCache::systemFontFamilies()
 
 RefPtr<Font> FontCache::fontFromDescriptionAndLogFont(const FontDescription& fontDescription, const LOGFONT& font, AtomicString& outFontFamilyName)
 {
-    AtomicString familyName = String(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
+    AtomicString familyName = wcharToString(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
     RefPtr<Font> fontData = fontForFamily(fontDescription, familyName);
     if (fontData)
         outFontFamilyName = familyName;
index b60d514..c63feec 100644 (file)
@@ -29,6 +29,7 @@
 #include <cairo-win32.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/text/Base64.h>
+#include <wtf/text/win/WCharStringExtras.h>
 #include <wtf/win/GDIObject.h>
 
 namespace WebCore {
@@ -46,7 +47,7 @@ FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription&
 
     LOGFONT logFont;
     memset(&logFont, 0, sizeof(LOGFONT));
-    wcsncpy(logFont.lfFaceName, m_name.charactersWithNullTermination().data(), LF_FACESIZE - 1);
+    wcsncpy(logFont.lfFaceName, stringToNullTerminatedWChar(m_name).data(), LF_FACESIZE - 1);
 
     logFont.lfHeight = -size;
     if (renderingMode == FontRenderingMode::Normal)
index a3946ca..799e347 100644 (file)
@@ -26,6 +26,7 @@
 #include "LocalWindowsContext.h"
 #include <windows.h>
 #include <wtf/text/WTFString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -53,7 +54,7 @@ RefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames)
         memset(&sfi, 0, sizeof(sfi));
 
         String tmpFilename = filenames[0];
-        if (!SHGetFileInfo(tmpFilename.charactersWithNullTermination().data(), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_SMALLICON))
+        if (!SHGetFileInfo(stringToNullTerminatedWChar(tmpFilename).data(), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_SMALLICON))
             return 0;
 
         return adoptRef(new Icon(sfi.hIcon));
index e00de96..3d6b11a 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -60,7 +61,7 @@ bool appendResumeData(const char* resumeBytes, uint32_t resumeLength, const Stri
 
     String nullifiedPath = bundlePath;
     FILE* bundle = 0;
-    if (_wfopen_s(&bundle, nullifiedPath.charactersWithNullTermination().data(), TEXT("ab")) || !bundle) {
+    if (_wfopen_s(&bundle, stringToNullTerminatedWChar(nullifiedPath).data(), TEXT("ab")) || !bundle) {
         LOG_ERROR("Failed to open file %s to append resume data", bundlePath.ascii().data());
         return false;
     }
@@ -99,7 +100,7 @@ bool extractResumeData(const String& bundlePath, Vector<char>& resumeData)
     // Open a handle to the bundle file
     String nullifiedPath = bundlePath;
     FILE* bundle = 0;
-    if (_wfopen_s(&bundle, nullifiedPath.charactersWithNullTermination().data(), TEXT("r+b")) || !bundle) {
+    if (_wfopen_s(&bundle, stringToNullTerminatedWChar(nullifiedPath).data(), TEXT("r+b")) || !bundle) {
         LOG_ERROR("Failed to open file %s to get resume data", bundlePath.ascii().data());
         return false;
     }
index d19693a..b75e76d 100644 (file)
@@ -42,7 +42,7 @@
 #include <wtf/Language.h>
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/StringHash.h>
-
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 using namespace std;
@@ -61,7 +61,7 @@ static LCID LCIDFromLocaleInternal(LCID userDefaultLCID, const String& userDefau
 {
     if (equalIgnoringASCIICase(extractLanguageCode(locale), userDefaultLanguageCode))
         return userDefaultLCID;
-    return LocaleNameToLCID(locale.charactersWithNullTermination().data(), 0);
+    return LocaleNameToLCID(stringToNullTerminatedWChar(locale).data(), 0);
 }
 
 static LCID LCIDFromLocale(const AtomicString& locale)
@@ -70,7 +70,7 @@ static LCID LCIDFromLocale(const AtomicString& locale)
     const size_t languageCodeBufferSize = 9;
     WCHAR lowercaseLanguageCode[languageCodeBufferSize];
     ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, lowercaseLanguageCode, languageCodeBufferSize);
-    String userDefaultLanguageCode = String(lowercaseLanguageCode);
+    String userDefaultLanguageCode = nullTerminatedWCharToString(lowercaseLanguageCode);
 
     LCID lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCode, String(locale));
     if (!lcid)
index 1400af7..75874e7 100644 (file)
@@ -37,7 +37,7 @@
 #include <wtf/Vector.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
-
+#include <wtf/text/win/WCharStringExtras.h>
 
 #if USE(CF)
 #include <CoreFoundation/CoreFoundation.h>
@@ -131,7 +131,7 @@ static bool getWebLocData(const DragDataMap* dataObject, String& url, String* ti
     if (!dataObject->contains(cfHDropFormat()->cfFormat))
         return false;
 
-    wcscpy(filename, dataObject->get(cfHDropFormat()->cfFormat)[0].charactersWithNullTermination().data());
+    wcscpy(filename, stringToNullTerminatedWChar(dataObject->get(cfHDropFormat()->cfFormat)[0]).data());
     if (_wcsicmp(PathFindExtensionW(filename), L".url"))
         return false;    
 
@@ -140,10 +140,10 @@ static bool getWebLocData(const DragDataMap* dataObject, String& url, String* ti
 
     if (title) {
         PathRemoveExtension(filename);
-        *title = filename;
+        *title = nullTerminatedWCharToString(filename);
     }
     
-    url = urlBuffer;
+    url = nullTerminatedWCharToString(urlBuffer);
     return true;
 #else
     return false;
@@ -180,7 +180,7 @@ HGLOBAL createGlobalData(const URL& url, const String& title)
 
     if (cbData) {
         PWSTR buffer = static_cast<PWSTR>(GlobalLock(cbData));
-        _snwprintf(buffer, size, L"%s\n%s", mutableURL.charactersWithNullTermination().data(), mutableTitle.charactersWithNullTermination().data());
+        _snwprintf(buffer, size, L"%s\n%s", stringToNullTerminatedWChar(mutableURL).data(), stringToNullTerminatedWChar(mutableTitle).data());
         GlobalUnlock(cbData);
     }
     return cbData;
@@ -397,7 +397,7 @@ void getFileDescriptorData(IDataObject* dataObject, int& size, String& pathname)
 
     FILEGROUPDESCRIPTOR* fgd = static_cast<FILEGROUPDESCRIPTOR*>(GlobalLock(store.hGlobal));
     size = fgd->fgd[0].nFileSizeLow;
-    pathname = fgd->fgd[0].cFileName;
+    pathname = nullTerminatedWCharToString(fgd->fgd[0].cFileName);
 
     GlobalUnlock(store.hGlobal);
     ::ReleaseStgMedium(&store);
@@ -520,9 +520,9 @@ String getURL(const DragDataMap* data, DragData::FilenameConversionPolicy filena
     if (!getDataMapItem(data, filenameWFormat(), stringData))
         getDataMapItem(data, filenameFormat(), stringData);
 
-    if (stringData.isEmpty() || (!PathFileExists(stringData.charactersWithNullTermination().data()) && !PathIsUNC(stringData.charactersWithNullTermination().data())))
+    if (stringData.isEmpty() || (!PathFileExists(stringToNullTerminatedWChar(stringData).data()) && !PathIsUNC(stringToNullTerminatedWChar(stringData).data())))
         return url;
-    RetainPtr<CFStringRef> pathAsCFString = adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar *)stringData.charactersWithNullTermination().data(), wcslen(stringData.charactersWithNullTermination().data())));
+    RetainPtr<CFStringRef> pathAsCFString = adoptCF(CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar *)stringToNullTerminatedWChar(stringData).data(), wcslen(stringToNullTerminatedWChar(stringData).data())));
     if (urlFromPath(pathAsCFString.get(), url) && title)
         *title = url;
 #endif
@@ -737,7 +737,7 @@ void getCFData(IDataObject* data, FORMATETC* format, Vector<String>& dataStrings
     for (UINT i = 0; i < fileCount; i++) {
         if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
             continue;
-        dataStrings.append(static_cast<UChar*>(filename));
+        dataStrings.append(nullTerminatedWCharToString(filename));
     }
 
     GlobalUnlock(store.hGlobal);
@@ -792,7 +792,7 @@ void setCFData(IDataObject* data, FORMATETC* format, const Vector<String>& dataS
     dropFiles->pFiles = sizeof(DROPFILES);
     dropFiles->fWide = TRUE;
     String filename = dataStrings.first();
-    wcscpy(reinterpret_cast<LPWSTR>(dropFiles + 1), filename.charactersWithNullTermination().data());    
+    wcscpy(reinterpret_cast<LPWSTR>(dropFiles + 1), stringToNullTerminatedWChar(filename).data());
     GlobalUnlock(medium.hGlobal);
     data->SetData(format, &medium, FALSE);
     ::GlobalFree(medium.hGlobal);
index 40a0de9..479e0ca 100644 (file)
@@ -37,6 +37,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -157,7 +158,7 @@ Vector<String> DragData::asFilenames() const
         for (unsigned i = 0; i < numFiles; i++) {
             if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
                 continue;
-            result.append(static_cast<UChar*>(filename)); 
+            result.append(nullTerminatedWCharToString(filename));
         }
 
         // Free up memory from drag
index 6399ea2..f9971e6 100644 (file)
@@ -40,6 +40,7 @@
 #include "TextRun.h"
 #include "WebCoreTextRenderer.h"
 #include <wtf/RetainPtr.h>
+#include <wtf/text/win/WCharStringExtras.h>
 #include <wtf/win/GDIObject.h>
 
 #include <windows.h>
@@ -74,8 +75,7 @@ DragImageRef createDragImageIconForCachedImageFilename(const String& filename)
 {
     SHFILEINFO shfi = {0};
     String fname = filename;
-    if (FAILED(SHGetFileInfo(static_cast<LPCWSTR>(fname.charactersWithNullTermination().data()), FILE_ATTRIBUTE_NORMAL,
-        &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)))
+    if (FAILED(SHGetFileInfo(stringToNullTerminatedWChar(fname).data(), FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES)))
         return 0;
 
     ICONINFO iconInfo;
@@ -112,7 +112,7 @@ static FontCascade dragLabelFont(int size, bool bold, FontRenderingMode renderin
 
     FontCascadeDescription description;
     description.setWeight(bold ? boldWeightValue() : normalWeightValue());
-    description.setOneFamily(metrics.lfSmCaptionFont.lfFaceName);
+    description.setOneFamily(nullTerminatedWCharToString(metrics.lfSmCaptionFont.lfFaceName));
     description.setSpecifiedSize((float)size);
     description.setComputedSize((float)size);
     description.setRenderingMode(renderingMode);
index ee01286..d86a3f3 100644 (file)
@@ -42,6 +42,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -51,7 +52,7 @@ static const ULONGLONG kSecondsFromFileTimeToTimet = 11644473600;
 
 static bool getFindData(String path, WIN32_FIND_DATAW& findData)
 {
-    HANDLE handle = FindFirstFileW(path.charactersWithNullTermination().data(), &findData);
+    HANDLE handle = FindFirstFileW(stringToNullTerminatedWChar(path).data(), &findData);
     if (handle == INVALID_HANDLE_VALUE)
         return false;
     FindClose(handle);
@@ -219,7 +220,7 @@ std::optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path)
 
 bool createSymbolicLink(const String& targetPath, const String& symbolicLinkPath)
 {
-    return !::CreateSymbolicLinkW(symbolicLinkPath.charactersWithNullTermination().data(), targetPath.charactersWithNullTermination().data(), 0);
+    return !::CreateSymbolicLinkW(stringToNullTerminatedWChar(symbolicLinkPath).data(), stringToNullTerminatedWChar(targetPath).data(), 0);
 }
 
 bool fileExists(const String& path)
@@ -231,20 +232,20 @@ bool fileExists(const String& path)
 bool deleteFile(const String& path)
 {
     String filename = path;
-    return !!DeleteFileW(filename.charactersWithNullTermination().data());
+    return !!DeleteFileW(stringToNullTerminatedWChar(filename).data());
 }
 
 bool deleteEmptyDirectory(const String& path)
 {
     String filename = path;
-    return !!RemoveDirectoryW(filename.charactersWithNullTermination().data());
+    return !!RemoveDirectoryW(stringToNullTerminatedWChar(filename).data());
 }
 
 bool moveFile(const String& oldPath, const String& newPath)
 {
     String oldFilename = oldPath;
     String newFilename = newPath;
-    return !!::MoveFileEx(oldFilename.charactersWithNullTermination().data(), newFilename.charactersWithNullTermination().data(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
+    return !!::MoveFileEx(stringToNullTerminatedWChar(oldFilename).data(), stringToNullTerminatedWChar(newFilename).data(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
 }
 
 String pathByAppendingComponent(const String& path, const String& component)
@@ -257,7 +258,7 @@ String pathByAppendingComponent(const String& path, const String& component)
     StringView(path).getCharactersWithUpconvert(buffer.data());
     buffer[path.length()] = '\0';
 
-    if (!PathAppendW(buffer.data(), component.charactersWithNullTermination().data()))
+    if (!PathAppendW(buffer.data(), stringToNullTerminatedWChar(component).data()))
         return String();
 
     buffer.shrink(wcslen(buffer.data()));
@@ -295,7 +296,7 @@ CString fileSystemRepresentation(const String& path)
 bool makeAllDirectories(const String& path)
 {
     String fullPath = path;
-    if (SHCreateDirectoryEx(0, fullPath.charactersWithNullTermination().data(), 0) != ERROR_SUCCESS) {
+    if (SHCreateDirectoryEx(0, stringToNullTerminatedWChar(fullPath).data(), 0) != ERROR_SUCCESS) {
         DWORD error = GetLastError();
         if (error != ERROR_FILE_EXISTS && error != ERROR_ALREADY_EXISTS) {
             LOG_ERROR("Failed to create path %s", path.ascii().data());
@@ -313,7 +314,7 @@ String homeDirectoryPath()
 
 String pathGetFileName(const String& path)
 {
-    return String(::PathFindFileName(String(path).charactersWithNullTermination().data()));
+    return nullTerminatedWCharToString(::PathFindFileName(stringToNullTerminatedWChar(path).data()));
 }
 
 String directoryName(const String& path)
@@ -398,12 +399,12 @@ String openTemporaryFile(const String&, PlatformFileHandle& handle)
 
         ASSERT(wcslen(tempFile) == WTF_ARRAY_LENGTH(tempFile) - 1);
 
-        proposedPath = pathByAppendingComponent(tempPath, tempFile);
+        proposedPath = pathByAppendingComponent(nullTerminatedWCharToString(tempPath), nullTerminatedWCharToString(tempFile));
         if (proposedPath.isEmpty())
             break;
 
         // use CREATE_NEW to avoid overwriting an existing file with the same name
-        handle = ::CreateFileW(proposedPath.charactersWithNullTermination().data(), GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
+        handle = ::CreateFileW(stringToNullTerminatedWChar(proposedPath).data(), GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
     } while (!isHandleValid(handle) && GetLastError() == ERROR_ALREADY_EXISTS);
 
     if (!isHandleValid(handle))
@@ -432,7 +433,7 @@ PlatformFileHandle openFile(const String& path, FileOpenMode mode)
     }
 
     String destination = path;
-    return CreateFile(destination.charactersWithNullTermination().data(), desiredAccess, shareMode, 0, creationDisposition, FILE_ATTRIBUTE_NORMAL, 0);
+    return CreateFile(stringToNullTerminatedWChar(destination).data(), desiredAccess, shareMode, 0, creationDisposition, FILE_ATTRIBUTE_NORMAL, 0);
 }
 
 void closeFile(PlatformFileHandle& handle)
@@ -491,7 +492,7 @@ int readFromFile(PlatformFileHandle handle, char* data, int length)
 
 bool hardLinkOrCopyFile(const String& source, const String& destination)
 {
-    return !!::CopyFile(source.charactersWithNullTermination().data(), destination.charactersWithNullTermination().data(), TRUE);
+    return !!::CopyFile(stringToNullTerminatedWChar(source).data(), stringToNullTerminatedWChar(destination).data(), TRUE);
 }
 
 String localUserSpecificStorageDirectory()
index 73a6270..03c7b76 100644 (file)
@@ -30,6 +30,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
 #include <wtf/WindowsExtras.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -40,10 +41,10 @@ static String mimeTypeForExtension(const String& extension)
     DWORD contentTypeStrLen = sizeof(contentTypeStr);
     DWORD keyType;
 
-    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, ext.charactersWithNullTermination().data(), L"Content Type", &keyType, contentTypeStr, &contentTypeStrLen);
+    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, stringToNullTerminatedWChar(ext).data(), L"Content Type", &keyType, contentTypeStr, &contentTypeStrLen);
 
     if (result == ERROR_SUCCESS && keyType == REG_SZ)
-        return String(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1);
+        return wcharToString(contentTypeStr, contentTypeStrLen / sizeof(contentTypeStr[0]) - 1);
 
     return String();
 }
@@ -55,10 +56,10 @@ String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
     DWORD extStrLen = sizeof(extStr);
     DWORD keyType;
 
-    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, path.charactersWithNullTermination().data(), L"Extension", &keyType, extStr, &extStrLen);
+    HRESULT result = getRegistryValue(HKEY_CLASSES_ROOT, stringToNullTerminatedWChar(path).data(), L"Extension", &keyType, extStr, &extStrLen);
 
     if (result == ERROR_SUCCESS && keyType == REG_SZ)
-        return String(extStr + 1, extStrLen / sizeof(extStr[0]) - 2);
+        return wcharToString(extStr + 1, extStrLen / sizeof(extStr[0]) - 2);
 
     return String();
 }
index 009e7a0..c9a0d2d 100644 (file)
@@ -51,6 +51,7 @@
 #include <wtf/WindowsExtras.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringView.h>
+#include <wtf/text/win/WCharStringExtras.h>
 #include <wtf/win/GDIObject.h>
 
 namespace WebCore {
@@ -339,7 +340,7 @@ void Pasteboard::read(PasteboardFileReader& reader)
         for (UINT i = 0; i < fileCount; i++) {
             if (!DragQueryFileW(hdrop, i, filename, WTF_ARRAY_LENGTH(filename)))
                 continue;
-            reader.readFilename(filename);
+            reader.readFilename(nullTerminatedWCharToString(filename));
         }
 
         GlobalUnlock(medium.hGlobal);
@@ -959,7 +960,7 @@ static HGLOBAL createGlobalHDropContent(const URL& url, String& fileName, Shared
         // windows does not enjoy a leading slash on paths
         if (localPath[0] == '/')
             localPath = localPath.substring(1);
-        const Vector<UChar>& localPathWide = localPath.charactersWithNullTermination();
+        auto localPathWide = stringToNullTerminatedWChar(localPath);
         LPCWSTR localPathStr = localPathWide.data();
         if (localPathStr && wcslen(localPathStr) + 1 < MAX_PATH)
             wcscpy_s(filePath, MAX_PATH, localPathStr);
@@ -970,7 +971,7 @@ static HGLOBAL createGlobalHDropContent(const URL& url, String& fileName, Shared
         WCHAR extension[MAX_PATH];
         if (!::GetTempPath(WTF_ARRAY_LENGTH(tempPath), tempPath))
             return 0;
-        if (!::PathAppend(tempPath, fileName.charactersWithNullTermination().data()))
+        if (!::PathAppend(tempPath, stringToNullTerminatedWChar(fileName).data()))
             return 0;
         LPCWSTR foundExtension = ::PathFindExtension(tempPath);
         if (foundExtension) {
index 8ba6ef2..f20407b 100644 (file)
 #include "PathWalker.h"
 
 #include <wtf/text/WTFString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
 PathWalker::PathWalker(const String& directory, const String& pattern)
 {
     String path = directory + "\\" + pattern;
-    m_handle = ::FindFirstFileW(path.charactersWithNullTermination().data(), &m_data);
+    m_handle = ::FindFirstFileW(stringToNullTerminatedWChar(path).data(), &m_data);
 }
 
 PathWalker::~PathWalker()
index 92b2d83..de20b8d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <wtf/text/Base64.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 #include <windows.h>
 #include <wincrypt.h>
@@ -67,7 +68,7 @@ String WebCore::signedPublicKeyAndChallengeString(unsigned index, const String&
         String localChallenge = challenge;
 
         // Windows API won't write to our buffer, although it's not declared with const.
-        const Vector<UChar>& localChallengeWide = localChallenge.charactersWithNullTermination();
+        auto localChallengeWide = stringToNullTerminatedWChar(localChallenge);
         requestInfo.pwszChallengeString = const_cast<wchar_t*>(localChallengeWide.data());
 
         CRYPT_ALGORITHM_IDENTIFIER signAlgo = { 0 };
index 42ece0f..5bdabb6 100644 (file)
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "SharedBuffer.h"
 #include <wtf/text/CString.h>
+#include <wtf/text/win/WCharStringExtras.h>
 
 namespace WebCore {
 
@@ -39,7 +40,7 @@ RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath)
         return nullptr;
 
     String nullifiedPath = filePath;
-    HANDLE fileHandle = CreateFileW(nullifiedPath.charactersWithNullTermination().data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+    HANDLE fileHandle = CreateFileW(stringToNullTerminatedWChar(nullifiedPath).data(), GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
     if (fileHandle == INVALID_HANDLE_VALUE) {
         LOG_ERROR("Failed to open file %s to create shared buffer, GetLastError() = %u", filePath.ascii().data(), GetLastError());
         return nullptr;
index d234569..33aec68 100644 (file)
@@ -40,6 +40,7 @@
 #include "WebCoreBundleWin.h"
 #include <wtf/SoftLinking.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/text/win/WCharStringExtras.h>
 #include <wtf/win/GDIObject.h>
 
 #if ENABLE(VIDEO)
@@ -318,7 +319,7 @@ Color RenderThemeWin::platformInactiveSelectionForegroundColor() const
 static void fillFontDescription(FontCascadeDescription& fontDescription, LOGFONT& logFont, float fontSize)
 {    
     fontDescription.setIsAbsoluteSize(true);
-    fontDescription.setOneFamily(String(logFont.lfFaceName));
+    fontDescription.setOneFamily(nullTerminatedWCharToString(logFont.lfFaceName));
     fontDescription.setSpecifiedSize(fontSize);
     fontDescription.setWeight(logFont.lfWeight >= 700 ? boldWeightValue() : normalWeightValue()); // FIXME: Use real weight.
     fontDescription.setIsItalic(logFont.lfItalic);