ReplayController.h [plain text]
#ifndef ReplayController_h
#define ReplayController_h
#if ENABLE(WEB_REPLAY)
#include "EventLoopInputDispatcher.h"
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
#define ENABLE_AGGRESSIVE_DETERMINISM_CHECKS 0
namespace JSC {
class InputCursor;
}
namespace WebCore {
class DOMWindow;
class Document;
class DocumentLoader;
class Element;
class Event;
class EventLoopInputBase;
class Frame;
class Node;
class Page;
class ReplaySession;
class ReplaySessionSegment;
enum class SessionState {
Capturing,
Inactive,
Replaying,
};
enum class SegmentState {
Appending,
Unloaded,
Loaded,
Dispatching,
};
struct ReplayPosition {
ReplayPosition(unsigned segmentOffset, unsigned inputOffset)
: segmentOffset(segmentOffset)
, inputOffset(inputOffset)
{
}
ReplayPosition()
: segmentOffset(0)
, inputOffset(0)
{
}
bool operator<(const ReplayPosition& other)
{
return segmentOffset <= other.segmentOffset && inputOffset < other.inputOffset;
}
bool operator==(const ReplayPosition& other)
{
return segmentOffset == other.segmentOffset && inputOffset == other.inputOffset;
}
unsigned segmentOffset;
unsigned inputOffset;
};
class ReplayController final : public EventLoopInputDispatcherClient {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(ReplayController);
public:
ReplayController(Page&);
void startCapturing();
void stopCapturing();
void startPlayback();
void pausePlayback();
void cancelPlayback();
void replayToPosition(const ReplayPosition&, DispatchSpeed = DispatchSpeed::FastForward);
void replayToCompletion(DispatchSpeed speed = DispatchSpeed::FastForward)
{
replayToPosition(ReplayPosition(), speed);
}
void switchSession(RefPtr<ReplaySession>&&);
void frameNavigated(DocumentLoader*);
void frameDetached(Frame&);
void willDispatchEvent(const Event&, Frame*);
Page& page() const { return m_page; }
SessionState sessionState() const { return m_sessionState; }
SegmentState segmentState() const { return m_segmentState; }
RefPtr<ReplaySession> loadedSession() const;
RefPtr<ReplaySessionSegment> loadedSegment() const;
JSC::InputCursor& activeInputCursor();
ReplayPosition currentPosition() const { return m_currentPosition; }
private:
virtual void willDispatchInput(const EventLoopInputBase&) override;
virtual void didDispatchInput(const EventLoopInputBase&) override;
virtual void didDispatchFinalInput() override;
void createSegment();
void completeSegment();
void loadSegmentAtIndex(size_t);
void unloadSegment(bool suppressNotifications = false);
EventLoopInputDispatcher& dispatcher() const;
void setSessionState(SessionState);
void setSegmentState(SegmentState);
void setForceDeterministicSettings(bool);
struct SavedSettings {
bool usesPageCache;
SavedSettings()
: usesPageCache(false)
{ }
};
Page& m_page;
RefPtr<ReplaySessionSegment> m_loadedSegment;
RefPtr<ReplaySession> m_loadedSession;
Ref<JSC::InputCursor> m_emptyCursor;
RefPtr<JSC::InputCursor> m_activeCursor;
ReplayPosition m_targetPosition;
ReplayPosition m_currentPosition;
SegmentState m_segmentState;
SessionState m_sessionState;
DispatchSpeed m_dispatchSpeed;
SavedSettings m_savedSettings;
};
}
#endif // ENABLE(WEB_REPLAY)
#endif // ReplayController_h