Home | History | Annotate | Download | only in page
      1 /*
      2  * Copyright (C) 2006, 2008 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 "PlatformString.h"
     26 #include <wtf/Forward.h>
     27 #include <wtf/HashSet.h>
     28 #include <wtf/Noncopyable.h>
     29 
     30 #if PLATFORM(MAC)
     31 #include "SchedulePair.h"
     32 #endif
     33 
     34 #if PLATFORM(WIN) || (PLATFORM(WX) && OS(WINDOWS)) || (PLATFORM(QT) && defined(Q_WS_WIN))
     35 typedef struct HINSTANCE__* HINSTANCE;
     36 #endif
     37 
     38 namespace JSC {
     39     class Debugger;
     40 }
     41 
     42 namespace WebCore {
     43 
     44     class BackForwardList;
     45     class Chrome;
     46     class ChromeClient;
     47     class ContextMenuClient;
     48     class ContextMenuController;
     49     class Document;
     50     class DragClient;
     51     class DragController;
     52     class EditorClient;
     53     class FocusController;
     54     class Frame;
     55     class GeolocationController;
     56     class GeolocationControllerClient;
     57     class HaltablePlugin;
     58     class HistoryItem;
     59     class InspectorClient;
     60     class InspectorController;
     61     class InspectorTimelineAgent;
     62     class Node;
     63     class PageGroup;
     64     class PluginData;
     65     class PluginHalter;
     66     class PluginHalterClient;
     67     class PluginView;
     68     class ProgressTracker;
     69     class RenderTheme;
     70     class VisibleSelection;
     71     class SelectionController;
     72     class Settings;
     73 #if ENABLE(DOM_STORAGE)
     74     class StorageNamespace;
     75 #endif
     76 #if ENABLE(WML)
     77     class WMLPageState;
     78 #endif
     79 #if ENABLE(NOTIFICATIONS)
     80     class NotificationPresenter;
     81 #endif
     82 
     83     typedef uint64_t LinkHash;
     84 
     85     enum FindDirection { FindDirectionForward, FindDirectionBackward };
     86 
     87     class Page : public Noncopyable {
     88     public:
     89         static void setNeedsReapplyStyles();
     90 
     91         Page(ChromeClient*, ContextMenuClient*, EditorClient*, DragClient*, InspectorClient*, PluginHalterClient*, GeolocationControllerClient*);
     92         ~Page();
     93 
     94         RenderTheme* theme() const { return m_theme.get(); };
     95 
     96         static void refreshPlugins(bool reload);
     97         PluginData* pluginData() const;
     98 
     99         void setCanStartPlugins(bool);
    100         bool canStartPlugins() const { return m_canStartPlugins; }
    101         void addUnstartedPlugin(PluginView*);
    102         void removeUnstartedPlugin(PluginView*);
    103 
    104         EditorClient* editorClient() const { return m_editorClient; }
    105 
    106         void setMainFrame(PassRefPtr<Frame>);
    107         Frame* mainFrame() const { return m_mainFrame.get(); }
    108 
    109         bool openedByDOM() const;
    110         void setOpenedByDOM();
    111 
    112         BackForwardList* backForwardList();
    113 
    114         // FIXME: The following three methods don't fall under the responsibilities of the Page object
    115         // They seem to fit a hypothetical Page-controller object that would be akin to the
    116         // Frame-FrameLoader relationship.  They have to live here now, but should move somewhere that
    117         // makes more sense when that class exists.
    118         bool goBack();
    119         bool goForward();
    120         bool canGoBackOrForward(int distance) const;
    121         void goBackOrForward(int distance);
    122         void goToItem(HistoryItem*, FrameLoadType);
    123         int getHistoryLength();
    124 
    125         HistoryItem* globalHistoryItem() const { return m_globalHistoryItem.get(); }
    126         void setGlobalHistoryItem(HistoryItem*);
    127 
    128         void setGroupName(const String&);
    129         const String& groupName() const;
    130 
    131         PageGroup& group() { if (!m_group) initGroup(); return *m_group; }
    132         PageGroup* groupPtr() { return m_group; } // can return 0
    133 
    134         void incrementFrameCount() { ++m_frameCount; }
    135         void decrementFrameCount() { ASSERT(m_frameCount); --m_frameCount; }
    136         int frameCount() const { checkFrameCountConsistency(); return m_frameCount; }
    137 
    138         Chrome* chrome() const { return m_chrome.get(); }
    139         SelectionController* dragCaretController() const { return m_dragCaretController.get(); }
    140 #if ENABLE(DRAG_SUPPORT)
    141         DragController* dragController() const { return m_dragController.get(); }
    142 #endif
    143         FocusController* focusController() const { return m_focusController.get(); }
    144 #if ENABLE(CONTEXT_MENUS)
    145         ContextMenuController* contextMenuController() const { return m_contextMenuController.get(); }
    146 #endif
    147 #if ENABLE(INSPECTOR)
    148         InspectorController* inspectorController() const { return m_inspectorController.get(); }
    149 #endif
    150 #if ENABLE(CLIENT_BASED_GEOLOCATION)
    151         GeolocationController* geolocationController() const { return m_geolocationController.get(); }
    152 #endif
    153         Settings* settings() const { return m_settings.get(); }
    154         ProgressTracker* progress() const { return m_progress.get(); }
    155 
    156 #if ENABLE(INSPECTOR)
    157         void setParentInspectorController(InspectorController* controller) { m_parentInspectorController = controller; }
    158         InspectorController* parentInspectorController() const { return m_parentInspectorController; }
    159 #endif
    160 
    161         void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; }
    162         bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; }
    163 
    164         bool findString(const String&, TextCaseSensitivity, FindDirection, bool shouldWrap);
    165         unsigned int markAllMatchesForText(const String&, TextCaseSensitivity, bool shouldHighlight, unsigned);
    166         void unmarkAllTextMatches();
    167 
    168 #if PLATFORM(MAC)
    169         void addSchedulePair(PassRefPtr<SchedulePair>);
    170         void removeSchedulePair(PassRefPtr<SchedulePair>);
    171         SchedulePairHashSet* scheduledRunLoopPairs() { return m_scheduledRunLoopPairs.get(); }
    172 
    173         OwnPtr<SchedulePairHashSet> m_scheduledRunLoopPairs;
    174 #endif
    175 
    176         const VisibleSelection& selection() const;
    177 
    178         void setDefersLoading(bool);
    179         bool defersLoading() const { return m_defersLoading; }
    180 
    181         void clearUndoRedoOperations();
    182 
    183         bool inLowQualityImageInterpolationMode() const;
    184         void setInLowQualityImageInterpolationMode(bool = true);
    185 
    186         bool cookieEnabled() const { return m_cookieEnabled; }
    187         void setCookieEnabled(bool enabled) { m_cookieEnabled = enabled; }
    188 
    189         float mediaVolume() const { return m_mediaVolume; }
    190         void setMediaVolume(float volume);
    191 
    192         // Notifications when the Page starts and stops being presented via a native window.
    193         void didMoveOnscreen();
    194         void willMoveOffscreen();
    195 
    196         void userStyleSheetLocationChanged();
    197         const String& userStyleSheet() const;
    198 
    199         void didStartPlugin(HaltablePlugin*);
    200         void didStopPlugin(HaltablePlugin*);
    201         void pluginAllowedRunTimeChanged();
    202 
    203         static void setDebuggerForAllPages(JSC::Debugger*);
    204         void setDebugger(JSC::Debugger*);
    205         JSC::Debugger* debugger() const { return m_debugger; }
    206 
    207 #if PLATFORM(WIN) || (PLATFORM(WX) && OS(WINDOWS)) || (PLATFORM(QT) && defined(Q_WS_WIN))
    208         // The global DLL or application instance used for all windows.
    209         static void setInstanceHandle(HINSTANCE instanceHandle) { s_instanceHandle = instanceHandle; }
    210         static HINSTANCE instanceHandle() { return s_instanceHandle; }
    211 #endif
    212 
    213         static void removeAllVisitedLinks();
    214 
    215         static void allVisitedStateChanged(PageGroup*);
    216         static void visitedStateChanged(PageGroup*, LinkHash visitedHash);
    217 
    218 #if ENABLE(DOM_STORAGE)
    219         StorageNamespace* sessionStorage(bool optionalCreate = true);
    220         void setSessionStorage(PassRefPtr<StorageNamespace>);
    221 #endif
    222 
    223 #if ENABLE(WML)
    224         WMLPageState* wmlPageState();
    225 #endif
    226 
    227         void setCustomHTMLTokenizerTimeDelay(double);
    228         bool hasCustomHTMLTokenizerTimeDelay() const { return m_customHTMLTokenizerTimeDelay != -1; }
    229         double customHTMLTokenizerTimeDelay() const { ASSERT(m_customHTMLTokenizerTimeDelay != -1); return m_customHTMLTokenizerTimeDelay; }
    230 
    231         void setCustomHTMLTokenizerChunkSize(int);
    232         bool hasCustomHTMLTokenizerChunkSize() const { return m_customHTMLTokenizerChunkSize != -1; }
    233         int customHTMLTokenizerChunkSize() const { ASSERT(m_customHTMLTokenizerChunkSize != -1); return m_customHTMLTokenizerChunkSize; }
    234 
    235         void setMemoryCacheClientCallsEnabled(bool);
    236         bool areMemoryCacheClientCallsEnabled() const { return m_areMemoryCacheClientCallsEnabled; }
    237 
    238         void setJavaScriptURLsAreAllowed(bool);
    239         bool javaScriptURLsAreAllowed() const;
    240 
    241 #if ENABLE(INSPECTOR)
    242         InspectorTimelineAgent* inspectorTimelineAgent() const;
    243 #endif
    244     private:
    245         void initGroup();
    246 
    247 #if ASSERT_DISABLED
    248         void checkFrameCountConsistency() const { }
    249 #else
    250         void checkFrameCountConsistency() const;
    251 #endif
    252 
    253         OwnPtr<Chrome> m_chrome;
    254         OwnPtr<SelectionController> m_dragCaretController;
    255 #if ENABLE(DRAG_SUPPORT)
    256         OwnPtr<DragController> m_dragController;
    257 #endif
    258         OwnPtr<FocusController> m_focusController;
    259 #if ENABLE(CONTEXT_MENUS)
    260         OwnPtr<ContextMenuController> m_contextMenuController;
    261 #endif
    262 #if ENABLE(INSPECTOR)
    263         OwnPtr<InspectorController> m_inspectorController;
    264 #endif
    265 #if ENABLE(CLIENT_BASED_GEOLOCATION)
    266         OwnPtr<GeolocationController> m_geolocationController;
    267 #endif
    268         OwnPtr<Settings> m_settings;
    269         OwnPtr<ProgressTracker> m_progress;
    270 
    271         RefPtr<BackForwardList> m_backForwardList;
    272         RefPtr<Frame> m_mainFrame;
    273 
    274         RefPtr<HistoryItem> m_globalHistoryItem;
    275 
    276         mutable RefPtr<PluginData> m_pluginData;
    277 
    278         RefPtr<RenderTheme> m_theme;
    279 
    280         EditorClient* m_editorClient;
    281 
    282         int m_frameCount;
    283         String m_groupName;
    284         bool m_openedByDOM;
    285 
    286         bool m_tabKeyCyclesThroughElements;
    287         bool m_defersLoading;
    288 
    289         bool m_inLowQualityInterpolationMode;
    290         bool m_cookieEnabled;
    291         bool m_areMemoryCacheClientCallsEnabled;
    292         float m_mediaVolume;
    293 
    294         bool m_javaScriptURLsAreAllowed;
    295 
    296 #if ENABLE(INSPECTOR)
    297         InspectorController* m_parentInspectorController;
    298 #endif
    299 
    300         String m_userStyleSheetPath;
    301         mutable String m_userStyleSheet;
    302         mutable bool m_didLoadUserStyleSheet;
    303         mutable time_t m_userStyleSheetModificationTime;
    304 
    305         OwnPtr<PageGroup> m_singlePageGroup;
    306         PageGroup* m_group;
    307 
    308         JSC::Debugger* m_debugger;
    309 
    310         double m_customHTMLTokenizerTimeDelay;
    311         int m_customHTMLTokenizerChunkSize;
    312 
    313         bool m_canStartPlugins;
    314         HashSet<PluginView*> m_unstartedPlugins;
    315 
    316         OwnPtr<PluginHalter> m_pluginHalter;
    317 
    318 #if ENABLE(DOM_STORAGE)
    319         RefPtr<StorageNamespace> m_sessionStorage;
    320 #endif
    321 
    322 #if PLATFORM(WIN) || (PLATFORM(WX) && defined(__WXMSW__)) || (PLATFORM(QT) && defined(Q_WS_WIN))
    323         static HINSTANCE s_instanceHandle;
    324 #endif
    325 
    326 #if ENABLE(WML)
    327         OwnPtr<WMLPageState> m_wmlPageState;
    328 #endif
    329 
    330 #if ENABLE(NOTIFICATIONS)
    331         NotificationPresenter* m_notificationPresenter;
    332 #endif
    333     };
    334 
    335 } // namespace WebCore
    336 
    337 #endif // Page_h
    338