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 bool openedByDOM() const;
156 void setOpenedByDOM();
158 WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType);
160 WEBCORE_EXPORT void setGroupName(const String&);
161 WEBCORE_EXPORT const String& groupName() const;
164 PageGroup* groupPtr() { return m_group; } // can return 0
166 void incrementSubframeCount() { ++m_subframeCount; }
167 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
168 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
170 #if ENABLE(REMOTE_INSPECTOR)
171 WEBCORE_EXPORT bool remoteInspectionAllowed() const;
172 WEBCORE_EXPORT void setRemoteInspectionAllowed(bool);
173 void remoteInspectorInformationDidChange() const;
176 Chrome& chrome() const { return *m_chrome; }
177 DragCaretController& dragCaretController() const { return *m_dragCaretController; }
178 #if ENABLE(DRAG_SUPPORT)
179 DragController& dragController() const { return *m_dragController; }
181 FocusController& focusController() const { return *m_focusController; }
182 #if ENABLE(CONTEXT_MENUS)
183 ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
185 UserInputBridge& userInputBridge() const { return *m_userInputBridge; }
186 #if ENABLE(WEB_REPLAY)
187 ReplayController& replayController() const { return *m_replayController; }
189 InspectorController& inspectorController() const { return *m_inspectorController; }
190 #if ENABLE(POINTER_LOCK)
191 PointerLockController& pointerLockController() const { return *m_pointerLockController; }
193 ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
195 WEBCORE_EXPORT ScrollingCoordinator* scrollingCoordinator();
197 WEBCORE_EXPORT String scrollingStateTreeAsText();
198 WEBCORE_EXPORT String synchronousScrollingReasonsAsText();
199 WEBCORE_EXPORT Ref<ClientRectList> nonFastScrollableRects(const Frame&);
201 Settings& settings() const { return *m_settings; }
202 ProgressTracker& progress() const { return *m_progress; }
203 BackForwardController& backForward() const { return *m_backForwardController; }
205 #if ENABLE(VIEW_MODE_CSS_MEDIA)
214 static ViewMode stringToViewMode(const String&);
216 ViewMode viewMode() const { return m_viewMode; }
217 WEBCORE_EXPORT void setViewMode(ViewMode);
218 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
220 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
221 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
223 WEBCORE_EXPORT bool findString(const String&, FindOptions);
225 WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
227 WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
228 WEBCORE_EXPORT unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned maxMatchCount);
230 WEBCORE_EXPORT void unmarkAllTextMatches();
232 // find all the Ranges for the matching text.
233 // Upon return, indexForSelection will be one of the following:
234 // 0 if there is no user selection
235 // the index of the first range after the user selection
236 // NoMatchAfterUserSelection if there is no matching text after the user selection.
237 enum { NoMatchAfterUserSelection = -1 };
238 WEBCORE_EXPORT void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>&, int& indexForSelection);
240 WEBCORE_EXPORT void addSchedulePair(Ref<SchedulePair>&&);
241 WEBCORE_EXPORT void removeSchedulePair(Ref<SchedulePair>&&);
242 SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
244 std::unique_ptr<SchedulePairHashSet> m_scheduledRunLoopPairs;
247 WEBCORE_EXPORT const VisibleSelection& selection() const;
249 WEBCORE_EXPORT void setDefersLoading(bool);
250 bool defersLoading() const { return m_defersLoading; }
252 WEBCORE_EXPORT void clearUndoRedoOperations();
254 WEBCORE_EXPORT bool inLowQualityImageInterpolationMode() const;
255 WEBCORE_EXPORT void setInLowQualityImageInterpolationMode(bool = true);
257 float mediaVolume() const { return m_mediaVolume; }
258 WEBCORE_EXPORT void setMediaVolume(float);
260 WEBCORE_EXPORT void setPageScaleFactor(float scale, const IntPoint& origin, bool inStableState = true);
261 float pageScaleFactor() const { return m_pageScaleFactor; }
263 WEBCORE_EXPORT void setZoomedOutPageScaleFactor(float);
264 float zoomedOutPageScaleFactor() const { return m_zoomedOutPageScaleFactor; }
266 float deviceScaleFactor() const { return m_deviceScaleFactor; }
267 WEBCORE_EXPORT void setDeviceScaleFactor(float);
269 float topContentInset() const { return m_topContentInset; }
270 WEBCORE_EXPORT void setTopContentInset(float);
272 #if ENABLE(IOS_TEXT_AUTOSIZING)
273 float textAutosizingWidth() const { return m_textAutosizingWidth; }
274 void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
277 bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
278 WEBCORE_EXPORT void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
279 void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
281 WEBCORE_EXPORT void setVerticalScrollElasticity(ScrollElasticity);
282 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
284 WEBCORE_EXPORT void setHorizontalScrollElasticity(ScrollElasticity);
285 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
287 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
288 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
289 // FrameViews in the page cache, but FrameView::pagination() only affects the current
291 const Pagination& pagination() const { return m_pagination; }
292 WEBCORE_EXPORT void setPagination(const Pagination&);
294 WEBCORE_EXPORT unsigned pageCount() const;
296 // Notifications when the Page starts and stops being presented via a native window.
297 WEBCORE_EXPORT void setViewState(ViewState::Flags);
298 void setPageActivityState(PageActivityState::Flags);
299 WEBCORE_EXPORT void setIsVisible(bool);
300 WEBCORE_EXPORT void setIsPrerender();
301 bool isVisible() const { return m_viewState & ViewState::IsVisible; }
303 // Notification that this Page was moved into or out of a native window.
304 WEBCORE_EXPORT void setIsInWindow(bool);
305 bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
307 void setIsClosing() { m_isClosing = true; }
308 bool isClosing() const { return m_isClosing; }
310 void addViewStateChangeObserver(ViewStateChangeObserver&);
311 void removeViewStateChangeObserver(ViewStateChangeObserver&);
313 WEBCORE_EXPORT void suspendScriptedAnimations();
314 WEBCORE_EXPORT void resumeScriptedAnimations();
315 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
317 void userStyleSheetLocationChanged();
318 const String& userStyleSheet() const;
320 void dnsPrefetchingStateChanged();
321 void storageBlockingStateChanged();
323 void setDebugger(JSC::Debugger*);
324 JSC::Debugger* debugger() const { return m_debugger; }
326 WEBCORE_EXPORT void invalidateStylesForAllLinks();
327 WEBCORE_EXPORT void invalidateStylesForLink(LinkHash);
329 StorageNamespace* sessionStorage(bool optionalCreate = true);
330 void setSessionStorage(RefPtr<StorageNamespace>&&);
332 bool hasCustomHTMLTokenizerTimeDelay() const;
333 double customHTMLTokenizerTimeDelay() const;
335 WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool);
336 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
338 // Don't allow more than a certain number of frames in a page.
339 // This seems like a reasonable upper bound, and otherwise mutually
340 // recursive frameset pages can quickly bring the program to its knees
341 // with exponential growth in the number of frames.
342 static const int maxNumberOfFrames = 1000;
344 void setEditable(bool isEditable) { m_isEditable = isEditable; }
345 bool isEditable() { return m_isEditable; }
347 WEBCORE_EXPORT PageVisibilityState visibilityState() const;
348 WEBCORE_EXPORT void resumeAnimatingImages();
350 WEBCORE_EXPORT void addLayoutMilestones(LayoutMilestones);
351 WEBCORE_EXPORT void removeLayoutMilestones(LayoutMilestones);
352 LayoutMilestones requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
354 #if ENABLE(RUBBER_BANDING)
355 WEBCORE_EXPORT void addHeaderWithHeight(int);
356 WEBCORE_EXPORT void addFooterWithHeight(int);
359 int headerHeight() const { return m_headerHeight; }
360 int footerHeight() const { return m_footerHeight; }
362 WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
364 bool isCountingRelevantRepaintedObjects() const;
365 void setIsCountingRelevantRepaintedObjects(bool isCounting) { m_isCountingRelevantRepaintedObjects = isCounting; }
366 void startCountingRelevantRepaintedObjects();
367 void resetRelevantPaintedObjectCounter();
368 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
369 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
371 WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
372 WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
374 void setIsPainting(bool painting) { m_isPainting = painting; }
375 bool isPainting() const { return m_isPainting; }
378 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
380 bool hasSeenPlugin(const String& serviceType) const;
381 WEBCORE_EXPORT bool hasSeenAnyPlugin() const;
382 void sawPlugin(const String& serviceType);
383 void resetSeenPlugins();
385 bool hasSeenMediaEngine(const String& engineName) const;
386 bool hasSeenAnyMediaEngine() const;
387 void sawMediaEngine(const String& engineName);
388 void resetSeenMediaEngines();
390 PageThrottler& pageThrottler() { return m_pageThrottler; }
392 PageConsoleClient& console() { return *m_consoleClient; }
394 #if ENABLE(REMOTE_INSPECTOR)
395 PageDebuggable& inspectorDebuggable() const { return *m_inspectorDebuggable.get(); }
398 void hiddenPageCSSAnimationSuspensionStateChanged();
400 #if ENABLE(VIDEO_TRACK)
401 void captionPreferencesChanged();
404 void incrementFrameHandlingBeforeUnloadEventCount();
405 void decrementFrameHandlingBeforeUnloadEventCount();
406 bool isAnyFrameHandlingBeforeUnloadEvent();
407 void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
408 unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
410 ApplicationCacheStorage& applicationCacheStorage() { return m_applicationCacheStorage; }
411 DatabaseProvider& databaseProvider() { return m_databaseProvider; }
413 StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
414 void setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&&);
416 UserContentController* userContentController() { return m_userContentController.get(); }
417 WEBCORE_EXPORT void setUserContentController(UserContentController*);
419 VisitedLinkStore& visitedLinkStore();
420 WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
422 WEBCORE_EXPORT SessionID sessionID() const;
423 WEBCORE_EXPORT void setSessionID(SessionID);
424 WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
425 bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
427 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
428 void updateIsPlayingMedia();
429 bool isMuted() const { return m_muted; }
430 WEBCORE_EXPORT void setMuted(bool);
432 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
433 void addPlaybackTargetPickerClient(uint64_t);
434 void removePlaybackTargetPickerClient(uint64_t);
435 void showPlaybackTargetPicker(uint64_t, const WebCore::IntPoint&, bool);
436 void playbackTargetPickerClientStateDidChange(uint64_t, MediaProducer::MediaStateFlags);
438 WEBCORE_EXPORT void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
439 WEBCORE_EXPORT void playbackTargetAvailabilityDidChange(uint64_t, bool);
440 WEBCORE_EXPORT void setShouldPlayToPlaybackTarget(uint64_t, bool);
443 WEBCORE_EXPORT RefPtr<WheelEventTestTrigger> testTrigger() const;
444 WEBCORE_EXPORT WheelEventTestTrigger& ensureTestTrigger();
445 WEBCORE_EXPORT void clearTrigger();
446 WEBCORE_EXPORT bool expectsWheelEventTriggers() const { return !!m_testTrigger; }
449 WEBCORE_EXPORT void initGroup();
451 void setIsInWindowInternal(bool);
452 void setIsVisibleInternal(bool);
453 void setIsVisuallyIdleInternal(bool);
456 void checkSubframeCountConsistency() const { }
458 void checkSubframeCountConsistency() const;
461 enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
462 enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
464 unsigned findMatchesForText(const String&, FindOptions, unsigned maxMatchCount, ShouldHighlightMatches, ShouldMarkMatches);
466 MediaCanStartListener* takeAnyMediaCanStartListener();
468 Vector<Ref<PluginViewBase>> pluginViews();
470 void hiddenPageDOMTimerThrottlingStateChanged();
471 void setTimerThrottlingEnabled(bool);
473 const std::unique_ptr<Chrome> m_chrome;
474 const std::unique_ptr<DragCaretController> m_dragCaretController;
476 #if ENABLE(DRAG_SUPPORT)
477 const std::unique_ptr<DragController> m_dragController;
479 const std::unique_ptr<FocusController> m_focusController;
480 #if ENABLE(CONTEXT_MENUS)
481 const std::unique_ptr<ContextMenuController> m_contextMenuController;
483 const std::unique_ptr<UserInputBridge> m_userInputBridge;
484 #if ENABLE(WEB_REPLAY)
485 const std::unique_ptr<ReplayController> m_replayController;
487 const std::unique_ptr<InspectorController> m_inspectorController;
488 #if ENABLE(POINTER_LOCK)
489 const std::unique_ptr<PointerLockController> m_pointerLockController;
491 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
493 const RefPtr<Settings> m_settings;
494 const std::unique_ptr<ProgressTracker> m_progress;
496 const std::unique_ptr<BackForwardController> m_backForwardController;
497 const RefPtr<MainFrame> m_mainFrame;
499 mutable RefPtr<PluginData> m_pluginData;
501 RefPtr<RenderTheme> m_theme;
503 EditorClient& m_editorClient;
504 PlugInClient* m_plugInClient;
505 ValidationMessageClient* m_validationMessageClient;
511 bool m_tabKeyCyclesThroughElements;
512 bool m_defersLoading;
513 unsigned m_defersLoadingCallCount;
515 bool m_inLowQualityInterpolationMode;
516 bool m_areMemoryCacheClientCallsEnabled;
520 float m_pageScaleFactor;
521 float m_zoomedOutPageScaleFactor;
522 float m_deviceScaleFactor;
524 float m_topContentInset;
526 #if ENABLE(IOS_TEXT_AUTOSIZING)
527 float m_textAutosizingWidth;
530 bool m_suppressScrollbarAnimations;
532 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
533 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
535 Pagination m_pagination;
537 String m_userStyleSheetPath;
538 mutable String m_userStyleSheet;
539 mutable bool m_didLoadUserStyleSheet;
540 mutable time_t m_userStyleSheetModificationTime;
542 std::unique_ptr<PageGroup> m_singlePageGroup;
545 JSC::Debugger* m_debugger;
547 bool m_canStartMedia;
549 RefPtr<StorageNamespace> m_sessionStorage;
551 #if ENABLE(VIEW_MODE_CSS_MEDIA)
553 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
555 bool m_timerThrottlingEnabled;
559 ViewState::Flags m_viewState;
561 LayoutMilestones m_requestedLayoutMilestones;
566 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
567 Region m_topRelevantPaintedRegion;
568 Region m_bottomRelevantPaintedRegion;
569 Region m_relevantUnpaintedRegion;
570 bool m_isCountingRelevantRepaintedObjects;
574 AlternativeTextClient* m_alternativeTextClient;
576 bool m_scriptedAnimationsSuspended;
577 PageThrottler m_pageThrottler;
578 const std::unique_ptr<PageConsoleClient> m_consoleClient;
580 #if ENABLE(REMOTE_INSPECTOR)
581 const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
584 HashSet<String> m_seenPlugins;
585 HashSet<String> m_seenMediaEngines;
587 unsigned m_lastSpatialNavigationCandidatesCount;
588 unsigned m_framesHandlingBeforeUnloadEvent;
590 Ref<ApplicationCacheStorage> m_applicationCacheStorage;
591 Ref<DatabaseProvider> m_databaseProvider;
592 Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
593 RefPtr<UserContentController> m_userContentController;
594 Ref<VisitedLinkStore> m_visitedLinkStore;
595 RefPtr<WheelEventTestTrigger> m_testTrigger;
597 HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
599 SessionID m_sessionID;
603 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
606 inline PageGroup& Page::group()
613 } // namespace WebCore