
/* Copyright (C) 2024 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once

#include <os/log.h>
#include <wtf/ThreadSafeRefCounted.h>

namespace WebCore {

class LogClient {
    WTF_DEPRECATED_MAKE_FAST_ALLOCATED(LogClient);
public:
    LogClient() = default;
    virtual ~LogClient() { }

    virtual void log(std::span<const uint8_t> logChannel, std::span<const uint8_t> logCategory, std::span<const uint8_t> logString, os_log_type_t) = 0;
    virtual bool isWebKitLogClient() const { return false; }

    virtual void DocumentLoaderAttachToFrame(uint64_t, uint64_t, int) { }
    virtual void DocumentLoaderDetachFromFrame(uint64_t, uint64_t, int) { }
    virtual void DocumentLoaderStartLoadingMainResourceEmptyDocument(uint64_t, uint64_t, int) { }
    virtual void DocumentLoaderStartLoadingMainResourceStartingLoad(uint64_t, uint64_t, int) { }
    virtual void DocumentLoaderStopLoading(uint64_t, uint64_t, int) { }
    virtual void FontCacheCoreTextRegisterError(CString&&, CString&&) { }
    virtual void FontCacheCoreTextRegisterFont(CString&&, CString&&) { }
    virtual void FrameLoaderChangeLocation(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderCheckLoadCompleteForThisFrame(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderContinueLoadAfterNavigationPolicy(uint64_t, uint64_t, int, uint64_t) { }
    virtual void FrameLoaderContinueLoadAfterNavigationPolicyCannotContinue(uint64_t, uint64_t, int, int, int, int) { }
    virtual void FrameLoaderLoadDocumentLoader(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadFrameLoadRequest(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadFrameRequestFrameLoadStarted(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadUrl(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadUrlIntoChildFrame(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadWithDocumentLoaderFrameLoadStarted(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadWithDocumentLoaderMainFrameLoadStarted(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderLoadWithNavigationAction(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderPrepareForLoadStart(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderReload(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderSetDocumentLoader(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FrameLoaderSetPolicyDocumentLoader(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FrameLoaderSetProvisionalDocumentLoader(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FrameLoaderSetStateMainFrameLoadCompleted(uint64_t, uint64_t, int) { }
    virtual void FrameLoaderStopAllLoaders(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FrameLoaderStopAllLoadersClearingProvisionalDocumentLoader(uint64_t, uint64_t, int, uint64_t) { }
    virtual void FrameLoaderTransitionToCommitted(uint64_t, uint64_t, int, uint64_t) { }
    virtual void HTMLMediaElementAddAudioTrack(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMediaElementAddVideoTrack(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMediaElementApplyConfiguration(uint64_t) { }
    virtual void HTMLMediaElementCanPlayType(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMediaElementCanTransitionFromAutoplayToPlayNotAutoplaying(uint64_t) { }
    virtual void HTMLMediaElementCanTransitionFromAutoplayToPlayNotEnoughData(uint64_t) { }
    virtual void HTMLMediaElementCheckPlaybackTargetCompatibility(uint64_t) { }
    virtual void HTMLMediaElementConfigureTextTrackDisplay(uint64_t, CString&&) { }
    virtual void HTMLMediaElementConfigureTextTrackGroup(uint64_t, CString&&, CString&&, CString&&, int) { }
    virtual void HTMLMediaElementCancelSpeakingCueText(uint64_t) { }
    virtual void HTMLMediaElementConstructor(uint64_t) { }
    virtual void HTMLMediaElementCreateMediaPlayer(uint64_t) { }
    virtual void HTMLMediaElementCurrentMediaTimeSeeking(uint64_t, float) { }
    virtual void HTMLMediaElementDestructor(uint64_t) { }
    virtual void HTMLMediaElementDidMoveToNewDocument(uint64_t) { }
    virtual void HTMLMediaElementDispatchPlayPauseEventsIfNeedsQuirks(uint64_t) { }
    virtual void HTMLMediaElementExitFullscreen(uint64_t) { }
    virtual void HTMLMediaElementFinishSeek(uint64_t, double, int) { }
    virtual void HTMLMediaElementHardwareMutedStateDidChange(uint64_t) { }
    virtual void HTMLMediaElementInsertionSteps(uint64_t) { }
    virtual void HTMLMediaElementLoadNextSourceChild(uint64_t) { }
    virtual void HTMLMediaElementMediaEngineWasUpdated(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerCharacteristicsChanged(uint64_t, CString&&) { }
    virtual void HTMLMediaElementMediaPlayerCharacteristicsChangedNoMediaSession(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerDurationChanged(uint64_t, float, float) { }
    virtual void HTMLMediaElementMediaPlayerEngineUpdated(uint64_t, CString&&) { }
    virtual void HTMLMediaElementMediaPlayerMuteChanged(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerRateChanged(uint64_t, double) { }
    virtual void HTMLMediaElementMediaPlayerResourceNotSupported(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerSeeked(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerSizeChanged(uint64_t, float, float) { }
    virtual void HTMLMediaElementMediaPlayerTimeChanged(uint64_t) { }
    virtual void HTMLMediaElementMediaPlayerTimeChangedLooping(uint64_t, double, double) { }
    virtual void HTMLMediaElementMediaPlayerVolumeChanged(uint64_t) { }
    virtual void HTMLMediaElementMediaStreamCaptureStarted(uint64_t) { }
    virtual void HTMLMediaElementNoneSupported(uint64_t) { }
    virtual void HTMLMediaElementPause(uint64_t) { }
    virtual void HTMLMediaElementPauseInternal(uint64_t) { }
    virtual void HTMLMediaElementPausePlaybackForExtendedTextDescription(uint64_t) { }
    virtual void HTMLMediaElementPauseSpeakingCueText(uint64_t) { }
    virtual void HTMLMediaElementPlay(uint64_t) { }
    virtual void HTMLMediaElementPlayDom(uint64_t) { }
    virtual void HTMLMediaElementPlayInternal(uint64_t) { }
    virtual void HTMLMediaElementPostConnectionSteps(uint64_t) { }
    virtual void HTMLMediaElementPrepareForLoad(uint64_t, int) { }
    virtual void HTMLMediaElementPurgeBufferedDataIfPossible(uint64_t) { }
    virtual void HTMLMediaElementRemoveAudioTrack(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMediaElementRebuildMediaEngineForWirelessPlayback(uint64_t) { }
    virtual void HTMLMediaElementRemovingSteps(uint64_t) { }
    virtual void HTMLMediaElementResume(uint64_t) { }
    virtual void HTMLMediaElementResumeSpeakingCueText(uint64_t) { }
    virtual void HTMLMediaElementSceneIdentifierDidChange(uint64_t, CString&&) { }
    virtual void HTMLMediaElementScheduleConfigureTextTracksLambdaTaskFired(uint64_t) { }
    virtual void HTMLMediaElementScheduleConfigureTextTracksTaskScheduled(uint64_t) { }
    virtual void HTMLMediaElementScheduleMediaEngineWasUpdatedLambdaTaskFired(uint64_t) { }
    virtual void HTMLMediaElementScheduleMediaEngineWasUpdatedTaskScheduled(uint64_t) { }
    virtual void HTMLMediaElementSeekInternal(uint64_t, double) { }
    virtual void HTMLMediaElementSeekWithTolerance(uint64_t, CString&&) { }
    virtual void HTMLMediaElementSelectMediaResourceAttemptingUseOfUnattachedMediaSourceHandle(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceEmptySrc(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceHasSrcAttrPlayerNotCreated(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceLambdaTaskFired(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceNothingToLoad(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceUsingSrcAttributeUrl(uint64_t) { }
    virtual void HTMLMediaElementSelectMediaResourceUsingSrcObjectProperty(uint64_t) { }
    virtual void HTMLMediaElementSetAutoplayEventPlaybackState(uint64_t, CString&&) { }
    virtual void HTMLMediaElementSetBufferingPolicy(uint64_t, uint8_t) { }
    virtual void HTMLMediaElementSetMutedInternal(uint64_t, int) { }
    virtual void HTMLMediaElementSetNetworkState(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMediaElementSetPlaybackRate(uint64_t, double) { }
    virtual void HTMLMediaElementSetPlayerIdentifierForVideoElement(uint64_t) { }
    virtual void HTMLMediaElementSetReadyState(uint64_t, CString&&, CString&&, bool) { }
    virtual void HTMLMediaElementSetShouldDelayLoadEvent(uint64_t, uint8_t) { }
    virtual void HTMLMediaElementSetShowPosterFlag(uint64_t, int) { }
    virtual void HTMLMediaElementSetVolume(uint64_t, double) { }
    virtual void HTMLMediaElementStop(uint64_t) { }
    virtual void HTMLMediaElementUpdatePlayState(uint64_t, int, int) { }
    virtual void HTMLMediaElementUpdateShouldPlay(uint64_t) { }
    virtual void HTMLMediaElementUserDidInterfereWithAutoplay(uint64_t) { }
    virtual void HTMLMediaElementVisibilityStateChanged(uint64_t, int) { }
    virtual void HTMLMediaElementWaitForSourceChange(uint64_t) { }
    virtual void HTMLMediaElementWebkitShowPlaybackTargetPicker(uint64_t) { }
    virtual void HTMLVideoElementMediaPlayerFirstVideoFrameAvailable(uint64_t, int) { }
    virtual void HTMLVideoElementMediaPlayerRenderingModeChanged(uint64_t) { }
    virtual void HTMLVideoElementScheduleResizeEvent(uint64_t, float, float) { }
    virtual void LibWebRtcLogError(CString&&) { }
    virtual void LibWebRtcLogMessage(CString&&) { }
    virtual void LibWebRtcMediaEndpointOnStatsDelivered(uint64_t, CString&&) { }
    virtual void LocalFrameViewFiringFirstVisuallyNonEmptyLayoutMilestone(uint64_t, uint64_t, int) { }
    virtual void LocalFrameViewFiringResizeEventsDisabledForPage(uint64_t, uint64_t, int) { }
    virtual void LocalFrameViewNotPaintingLayoutNeeded(uint64_t, uint64_t, int) { }
    virtual void MediaSessionManagerCocoaClientCharacteristicsChanged(uint64_t) { }
    virtual void MediaSessionManagerCocoaSessionCanProduceAudioChanged() { }
    virtual void MediaSessionManagerCocoaUpdateSessionState(int, int, int, int, int, int, int) { }
    virtual void MediaSessionManagerInterfaceAddSession(uint64_t) { }
    virtual void MediaSessionManagerInterfaceMaybeActivateAudioSessionActiveSessionNotRequired() { }
    virtual void MediaSessionManagerInterfaceRemoveSession(uint64_t) { }
    virtual void MediaSessionManagerInterfaceSessionCanProduceAudioChanged() { }
    virtual void MediaSessionManagerInterfaceSessionWillEndPlayback(uint64_t) { }
    virtual void PeerConnectionBackendCreateAnswerSucceeded(uint64_t, CString&&) { }
    virtual void PeerConnectionBackendCreateOfferSucceeded(uint64_t, CString&&) { }
    virtual void PerformanceLoggingMemoryUsageForKey(CString&&, uint64_t) { }
    virtual void PerformanceLoggingMemoryUsageInfo(CString&&) { }
    virtual void PerformanceMonitorMeasureCpuUsageInActivityState(double, CString&&) { }
    virtual void PerformanceMonitorMeasurePostBackgroundCpuUsage(double) { }
    virtual void PerformanceMonitorMeasurePostBackgroundMemoryUsage(uint64_t) { }
    virtual void PerformanceMonitorMeasurePostLoadCpuUsage(double) { }
    virtual void PerformanceMonitorMeasurePostLoadMemoryUsage(uint64_t) { }
    virtual void PolicyCheckerCheckNavigationPolicyContinueInitialEmptyDocument(uint64_t, uint64_t) { }
    virtual void PolicyCheckerCheckNavigationPolicyContinueLoadInAnotherProcess(uint64_t, uint64_t) { }
    virtual void PolicyCheckerCheckNavigationPolicyContinuePolicyActionIsUse(uint64_t, uint64_t) { }
    virtual void ProgressTrackerFinalProgressComplete(double, int, uint64_t, int, int) { }
    virtual void ProgressTrackerProgressCompleted(uint64_t, double, int, uint64_t, int) { }
    virtual void ProgressTrackerProgressStarted(uint64_t, double, int, uint64_t, int) { }
    virtual void ResourceLoaderWillSendRequestInternal(uint64_t, uint64_t, uint64_t) { }
    virtual void RtcPeerConnectionSetLocalDescription(uint64_t, CString&&) { }
    virtual void RtcPeerConnectionSetRemoteDescription(uint64_t, CString&&) { }
    virtual void ServiceWorkerThreadProxyRemoveFetch(uint64_t) { }
    virtual void SubResourceLoaderDidFail(uint64_t, uint64_t, uint64_t, int, int) { }
    virtual void SubResourceLoaderDidFinishLoading(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidFinishLoadingCanceled(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidFinishLoadingDidNotReachTerminalState(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidFinishLoadingReachedTerminalState(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidReceiveResponseCancelingLoadBecauseOfCrossOriginAccessControl(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidReceiveResponseCancelingLoadBecauseOfMultipartNonImage(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidReceiveResponseCancelingLoadBlockedByContentPolicy(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderDidReceiveResponseCancelingLoadReceivedUnexpectedRangeResponse(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillCancel(uint64_t, uint64_t, uint64_t, int, int) { }
    virtual void SubResourceLoaderWillSendRequestInternal(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalCancelledInvalidNewRequest(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalCancelledInvalidRequest(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalCancelledTerminalState(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalReachedTerminalState(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceDoneNotifyingClients(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledAfterImageBeingDeferred(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledAfterRedirectDeniedByCorsPolicy(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledAfterUsingBlockedPort(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledCannotRequestAfterRedirection(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledDataURL(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledRedirectNotAllowed(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCancelledTooManyRedirects(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadCompleted(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalResourceLoadFinished(uint64_t, uint64_t, uint64_t) { }
    virtual void SubResourceLoaderWillSendRequestInternalTerminalStateCallingCompletionHandler(uint64_t, uint64_t, uint64_t) { }
    virtual void WebCoreTestLog(unsigned) { }

    };

WEBCORE_EXPORT std::unique_ptr<LogClient>& logClient();

}

