| 1 | /* |
| 2 | * Copyright (C) 2006-2018 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 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 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #pragma once |
| 30 | |
| 31 | #include "AdClickAttribution.h" |
| 32 | #include "BackForwardItemIdentifier.h" |
| 33 | #include "FrameLoaderTypes.h" |
| 34 | #include "LayoutPoint.h" |
| 35 | #include "ResourceRequest.h" |
| 36 | #include "SecurityOrigin.h" |
| 37 | #include "UserGestureIndicator.h" |
| 38 | #include <wtf/Forward.h> |
| 39 | #include <wtf/Optional.h> |
| 40 | |
| 41 | namespace WebCore { |
| 42 | |
| 43 | class Document; |
| 44 | class Event; |
| 45 | class HistoryItem; |
| 46 | class MouseEvent; |
| 47 | class UIEventWithKeyState; |
| 48 | |
| 49 | // NavigationAction should never hold a strong reference to the originating document either directly |
| 50 | // or indirectly as doing so prevents its destruction even after navigating away from it because |
| 51 | // DocumentLoader keeps around the NavigationAction for the last navigation. |
| 52 | class NavigationAction { |
| 53 | public: |
| 54 | NavigationAction(); |
| 55 | WEBCORE_EXPORT NavigationAction(Document&, const ResourceRequest&, InitiatedByMainFrame, NavigationType = NavigationType::Other, ShouldOpenExternalURLsPolicy = ShouldOpenExternalURLsPolicy::ShouldNotAllow, Event* = nullptr, const AtomicString& downloadAttribute = nullAtom()); |
| 56 | NavigationAction(Document&, const ResourceRequest&, InitiatedByMainFrame, FrameLoadType, bool isFormSubmission, Event* = nullptr, ShouldOpenExternalURLsPolicy = ShouldOpenExternalURLsPolicy::ShouldNotAllow, const AtomicString& downloadAttribute = nullAtom()); |
| 57 | |
| 58 | WEBCORE_EXPORT ~NavigationAction(); |
| 59 | |
| 60 | WEBCORE_EXPORT NavigationAction(const NavigationAction&); |
| 61 | NavigationAction& operator=(const NavigationAction&); |
| 62 | |
| 63 | NavigationAction(NavigationAction&&); |
| 64 | NavigationAction& operator=(NavigationAction&&); |
| 65 | |
| 66 | using PageIDAndFrameIDPair = std::pair<uint64_t /* pageID */, uint64_t /* frameID */>; |
| 67 | class Requester { |
| 68 | public: |
| 69 | Requester(const Document&); |
| 70 | |
| 71 | const URL& url() const { return m_url; } |
| 72 | const SecurityOrigin& securityOrigin() const { return *m_origin; } |
| 73 | uint64_t pageID() const { return m_pageIDAndFrameIDPair.first; } |
| 74 | uint64_t frameID() const { return m_pageIDAndFrameIDPair.second; } |
| 75 | private: |
| 76 | URL m_url; |
| 77 | RefPtr<SecurityOrigin> m_origin; |
| 78 | PageIDAndFrameIDPair m_pageIDAndFrameIDPair; |
| 79 | }; |
| 80 | const Optional<Requester>& requester() const { return m_requester; } |
| 81 | |
| 82 | struct UIEventWithKeyStateData { |
| 83 | UIEventWithKeyStateData(const UIEventWithKeyState&); |
| 84 | |
| 85 | bool isTrusted; |
| 86 | bool shiftKey; |
| 87 | bool ctrlKey; |
| 88 | bool altKey; |
| 89 | bool metaKey; |
| 90 | }; |
| 91 | struct MouseEventData : UIEventWithKeyStateData { |
| 92 | MouseEventData(const MouseEvent&); |
| 93 | |
| 94 | LayoutPoint absoluteLocation; |
| 95 | FloatPoint locationInRootViewCoordinates; |
| 96 | unsigned short button; |
| 97 | unsigned short syntheticClickType; |
| 98 | bool buttonDown; |
| 99 | }; |
| 100 | const Optional<UIEventWithKeyStateData>& keyStateEventData() const { return m_keyStateEventData; } |
| 101 | const Optional<MouseEventData>& mouseEventData() const { return m_mouseEventData; } |
| 102 | |
| 103 | NavigationAction copyWithShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy) const; |
| 104 | |
| 105 | bool isEmpty() const { return !m_requester || m_requester->url().isEmpty() || m_resourceRequest.url().isEmpty(); } |
| 106 | |
| 107 | URL url() const { return m_resourceRequest.url(); } |
| 108 | const ResourceRequest& resourceRequest() const { return m_resourceRequest; } |
| 109 | |
| 110 | NavigationType type() const { return m_type; } |
| 111 | |
| 112 | bool processingUserGesture() const { return m_userGestureToken ? m_userGestureToken->processingUserGesture() : false; } |
| 113 | RefPtr<UserGestureToken> userGestureToken() const { return m_userGestureToken; } |
| 114 | |
| 115 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy() const { return m_shouldOpenExternalURLsPolicy; } |
| 116 | void setShouldOpenExternalURLsPolicy(ShouldOpenExternalURLsPolicy policy) { m_shouldOpenExternalURLsPolicy = policy; } |
| 117 | InitiatedByMainFrame initiatedByMainFrame() const { return m_initiatedByMainFrame; } |
| 118 | |
| 119 | const AtomicString& downloadAttribute() const { return m_downloadAttribute; } |
| 120 | |
| 121 | bool treatAsSameOriginNavigation() const { return m_treatAsSameOriginNavigation; } |
| 122 | |
| 123 | bool hasOpenedFrames() const { return m_hasOpenedFrames; } |
| 124 | void setHasOpenedFrames(bool value) { m_hasOpenedFrames = value; } |
| 125 | |
| 126 | bool openedByDOMWithOpener() const { return m_openedByDOMWithOpener; } |
| 127 | void setOpenedByDOMWithOpener() { m_openedByDOMWithOpener = true; } |
| 128 | |
| 129 | void setTargetBackForwardItem(HistoryItem&); |
| 130 | const Optional<BackForwardItemIdentifier>& targetBackForwardItemIdentifier() const { return m_targetBackForwardItemIdentifier; } |
| 131 | |
| 132 | void setSourceBackForwardItem(HistoryItem*); |
| 133 | const Optional<BackForwardItemIdentifier>& sourceBackForwardItemIdentifier() const { return m_sourceBackForwardItemIdentifier; } |
| 134 | |
| 135 | LockHistory lockHistory() const { return m_lockHistory; } |
| 136 | void setLockHistory(LockHistory lockHistory) { m_lockHistory = lockHistory; } |
| 137 | |
| 138 | LockBackForwardList lockBackForwardList() const { return m_lockBackForwardList; } |
| 139 | void setLockBackForwardList(LockBackForwardList lockBackForwardList) { m_lockBackForwardList = lockBackForwardList; } |
| 140 | |
| 141 | const Optional<AdClickAttribution>& adClickAttribution() const { return m_adClickAttribution; }; |
| 142 | void setAdClickAttribution(AdClickAttribution&& adClickAttribution) { m_adClickAttribution = adClickAttribution; }; |
| 143 | |
| 144 | private: |
| 145 | // Do not add a strong reference to the originating document or a subobject that holds the |
| 146 | // originating document. See comment above the class for more details. |
| 147 | Optional<Requester> m_requester; |
| 148 | ResourceRequest m_resourceRequest; |
| 149 | NavigationType m_type; |
| 150 | ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy; |
| 151 | InitiatedByMainFrame m_initiatedByMainFrame; |
| 152 | Optional<UIEventWithKeyStateData> m_keyStateEventData; |
| 153 | Optional<MouseEventData> m_mouseEventData; |
| 154 | RefPtr<UserGestureToken> m_userGestureToken { UserGestureIndicator::currentUserGesture() }; |
| 155 | AtomicString m_downloadAttribute; |
| 156 | bool m_treatAsSameOriginNavigation; |
| 157 | bool m_hasOpenedFrames { false }; |
| 158 | bool m_openedByDOMWithOpener { false }; |
| 159 | Optional<BackForwardItemIdentifier> m_targetBackForwardItemIdentifier; |
| 160 | Optional<BackForwardItemIdentifier> m_sourceBackForwardItemIdentifier; |
| 161 | LockHistory m_lockHistory { LockHistory::No }; |
| 162 | LockBackForwardList m_lockBackForwardList { LockBackForwardList::No }; |
| 163 | Optional<AdClickAttribution> m_adClickAttribution; |
| 164 | }; |
| 165 | |
| 166 | } // namespace WebCore |
| 167 | |