• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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/)
4  *
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.
9  *
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.
14  *
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.
19  */
20 
21 #ifndef Page_h
22 #define Page_h
23 
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"
39 
40 namespace blink {
41 
42 class AutoscrollController;
43 class BackForwardClient;
44 class Chrome;
45 class ChromeClient;
46 class ClientRectList;
47 class ContextMenuClient;
48 class ContextMenuController;
49 class Document;
50 class DragCaretController;
51 class DragClient;
52 class DragController;
53 class EditorClient;
54 class FocusController;
55 class Frame;
56 class FrameHost;
57 class InspectorClient;
58 class InspectorController;
59 class PageLifecycleNotifier;
60 class PluginData;
61 class PointerLockController;
62 class StorageClient;
63 class ScrollingCoordinator;
64 class Settings;
65 class SpellCheckerClient;
66 class StorageNamespace;
67 class UndoStack;
68 class ValidationMessageClient;
69 
70 typedef uint64_t LinkHash;
71 
72 float deviceScaleFactor(LocalFrame*);
73 
74 class Page FINAL : public NoBaseWillBeGarbageCollectedFinalized<Page>, public WillBeHeapSupplementable<Page>, public LifecycleContext<Page>, public SettingsDelegate {
75     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Page);
76     WTF_MAKE_NONCOPYABLE(Page);
77     friend class Settings;
78 public:
79     static void scheduleForcedStyleRecalcForAllPages();
80 
81     // It is up to the platform to ensure that non-null clients are provided where required.
82     struct PageClients {
83         WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
84     public:
85         PageClients();
86         ~PageClients();
87 
88         ChromeClient* chromeClient;
89         ContextMenuClient* contextMenuClient;
90         EditorClient* editorClient;
91         DragClient* dragClient;
92         InspectorClient* inspectorClient;
93         BackForwardClient* backForwardClient;
94         SpellCheckerClient* spellCheckerClient;
95         StorageClient* storageClient;
96     };
97 
98     explicit Page(PageClients&);
99     virtual ~Page();
100 
101     void makeOrdinary();
102 
103     // This method returns all pages, incl. private ones associated with
104     // inspector overlay, popups, SVGImage, etc.
105     static HashSet<Page*>& allPages();
106     // This method returns all ordinary pages.
107     static HashSet<Page*>& ordinaryPages();
108 
frameHost()109     FrameHost& frameHost() const { return *m_frameHost; }
110 
111     void setNeedsRecalcStyleInAllFrames();
112     void updateAcceleratedCompositingSettings();
113 
114     ViewportDescription viewportDescription() const;
115 
116     static void refreshPlugins(bool reload);
117     PluginData* pluginData() const;
118 
editorClient()119     EditorClient& editorClient() const { return *m_editorClient; }
spellCheckerClient()120     SpellCheckerClient& spellCheckerClient() const { return *m_spellCheckerClient; }
undoStack()121     UndoStack& undoStack() const { return *m_undoStack; }
122 
123     void setMainFrame(Frame*);
mainFrame()124     Frame* mainFrame() const { return m_mainFrame; }
125     // Escape hatch for existing code that assumes that the root frame is
126     // always a LocalFrame. With OOPI, this is not always the case. Code that
127     // depends on this will generally have to be rewritten to propagate any
128     // necessary state through all renderer processes for that page and/or
129     // coordinate/rely on the browser process to help dispatch/coordinate work.
deprecatedLocalMainFrame()130     LocalFrame* deprecatedLocalMainFrame() const { return toLocalFrame(m_mainFrame); }
131 
132     void documentDetached(Document*);
133 
134     bool openedByDOM() const;
135     void setOpenedByDOM();
136 
incrementSubframeCount()137     void incrementSubframeCount() { ++m_subframeCount; }
decrementSubframeCount()138     void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
subframeCount()139     int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
140 
animator()141     PageAnimator& animator() { return *m_animator; }
chrome()142     Chrome& chrome() const { return *m_chrome; }
autoscrollController()143     AutoscrollController& autoscrollController() const { return *m_autoscrollController; }
dragCaretController()144     DragCaretController& dragCaretController() const { return *m_dragCaretController; }
dragController()145     DragController& dragController() const { return *m_dragController; }
focusController()146     FocusController& focusController() const { return *m_focusController; }
contextMenuController()147     ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
inspectorController()148     InspectorController& inspectorController() const { return *m_inspectorController; }
pointerLockController()149     PointerLockController& pointerLockController() const { return *m_pointerLockController; }
validationMessageClient()150     ValidationMessageClient& validationMessageClient() const { return *m_validationMessageClient; }
151     void setValidationMessageClient(PassOwnPtrWillBeRawPtr<ValidationMessageClient>);
152 
153     ScrollingCoordinator* scrollingCoordinator();
154 
155     String mainThreadScrollingReasonsAsText();
156     PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(const LocalFrame*);
157 
settings()158     Settings& settings() const { return *m_settings; }
backForward()159     BackForwardClient& backForward() const { return *m_backForwardClient; }
160 
useCounter()161     UseCounter& useCounter() { return m_useCounter; }
162 
setTabKeyCyclesThroughElements(bool b)163     void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
tabKeyCyclesThroughElements()164     bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
165 
166     void unmarkAllTextMatches();
167 
168     // DefersLoading is used to delay loads during modal dialogs.
169     // Modal dialogs are supposed to freeze all background processes
170     // in the page, including prevent additional loads from staring/continuing.
171     void setDefersLoading(bool);
defersLoading()172     bool defersLoading() const { return m_defersLoading; }
173 
174     void setPageScaleFactor(float scale, const IntPoint& origin);
175     float pageScaleFactor() const;
176 
deviceScaleFactor()177     float deviceScaleFactor() const { return m_deviceScaleFactor; }
178     void setDeviceScaleFactor(float);
179     void setDeviceColorProfile(const Vector<char>&);
180     void resetDeviceColorProfile();
181 
182     static void allVisitedStateChanged();
183     static void visitedStateChanged(LinkHash visitedHash);
184 
185     StorageNamespace* sessionStorage(bool optionalCreate = true);
storageClient()186     StorageClient& storageClient() const { return *m_storageClient; }
187 
188     // Don't allow more than a certain number of frames in a page.
189     // This seems like a reasonable upper bound, and otherwise mutually
190     // recursive frameset pages can quickly bring the program to its knees
191     // with exponential growth in the number of frames.
192     static const int maxNumberOfFrames = 1000;
193 
194     PageVisibilityState visibilityState() const;
195     void setVisibilityState(PageVisibilityState, bool);
196 
197     bool isCursorVisible() const;
setIsCursorVisible(bool isVisible)198     void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; }
199 
200 #if ENABLE(ASSERT)
setIsPainting(bool painting)201     void setIsPainting(bool painting) { m_isPainting = painting; }
isPainting()202     bool isPainting() const { return m_isPainting; }
203 #endif
204 
205     double timerAlignmentInterval() const;
206 
207     class MultisamplingChangedObserver : public WillBeGarbageCollectedMixin {
208     public:
209         virtual void multisamplingChanged(bool) = 0;
210     };
211 
212     void addMultisamplingChangedObserver(MultisamplingChangedObserver*);
213     void removeMultisamplingChangedObserver(MultisamplingChangedObserver*);
214 
215     void didCommitLoad(LocalFrame*);
216 
217     void acceptLanguagesChanged();
218 
219     static void networkStateChanged(bool online);
220     PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier();
221 
222     void trace(Visitor*);
223     void willBeDestroyed();
224 
225 protected:
226     PageLifecycleNotifier& lifecycleNotifier();
227 
228 private:
229     void initGroup();
230 
231 #if ENABLE(ASSERT)
232     void checkSubframeCountConsistency() const;
233 #else
checkSubframeCountConsistency()234     void checkSubframeCountConsistency() const { }
235 #endif
236 
237     void setTimerAlignmentInterval(double);
238 
239     void setNeedsLayoutInAllFrames();
240 
241     // SettingsDelegate overrides.
242     virtual void settingsChanged(SettingsDelegate::ChangeType) OVERRIDE;
243 
244     RefPtrWillBeMember<PageAnimator> m_animator;
245     const OwnPtr<AutoscrollController> m_autoscrollController;
246     const OwnPtr<Chrome> m_chrome;
247     const OwnPtrWillBeMember<DragCaretController> m_dragCaretController;
248     const OwnPtrWillBeMember<DragController> m_dragController;
249     const OwnPtrWillBeMember<FocusController> m_focusController;
250     const OwnPtrWillBeMember<ContextMenuController> m_contextMenuController;
251     const OwnPtrWillBeMember<InspectorController> m_inspectorController;
252     const OwnPtrWillBeMember<PointerLockController> m_pointerLockController;
253     OwnPtr<ScrollingCoordinator> m_scrollingCoordinator;
254     const OwnPtrWillBeMember<UndoStack> m_undoStack;
255 
256     // Typically, the main frame and Page should both be owned by the embedder,
257     // which must call Page::willBeDestroyed() prior to destroying Page. This
258     // call detaches the main frame and clears this pointer, thus ensuring that
259     // this field only references a live main frame.
260     //
261     // However, there are several locations (InspectorOverlay, SVGImage, and
262     // WebPagePopupImpl) which don't hold a reference to the main frame at all
263     // after creating it. These are still safe because they always create a
264     // Frame with a FrameView. FrameView and Frame hold references to each
265     // other, thus keeping each other alive. The call to willBeDestroyed()
266     // breaks this cycle, so the frame is still properly destroyed once no
267     // longer needed.
268     RawPtrWillBeMember<Frame> m_mainFrame;
269 
270     mutable RefPtr<PluginData> m_pluginData;
271 
272     BackForwardClient* m_backForwardClient;
273     EditorClient* const m_editorClient;
274     SpellCheckerClient* const m_spellCheckerClient;
275     StorageClient* m_storageClient;
276     OwnPtrWillBeMember<ValidationMessageClient> m_validationMessageClient;
277 
278     UseCounter m_useCounter;
279 
280     int m_subframeCount;
281     bool m_openedByDOM;
282 
283     bool m_tabKeyCyclesThroughElements;
284     bool m_defersLoading;
285 
286     float m_deviceScaleFactor;
287 
288     OwnPtr<StorageNamespace> m_sessionStorage;
289 
290     double m_timerAlignmentInterval;
291 
292     PageVisibilityState m_visibilityState;
293 
294     bool m_isCursorVisible;
295 
296 #if ENABLE(ASSERT)
297     bool m_isPainting;
298 #endif
299 
300     WillBeHeapHashSet<RawPtrWillBeWeakMember<MultisamplingChangedObserver> > m_multisamplingChangedObservers;
301 
302     // A pointer to all the interfaces provided to in-process Frames for this Page.
303     // FIXME: Most of the members of Page should move onto FrameHost.
304     OwnPtrWillBeMember<FrameHost> m_frameHost;
305 };
306 
307 } // namespace blink
308 
309 #endif // Page_h
310