ea2b7d2bafcfabadcdf39a8dbba498c4003d5eda
[WebKit-https.git] / Source / WebCore / page / Page.h
1 /*
2  * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #pragma once
22
23 #include "ActivityState.h"
24 #include "DisabledAdaptations.h"
25 #include "Document.h"
26 #include "FindOptions.h"
27 #include "FrameLoaderTypes.h"
28 #include "LayoutMilestone.h"
29 #include "LayoutRect.h"
30 #include "LengthBox.h"
31 #include "MediaProducer.h"
32 #include "Pagination.h"
33 #include "RTCController.h"
34 #include "Region.h"
35 #include "RegistrableDomain.h"
36 #include "RenderingUpdateScheduler.h"
37 #include "ScrollTypes.h"
38 #include "Supplementable.h"
39 #include "Timer.h"
40 #include "UserInterfaceLayoutDirection.h"
41 #include "ViewportArguments.h"
42 #include "VisibilityState.h"
43 #include "WheelEventTestMonitor.h"
44 #include <memory>
45 #include <pal/SessionID.h>
46 #include <wtf/Assertions.h>
47 #include <wtf/Forward.h>
48 #include <wtf/Function.h>
49 #include <wtf/HashSet.h>
50 #include <wtf/Noncopyable.h>
51 #include <wtf/Ref.h>
52 #include <wtf/UniqueRef.h>
53 #include <wtf/WeakPtr.h>
54 #include <wtf/text/WTFString.h>
55
56 #if PLATFORM(COCOA)
57 #include <wtf/SchedulePair.h>
58 #endif
59
60 #if ENABLE(APPLICATION_MANIFEST)
61 #include "ApplicationManifest.h"
62 #endif
63
64 #if ENABLE(MEDIA_SESSION)
65 #include "MediaSessionEvents.h"
66 #endif
67
68 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
69 #include "MediaPlaybackTargetContext.h"
70 #endif
71
72 namespace JSC {
73 class Debugger;
74 }
75
76 namespace WebCore {
77
78 namespace IDBClient {
79 class IDBConnectionToServer;
80 }
81
82 class AlternativeTextClient;
83 class ApplicationCacheStorage;
84 class AuthenticatorCoordinator;
85 class BackForwardController;
86 class BackForwardClient;
87 class CacheStorageProvider;
88 class Chrome;
89 class ChromeClient;
90 class Color;
91 class ContextMenuClient;
92 class ContextMenuController;
93 class CookieJar;
94 class DOMRect;
95 class DOMRectList;
96 class DatabaseProvider;
97 class DiagnosticLoggingClient;
98 class DragCaretController;
99 class DragClient;
100 class DragController;
101 class EditorClient;
102 class Element;
103 class FocusController;
104 class Frame;
105 class FrameLoaderClient;
106 class HistoryItem;
107 class HTMLMediaElement;
108 class UserInputBridge;
109 class InspectorClient;
110 class InspectorController;
111 class LibWebRTCProvider;
112 class LowPowerModeNotifier;
113 class MediaCanStartListener;
114 class MediaPlaybackTarget;
115 class PageConfiguration;
116 class PageConsoleClient;
117 class PageDebuggable;
118 class PageGroup;
119 class PageOverlayController;
120 class PaymentCoordinator;
121 class PerformanceLogging;
122 class PerformanceLoggingClient;
123 class PerformanceMonitor;
124 class PlugInClient;
125 class PluginData;
126 class PluginInfoProvider;
127 class PluginViewBase;
128 class PointerCaptureController;
129 class PointerLockController;
130 class ProgressTracker;
131 class ProgressTrackerClient;
132 class Range;
133 class RenderObject;
134 class RenderTheme;
135 class ResourceUsageOverlay;
136 class VisibleSelection;
137 class ScrollLatchingState;
138 class ScrollableArea;
139 class ScrollingCoordinator;
140 class ServicesOverlayController;
141 class Settings;
142 class SocketProvider;
143 class StorageNamespace;
144 class StorageNamespaceProvider;
145 class UserContentProvider;
146 class ValidationMessageClient;
147 class ActivityStateChangeObserver;
148 class VisitedLinkStore;
149 class WebGLStateTracker;
150 class SpeechSynthesisClient;
151 class WheelEventDeltaFilter;
152
153 typedef uint64_t SharedStringHash;
154
155 enum FindDirection {
156     FindDirectionForward,
157     FindDirectionBackward
158 };
159
160 enum class EventThrottlingBehavior {
161     Responsive,
162     Unresponsive
163 };
164
165 enum class CompositingPolicy : uint8_t {
166     Normal,
167     Conservative, // Used in low memory situations.
168 };
169
170 enum class CanWrap : bool;
171 enum class DidWrap : bool;
172 enum class RouteSharingPolicy : uint8_t;
173 enum class ShouldTreatAsContinuingLoad : bool;
174
175 class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
176     WTF_MAKE_NONCOPYABLE(Page);
177     WTF_MAKE_FAST_ALLOCATED;
178     friend class SettingsBase;
179
180 public:
181     WEBCORE_EXPORT static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
182     WEBCORE_EXPORT static void clearPreviousItemFromAllPages(HistoryItem*);
183
184     void updateStyleAfterChangeInEnvironment();
185
186     WEBCORE_EXPORT explicit Page(PageConfiguration&&);
187     WEBCORE_EXPORT ~Page();
188
189     WEBCORE_EXPORT uint64_t renderTreeSize() const;
190
191     WEBCORE_EXPORT void setNeedsRecalcStyleInAllFrames();
192
193     WEBCORE_EXPORT OptionSet<DisabledAdaptations> disabledAdaptations() const;
194     WEBCORE_EXPORT ViewportArguments viewportArguments() const;
195
196     const Optional<ViewportArguments>& overrideViewportArguments() const { return m_overrideViewportArguments; }
197     WEBCORE_EXPORT void setOverrideViewportArguments(const Optional<ViewportArguments>&);
198
199     static void refreshPlugins(bool reload);
200     WEBCORE_EXPORT PluginData& pluginData();
201     void clearPluginData();
202
203     WEBCORE_EXPORT void setCanStartMedia(bool);
204     bool canStartMedia() const { return m_canStartMedia; }
205
206     EditorClient& editorClient() { return m_editorClient.get(); }
207     PlugInClient* plugInClient() const { return m_plugInClient; }
208
209     Frame& mainFrame() { return m_mainFrame.get(); }
210     const Frame& mainFrame() const { return m_mainFrame.get(); }
211
212     bool openedByDOM() const;
213     void setOpenedByDOM();
214
215     bool openedByDOMWithOpener() const { return m_openedByDOMWithOpener; }
216     void setOpenedByDOMWithOpener() { m_openedByDOMWithOpener = true; }
217
218     WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType, ShouldTreatAsContinuingLoad);
219
220     WEBCORE_EXPORT void setGroupName(const String&);
221     WEBCORE_EXPORT const String& groupName() const;
222
223     PageGroup& group();
224
225     WEBCORE_EXPORT static void forEachPage(const WTF::Function<void(Page&)>&);
226
227     void incrementSubframeCount() { ++m_subframeCount; }
228     void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
229     int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
230
231     void incrementNestedRunLoopCount();
232     void decrementNestedRunLoopCount();
233     bool insideNestedRunLoop() const { return m_nestedRunLoopCount > 0; }
234     WEBCORE_EXPORT void whenUnnested(WTF::Function<void()>&&);
235
236 #if ENABLE(REMOTE_INSPECTOR)
237     WEBCORE_EXPORT bool remoteInspectionAllowed() const;
238     WEBCORE_EXPORT void setRemoteInspectionAllowed(bool);
239     WEBCORE_EXPORT String remoteInspectionNameOverride() const;
240     WEBCORE_EXPORT void setRemoteInspectionNameOverride(const String&);
241     void remoteInspectorInformationDidChange() const;
242 #endif
243
244     Chrome& chrome() const { return *m_chrome; }
245     DragCaretController& dragCaretController() const { return *m_dragCaretController; }
246 #if ENABLE(DRAG_SUPPORT)
247     DragController& dragController() const { return *m_dragController; }
248 #endif
249     FocusController& focusController() const { return *m_focusController; }
250 #if ENABLE(CONTEXT_MENUS)
251     ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
252 #endif
253     UserInputBridge& userInputBridge() const { return *m_userInputBridge; }
254     InspectorController& inspectorController() const { return *m_inspectorController; }
255 #if ENABLE(POINTER_EVENTS)
256     PointerCaptureController& pointerCaptureController() const { return *m_pointerCaptureController; }
257 #endif
258 #if ENABLE(POINTER_LOCK)
259     PointerLockController& pointerLockController() const { return *m_pointerLockController; }
260 #endif
261     LibWebRTCProvider& libWebRTCProvider() { return m_libWebRTCProvider.get(); }
262     RTCController& rtcController() { return m_rtcController; }
263     WEBCORE_EXPORT void disableICECandidateFiltering();
264     WEBCORE_EXPORT void enableICECandidateFiltering();
265     bool shouldEnableICECandidateFilteringByDefault() const { return m_shouldEnableICECandidateFilteringByDefault; }
266
267     void didChangeMainDocument();
268
269     PerformanceMonitor* performanceMonitor() { return m_performanceMonitor.get(); }
270
271     RenderingUpdateScheduler& renderingUpdateScheduler();
272
273     ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient.get(); }
274     void updateValidationBubbleStateIfNeeded();
275
276     WEBCORE_EXPORT ScrollingCoordinator* scrollingCoordinator();
277
278     WEBCORE_EXPORT String scrollingStateTreeAsText();
279     WEBCORE_EXPORT String synchronousScrollingReasonsAsText();
280     WEBCORE_EXPORT Ref<DOMRectList> nonFastScrollableRects();
281
282     WEBCORE_EXPORT Ref<DOMRectList> touchEventRectsForEvent(const String& eventName);
283     WEBCORE_EXPORT Ref<DOMRectList> passiveTouchEventListenerRects();
284
285     Settings& settings() const { return *m_settings; }
286     ProgressTracker& progress() const { return *m_progress; }
287     BackForwardController& backForward() const { return *m_backForwardController; }
288
289     Seconds domTimerAlignmentInterval() const { return m_domTimerAlignmentInterval; }
290
291     void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
292     bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
293
294     WEBCORE_EXPORT bool findString(const String&, FindOptions, DidWrap* = nullptr);
295     WEBCORE_EXPORT uint32_t replaceRangesWithText(const Vector<Ref<Range>>& rangesToReplace, const String& replacementText, bool selectionOnly);
296     WEBCORE_EXPORT uint32_t replaceSelectionWithText(const String& replacementText);
297
298     WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
299
300     WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
301     WEBCORE_EXPORT unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned maxMatchCount);
302
303     WEBCORE_EXPORT void unmarkAllTextMatches();
304
305     WEBCORE_EXPORT void dispatchBeforePrintEvent();
306     WEBCORE_EXPORT void dispatchAfterPrintEvent();
307
308     // find all the Ranges for the matching text.
309     // Upon return, indexForSelection will be one of the following:
310     // 0 if there is no user selection
311     // the index of the first range after the user selection
312     // NoMatchAfterUserSelection if there is no matching text after the user selection.
313     enum { NoMatchAfterUserSelection = -1 };
314     WEBCORE_EXPORT void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>&, int& indexForSelection);
315 #if PLATFORM(COCOA)
316     void platformInitialize();
317     WEBCORE_EXPORT void addSchedulePair(Ref<SchedulePair>&&);
318     WEBCORE_EXPORT void removeSchedulePair(Ref<SchedulePair>&&);
319     SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
320
321     std::unique_ptr<SchedulePairHashSet> m_scheduledRunLoopPairs;
322 #endif
323
324     WEBCORE_EXPORT const VisibleSelection& selection() const;
325
326     WEBCORE_EXPORT void setDefersLoading(bool);
327     bool defersLoading() const { return m_defersLoading; }
328
329     WEBCORE_EXPORT void clearUndoRedoOperations();
330
331     WEBCORE_EXPORT bool inLowQualityImageInterpolationMode() const;
332     WEBCORE_EXPORT void setInLowQualityImageInterpolationMode(bool = true);
333
334     float mediaVolume() const { return m_mediaVolume; }
335     WEBCORE_EXPORT void setMediaVolume(float);
336
337     WEBCORE_EXPORT void setPageScaleFactor(float scale, const IntPoint& origin, bool inStableState = true);
338     float pageScaleFactor() const { return m_pageScaleFactor; }
339
340     UserInterfaceLayoutDirection userInterfaceLayoutDirection() const { return m_userInterfaceLayoutDirection; }
341     WEBCORE_EXPORT void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
342
343     WEBCORE_EXPORT void updateMediaElementRateChangeRestrictions();
344
345     void didStartProvisionalLoad();
346     void didFinishLoad(); // Called when the load has been committed in the main frame.
347
348     // The view scale factor is multiplied into the page scale factor by all
349     // callers of setPageScaleFactor.
350     WEBCORE_EXPORT void setViewScaleFactor(float);
351     float viewScaleFactor() const { return m_viewScaleFactor; }
352
353     WEBCORE_EXPORT void setZoomedOutPageScaleFactor(float);
354     float zoomedOutPageScaleFactor() const { return m_zoomedOutPageScaleFactor; }
355
356     float deviceScaleFactor() const { return m_deviceScaleFactor; }
357     WEBCORE_EXPORT void setDeviceScaleFactor(float);
358
359     float initialScale() const { return m_initialScale; }
360     WEBCORE_EXPORT void setInitialScale(float);
361
362     float topContentInset() const { return m_topContentInset; }
363     WEBCORE_EXPORT void setTopContentInset(float);
364
365     const FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; }
366     void setObscuredInsets(const FloatBoxExtent& obscuredInsets) { m_obscuredInsets = obscuredInsets; }
367
368     const FloatBoxExtent& contentInsets() const { return m_contentInsets; }
369     void setContentInsets(const FloatBoxExtent& insets) { m_contentInsets = insets; }
370
371     const FloatBoxExtent& unobscuredSafeAreaInsets() const { return m_unobscuredSafeAreaInsets; }
372     WEBCORE_EXPORT void setUnobscuredSafeAreaInsets(const FloatBoxExtent&);
373
374 #if PLATFORM(IOS_FAMILY)
375     bool enclosedInScrollableAncestorView() const { return m_enclosedInScrollableAncestorView; }
376     void setEnclosedInScrollableAncestorView(bool f) { m_enclosedInScrollableAncestorView = f; }
377 #endif
378     
379     bool useSystemAppearance() const { return m_useSystemAppearance; }
380     WEBCORE_EXPORT void setUseSystemAppearance(bool);
381     
382     WEBCORE_EXPORT bool useDarkAppearance() const;
383     bool useElevatedUserInterfaceLevel() const { return m_useElevatedUserInterfaceLevel; }
384     WEBCORE_EXPORT void effectiveAppearanceDidChange(bool useDarkAppearance, bool useElevatedUserInterfaceLevel);
385     bool defaultUseDarkAppearance() const { return m_useDarkAppearance; }
386     void setUseDarkAppearanceOverride(Optional<bool>);
387
388 #if ENABLE(TEXT_AUTOSIZING)
389     float textAutosizingWidth() const { return m_textAutosizingWidth; }
390     void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
391     WEBCORE_EXPORT void recomputeTextAutoSizingInAllFrames();
392 #endif
393
394     const FloatBoxExtent& fullscreenInsets() const { return m_fullscreenInsets; }
395     WEBCORE_EXPORT void setFullscreenInsets(const FloatBoxExtent&);
396
397     const Seconds fullscreenAutoHideDuration() const { return m_fullscreenAutoHideDuration; }
398     WEBCORE_EXPORT void setFullscreenAutoHideDuration(Seconds);
399     WEBCORE_EXPORT void setFullscreenControlsHidden(bool);
400
401     bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
402     WEBCORE_EXPORT void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
403     void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
404     
405     WEBCORE_EXPORT void setVerticalScrollElasticity(ScrollElasticity);
406     ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
407
408     WEBCORE_EXPORT void setHorizontalScrollElasticity(ScrollElasticity);
409     ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
410
411     WEBCORE_EXPORT void accessibilitySettingsDidChange();
412     WEBCORE_EXPORT void appearanceDidChange();
413
414     // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
415     // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
416     // FrameViews in the back/forward cache, but FrameView::pagination() only affects the current
417     // FrameView.
418     const Pagination& pagination() const { return m_pagination; }
419     WEBCORE_EXPORT void setPagination(const Pagination&);
420     bool paginationLineGridEnabled() const { return m_paginationLineGridEnabled; }
421     WEBCORE_EXPORT void setPaginationLineGridEnabled(bool flag);
422
423     WEBCORE_EXPORT unsigned pageCount() const;
424
425     WEBCORE_EXPORT DiagnosticLoggingClient& diagnosticLoggingClient() const;
426
427     PerformanceLoggingClient* performanceLoggingClient() const { return m_performanceLoggingClient.get(); }
428
429     WheelEventDeltaFilter* wheelEventDeltaFilter() { return m_recentWheelEventDeltaFilter.get(); }
430     PageOverlayController& pageOverlayController() { return *m_pageOverlayController; }
431
432 #if PLATFORM(MAC)
433 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
434     ServicesOverlayController& servicesOverlayController() { return *m_servicesOverlayController; }
435 #endif // ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
436
437     ScrollLatchingState* latchingState();
438     void pushNewLatchingState();
439     void popLatchingState();
440     void resetLatchingState();
441     void removeLatchingStateForTarget(Element&);
442 #endif // PLATFORM(MAC)
443
444 #if ENABLE(APPLE_PAY)
445     PaymentCoordinator& paymentCoordinator() const { return *m_paymentCoordinator; }
446     WEBCORE_EXPORT void setPaymentCoordinator(std::unique_ptr<PaymentCoordinator>&&);
447 #endif
448
449 #if ENABLE(WEB_AUTHN)
450     AuthenticatorCoordinator& authenticatorCoordinator() { return m_authenticatorCoordinator.get(); }
451 #endif
452
453 #if ENABLE(APPLICATION_MANIFEST)
454     const Optional<ApplicationManifest>& applicationManifest() const { return m_applicationManifest; }
455 #endif
456
457     // Notifications when the Page starts and stops being presented via a native window.
458     WEBCORE_EXPORT void setActivityState(OptionSet<ActivityState::Flag>);
459     OptionSet<ActivityState::Flag> activityState() const { return m_activityState; }
460
461     bool isWindowActive() const;
462     bool isVisibleAndActive() const;
463     WEBCORE_EXPORT void setIsVisible(bool);
464     WEBCORE_EXPORT void setIsPrerender();
465     bool isVisible() const { return m_activityState.contains(ActivityState::IsVisible); }
466
467     // Notification that this Page was moved into or out of a native window.
468     WEBCORE_EXPORT void setIsInWindow(bool);
469     bool isInWindow() const { return m_activityState.contains(ActivityState::IsInWindow); }
470
471     void setIsClosing() { m_isClosing = true; }
472     bool isClosing() const { return m_isClosing; }
473
474     void setIsRestoringCachedPage(bool value) { m_isRestoringCachedPage = value; }
475     bool isRestoringCachedPage() const { return m_isRestoringCachedPage; }
476
477     WEBCORE_EXPORT void addActivityStateChangeObserver(ActivityStateChangeObserver&);
478     WEBCORE_EXPORT void removeActivityStateChangeObserver(ActivityStateChangeObserver&);
479
480     WEBCORE_EXPORT void layoutIfNeeded();
481     WEBCORE_EXPORT void updateRendering();
482
483     WEBCORE_EXPORT void suspendScriptedAnimations();
484     WEBCORE_EXPORT void resumeScriptedAnimations();
485     bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
486
487     void userStyleSheetLocationChanged();
488     const String& userStyleSheet() const;
489
490     WEBCORE_EXPORT void userAgentChanged();
491
492     void dnsPrefetchingStateChanged();
493     void storageBlockingStateChanged();
494
495 #if ENABLE(RESOURCE_USAGE)
496     void setResourceUsageOverlayVisible(bool);
497 #endif
498
499     void setDebugger(JSC::Debugger*);
500     JSC::Debugger* debugger() const { return m_debugger; }
501
502     WEBCORE_EXPORT void invalidateStylesForAllLinks();
503     WEBCORE_EXPORT void invalidateStylesForLink(SharedStringHash);
504
505     void invalidateInjectedStyleSheetCacheInAllFrames();
506
507     StorageNamespace* sessionStorage(bool optionalCreate = true);
508     void setSessionStorage(RefPtr<StorageNamespace>&&);
509
510     bool hasCustomHTMLTokenizerTimeDelay() const;
511     double customHTMLTokenizerTimeDelay() const;
512
513     WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool);
514     bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
515
516     // Don't allow more than a certain number of frames in a page.
517     // This seems like a reasonable upper bound, and otherwise mutually
518     // recursive frameset pages can quickly bring the program to its knees
519     // with exponential growth in the number of frames.
520     static const int maxNumberOfFrames = 1000;
521
522     void setEditable(bool isEditable) { m_isEditable = isEditable; }
523     bool isEditable() { return m_isEditable; }
524
525     WEBCORE_EXPORT VisibilityState visibilityState() const;
526     WEBCORE_EXPORT void resumeAnimatingImages();
527
528     void didFinishLoadingImageForElement(HTMLImageElement&);
529
530     WEBCORE_EXPORT void addLayoutMilestones(OptionSet<LayoutMilestone>);
531     WEBCORE_EXPORT void removeLayoutMilestones(OptionSet<LayoutMilestone>);
532     OptionSet<LayoutMilestone> requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
533
534     WEBCORE_EXPORT void setHeaderHeight(int);
535     WEBCORE_EXPORT void setFooterHeight(int);
536
537     int headerHeight() const { return m_headerHeight; }
538     int footerHeight() const { return m_footerHeight; }
539
540     WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
541
542     bool isCountingRelevantRepaintedObjects() const;
543     void setIsCountingRelevantRepaintedObjects(bool isCounting) { m_isCountingRelevantRepaintedObjects = isCounting; }
544     void startCountingRelevantRepaintedObjects();
545     void resetRelevantPaintedObjectCounter();
546     void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
547     void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
548
549     WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
550     WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
551     void suspendDeviceMotionAndOrientationUpdates();
552     void resumeDeviceMotionAndOrientationUpdates();
553
554 #ifndef NDEBUG
555     void setIsPainting(bool painting) { m_isPainting = painting; }
556     bool isPainting() const { return m_isPainting; }
557 #endif
558
559     AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
560
561     bool hasSeenPlugin(const String& serviceType) const;
562     WEBCORE_EXPORT bool hasSeenAnyPlugin() const;
563     void sawPlugin(const String& serviceType);
564     void resetSeenPlugins();
565
566     bool hasSeenMediaEngine(const String& engineName) const;
567     bool hasSeenAnyMediaEngine() const;
568     void sawMediaEngine(const String& engineName);
569     void resetSeenMediaEngines();
570
571     PageConsoleClient& console() { return *m_consoleClient; }
572
573 #if ENABLE(REMOTE_INSPECTOR)
574     PageDebuggable& inspectorDebuggable() const { return *m_inspectorDebuggable.get(); }
575 #endif
576
577     void hiddenPageCSSAnimationSuspensionStateChanged();
578
579 #if ENABLE(VIDEO_TRACK)
580     void captionPreferencesChanged();
581 #endif
582
583     void forbidPrompts();
584     void allowPrompts();
585     bool arePromptsAllowed();
586
587     void mainFrameLoadStarted(const URL&, FrameLoadType);
588
589     void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
590     unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
591
592     ApplicationCacheStorage& applicationCacheStorage() { return m_applicationCacheStorage; }
593     DatabaseProvider& databaseProvider() { return m_databaseProvider; }
594     CacheStorageProvider& cacheStorageProvider() { return m_cacheStorageProvider; }
595     SocketProvider& socketProvider() { return m_socketProvider; }
596     CookieJar& cookieJar() { return m_cookieJar.get(); }
597
598     StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
599
600     PluginInfoProvider& pluginInfoProvider();
601
602     WEBCORE_EXPORT UserContentProvider& userContentProvider();
603     WEBCORE_EXPORT void setUserContentProvider(Ref<UserContentProvider>&&);
604
605     VisitedLinkStore& visitedLinkStore();
606     WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
607
608     WEBCORE_EXPORT PAL::SessionID sessionID() const;
609     WEBCORE_EXPORT void setSessionID(PAL::SessionID);
610     bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
611
612     MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
613     void updateIsPlayingMedia(uint64_t);
614     MediaProducer::MutedStateFlags mutedState() const { return m_mutedState; }
615     bool isAudioMuted() const { return m_mutedState & MediaProducer::AudioIsMuted; }
616     bool isMediaCaptureMuted() const { return m_mutedState & MediaProducer::MediaStreamCaptureIsMuted; };
617     void schedulePlaybackControlsManagerUpdate();
618     WEBCORE_EXPORT void setMuted(MediaProducer::MutedStateFlags);
619     WEBCORE_EXPORT void stopMediaCapture();
620
621     WEBCORE_EXPORT void stopAllMediaPlayback();
622     WEBCORE_EXPORT void suspendAllMediaPlayback();
623     WEBCORE_EXPORT void resumeAllMediaPlayback();
624     bool mediaPlaybackIsSuspended() const { return m_mediaPlaybackIsSuspended; }
625     WEBCORE_EXPORT void suspendAllMediaBuffering();
626     WEBCORE_EXPORT void resumeAllMediaBuffering();
627     bool mediaBufferingIsSuspended() const { return m_mediaBufferingIsSuspended; }
628
629 #if ENABLE(MEDIA_SESSION)
630     WEBCORE_EXPORT void handleMediaEvent(MediaEventType);
631     WEBCORE_EXPORT void setVolumeOfMediaElement(double, uint64_t);
632 #endif
633
634 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
635     void addPlaybackTargetPickerClient(uint64_t);
636     void removePlaybackTargetPickerClient(uint64_t);
637     void showPlaybackTargetPicker(uint64_t, const IntPoint&, bool, RouteSharingPolicy, const String&);
638     void playbackTargetPickerClientStateDidChange(uint64_t, MediaProducer::MediaStateFlags);
639     WEBCORE_EXPORT void setMockMediaPlaybackTargetPickerEnabled(bool);
640     WEBCORE_EXPORT void setMockMediaPlaybackTargetPickerState(const String&, MediaPlaybackTargetContext::State);
641     WEBCORE_EXPORT void mockMediaPlaybackTargetPickerDismissPopup();
642
643     WEBCORE_EXPORT void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
644     WEBCORE_EXPORT void playbackTargetAvailabilityDidChange(uint64_t, bool);
645     WEBCORE_EXPORT void setShouldPlayToPlaybackTarget(uint64_t, bool);
646     WEBCORE_EXPORT void playbackTargetPickerWasDismissed(uint64_t);
647 #endif
648
649     RefPtr<WheelEventTestMonitor> wheelEventTestMonitor() const { return m_wheelEventTestMonitor; }
650     WEBCORE_EXPORT WheelEventTestMonitor& ensureWheelEventTestMonitor();
651     void clearWheelEventTestMonitor() { m_wheelEventTestMonitor = nullptr; }
652     bool isMonitoringWheelEvents() const { return !!m_wheelEventTestMonitor; }
653
654     void setIsForSanitizingWebContent() { m_isForSanitizingWebContent = true; }
655     bool isForSanitizingWebContent() const { return m_isForSanitizingWebContent; }
656
657 #if ENABLE(VIDEO)
658     bool allowsMediaDocumentInlinePlayback() const { return m_allowsMediaDocumentInlinePlayback; }
659     WEBCORE_EXPORT void setAllowsMediaDocumentInlinePlayback(bool);
660 #endif
661
662     bool allowsPlaybackControlsForAutoplayingAudio() const { return m_allowsPlaybackControlsForAutoplayingAudio; }
663     void setAllowsPlaybackControlsForAutoplayingAudio(bool allowsPlaybackControlsForAutoplayingAudio) { m_allowsPlaybackControlsForAutoplayingAudio = allowsPlaybackControlsForAutoplayingAudio; }
664
665 #if ENABLE(INDEXED_DATABASE)
666     IDBClient::IDBConnectionToServer& idbConnection();
667     WEBCORE_EXPORT IDBClient::IDBConnectionToServer* optionalIDBConnection();
668     WEBCORE_EXPORT void clearIDBConnection();
669 #endif
670
671     void setShowAllPlugins(bool showAll) { m_showAllPlugins = showAll; }
672     bool showAllPlugins() const;
673
674     WEBCORE_EXPORT void setDOMTimerAlignmentIntervalIncreaseLimit(Seconds);
675
676     bool isControlledByAutomation() const { return m_controlledByAutomation; }
677     void setControlledByAutomation(bool controlled) { m_controlledByAutomation = controlled; }
678
679     WEBCORE_EXPORT bool isAlwaysOnLoggingAllowed() const;
680
681     String captionUserPreferencesStyleSheet();
682     void setCaptionUserPreferencesStyleSheet(const String&);
683
684     bool isResourceCachingDisabledByWebInspector() const { return m_resourceCachingDisabledByWebInspector; }
685     void setResourceCachingDisabledByWebInspector(bool disabled) { m_resourceCachingDisabledByWebInspector = disabled; }
686
687     Optional<EventThrottlingBehavior> eventThrottlingBehaviorOverride() const { return m_eventThrottlingBehaviorOverride; }
688     void setEventThrottlingBehaviorOverride(Optional<EventThrottlingBehavior> throttling) { m_eventThrottlingBehaviorOverride = throttling; }
689
690     Optional<CompositingPolicy> compositingPolicyOverride() const { return m_compositingPolicyOverride; }
691     void setCompositingPolicyOverride(Optional<CompositingPolicy> policy) { m_compositingPolicyOverride = policy; }
692
693 #if ENABLE(WEBGL)
694     WebGLStateTracker* webGLStateTracker() const { return m_webGLStateTracker.get(); }
695 #endif
696
697 #if ENABLE(SPEECH_SYNTHESIS)
698     SpeechSynthesisClient* speechSynthesisClient() const { return m_speechSynthesisClient.get(); }
699 #endif
700
701     bool isOnlyNonUtilityPage() const;
702     bool isUtilityPage() const { return m_isUtilityPage; }
703
704 #if ENABLE(DATA_INTERACTION)
705     WEBCORE_EXPORT bool hasSelectionAtPosition(const FloatPoint&) const;
706 #endif
707
708     bool isLowPowerModeEnabled() const;
709     WEBCORE_EXPORT void setLowPowerModeEnabledOverrideForTesting(Optional<bool>);
710
711     WEBCORE_EXPORT void applicationWillResignActive();
712     WEBCORE_EXPORT void applicationDidEnterBackground();
713     WEBCORE_EXPORT void applicationWillEnterForeground();
714     WEBCORE_EXPORT void applicationDidBecomeActive();
715
716     PerformanceLogging& performanceLogging() const { return *m_performanceLogging; }
717
718     void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel);
719
720 private:
721     struct Navigation {
722         RegistrableDomain domain;
723         FrameLoadType type;
724     };
725     void logNavigation(const Navigation&);
726
727     WEBCORE_EXPORT void initGroup();
728
729     void setIsInWindowInternal(bool);
730     void setIsVisibleInternal(bool);
731     void setIsVisuallyIdleInternal(bool);
732
733 #if ASSERT_DISABLED
734     void checkSubframeCountConsistency() const { }
735 #else
736     void checkSubframeCountConsistency() const;
737 #endif
738
739     enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
740     enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
741
742     unsigned findMatchesForText(const String&, FindOptions, unsigned maxMatchCount, ShouldHighlightMatches, ShouldMarkMatches);
743
744     Optional<std::pair<MediaCanStartListener&, Document&>> takeAnyMediaCanStartListener();
745
746 #if ENABLE(VIDEO)
747     void playbackControlsManagerUpdateTimerFired();
748 #endif
749
750     Vector<Ref<PluginViewBase>> pluginViews();
751
752     void handleLowModePowerChange(bool);
753
754     void forEachDocument(const WTF::Function<void(Document&)>&);
755     Vector<Ref<Document>> collectDocuments();
756
757     enum class TimerThrottlingState { Disabled, Enabled, EnabledIncreasing };
758     void hiddenPageDOMTimerThrottlingStateChanged();
759     void setTimerThrottlingState(TimerThrottlingState);
760     void updateTimerThrottlingState();
761     void updateDOMTimerAlignmentInterval();
762     void domTimerAlignmentIntervalIncreaseTimerFired();
763
764     const std::unique_ptr<Chrome> m_chrome;
765     const std::unique_ptr<DragCaretController> m_dragCaretController;
766
767 #if ENABLE(DRAG_SUPPORT)
768     const std::unique_ptr<DragController> m_dragController;
769 #endif
770     const std::unique_ptr<FocusController> m_focusController;
771 #if ENABLE(CONTEXT_MENUS)
772     const std::unique_ptr<ContextMenuController> m_contextMenuController;
773 #endif
774     const std::unique_ptr<UserInputBridge> m_userInputBridge;
775     const std::unique_ptr<InspectorController> m_inspectorController;
776 #if ENABLE(POINTER_EVENTS)
777     const std::unique_ptr<PointerCaptureController> m_pointerCaptureController;
778 #endif
779 #if ENABLE(POINTER_LOCK)
780     const std::unique_ptr<PointerLockController> m_pointerLockController;
781 #endif
782     RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
783
784     const RefPtr<Settings> m_settings;
785     const std::unique_ptr<ProgressTracker> m_progress;
786
787     const std::unique_ptr<BackForwardController> m_backForwardController;
788     Ref<Frame> m_mainFrame;
789
790     RefPtr<PluginData> m_pluginData;
791
792     UniqueRef<EditorClient> m_editorClient;
793     PlugInClient* m_plugInClient;
794     std::unique_ptr<ValidationMessageClient> m_validationMessageClient;
795     std::unique_ptr<DiagnosticLoggingClient> m_diagnosticLoggingClient;
796     std::unique_ptr<PerformanceLoggingClient> m_performanceLoggingClient;
797
798 #if ENABLE(WEBGL)
799     std::unique_ptr<WebGLStateTracker> m_webGLStateTracker;
800 #endif
801
802 #if ENABLE(SPEECH_SYNTHESIS)
803     std::unique_ptr<SpeechSynthesisClient> m_speechSynthesisClient;
804 #endif
805
806     UniqueRef<LibWebRTCProvider> m_libWebRTCProvider;
807     RTCController m_rtcController;
808
809     int m_nestedRunLoopCount { 0 };
810     WTF::Function<void()> m_unnestCallback;
811
812     int m_subframeCount { 0 };
813     String m_groupName;
814     bool m_openedByDOM { false };
815     bool m_openedByDOMWithOpener { false };
816
817     bool m_tabKeyCyclesThroughElements { true };
818     bool m_defersLoading { false };
819     unsigned m_defersLoadingCallCount { 0 };
820
821     bool m_inLowQualityInterpolationMode { false };
822     bool m_areMemoryCacheClientCallsEnabled { true };
823     float m_mediaVolume { 1 };
824     MediaProducer::MutedStateFlags m_mutedState { MediaProducer::NoneMuted };
825
826     float m_pageScaleFactor { 1 };
827     float m_zoomedOutPageScaleFactor { 0 };
828     float m_deviceScaleFactor { 1 };
829     float m_viewScaleFactor { 1 };
830
831     float m_topContentInset { 0 };
832     FloatBoxExtent m_obscuredInsets;
833     FloatBoxExtent m_contentInsets;
834     FloatBoxExtent m_unobscuredSafeAreaInsets;
835     FloatBoxExtent m_fullscreenInsets;
836     Seconds m_fullscreenAutoHideDuration { 0_s };
837
838 #if PLATFORM(IOS_FAMILY)
839     bool m_enclosedInScrollableAncestorView { false };
840 #endif
841     
842     bool m_useSystemAppearance { false };
843     bool m_useElevatedUserInterfaceLevel { false };
844     bool m_useDarkAppearance { false };
845     Optional<bool> m_useDarkAppearanceOverride;
846
847 #if ENABLE(TEXT_AUTOSIZING)
848     float m_textAutosizingWidth { 0 };
849 #endif
850     float m_initialScale { 1.0f };
851     
852     bool m_suppressScrollbarAnimations { false };
853     
854     unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
855     unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity    
856
857     Pagination m_pagination;
858     bool m_paginationLineGridEnabled { false };
859
860     String m_userStyleSheetPath;
861     mutable String m_userStyleSheet;
862     mutable bool m_didLoadUserStyleSheet { false };
863     mutable Optional<WallTime> m_userStyleSheetModificationTime;
864
865     String m_captionUserPreferencesStyleSheet;
866
867     std::unique_ptr<PageGroup> m_singlePageGroup;
868     PageGroup* m_group { nullptr };
869
870     JSC::Debugger* m_debugger { nullptr };
871
872     bool m_canStartMedia { true };
873
874     RefPtr<StorageNamespace> m_sessionStorage;
875
876     TimerThrottlingState m_timerThrottlingState { TimerThrottlingState::Disabled };
877     MonotonicTime m_timerThrottlingStateLastChangedTime;
878     Seconds m_domTimerAlignmentInterval;
879     Timer m_domTimerAlignmentIntervalIncreaseTimer;
880     Seconds m_domTimerAlignmentIntervalIncreaseLimit;
881
882     bool m_isEditable { false };
883     bool m_isPrerender { false };
884     OptionSet<ActivityState::Flag> m_activityState;
885
886     OptionSet<LayoutMilestone> m_requestedLayoutMilestones;
887
888     int m_headerHeight { 0 };
889     int m_footerHeight { 0 };
890
891     std::unique_ptr<RenderingUpdateScheduler> m_renderingUpdateScheduler;
892
893     HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
894     Region m_topRelevantPaintedRegion;
895     Region m_bottomRelevantPaintedRegion;
896     Region m_relevantUnpaintedRegion;
897     bool m_isCountingRelevantRepaintedObjects { false };
898 #ifndef NDEBUG
899     bool m_isPainting { false };
900 #endif
901     AlternativeTextClient* m_alternativeTextClient;
902
903     bool m_scriptedAnimationsSuspended { false };
904     const std::unique_ptr<PageConsoleClient> m_consoleClient;
905
906 #if ENABLE(REMOTE_INSPECTOR)
907     const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
908 #endif
909
910 #if ENABLE(INDEXED_DATABASE)
911     RefPtr<IDBClient::IDBConnectionToServer> m_idbConnectionToServer;
912 #endif
913
914     HashSet<String> m_seenPlugins;
915     HashSet<String> m_seenMediaEngines;
916
917     unsigned m_lastSpatialNavigationCandidatesCount { 0 };
918     unsigned m_forbidPromptsDepth { 0 };
919
920     Ref<SocketProvider> m_socketProvider;
921     Ref<CookieJar> m_cookieJar;
922     Ref<ApplicationCacheStorage> m_applicationCacheStorage;
923     Ref<CacheStorageProvider> m_cacheStorageProvider;
924     Ref<DatabaseProvider> m_databaseProvider;
925     Ref<PluginInfoProvider> m_pluginInfoProvider;
926     Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
927     Ref<UserContentProvider> m_userContentProvider;
928     Ref<VisitedLinkStore> m_visitedLinkStore;
929     RefPtr<WheelEventTestMonitor> m_wheelEventTestMonitor;
930
931     HashSet<ActivityStateChangeObserver*> m_activityStateChangeObservers;
932
933 #if ENABLE(RESOURCE_USAGE)
934     std::unique_ptr<ResourceUsageOverlay> m_resourceUsageOverlay;
935 #endif
936
937     PAL::SessionID m_sessionID;
938
939     bool m_isClosing { false };
940     bool m_isRestoringCachedPage { false };
941
942     MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
943
944 #if ENABLE(VIDEO)
945     Timer m_playbackControlsManagerUpdateTimer;
946 #endif
947
948     bool m_allowsMediaDocumentInlinePlayback { false };
949     bool m_allowsPlaybackControlsForAutoplayingAudio { false };
950     bool m_showAllPlugins { false };
951     bool m_controlledByAutomation { false };
952     bool m_resourceCachingDisabledByWebInspector { false };
953     bool m_isUtilityPage;
954     UserInterfaceLayoutDirection m_userInterfaceLayoutDirection { UserInterfaceLayoutDirection::LTR };
955     
956     // For testing.
957     Optional<EventThrottlingBehavior> m_eventThrottlingBehaviorOverride;
958     Optional<CompositingPolicy> m_compositingPolicyOverride;
959
960     std::unique_ptr<PerformanceMonitor> m_performanceMonitor;
961     std::unique_ptr<LowPowerModeNotifier> m_lowPowerModeNotifier;
962     Optional<bool> m_lowPowerModeEnabledOverrideForTesting;
963
964     Optional<Navigation> m_navigationToLogWhenVisible;
965
966     std::unique_ptr<PerformanceLogging> m_performanceLogging;
967 #if PLATFORM(MAC)
968     Vector<ScrollLatchingState> m_latchingState;
969 #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
970     std::unique_ptr<ServicesOverlayController> m_servicesOverlayController;
971 #endif
972 #endif
973
974     std::unique_ptr<WheelEventDeltaFilter> m_recentWheelEventDeltaFilter;
975     std::unique_ptr<PageOverlayController> m_pageOverlayController;
976
977 #if ENABLE(APPLE_PAY)
978     std::unique_ptr<PaymentCoordinator> m_paymentCoordinator;
979 #endif
980
981 #if ENABLE(WEB_AUTHN)
982     UniqueRef<AuthenticatorCoordinator> m_authenticatorCoordinator;
983 #endif
984
985 #if ENABLE(APPLICATION_MANIFEST)
986     Optional<ApplicationManifest> m_applicationManifest;
987 #endif
988
989     Optional<ViewportArguments> m_overrideViewportArguments;
990
991     bool m_shouldEnableICECandidateFilteringByDefault { true };
992     bool m_mediaPlaybackIsSuspended { false };
993     bool m_mediaBufferingIsSuspended { false };
994     bool m_inUpdateRendering { false };
995
996     bool m_isForSanitizingWebContent { false };
997 };
998
999 inline PageGroup& Page::group()
1000 {
1001     if (!m_group)
1002         initGroup();
1003     return *m_group;
1004 }
1005
1006 } // namespace WebCore