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