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 "WheelEventTestTrigger.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
72namespace JSC {
73class Debugger;
74}
75
76namespace WebCore {
77
78namespace IDBClient {
79class IDBConnectionToServer;
80}
81
82class AlternativeTextClient;
83class ApplicationCacheStorage;
84class AuthenticatorCoordinator;
85class BackForwardController;
86class BackForwardClient;
87class CacheStorageProvider;
88class Chrome;
89class ChromeClient;
90class Color;
91class ContextMenuClient;
92class ContextMenuController;
93class CookieJar;
94class DOMRect;
95class DOMRectList;
96class DatabaseProvider;
97class DiagnosticLoggingClient;
98class DragCaretController;
99class DragClient;
100class DragController;
101class EditorClient;
102class Element;
103class FocusController;
104class Frame;
105class FrameLoaderClient;
106class HistoryItem;
107class HTMLMediaElement;
108class UserInputBridge;
109class InspectorClient;
110class InspectorController;
111class LibWebRTCProvider;
112class LowPowerModeNotifier;
113class MediaCanStartListener;
114class MediaPlaybackTarget;
115class PageConfiguration;
116class PageConsoleClient;
117class PageDebuggable;
118class PageGroup;
119class PageOverlayController;
120class PaymentCoordinator;
121class PerformanceLogging;
122class PerformanceLoggingClient;
123class PerformanceMonitor;
124class PlugInClient;
125class PluginData;
126class PluginInfoProvider;
127class PluginViewBase;
128class PointerCaptureController;
129class PointerLockController;
130class ProgressTracker;
131class ProgressTrackerClient;
132class Range;
133class RenderObject;
134class RenderTheme;
135class ResourceUsageOverlay;
136class VisibleSelection;
137class ScrollLatchingState;
138class ScrollableArea;
139class ScrollingCoordinator;
140class ServicesOverlayController;
141class Settings;
142class SocketProvider;
143class StorageNamespace;
144class StorageNamespaceProvider;
145class UserContentProvider;
146class ValidationMessageClient;
147class ActivityStateChangeObserver;
148class VisitedLinkStore;
149class WebGLStateTracker;
150class SpeechSynthesisClient;
151class WheelEventDeltaFilter;
152
153typedef uint64_t SharedStringHash;
154
155enum FindDirection {
156 FindDirectionForward,
157 FindDirectionBackward
158};
159
160enum class EventThrottlingBehavior {
161 Responsive,
162 Unresponsive
163};
164
165enum class CompositingPolicy : uint8_t {
166 Normal,
167 Conservative, // Used in low memory situations.
168};
169
170enum class CanWrap : bool;
171enum class DidWrap : bool;
172enum class RouteSharingPolicy : uint8_t;
173enum class ShouldTreatAsContinuingLoad : bool;
174
175class Page : public Supplementable<Page>, public CanMakeWeakPtr<Page> {
176 WTF_MAKE_NONCOPYABLE(Page);
177 WTF_MAKE_FAST_ALLOCATED;
178 friend class SettingsBase;
179
180public:
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 useInactiveAppearance() const { return m_useInactiveAppearance; }
384 WEBCORE_EXPORT void effectiveAppearanceDidChange(bool useDarkAppearance, bool useInactiveAppearance);
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#endif
392
393 const FloatBoxExtent& fullscreenInsets() const { return m_fullscreenInsets; }
394 WEBCORE_EXPORT void setFullscreenInsets(const FloatBoxExtent&);
395
396 const Seconds fullscreenAutoHideDuration() const { return m_fullscreenAutoHideDuration; }
397 WEBCORE_EXPORT void setFullscreenAutoHideDuration(Seconds);
398 WEBCORE_EXPORT void setFullscreenControlsHidden(bool);
399
400 bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
401 WEBCORE_EXPORT void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
402 void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
403
404 WEBCORE_EXPORT void setVerticalScrollElasticity(ScrollElasticity);
405 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
406
407 WEBCORE_EXPORT void setHorizontalScrollElasticity(ScrollElasticity);
408 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
409
410 WEBCORE_EXPORT void accessibilitySettingsDidChange();
411 WEBCORE_EXPORT void appearanceDidChange();
412
413 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
414 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
415 // FrameViews in the page cache, but FrameView::pagination() only affects the current
416 // FrameView.
417 const Pagination& pagination() const { return m_pagination; }
418 WEBCORE_EXPORT void setPagination(const Pagination&);
419 bool paginationLineGridEnabled() const { return m_paginationLineGridEnabled; }
420 WEBCORE_EXPORT void setPaginationLineGridEnabled(bool flag);
421
422 WEBCORE_EXPORT unsigned pageCount() const;
423
424 WEBCORE_EXPORT DiagnosticLoggingClient& diagnosticLoggingClient() const;
425
426 PerformanceLoggingClient* performanceLoggingClient() const { return m_performanceLoggingClient.get(); }
427
428 WheelEventDeltaFilter* wheelEventDeltaFilter() { return m_recentWheelEventDeltaFilter.get(); }
429 PageOverlayController& pageOverlayController() { return *m_pageOverlayController; }
430
431#if PLATFORM(MAC)
432#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
433 ServicesOverlayController& servicesOverlayController() { return *m_servicesOverlayController; }
434#endif // ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
435
436 ScrollLatchingState* latchingState();
437 void pushNewLatchingState();
438 void popLatchingState();
439 void resetLatchingState();
440 void removeLatchingStateForTarget(Element&);
441#endif // PLATFORM(MAC)
442
443#if ENABLE(APPLE_PAY)
444 PaymentCoordinator& paymentCoordinator() const { return *m_paymentCoordinator; }
445 WEBCORE_EXPORT void setPaymentCoordinator(std::unique_ptr<PaymentCoordinator>&&);
446#endif
447
448#if ENABLE(WEB_AUTHN)
449 AuthenticatorCoordinator& authenticatorCoordinator() { return m_authenticatorCoordinator.get(); }
450#endif
451
452#if ENABLE(APPLICATION_MANIFEST)
453 const Optional<ApplicationManifest>& applicationManifest() const { return m_applicationManifest; }
454#endif
455
456 // Notifications when the Page starts and stops being presented via a native window.
457 WEBCORE_EXPORT void setActivityState(OptionSet<ActivityState::Flag>);
458 OptionSet<ActivityState::Flag> activityState() const { return m_activityState; }
459
460 bool isWindowActive() const;
461 bool isVisibleAndActive() const;
462 WEBCORE_EXPORT void setIsVisible(bool);
463 WEBCORE_EXPORT void setIsPrerender();
464 bool isVisible() const { return m_activityState.contains(ActivityState::IsVisible); }
465
466 // Notification that this Page was moved into or out of a native window.
467 WEBCORE_EXPORT void setIsInWindow(bool);
468 bool isInWindow() const { return m_activityState.contains(ActivityState::IsInWindow); }
469
470 void setIsClosing() { m_isClosing = true; }
471 bool isClosing() const { return m_isClosing; }
472
473 void setIsRestoringCachedPage(bool value) { m_isRestoringCachedPage = value; }
474 bool isRestoringCachedPage() const { return m_isRestoringCachedPage; }
475
476 WEBCORE_EXPORT void addActivityStateChangeObserver(ActivityStateChangeObserver&);
477 WEBCORE_EXPORT void removeActivityStateChangeObserver(ActivityStateChangeObserver&);
478
479 WEBCORE_EXPORT void layoutIfNeeded();
480 WEBCORE_EXPORT void updateRendering();
481
482 WEBCORE_EXPORT void suspendScriptedAnimations();
483 WEBCORE_EXPORT void resumeScriptedAnimations();
484 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
485
486 void userStyleSheetLocationChanged();
487 const String& userStyleSheet() const;
488
489 WEBCORE_EXPORT void userAgentChanged();
490
491 void dnsPrefetchingStateChanged();
492 void storageBlockingStateChanged();
493
494#if ENABLE(RESOURCE_USAGE)
495 void setResourceUsageOverlayVisible(bool);
496#endif
497
498 void setDebugger(JSC::Debugger*);
499 JSC::Debugger* debugger() const { return m_debugger; }
500
501 WEBCORE_EXPORT void invalidateStylesForAllLinks();
502 WEBCORE_EXPORT void invalidateStylesForLink(SharedStringHash);
503
504 void invalidateInjectedStyleSheetCacheInAllFrames();
505
506 StorageNamespace* sessionStorage(bool optionalCreate = true);
507 void setSessionStorage(RefPtr<StorageNamespace>&&);
508
509 StorageNamespace* ephemeralLocalStorage(bool optionalCreate = true);
510 void setEphemeralLocalStorage(RefPtr<StorageNamespace>&&);
511
512 bool hasCustomHTMLTokenizerTimeDelay() const;
513 double customHTMLTokenizerTimeDelay() const;
514
515 WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool);
516 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
517
518 // Don't allow more than a certain number of frames in a page.
519 // This seems like a reasonable upper bound, and otherwise mutually
520 // recursive frameset pages can quickly bring the program to its knees
521 // with exponential growth in the number of frames.
522 static const int maxNumberOfFrames = 1000;
523
524 void setEditable(bool isEditable) { m_isEditable = isEditable; }
525 bool isEditable() { return m_isEditable; }
526
527 WEBCORE_EXPORT VisibilityState visibilityState() const;
528 WEBCORE_EXPORT void resumeAnimatingImages();
529
530 void didFinishLoadingImageForElement(HTMLImageElement&);
531
532 WEBCORE_EXPORT void addLayoutMilestones(OptionSet<LayoutMilestone>);
533 WEBCORE_EXPORT void removeLayoutMilestones(OptionSet<LayoutMilestone>);
534 OptionSet<LayoutMilestone> requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
535
536 WEBCORE_EXPORT void setHeaderHeight(int);
537 WEBCORE_EXPORT void setFooterHeight(int);
538
539 int headerHeight() const { return m_headerHeight; }
540 int footerHeight() const { return m_footerHeight; }
541
542 WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
543
544 bool isCountingRelevantRepaintedObjects() const;
545 void setIsCountingRelevantRepaintedObjects(bool isCounting) { m_isCountingRelevantRepaintedObjects = isCounting; }
546 void startCountingRelevantRepaintedObjects();
547 void resetRelevantPaintedObjectCounter();
548 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
549 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
550
551 WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
552 WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
553 void suspendDeviceMotionAndOrientationUpdates();
554 void resumeDeviceMotionAndOrientationUpdates();
555
556#ifndef NDEBUG
557 void setIsPainting(bool painting) { m_isPainting = painting; }
558 bool isPainting() const { return m_isPainting; }
559#endif
560
561 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
562
563 bool hasSeenPlugin(const String& serviceType) const;
564 WEBCORE_EXPORT bool hasSeenAnyPlugin() const;
565 void sawPlugin(const String& serviceType);
566 void resetSeenPlugins();
567
568 bool hasSeenMediaEngine(const String& engineName) const;
569 bool hasSeenAnyMediaEngine() const;
570 void sawMediaEngine(const String& engineName);
571 void resetSeenMediaEngines();
572
573 PageConsoleClient& console() { return *m_consoleClient; }
574
575#if ENABLE(REMOTE_INSPECTOR)
576 PageDebuggable& inspectorDebuggable() const { return *m_inspectorDebuggable.get(); }
577#endif
578
579 void hiddenPageCSSAnimationSuspensionStateChanged();
580
581#if ENABLE(VIDEO_TRACK)
582 void captionPreferencesChanged();
583#endif
584
585 void forbidPrompts();
586 void allowPrompts();
587 bool arePromptsAllowed();
588
589 void mainFrameLoadStarted(const URL&, FrameLoadType);
590
591 void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
592 unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
593
594 ApplicationCacheStorage& applicationCacheStorage() { return m_applicationCacheStorage; }
595 DatabaseProvider& databaseProvider() { return m_databaseProvider; }
596 CacheStorageProvider& cacheStorageProvider() { return m_cacheStorageProvider; }
597 SocketProvider& socketProvider() { return m_socketProvider; }
598 CookieJar& cookieJar() { return m_cookieJar.get(); }
599
600 StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
601 void setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&&);
602
603 PluginInfoProvider& pluginInfoProvider();
604
605 WEBCORE_EXPORT UserContentProvider& userContentProvider();
606 WEBCORE_EXPORT void setUserContentProvider(Ref<UserContentProvider>&&);
607
608 VisitedLinkStore& visitedLinkStore();
609 WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
610
611 WEBCORE_EXPORT PAL::SessionID sessionID() const;
612 WEBCORE_EXPORT void setSessionID(PAL::SessionID);
613 WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
614 bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
615
616 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
617 void updateIsPlayingMedia(uint64_t);
618 MediaProducer::MutedStateFlags mutedState() const { return m_mutedState; }
619 bool isAudioMuted() const { return m_mutedState & MediaProducer::AudioIsMuted; }
620 bool isMediaCaptureMuted() const { return m_mutedState & MediaProducer::MediaStreamCaptureIsMuted; };
621 void schedulePlaybackControlsManagerUpdate();
622 WEBCORE_EXPORT void setMuted(MediaProducer::MutedStateFlags);
623 WEBCORE_EXPORT void stopMediaCapture();
624
625 WEBCORE_EXPORT void stopAllMediaPlayback();
626 WEBCORE_EXPORT void suspendAllMediaPlayback();
627 WEBCORE_EXPORT void resumeAllMediaPlayback();
628 bool mediaPlaybackIsSuspended() const { return m_mediaPlaybackIsSuspended; }
629 WEBCORE_EXPORT void suspendAllMediaBuffering();
630 WEBCORE_EXPORT void resumeAllMediaBuffering();
631 bool mediaBufferingIsSuspended() const { return m_mediaBufferingIsSuspended; }
632
633#if ENABLE(MEDIA_SESSION)
634 WEBCORE_EXPORT void handleMediaEvent(MediaEventType);
635 WEBCORE_EXPORT void setVolumeOfMediaElement(double, uint64_t);
636#endif
637
638#if ENABLE(WIRELESS_PLAYBACK_TARGET)
639 void addPlaybackTargetPickerClient(uint64_t);
640 void removePlaybackTargetPickerClient(uint64_t);
641 void showPlaybackTargetPicker(uint64_t, const IntPoint&, bool, RouteSharingPolicy, const String&);
642 void playbackTargetPickerClientStateDidChange(uint64_t, MediaProducer::MediaStateFlags);
643 WEBCORE_EXPORT void setMockMediaPlaybackTargetPickerEnabled(bool);
644 WEBCORE_EXPORT void setMockMediaPlaybackTargetPickerState(const String&, MediaPlaybackTargetContext::State);
645
646 WEBCORE_EXPORT void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
647 WEBCORE_EXPORT void playbackTargetAvailabilityDidChange(uint64_t, bool);
648 WEBCORE_EXPORT void setShouldPlayToPlaybackTarget(uint64_t, bool);
649#endif
650
651 RefPtr<WheelEventTestTrigger> testTrigger() const { return m_testTrigger; }
652 WEBCORE_EXPORT WheelEventTestTrigger& ensureTestTrigger();
653 void clearTrigger() { m_testTrigger = nullptr; }
654 bool expectsWheelEventTriggers() const { return !!m_testTrigger; }
655
656#if ENABLE(VIDEO)
657 bool allowsMediaDocumentInlinePlayback() const { return m_allowsMediaDocumentInlinePlayback; }
658 WEBCORE_EXPORT void setAllowsMediaDocumentInlinePlayback(bool);
659#endif
660
661 bool allowsPlaybackControlsForAutoplayingAudio() const { return m_allowsPlaybackControlsForAutoplayingAudio; }
662 void setAllowsPlaybackControlsForAutoplayingAudio(bool allowsPlaybackControlsForAutoplayingAudio) { m_allowsPlaybackControlsForAutoplayingAudio = allowsPlaybackControlsForAutoplayingAudio; }
663
664#if ENABLE(INDEXED_DATABASE)
665 IDBClient::IDBConnectionToServer& idbConnection();
666 WEBCORE_EXPORT IDBClient::IDBConnectionToServer* optionalIDBConnection();
667 WEBCORE_EXPORT void clearIDBConnection();
668#endif
669
670 void setShowAllPlugins(bool showAll) { m_showAllPlugins = showAll; }
671 bool showAllPlugins() const;
672
673 WEBCORE_EXPORT void setDOMTimerAlignmentIntervalIncreaseLimit(Seconds);
674
675 bool isControlledByAutomation() const { return m_controlledByAutomation; }
676 void setControlledByAutomation(bool controlled) { m_controlledByAutomation = controlled; }
677
678 WEBCORE_EXPORT bool isAlwaysOnLoggingAllowed() const;
679
680 String captionUserPreferencesStyleSheet();
681 void setCaptionUserPreferencesStyleSheet(const String&);
682
683 bool isResourceCachingDisabled() const { return m_resourceCachingDisabled || m_resourceCachingDisabledOverride; }
684 void setResourceCachingDisabled(bool disabled) { m_resourceCachingDisabled = disabled; }
685
686 // Web Inspector can override whatever value is set via WebKit SPI, but only while it is open.
687 void setResourceCachingDisabledOverride(bool disabled) { m_resourceCachingDisabledOverride = disabled; }
688
689 Optional<EventThrottlingBehavior> eventThrottlingBehaviorOverride() const { return m_eventThrottlingBehaviorOverride; }
690 void setEventThrottlingBehaviorOverride(Optional<EventThrottlingBehavior> throttling) { m_eventThrottlingBehaviorOverride = throttling; }
691
692 Optional<CompositingPolicy> compositingPolicyOverride() const { return m_compositingPolicyOverride; }
693 void setCompositingPolicyOverride(Optional<CompositingPolicy> policy) { m_compositingPolicyOverride = policy; }
694
695 WebGLStateTracker* webGLStateTracker() const { return m_webGLStateTracker.get(); }
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
720private:
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
756 enum class TimerThrottlingState { Disabled, Enabled, EnabledIncreasing };
757 void hiddenPageDOMTimerThrottlingStateChanged();
758 void setTimerThrottlingState(TimerThrottlingState);
759 void updateTimerThrottlingState();
760 void updateDOMTimerAlignmentInterval();
761 void domTimerAlignmentIntervalIncreaseTimerFired();
762
763 const std::unique_ptr<Chrome> m_chrome;
764 const std::unique_ptr<DragCaretController> m_dragCaretController;
765
766#if ENABLE(DRAG_SUPPORT)
767 const std::unique_ptr<DragController> m_dragController;
768#endif
769 const std::unique_ptr<FocusController> m_focusController;
770#if ENABLE(CONTEXT_MENUS)
771 const std::unique_ptr<ContextMenuController> m_contextMenuController;
772#endif
773 const std::unique_ptr<UserInputBridge> m_userInputBridge;
774 const std::unique_ptr<InspectorController> m_inspectorController;
775#if ENABLE(POINTER_EVENTS)
776 const std::unique_ptr<PointerCaptureController> m_pointerCaptureController;
777#endif
778#if ENABLE(POINTER_LOCK)
779 const std::unique_ptr<PointerLockController> m_pointerLockController;
780#endif
781 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
782
783 const RefPtr<Settings> m_settings;
784 const std::unique_ptr<ProgressTracker> m_progress;
785
786 const std::unique_ptr<BackForwardController> m_backForwardController;
787 Ref<Frame> m_mainFrame;
788
789 RefPtr<PluginData> m_pluginData;
790
791 UniqueRef<EditorClient> m_editorClient;
792 PlugInClient* m_plugInClient;
793 std::unique_ptr<ValidationMessageClient> m_validationMessageClient;
794 std::unique_ptr<DiagnosticLoggingClient> m_diagnosticLoggingClient;
795 std::unique_ptr<PerformanceLoggingClient> m_performanceLoggingClient;
796
797 std::unique_ptr<WebGLStateTracker> m_webGLStateTracker;
798
799#if ENABLE(SPEECH_SYNTHESIS)
800 std::unique_ptr<SpeechSynthesisClient> m_speechSynthesisClient;
801#endif
802
803 UniqueRef<LibWebRTCProvider> m_libWebRTCProvider;
804 RTCController m_rtcController;
805
806 int m_nestedRunLoopCount { 0 };
807 WTF::Function<void()> m_unnestCallback;
808
809 int m_subframeCount { 0 };
810 String m_groupName;
811 bool m_openedByDOM { false };
812 bool m_openedByDOMWithOpener { false };
813
814 bool m_tabKeyCyclesThroughElements { true };
815 bool m_defersLoading { false };
816 unsigned m_defersLoadingCallCount { 0 };
817
818 bool m_inLowQualityInterpolationMode { false };
819 bool m_areMemoryCacheClientCallsEnabled { true };
820 float m_mediaVolume { 1 };
821 MediaProducer::MutedStateFlags m_mutedState { MediaProducer::NoneMuted };
822
823 float m_pageScaleFactor { 1 };
824 float m_zoomedOutPageScaleFactor { 0 };
825 float m_deviceScaleFactor { 1 };
826 float m_viewScaleFactor { 1 };
827
828 float m_topContentInset { 0 };
829 FloatBoxExtent m_obscuredInsets;
830 FloatBoxExtent m_contentInsets;
831 FloatBoxExtent m_unobscuredSafeAreaInsets;
832 FloatBoxExtent m_fullscreenInsets;
833 Seconds m_fullscreenAutoHideDuration { 0_s };
834
835#if PLATFORM(IOS_FAMILY)
836 bool m_enclosedInScrollableAncestorView { false };
837#endif
838
839 bool m_useSystemAppearance { false };
840 bool m_useInactiveAppearance { false };
841 bool m_useDarkAppearance { false };
842 Optional<bool> m_useDarkAppearanceOverride;
843
844#if ENABLE(TEXT_AUTOSIZING)
845 float m_textAutosizingWidth { 0 };
846#endif
847 float m_initialScale { 1.0f };
848
849 bool m_suppressScrollbarAnimations { false };
850
851 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
852 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
853
854 Pagination m_pagination;
855 bool m_paginationLineGridEnabled { false };
856
857 String m_userStyleSheetPath;
858 mutable String m_userStyleSheet;
859 mutable bool m_didLoadUserStyleSheet { false };
860 mutable Optional<WallTime> m_userStyleSheetModificationTime;
861
862 String m_captionUserPreferencesStyleSheet;
863
864 std::unique_ptr<PageGroup> m_singlePageGroup;
865 PageGroup* m_group { nullptr };
866
867 JSC::Debugger* m_debugger { nullptr };
868
869 bool m_canStartMedia { true };
870
871 RefPtr<StorageNamespace> m_sessionStorage;
872 RefPtr<StorageNamespace> m_ephemeralLocalStorage;
873
874 TimerThrottlingState m_timerThrottlingState { TimerThrottlingState::Disabled };
875 MonotonicTime m_timerThrottlingStateLastChangedTime;
876 Seconds m_domTimerAlignmentInterval;
877 Timer m_domTimerAlignmentIntervalIncreaseTimer;
878 Seconds m_domTimerAlignmentIntervalIncreaseLimit;
879
880 bool m_isEditable { false };
881 bool m_isPrerender { false };
882 OptionSet<ActivityState::Flag> m_activityState;
883
884 OptionSet<LayoutMilestone> m_requestedLayoutMilestones;
885
886 int m_headerHeight { 0 };
887 int m_footerHeight { 0 };
888
889 std::unique_ptr<RenderingUpdateScheduler> m_renderingUpdateScheduler;
890
891 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
892 Region m_topRelevantPaintedRegion;
893 Region m_bottomRelevantPaintedRegion;
894 Region m_relevantUnpaintedRegion;
895 bool m_isCountingRelevantRepaintedObjects { false };
896#ifndef NDEBUG
897 bool m_isPainting { false };
898#endif
899 AlternativeTextClient* m_alternativeTextClient;
900
901 bool m_scriptedAnimationsSuspended { false };
902 const std::unique_ptr<PageConsoleClient> m_consoleClient;
903
904#if ENABLE(REMOTE_INSPECTOR)
905 const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
906#endif
907
908#if ENABLE(INDEXED_DATABASE)
909 RefPtr<IDBClient::IDBConnectionToServer> m_idbConnectionToServer;
910#endif
911
912 HashSet<String> m_seenPlugins;
913 HashSet<String> m_seenMediaEngines;
914
915 unsigned m_lastSpatialNavigationCandidatesCount { 0 };
916 unsigned m_forbidPromptsDepth { 0 };
917
918 Ref<SocketProvider> m_socketProvider;
919 Ref<CookieJar> m_cookieJar;
920 Ref<ApplicationCacheStorage> m_applicationCacheStorage;
921 Ref<CacheStorageProvider> m_cacheStorageProvider;
922 Ref<DatabaseProvider> m_databaseProvider;
923 Ref<PluginInfoProvider> m_pluginInfoProvider;
924 Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
925 Ref<UserContentProvider> m_userContentProvider;
926 Ref<VisitedLinkStore> m_visitedLinkStore;
927 RefPtr<WheelEventTestTrigger> m_testTrigger;
928
929 HashSet<ActivityStateChangeObserver*> m_activityStateChangeObservers;
930
931#if ENABLE(RESOURCE_USAGE)
932 std::unique_ptr<ResourceUsageOverlay> m_resourceUsageOverlay;
933#endif
934
935 PAL::SessionID m_sessionID;
936
937 bool m_isClosing { false };
938 bool m_isRestoringCachedPage { false };
939
940 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
941
942#if ENABLE(VIDEO)
943 Timer m_playbackControlsManagerUpdateTimer;
944#endif
945
946 bool m_allowsMediaDocumentInlinePlayback { false };
947 bool m_allowsPlaybackControlsForAutoplayingAudio { false };
948 bool m_showAllPlugins { false };
949 bool m_controlledByAutomation { false };
950 bool m_resourceCachingDisabled { false };
951 bool m_resourceCachingDisabledOverride { false };
952 bool m_isUtilityPage;
953 UserInterfaceLayoutDirection m_userInterfaceLayoutDirection { UserInterfaceLayoutDirection::LTR };
954
955 // For testing.
956 Optional<EventThrottlingBehavior> m_eventThrottlingBehaviorOverride;
957 Optional<CompositingPolicy> m_compositingPolicyOverride;
958
959 std::unique_ptr<PerformanceMonitor> m_performanceMonitor;
960 std::unique_ptr<LowPowerModeNotifier> m_lowPowerModeNotifier;
961 Optional<bool> m_lowPowerModeEnabledOverrideForTesting;
962
963 Optional<Navigation> m_navigationToLogWhenVisible;
964
965 std::unique_ptr<PerformanceLogging> m_performanceLogging;
966#if PLATFORM(MAC)
967 Vector<ScrollLatchingState> m_latchingState;
968#if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
969 std::unique_ptr<ServicesOverlayController> m_servicesOverlayController;
970#endif
971#endif
972
973 std::unique_ptr<WheelEventDeltaFilter> m_recentWheelEventDeltaFilter;
974 std::unique_ptr<PageOverlayController> m_pageOverlayController;
975
976#if ENABLE(APPLE_PAY)
977 std::unique_ptr<PaymentCoordinator> m_paymentCoordinator;
978#endif
979
980#if ENABLE(WEB_AUTHN)
981 UniqueRef<AuthenticatorCoordinator> m_authenticatorCoordinator;
982#endif
983
984#if ENABLE(APPLICATION_MANIFEST)
985 Optional<ApplicationManifest> m_applicationManifest;
986#endif
987
988 Optional<ViewportArguments> m_overrideViewportArguments;
989
990 bool m_shouldEnableICECandidateFilteringByDefault { true };
991 bool m_mediaPlaybackIsSuspended { false };
992 bool m_mediaBufferingIsSuspended { false };
993 bool m_inUpdateRendering { false };
994};
995
996inline PageGroup& Page::group()
997{
998 if (!m_group)
999 initGroup();
1000 return *m_group;
1001}
1002
1003} // namespace WebCore
1004