1 /* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 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 "core/dom/ViewportDescription.h" 25 #include "core/frame/SettingsDelegate.h" 26 #include "core/frame/UseCounter.h" 27 #include "core/loader/HistoryController.h" 28 #include "core/page/PageVisibilityState.h" 29 #include "core/rendering/Pagination.h" 30 #include "platform/LifecycleContext.h" 31 #include "platform/Supplementable.h" 32 #include "platform/geometry/LayoutRect.h" 33 #include "platform/geometry/Region.h" 34 #include "wtf/Forward.h" 35 #include "wtf/HashSet.h" 36 #include "wtf/Noncopyable.h" 37 #include "wtf/text/WTFString.h" 38 39 namespace WebCore { 40 41 class AutoscrollController; 42 class BackForwardClient; 43 class Chrome; 44 class ChromeClient; 45 class ClientRectList; 46 class ContextMenuClient; 47 class ContextMenuController; 48 class Document; 49 class DragCaretController; 50 class DragClient; 51 class DragController; 52 class EditorClient; 53 class FocusController; 54 class Frame; 55 class FrameSelection; 56 class HaltablePlugin; 57 class HistoryItem; 58 class InspectorClient; 59 class InspectorController; 60 class Node; 61 class PageConsole; 62 class PageGroup; 63 class PageLifecycleNotifier; 64 class PlatformMouseEvent; 65 class PluginData; 66 class PointerLockController; 67 class ProgressTracker; 68 class Range; 69 class RenderBox; 70 class RenderObject; 71 class RenderTheme; 72 class VisibleSelection; 73 class ScrollableArea; 74 class ScrollingCoordinator; 75 class Settings; 76 class SharedWorkerRepositoryClient; 77 class SpellCheckerClient; 78 class StorageNamespace; 79 class UndoStack; 80 class ValidationMessageClient; 81 82 typedef uint64_t LinkHash; 83 84 float deviceScaleFactor(Frame*); 85 86 class Page : public Supplementable<Page>, public LifecycleContext<Page>, public SettingsDelegate { 87 WTF_MAKE_NONCOPYABLE(Page); 88 friend class Settings; 89 public: 90 static void scheduleForcedStyleRecalcForAllPages(); 91 92 // It is up to the platform to ensure that non-null clients are provided where required. 93 struct PageClients { 94 WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED; 95 public: 96 PageClients(); 97 ~PageClients(); 98 99 ChromeClient* chromeClient; 100 ContextMenuClient* contextMenuClient; 101 EditorClient* editorClient; 102 DragClient* dragClient; 103 InspectorClient* inspectorClient; 104 BackForwardClient* backForwardClient; 105 SpellCheckerClient* spellCheckerClient; 106 }; 107 108 explicit Page(PageClients&); 109 ~Page(); 110 111 void setNeedsRecalcStyleInAllFrames(); 112 113 ViewportDescription viewportDescription() const; 114 115 static void refreshPlugins(bool reload); 116 PluginData* pluginData() const; 117 118 EditorClient& editorClient() const { return *m_editorClient; } 119 SpellCheckerClient& spellCheckerClient() const { return *m_spellCheckerClient; } 120 UndoStack& undoStack() const { return *m_undoStack; } 121 122 HistoryController& historyController() const { return *m_historyController; } 123 124 void setMainFrame(PassRefPtr<Frame>); 125 Frame* mainFrame() const { return m_mainFrame.get(); } 126 127 void documentDetached(Document*); 128 129 bool openedByDOM() const; 130 void setOpenedByDOM(); 131 132 enum PageGroupType { PrivatePageGroup, SharedPageGroup }; 133 void setGroupType(PageGroupType); 134 void clearPageGroup(); 135 PageGroup& group() 136 { 137 if (!m_group) 138 setGroupType(PrivatePageGroup); 139 return *m_group; 140 } 141 142 void incrementSubframeCount() { ++m_subframeCount; } 143 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; } 144 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; } 145 146 Chrome& chrome() const { return *m_chrome; } 147 AutoscrollController& autoscrollController() const { return *m_autoscrollController; } 148 DragCaretController& dragCaretController() const { return *m_dragCaretController; } 149 DragController& dragController() const { return *m_dragController; } 150 FocusController& focusController() const { return *m_focusController; } 151 ContextMenuController& contextMenuController() const { return *m_contextMenuController; } 152 InspectorController& inspectorController() const { return *m_inspectorController; } 153 PointerLockController& pointerLockController() const { return *m_pointerLockController; } 154 ValidationMessageClient* validationMessageClient() const { return m_validationMessageClient; } 155 void setValidationMessageClient(ValidationMessageClient* client) { m_validationMessageClient = client; } 156 SharedWorkerRepositoryClient* sharedWorkerRepositoryClient() { return m_sharedWorkerRepositoryClient; } 157 void setSharedWorkerRepositoryClient(SharedWorkerRepositoryClient* client) { m_sharedWorkerRepositoryClient = client; } 158 159 ScrollingCoordinator* scrollingCoordinator(); 160 161 String mainThreadScrollingReasonsAsText(); 162 PassRefPtr<ClientRectList> nonFastScrollableRects(const Frame*); 163 164 Settings& settings() const { return *m_settings; } 165 ProgressTracker& progress() const { return *m_progress; } 166 BackForwardClient& backForward() const { return *m_backForwardClient; } 167 168 UseCounter& useCounter() { return m_useCounter; } 169 170 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; } 171 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; } 172 173 void unmarkAllTextMatches(); 174 175 // DefersLoading is used to delay loads during modal dialogs. 176 // Modal dialogs are supposed to freeze all background processes 177 // in the page, including prevent additional loads from staring/continuing. 178 void setDefersLoading(bool); 179 bool defersLoading() const { return m_defersLoading; } 180 181 void setPageScaleFactor(float scale, const IntPoint& origin); 182 float pageScaleFactor() const { return m_pageScaleFactor; } 183 184 float deviceScaleFactor() const { return m_deviceScaleFactor; } 185 void setDeviceScaleFactor(float); 186 187 // Page and FrameView both store a Pagination value. Page::pagination() is set only by API, 188 // and FrameView::pagination() is set only by CSS. Page::pagination() will affect all 189 // FrameViews in the page cache, but FrameView::pagination() only affects the current 190 // FrameView. 191 const Pagination& pagination() const { return m_pagination; } 192 void setPagination(const Pagination&); 193 194 static void allVisitedStateChanged(PageGroup*); 195 static void visitedStateChanged(PageGroup*, LinkHash visitedHash); 196 197 StorageNamespace* sessionStorage(bool optionalCreate = true); 198 199 // Don't allow more than a certain number of frames in a page. 200 // This seems like a reasonable upper bound, and otherwise mutually 201 // recursive frameset pages can quickly bring the program to its knees 202 // with exponential growth in the number of frames. 203 static const int maxNumberOfFrames = 1000; 204 205 PageVisibilityState visibilityState() const; 206 void setVisibilityState(PageVisibilityState, bool); 207 208 bool isCursorVisible() const { return m_isCursorVisible; } 209 void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; } 210 211 #ifndef NDEBUG 212 void setIsPainting(bool painting) { m_isPainting = painting; } 213 bool isPainting() const { return m_isPainting; } 214 #endif 215 216 PageConsole& console() { return *m_console; } 217 218 double timerAlignmentInterval() const; 219 220 class MultisamplingChangedObserver { 221 public: 222 virtual void multisamplingChanged(bool) = 0; 223 }; 224 225 void addMultisamplingChangedObserver(MultisamplingChangedObserver*); 226 void removeMultisamplingChangedObserver(MultisamplingChangedObserver*); 227 228 void didCommitLoad(Frame*); 229 230 static void networkStateChanged(bool online); 231 PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier(); 232 233 protected: 234 PageLifecycleNotifier& lifecycleNotifier(); 235 236 private: 237 void initGroup(); 238 239 #if ASSERT_DISABLED 240 void checkSubframeCountConsistency() const { } 241 #else 242 void checkSubframeCountConsistency() const; 243 #endif 244 245 void setTimerAlignmentInterval(double); 246 247 // SettingsDelegate overrides. 248 virtual Page* page() OVERRIDE { return this; } 249 virtual void settingsChanged(SettingsDelegate::ChangeType) OVERRIDE; 250 251 const OwnPtr<AutoscrollController> m_autoscrollController; 252 const OwnPtr<Chrome> m_chrome; 253 const OwnPtr<DragCaretController> m_dragCaretController; 254 const OwnPtr<DragController> m_dragController; 255 const OwnPtr<FocusController> m_focusController; 256 const OwnPtr<ContextMenuController> m_contextMenuController; 257 const OwnPtr<InspectorController> m_inspectorController; 258 const OwnPtr<PointerLockController> m_pointerLockController; 259 RefPtr<ScrollingCoordinator> m_scrollingCoordinator; 260 261 const OwnPtr<HistoryController> m_historyController; 262 const OwnPtr<ProgressTracker> m_progress; 263 const OwnPtr<UndoStack> m_undoStack; 264 265 RefPtr<Frame> m_mainFrame; 266 267 mutable RefPtr<PluginData> m_pluginData; 268 269 BackForwardClient* m_backForwardClient; 270 EditorClient* const m_editorClient; 271 ValidationMessageClient* m_validationMessageClient; 272 SharedWorkerRepositoryClient* m_sharedWorkerRepositoryClient; 273 SpellCheckerClient* const m_spellCheckerClient; 274 275 UseCounter m_useCounter; 276 277 int m_subframeCount; 278 bool m_openedByDOM; 279 280 bool m_tabKeyCyclesThroughElements; 281 bool m_defersLoading; 282 283 float m_pageScaleFactor; 284 float m_deviceScaleFactor; 285 286 Pagination m_pagination; 287 288 RefPtr<PageGroup> m_group; 289 290 OwnPtr<StorageNamespace> m_sessionStorage; 291 292 double m_timerAlignmentInterval; 293 294 PageVisibilityState m_visibilityState; 295 296 bool m_isCursorVisible; 297 298 #ifndef NDEBUG 299 bool m_isPainting; 300 #endif 301 302 const OwnPtr<PageConsole> m_console; 303 304 HashSet<MultisamplingChangedObserver*> m_multisamplingChangedObservers; 305 }; 306 307 } // namespace WebCore 308 309 #endif // Page_h 310