- Revision
- 277239
- Author
- [email protected]
- Date
- 2021-05-08 21:09:18 -0700 (Sat, 08 May 2021)
Log Message
Remove uses of the WTF::String::toInt family of functions from WebKit framework sources
https://bugs.webkit.org/show_bug.cgi?id=225570
Reviewed by Sam Weinig.
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::readSizeFile): Use parseInteger<uint64_t>
instead of charactersToUIntStrict. Also simplified the code a bit by
reducing the mixing of integer types in the function.
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::deleteOldVersions): Use parseInteger<unsigned>
instead of String::toUIntStrict. Also use StringView::substring so we don't
have to allocate a copy of a substring just to parse it.
* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
(WebKit::XPCServiceInitializerDelegate::getClientSDKVersion): Use
parseInteger<uint32_t> instead of charactersToUIntStrict. Also let the
StringView constructor take care of converting the const char*
so we don't have to write explicit calls to std::strlen here.
(WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): Use
parseInteger<uint64_t> instead of String::toUInt64Strict. Also pass the
const char* as a StringView rather than converting it to a String so we
don't have to allocate a copy of the string just to parse it.
* Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm:
(WebKit::PluginVersion::parse): Use parseIntegerAllowingTrailingJunk<unsigned>
instead of String::toUInt. Also use StringView::split instead of String::split
so we don't have to allocate memory for all the substrings and a range-based
for loop for simplicity.
* UIProcess/API/Cocoa/WKWebView.mm:
(coreTextManipulationItemIdentifierFromString): Use -[NSString longLongValue]
instead of String::toUInt64. There's no need to parse this unsigned because
the values will fit in 63 bits just fine, and it's nice to use NSString
directly rather than copying the string just to parse the integer in it.
(coreTextManipulationTokenIdentifierFromString): Ditto.
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::parsePostBuffer): Use parseIntegerAllowingTrailingJunk<unsigned>
instead of String::toInt. The length can't be negative; it was not helpful
to parse negative numbers before and this is a small bug fix, but in a code
path that is probably not used for much of anything any more.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (277238 => 277239)
--- trunk/Source/WebKit/ChangeLog 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/ChangeLog 2021-05-09 04:09:18 UTC (rev 277239)
@@ -1,3 +1,49 @@
+2021-05-08 Darin Adler <[email protected]>
+
+ Remove uses of the WTF::String::toInt family of functions from WebKit framework sources
+ https://bugs.webkit.org/show_bug.cgi?id=225570
+
+ Reviewed by Sam Weinig.
+
+ * NetworkProcess/cache/CacheStorageEngine.cpp:
+ (WebKit::CacheStorage::Engine::readSizeFile): Use parseInteger<uint64_t>
+ instead of charactersToUIntStrict. Also simplified the code a bit by
+ reducing the mixing of integer types in the function.
+
+ * NetworkProcess/cache/NetworkCacheStorage.cpp:
+ (WebKit::NetworkCache::Storage::deleteOldVersions): Use parseInteger<unsigned>
+ instead of String::toUIntStrict. Also use StringView::substring so we don't
+ have to allocate a copy of a substring just to parse it.
+
+ * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm:
+ (WebKit::XPCServiceInitializerDelegate::getClientSDKVersion): Use
+ parseInteger<uint32_t> instead of charactersToUIntStrict. Also let the
+ StringView constructor take care of converting the const char*
+ so we don't have to write explicit calls to std::strlen here.
+ (WebKit::XPCServiceInitializerDelegate::getProcessIdentifier): Use
+ parseInteger<uint64_t> instead of String::toUInt64Strict. Also pass the
+ const char* as a StringView rather than converting it to a String so we
+ don't have to allocate a copy of the string just to parse it.
+
+ * Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm:
+ (WebKit::PluginVersion::parse): Use parseIntegerAllowingTrailingJunk<unsigned>
+ instead of String::toUInt. Also use StringView::split instead of String::split
+ so we don't have to allocate memory for all the substrings and a range-based
+ for loop for simplicity.
+
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (coreTextManipulationItemIdentifierFromString): Use -[NSString longLongValue]
+ instead of String::toUInt64. There's no need to parse this unsigned because
+ the values will fit in 63 bits just fine, and it's nice to use NSString
+ directly rather than copying the string just to parse the integer in it.
+ (coreTextManipulationTokenIdentifierFromString): Ditto.
+
+ * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+ (WebKit::parsePostBuffer): Use parseIntegerAllowingTrailingJunk<unsigned>
+ instead of String::toInt. The length can't be negative; it was not helpful
+ to parse negative numbers before and this is a small bug fix, but in a code
+ path that is probably not used for much of anything any more.
+
2021-05-08 Sam Weinig <[email protected]>
Factor out pixel buffer from DOM specific ImageData class
Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (277238 => 277239)
--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp 2021-05-09 04:09:18 UTC (rev 277239)
@@ -39,6 +39,7 @@
#include <wtf/Scope.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/text/StringHash.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
@@ -570,16 +571,17 @@
if (!FileSystem::getFileSize(path, fileSize) || !fileSize)
return WTF::nullopt;
- size_t bytesToRead;
+ unsigned bytesToRead;
if (!WTF::convertSafely(fileSize, bytesToRead))
return WTF::nullopt;
- Vector<unsigned char> buffer(bytesToRead);
- size_t totalBytesRead = FileSystem::readFromFile(fileHandle, reinterpret_cast<char*>(buffer.data()), buffer.size());
+ // FIXME: No reason we need a heap buffer to read an arbitrary number of bytes when we only support small files that contain numerals.
+ Vector<char> buffer(bytesToRead);
+ unsigned totalBytesRead = FileSystem::readFromFile(fileHandle, buffer.data(), buffer.size());
if (totalBytesRead != bytesToRead)
return WTF::nullopt;
- return charactersToUIntStrict(buffer.data(), totalBytesRead);
+ return parseInteger<uint64_t>({ buffer.data(), totalBytesRead });
}
class ReadOriginsTaskCounter : public RefCounted<ReadOriginsTaskCounter> {
Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp (277238 => 277239)
--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp 2021-05-09 04:09:18 UTC (rev 277239)
@@ -40,6 +40,7 @@
#include <wtf/RunLoop.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringConcatenateNumbers.h>
+#include <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
namespace NetworkCache {
@@ -1183,17 +1184,11 @@
return;
if (!subdirName.startsWith(versionDirectoryPrefix))
return;
- auto versionString = subdirName.substring(strlen(versionDirectoryPrefix));
- bool success;
- unsigned directoryVersion = versionString.toUIntStrict(&success);
- if (!success)
+ auto directoryVersion = parseInteger<unsigned>(StringView { subdirName }.substring(strlen(versionDirectoryPrefix)));
+ if (!directoryVersion || *directoryVersion >= version)
return;
- if (directoryVersion >= version)
- return;
-
auto oldVersionPath = FileSystem::pathByAppendingComponent(cachePath, subdirName);
LOG(NetworkCacheStorage, "(NetworkProcess) deleting old cache version, path %s", oldVersionPath.utf8().data());
-
FileSystem::deleteNonEmptyDirectory(oldVersionPath);
});
});
Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm (277238 => 277239)
--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceEntryPoint.mm 2021-05-09 04:09:18 UTC (rev 277239)
@@ -31,9 +31,9 @@
#import <WebCore/ProcessIdentifier.h>
#import <wtf/cocoa/Entitlements.h>
#import <wtf/spi/darwin/SandboxSPI.h>
+#import <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
-using namespace WebCore;
XPCServiceInitializerDelegate::~XPCServiceInitializerDelegate()
{
@@ -83,24 +83,18 @@
bool XPCServiceInitializerDelegate::getClientSDKVersion(uint32_t& clientSDKVersion)
{
- auto string = xpc_dictionary_get_string(m_initializerMessage, "client-sdk-version");
- bool ok;
- clientSDKVersion = charactersToUIntStrict(reinterpret_cast<const LChar*>(string), string ? std::strlen(string) : 0, &ok);
- return ok;
+ auto version = parseInteger<uint32_t>(xpc_dictionary_get_string(m_initializerMessage, "client-sdk-version"));
+ clientSDKVersion = version.valueOr(0);
+ return version.hasValue();
}
bool XPCServiceInitializerDelegate::getProcessIdentifier(ProcessIdentifier& identifier)
{
- String processIdentifierString = xpc_dictionary_get_string(m_initializerMessage, "process-identifier");
- if (processIdentifierString.isEmpty())
+ auto parsedIdentifier = parseInteger<uint64_t>(xpc_dictionary_get_string(m_initializerMessage, "process-identifier"));
+ if (!parsedIdentifier)
return false;
- bool ok;
- auto parsedIdentifier = processIdentifierString.toUInt64Strict(&ok);
- if (!ok)
- return false;
-
- identifier = makeObjectIdentifier<ProcessIdentifierType>(parsedIdentifier);
+ identifier = makeObjectIdentifier<ProcessIdentifierType>(*parsedIdentifier);
return true;
}
@@ -107,9 +101,7 @@
bool XPCServiceInitializerDelegate::getClientProcessName(String& clientProcessName)
{
clientProcessName = xpc_dictionary_get_string(m_initializerMessage, "ui-process-name");
- if (clientProcessName.isEmpty())
- return false;
- return true;
+ return !clientProcessName.isEmpty();
}
bool XPCServiceInitializerDelegate::getExtraInitializationData(HashMap<String, String>& extraInitializationData)
Modified: trunk/Source/WebKit/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm (277238 => 277239)
--- trunk/Source/WebKit/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm 2021-05-09 04:09:18 UTC (rev 277239)
@@ -33,9 +33,9 @@
#import <wtf/HashSet.h>
#import <wtf/MainThread.h>
#import <wtf/spi/cf/CFBundleSPI.h>
+#import <wtf/text/StringToIntegerConversion.h>
namespace WebKit {
-using namespace WebCore;
static bool getPluginArchitecture(CFBundleRef bundle, PluginModuleInfo& plugin)
{
@@ -88,7 +88,7 @@
CFDictionaryGetKeysAndValues(mimeTypes.get(), reinterpret_cast<const void**>(mimeTypesVector.data()), reinterpret_cast<const void**>(mimeTypeInfoVector.data()));
for (CFIndex i = 0; i < numMimeTypes; ++i) {
- MimeClassInfo mimeClassInfo;
+ WebCore::MimeClassInfo mimeClassInfo;
// If this MIME type is invalid, ignore it.
CFStringRef mimeType = mimeTypesVector[i];
@@ -194,7 +194,7 @@
plugin.info.desc = plugin.info.file;
plugin.info.isApplicationPlugin = false;
- plugin.info.clientLoadPolicy = PluginLoadClientPolicy::Undefined;
+ plugin.info.clientLoadPolicy = WebCore::PluginLoadClientPolicy::Undefined;
#if PLATFORM(MAC)
plugin.info.bundleIdentifier = plugin.bundleIdentifier;
plugin.info.versionString = plugin.versionString;
@@ -222,17 +222,12 @@
PluginVersion PluginVersion::parse(const String& versionString)
{
PluginVersion version;
-
- Vector<String> versionStringComponents = versionString.split('.');
- for (size_t i = 0; i < versionStringComponents.size(); ++i) {
- bool successfullyParsed = false;
- unsigned versionComponent = versionStringComponents[i].toUInt(&successfullyParsed);
- if (!successfullyParsed)
- return PluginVersion();
-
- version.m_versionComponents.append(versionComponent);
+ for (auto component : StringView { versionString }.split('.')) {
+ auto versionComponent = parseIntegerAllowingTrailingJunk<unsigned>(component);
+ if (!versionComponent)
+ return { };
+ version.m_versionComponents.append(*versionComponent);
}
-
return version;
}
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (277238 => 277239)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2021-05-09 04:09:18 UTC (rev 277239)
@@ -1955,14 +1955,14 @@
});
}
-static WebCore::TextManipulationController::ItemIdentifier coreTextManipulationItemIdentifierFromString(NSString* identifier)
+static WebCore::TextManipulationController::ItemIdentifier coreTextManipulationItemIdentifierFromString(NSString *identifier)
{
- return makeObjectIdentifier<WebCore::TextManipulationController::ItemIdentifierType>(String(identifier).toUInt64());
+ return makeObjectIdentifier<WebCore::TextManipulationController::ItemIdentifierType>(identifier.longLongValue);
}
-static WebCore::TextManipulationController::TokenIdentifier coreTextManipulationTokenIdentifierFromString(NSString* identifier)
+static WebCore::TextManipulationController::TokenIdentifier coreTextManipulationTokenIdentifierFromString(NSString *identifier)
{
- return makeObjectIdentifier<WebCore::TextManipulationController::TokenIdentifierType>(String(identifier).toUInt64());
+ return makeObjectIdentifier<WebCore::TextManipulationController::TokenIdentifierType>(identifier.longLongValue);
}
- (void)_completeTextManipulation:(_WKTextManipulationItem *)item completion:(void(^)(BOOL success))completionHandler
Modified: trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp (277238 => 277239)
--- trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp 2021-05-09 02:18:25 UTC (rev 277238)
+++ trunk/Source/WebKit/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp 2021-05-09 04:09:18 UTC (rev 277239)
@@ -40,6 +40,7 @@
#include <memory>
#include <utility>
#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringToIntegerConversion.h>
#if PLATFORM(COCOA)
#include <wtf/MachSendRight.h>
@@ -237,16 +238,16 @@
// If the blank line is somewhere in the middle of the buffer, everything before is the header
headerFields = parseRFC822HeaderFields(postBuffer, location);
unsigned dataLength = postBufferSize - location;
-
+
// Sometimes plugins like to set Content-Length themselves when they post,
// but WebFoundation does not like that. So we will remove the header
// and instead truncate the data to the requested length.
String contentLength = headerFields.get(HTTPHeaderName::ContentLength);
-
+
if (!contentLength.isNull())
- dataLength = std::min(contentLength.toInt(), (int)dataLength);
+ dataLength = std::min(parseIntegerAllowingTrailingJunk<unsigned>(contentLength).valueOr(0), dataLength);
headerFields.remove(HTTPHeaderName::ContentLength);
-
+
postBuffer += location;
postBufferSize = dataLength;
}