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