2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 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"
40 #include <wtf/Forward.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/HashSet.h>
43 #include <wtf/Noncopyable.h>
45 #include <wtf/RefCounted.h>
46 #include <wtf/text/WTFString.h>
49 #include <sys/time.h> // For time_t structure.
53 #include <wtf/SchedulePair.h>
62 class AlternativeTextClient;
63 class ApplicationCacheStorage;
64 class BackForwardController;
65 class BackForwardClient;
70 class ContextMenuClient;
71 class ContextMenuController;
72 class DatabaseProvider;
73 class DragCaretController;
77 class FocusController;
79 class FrameLoaderClient;
81 class HTMLMediaElement;
82 class UserInputBridge;
83 class InspectorClient;
84 class InspectorController;
86 class MediaCanStartListener;
87 class MediaPlaybackTarget;
88 class PageConfiguration;
89 class PageConsoleClient;
96 class PointerLockController;
97 class ProgressTracker;
98 class ProgressTrackerClient;
102 class ReplayController;
103 class VisibleSelection;
104 class ScrollableArea;
105 class ScrollingCoordinator;
107 class StorageNamespace;
108 class StorageNamespaceProvider;
109 class UserContentController;
110 class ValidationMessageClient;
111 class ViewStateChangeObserver;
112 class VisitedLinkStore;
114 typedef uint64_t LinkHash;
117 enum FindDirection { FindDirectionForward, FindDirectionBackward };
119 class Page : public Supplementable<Page> {
120 WTF_MAKE_NONCOPYABLE(Page);
121 WTF_MAKE_FAST_ALLOCATED;
122 friend class Settings;
123 friend class PageThrottler;
126 WEBCORE_EXPORT static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
127 WEBCORE_EXPORT static void clearPreviousItemFromAllPages(HistoryItem*);
129 WEBCORE_EXPORT explicit Page(PageConfiguration&);
130 WEBCORE_EXPORT ~Page();
132 WEBCORE_EXPORT uint64_t renderTreeSize() const;
134 static std::unique_ptr<Page> createPageFromBuffer(PageConfiguration&, const SharedBuffer*, const String& mimeType, bool canHaveScrollbars, bool transparent);
136 void setNeedsRecalcStyleInAllFrames();
138 RenderTheme& theme() const { return *m_theme; }
140 WEBCORE_EXPORT ViewportArguments viewportArguments() const;
142 static void refreshPlugins(bool reload);
143 WEBCORE_EXPORT PluginData& pluginData() const;
145 WEBCORE_EXPORT void setCanStartMedia(bool);
146 bool canStartMedia() const { return m_canStartMedia; }
148 EditorClient& editorClient() { return m_editorClient; }
149 PlugInClient* plugInClient() const { return m_plugInClient; }
151 MainFrame& mainFrame() { ASSERT(m_mainFrame); return *m_mainFrame; }
152 const MainFrame& mainFrame() const { ASSERT(m_mainFrame); return *m_mainFrame; }
154 bool openedByDOM() const;
155 void setOpenedByDOM();
157 WEBCORE_EXPORT void goToItem(HistoryItem&, FrameLoadType);
159 WEBCORE_EXPORT void setGroupName(const String&);
160 WEBCORE_EXPORT const String& groupName() const;
163 PageGroup* groupPtr() { return m_group; } // can return 0
165 void incrementSubframeCount() { ++m_subframeCount; }
166 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
167 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
169 #if ENABLE(REMOTE_INSPECTOR)
170 WEBCORE_EXPORT bool remoteInspectionAllowed() const;
171 WEBCORE_EXPORT void setRemoteInspectionAllowed(bool);
172 void remoteInspectorInformationDidChange() const;
175 Chrome& chrome() const { return *m_chrome; }
176 DragCaretController& dragCaretController() const { return *m_dragCaretController; }
177 #if ENABLE(DRAG_SUPPORT)
178 DragController& dragController() const { return *m_dragController; }
180 FocusController& focusController() const { return *m_focusController; }
181 #if ENABLE(CONTEXT_MENUS)
182 ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
184 UserInputBridge& userInputBridge() const { return *m_userInputBridge; }
185 #if ENABLE(WEB_REPLAY)
186 ReplayController& replayController() const { return *m_replayController; }
188 InspectorController& inspectorController() const { return *m_inspectorController; }
189 #if ENABLE(POINTER_LOCK)
190 PointerLockController& pointerLockController() const { return *m_pointerLockController; }
192 ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
194 WEBCORE_EXPORT ScrollingCoordinator* scrollingCoordinator();
196 WEBCORE_EXPORT String scrollingStateTreeAsText();
197 WEBCORE_EXPORT String synchronousScrollingReasonsAsText();
198 WEBCORE_EXPORT Ref<ClientRectList> nonFastScrollableRects(const Frame&);
200 Settings& settings() const { return *m_settings; }
201 ProgressTracker& progress() const { return *m_progress; }
202 BackForwardController& backForward() const { return *m_backForwardController; }
204 #if ENABLE(VIEW_MODE_CSS_MEDIA)
213 static ViewMode stringToViewMode(const String&);
215 ViewMode viewMode() const { return m_viewMode; }
216 WEBCORE_EXPORT void setViewMode(ViewMode);
217 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
219 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
220 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
222 WEBCORE_EXPORT bool findString(const String&, FindOptions);
224 WEBCORE_EXPORT RefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
226 WEBCORE_EXPORT unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
227 WEBCORE_EXPORT unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned maxMatchCount);
229 WEBCORE_EXPORT void unmarkAllTextMatches();
231 // find all the Ranges for the matching text.
232 // Upon return, indexForSelection will be one of the following:
233 // 0 if there is no user selection
234 // the index of the first range after the user selection
235 // NoMatchAfterUserSelection if there is no matching text after the user selection.
236 enum { NoMatchAfterUserSelection = -1 };
237 WEBCORE_EXPORT void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>&, int& indexForSelection);
239 WEBCORE_EXPORT void addSchedulePair(Ref<SchedulePair>&&);
240 WEBCORE_EXPORT void removeSchedulePair(Ref<SchedulePair>&&);
241 SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
243 std::unique_ptr<SchedulePairHashSet> m_scheduledRunLoopPairs;
246 WEBCORE_EXPORT const VisibleSelection& selection() const;
248 WEBCORE_EXPORT void setDefersLoading(bool);
249 bool defersLoading() const { return m_defersLoading; }
251 WEBCORE_EXPORT void clearUndoRedoOperations();
253 WEBCORE_EXPORT bool inLowQualityImageInterpolationMode() const;
254 WEBCORE_EXPORT void setInLowQualityImageInterpolationMode(bool = true);
256 float mediaVolume() const { return m_mediaVolume; }
257 WEBCORE_EXPORT void setMediaVolume(float);
259 WEBCORE_EXPORT void setPageScaleFactor(float scale, const IntPoint& origin, bool inStableState = true);
260 float pageScaleFactor() const { return m_pageScaleFactor; }
262 WEBCORE_EXPORT void setZoomedOutPageScaleFactor(float);
263 float zoomedOutPageScaleFactor() const { return m_zoomedOutPageScaleFactor; }
265 float deviceScaleFactor() const { return m_deviceScaleFactor; }
266 WEBCORE_EXPORT void setDeviceScaleFactor(float);
268 float topContentInset() const { return m_topContentInset; }
269 WEBCORE_EXPORT void setTopContentInset(float);
271 #if ENABLE(IOS_TEXT_AUTOSIZING)
272 float textAutosizingWidth() const { return m_textAutosizingWidth; }
273 void setTextAutosizingWidth(float textAutosizingWidth) { m_textAutosizingWidth = textAutosizingWidth; }
276 bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
277 WEBCORE_EXPORT void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
278 void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
280 WEBCORE_EXPORT void setVerticalScrollElasticity(ScrollElasticity);
281 ScrollElasticity verticalScrollElasticity() const { return static_cast<ScrollElasticity>(m_verticalScrollElasticity); }
283 WEBCORE_EXPORT void setHorizontalScrollElasticity(ScrollElasticity);
284 ScrollElasticity horizontalScrollElasticity() const { return static_cast<ScrollElasticity>(m_horizontalScrollElasticity); }
286 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
287 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
288 // FrameViews in the page cache, but FrameView::pagination() only affects the current
290 const Pagination& pagination() const { return m_pagination; }
291 WEBCORE_EXPORT void setPagination(const Pagination&);
293 WEBCORE_EXPORT unsigned pageCount() const;
295 // Notifications when the Page starts and stops being presented via a native window.
296 WEBCORE_EXPORT void setViewState(ViewState::Flags);
297 void setPageActivityState(PageActivityState::Flags);
298 WEBCORE_EXPORT void setIsVisible(bool);
299 WEBCORE_EXPORT void setIsPrerender();
300 bool isVisible() const { return m_viewState & ViewState::IsVisible; }
302 // Notification that this Page was moved into or out of a native window.
303 WEBCORE_EXPORT void setIsInWindow(bool);
304 bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
306 void setIsClosing() { m_isClosing = true; }
307 bool isClosing() const { return m_isClosing; }
309 void addViewStateChangeObserver(ViewStateChangeObserver&);
310 void removeViewStateChangeObserver(ViewStateChangeObserver&);
312 WEBCORE_EXPORT void suspendScriptedAnimations();
313 WEBCORE_EXPORT void resumeScriptedAnimations();
314 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
316 void userStyleSheetLocationChanged();
317 const String& userStyleSheet() const;
319 void dnsPrefetchingStateChanged();
320 void storageBlockingStateChanged();
322 void setDebugger(JSC::Debugger*);
323 JSC::Debugger* debugger() const { return m_debugger; }
325 WEBCORE_EXPORT void invalidateStylesForAllLinks();
326 WEBCORE_EXPORT void invalidateStylesForLink(LinkHash);
328 StorageNamespace* sessionStorage(bool optionalCreate = true);
329 void setSessionStorage(RefPtr<StorageNamespace>&&);
331 bool hasCustomHTMLTokenizerTimeDelay() const;
332 double customHTMLTokenizerTimeDelay() const;
334 WEBCORE_EXPORT void setMemoryCacheClientCallsEnabled(bool);
335 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
337 // Don't allow more than a certain number of frames in a page.
338 // This seems like a reasonable upper bound, and otherwise mutually
339 // recursive frameset pages can quickly bring the program to its knees
340 // with exponential growth in the number of frames.
341 static const int maxNumberOfFrames = 1000;
343 void setEditable(bool isEditable) { m_isEditable = isEditable; }
344 bool isEditable() { return m_isEditable; }
346 WEBCORE_EXPORT PageVisibilityState visibilityState() const;
347 WEBCORE_EXPORT void resumeAnimatingImages();
349 WEBCORE_EXPORT void addLayoutMilestones(LayoutMilestones);
350 WEBCORE_EXPORT void removeLayoutMilestones(LayoutMilestones);
351 LayoutMilestones requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
353 #if ENABLE(RUBBER_BANDING)
354 WEBCORE_EXPORT void addHeaderWithHeight(int);
355 WEBCORE_EXPORT void addFooterWithHeight(int);
358 int headerHeight() const { return m_headerHeight; }
359 int footerHeight() const { return m_footerHeight; }
361 WEBCORE_EXPORT Color pageExtendedBackgroundColor() const;
363 bool isCountingRelevantRepaintedObjects() const;
364 void setIsCountingRelevantRepaintedObjects(bool isCounting) { m_isCountingRelevantRepaintedObjects = isCounting; }
365 void startCountingRelevantRepaintedObjects();
366 void resetRelevantPaintedObjectCounter();
367 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
368 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
370 WEBCORE_EXPORT void suspendActiveDOMObjectsAndAnimations();
371 WEBCORE_EXPORT void resumeActiveDOMObjectsAndAnimations();
373 void setIsPainting(bool painting) { m_isPainting = painting; }
374 bool isPainting() const { return m_isPainting; }
377 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
379 bool hasSeenPlugin(const String& serviceType) const;
380 WEBCORE_EXPORT bool hasSeenAnyPlugin() const;
381 void sawPlugin(const String& serviceType);
382 void resetSeenPlugins();
384 bool hasSeenMediaEngine(const String& engineName) const;
385 bool hasSeenAnyMediaEngine() const;
386 void sawMediaEngine(const String& engineName);
387 void resetSeenMediaEngines();
389 PageThrottler& pageThrottler() { return m_pageThrottler; }
391 PageConsoleClient& console() { return *m_consoleClient; }
393 #if ENABLE(REMOTE_INSPECTOR)
394 PageDebuggable& inspectorDebuggable() const { return *m_inspectorDebuggable.get(); }
397 void hiddenPageCSSAnimationSuspensionStateChanged();
399 #if ENABLE(VIDEO_TRACK)
400 void captionPreferencesChanged();
403 void incrementFrameHandlingBeforeUnloadEventCount();
404 void decrementFrameHandlingBeforeUnloadEventCount();
405 bool isAnyFrameHandlingBeforeUnloadEvent();
406 void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
407 unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
409 ApplicationCacheStorage& applicationCacheStorage() { return m_applicationCacheStorage; }
410 DatabaseProvider& databaseProvider() { return m_databaseProvider; }
412 StorageNamespaceProvider& storageNamespaceProvider() { return m_storageNamespaceProvider.get(); }
413 void setStorageNamespaceProvider(Ref<StorageNamespaceProvider>&&);
415 UserContentController* userContentController() { return m_userContentController.get(); }
416 WEBCORE_EXPORT void setUserContentController(UserContentController*);
418 VisitedLinkStore& visitedLinkStore();
419 WEBCORE_EXPORT void setVisitedLinkStore(Ref<VisitedLinkStore>&&);
421 WEBCORE_EXPORT SessionID sessionID() const;
422 WEBCORE_EXPORT void setSessionID(SessionID);
423 WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
424 bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
426 MediaProducer::MediaStateFlags mediaState() const { return m_mediaState; }
427 void updateIsPlayingMedia();
428 bool isMuted() const { return m_muted; }
429 WEBCORE_EXPORT void setMuted(bool);
431 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
432 void addPlaybackTargetPickerClient(uint64_t);
433 void removePlaybackTargetPickerClient(uint64_t);
434 void showPlaybackTargetPicker(uint64_t, const WebCore::IntPoint&, bool);
435 void playbackTargetPickerClientStateDidChange(uint64_t, MediaProducer::MediaStateFlags);
437 WEBCORE_EXPORT void setPlaybackTarget(uint64_t, Ref<MediaPlaybackTarget>&&);
438 WEBCORE_EXPORT void playbackTargetAvailabilityDidChange(uint64_t, bool);
439 WEBCORE_EXPORT void setShouldPlayToPlaybackTarget(uint64_t, bool);
443 WEBCORE_EXPORT void initGroup();
445 void setIsInWindowInternal(bool);
446 void setIsVisibleInternal(bool);
447 void setIsVisuallyIdleInternal(bool);
450 void checkSubframeCountConsistency() const { }
452 void checkSubframeCountConsistency() const;
455 enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
456 enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
458 unsigned findMatchesForText(const String&, FindOptions, unsigned maxMatchCount, ShouldHighlightMatches, ShouldMarkMatches);
460 MediaCanStartListener* takeAnyMediaCanStartListener();
462 Vector<Ref<PluginViewBase>> pluginViews();
464 void hiddenPageDOMTimerThrottlingStateChanged();
465 void setTimerThrottlingEnabled(bool);
467 const std::unique_ptr<Chrome> m_chrome;
468 const std::unique_ptr<DragCaretController> m_dragCaretController;
470 #if ENABLE(DRAG_SUPPORT)
471 const std::unique_ptr<DragController> m_dragController;
473 const std::unique_ptr<FocusController> m_focusController;
474 #if ENABLE(CONTEXT_MENUS)
475 const std::unique_ptr<ContextMenuController> m_contextMenuController;
477 const std::unique_ptr<UserInputBridge> m_userInputBridge;
478 #if ENABLE(WEB_REPLAY)
479 const std::unique_ptr<ReplayController> m_replayController;
481 const std::unique_ptr<InspectorController> m_inspectorController;
482 #if ENABLE(POINTER_LOCK)
483 const std::unique_ptr<PointerLockController> m_pointerLockController;
485 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
487 const RefPtr<Settings> m_settings;
488 const std::unique_ptr<ProgressTracker> m_progress;
490 const std::unique_ptr<BackForwardController> m_backForwardController;
491 const RefPtr<MainFrame> m_mainFrame;
493 mutable RefPtr<PluginData> m_pluginData;
495 RefPtr<RenderTheme> m_theme;
497 EditorClient& m_editorClient;
498 PlugInClient* m_plugInClient;
499 ValidationMessageClient* m_validationMessageClient;
505 bool m_tabKeyCyclesThroughElements;
506 bool m_defersLoading;
507 unsigned m_defersLoadingCallCount;
509 bool m_inLowQualityInterpolationMode;
510 bool m_areMemoryCacheClientCallsEnabled;
514 float m_pageScaleFactor;
515 float m_zoomedOutPageScaleFactor;
516 float m_deviceScaleFactor;
518 float m_topContentInset;
520 #if ENABLE(IOS_TEXT_AUTOSIZING)
521 float m_textAutosizingWidth;
524 bool m_suppressScrollbarAnimations;
526 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity
527 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity
529 Pagination m_pagination;
531 String m_userStyleSheetPath;
532 mutable String m_userStyleSheet;
533 mutable bool m_didLoadUserStyleSheet;
534 mutable time_t m_userStyleSheetModificationTime;
536 std::unique_ptr<PageGroup> m_singlePageGroup;
539 JSC::Debugger* m_debugger;
541 bool m_canStartMedia;
543 RefPtr<StorageNamespace> m_sessionStorage;
545 #if ENABLE(VIEW_MODE_CSS_MEDIA)
547 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
549 bool m_timerThrottlingEnabled;
553 ViewState::Flags m_viewState;
555 LayoutMilestones m_requestedLayoutMilestones;
560 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
561 Region m_topRelevantPaintedRegion;
562 Region m_bottomRelevantPaintedRegion;
563 Region m_relevantUnpaintedRegion;
564 bool m_isCountingRelevantRepaintedObjects;
568 AlternativeTextClient* m_alternativeTextClient;
570 bool m_scriptedAnimationsSuspended;
571 PageThrottler m_pageThrottler;
572 const std::unique_ptr<PageConsoleClient> m_consoleClient;
574 #if ENABLE(REMOTE_INSPECTOR)
575 const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
578 HashSet<String> m_seenPlugins;
579 HashSet<String> m_seenMediaEngines;
581 unsigned m_lastSpatialNavigationCandidatesCount;
582 unsigned m_framesHandlingBeforeUnloadEvent;
584 Ref<ApplicationCacheStorage> m_applicationCacheStorage;
585 Ref<DatabaseProvider> m_databaseProvider;
586 Ref<StorageNamespaceProvider> m_storageNamespaceProvider;
587 RefPtr<UserContentController> m_userContentController;
588 Ref<VisitedLinkStore> m_visitedLinkStore;
590 HashSet<ViewStateChangeObserver*> m_viewStateChangeObservers;
592 SessionID m_sessionID;
596 MediaProducer::MediaStateFlags m_mediaState { MediaProducer::IsNotPlaying };
599 inline PageGroup& Page::group()
606 } // namespace WebCore