NavigateEvent.h (5334B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_NavigateEvent_h___ 8 #define mozilla_dom_NavigateEvent_h___ 9 10 #include "js/RootingAPI.h" 11 #include "js/Value.h" 12 #include "mozilla/AlreadyAddRefed.h" 13 #include "mozilla/RefPtr.h" 14 #include "mozilla/dom/AbortController.h" 15 #include "mozilla/dom/BindingDeclarations.h" 16 #include "mozilla/dom/Event.h" 17 #include "mozilla/dom/NavigateEventBinding.h" 18 #include "mozilla/dom/NavigationPrecommitControllerBinding.h" 19 #include "nsCycleCollectionParticipant.h" 20 21 namespace mozilla::dom { 22 23 class AbortController; 24 class AbortSignal; 25 class FormData; 26 class NavigationDestination; 27 struct NavigationInterceptOptions; 28 29 enum class NavigationType : uint8_t; 30 31 // https://html.spec.whatwg.org/#the-navigateevent-interface 32 class NavigateEvent final : public Event { 33 public: 34 NS_DECL_ISUPPORTS_INHERITED 35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(NavigateEvent, Event) 36 37 virtual JSObject* WrapObjectInternal( 38 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; 39 40 static already_AddRefed<NavigateEvent> Constructor( 41 const GlobalObject& aGlobal, const nsAString& aType, 42 const NavigateEventInit& aEventInitDict); 43 44 static already_AddRefed<NavigateEvent> Constructor( 45 EventTarget* aEventTarget, const nsAString& aType, 46 const NavigateEventInit& aEventInitDict); 47 48 static already_AddRefed<NavigateEvent> Constructor( 49 EventTarget* aEventTarget, const nsAString& aType, 50 const NavigateEventInit& aEventInitDict, 51 nsIStructuredCloneContainer* aClassicHistoryAPIState, 52 AbortController* aAbortController); 53 54 enum NavigationType NavigationType() const; 55 56 void SetNavigationType(enum NavigationType aNavigationType); 57 58 already_AddRefed<NavigationDestination> Destination() const; 59 60 bool CanIntercept() const; 61 62 bool UserInitiated() const; 63 64 bool HashChange() const; 65 66 AbortSignal* Signal() const; 67 68 already_AddRefed<FormData> GetFormData() const; 69 70 void GetDownloadRequest(nsAString& aDownloadRequest) const; 71 72 void GetInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aInfo) const; 73 74 void SetInfo(JS::Value aInfo) { mInfo = aInfo; } 75 76 bool HasUAVisualTransition() const; 77 78 Element* GetSourceElement() const; 79 80 void Intercept(const NavigationInterceptOptions& aOptions, ErrorResult& aRv); 81 82 MOZ_CAN_RUN_SCRIPT 83 void Scroll(ErrorResult& aRv); 84 85 void InitNavigateEvent(const NavigateEventInit& aEventInitDict); 86 87 void SetCanIntercept(bool aCanIntercept); 88 89 enum class InterceptionState : uint8_t { 90 None, 91 Intercepted, 92 Committed, 93 Scrolled, 94 Finished 95 }; 96 97 InterceptionState InterceptionState() const; 98 99 void SetInterceptionState(enum InterceptionState aInterceptionState); 100 101 nsIStructuredCloneContainer* ClassicHistoryAPIState() const; 102 103 nsTArray<RefPtr<NavigationInterceptHandler>>& NavigationHandlerList(); 104 105 dom::AbortController* AbortController() const; 106 107 bool IsBeingDispatched() const; 108 109 MOZ_CAN_RUN_SCRIPT 110 void Finish(bool aDidFulfill); 111 112 nsTArray<RefPtr<NavigationPrecommitHandler>>& 113 NavigationPrecommitHandlerList() { 114 return mNavigationPrecommitHandlerList; 115 } 116 117 void PerformSharedChecks(ErrorResult& aRv); 118 119 Document* GetAssociatedDocument() const; 120 121 private: 122 MOZ_CAN_RUN_SCRIPT 123 void PotentiallyResetFocus(); 124 125 MOZ_CAN_RUN_SCRIPT 126 void PotentiallyProcessScrollBehavior(); 127 128 MOZ_CAN_RUN_SCRIPT 129 void ProcessScrollBehavior(); 130 131 explicit NavigateEvent(EventTarget* aOwner); 132 ~NavigateEvent(); 133 134 enum NavigationType mNavigationType {}; 135 RefPtr<NavigationDestination> mDestination; 136 bool mCanIntercept = false; 137 bool mUserInitiated = false; 138 bool mHashChange = false; 139 RefPtr<AbortSignal> mSignal; 140 RefPtr<FormData> mFormData; 141 nsString mDownloadRequest; 142 JS::Heap<JS::Value> mInfo; 143 bool mHasUAVisualTransition = false; 144 RefPtr<Element> mSourceElement; 145 uint32_t mLastScrollGeneration = 0; 146 147 nsTArray<RefPtr<NavigationPrecommitHandler>> mNavigationPrecommitHandlerList; 148 149 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-2 150 enum InterceptionState mInterceptionState = InterceptionState::None; 151 152 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-3 153 nsTArray<RefPtr<NavigationInterceptHandler>> mNavigationHandlerList; 154 155 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-4 156 Maybe<NavigationFocusReset> mFocusResetBehavior; 157 158 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-5 159 Maybe<NavigationScrollBehavior> mScrollBehavior; 160 161 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-6 162 RefPtr<dom::AbortController> mAbortController; 163 164 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-7 165 nsCOMPtr<nsIStructuredCloneContainer> mClassicHistoryAPIState; 166 }; 167 168 } // namespace mozilla::dom 169 170 #endif // mozilla_dom_NavigateEvent_h___