2 * Copyright (C) 2006-2010, 2013, 2015 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
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.
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.
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.
24 #include "FindOptions.h"
25 #include "FrameLoaderTypes.h"
26 #include "LayoutMilestones.h"
27 #include "LayoutRect.h"
28 #include "MediaProducer.h"
29 #include "PageThrottler.h"
30 #include "PageVisibilityState.h"
31 #include "Pagination.h"
32 #include "PlatformScreen.h"
34 #include "ScrollTypes.h"
35 #include "SessionID.h"
36 #include "Supplementable.h"
37 #include "ViewState.h"
38 #include "ViewportArguments.h"
39 #include "WheelEventTestTrigger.h"
41 #include <wtf/Forward.h>
42 #include <wtf/HashMap.h>
43 #include <wtf/HashSet.h>
44 #include <wtf/Noncopyable.h>
46 #include <wtf/RefCounted.h>
47 #include <wtf/text/WTFString.h>
50 #include <sys/time.h> // For time_t structure.
54 #include <wtf/SchedulePair.h>
63 class AlternativeTextClient;
64 class ApplicationCacheStorage;
65 class BackForwardController;
66 class BackForwardClient;
71 class ContextMenuClient;
72 class ContextMenuController;
73 class DatabaseProvider;
74 class DragCaretController;
78 class FocusController;
80 class FrameLoaderClient;
82 class HTMLMediaElement;
83 class UserInputBridge;
84 class InspectorClient;
85 class InspectorController;
87 class MediaCanStartListener;
88 class MediaPlaybackTarget;
89 class PageConfiguration;
90 class PageConsoleClient;
97 class PointerLockController;
98 class ProgressTracker;
99 class ProgressTrackerClient;
103 class ReplayController;
104 class VisibleSelection;
105 class ScrollableArea;
106 class ScrollingCoordinator;
108 class StorageNamespace;
109 class StorageNamespaceProvider;
110 class UserContentController;
111 class ValidationMessageClient;
112 class ViewStateChangeObserver;
113 class VisitedLinkStore;
115 typedef uint64_t LinkHash;
118 enum FindDirection { FindDirectionForward, FindDirectionBackward };
120 class Page : public Supplementable<Page> {
121 WTF_MAKE_NONCOPYABLE(Page);
122 WTF_MAKE_FAST_ALLOCATED;
123 friend class Settings;
124 friend class PageThrottler;
127 WEBCORE_EXPORT static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
128 WEBCORE_EXPORT static void clearPreviousItemFromAllPages(HistoryItem*);
130 WEBCORE_EXPORT explicit Page(PageConfiguration&);
131 WEBCORE_EXPORT ~Page();
133 WEBCORE_EXPORT uint64_t renderTreeSize() const;
135 static std::unique_ptr<Page> createPageFromBuffer(PageConfiguration&, const SharedBuffer*, const String& mimeType, bool canHaveScrollbars, bool transparent);
137 void setNeedsRecalcStyleInAllFrames();
139 RenderTheme& theme() const { return *m_theme; }
141 WEBCORE_EXPORT ViewportArguments viewportArguments() const;
143 static void refreshPlugins(bool reload);
144 WEBCORE_EXPORT PluginData& pluginData() const;
146 WEBCORE_EXPORT void setCanStartMedia(bool);
147 bool canStartMedia() const { return m_canStartMedia; }
149 EditorClient& editorClient() { return m_editorClient; }
150 PlugInClient* plugInClient() const { return m_plugInClient; }
152 MainFrame& mainFrame() { ASSERT(m_mainFrame); return *m_mainFrame; }
153 const MainFrame& mainFrame() const { ASSERT(m_mainFrame); return *m_mainFrame; }
155 enum class DismissalType {
161 DismissalType dismissalEventBeingDispatched() const { return m_dismissalEventBeingDispatched; }
162 void setDismissalEventBeingDispatched(DismissalType dismissalType) { m_dismissalEventBeingDispatched = dismissalType; }
164 bool openedByDOM() const;
165 void setOpenedByDOM();
167 WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType);
169 WEBCORE_EXPORT void setGroupName(const String&);
170 WEBCORE_EXPORT const String& groupName() const;
173 PageGroup* groupPtr() { return m_group; } // can return 0
175 void incrementSubframeCount() { ++m_subframeCount; }
176 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
177 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
179 #if ENABLE(REMOTE_INSPECTOR)
180 WEBCORE_EXPORT bool remoteInspectionAllowed() const;
181 WEBCORE_EXPORT void setRemoteInspectionAllowed(bool);
182 void remoteInspectorInformationDidChange() const;
185 Chrome& chrome() const { return *m_chrome; }
186 DragCaretController& dragCaretController() const { return *m_dragCaretController; }
187 #if ENABLE(DRAG_SUPPORT)
188 DragController& dragController() const { return *m_dragController; }
190 FocusController& focusController() const { return *m_focusController; }
191 #if ENABLE(CONTEXT_MENUS)
192 ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
194 UserInputBridge& userInputBridge() const { return *m_userInputBridge; }
195 #if ENABLE(WEB_REPLAY)
196 ReplayController& replayController() const { return *m_replayController; }
198 InspectorController& inspectorController() const { return *m_inspectorController; }
199 #if ENABLE(POINTER_LOCK)
200 PointerLockController& pointerLockController() const { return *m_pointerLockController; }
202 ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
204 WEBCORE_EXPORT ScrollingCoordinator* scrollingCoordinator();
206 WEBCORE_EXPORT String scrollingStateTreeAsText();
207 WEBCORE_EXPORT String synchronousScrollingReasonsAsText();
208 WEBCORE_EXPORT Ref<ClientRectList> nonFastScrollableRects();
210 Settings& settings() const { return *m_settings; }
211 ProgressTracker& progress() const { return *m_progress; }
212 BackForwardController& backForward() const { return *m_backForwardController; }
214 #if ENABLE(VIEW_MODE_CSS_MEDIA)
223 static ViewMode stringToViewMode(const String&);
225 ViewMode viewMode() const { return m_viewMode; }
226 WEBCORE_EXPORT void setViewMode(ViewMode);
227 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
229 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
230 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
232 WEBCORE_EXPORT bool findString(const String&, FindOptions);
234 WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
236 WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
237 WEBCORE_EXPORT unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned maxMatchCount);
239 WEBCORE_EXPORT void unmarkAllTextMatches();
241 // find all the Ranges for the matching text.
242 // Upon return, indexForSelection will be one of the following:
243 // 0 if there is no user selection
244 // the index of the first range after the user selection
245 // NoMatchAfterUserSelection if there is no matching text after the user selection.
246 enum { NoMatchAfterUserSelection = -1 };
247 WEBCORE_EXPORT void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>&, int& indexForSelection);
249 WEBCORE_EXPORT void addSchedulePair(Ref<SchedulePair>&&);
250 WEBCORE_EXPORT void removeSchedulePair(Ref<SchedulePair>&&);
251 SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
253 std::unique_ptr<SchedulePairHashSet> m_scheduledRunLoopPairs;
256 WEBCORE_EXPORT const VisibleSelection& selection() const;
258 WEBCORE_EXPORT void setDefersLoading(bool);
259 bool defersLoading() const { return m_defersLoading; }
261 WEBCORE_EXPORT void clearUndoRedoOperations();
263 WEBCORE_EXPORT bool inLowQualityImageInterpolationMode() const;
264 WEBCORE_EXPORT void setInLowQualityImageInterpolationMode(bool = true);
266 float mediaVolume() const { return m_mediaVolume; }
267 WEBCORE_EXPORT void setMediaVolume(float);
269 WEBCORE_EXPORT void setPageScaleFactor(float scale, const IntPoint& origin, bool inStableState = true);
270 float pageScaleFactor() const { return m_pageScaleFactor; }
272 // The view scale factor is multiplied into the page scale factor by all
273 // callers of setPageScaleFactor.
274 WEBCORE_EXPORT void setViewScaleFactor(float);
275 float viewScaleFactor() const { return m_viewScaleFactor; }
277 WEBCORE_EXPORT void setZoomedOutPageScaleFactor(float);
278 float zoomedOutPageScaleFactor() const { return m_zoomedOutPageScaleFactor; }
280 float deviceScaleFactor() const { return m_deviceScaleFactor; }
281 WEBCORE_EXPORT void setDeviceScaleFactor(float);
283 float topContentInset() const { return m_topContentInset; }
284 WEBCORE_EXPORT void setTopContentInset(float);
286 #if ENABLE(IOS_TEXT_AUTOSIZING)
287 float textAutosizingWidth() const { return m_textAutosizingWidth; }
288 void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
291 bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
292 WEBCORE_EXPORT void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
293 void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
295 WEBCORE_EXPORT void setVerticalScrollElasticity(ScrollElasticity);
296 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
298 WEBCORE_EXPORT void setHorizontalScrollElasticity(ScrollElasticity);
299 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
301 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
302 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
303 // FrameViews in the page cache, but FrameView::pagination() only affects the current
305 const Pagination& pagination() const { return m_pagination; }
306 WEBCORE_EXPORT void setPagination(const Pagination&);
308 WEBCORE_EXPORT unsigned pageCount() const;
310 // Notifications when the Page starts and stops being presented via a native window.
311 WEBCORE_EXPORT void setViewState(ViewState::Flags);
312 void setPageActivityState(PageActivityState::Flags);
313 WEBCORE_EXPORT void setIsVisible(bool);
314 WEBCORE_EXPORT void setIsPrerender();
315 bool isVisible() const { return m_viewState & ViewState::IsVisible; }
317 // Notification that this Page was moved into or out of a native window.
318 WEBCORE_EXPORT void setIsInWindow(bool);
319 bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
321 void setIsClosing() { m_isClosing = true; }
322 bool isClosing() const { return m_isClosing; }
324 void addViewStateChangeObserver(ViewStateChangeObserver&);
325 void removeViewStateChangeObserver(ViewStateChangeObserver&);
327 WEBCORE_EXPORT void suspendScriptedAnimations();
328 WEBCORE_EXPORT void resumeScriptedAnimations();
329 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
331 void userStyleSheetLocationChanged();
332 const String& userStyleSheet() const;
334 void dnsPrefetchingStateChanged();
335 void storageBlockingStateChanged();
337 void setDebugger(JSC::Debugger*);
338 JSC::Debugger* debugger() const { return m_debugger; }
340 WEBCORE_EXPORT void invalidateStylesForAllLinks();
341 WEBCORE_EXPORT void invalidateStylesForLink(LinkHash);
343 StorageNamespace* sessionStorage(bool optionalCreate = true);
344 void setSessionStorage(RefPtr<StorageNamespace>&&);
346 bool hasCustomHTMLTokenizerTimeDelay() const;
347 double customHTMLTokenizerTimeDelay() const;
349 WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool);
350 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
352 // Don't allow more than a certain number of frames in a page.
353 // This seems like a reasonable upper bound, and otherwise mutually
354 // recursive frameset pages can quickly bring the program to its knees
355 // with exponential growth in the number of frames.
356 static const int maxNumberOfFrames = 1000;
358 void setEditable(bool isEditable) { m_isEditable = isEditable; }
359 bool isEditable() { return m_isEditable; }
361 WEBCORE_EXPORT PageVisibilityState visibilityState() const;
362 WEBCORE_EXPORT void resumeAnimatingImages();
364 WEBCORE_EXPORT void addLayoutMilestones(LayoutMilestones);
365 WEBCORE_EXPORT void removeLayoutMilestones(LayoutMilestones);
366 LayoutMilestones requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
368 #if ENABLE(RUBBER_BANDING)
369 WEBCORE_EXPORT void addHeaderWithHeight(int);
370 WEBCORE_EXPORT void addFooterWithHeight(int);
373 int headerHeight() const { return m_headerHeight; }
374 int footerHeight() const { return m_footerHeight; }
376 WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
378 bool isCountingRelevantRepaintedObjects() const;
379 void setIsCountingRelevantRepaintedObjects(bool isCounting) { m_isCountingRelevantRepaintedObjects = isCounting; }
380 void startCountingRelevantRepaintedObjects();
381 void resetRelevantPaintedObjectCounter();
382 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
383 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
385 WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
386 WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
388 void setIsPainting(bool painting) { m_isPainting = painting; }
389 bool isPainting() const { return m_isPainting; }
392 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
394 bool hasSeenPlugin(const String& serviceType) const;
395 WEBCORE_EXPORT bool hasSeenAnyPlugin() const;
396 void sawPlugin(const String& serviceType);
397 void resetSeenPlugins();
399 bool hasSeenMediaEngine(const String& engineName) const;
400 bool hasSeenAnyMediaEngine() const;
401 void sawMediaEngine(const String& engineName);
402 void resetSeenMediaEngines();
404 PageThrottler& pageThrottler() { return m_pageThrottler; }
406 PageConsoleClient& console() { return *m_consoleClient; }
408 #if ENABLE(REMOTE_INSPECTOR)
409 PageDebuggable& inspectorDebuggable() const { return *m_inspectorDebuggable.get(); }
412 void hiddenPageCSSAnimationSuspensionStateChanged();
414 #if ENABLE(VIDEO_TRACK)
415 void captionPreferencesChanged();
418 void incrementFrameHandlingBeforeUnloadEventCount();
419 void decrementFrameHandlingBeforeUnloadEventCount();
420 bool isAnyFrameHandlingBeforeUnloadEvent();
421 void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
422 unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
424 ApplicationCacheStorage& applicationCacheStorage() { return m_applicationCacheStorage; }
425 DatabaseProvider& databaseProvider() { return m_databaseProvider; }
427 StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
428 void setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&&);
430 UserContentController* userContentController() { return m_userContentController.get(); }
431 WEBCORE_EXPORT void setUserContentController(UserContentController*);
433 VisitedLinkStore& visitedLinkStore();
434 WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
436 WEBCORE_EXPORT SessionID sessionID() const;
437 WEBCORE_EXPORT void setSessionID(SessionID);
438 WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
439 bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
441 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
442 void updateIsPlayingMedia();
443 bool isMuted() const { return m_muted; }
444 WEBCORE_EXPORT void setMuted(bool);
446 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
447 void addPlaybackTargetPickerClient(uint64_t);
448 void removePlaybackTargetPickerClient(uint64_t);
449 void showPlaybackTargetPicker(uint64_t, const WebCore::IntPoint&, bool);
450 void playbackTargetPickerClientStateDidChange(uint64_t, MediaProducer::MediaStateFlags);
452 WEBCORE_EXPORT void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
453 WEBCORE_EXPORT void playbackTargetAvailabilityDidChange(uint64_t, bool);
454 WEBCORE_EXPORT void setShouldPlayToPlaybackTarget(uint64_t, bool);
457 RefPtr<WheelEventTestTrigger> testTrigger() const { return m_testTrigger; }
458 WEBCORE_EXPORT WheelEventTestTrigger& ensureTestTrigger();
459 void clearTrigger() { m_testTrigger = nullptr; }
460 bool expectsWheelEventTriggers() const { return !!m_testTrigger; }
463 WEBCORE_EXPORT void initGroup();
465 void setIsInWindowInternal(bool);
466 void setIsVisibleInternal(bool);
467 void setIsVisuallyIdleInternal(bool);
470 void checkSubframeCountConsistency() const { }
472 void checkSubframeCountConsistency() const;
475 enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
476 enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
478 unsigned findMatchesForText(const String&, FindOptions, unsigned maxMatchCount, ShouldHighlightMatches, ShouldMarkMatches);
480 MediaCanStartListener* takeAnyMediaCanStartListener();
482 Vector<Ref<PluginViewBase>> pluginViews();
484 void hiddenPageDOMTimerThrottlingStateChanged();
485 void setTimerThrottlingEnabled(bool);
487 const std::unique_ptr<Chrome> m_chrome;
488 const std::unique_ptr<DragCaretController> m_dragCaretController;
490 #if ENABLE(DRAG_SUPPORT)
491 const std::unique_ptr<DragController> m_dragController;
493 const std::unique_ptr<FocusController> m_focusController;
494 #if ENABLE(CONTEXT_MENUS)
495 const std::unique_ptr<ContextMenuController> m_contextMenuController;
497 const std::unique_ptr<UserInputBridge> m_userInputBridge;
498 #if ENABLE(WEB_REPLAY)
499 const std::unique_ptr<ReplayController> m_replayController;
501 const std::unique_ptr<InspectorController> m_inspectorController;
502 #if ENABLE(POINTER_LOCK)
503 const std::unique_ptr<PointerLockController> m_pointerLockController;
505 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
507 const RefPtr<Settings> m_settings;
508 const std::unique_ptr<ProgressTracker> m_progress;
510 const std::unique_ptr<BackForwardController> m_backForwardController;
511 const RefPtr<MainFrame> m_mainFrame;
513 mutable RefPtr<PluginData> m_pluginData;
515 RefPtr<RenderTheme> m_theme;
517 EditorClient& m_editorClient;
518 PlugInClient* m_plugInClient;
519 ValidationMessageClient* m_validationMessageClient;
525 bool m_tabKeyCyclesThroughElements;
526 bool m_defersLoading;
527 unsigned m_defersLoadingCallCount;
529 bool m_inLowQualityInterpolationMode;
530 bool m_areMemoryCacheClientCallsEnabled;
534 float m_pageScaleFactor;
535 float m_zoomedOutPageScaleFactor;
536 float m_deviceScaleFactor;
537 float m_viewScaleFactor { 1 };
539 float m_topContentInset;
541 #if ENABLE(IOS_TEXT_AUTOSIZING)
542 float m_textAutosizingWidth;
545 bool m_suppressScrollbarAnimations;
547 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
548 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
550 Pagination m_pagination;
552 String m_userStyleSheetPath;
553 mutable String m_userStyleSheet;
554 mutable bool m_didLoadUserStyleSheet;
555 mutable time_t m_userStyleSheetModificationTime;
557 std::unique_ptr<PageGroup> m_singlePageGroup;
560 JSC::Debugger* m_debugger;
562 bool m_canStartMedia;
564 RefPtr<StorageNamespace> m_sessionStorage;
566 #if ENABLE(VIEW_MODE_CSS_MEDIA)
568 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
570 bool m_timerThrottlingEnabled;
574 ViewState::Flags m_viewState;
576 LayoutMilestones m_requestedLayoutMilestones;
581 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
582 Region m_topRelevantPaintedRegion;
583 Region m_bottomRelevantPaintedRegion;
584 Region m_relevantUnpaintedRegion;
585 bool m_isCountingRelevantRepaintedObjects;
589 AlternativeTextClient* m_alternativeTextClient;
591 bool m_scriptedAnimationsSuspended;
592 PageThrottler m_pageThrottler;
593 const std::unique_ptr<PageConsoleClient> m_consoleClient;
595 #if ENABLE(REMOTE_INSPECTOR)
596 const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
599 HashSet<String> m_seenPlugins;
600 HashSet<String> m_seenMediaEngines;
602 unsigned m_lastSpatialNavigationCandidatesCount;
603 unsigned m_framesHandlingBeforeUnloadEvent;
605 Ref<ApplicationCacheStorage> m_applicationCacheStorage;
606 Ref<DatabaseProvider> m_databaseProvider;
607 Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
608 RefPtr<UserContentController> m_userContentController;
609 Ref<VisitedLinkStore> m_visitedLinkStore;
610 RefPtr<WheelEventTestTrigger> m_testTrigger;
612 HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
614 SessionID m_sessionID;
618 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
619 DismissalType m_dismissalEventBeingDispatched { DismissalType::None };
622 inline PageGroup& Page::group()
629 } // namespace WebCore