| 1 | /* |
| 2 | * Copyright (C) 2006, 2008, 2011, 2014 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2012 Research In Motion Limited. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #include "BackForwardItemIdentifier.h" |
| 30 | #include "FloatRect.h" |
| 31 | #include "FrameLoaderTypes.h" |
| 32 | #include "IntPoint.h" |
| 33 | #include "IntRect.h" |
| 34 | #include "LengthBox.h" |
| 35 | #include "SerializedScriptValue.h" |
| 36 | #include <memory> |
| 37 | #include <wtf/RefCounted.h> |
| 38 | #include <wtf/text/WTFString.h> |
| 39 | |
| 40 | #if PLATFORM(IOS_FAMILY) |
| 41 | #include "ViewportArguments.h" |
| 42 | #endif |
| 43 | |
| 44 | #if PLATFORM(COCOA) |
| 45 | #import <wtf/RetainPtr.h> |
| 46 | typedef struct objc_object* id; |
| 47 | #endif |
| 48 | |
| 49 | namespace WebCore { |
| 50 | |
| 51 | class CachedPage; |
| 52 | class Document; |
| 53 | class FormData; |
| 54 | class HistoryItem; |
| 55 | class Image; |
| 56 | class ResourceRequest; |
| 57 | enum class PruningReason; |
| 58 | |
| 59 | WEBCORE_EXPORT extern void (*notifyHistoryItemChanged)(HistoryItem&); |
| 60 | |
| 61 | class HistoryItem : public RefCounted<HistoryItem> { |
| 62 | friend class PageCache; |
| 63 | |
| 64 | public: |
| 65 | static Ref<HistoryItem> create() |
| 66 | { |
| 67 | return adoptRef(*new HistoryItem); |
| 68 | } |
| 69 | |
| 70 | static Ref<HistoryItem> create(const String& urlString, const String& title) |
| 71 | { |
| 72 | return adoptRef(*new HistoryItem(urlString, title)); |
| 73 | } |
| 74 | |
| 75 | static Ref<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle) |
| 76 | { |
| 77 | return adoptRef(*new HistoryItem(urlString, title, alternateTitle)); |
| 78 | } |
| 79 | |
| 80 | static Ref<HistoryItem> create(const String& urlString, const String& title, const String& alternateTitle, BackForwardItemIdentifier identifier) |
| 81 | { |
| 82 | return adoptRef(*new HistoryItem(urlString, title, alternateTitle, identifier)); |
| 83 | } |
| 84 | |
| 85 | WEBCORE_EXPORT ~HistoryItem(); |
| 86 | |
| 87 | WEBCORE_EXPORT Ref<HistoryItem> copy() const; |
| 88 | |
| 89 | const BackForwardItemIdentifier& identifier() const { return m_identifier; } |
| 90 | |
| 91 | // Resets the HistoryItem to its initial state, as returned by create(). |
| 92 | void reset(); |
| 93 | |
| 94 | WEBCORE_EXPORT const String& originalURLString() const; |
| 95 | WEBCORE_EXPORT const String& urlString() const; |
| 96 | WEBCORE_EXPORT const String& title() const; |
| 97 | |
| 98 | bool isInPageCache() const { return m_cachedPage.get(); } |
| 99 | WEBCORE_EXPORT bool hasCachedPageExpired() const; |
| 100 | |
| 101 | WEBCORE_EXPORT void setAlternateTitle(const String&); |
| 102 | WEBCORE_EXPORT const String& alternateTitle() const; |
| 103 | |
| 104 | WEBCORE_EXPORT URL url() const; |
| 105 | WEBCORE_EXPORT URL originalURL() const; |
| 106 | WEBCORE_EXPORT const String& referrer() const; |
| 107 | WEBCORE_EXPORT const String& target() const; |
| 108 | WEBCORE_EXPORT bool isTargetItem() const; |
| 109 | |
| 110 | WEBCORE_EXPORT FormData* formData(); |
| 111 | WEBCORE_EXPORT String formContentType() const; |
| 112 | |
| 113 | bool lastVisitWasFailure() const { return m_lastVisitWasFailure; } |
| 114 | |
| 115 | WEBCORE_EXPORT const IntPoint& scrollPosition() const; |
| 116 | WEBCORE_EXPORT void setScrollPosition(const IntPoint&); |
| 117 | void clearScrollPosition(); |
| 118 | |
| 119 | WEBCORE_EXPORT bool shouldRestoreScrollPosition() const; |
| 120 | WEBCORE_EXPORT void setShouldRestoreScrollPosition(bool); |
| 121 | |
| 122 | WEBCORE_EXPORT float pageScaleFactor() const; |
| 123 | WEBCORE_EXPORT void setPageScaleFactor(float); |
| 124 | |
| 125 | WEBCORE_EXPORT const Vector<String>& documentState() const; |
| 126 | WEBCORE_EXPORT void setDocumentState(const Vector<String>&); |
| 127 | void clearDocumentState(); |
| 128 | |
| 129 | WEBCORE_EXPORT void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy); |
| 130 | WEBCORE_EXPORT ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const; |
| 131 | |
| 132 | void setURL(const URL&); |
| 133 | WEBCORE_EXPORT void setURLString(const String&); |
| 134 | WEBCORE_EXPORT void setOriginalURLString(const String&); |
| 135 | WEBCORE_EXPORT void setReferrer(const String&); |
| 136 | WEBCORE_EXPORT void setTarget(const String&); |
| 137 | WEBCORE_EXPORT void setTitle(const String&); |
| 138 | WEBCORE_EXPORT void setIsTargetItem(bool); |
| 139 | |
| 140 | WEBCORE_EXPORT void setStateObject(RefPtr<SerializedScriptValue>&&); |
| 141 | SerializedScriptValue* stateObject() const { return m_stateObject.get(); } |
| 142 | |
| 143 | void setItemSequenceNumber(long long number) { m_itemSequenceNumber = number; } |
| 144 | long long itemSequenceNumber() const { return m_itemSequenceNumber; } |
| 145 | |
| 146 | void setDocumentSequenceNumber(long long number) { m_documentSequenceNumber = number; } |
| 147 | long long documentSequenceNumber() const { return m_documentSequenceNumber; } |
| 148 | |
| 149 | void setFormInfoFromRequest(const ResourceRequest&); |
| 150 | WEBCORE_EXPORT void setFormData(RefPtr<FormData>&&); |
| 151 | WEBCORE_EXPORT void setFormContentType(const String&); |
| 152 | |
| 153 | void setLastVisitWasFailure(bool wasFailure) { m_lastVisitWasFailure = wasFailure; } |
| 154 | |
| 155 | WEBCORE_EXPORT void addChildItem(Ref<HistoryItem>&&); |
| 156 | void setChildItem(Ref<HistoryItem>&&); |
| 157 | WEBCORE_EXPORT HistoryItem* childItemWithTarget(const String&); |
| 158 | HistoryItem* childItemWithDocumentSequenceNumber(long long number); |
| 159 | WEBCORE_EXPORT const Vector<Ref<HistoryItem>>& children() const; |
| 160 | WEBCORE_EXPORT bool hasChildren() const; |
| 161 | void clearChildren(); |
| 162 | |
| 163 | bool shouldDoSameDocumentNavigationTo(HistoryItem& otherItem) const; |
| 164 | bool hasSameFrames(HistoryItem& otherItem) const; |
| 165 | |
| 166 | bool isCurrentDocument(Document&) const; |
| 167 | |
| 168 | #if PLATFORM(COCOA) |
| 169 | WEBCORE_EXPORT id viewState() const; |
| 170 | WEBCORE_EXPORT void setViewState(id); |
| 171 | #endif |
| 172 | |
| 173 | #ifndef NDEBUG |
| 174 | int showTree() const; |
| 175 | int showTreeWithIndent(unsigned indentLevel) const; |
| 176 | #endif |
| 177 | |
| 178 | #if PLATFORM(IOS_FAMILY) |
| 179 | FloatRect exposedContentRect() const { return m_exposedContentRect; } |
| 180 | void setExposedContentRect(FloatRect exposedContentRect) { m_exposedContentRect = exposedContentRect; } |
| 181 | |
| 182 | IntRect unobscuredContentRect() const { return m_unobscuredContentRect; } |
| 183 | void setUnobscuredContentRect(IntRect unobscuredContentRect) { m_unobscuredContentRect = unobscuredContentRect; } |
| 184 | |
| 185 | const FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; } |
| 186 | void setObscuredInsets(const FloatBoxExtent& insets) { m_obscuredInsets = insets; } |
| 187 | |
| 188 | FloatSize minimumLayoutSizeInScrollViewCoordinates() const { return m_minimumLayoutSizeInScrollViewCoordinates; } |
| 189 | void setMinimumLayoutSizeInScrollViewCoordinates(FloatSize minimumLayoutSizeInScrollViewCoordinates) { m_minimumLayoutSizeInScrollViewCoordinates = minimumLayoutSizeInScrollViewCoordinates; } |
| 190 | |
| 191 | IntSize contentSize() const { return m_contentSize; } |
| 192 | void setContentSize(IntSize contentSize) { m_contentSize = contentSize; } |
| 193 | |
| 194 | float scale() const { return m_scale; } |
| 195 | bool scaleIsInitial() const { return m_scaleIsInitial; } |
| 196 | void setScaleIsInitial(bool scaleIsInitial) { m_scaleIsInitial = scaleIsInitial; } |
| 197 | void setScale(float newScale, bool isInitial) |
| 198 | { |
| 199 | m_scale = newScale; |
| 200 | m_scaleIsInitial = isInitial; |
| 201 | } |
| 202 | |
| 203 | const ViewportArguments& viewportArguments() const { return m_viewportArguments; } |
| 204 | void setViewportArguments(const ViewportArguments& viewportArguments) { m_viewportArguments = viewportArguments; } |
| 205 | #endif |
| 206 | |
| 207 | void notifyChanged(); |
| 208 | |
| 209 | void setWasRestoredFromSession(bool wasRestoredFromSession) { m_wasRestoredFromSession = wasRestoredFromSession; } |
| 210 | bool wasRestoredFromSession() const { return m_wasRestoredFromSession; } |
| 211 | |
| 212 | #if !LOG_DISABLED |
| 213 | const char* logString() const; |
| 214 | #endif |
| 215 | |
| 216 | private: |
| 217 | WEBCORE_EXPORT HistoryItem(); |
| 218 | WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title); |
| 219 | WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title, const String& alternateTitle); |
| 220 | WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title, const String& alternateTitle, BackForwardItemIdentifier); |
| 221 | |
| 222 | HistoryItem(const HistoryItem&); |
| 223 | |
| 224 | static int64_t generateSequenceNumber(); |
| 225 | |
| 226 | bool hasSameDocumentTree(HistoryItem& otherItem) const; |
| 227 | |
| 228 | String m_urlString; |
| 229 | String m_originalURLString; |
| 230 | String m_referrer; |
| 231 | String m_target; |
| 232 | String m_title; |
| 233 | String m_displayTitle; |
| 234 | |
| 235 | IntPoint m_scrollPosition; |
| 236 | float m_pageScaleFactor { 0 }; // 0 indicates "unset". |
| 237 | Vector<String> m_documentState; |
| 238 | |
| 239 | ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow }; |
| 240 | |
| 241 | Vector<Ref<HistoryItem>> m_children; |
| 242 | |
| 243 | bool m_lastVisitWasFailure { false }; |
| 244 | bool m_isTargetItem { false }; |
| 245 | bool m_wasRestoredFromSession { false }; |
| 246 | bool m_shouldRestoreScrollPosition { true }; |
| 247 | |
| 248 | // If two HistoryItems have the same item sequence number, then they are |
| 249 | // clones of one another. Traversing history from one such HistoryItem to |
| 250 | // another is a no-op. HistoryItem clones are created for parent and |
| 251 | // sibling frames when only a subframe navigates. |
| 252 | int64_t m_itemSequenceNumber { generateSequenceNumber() }; |
| 253 | |
| 254 | // If two HistoryItems have the same document sequence number, then they |
| 255 | // refer to the same instance of a document. Traversing history from one |
| 256 | // such HistoryItem to another preserves the document. |
| 257 | int64_t m_documentSequenceNumber { generateSequenceNumber() }; |
| 258 | |
| 259 | // Support for HTML5 History |
| 260 | RefPtr<SerializedScriptValue> m_stateObject; |
| 261 | |
| 262 | // info used to repost form data |
| 263 | RefPtr<FormData> m_formData; |
| 264 | String m_formContentType; |
| 265 | |
| 266 | // PageCache controls these fields. |
| 267 | std::unique_ptr<CachedPage> m_cachedPage; |
| 268 | PruningReason m_pruningReason; |
| 269 | |
| 270 | #if PLATFORM(IOS_FAMILY) |
| 271 | FloatRect m_exposedContentRect; |
| 272 | IntRect m_unobscuredContentRect; |
| 273 | FloatSize m_minimumLayoutSizeInScrollViewCoordinates; |
| 274 | IntSize m_contentSize; |
| 275 | FloatBoxExtent m_obscuredInsets; |
| 276 | float m_scale { 0 }; // Note that UIWebView looks for a non-zero value, so this has to start as 0. |
| 277 | bool m_scaleIsInitial { false }; |
| 278 | ViewportArguments m_viewportArguments; |
| 279 | #endif |
| 280 | |
| 281 | #if PLATFORM(COCOA) |
| 282 | RetainPtr<id> m_viewState; |
| 283 | #endif |
| 284 | |
| 285 | BackForwardItemIdentifier m_identifier; |
| 286 | }; |
| 287 | |
| 288 | } // namespace WebCore |
| 289 | |
| 290 | #if ENABLE(TREE_DEBUGGING) |
| 291 | // Outside the WebCore namespace for ease of invocation from the debugger. |
| 292 | extern "C" int showTree(const WebCore::HistoryItem*); |
| 293 | #endif |
| 294 | |