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