Skip to content

Commit

Permalink
Deploy more smart pointers in Source/WebKit/Platform/IPC and Source/W…
Browse files Browse the repository at this point in the history
…ebKit/Shared/API/Cocoa

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

Reviewed by Chris Dumez.

Deployed more smart pointers in these files.

* Source/WebKit/Platform/IPC/Connection.h:
(IPC::Connection::send):
* Source/WebKit/Platform/IPC/MessageSender.cpp:
(IPC::MessageSender::sendMessage):
(IPC::MessageSender::sendMessageWithAsyncReply):
* Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(decodeObjectFromObjectStream):
(decodeString):
(decodeObject):
(-[WKRemoteObjectDecoder decodeBoolForKey:]):
(-[WKRemoteObjectDecoder decodeIntForKey:]):
(-[WKRemoteObjectDecoder decodeInt32ForKey:]):
(-[WKRemoteObjectDecoder decodeInt64ForKey:]):
(-[WKRemoteObjectDecoder decodeFloatForKey:]):
(-[WKRemoteObjectDecoder decodeDoubleForKey:]):
(-[WKRemoteObjectDecoder decodeBytesForKey:returnedLength:]):
(-[WKRemoteObjectDecoder decodeObjectOfClasses:forKey:]):
* Source/WebKit/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
(-[_WKRemoteObjectRegistry _invokeMethod:]):
(-[_WKRemoteObjectRegistry _callReplyWithID:blockInvocation:]):

Canonical link: https://commits.webkit.org/267295@main
  • Loading branch information
rniwa authored and JonWBedard committed Aug 25, 2023
1 parent 72de90f commit f46ead2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Source/WebKit/Platform/IPC/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ template<typename T>
Error Connection::send(UniqueID connectionID, T&& message, uint64_t destinationID, OptionSet<SendOption> sendOptions, std::optional<Thread::QOS> qos)
{
Locker locker { s_connectionMapLock };
auto* connection = connectionMap().get(connectionID);
RefPtr connection = connectionMap().get(connectionID);
if (!connection)
return Error::NoConnectionForIdentifier;
return connection->send(WTFMove(message), destinationID, sendOptions, qos);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/Platform/IPC/MessageSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ MessageSender::~MessageSender() = default;

bool MessageSender::sendMessage(UniqueRef<Encoder>&& encoder, OptionSet<SendOption> sendOptions)
{
auto* connection = messageSenderConnection();
RefPtr connection = messageSenderConnection();
ASSERT(connection);
// FIXME: Propagate errors out.
return connection->sendMessage(WTFMove(encoder), sendOptions) == Error::NoError;
}

bool MessageSender::sendMessageWithAsyncReply(UniqueRef<Encoder>&& encoder, AsyncReplyHandler replyHandler, OptionSet<SendOption> sendOptions)
{
auto* connection = messageSenderConnection();
RefPtr connection = messageSenderConnection();
ASSERT(connection);
// FIXME: Propagate errors out.
return connection->sendMessageWithAsyncReply(WTFMove(encoder), WTFMove(replyHandler), sendOptions) == Error::NoError;
Expand Down
25 changes: 13 additions & 12 deletions Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,9 @@ static id decodeObjectFromObjectStream(WKRemoteObjectDecoder *decoder, const Has
if (decoder->_objectStreamPosition == decoder->_objectStream->size())
return nil;

const API::Dictionary* dictionary = decoder->_objectStream->at<API::Dictionary>(decoder->_objectStreamPosition++);
RefPtr dictionary = decoder->_objectStream->at<API::Dictionary>(decoder->_objectStreamPosition++);

return decodeObject(decoder, dictionary, allowedClasses);
return decodeObject(decoder, dictionary.get(), allowedClasses);
}

static const HashSet<CFTypeRef> alwaysAllowedClasses()
Expand Down Expand Up @@ -1014,7 +1014,7 @@ static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocati

static RetainPtr<NSString> decodeString(WKRemoteObjectDecoder *decoder)
{
API::String* string = decoder->_currentDictionary->get<API::String>(stringKey);
RefPtr string = decoder->_currentDictionary->get<API::String>(stringKey);
if (!string)
[NSException raise:NSInvalidUnarchiveOperationException format:@"String missing"];

Expand All @@ -1023,7 +1023,7 @@ static void decodeInvocationArguments(WKRemoteObjectDecoder *decoder, NSInvocati

static id decodeObject(WKRemoteObjectDecoder *decoder)
{
API::String* classNameString = decoder->_currentDictionary->get<API::String>(classNameKey);
RefPtr classNameString = decoder->_currentDictionary->get<API::String>(classNameKey);
if (!classNameString)
[NSException raise:NSInvalidUnarchiveOperationException format:@"Class name missing"];

Expand Down Expand Up @@ -1067,31 +1067,31 @@ static id decodeObject(WKRemoteObjectDecoder *decoder, const API::Dictionary* di

- (BOOL)decodeBoolForKey:(NSString *)key
{
const API::Boolean* value = _currentDictionary->get<API::Boolean>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::Boolean>(escapeKey(key));
if (!value)
return false;
return value->value();
}

- (int)decodeIntForKey:(NSString *)key
{
const API::UInt64* value = _currentDictionary->get<API::UInt64>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::UInt64>(escapeKey(key));
if (!value)
return 0;
return static_cast<int>(value->value());
}

- (int32_t)decodeInt32ForKey:(NSString *)key
{
const API::UInt64* value = _currentDictionary->get<API::UInt64>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::UInt64>(escapeKey(key));
if (!value)
return 0;
return static_cast<int32_t>(value->value());
}

- (int64_t)decodeInt64ForKey:(NSString *)key
{
const API::UInt64* value = _currentDictionary->get<API::UInt64>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::UInt64>(escapeKey(key));
if (!value)
return 0;
return value->value();
Expand All @@ -1104,23 +1104,23 @@ - (NSInteger)decodeIntegerForKey:(NSString *)key

- (float)decodeFloatForKey:(NSString *)key
{
const API::Double* value = _currentDictionary->get<API::Double>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::Double>(escapeKey(key));
if (!value)
return 0;
return value->value();
}

- (double)decodeDoubleForKey:(NSString *)key
{
const API::Double* value = _currentDictionary->get<API::Double>(escapeKey(key));
RefPtr value = _currentDictionary->get<API::Double>(escapeKey(key));
if (!value)
return 0;
return value->value();
}

- (const uint8_t *)decodeBytesForKey:(NSString *)key returnedLength:(NSUInteger *)length
{
auto* data = _currentDictionary->get<API::Data>(escapeKey(key));
RefPtr data = _currentDictionary->get<API::Data>(escapeKey(key));
if (!data || !data->size()) {
*length = 0;
return nullptr;
Expand All @@ -1141,7 +1141,8 @@ - (id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key
for (Class allowedClass in classes)
allowedClasses.add((__bridge CFTypeRef)allowedClass);

return decodeObject(self, _currentDictionary->get<API::Dictionary>(escapeKey(key)), allowedClasses);
RefPtr dictionary = _currentDictionary->get<API::Dictionary>(escapeKey(key));
return decodeObject(self, dictionary.get(), allowedClasses);
}

- (NSSet *)allowedClasses
Expand Down
8 changes: 4 additions & 4 deletions Source/WebKit/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ - (void)_sendInvocation:(NSInvocation *)invocation interface:(_WKRemoteObjectInt
- (void)_invokeMethod:(const WebKit::RemoteObjectInvocation&)remoteObjectInvocation
{
auto& interfaceIdentifier = remoteObjectInvocation.interfaceIdentifier();
auto* encodedInvocation = remoteObjectInvocation.encodedInvocation();
RefPtr encodedInvocation = remoteObjectInvocation.encodedInvocation();

auto interfaceAndObject = _exportedObjects.get(interfaceIdentifier);
if (!interfaceAndObject.second) {
Expand All @@ -220,7 +220,7 @@ - (void)_invokeMethod:(const WebKit::RemoteObjectInvocation&)remoteObjectInvocat

RetainPtr<_WKRemoteObjectInterface> interface = interfaceAndObject.second;

auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:interface.get() rootObjectDictionary:encodedInvocation replyToSelector:nullptr]);
auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:interface.get() rootObjectDictionary:encodedInvocation.get() replyToSelector:nullptr]);

NSInvocation *invocation = [decoder decodeObjectOfClass:[NSInvocation class] forKey:invocationKey];

Expand Down Expand Up @@ -321,7 +321,7 @@ - (void)_invokeMethod:(const WebKit::RemoteObjectInvocation&)remoteObjectInvocat

- (void)_callReplyWithID:(uint64_t)replyID blockInvocation:(const WebKit::UserData&)blockInvocation
{
auto encodedInvocation = blockInvocation.object();
RefPtr encodedInvocation = blockInvocation.object();
if (!encodedInvocation || encodedInvocation->type() != API::Object::Type::Dictionary)
return;

Expand All @@ -332,7 +332,7 @@ - (void)_callReplyWithID:(uint64_t)replyID blockInvocation:(const WebKit::UserDa
auto pendingReply = it->value;
_pendingReplies.remove(it);

auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:pendingReply.interface.get() rootObjectDictionary:static_cast<API::Dictionary*>(encodedInvocation) replyToSelector:pendingReply.selector]);
auto decoder = adoptNS([[WKRemoteObjectDecoder alloc] initWithInterface:pendingReply.interface.get() rootObjectDictionary:static_cast<API::Dictionary*>(encodedInvocation.get()) replyToSelector:pendingReply.selector]);

NSInvocation *replyInvocation = [decoder decodeObjectOfClass:[NSInvocation class] forKey:invocationKey];

Expand Down

0 comments on commit f46ead2

Please sign in to comment.