2a057c3841733b792f50477db92ab7d14050bc01
[WebKit-https.git] / WebCore / page / Page.h
1 /*
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/)
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 "FrameLoaderTypes.h"
25 #include "FindOptions.h"
26 #include "PlatformString.h"
27 #include "ViewportArguments.h"
28 #include <wtf/Forward.h>
29 #include <wtf/HashSet.h>
30 #include <wtf/Noncopyable.h>
31
32 #if PLATFORM(MAC)
33 #include "SchedulePair.h"
34 #endif
35
36 namespace JSC {
37     class Debugger;
38 }
39
40 namespace WebCore {
41
42     class AnimationTimeController;
43     class BackForwardController;
44     class BackForwardList;
45     class Chrome;
46     class ChromeClient;
47     class ContextMenuClient;
48     class ContextMenuController;
49     class DeviceMotionClient;
50     class DeviceMotionController;
51     class DeviceOrientationClient;
52     class DeviceOrientationController;
53     class Document;
54     class DragClient;
55     class DragController;
56     class EditorClient;
57     class FocusController;
58     class Frame;
59     class GeolocationClient;
60     class GeolocationController;
61     class HaltablePlugin;
62     class HistoryItem;
63     class InspectorClient;
64     class InspectorController;
65     class MediaCanStartListener;
66     class Node;
67     class PageGroup;
68     class PluginData;
69     class PluginHalter;
70     class PluginHalterClient;
71     class ProgressTracker;
72     class RenderTheme;
73     class VisibleSelection;
74     class SelectionController;
75     class Settings;
76     class SharedGraphicsContext3D;
77     class SpeechInput;
78     class SpeechInputClient;
79
80 #if ENABLE(DOM_STORAGE)
81     class StorageNamespace;
82 #endif
83 #if ENABLE(NOTIFICATIONS)
84     class NotificationPresenter;
85 #endif
86 #if ENABLE(WML)
87     class WMLPageState;
88 #endif
89
90     typedef uint64_t LinkHash;
91
92     enum FindDirection { FindDirectionForward, FindDirectionBackward };
93
94     class Page : public Noncopyable {
95     public:
96         static void scheduleForcedStyleRecalcForAllPages();
97
98         // It is up to the platform to ensure that non-null clients are provided where required.
99         struct PageClients : Noncopyable {
100             PageClients();
101             ~PageClients();
102
103             ChromeClient* chromeClient;
104             ContextMenuClient* contextMenuClient;
105             EditorClient* editorClient;
106             DragClient* dragClient;
107             InspectorClient* inspectorClient;
108             PluginHalterClient* pluginHalterClient;
109             GeolocationClient* geolocationClient;
110             DeviceMotionClient* deviceMotionClient;
111             DeviceOrientationClient* deviceOrientationClient;
112             RefPtr<BackForwardList> backForwardClient;
113             SpeechInputClient* speechInputClient;
114         };
115
116         Page(const PageClients&);
117         ~Page();
118
119         RenderTheme* theme() const { return m_theme.get(); };
120
121         ViewportArguments viewportArguments() const { return m_viewportArguments; }
122         void updateViewportArguments();
123
124         static void refreshPlugins(bool reload);
125         PluginData* pluginData() const;
126
127         void setCanStartMedia(bool);
128         bool canStartMedia() const { return m_canStartMedia; }
129
130         EditorClient* editorClient() const { return m_editorClient; }
131
132         void setMainFrame(PassRefPtr<Frame>);
133         Frame* mainFrame() const { return m_mainFrame.get(); }
134
135         bool openedByDOM() const;
136         void setOpenedByDOM();
137
138         // DEPRECATED. Use backForward() instead of the following 6 functions.
139         BackForwardList* backForwardList() const;
140         bool goBack();
141         bool goForward();
142         bool canGoBackOrForward(int distance) const;
143         void goBackOrForward(int distance);
144         int getHistoryLength();
145
146         void goToItem(HistoryItem*, FrameLoadType);
147
148         HistoryItem* globalHistoryItem() const { return m_globalHistoryItem.get(); }
149         void setGlobalHistoryItem(HistoryItem*);
150
151         void setGroupName(const String&);
152         const String& groupName() const;
153
154         PageGroup& group() { if (!m_group) initGroup(); return *m_group; }
155         PageGroup* groupPtr() { return m_group; } // can return 0
156
157         void incrementFrameCount() { ++m_frameCount; }
158         void decrementFrameCount() { ASSERT(m_frameCount); --m_frameCount; }
159         int frameCount() const { checkFrameCountConsistency(); return m_frameCount; }
160
161         Chrome* chrome() const { return m_chrome.get(); }
162         SelectionController* dragCaretController() const { return m_dragCaretController.get(); }
163 #if ENABLE(DRAG_SUPPORT)
164         DragController* dragController() const { return m_dragController.get(); }
165 #endif
166         FocusController* focusController() const { return m_focusController.get(); }
167 #if ENABLE(CONTEXT_MENUS)
168         ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
169 #endif
170 #if ENABLE(INSPECTOR)
171         InspectorController* inspectorController() const { return m_inspectorController.get(); }
172 #endif
173 #if ENABLE(CLIENT_BASED_GEOLOCATION)
174         GeolocationController* geolocationController() const { return m_geolocationController.get(); }
175 #endif
176 #if ENABLE(DEVICE_ORIENTATION)
177         DeviceMotionController* deviceMotionController() const { return m_deviceMotionController.get(); }
178         DeviceOrientationController* deviceOrientationController() const { return m_deviceOrientationController.get(); }
179 #endif
180 #if ENABLE(INPUT_SPEECH)
181         SpeechInput* speechInput();
182 #endif
183         Settings* settings() const { return m_settings.get(); }
184         ProgressTracker* progress() const { return m_progress.get(); }
185         BackForwardController* backForward() const { return m_backForwardController.get(); }
186         AnimationTimeController* animationTime() const { return m_animationTimeController.get(); }
187
188         enum ViewMode {
189             ViewModeInvalid,
190             ViewModeWindowed,
191             ViewModeFloating,
192             ViewModeFullscreen,
193             ViewModeMaximized,
194             ViewModeMinimized
195         };
196         static ViewMode stringToViewMode(const String&);
197
198         ViewMode viewMode() const { return m_viewMode; }
199         void setViewMode(ViewMode);
200         
201         void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
202         bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
203
204         bool findString(const String&, FindOptions);
205         // FIXME: Switch callers over to the FindOptions version and retire this one.
206         bool findString(const String&, TextCaseSensitivity, FindDirection, bool shouldWrap);
207         unsigned markAllMatchesForText(const String&, FindOptions, bool shouldHighlight, unsigned);
208         // FIXME: Switch callers over to the FindOptions version and retire this one.
209         unsigned markAllMatchesForText(const String&, TextCaseSensitivity, bool shouldHighlight, unsigned);
210         void unmarkAllTextMatches();
211
212 #if PLATFORM(MAC)
213         void addSchedulePair(PassRefPtr<SchedulePair>);
214         void removeSchedulePair(PassRefPtr<SchedulePair>);
215         SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
216
217         OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
218 #endif
219
220         const VisibleSelection& selection() const;
221
222         void setDefersLoading(bool);
223         bool defersLoading() const { return m_defersLoading; }
224         
225         void clearUndoRedoOperations();
226
227         bool inLowQualityImageInterpolationMode() const;
228         void setInLowQualityImageInterpolationMode(bool = true);
229
230         bool cookieEnabled() const { return m_cookieEnabled; }
231         void setCookieEnabled(bool enabled) { m_cookieEnabled = enabled; }
232
233         float mediaVolume() const { return m_mediaVolume; }
234         void setMediaVolume(float volume);
235
236         // Notifications when the Page starts and stops being presented via a native window.
237         void didMoveOnscreen();
238         void willMoveOffscreen();
239
240         void userStyleSheetLocationChanged();
241         const String& userStyleSheet() const;
242
243         void dnsPrefetchingStateChanged();
244         void privateBrowsingStateChanged();
245
246         void didStartPlugin(HaltablePlugin*);
247         void didStopPlugin(HaltablePlugin*);
248         void pluginAllowedRunTimeChanged();
249
250         static void setDebuggerForAllPages(JSC::Debugger*);
251         void setDebugger(JSC::Debugger*);
252         JSC::Debugger* debugger() const { return m_debugger; }
253
254         static void removeAllVisitedLinks();
255
256         static void allVisitedStateChanged(PageGroup*);
257         static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
258
259         SharedGraphicsContext3D* sharedGraphicsContext3D();
260
261 #if ENABLE(DOM_STORAGE)
262         StorageNamespace* sessionStorage(bool optionalCreate = true);
263         void setSessionStorage(PassRefPtr<StorageNamespace>);
264 #endif
265
266 #if ENABLE(WML)
267         WMLPageState* wmlPageState();
268 #endif
269
270         void setCustomHTMLTokenizerTimeDelay(double);
271         bool hasCustomHTMLTokenizerTimeDelay() const { return m_customHTMLTokenizerTimeDelay != -1; }
272         double customHTMLTokenizerTimeDelay() const { ASSERT(m_customHTMLTokenizerTimeDelay != -1); return m_customHTMLTokenizerTimeDelay; }
273
274         void setCustomHTMLTokenizerChunkSize(int);
275         bool hasCustomHTMLTokenizerChunkSize() const { return m_customHTMLTokenizerChunkSize != -1; }
276         int customHTMLTokenizerChunkSize() const { ASSERT(m_customHTMLTokenizerChunkSize != -1); return m_customHTMLTokenizerChunkSize; }
277
278         void setMemoryCacheClientCallsEnabled(bool);
279         bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
280
281         void setJavaScriptURLsAreAllowed(bool);
282         bool javaScriptURLsAreAllowed() const;
283
284         // Don't allow more than a certain number of frames in a page.
285         // This seems like a reasonable upper bound, and otherwise mutually
286         // recursive frameset pages can quickly bring the program to its knees
287         // with exponential growth in the number of frames.
288         static const int maxNumberOfFrames = 1000;
289     private:
290         void initGroup();
291
292 #if ASSERT_DISABLED
293         void checkFrameCountConsistency() const { }
294 #else
295         void checkFrameCountConsistency() const;
296 #endif
297
298         MediaCanStartListener* takeAnyMediaCanStartListener();
299
300         OwnPtr<Chrome> m_chrome;
301         OwnPtr<SelectionController> m_dragCaretController;
302
303 #if ENABLE(ACCELERATED_2D_CANVAS)
304         RefPtr<SharedGraphicsContext3D> m_sharedGraphicsContext3D;
305 #endif
306         
307 #if ENABLE(DRAG_SUPPORT)
308         OwnPtr<DragController> m_dragController;
309 #endif
310         OwnPtr<FocusController> m_focusController;
311 #if ENABLE(CONTEXT_MENUS)
312         OwnPtr<ContextMenuController> m_contextMenuController;
313 #endif
314 #if ENABLE(INSPECTOR)
315         OwnPtr<InspectorController> m_inspectorController;
316 #endif
317 #if ENABLE(CLIENT_BASED_GEOLOCATION)
318         OwnPtr<GeolocationController> m_geolocationController;
319 #endif
320 #if ENABLE(DEVICE_ORIENTATION)
321         OwnPtr<DeviceMotionController> m_deviceMotionController;
322         OwnPtr<DeviceOrientationController> m_deviceOrientationController;
323 #endif
324 #if ENABLE(INPUT_SPEECH)
325         SpeechInputClient* m_speechInputClient;
326         OwnPtr<SpeechInput> m_speechInput;
327 #endif
328         OwnPtr<Settings> m_settings;
329         OwnPtr<ProgressTracker> m_progress;
330         
331         OwnPtr<BackForwardController> m_backForwardController;
332         OwnPtr<AnimationTimeController> m_animationTimeController;
333         RefPtr<Frame> m_mainFrame;
334
335         RefPtr<HistoryItem> m_globalHistoryItem;
336
337         mutable RefPtr<PluginData> m_pluginData;
338
339         RefPtr<RenderTheme> m_theme;
340
341         EditorClient* m_editorClient;
342
343         int m_frameCount;
344         String m_groupName;
345         bool m_openedByDOM;
346
347         bool m_tabKeyCyclesThroughElements;
348         bool m_defersLoading;
349
350         bool m_inLowQualityInterpolationMode;
351         bool m_cookieEnabled;
352         bool m_areMemoryCacheClientCallsEnabled;
353         float m_mediaVolume;
354
355         bool m_javaScriptURLsAreAllowed;
356
357         String m_userStyleSheetPath;
358         mutable String m_userStyleSheet;
359         mutable bool m_didLoadUserStyleSheet;
360         mutable time_t m_userStyleSheetModificationTime;
361
362         OwnPtr<PageGroup> m_singlePageGroup;
363         PageGroup* m_group;
364
365         JSC::Debugger* m_debugger;
366
367         double m_customHTMLTokenizerTimeDelay;
368         int m_customHTMLTokenizerChunkSize;
369
370         bool m_canStartMedia;
371
372         OwnPtr<PluginHalter> m_pluginHalter;
373
374 #if ENABLE(DOM_STORAGE)
375         RefPtr<StorageNamespace> m_sessionStorage;
376 #endif
377
378 #if ENABLE(WML)
379         OwnPtr<WMLPageState> m_wmlPageState;
380 #endif
381
382 #if ENABLE(NOTIFICATIONS)
383         NotificationPresenter* m_notificationPresenter;
384 #endif
385
386         double m_currentAnimationTime;
387
388         ViewMode m_viewMode;
389
390         ViewportArguments m_viewportArguments;
391     };
392
393 } // namespace WebCore
394     
395 #endif // Page_h