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/LocalFrame.h" 26 #include "core/frame/SettingsDelegate.h" 27 #include "core/frame/UseCounter.h" 28 #include "core/page/PageAnimator.h" 29 #include "core/page/PageVisibilityState.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 "platform/heap/Handle.h" 35 #include "wtf/Forward.h" 36 #include "wtf/HashSet.h" 37 #include "wtf/Noncopyable.h" 38 #include "wtf/text/WTFString.h" 39 40 namespace WebCore { 41 42 class AutoscrollController; 43 class BackForwardClient; 44 class Chrome; 45 class ChromeClient; 46 class ClientRectList; 47 class ContextMenuClient; 48 class ContextMenuController; 49 class Document; 50 class DragCaretController; 51 class DragClient; 52 class DragController; 53 class EditorClient; 54 class FocusController; 55 class Frame; 56 class FrameHost; 57 class HistoryItem; 58 class InspectorClient; 59 class InspectorController; 60 class PageLifecycleNotifier; 61 class PlatformMouseEvent; 62 class PluginData; 63 class PointerLockController; 64 class Range; 65 class RenderBox; 66 class RenderObject; 67 class RenderTheme; 68 class StorageClient; 69 class VisibleSelection; 70 class ScrollableArea; 71 class ScrollingCoordinator; 72 class Settings; 73 class SpellCheckerClient; 74 class StorageNamespace; 75 class UndoStack; 76 class ValidationMessageClient; 77 78 typedef uint64_t LinkHash; 79 80 float deviceScaleFactor(LocalFrame*); 81 82 class Page FINAL : public NoBaseWillBeGarbageCollectedFinalized<Page>, public WillBeHeapSupplementable<Page>, public LifecycleContext<Page>, public SettingsDelegate { 83 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Page); 84 WTF_MAKE_NONCOPYABLE(Page); 85 friend class Settings; 86 public: 87 static void scheduleForcedStyleRecalcForAllPages(); 88 89 // It is up to the platform to ensure that non-null clients are provided where required. 90 struct PageClients { 91 WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED; 92 public: 93 PageClients(); 94 ~PageClients(); 95 96 ChromeClient* chromeClient; 97 ContextMenuClient* contextMenuClient; 98 EditorClient* editorClient; 99 DragClient* dragClient; 100 InspectorClient* inspectorClient; 101 BackForwardClient* backForwardClient; 102 SpellCheckerClient* spellCheckerClient; 103 StorageClient* storageClient; 104 }; 105 106 explicit Page(PageClients&); 107 virtual ~Page(); 108 109 void makeOrdinary(); 110 111 // This method returns all pages, incl. private ones associated with 112 // inspector overlay, popups, SVGImage, etc. 113 static HashSet<Page*>& allPages(); 114 // This method returns all ordinary pages. 115 static HashSet<Page*>& ordinaryPages(); 116 117 FrameHost& frameHost() const { return *m_frameHost; } 118 119 void setNeedsRecalcStyleInAllFrames(); 120 void updateAcceleratedCompositingSettings(); 121 122 ViewportDescription viewportDescription() const; 123 124 static void refreshPlugins(bool reload); 125 PluginData* pluginData() const; 126 127 EditorClient& editorClient() const { return *m_editorClient; } 128 SpellCheckerClient& spellCheckerClient() const { return *m_spellCheckerClient; } 129 UndoStack& undoStack() const { return *m_undoStack; } 130 131 void setMainFrame(Frame*); 132 Frame* mainFrame() const { return m_mainFrame; } 133 // Escape hatch for existing code that assumes that the root frame is 134 // always a LocalFrame. With OOPI, this is not always the case. Code that 135 // depends on this will generally have to be rewritten to propagate any 136 // necessary state through all renderer processes for that page and/or 137 // coordinate/rely on the browser process to help dispatch/coordinate work. 138 LocalFrame* deprecatedLocalMainFrame() const { return toLocalFrame(m_mainFrame); } 139 140 void documentDetached(Document*); 141 142 bool openedByDOM() const; 143 void setOpenedByDOM(); 144 145 void incrementSubframeCount() { ++m_subframeCount; } 146 void decrementSubframeCount() { ASSERT(m_subframeCount); --m_subframeCount; } 147 int subframeCount() const { checkSubframeCountConsistency(); return m_subframeCount; } 148 149 PageAnimator& animator() { return m_animator; } 150 Chrome& chrome() const { return *m_chrome; } 151 AutoscrollController& autoscrollController() const { return *m_autoscrollController; } 152 DragCaretController& dragCaretController() const { return *m_dragCaretController; } 153 DragController& dragController() const { return *m_dragController; } 154 FocusController& focusController() const { return *m_focusController; } 155 ContextMenuController& contextMenuController() const { return *m_contextMenuController; } 156 InspectorController& inspectorController() const { return *m_inspectorController; } 157 PointerLockController& pointerLockController() const { return *m_pointerLockController; } 158 ValidationMessageClient& validationMessageClient() const { return *m_validationMessageClient; } 159 void setValidationMessageClient(PassOwnPtrWillBeRawPtr<ValidationMessageClient>); 160 161 ScrollingCoordinator* scrollingCoordinator(); 162 163 String mainThreadScrollingReasonsAsText(); 164 PassRefPtrWillBeRawPtr<ClientRectList> nonFastScrollableRects(const LocalFrame*); 165 166 Settings& settings() const { return *m_settings; } 167 BackForwardClient& backForward() const { return *m_backForwardClient; } 168 169 UseCounter& useCounter() { return m_useCounter; } 170 171 void setTabKeyCyclesThroughElements(bool b) { m_tabKeyCyclesThroughElements = b; } 172 bool tabKeyCyclesThroughElements() const { return m_tabKeyCyclesThroughElements; } 173 174 void unmarkAllTextMatches(); 175 176 // DefersLoading is used to delay loads during modal dialogs. 177 // Modal dialogs are supposed to freeze all background processes 178 // in the page, including prevent additional loads from staring/continuing. 179 void setDefersLoading(bool); 180 bool defersLoading() const { return m_defersLoading; } 181 182 void setPageScaleFactor(float scale, const IntPoint& origin); 183 float pageScaleFactor() const; 184 185 float deviceScaleFactor() const { return m_deviceScaleFactor; } 186 void setDeviceScaleFactor(float); 187 188 static void allVisitedStateChanged(); 189 static void visitedStateChanged(LinkHash visitedHash); 190 191 StorageNamespace* sessionStorage(bool optionalCreate = true); 192 StorageClient& storageClient() const { return *m_storageClient; } 193 194 // Don't allow more than a certain number of frames in a page. 195 // This seems like a reasonable upper bound, and otherwise mutually 196 // recursive frameset pages can quickly bring the program to its knees 197 // with exponential growth in the number of frames. 198 static const int maxNumberOfFrames = 1000; 199 200 PageVisibilityState visibilityState() const; 201 void setVisibilityState(PageVisibilityState, bool); 202 203 bool isCursorVisible() const; 204 void setIsCursorVisible(bool isVisible) { m_isCursorVisible = isVisible; } 205 206 #ifndef NDEBUG 207 void setIsPainting(bool painting) { m_isPainting = painting; } 208 bool isPainting() const { return m_isPainting; } 209 #endif 210 211 double timerAlignmentInterval() const; 212 213 class MultisamplingChangedObserver : public WillBeGarbageCollectedMixin { 214 public: 215 virtual void multisamplingChanged(bool) = 0; 216 }; 217 218 void addMultisamplingChangedObserver(MultisamplingChangedObserver*); 219 void removeMultisamplingChangedObserver(MultisamplingChangedObserver*); 220 221 void didCommitLoad(LocalFrame*); 222 223 void acceptLanguagesChanged(); 224 225 static void networkStateChanged(bool online); 226 PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier(); 227 228 void trace(Visitor*); 229 void willBeDestroyed(); 230 231 protected: 232 PageLifecycleNotifier& lifecycleNotifier(); 233 234 private: 235 void initGroup(); 236 237 #if ASSERT_ENABLED 238 void checkSubframeCountConsistency() const; 239 #else 240 void checkSubframeCountConsistency() const { } 241 #endif 242 243 void setTimerAlignmentInterval(double); 244 245 void setNeedsLayoutInAllFrames(); 246 247 // SettingsDelegate overrides. 248 virtual void settingsChanged(SettingsDelegate::ChangeType) OVERRIDE; 249 250 PageAnimator m_animator; 251 const OwnPtr<AutoscrollController> m_autoscrollController; 252 const OwnPtr<Chrome> m_chrome; 253 const OwnPtrWillBeMember<DragCaretController> m_dragCaretController; 254 const OwnPtrWillBeMember<DragController> m_dragController; 255 const OwnPtr<FocusController> m_focusController; 256 const OwnPtr<ContextMenuController> m_contextMenuController; 257 const OwnPtr<InspectorController> m_inspectorController; 258 const OwnPtrWillBeMember<PointerLockController> m_pointerLockController; 259 OwnPtr<ScrollingCoordinator> m_scrollingCoordinator; 260 const OwnPtrWillBeMember<UndoStack> m_undoStack; 261 262 // Typically, the main frame and Page should both be owned by the embedder, 263 // which must call Page::willBeDestroyed() prior to destroying Page. This 264 // call detaches the main frame and clears this pointer, thus ensuring that 265 // this field only references a live main frame. 266 // 267 // However, there are several locations (InspectorOverlay, SVGImage, and 268 // WebPagePopupImpl) which don't hold a reference to the main frame at all 269 // after creating it. These are still safe because they always create a 270 // Frame with a FrameView. FrameView and Frame hold references to each 271 // other, thus keeping each other alive. The call to willBeDestroyed() 272 // breaks this cycle, so the frame is still properly destroyed once no 273 // longer needed. 274 Frame* m_mainFrame; 275 276 mutable RefPtr<PluginData> m_pluginData; 277 278 BackForwardClient* m_backForwardClient; 279 EditorClient* const m_editorClient; 280 SpellCheckerClient* const m_spellCheckerClient; 281 StorageClient* m_storageClient; 282 OwnPtrWillBeMember<ValidationMessageClient> m_validationMessageClient; 283 284 UseCounter m_useCounter; 285 286 int m_subframeCount; 287 bool m_openedByDOM; 288 289 bool m_tabKeyCyclesThroughElements; 290 bool m_defersLoading; 291 292 float m_deviceScaleFactor; 293 294 OwnPtr<StorageNamespace> m_sessionStorage; 295 296 double m_timerAlignmentInterval; 297 298 PageVisibilityState m_visibilityState; 299 300 bool m_isCursorVisible; 301 302 #ifndef NDEBUG 303 bool m_isPainting; 304 #endif 305 306 WillBeHeapHashSet<RawPtrWillBeWeakMember<MultisamplingChangedObserver> > m_multisamplingChangedObservers; 307 308 // A pointer to all the interfaces provided to in-process Frames for this Page. 309 // FIXME: Most of the members of Page should move onto FrameHost. 310 OwnPtrWillBeMember<FrameHost> m_frameHost; 311 }; 312 313 } // namespace WebCore 314 315 #endif // Page_h 316