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 "PageThrottler.h"
29 #include "PageVisibilityState.h"
30 #include "Pagination.h"
31 #include "PlatformScreen.h"
33 #include "SessionID.h"
34 #include "Supplementable.h"
35 #include "ViewState.h"
36 #include "ViewportArguments.h"
37 #include <wtf/Forward.h>
38 #include <wtf/HashMap.h>
39 #include <wtf/HashSet.h>
40 #include <wtf/Noncopyable.h>
42 #include <wtf/RefCounted.h>
43 #include <wtf/text/WTFString.h>
46 #include <sys/time.h> // For time_t structure.
50 #include <wtf/SchedulePair.h>
59 class AlternativeTextClient;
60 class BackForwardController;
61 class BackForwardClient;
66 class ContextMenuClient;
67 class ContextMenuController;
69 class DragCaretController;
73 class FocusController;
75 class FrameLoaderClient;
79 class UserInputBridge;
80 class InspectorClient;
81 class InspectorController;
83 class MediaCanStartListener;
85 class PageActivityAssertionToken;
93 class PointerLockController;
94 class ProgressTracker;
95 class ProgressTrackerClient;
99 class ReplayController;
100 class VisibleSelection;
101 class ScrollableArea;
102 class ScrollingCoordinator;
104 class StorageNamespace;
105 class UserContentController;
106 class ValidationMessageClient;
107 class VisitedLinkStore;
109 typedef uint64_t LinkHash;
111 enum FindDirection { FindDirectionForward, FindDirectionBackward };
113 class Page : public Supplementable<Page> {
114 WTF_MAKE_NONCOPYABLE(Page);
115 friend class Settings;
116 friend class PageThrottler;
119 static void updateStyleForAllPagesAfterGlobalChangeInEnvironment();
121 // It is up to the platform to ensure that non-null clients are provided where required.
123 WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
128 AlternativeTextClient* alternativeTextClient;
129 ChromeClient* chromeClient;
130 #if ENABLE(CONTEXT_MENUS)
131 ContextMenuClient* contextMenuClient;
133 EditorClient* editorClient;
134 DragClient* dragClient;
135 InspectorClient* inspectorClient;
136 PlugInClient* plugInClient;
137 ProgressTrackerClient* progressTrackerClient;
138 RefPtr<BackForwardClient> backForwardClient;
139 ValidationMessageClient* validationMessageClient;
140 FrameLoaderClient* loaderClientForMainFrame;
142 RefPtr<VisitedLinkStore> visitedLinkStore;
145 explicit Page(PageClients&);
148 uint64_t renderTreeSize() const;
150 void setNeedsRecalcStyleInAllFrames();
152 RenderTheme& theme() const { return *m_theme; }
154 ViewportArguments viewportArguments() const;
156 static void refreshPlugins(bool reload);
157 PluginData& pluginData() const;
159 void setCanStartMedia(bool);
160 bool canStartMedia() const { return m_canStartMedia; }
162 EditorClient* editorClient() const { return m_editorClient; }
163 PlugInClient* plugInClient() const { return m_plugInClient; }
165 MainFrame& mainFrame() { ASSERT(m_mainFrame); return *m_mainFrame; }
166 const MainFrame& mainFrame() const { ASSERT(m_mainFrame); return *m_mainFrame; }
168 bool openedByDOM() const;
169 void setOpenedByDOM();
171 void goToItem(HistoryItem*, FrameLoadType);
173 void setGroupName(const String&);
174 const String& groupName() const;
177 PageGroup* groupPtr() { return m_group; } // can return 0
179 void incrementSubframeCount() { ++m_subframeCount; }
180 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
181 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
183 #if ENABLE(REMOTE_INSPECTOR)
184 bool remoteInspectionAllowed() const;
185 void setRemoteInspectionAllowed(bool);
186 void remoteInspectorInformationDidChange() const;
189 Chrome& chrome() const { return *m_chrome; }
190 DragCaretController& dragCaretController() const { return *m_dragCaretController; }
191 #if ENABLE(DRAG_SUPPORT)
192 DragController& dragController() const { return *m_dragController; }
194 FocusController& focusController() const { return *m_focusController; }
195 #if ENABLE(CONTEXT_MENUS)
196 ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
198 UserInputBridge& userInputBridge() const { return *m_userInputBridge; }
199 #if ENABLE(WEB_REPLAY)
200 ReplayController& replayController() const { return *m_replayController; }
202 #if ENABLE(INSPECTOR)
203 InspectorController& inspectorController() const { return *m_inspectorController; }
205 #if ENABLE(POINTER_LOCK)
206 PointerLockController* pointerLockController() const { return m_pointerLockController.get(); }
208 ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; }
210 ScrollingCoordinator* scrollingCoordinator();
212 String scrollingStateTreeAsText();
213 String synchronousScrollingReasonsAsText();
214 PassRefPtr<ClientRectList> nonFastScrollableRects(const Frame*);
216 Settings& settings() const { return *m_settings; }
217 ProgressTracker& progress() const { return *m_progress; }
218 BackForwardController& backForward() const { return *m_backForwardController; }
220 #if ENABLE(VIEW_MODE_CSS_MEDIA)
229 static ViewMode stringToViewMode(const String&);
231 ViewMode viewMode() const { return m_viewMode; }
232 void setViewMode(ViewMode);
233 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
235 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
236 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
238 bool findString(const String&, FindOptions);
240 PassRefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
242 unsigned countFindMatches(const String&, FindOptions, unsigned maxMatchCount);
243 unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned maxMatchCount);
245 void unmarkAllTextMatches();
247 // find all the Ranges for the matching text.
248 // Upon return, indexForSelection will be one of the following:
249 // 0 if there is no user selection
250 // the index of the first range after the user selection
251 // NoMatchAfterUserSelection if there is no matching text after the user selection.
252 enum { NoMatchAfterUserSelection = -1 };
253 void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range>>*, int& indexForSelection);
255 void addSchedulePair(PassRefPtr<SchedulePair>);
256 void removeSchedulePair(PassRefPtr<SchedulePair>);
257 SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
259 OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
262 const VisibleSelection& selection() const;
264 void setDefersLoading(bool);
265 bool defersLoading() const { return m_defersLoading; }
267 void clearUndoRedoOperations();
269 bool inLowQualityImageInterpolationMode() const;
270 void setInLowQualityImageInterpolationMode(bool = true);
272 float mediaVolume() const { return m_mediaVolume; }
273 void setMediaVolume(float);
275 void setPageScaleFactor(float scale, const IntPoint& origin);
276 float pageScaleFactor() const { return m_pageScaleFactor; }
278 float deviceScaleFactor() const { return m_deviceScaleFactor; }
279 void setDeviceScaleFactor(float);
281 bool shouldSuppressScrollbarAnimations() const { return m_suppressScrollbarAnimations; }
282 void setShouldSuppressScrollbarAnimations(bool suppressAnimations);
283 void lockAllOverlayScrollbarsToHidden(bool lockOverlayScrollbars);
285 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API,
286 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all
287 // FrameViews in the page cache, but FrameView::pagination() only affects the current
289 const Pagination& pagination() const { return m_pagination; }
290 void setPagination(const Pagination&);
292 unsigned pageCount() const;
294 // Notifications when the Page starts and stops being presented via a native window.
295 void setViewState(ViewState::Flags);
296 void setIsVisible(bool);
297 void setIsPrerender();
298 bool isVisible() const { return m_viewState & ViewState::IsVisible; }
300 // Notification that this Page was moved into or out of a native window.
301 void setIsInWindow(bool);
302 bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
304 void suspendScriptedAnimations();
305 void resumeScriptedAnimations();
306 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
308 void userStyleSheetLocationChanged();
309 const String& userStyleSheet() const;
311 void dnsPrefetchingStateChanged();
312 void storageBlockingStateChanged();
313 void privateBrowsingStateChanged();
315 void setDebugger(JSC::Debugger*);
316 JSC::Debugger* debugger() const { return m_debugger; }
318 static void removeAllVisitedLinks();
320 void invalidateStylesForAllLinks();
321 void invalidateStylesForLink(LinkHash);
323 StorageNamespace* sessionStorage(bool optionalCreate = true);
324 void setSessionStorage(PassRefPtr<StorageNamespace>);
326 bool hasCustomHTMLTokenizerTimeDelay() const;
327 double customHTMLTokenizerTimeDelay() const;
329 void setMemoryCacheClientCallsEnabled(bool);
330 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
332 // Don't allow more than a certain number of frames in a page.
333 // This seems like a reasonable upper bound, and otherwise mutually
334 // recursive frameset pages can quickly bring the program to its knees
335 // with exponential growth in the number of frames.
336 static const int maxNumberOfFrames = 1000;
338 void setEditable(bool isEditable) { m_isEditable = isEditable; }
339 bool isEditable() { return m_isEditable; }
341 #if ENABLE(PAGE_VISIBILITY_API)
342 PageVisibilityState visibilityState() const;
344 void resumeAnimatingImages();
346 void addLayoutMilestones(LayoutMilestones);
347 void removeLayoutMilestones(LayoutMilestones);
348 LayoutMilestones requestedLayoutMilestones() const { return m_requestedLayoutMilestones; }
350 #if ENABLE(RUBBER_BANDING)
351 void addHeaderWithHeight(int);
352 void addFooterWithHeight(int);
355 int headerHeight() const { return m_headerHeight; }
356 int footerHeight() const { return m_footerHeight; }
358 Color pageExtendedBackgroundColor() const;
360 bool isCountingRelevantRepaintedObjects() const;
361 void startCountingRelevantRepaintedObjects();
362 void resetRelevantPaintedObjectCounter();
363 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
364 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
366 void suspendActiveDOMObjectsAndAnimations();
367 void resumeActiveDOMObjectsAndAnimations();
369 void setIsPainting(bool painting) { m_isPainting = painting; }
370 bool isPainting() const { return m_isPainting; }
373 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
375 bool hasSeenPlugin(const String& serviceType) const;
376 bool hasSeenAnyPlugin() const;
377 void sawPlugin(const String& serviceType);
378 void resetSeenPlugins();
380 bool hasSeenMediaEngine(const String& engineName) const;
381 bool hasSeenAnyMediaEngine() const;
382 void sawMediaEngine(const String& engineName);
383 void resetSeenMediaEngines();
385 PageThrottler& pageThrottler() { return m_pageThrottler; }
387 PageConsole& console() { return *m_console; }
389 #if ENABLE(PAGE_VISIBILITY_API)
390 void hiddenPageCSSAnimationSuspensionStateChanged();
393 #if ENABLE(VIDEO_TRACK)
394 void captionPreferencesChanged();
397 void incrementFrameHandlingBeforeUnloadEventCount();
398 void decrementFrameHandlingBeforeUnloadEventCount();
399 bool isAnyFrameHandlingBeforeUnloadEvent();
400 void setLastSpatialNavigationCandidateCount(unsigned count) { m_lastSpatialNavigationCandidatesCount = count; }
401 unsigned lastSpatialNavigationCandidateCount() const { return m_lastSpatialNavigationCandidatesCount; }
403 void setUserContentController(UserContentController*);
404 UserContentController* userContentController() { return m_userContentController.get(); }
406 VisitedLinkStore& visitedLinkStore();
408 SessionID sessionID() const;
409 void setSessionID(SessionID);
410 bool isSessionIDSet() const { return m_sessionID.isValid(); }
415 void setIsInWindowInternal(bool);
416 void setIsVisibleInternal(bool);
417 void setIsVisuallyIdleInternal(bool);
420 void checkSubframeCountConsistency() const { }
422 void checkSubframeCountConsistency() const;
425 enum ShouldHighlightMatches { DoNotHighlightMatches, HighlightMatches };
426 enum ShouldMarkMatches { DoNotMarkMatches, MarkMatches };
428 unsigned findMatchesForText(const String&, FindOptions, unsigned maxMatchCount, ShouldHighlightMatches, ShouldMarkMatches);
430 MediaCanStartListener* takeAnyMediaCanStartListener();
432 void setMinimumTimerInterval(double);
433 double minimumTimerInterval() const;
435 double timerAlignmentInterval() const { return m_timerAlignmentInterval; }
437 Vector<Ref<PluginViewBase>> pluginViews();
439 void setTimerThrottlingEnabled(bool);
441 const std::unique_ptr<Chrome> m_chrome;
442 const std::unique_ptr<DragCaretController> m_dragCaretController;
444 #if ENABLE(DRAG_SUPPORT)
445 const std::unique_ptr<DragController> m_dragController;
447 const std::unique_ptr<FocusController> m_focusController;
448 #if ENABLE(CONTEXT_MENUS)
449 const std::unique_ptr<ContextMenuController> m_contextMenuController;
451 const std::unique_ptr<UserInputBridge> m_userInputBridge;
452 #if ENABLE(WEB_REPLAY)
453 const std::unique_ptr<ReplayController> m_replayController;
455 #if ENABLE(INSPECTOR)
456 const std::unique_ptr<InspectorController> m_inspectorController;
458 #if ENABLE(POINTER_LOCK)
459 OwnPtr<PointerLockController> m_pointerLockController;
461 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
463 const RefPtr<Settings> m_settings;
464 const std::unique_ptr<ProgressTracker> m_progress;
466 const std::unique_ptr<BackForwardController> m_backForwardController;
467 const RefPtr<MainFrame> m_mainFrame;
469 mutable RefPtr<PluginData> m_pluginData;
471 RefPtr<RenderTheme> m_theme;
473 EditorClient* m_editorClient;
474 PlugInClient* m_plugInClient;
475 ValidationMessageClient* m_validationMessageClient;
481 bool m_tabKeyCyclesThroughElements;
482 bool m_defersLoading;
483 unsigned m_defersLoadingCallCount;
485 bool m_inLowQualityInterpolationMode;
486 bool m_areMemoryCacheClientCallsEnabled;
489 float m_pageScaleFactor;
490 float m_deviceScaleFactor;
492 bool m_suppressScrollbarAnimations;
494 Pagination m_pagination;
496 String m_userStyleSheetPath;
497 mutable String m_userStyleSheet;
498 mutable bool m_didLoadUserStyleSheet;
499 mutable time_t m_userStyleSheetModificationTime;
501 std::unique_ptr<PageGroup> m_singlePageGroup;
504 JSC::Debugger* m_debugger;
506 bool m_canStartMedia;
508 RefPtr<StorageNamespace> m_sessionStorage;
510 #if ENABLE(VIEW_MODE_CSS_MEDIA)
512 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
514 double m_minimumTimerInterval;
516 bool m_timerThrottlingEnabled;
517 double m_timerAlignmentInterval;
521 ViewState::Flags m_viewState;
523 LayoutMilestones m_requestedLayoutMilestones;
528 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
529 Region m_topRelevantPaintedRegion;
530 Region m_bottomRelevantPaintedRegion;
531 Region m_relevantUnpaintedRegion;
532 bool m_isCountingRelevantRepaintedObjects;
536 AlternativeTextClient* m_alternativeTextClient;
538 bool m_scriptedAnimationsSuspended;
539 PageThrottler m_pageThrottler;
540 const std::unique_ptr<PageConsole> m_console;
542 #if ENABLE(REMOTE_INSPECTOR)
543 const std::unique_ptr<PageDebuggable> m_inspectorDebuggable;
546 HashSet<String> m_seenPlugins;
547 HashSet<String> m_seenMediaEngines;
549 unsigned m_lastSpatialNavigationCandidatesCount;
550 unsigned m_framesHandlingBeforeUnloadEvent;
552 RefPtr<UserContentController> m_userContentController;
553 RefPtr<VisitedLinkStore> m_visitedLinkStore;
555 SessionID m_sessionID;
558 inline PageGroup& Page::group()
565 } // namespace WebCore