| File: | Source/WebKit/UIProcess/WebPageProxyTesting.cpp |
| Warning: | line 249, column 5 Call argument for 'this' parameter is uncounted and unsafe |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (C) 2024 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "WebPageProxyTesting.h" |
| 28 | |
| 29 | #include "BrowsingContextGroup.h" |
| 30 | #include "Connection.h" |
| 31 | #include "MessageSenderInlines.h" |
| 32 | #include "NetworkProcessMessages.h" |
| 33 | #include "WebBackForwardList.h" |
| 34 | #include "WebFrameProxy.h" |
| 35 | #include "WebPageMessages.h" |
| 36 | #include "WebPageProxy.h" |
| 37 | #include "WebPageTestingMessages.h" |
| 38 | #include "WebProcessMessages.h" |
| 39 | #include "WebProcessPool.h" |
| 40 | #include "WebProcessProxy.h" |
| 41 | #include <WebCore/IntPoint.h> |
| 42 | #include <wtf/CallbackAggregator.h> |
| 43 | #include <wtf/TZoneMallocInlines.h> |
| 44 | |
| 45 | #if PLATFORM(COCOA)(defined 1 && 1) && ENABLE(MEDIA_STREAM)(defined 1 && 1) |
| 46 | #include "DisplayCaptureSessionManager.h" |
| 47 | #endif |
| 48 | |
| 49 | namespace WebKit { |
| 50 | using namespace WebCore; |
| 51 | |
| 52 | WTF_MAKE_TZONE_ALLOCATED_IMPL(WebPageProxyTesting)::bmalloc::api::HeapRef WebPageProxyTesting::s_heapRef; const TZoneSpecification WebPageProxyTesting::s_heapSpec = { & WebPageProxyTesting::s_heapRef, TZoneSpecification::encodeSize <WebPageProxyTesting>(), TZoneSpecification::encodeAlignment <WebPageProxyTesting>(), TZoneSpecification::encodeCategory <WebPageProxyTesting>(), ::bmalloc::api::compactAllocationMode <WebPageProxyTesting>(), TZoneSpecification::encodeDescriptor <WebPageProxyTesting>(), }; void* WebPageProxyTesting:: operatorNewSlow(size_t size) { if constexpr (::bmalloc::api:: compactAllocationMode<WebPageProxyTesting>() == CompactAllocationMode ::Compact) return ::bmalloc::api::tzoneAllocateCompactSlow(size , s_heapSpec); return ::bmalloc::api::tzoneAllocateNonCompactSlow (size, s_heapSpec); } using __makeBtzoneMallocedInlineMacroSemicolonifier __attribute__((unused)) = int; |
| 53 | |
| 54 | WebPageProxyTesting::WebPageProxyTesting(WebPageProxy& page) |
| 55 | : m_page(page) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | bool WebPageProxyTesting::sendMessage(UniqueRef<IPC::Encoder>&& encoder, OptionSet<IPC::SendOption> sendOptions) |
| 60 | { |
| 61 | return protect(protect(page())->legacyMainFrameProcess())->sendMessage(WTF::move(encoder), sendOptions); |
| 62 | } |
| 63 | |
| 64 | bool WebPageProxyTesting::sendMessageWithAsyncReply(UniqueRef<IPC::Encoder>&& encoder, AsyncReplyHandler handler, OptionSet<IPC::SendOption> sendOptions) |
| 65 | { |
| 66 | return protect(protect(page())->legacyMainFrameProcess())->sendMessage(WTF::move(encoder), sendOptions, WTF::move(handler)); |
| 67 | } |
| 68 | |
| 69 | IPC::Connection* WebPageProxyTesting::messageSenderConnection() const |
| 70 | { |
| 71 | return &page().legacyMainFrameProcess().connection(); |
| 72 | } |
| 73 | |
| 74 | uint64_t WebPageProxyTesting::messageSenderDestinationID() const |
| 75 | { |
| 76 | return page().webPageIDInMainFrameProcess().toUInt64(); |
| 77 | } |
| 78 | |
| 79 | void WebPageProxyTesting::dispatchActivityStateUpdate() |
| 80 | { |
| 81 | RunLoop::currentSingleton().dispatch([protectedPage = protect(page())] { |
| 82 | protectedPage->updateActivityState(); |
| 83 | protectedPage->dispatchActivityStateChange(); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | void WebPageProxyTesting::isLayerTreeFrozen(CompletionHandler<void(bool)>&& completionHandler) |
| 88 | { |
| 89 | sendWithAsyncReply(Messages::WebPageTesting::IsLayerTreeFrozen(), WTF::move(completionHandler)); |
| 90 | } |
| 91 | |
| 92 | void WebPageProxyTesting::setCrossSiteLoadWithLinkDecorationForTesting(const URL& fromURL, const URL& toURL, bool wasFiltered, CompletionHandler<void()>&& completionHandler) |
| 93 | { |
| 94 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->setCrossSiteLoadWithLinkDecorationForTesting(protect(page())->sessionID(), WebCore::RegistrableDomain { fromURL }, WebCore::RegistrableDomain { toURL }, wasFiltered, WTF::move(completionHandler)); |
| 95 | } |
| 96 | |
| 97 | void WebPageProxyTesting::setPermissionLevel(const String& origin, bool allowed) |
| 98 | { |
| 99 | protect(page())->forEachWebContentProcess([&](auto& webProcess, auto pageID) { |
| 100 | webProcess.send(Messages::WebPageTesting::SetPermissionLevel(origin, allowed), pageID); |
| 101 | }); |
| 102 | } |
| 103 | |
| 104 | bool WebPageProxyTesting::isEditingCommandEnabled(const String& commandName) |
| 105 | { |
| 106 | RefPtr focusedOrMainFrame = m_page->focusedOrMainFrame(); |
| 107 | auto targetFrameID = focusedOrMainFrame ? std::optional(focusedOrMainFrame->frameID()) : std::nullopt; |
| 108 | auto sendResult = protect(page())->sendSyncToProcessContainingFrame(targetFrameID, Messages::WebPageTesting::IsEditingCommandEnabled(commandName), Seconds::infinity()); |
| 109 | if (!sendResult.succeeded()) |
| 110 | return false; |
| 111 | auto [result] = sendResult.takeReply(); |
| 112 | return result; |
| 113 | } |
| 114 | |
| 115 | void WebPageProxyTesting::dumpPrivateClickMeasurement(CompletionHandler<void(const String&)>&& completionHandler) |
| 116 | { |
| 117 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::DumpPrivateClickMeasurement(m_page->websiteDataStore().sessionID()), WTF::move(completionHandler)); |
| 118 | } |
| 119 | |
| 120 | void WebPageProxyTesting::clearPrivateClickMeasurement(CompletionHandler<void()>&& completionHandler) |
| 121 | { |
| 122 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::ClearPrivateClickMeasurement(m_page->websiteDataStore().sessionID()), WTF::move(completionHandler)); |
| 123 | } |
| 124 | |
| 125 | void WebPageProxyTesting::setPrivateClickMeasurementOverrideTimer(bool value, CompletionHandler<void()>&& completionHandler) |
| 126 | { |
| 127 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementOverrideTimerForTesting(m_page->websiteDataStore().sessionID(), value), WTF::move(completionHandler)); |
| 128 | } |
| 129 | |
| 130 | void WebPageProxyTesting::markAttributedPrivateClickMeasurementsAsExpired(CompletionHandler<void()>&& completionHandler) |
| 131 | { |
| 132 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::MarkAttributedPrivateClickMeasurementsAsExpiredForTesting(m_page->websiteDataStore().sessionID()), WTF::move(completionHandler)); |
| 133 | } |
| 134 | |
| 135 | void WebPageProxyTesting::setPrivateClickMeasurementEphemeralMeasurement(bool value, CompletionHandler<void()>&& completionHandler) |
| 136 | { |
| 137 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementEphemeralMeasurementForTesting(m_page->websiteDataStore().sessionID(), value), WTF::move(completionHandler)); |
| 138 | } |
| 139 | |
| 140 | void WebPageProxyTesting::simulatePrivateClickMeasurementSessionRestart(CompletionHandler<void()>&& completionHandler) |
| 141 | { |
| 142 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SimulatePrivateClickMeasurementSessionRestart(m_page->websiteDataStore().sessionID()), WTF::move(completionHandler)); |
| 143 | } |
| 144 | |
| 145 | void WebPageProxyTesting::setPrivateClickMeasurementTokenPublicKeyURL(const URL& url, CompletionHandler<void()>&& completionHandler) |
| 146 | { |
| 147 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementTokenPublicKeyURLForTesting(m_page->websiteDataStore().sessionID(), url), WTF::move(completionHandler)); |
| 148 | } |
| 149 | |
| 150 | void WebPageProxyTesting::setPrivateClickMeasurementTokenSignatureURL(const URL& url, CompletionHandler<void()>&& completionHandler) |
| 151 | { |
| 152 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementTokenSignatureURLForTesting(m_page->websiteDataStore().sessionID(), url), WTF::move(completionHandler)); |
| 153 | } |
| 154 | |
| 155 | void WebPageProxyTesting::setPrivateClickMeasurementAttributionReportURLs(const URL& sourceURL, const URL& destinationURL, CompletionHandler<void()>&& completionHandler) |
| 156 | { |
| 157 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementAttributionReportURLsForTesting(m_page->websiteDataStore().sessionID(), sourceURL, destinationURL), WTF::move(completionHandler)); |
| 158 | } |
| 159 | |
| 160 | void WebPageProxyTesting::markPrivateClickMeasurementsAsExpired(CompletionHandler<void()>&& completionHandler) |
| 161 | { |
| 162 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::MarkPrivateClickMeasurementsAsExpiredForTesting(m_page->websiteDataStore().sessionID()), WTF::move(completionHandler)); |
| 163 | } |
| 164 | |
| 165 | void WebPageProxyTesting::setPCMFraudPreventionValues(const String& unlinkableToken, const String& secretToken, const String& signature, const String& keyID, CompletionHandler<void()>&& completionHandler) |
| 166 | { |
| 167 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPCMFraudPreventionValuesForTesting(m_page->websiteDataStore().sessionID(), unlinkableToken, secretToken, signature, keyID), WTF::move(completionHandler)); |
| 168 | } |
| 169 | |
| 170 | void WebPageProxyTesting::setPrivateClickMeasurementAppBundleID(const String& appBundleIDForTesting, CompletionHandler<void()>&& completionHandler) |
| 171 | { |
| 172 | protect(protect(protect(page())->websiteDataStore())->networkProcess())->sendWithAsyncReply(Messages::NetworkProcess::SetPrivateClickMeasurementAppBundleIDForTesting(m_page->websiteDataStore().sessionID(), appBundleIDForTesting), WTF::move(completionHandler)); |
| 173 | } |
| 174 | |
| 175 | #if ENABLE(NOTIFICATIONS)(defined 1 && 1) |
| 176 | void WebPageProxyTesting::clearNotificationPermissionState() |
| 177 | { |
| 178 | send(Messages::WebPageTesting::ClearNotificationPermissionState()); |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | void WebPageProxyTesting::clearWheelEventTestMonitor() |
| 183 | { |
| 184 | if (!page().hasRunningProcess()) |
| 185 | return; |
| 186 | send(Messages::WebPageTesting::ClearWheelEventTestMonitor()); |
| 187 | } |
| 188 | |
| 189 | void WebPageProxyTesting::startMonitoringWheelEventsForTesting(CompletionHandler<void()>&& completionHandler) |
| 190 | { |
| 191 | if (!page().hasRunningProcess()) { |
| 192 | completionHandler(); |
| 193 | return; |
| 194 | } |
| 195 | sendWithAsyncReply(Messages::WebPageTesting::StartMonitoringWheelEventsForTesting(), WTF::move(completionHandler)); |
| 196 | } |
| 197 | |
| 198 | void WebPageProxyTesting::waitForWheelEventsToCompleteForTesting(CompletionHandler<void()>&& completionHandler) |
| 199 | { |
| 200 | if (!page().hasRunningProcess()) { |
| 201 | completionHandler(); |
| 202 | return; |
| 203 | } |
| 204 | sendWithAsyncReply(Messages::WebPageTesting::WaitForWheelEventsToCompleteForTesting(), WTF::move(completionHandler)); |
| 205 | } |
| 206 | |
| 207 | #if PLATFORM(COCOA)(defined 1 && 1) && ENABLE(MEDIA_STREAM)(defined 1 && 1) |
| 208 | void WebPageProxyTesting::setIndexOfGetDisplayMediaDeviceSelectedForTesting(std::optional<unsigned> index) |
| 209 | { |
| 210 | DisplayCaptureSessionManager::singleton().setIndexOfDeviceSelectedForTesting(index); |
| 211 | } |
| 212 | |
| 213 | void WebPageProxyTesting::setSystemCanPromptForGetDisplayMediaForTesting(bool canPrompt) |
| 214 | { |
| 215 | DisplayCaptureSessionManager::singleton().setSystemCanPromptForTesting(canPrompt); |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | void WebPageProxyTesting::setObscuredContentInsets(float top, float right, float bottom, float left, CompletionHandler<void()>&& completionHandler) |
| 220 | { |
| 221 | sendWithAsyncReply(Messages::WebPageTesting::SetObscuredContentInsets(top, right, bottom, left), WTF::move(completionHandler)); |
| 222 | } |
| 223 | |
| 224 | void WebPageProxyTesting::resetStateBetweenTests() |
| 225 | { |
| 226 | page().legacyMainFrameProcess().resetState(); |
| 227 | |
| 228 | if (auto* mainFrame = m_page->mainFrame()) |
| 229 | mainFrame->disownOpener(); |
| 230 | |
| 231 | protect(page())->forEachWebContentProcess([&](auto& webProcess, auto pageID) { |
| 232 | webProcess.send(Messages::WebPageTesting::ResetStateBetweenTests(), pageID); |
| 233 | }); |
| 234 | } |
| 235 | |
| 236 | void WebPageProxyTesting::clearBackForwardList(CompletionHandler<void()>&& completionHandler) |
| 237 | { |
| 238 | Ref page = m_page.get(); |
| 239 | protect(page->backForwardListWrapper())->clear(); |
| 240 | |
| 241 | Ref callbackAggregator = CallbackAggregator::create(WTF::move(completionHandler)); |
| 242 | page->forEachWebContentProcess([&](auto& webProcess, auto pageID) { |
| 243 | webProcess.sendWithAsyncReply(Messages::WebPageTesting::ClearCachedBackForwardListCounts(), [callbackAggregator] { }, pageID); |
| 244 | }); |
| 245 | } |
| 246 | |
| 247 | void WebPageProxyTesting::clearBrowsingContextGroup() |
| 248 | { |
| 249 | protect(page())->browsingContextGroup().clearBrowsingContextGroupForTesting(); |
Call argument for 'this' parameter is uncounted and unsafe | |
| 250 | } |
| 251 | |
| 252 | void WebPageProxyTesting::setTracksRepaints(bool trackRepaints, CompletionHandler<void()>&& completionHandler) |
| 253 | { |
| 254 | Ref callbackAggregator = CallbackAggregator::create(WTF::move(completionHandler)); |
| 255 | protect(page())->forEachWebContentProcess([&](auto& webProcess, auto pageID) { |
| 256 | webProcess.sendWithAsyncReply(Messages::WebPageTesting::SetTracksRepaints(trackRepaints), [callbackAggregator] { }, pageID); |
| 257 | }); |
| 258 | } |
| 259 | |
| 260 | void WebPageProxyTesting::displayAndTrackRepaints(CompletionHandler<void()>&& completionHandler) |
| 261 | { |
| 262 | Ref callbackAggregator = CallbackAggregator::create(WTF::move(completionHandler)); |
| 263 | protect(page())->forEachWebContentProcess([&](auto& webProcess, auto pageID) { |
| 264 | webProcess.sendWithAsyncReply(Messages::WebPageTesting::DisplayAndTrackRepaints(), [callbackAggregator] { }, pageID); |
| 265 | }); |
| 266 | } |
| 267 | |
| 268 | void WebPageProxyTesting::storageAreaMapCount(CompletionHandler<void(uint64_t)>&& completionHandler) |
| 269 | { |
| 270 | Ref processPool = page().legacyMainFrameProcess().processPool(); |
| 271 | |
| 272 | struct TotalCount : RefCounted<TotalCount> { |
| 273 | uint64_t value { 0 }; |
| 274 | }; |
| 275 | Ref totalCount = adoptRef(*new TotalCount); |
| 276 | Ref callbackAggregator = CallbackAggregator::create([totalCount, completionHandler = WTF::move(completionHandler)]() mutable { |
| 277 | completionHandler(totalCount->value); |
| 278 | }); |
| 279 | for (auto& process : processPool->processes()) { |
| 280 | if (!process->pageCount()) |
| 281 | continue; |
| 282 | process->sendWithAsyncReply(Messages::WebProcess::GetStorageAreaMapCountForTesting(), [totalCount, callbackAggregator](uint64_t count) { |
| 283 | totalCount->value += count; |
| 284 | }); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | } // namespace WebKit |