Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / Page.h
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/SettingsDelegate.h"
26 #include "core/frame/UseCounter.h"
27 #include "core/page/PageAnimator.h"
28 #include "core/page/PageVisibilityState.h"
29 #include "platform/LifecycleContext.h"
30 #include "platform/Supplementable.h"
31 #include "platform/geometry/LayoutRect.h"
32 #include "platform/geometry/Region.h"
33 #include "platform/heap/Handle.h"
34 #include "wtf/Forward.h"
35 #include "wtf/HashSet.h"
36 #include "wtf/Noncopyable.h"
37 #include "wtf/text/WTFString.h"
38
39 namespace WebCore {
40
41 class AutoscrollController;
42 class BackForwardClient;
43 class Chrome;
44 class ChromeClient;
45 class ClientRectList;
46 class ContextMenuClient;
47 class ContextMenuController;
48 class Document;
49 class DragCaretController;
50 class DragClient;
51 class DragController;
52 class EditorClient;
53 class FocusController;
54 class LocalFrame;
55 class FrameHost;
56 class HistoryItem;
57 class InspectorClient;
58 class InspectorController;
59 class PageLifecycleNotifier;
60 class PlatformMouseEvent;
61 class PluginData;
62 class PointerLockController;
63 class Range;
64 class RenderBox;
65 class RenderObject;
66 class RenderTheme;
67 class StorageClient;
68 class VisibleSelection;
69 class ScrollableArea;
70 class ScrollingCoordinator;
71 class Settings;
72 class SpellCheckerClient;
73 class StorageNamespace;
74 class UndoStack;
75 class ValidationMessageClient;
76
77 typedef uint64_t LinkHash;
78
79 float deviceScaleFactor(LocalFrame*);
80
81 class Page FINAL : public NoBaseWillBeGarbageCollectedFinalized<Page>, public WillBeHeapSupplementable<Page>, public LifecycleContext<Page>, public SettingsDelegate {
82     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Page);
83     WTF_MAKE_NONCOPYABLE(Page);
84     friend class Settings;
85 public:
86     static void scheduleForcedStyleRecalcForAllPages();
87
88     // It is up to the platform to ensure that non-null clients are provided where required.
89     struct PageClients {
90         WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
91     public:
92         PageClients();
93         ~PageClients();
94
95         ChromeClient* chromeClient;
96         ContextMenuClient* contextMenuClient;
97         EditorClient* editorClient;
98         DragClient* dragClient;
99         InspectorClient* inspectorClient;
100         BackForwardClient* backForwardClient;
101         SpellCheckerClient* spellCheckerClient;
102         StorageClient* storageClient;
103     };
104
105     explicit Page(PageClients&);
106     virtual ~Page();
107
108     void makeOrdinary();
109
110     // This method returns all pages, incl. private ones associated with
111     // inspector overlay, popups, SVGImage, etc.
112     static HashSet<Page*>& allPages();
113     // This method returns all ordinary pages.
114     static HashSet<Page*>& ordinaryPages();
115
116     FrameHost& frameHost() const { return *m_frameHost; }
117
118     void setNeedsRecalcStyleInAllFrames();
119     void updateAcceleratedCompositingSettings();
120
121     ViewportDescription viewportDescription() const;
122
123     static void refreshPlugins(bool reload);
124     PluginData* pluginData() const;
125
126     EditorClient& editorClient() const { return *m_editorClient; }
127     SpellCheckerClient& spellCheckerClient() const { return *m_spellCheckerClient; }
128     UndoStack& undoStack() const { return *m_undoStack; }
129
130     void setMainFrame(PassRefPtr<LocalFrame>);
131     LocalFrame* mainFrame() const { return m_mainFrame.get(); }
132
133     void documentDetached(Document*);
134
135     bool openedByDOM() const;
136     void setOpenedByDOM();
137
138     void incrementSubframeCount() { ++m_subframeCount; }
139     void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; }
140     int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; }
141
142     PageAnimator& animator() { return m_animator; }
143     Chrome& chrome() const { return *m_chrome; }
144     AutoscrollController& autoscrollController() const { return *m_autoscrollController; }
145     DragCaretController& dragCaretController() const { return *m_dragCaretController; }
146     DragController& dragController() const { return *m_dragController; }
147     FocusController& focusController() const { return *m_focusController; }
148     ContextMenuController& contextMenuController() const { return *m_contextMenuController; }
149     InspectorController& inspectorController() const { return *m_inspectorController; }
150     PointerLockController& pointerLockController() const { return *m_pointerLockController; }
151     ValidationMessageClient& validationMessageClient() const { return *m_validationMessageClient; }
152     void setValidationMessageClient(PassOwnPtr<ValidationMessageClient>);
153
154     ScrollingCoordinator* scrollingCoordinator();
155
156     String mainThreadScrollingReasonsAsText();
157     PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(const LocalFrame*);
158
159     Settings& settings() const { return *m_settings; }
160     BackForwardClient& backForward() const { return *m_backForwardClient; }
161
162     UseCounter& useCounter() { return m_useCounter; }
163
164     void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
165     bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
166
167     void unmarkAllTextMatches();
168
169     // DefersLoading is used to delay loads during modal dialogs.
170     // Modal dialogs are supposed to freeze all background processes
171     // in the page, including prevent additional loads from staring/continuing.
172     void setDefersLoading(bool);
173     bool defersLoading() const { return m_defersLoading; }
174
175     void setPageScaleFactor(float scale, const IntPoint& origin);
176     float pageScaleFactor() const;
177
178     float deviceScaleFactor() const { return m_deviceScaleFactor; }
179     void setDeviceScaleFactor(float);
180
181     static void allVisitedStateChanged();
182     static void visitedStateChanged(LinkHash visitedHash);
183
184     StorageNamespace* sessionStorage(bool optionalCreate = true);
185     StorageClient& storageClient() const { return *m_storageClient; }
186
187     // Don't allow more than a certain number of frames in a page.
188     // This seems like a reasonable upper bound, and otherwise mutually
189     // recursive frameset pages can quickly bring the program to its knees
190     // with exponential growth in the number of frames.
191     static const int maxNumberOfFrames = 1000;
192
193     PageVisibilityState visibilityState() const;
194     void setVisibilityState(PageVisibilityState, bool);
195
196     bool isCursorVisible() const;
197     void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; }
198
199 #ifndef NDEBUG
200     void setIsPainting(bool painting) { m_isPainting = painting; }
201     bool isPainting() const { return m_isPainting; }
202 #endif
203
204     double timerAlignmentInterval() const;
205
206     class MultisamplingChangedObserver : public WillBeGarbageCollectedMixin {
207     public:
208         virtual void multisamplingChanged(bool) = 0;
209     };
210
211     void addMultisamplingChangedObserver(MultisamplingChangedObserver*);
212     void removeMultisamplingChangedObserver(MultisamplingChangedObserver*);
213
214     void didCommitLoad(LocalFrame*);
215
216     static void networkStateChanged(bool online);
217     PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier();
218
219     void trace(Visitor*);
220     void willBeDestroyed();
221
222 protected:
223     PageLifecycleNotifier& lifecycleNotifier();
224
225 private:
226     void initGroup();
227
228 #if ASSERT_DISABLED
229     void checkSubframeCountConsistency() const { }
230 #else
231     void checkSubframeCountConsistency() const;
232 #endif
233
234     void setTimerAlignmentInterval(double);
235
236     void setNeedsLayoutInAllFrames();
237
238     // SettingsDelegate overrides.
239     virtual void settingsChanged(SettingsDelegate::ChangeType) OVERRIDE;
240
241     PageAnimator m_animator;
242     const OwnPtr<AutoscrollController> m_autoscrollController;
243     const OwnPtr<Chrome> m_chrome;
244     const OwnPtr<DragCaretController> m_dragCaretController;
245     const OwnPtr<DragController> m_dragController;
246     const OwnPtr<FocusController> m_focusController;
247     const OwnPtr<ContextMenuController> m_contextMenuController;
248     const OwnPtr<InspectorController> m_inspectorController;
249     const OwnPtr<PointerLockController> m_pointerLockController;
250     OwnPtr<ScrollingCoordinator> m_scrollingCoordinator;
251     const OwnPtr<UndoStack> m_undoStack;
252
253     RefPtr<LocalFrame> m_mainFrame;
254
255     mutable RefPtr<PluginData> m_pluginData;
256
257     BackForwardClient* m_backForwardClient;
258     EditorClient* const m_editorClient;
259     SpellCheckerClient* const m_spellCheckerClient;
260     StorageClient* m_storageClient;
261     OwnPtr<ValidationMessageClient> m_validationMessageClient;
262
263     UseCounter m_useCounter;
264
265     int m_subframeCount;
266     bool m_openedByDOM;
267
268     bool m_tabKeyCyclesThroughElements;
269     bool m_defersLoading;
270
271     float m_deviceScaleFactor;
272
273     OwnPtr<StorageNamespace> m_sessionStorage;
274
275     double m_timerAlignmentInterval;
276
277     PageVisibilityState m_visibilityState;
278
279     bool m_isCursorVisible;
280
281 #ifndef NDEBUG
282     bool m_isPainting;
283 #endif
284
285     WillBeHeapHashSet<RawPtrWillBeWeakMember<MultisamplingChangedObserver> > m_multisamplingChangedObservers;
286
287     // A pointer to all the interfaces provided to in-process Frames for this Page.
288     // FIXME: Most of the members of Page should move onto FrameHost.
289     OwnPtrWillBeMember<FrameHost> m_frameHost;
290 };
291
292 } // namespace WebCore
293
294 #endif // Page_h