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 "core/dom/ViewportDescription.h"
25 #include "core/frame/LocalFrame.h"
26 #include "core/frame/SettingsDelegate.h"
27 #include "core/frame/UseCounter.h"
28 #include "core/page/PageAnimator.h"
29 #include "core/page/PageVisibilityState.h"
30 #include "platform/LifecycleContext.h"
31 #include "platform/Supplementable.h"
32 #include "platform/geometry/LayoutRect.h"
33 #include "platform/geometry/Region.h"
34 #include "platform/heap/Handle.h"
35 #include "wtf/Forward.h"
36 #include "wtf/HashSet.h"
37 #include "wtf/Noncopyable.h"
38 #include "wtf/text/WTFString.h"
42 class AutoscrollController;
43 class BackForwardClient;
47 class ContextMenuClient;
48 class ContextMenuController;
50 class DragCaretController;
54 class FocusController;
58 class InspectorClient;
59 class InspectorController;
60 class PageLifecycleNotifier;
61 class PlatformMouseEvent;
63 class PointerLockController;
69 class VisibleSelection;
71 class ScrollingCoordinator;
73 class SpellCheckerClient;
74 class StorageNamespace;
76 class ValidationMessageClient;
78 typedef uint64_t LinkHash;
80 float deviceScaleFactor(LocalFrame*);
82 class Page FINAL : public NoBaseWillBeGarbageCollectedFinalized<Page>, public WillBeHeapSupplementable<Page>, public LifecycleContext<Page>, public SettingsDelegate {
83 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Page);
84 WTF_MAKE_NONCOPYABLE(Page);
85 friend class Settings;
87 static void scheduleForcedStyleRecalcForAllPages();
89 // It is up to the platform to ensure that non-null clients are provided where required.
91 WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
96 ChromeClient* chromeClient;
97 ContextMenuClient* contextMenuClient;
98 EditorClient* editorClient;
99 DragClient* dragClient;
100 InspectorClient* inspectorClient;
101 BackForwardClient* backForwardClient;
102 SpellCheckerClient* spellCheckerClient;
103 StorageClient* storageClient;
106 explicit Page(PageClients&);
111 // This method returns all pages, incl. private ones associated with
112 // inspector overlay, popups, SVGImage, etc.
113 static HashSet<Page*>& allPages();
114 // This method returns all ordinary pages.
115 static HashSet<Page*>& ordinaryPages();
117 FrameHost& frameHost() const { return *m_frameHost; }
119 void setNeedsRecalcStyleInAllFrames();
120 void updateAcceleratedCompositingSettings();
122 ViewportDescription viewportDescription() const;
124 static void refreshPlugins(bool reload);
125 PluginData* pluginData() const;
127 EditorClient& editorClient() const { return *m_editorClient; }
128 SpellCheckerClient& spellCheckerClient() const { return *m_spellCheckerClient; }
129 UndoStack& undoStack() const { return *m_undoStack; }
131 void setMainFrame(Frame*);
132 Frame* mainFrame() const { return m_mainFrame; }
133 // Escape hatch for existing code that assumes that the root frame is
134 // always a LocalFrame. With OOPI, this is not always the case. Code that
135 // depends on this will generally have to be rewritten to propagate any
136 // necessary state through all renderer processes for that page and/or
137 // coordinate/rely on the browser process to help dispatch/coordinate work.
138 LocalFrame* deprecatedLocalMainFrame() const { return toLocalFrame(m_mainFrame); }
140 void documentDetached(Document*);
142 bool openedByDOM() const;
143 void setOpenedByDOM();
145 void incrementSubframeCount() { ++m_subframeCount; }
146 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
147 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
149 PageAnimator& animator() { return m_animator; }
150 Chrome& chrome() const { return *m_chrome; }
151 AutoscrollController& autoscrollController() const { return *m_autoscrollController; }
152 DragCaretController& dragCaretController() const { return *m_dragCaretController; }
153 DragController& dragController() const { return *m_dragController; }
154 FocusController& focusController() const { return *m_focusController; }
155 ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
156 InspectorController& inspectorController() const { return *m_inspectorController; }
157 PointerLockController& pointerLockController() const { return *m_pointerLockController; }
158 ValidationMessageClient& validationMessageClient() const { return *m_validationMessageClient; }
159 void setValidationMessageClient(PassOwnPtrWillBeRawPtr<ValidationMessageClient>);
161 ScrollingCoordinator* scrollingCoordinator();
163 String mainThreadScrollingReasonsAsText();
164 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(const LocalFrame*);
166 Settings& settings() const { return *m_settings; }
167 BackForwardClient& backForward() const { return *m_backForwardClient; }
169 UseCounter& useCounter() { return m_useCounter; }
171 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
172 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
174 void unmarkAllTextMatches();
176 // DefersLoading is used to delay loads during modal dialogs.
177 // Modal dialogs are supposed to freeze all background processes
178 // in the page, including prevent additional loads from staring/continuing.
179 void setDefersLoading(bool);
180 bool defersLoading() const { return m_defersLoading; }
182 void setPageScaleFactor(float scale, const IntPoint& origin);
183 float pageScaleFactor() const;
185 float deviceScaleFactor() const { return m_deviceScaleFactor; }
186 void setDeviceScaleFactor(float);
188 static void allVisitedStateChanged();
189 static void visitedStateChanged(LinkHash visitedHash);
191 StorageNamespace* sessionStorage(bool optionalCreate = true);
192 StorageClient& storageClient() const { return *m_storageClient; }
194 // Don't allow more than a certain number of frames in a page.
195 // This seems like a reasonable upper bound, and otherwise mutually
196 // recursive frameset pages can quickly bring the program to its knees
197 // with exponential growth in the number of frames.
198 static const int maxNumberOfFrames = 1000;
200 PageVisibilityState visibilityState() const;
201 void setVisibilityState(PageVisibilityState, bool);
203 bool isCursorVisible() const;
204 void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; }
207 void setIsPainting(bool painting) { m_isPainting = painting; }
208 bool isPainting() const { return m_isPainting; }
211 double timerAlignmentInterval() const;
213 class MultisamplingChangedObserver : public WillBeGarbageCollectedMixin {
215 virtual void multisamplingChanged(bool) = 0;
218 void addMultisamplingChangedObserver(MultisamplingChangedObserver*);
219 void removeMultisamplingChangedObserver(MultisamplingChangedObserver*);
221 void didCommitLoad(LocalFrame*);
223 void acceptLanguagesChanged();
225 static void networkStateChanged(bool online);
226 PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier();
228 void trace(Visitor*);
229 void willBeDestroyed();
232 PageLifecycleNotifier& lifecycleNotifier();
238 void checkSubframeCountConsistency() const;
240 void checkSubframeCountConsistency() const { }
243 void setTimerAlignmentInterval(double);
245 void setNeedsLayoutInAllFrames();
247 // SettingsDelegate overrides.
248 virtual void settingsChanged(SettingsDelegate::ChangeType) OVERRIDE;
250 PageAnimator m_animator;
251 const OwnPtr<AutoscrollController> m_autoscrollController;
252 const OwnPtr<Chrome> m_chrome;
253 const OwnPtrWillBeMember<DragCaretController> m_dragCaretController;
254 const OwnPtrWillBeMember<DragController> m_dragController;
255 const OwnPtr<FocusController> m_focusController;
256 const OwnPtr<ContextMenuController> m_contextMenuController;
257 const OwnPtr<InspectorController> m_inspectorController;
258 const OwnPtrWillBeMember<PointerLockController> m_pointerLockController;
259 OwnPtr<ScrollingCoordinator> m_scrollingCoordinator;
260 const OwnPtrWillBeMember<UndoStack> m_undoStack;
262 // Typically, the main frame and Page should both be owned by the embedder,
263 // which must call Page::willBeDestroyed() prior to destroying Page. This
264 // call detaches the main frame and clears this pointer, thus ensuring that
265 // this field only references a live main frame.
267 // However, there are several locations (InspectorOverlay, SVGImage, and
268 // WebPagePopupImpl) which don't hold a reference to the main frame at all
269 // after creating it. These are still safe because they always create a
270 // Frame with a FrameView. FrameView and Frame hold references to each
271 // other, thus keeping each other alive. The call to willBeDestroyed()
272 // breaks this cycle, so the frame is still properly destroyed once no
276 mutable RefPtr<PluginData> m_pluginData;
278 BackForwardClient* m_backForwardClient;
279 EditorClient* const m_editorClient;
280 SpellCheckerClient* const m_spellCheckerClient;
281 StorageClient* m_storageClient;
282 OwnPtrWillBeMember<ValidationMessageClient> m_validationMessageClient;
284 UseCounter m_useCounter;
289 bool m_tabKeyCyclesThroughElements;
290 bool m_defersLoading;
292 float m_deviceScaleFactor;
294 OwnPtr<StorageNamespace> m_sessionStorage;
296 double m_timerAlignmentInterval;
298 PageVisibilityState m_visibilityState;
300 bool m_isCursorVisible;
306 WillBeHeapHashSet<RawPtrWillBeWeakMember<MultisamplingChangedObserver> > m_multisamplingChangedObservers;
308 // A pointer to all the interfaces provided to in-process Frames for this Page.
309 // FIXME: Most of the members of Page should move onto FrameHost.
310 OwnPtrWillBeMember<FrameHost> m_frameHost;
313 } // namespace WebCore