
/* 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 SUBRESOURCELOADER_DIDFINISHLOADING(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_CANCELLED_INVALID_NEW_REQUEST(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_CANCELLED_TERMINAL_STATE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_TERMINAL_STATE_CALLING_COMPLETION_HANDLER(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_CANCELLED_INVALID_REQUEST(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCELOAD_FINISHED(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCELOAD_CANCELLED_REDIRECT_NOT_ALLOWED(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_REACHED_TERMINAL_STATE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_COMPLETED(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_CANCELLED_TOO_MANY_REDIRECTS(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_CANCELLED_CANNOT_REQUEST_AFTER_REDIRECTION(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_CANCELLED_AFTER_USING_BLOCKED_PORT(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_CANCELLED_AFTER_REDIRECT_DENIED_BY_CORS_POLICY(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_LOAD_CANCELLED_AFTER_IMAGE_BEING_DEFERRED(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_WILLSENDREQUESTINTERNAL_RESOURCE_DONE_NOTIFYING_CLIENTS(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDRECEIVERESPONSE_CANCELING_LOAD_BLOCKED_BY_CONTENT_POLICY(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDRECEIVERESPONSE_CANCELING_LOAD_RECEIVED_UNEXPECTED_RANGE_RESPONSE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDRECEIVERESPONSE_CANCELING_LOAD_BECAUSE_OF_CROSS_ORIGIN_ACCESS_CONTROL(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDRECEIVERESPONSE_CANCELING_LOAD_BECAUSE_OF_MULTIPART_NON_IMAGE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDFINISHLOADING_CANCELED(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDFINISHLOADING_REACHED_TERMINAL_STATE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDFINISHLOADING_DID_NOT_REACH_TERMINAL_STATE(uint64_t, uint64_t, uint64_t) { }
    virtual void SUBRESOURCELOADER_DIDFAIL(uint64_t, uint64_t, uint64_t, int, int) { }
    virtual void SUBRESOURCELOADER_WILLCANCEL(uint64_t, uint64_t, uint64_t, int, int) { }
    virtual void PROGRESSTRACKER_PROGRESSSTARTED(uint64_t, double, int, uint64_t, int) { }
    virtual void PROGRESSTRACKER_PROGRESSCOMPLETED(uint64_t, double, int, uint64_t, int) { }
    virtual void PROGRESSTRACKER_FINALPROGRESSCOMPLETE(double, int, uint64_t, int, int) { }
    virtual void FRAMELOADER_SETPROVISIONALDOCUMENTLOADER(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FRAMELOADER_SETSTATE_MAIN_FRAME_LOAD_COMPLETED(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_SETPOLICYDOCUMENTLOADER(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FRAMELOADER_TRANSITIONTOCOMMITTED(uint64_t, uint64_t, int, uint64_t) { }
    virtual void FRAMELOADER_SETDOCUMENTLOADER(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FRAMELOADER_STOPALLLOADERS_CLEARING_PROVISIONAL_DOCUMENT_LOADER(uint64_t, uint64_t, int, uint64_t) { }
    virtual void FRAMELOADER_LOADWITHDOCUMENTLOADER_FRAME_LOAD_STARTED(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOADWITHDOCUMENTLOADER_MAIN_FRAME_LOAD_STARTED(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_STOPALLLOADERS(uint64_t, uint64_t, int, uint64_t, uint64_t) { }
    virtual void FRAMELOADER_CONTINUELOADAFTERNAVIGATIONPOLICY(uint64_t, uint64_t, int, uint64_t) { }
    virtual void FRAMELOADER_PREPAREFORLOADSTART(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_CHANGELOCATION(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOADFRAMEREQUEST_FRAME_LOAD_STARTED(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_CHECKLOADCOMPLETEFORTHISFRAME(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOAD_URL(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOADWITHNAVIGATIONACTION(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOADURLINTOCHILDFRAME(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_CONTINUELOADAFTERNAVIGATIONPOLICY_CANNOT_CONTINUE(uint64_t, uint64_t, int, int, int, int) { }
    virtual void FRAMELOADER_LOAD_FRAMELOADREQUEST(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_LOAD_DOCUMENTLOADER(uint64_t, uint64_t, int) { }
    virtual void FRAMELOADER_RELOAD(uint64_t, uint64_t, int) { }
    virtual void RESOURCELOADER_WILLSENDREQUESTINTERNAL(uint64_t, uint64_t, uint64_t) { }
    virtual void DOCUMENTLOADER_STARTLOADINGMAINRESOURCE_EMTPY_DOCUMENT(uint64_t, uint64_t, int) { }
    virtual void DOCUMENTLOADER_STARTLOADINGMAINRESOURCE_STARTING_LOAD(uint64_t, uint64_t, int) { }
    virtual void DOCUMENTLOADER_ATTACHTOFRAME(uint64_t, uint64_t, int) { }
    virtual void DOCUMENTLOADER_DETACHFROMFRAME(uint64_t, uint64_t, int) { }
    virtual void DOCUMENTLOADER_STOPLOADING(uint64_t, uint64_t, int) { }
    virtual void MEDIASESSIONMANAGERCOCOA_SESSIONCANPRODUCEAUDIOCHANGED() { }
    virtual void MEDIASESSIONMANAGERCOCOA_CLIENTCHARACTERISTICSCHANGED(uint64_t) { }
    virtual void MEDIASESSIONMANAGERCOCOA_UPDATESESSIONSTATE(int, int, int, int, int, int, int) { }
    virtual void MEDIASESSIONMANAGERINTERFACE_REMOVESESSION(uint64_t) { }
    virtual void MEDIASESSIONMANAGERINTERFACE_SESSIONWILLENDPLAYBACK(uint64_t) { }
    virtual void MEDIASESSIONMANAGERINTERFACE_SESSIONCANPRODUCEAUDIOCHANGED() { }
    virtual void MEDIASESSIONMANAGERINTERFACE_ADDSESSION(uint64_t) { }
    virtual void MEDIASESSIONMANAGERINTERFACE_MAYBEACTIVATEAUDIOSESSION_ACTIVE_SESSION_NOT_REQUIRED() { }
    virtual void HTMLMEDIAELEMENT_CONSTRUCTOR(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_DESTRUCTOR(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SETBUFFERINGPOLICY(uint64_t, uint8_t) { }
    virtual void HTMLMEDIAELEMENT_INSERTEDINTOANCESTOR(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_REMOVEDFROMANCESTOR(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_DIDFINISHINSERTINGNODE(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERRATECHANGED(uint64_t, double) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERTIMECHANGED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SETSHOULDDELAYLOADEVENT(uint64_t, uint8_t) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERENGINEUPDATED(uint64_t, CString&&) { }
    virtual void HTMLMEDIAELEMENT_CURRENTMEDIATIME_SEEKING(uint64_t, float) { }
    virtual void HTMLMEDIAELEMENT_UPDATEPLAYSTATE(uint64_t, int, int) { }
    virtual void HTMLMEDIAELEMENT_VISIBILITYSTATECHANGED(uint64_t, int) { }
    virtual void HTMLMEDIAELEMENT_CREATEMEDIAPLAYER(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_PLAY(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_PLAYINTERNAL(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_ADDAUDIOTRACK(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_ADDVIDEOTRACK(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_CANPLAYTYPE(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_CANTRANSITIONFROMAUTOPLAYTOPLAY_NOT_ENOUGH_DATA(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_CANTRANSITIONFROMAUTOPLAYTOPLAY_NOT_AUTOPLAYING(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_CONFIGURETEXTTRACKDISPLAY(uint64_t, CString&&) { }
    virtual void HTMLMEDIAELEMENT_CONFIGURETEXTTRACKGROUP(uint64_t, CString&&, CString&&, CString&&, int) { }
    virtual void HTMLMEDIAELEMENT_MEDIAENGINEWASUPDATED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERCHARACTERISTICSCHANGED(uint64_t, CString&&) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERCHARACTERISTICSCHANGED_NO_MEDIASESSION(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERDURATIONCHANGED(uint64_t, float, float) { }
    virtual void HTMLMEDIAELEMENT_MEDIAPLAYERSIZECHANGED(uint64_t, float, float) { }
    virtual void HTMLMEDIAELEMENT_PAUSE(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_PAUSEINTERNAL(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_PREPAREFORLOAD(uint64_t, int) { }
    virtual void HTMLMEDIAELEMENT_REMOVEAUDIOTRACK(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_SCENEIDENTIFIERDIDCHANGE(uint64_t, CString&&) { }
    virtual void HTMLMEDIAELEMENT_SCHEDULECONFIGURETEXTTRACKS_TASK_SCHEDULED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SCHEDULECONFIGURETEXTTRACKS_LAMBDA_TASK_FIRED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SCHEDULEMEDIAENGINEWASUPDATED_TASK_SCHEDULED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SCHEDULEMEDIAENGINEWASUPDATED_LAMBDA_TASK_FIRED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_LAMBDA_TASK_FIRED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_NOTHING_TO_LOAD(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_HAS_SRCATTR_PLAYER_NOT_CREATED(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_ATTEMPTING_USE_OF_UNATTACHED_MEDIASOURCEHANDLE(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_USING_SRCOBJECT_PROPERTY(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_USING_SRC_ATTRIBUTE_URL(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SELECTMEDIARESOURCE_EMPTY_SRC(uint64_t) { }
    virtual void HTMLMEDIAELEMENT_SETAUTOPLAYEVENTPLAYBACKSTATE(uint64_t, CString&&) { }
    virtual void HTMLMEDIAELEMENT_SETMUTEDINTERNAL(uint64_t, int) { }
    virtual void HTMLMEDIAELEMENT_SETNETWORKSTATE(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_SETPLAYBACKRATE(uint64_t, double) { }
    virtual void HTMLMEDIAELEMENT_SETREADYSTATE(uint64_t, CString&&, CString&&) { }
    virtual void HTMLMEDIAELEMENT_SETSHOWPOSTERFLAG(uint64_t, int) { }
    virtual void HTMLMEDIAELEMENT_SETVOLUME(uint64_t, double) { }
    virtual void HTMLVIDEOELEMENT_MEDIAPLAYERRENDERINGMODECHANGED(uint64_t) { }
    virtual void HTMLVIDEOELEMENT_MEDIAPLAYERFIRSTVIDEOFRAMEAVAILABLE(uint64_t, int) { }
    virtual void HTMLVIDEOELEMENT_SCHEDULERESIZEEVENT(uint64_t, float, float) { }
    virtual void PERFORMANCELOGGING_MEMORY_USAGE_INFO(CString&&) { }
    virtual void PERFORMANCELOGGING_MEMORY_USAGE_FOR_KEY(CString&&, uint64_t) { }
    virtual void PERFORMANCEMONITOR_MEASURE_POSTLOAD_CPUUSAGE(double) { }
    virtual void PERFORMANCEMONITOR_MEASURE_POSTLOAD_MEMORYUSAGE(uint64_t) { }
    virtual void PERFORMANCEMONITOR_MEASURE_POSTBACKGROUND_MEMORYUSAGE(uint64_t) { }
    virtual void PERFORMANCEMONITOR_MEASURE_POSTBACKGROUND_CPUUSAGE(double) { }
    virtual void PERFORMANCEMONITOR_MEASURE_CPUUSAGE_IN_ACTIVITYSTATE(double, CString&&) { }
    virtual void POLICYCHECKER_CHECKNAVIGATIONPOLICY_CONTINUE_LOAD_IN_ANOTHER_PROCESS(uint64_t, uint64_t) { }
    virtual void POLICYCHECKER_CHECKNAVIGATIONPOLICY_CONTINUE_INITIAL_EMPTY_DOCUMENT(uint64_t, uint64_t) { }
    virtual void LIBWEBRTCMEDIAENDPOINT_ONSTATSDELIVERED(uint64_t, CString&&) { }
    virtual void LIBWEBRTC_LOG_ERROR(CString&&) { }
    virtual void LIBWEBRTC_LOG_MESSAGE(CString&&) { }
    virtual void LOCALFRAMEVIEW_FIRING_FIRST_VISUALLY_NON_EMPTY_LAYOUT_MILESTONE(uint64_t, uint64_t, int) { }
    virtual void LOCALFRAMEVIEW_FIRING_RESIZE_EVENTS_DISABLED_FOR_PAGE(uint64_t, uint64_t, int) { }
    virtual void LOCALFRAMEVIEW_NOT_PAINTING_LAYOUT_NEEDED(uint64_t, uint64_t, int) { }
    virtual void PEERCONNECTIONBACKEND_CREATEOFFERSUCCEEDED(uint64_t, CString&&) { }
    virtual void PEERCONNECTIONBACKEND_CREATEANSWERSUCCEEDED(uint64_t, CString&&) { }
    virtual void RTCPEERCONNECTION_SETLOCALDESCRIPTION(uint64_t, CString&&) { }
    virtual void RTCPEERCONNECTION_SETREMOTEDESCRIPTION(uint64_t, CString&&) { }
    virtual void SERVICEWORKERTHREADPROXY_REMOVEFETCH(uint64_t) { }
    virtual void FONTCACHECORETEXT_REGISTER_FONT(CString&&, CString&&) { }
    virtual void FONTCACHECORETEXT_REGISTER_ERROR(CString&&, CString&&) { }
    virtual void WEBCORE_TEST_LOG(unsigned) { }

    };

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

}

