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