2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 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 "FeatureObserver.h"
25 #include "FrameLoaderTypes.h"
26 #include "FindOptions.h"
27 #include "LayoutTypes.h"
28 #include "PageVisibilityState.h"
29 #include "PlatformScreen.h"
30 #include "PlatformString.h"
32 #include "Supplementable.h"
33 #include "ViewportArguments.h"
34 #include <wtf/Forward.h>
35 #include <wtf/HashMap.h>
36 #include <wtf/HashSet.h>
37 #include <wtf/Noncopyable.h>
40 #include <sys/time.h> // For time_t structure.
44 #include "SchedulePair.h"
53 class AlternativeTextClient;
54 class BackForwardController;
55 class BackForwardList;
58 #if ENABLE(CONTEXT_MENUS)
59 class ContextMenuClient;
60 class ContextMenuController;
63 class DragCaretController;
67 class FocusController;
72 class InspectorClient;
73 class InspectorController;
74 class MediaCanStartListener;
78 class PointerLockController;
79 class ProgressTracker;
83 class VisibleSelection;
85 class ScrollingCoordinator;
87 class StorageNamespace;
89 typedef uint64_t LinkHash;
91 enum FindDirection { FindDirectionForward, FindDirectionBackward };
93 float deviceScaleFactor(Frame*);
96 ArenaSize(size_t treeSize, size_t allocated)
98 , allocated(allocated)
105 class Page : public Supplementable<Page> {
106 WTF_MAKE_NONCOPYABLE(Page);
107 friend class Settings;
109 static void scheduleForcedStyleRecalcForAllPages();
111 // It is up to the platform to ensure that non-null clients are provided where required.
113 WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
118 AlternativeTextClient* alternativeTextClient;
119 ChromeClient* chromeClient;
120 #if ENABLE(CONTEXT_MENUS)
121 ContextMenuClient* contextMenuClient;
123 EditorClient* editorClient;
124 DragClient* dragClient;
125 InspectorClient* inspectorClient;
126 RefPtr<BackForwardList> backForwardClient;
129 explicit Page(PageClients&);
132 ArenaSize renderTreeSize() const;
134 void setNeedsRecalcStyleInAllFrames();
136 RenderTheme* theme() const { return m_theme.get(); };
138 ViewportArguments viewportArguments() const;
140 static void refreshPlugins(bool reload);
141 PluginData* pluginData() const;
143 void setCanStartMedia(bool);
144 bool canStartMedia() const { return m_canStartMedia; }
146 EditorClient* editorClient() const { return m_editorClient; }
148 void setMainFrame(PassRefPtr<Frame>);
149 Frame* mainFrame() const { return m_mainFrame.get(); }
151 bool openedByDOM() const;
152 void setOpenedByDOM();
154 // DEPRECATED. Use backForward() instead of the following 6 functions.
155 BackForwardList* backForwardList() const;
158 bool canGoBackOrForward(int distance) const;
159 void goBackOrForward(int distance);
160 int getHistoryLength();
162 void goToItem(HistoryItem*, FrameLoadType);
164 void setGroupName(const String&);
165 const String& groupName() const;
167 PageGroup& group() { if (!m_group) initGroup(); return *m_group; }
168 PageGroup* groupPtr() { return m_group; } // can return 0
170 void incrementFrameCount() { ++m_frameCount; }
171 void decrementFrameCount() { ASSERT(m_frameCount); --m_frameCount; }
172 int frameCount() const { checkFrameCountConsistency(); return m_frameCount; }
174 Chrome* chrome() const { return m_chrome.get(); }
175 DragCaretController* dragCaretController() const { return m_dragCaretController.get(); }
176 #if ENABLE(DRAG_SUPPORT)
177 DragController* dragController() const { return m_dragController.get(); }
179 FocusController* focusController() const { return m_focusController.get(); }
180 #if ENABLE(CONTEXT_MENUS)
181 ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
183 #if ENABLE(INSPECTOR)
184 InspectorController* inspectorController() const { return m_inspectorController.get(); }
186 #if ENABLE(POINTER_LOCK)
187 PointerLockController* pointerLockController() const { return m_pointerLockController.get(); }
189 ScrollingCoordinator* scrollingCoordinator();
191 Settings* settings() const { return m_settings.get(); }
192 ProgressTracker* progress() const { return m_progress.get(); }
193 BackForwardController* backForward() const { return m_backForwardController.get(); }
195 FeatureObserver* featureObserver() { return &m_featureObserver; }
205 static ViewMode stringToViewMode(const String&);
207 ViewMode viewMode() const { return m_viewMode; }
208 void setViewMode(ViewMode);
210 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
211 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
213 bool findString(const String&, FindOptions);
214 // FIXME: Switch callers over to the FindOptions version and retire this one.
215 bool findString(const String&, TextCaseSensitivity, FindDirection, bool shouldWrap);
217 PassRefPtr<Range> rangeOfString(const String&, Range*, FindOptions);
219 unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned);
220 // FIXME: Switch callers over to the FindOptions version and retire this one.
221 unsigned markAllMatchesForText(const String&, TextCaseSensitivity, bool shouldHighlight, unsigned);
222 void unmarkAllTextMatches();
224 // find all the Ranges for the matching text.
225 // Upon return, indexForSelection will be one of the following:
226 // 0 if there is no user selection
227 // the index of the first range after the user selection
228 // NoMatchBeforeUserSelection if there is no matching text after the user selection.
229 enum { NoMatchBeforeUserSelection = -1 };
230 void findStringMatchingRanges(const String&, FindOptions, int maxCount, Vector<RefPtr<Range> >*, int& indexForSelection);
232 void addSchedulePair(PassRefPtr<SchedulePair>);
233 void removeSchedulePair(PassRefPtr<SchedulePair>);
234 SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
236 OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
239 const VisibleSelection& selection() const;
241 void setDefersLoading(bool);
242 bool defersLoading() const { return m_defersLoading; }
244 void clearUndoRedoOperations();
246 bool inLowQualityImageInterpolationMode() const;
247 void setInLowQualityImageInterpolationMode(bool = true);
249 float mediaVolume() const { return m_mediaVolume; }
250 void setMediaVolume(float volume);
252 void setPageScaleFactor(float scale, const IntPoint& origin);
253 float pageScaleFactor() const { return m_pageScaleFactor; }
255 float deviceScaleFactor() const { return m_deviceScaleFactor; }
256 void setDeviceScaleFactor(float);
259 enum Mode { Unpaginated, LeftToRightPaginated, RightToLeftPaginated, TopToBottomPaginated, BottomToTopPaginated };
263 , behavesLikeColumns(false)
269 bool operator==(const Pagination& other) const
271 return mode == other.mode && behavesLikeColumns == other.behavesLikeColumns && pageLength == other.pageLength && gap == other.gap;
275 bool behavesLikeColumns;
280 const Pagination& pagination() const { return m_pagination; }
281 void setPagination(const Pagination&);
283 unsigned pageCount() const;
285 // Notifications when the Page starts and stops being presented via a native window.
286 void didMoveOnscreen();
287 void willMoveOffscreen();
288 bool isOnscreen() const { return m_isOnscreen; }
290 void windowScreenDidChange(PlatformDisplayID);
292 void suspendScriptedAnimations();
293 void resumeScriptedAnimations();
294 bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
296 void userStyleSheetLocationChanged();
297 const String& userStyleSheet() const;
299 void dnsPrefetchingStateChanged();
300 void privateBrowsingStateChanged();
302 static void setDebuggerForAllPages(JSC::Debugger*);
303 void setDebugger(JSC::Debugger*);
304 JSC::Debugger* debugger() const { return m_debugger; }
306 static void removeAllVisitedLinks();
308 static void allVisitedStateChanged(PageGroup*);
309 static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
311 StorageNamespace* sessionStorage(bool optionalCreate = true);
312 void setSessionStorage(PassRefPtr<StorageNamespace>);
314 void setCustomHTMLTokenizerTimeDelay(double);
315 bool hasCustomHTMLTokenizerTimeDelay() const { return m_customHTMLTokenizerTimeDelay != -1; }
316 double customHTMLTokenizerTimeDelay() const { ASSERT(m_customHTMLTokenizerTimeDelay != -1); return m_customHTMLTokenizerTimeDelay; }
318 void setCustomHTMLTokenizerChunkSize(int);
319 bool hasCustomHTMLTokenizerChunkSize() const { return m_customHTMLTokenizerChunkSize != -1; }
320 int customHTMLTokenizerChunkSize() const { ASSERT(m_customHTMLTokenizerChunkSize != -1); return m_customHTMLTokenizerChunkSize; }
322 void setMemoryCacheClientCallsEnabled(bool);
323 bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
325 void setJavaScriptURLsAreAllowed(bool);
326 bool javaScriptURLsAreAllowed() const;
328 // Don't allow more than a certain number of frames in a page.
329 // This seems like a reasonable upper bound, and otherwise mutually
330 // recursive frameset pages can quickly bring the program to its knees
331 // with exponential growth in the number of frames.
332 static const int maxNumberOfFrames = 1000;
334 void setEditable(bool isEditable) { m_isEditable = isEditable; }
335 bool isEditable() { return m_isEditable; }
337 #if ENABLE(PAGE_VISIBILITY_API)
338 PageVisibilityState visibilityState() const;
339 void setVisibilityState(PageVisibilityState, bool);
342 PlatformDisplayID displayID() const { return m_displayID; }
344 bool isCountingRelevantRepaintedObjects() const;
345 void setRelevantRepaintedObjectsCounterThreshold(uint64_t);
346 void startCountingRelevantRepaintedObjects();
347 void resetRelevantPaintedObjectCounter();
348 void addRelevantRepaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
349 void addRelevantUnpaintedObject(RenderObject*, const LayoutRect& objectPaintRect);
351 void suspendActiveDOMObjectsAndAnimations();
352 void resumeActiveDOMObjectsAndAnimations();
354 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
355 bool m_recordingSurfaceSetEnable;
356 bool recordingSurfaceSetEnableGet() { return m_recordingSurfaceSetEnable; }
360 void setIsPainting(bool painting) { m_isPainting = painting; }
361 bool isPainting() const { return m_isPainting; }
364 AlternativeTextClient* alternativeTextClient() const { return m_alternativeTextClient; }
366 bool hasSeenPlugin(const String& serviceType) const;
367 bool hasSeenAnyPlugin() const;
368 void sawPlugin(const String& serviceType);
369 void resetSeenPlugins();
375 void checkFrameCountConsistency() const { }
377 void checkFrameCountConsistency() const;
380 MediaCanStartListener* takeAnyMediaCanStartListener();
382 void setMinimumTimerInterval(double);
383 double minimumTimerInterval() const;
385 OwnPtr<Chrome> m_chrome;
386 OwnPtr<DragCaretController> m_dragCaretController;
388 #if ENABLE(DRAG_SUPPORT)
389 OwnPtr<DragController> m_dragController;
391 OwnPtr<FocusController> m_focusController;
392 #if ENABLE(CONTEXT_MENUS)
393 OwnPtr<ContextMenuController> m_contextMenuController;
395 #if ENABLE(INSPECTOR)
396 OwnPtr<InspectorController> m_inspectorController;
398 #if ENABLE(POINTER_LOCK)
399 OwnPtr<PointerLockController> m_pointerLockController;
402 RefPtr<ScrollingCoordinator> m_scrollingCoordinator;
404 OwnPtr<Settings> m_settings;
405 OwnPtr<ProgressTracker> m_progress;
407 OwnPtr<BackForwardController> m_backForwardController;
408 RefPtr<Frame> m_mainFrame;
410 mutable RefPtr<PluginData> m_pluginData;
412 RefPtr<RenderTheme> m_theme;
414 EditorClient* m_editorClient;
416 FeatureObserver m_featureObserver;
422 bool m_tabKeyCyclesThroughElements;
423 bool m_defersLoading;
424 unsigned m_defersLoadingCallCount;
426 bool m_inLowQualityInterpolationMode;
427 bool m_cookieEnabled;
428 bool m_areMemoryCacheClientCallsEnabled;
431 float m_pageScaleFactor;
432 float m_deviceScaleFactor;
434 Pagination m_pagination;
436 bool m_javaScriptURLsAreAllowed;
438 String m_userStyleSheetPath;
439 mutable String m_userStyleSheet;
440 mutable bool m_didLoadUserStyleSheet;
441 mutable time_t m_userStyleSheetModificationTime;
443 OwnPtr<PageGroup> m_singlePageGroup;
446 JSC::Debugger* m_debugger;
448 double m_customHTMLTokenizerTimeDelay;
449 int m_customHTMLTokenizerChunkSize;
451 bool m_canStartMedia;
453 RefPtr<StorageNamespace> m_sessionStorage;
457 double m_minimumTimerInterval;
462 #if ENABLE(PAGE_VISIBILITY_API)
463 PageVisibilityState m_visibilityState;
465 PlatformDisplayID m_displayID;
467 HashSet<RenderObject*> m_relevantUnpaintedRenderObjects;
468 Region m_relevantPaintedRegion;
469 Region m_relevantUnpaintedRegion;
470 bool m_isCountingRelevantRepaintedObjects;
474 AlternativeTextClient* m_alternativeTextClient;
476 bool m_scriptedAnimationsSuspended;
478 HashSet<String> m_seenPlugins;
481 } // namespace WebCore