Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef mozilla_dom_Event_h_ |
michael@0 | 7 | #define mozilla_dom_Event_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "mozilla/BasicEvents.h" |
michael@0 | 11 | #include "nsIDOMEvent.h" |
michael@0 | 12 | #include "nsISupports.h" |
michael@0 | 13 | #include "nsCOMPtr.h" |
michael@0 | 14 | #include "nsPIDOMWindow.h" |
michael@0 | 15 | #include "nsPoint.h" |
michael@0 | 16 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 17 | #include "nsAutoPtr.h" |
michael@0 | 18 | #include "mozilla/dom/EventBinding.h" |
michael@0 | 19 | #include "nsIScriptGlobalObject.h" |
michael@0 | 20 | #include "Units.h" |
michael@0 | 21 | #include "js/TypeDecls.h" |
michael@0 | 22 | |
michael@0 | 23 | class nsIContent; |
michael@0 | 24 | class nsIDOMEventTarget; |
michael@0 | 25 | class nsPresContext; |
michael@0 | 26 | |
michael@0 | 27 | namespace mozilla { |
michael@0 | 28 | namespace dom { |
michael@0 | 29 | |
michael@0 | 30 | class EventTarget; |
michael@0 | 31 | class ErrorEvent; |
michael@0 | 32 | |
michael@0 | 33 | // Dummy class so we can cast through it to get from nsISupports to |
michael@0 | 34 | // Event subclasses with only two non-ambiguous static casts. |
michael@0 | 35 | class EventBase : public nsIDOMEvent |
michael@0 | 36 | { |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | class Event : public EventBase, |
michael@0 | 40 | public nsWrapperCache |
michael@0 | 41 | { |
michael@0 | 42 | public: |
michael@0 | 43 | Event(EventTarget* aOwner, |
michael@0 | 44 | nsPresContext* aPresContext, |
michael@0 | 45 | WidgetEvent* aEvent); |
michael@0 | 46 | Event(nsPIDOMWindow* aWindow); |
michael@0 | 47 | virtual ~Event(); |
michael@0 | 48 | |
michael@0 | 49 | private: |
michael@0 | 50 | void ConstructorInit(EventTarget* aOwner, |
michael@0 | 51 | nsPresContext* aPresContext, |
michael@0 | 52 | WidgetEvent* aEvent); |
michael@0 | 53 | |
michael@0 | 54 | public: |
michael@0 | 55 | void GetParentObject(nsIScriptGlobalObject** aParentObject) |
michael@0 | 56 | { |
michael@0 | 57 | if (mOwner) { |
michael@0 | 58 | CallQueryInterface(mOwner, aParentObject); |
michael@0 | 59 | } else { |
michael@0 | 60 | *aParentObject = nullptr; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | static Event* FromSupports(nsISupports* aSupports) |
michael@0 | 65 | { |
michael@0 | 66 | nsIDOMEvent* event = |
michael@0 | 67 | static_cast<nsIDOMEvent*>(aSupports); |
michael@0 | 68 | #ifdef DEBUG |
michael@0 | 69 | { |
michael@0 | 70 | nsCOMPtr<nsIDOMEvent> target_qi = |
michael@0 | 71 | do_QueryInterface(aSupports); |
michael@0 | 72 | |
michael@0 | 73 | // If this assertion fires the QI implementation for the object in |
michael@0 | 74 | // question doesn't use the nsIDOMEvent pointer as the |
michael@0 | 75 | // nsISupports pointer. That must be fixed, or we'll crash... |
michael@0 | 76 | MOZ_ASSERT(target_qi == event, "Uh, fix QI!"); |
michael@0 | 77 | } |
michael@0 | 78 | #endif |
michael@0 | 79 | return static_cast<Event*>(event); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 83 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Event) |
michael@0 | 84 | |
michael@0 | 85 | nsISupports* GetParentObject() |
michael@0 | 86 | { |
michael@0 | 87 | return mOwner; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
michael@0 | 91 | { |
michael@0 | 92 | return EventBinding::Wrap(aCx, this); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | virtual ErrorEvent* AsErrorEvent() |
michael@0 | 96 | { |
michael@0 | 97 | return nullptr; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | // nsIDOMEvent Interface |
michael@0 | 101 | NS_DECL_NSIDOMEVENT |
michael@0 | 102 | |
michael@0 | 103 | void InitPresContextData(nsPresContext* aPresContext); |
michael@0 | 104 | |
michael@0 | 105 | // Returns true if the event should be trusted. |
michael@0 | 106 | bool Init(EventTarget* aGlobal); |
michael@0 | 107 | |
michael@0 | 108 | static PopupControlState GetEventPopupControlState(WidgetEvent* aEvent); |
michael@0 | 109 | |
michael@0 | 110 | static void PopupAllowedEventsChanged(); |
michael@0 | 111 | |
michael@0 | 112 | static void Shutdown(); |
michael@0 | 113 | |
michael@0 | 114 | static const char* GetEventName(uint32_t aEventType); |
michael@0 | 115 | static CSSIntPoint GetClientCoords(nsPresContext* aPresContext, |
michael@0 | 116 | WidgetEvent* aEvent, |
michael@0 | 117 | LayoutDeviceIntPoint aPoint, |
michael@0 | 118 | CSSIntPoint aDefaultPoint); |
michael@0 | 119 | static CSSIntPoint GetPageCoords(nsPresContext* aPresContext, |
michael@0 | 120 | WidgetEvent* aEvent, |
michael@0 | 121 | LayoutDeviceIntPoint aPoint, |
michael@0 | 122 | CSSIntPoint aDefaultPoint); |
michael@0 | 123 | static nsIntPoint GetScreenCoords(nsPresContext* aPresContext, |
michael@0 | 124 | WidgetEvent* aEvent, |
michael@0 | 125 | LayoutDeviceIntPoint aPoint); |
michael@0 | 126 | |
michael@0 | 127 | static already_AddRefed<Event> Constructor(const GlobalObject& aGlobal, |
michael@0 | 128 | const nsAString& aType, |
michael@0 | 129 | const EventInit& aParam, |
michael@0 | 130 | ErrorResult& aRv); |
michael@0 | 131 | |
michael@0 | 132 | // Implemented as xpidl method |
michael@0 | 133 | // void GetType(nsString& aRetval) {} |
michael@0 | 134 | |
michael@0 | 135 | EventTarget* GetTarget() const; |
michael@0 | 136 | EventTarget* GetCurrentTarget() const; |
michael@0 | 137 | |
michael@0 | 138 | uint16_t EventPhase() const; |
michael@0 | 139 | |
michael@0 | 140 | // xpidl implementation |
michael@0 | 141 | // void StopPropagation(); |
michael@0 | 142 | |
michael@0 | 143 | // xpidl implementation |
michael@0 | 144 | // void StopImmediatePropagation(); |
michael@0 | 145 | |
michael@0 | 146 | bool Bubbles() const |
michael@0 | 147 | { |
michael@0 | 148 | return mEvent->mFlags.mBubbles; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | bool Cancelable() const |
michael@0 | 152 | { |
michael@0 | 153 | return mEvent->mFlags.mCancelable; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | // xpidl implementation |
michael@0 | 157 | // void PreventDefault(); |
michael@0 | 158 | |
michael@0 | 159 | // You MUST NOT call PreventDefaultJ(JSContext*) from C++ code. A call of |
michael@0 | 160 | // this method always sets Event.defaultPrevented true for web contents. |
michael@0 | 161 | // If default action handler calls this, web applications meet wrong |
michael@0 | 162 | // defaultPrevented value. |
michael@0 | 163 | void PreventDefault(JSContext* aCx); |
michael@0 | 164 | |
michael@0 | 165 | // You MUST NOT call DefaultPrevented(JSContext*) from C++ code. This may |
michael@0 | 166 | // return false even if PreventDefault() has been called. |
michael@0 | 167 | // See comments in its implementation for the detail. |
michael@0 | 168 | bool DefaultPrevented(JSContext* aCx) const; |
michael@0 | 169 | |
michael@0 | 170 | bool DefaultPrevented() const |
michael@0 | 171 | { |
michael@0 | 172 | return mEvent->mFlags.mDefaultPrevented; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | bool MultipleActionsPrevented() const |
michael@0 | 176 | { |
michael@0 | 177 | return mEvent->mFlags.mMultipleActionsPrevented; |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | bool IsTrusted() const |
michael@0 | 181 | { |
michael@0 | 182 | return mEvent->mFlags.mIsTrusted; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | bool IsSynthesized() const |
michael@0 | 186 | { |
michael@0 | 187 | return mEvent->mFlags.mIsSynthesizedForTests; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | uint64_t TimeStamp() const |
michael@0 | 191 | { |
michael@0 | 192 | return mEvent->time; |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | void InitEvent(const nsAString& aType, bool aBubbles, bool aCancelable, |
michael@0 | 196 | ErrorResult& aRv) |
michael@0 | 197 | { |
michael@0 | 198 | aRv = InitEvent(aType, aBubbles, aCancelable); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | EventTarget* GetOriginalTarget() const; |
michael@0 | 202 | EventTarget* GetExplicitOriginalTarget() const; |
michael@0 | 203 | |
michael@0 | 204 | bool GetPreventDefault() const; |
michael@0 | 205 | |
michael@0 | 206 | /** |
michael@0 | 207 | * @param aCalledByDefaultHandler Should be true when this is called by |
michael@0 | 208 | * C++ or Chrome. Otherwise, e.g., called |
michael@0 | 209 | * by a call of Event.preventDefault() in |
michael@0 | 210 | * content script, false. |
michael@0 | 211 | */ |
michael@0 | 212 | void PreventDefaultInternal(bool aCalledByDefaultHandler); |
michael@0 | 213 | |
michael@0 | 214 | bool IsMainThreadEvent() |
michael@0 | 215 | { |
michael@0 | 216 | return mIsMainThreadEvent; |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | protected: |
michael@0 | 220 | |
michael@0 | 221 | // Internal helper functions |
michael@0 | 222 | void SetEventType(const nsAString& aEventTypeArg); |
michael@0 | 223 | already_AddRefed<nsIContent> GetTargetFromFrame(); |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * IsChrome() returns true if aCx is chrome context or the event is created |
michael@0 | 227 | * in chrome's thread. Otherwise, false. |
michael@0 | 228 | */ |
michael@0 | 229 | bool IsChrome(JSContext* aCx) const; |
michael@0 | 230 | |
michael@0 | 231 | mozilla::WidgetEvent* mEvent; |
michael@0 | 232 | nsRefPtr<nsPresContext> mPresContext; |
michael@0 | 233 | nsCOMPtr<EventTarget> mExplicitOriginalTarget; |
michael@0 | 234 | nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now. |
michael@0 | 235 | bool mEventIsInternal; |
michael@0 | 236 | bool mPrivateDataDuplicated; |
michael@0 | 237 | bool mIsMainThreadEvent; |
michael@0 | 238 | }; |
michael@0 | 239 | |
michael@0 | 240 | } // namespace dom |
michael@0 | 241 | } // namespace mozilla |
michael@0 | 242 | |
michael@0 | 243 | #define NS_FORWARD_TO_EVENT \ |
michael@0 | 244 | NS_FORWARD_NSIDOMEVENT(Event::) |
michael@0 | 245 | |
michael@0 | 246 | #define NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(_to) \ |
michael@0 | 247 | NS_IMETHOD GetType(nsAString& aType){ return _to GetType(aType); } \ |
michael@0 | 248 | NS_IMETHOD GetTarget(nsIDOMEventTarget * *aTarget) { return _to GetTarget(aTarget); } \ |
michael@0 | 249 | NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget * *aCurrentTarget) { return _to GetCurrentTarget(aCurrentTarget); } \ |
michael@0 | 250 | NS_IMETHOD GetEventPhase(uint16_t *aEventPhase) { return _to GetEventPhase(aEventPhase); } \ |
michael@0 | 251 | NS_IMETHOD GetBubbles(bool *aBubbles) { return _to GetBubbles(aBubbles); } \ |
michael@0 | 252 | NS_IMETHOD GetCancelable(bool *aCancelable) { return _to GetCancelable(aCancelable); } \ |
michael@0 | 253 | NS_IMETHOD GetTimeStamp(DOMTimeStamp *aTimeStamp) { return _to GetTimeStamp(aTimeStamp); } \ |
michael@0 | 254 | NS_IMETHOD StopPropagation(void) { return _to StopPropagation(); } \ |
michael@0 | 255 | NS_IMETHOD PreventDefault(void) { return _to PreventDefault(); } \ |
michael@0 | 256 | NS_IMETHOD InitEvent(const nsAString & eventTypeArg, bool canBubbleArg, bool cancelableArg) { return _to InitEvent(eventTypeArg, canBubbleArg, cancelableArg); } \ |
michael@0 | 257 | NS_IMETHOD GetDefaultPrevented(bool *aDefaultPrevented) { return _to GetDefaultPrevented(aDefaultPrevented); } \ |
michael@0 | 258 | NS_IMETHOD StopImmediatePropagation(void) { return _to StopImmediatePropagation(); } \ |
michael@0 | 259 | NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) { return _to GetOriginalTarget(aOriginalTarget); } \ |
michael@0 | 260 | NS_IMETHOD GetExplicitOriginalTarget(nsIDOMEventTarget** aExplicitOriginalTarget) { return _to GetExplicitOriginalTarget(aExplicitOriginalTarget); } \ |
michael@0 | 261 | NS_IMETHOD GetPreventDefault(bool* aRetval) { return _to GetPreventDefault(aRetval); } \ |
michael@0 | 262 | NS_IMETHOD GetIsTrusted(bool* aIsTrusted) { return _to GetIsTrusted(aIsTrusted); } \ |
michael@0 | 263 | NS_IMETHOD SetTarget(nsIDOMEventTarget *aTarget) { return _to SetTarget(aTarget); } \ |
michael@0 | 264 | NS_IMETHOD_(bool) IsDispatchStopped(void) { return _to IsDispatchStopped(); } \ |
michael@0 | 265 | NS_IMETHOD_(WidgetEvent*) GetInternalNSEvent(void) { return _to GetInternalNSEvent(); } \ |
michael@0 | 266 | NS_IMETHOD_(void) SetTrusted(bool aTrusted) { _to SetTrusted(aTrusted); } \ |
michael@0 | 267 | NS_IMETHOD_(void) SetOwner(EventTarget* aOwner) { _to SetOwner(aOwner); } \ |
michael@0 | 268 | NS_IMETHOD_(Event*) InternalDOMEvent() { return _to InternalDOMEvent(); } |
michael@0 | 269 | |
michael@0 | 270 | #define NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \ |
michael@0 | 271 | NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(Event::) |
michael@0 | 272 | |
michael@0 | 273 | inline nsISupports* |
michael@0 | 274 | ToSupports(mozilla::dom::Event* e) |
michael@0 | 275 | { |
michael@0 | 276 | return static_cast<nsIDOMEvent*>(e); |
michael@0 | 277 | } |
michael@0 | 278 | |
michael@0 | 279 | inline nsISupports* |
michael@0 | 280 | ToCanonicalSupports(mozilla::dom::Event* e) |
michael@0 | 281 | { |
michael@0 | 282 | return static_cast<nsIDOMEvent*>(e); |
michael@0 | 283 | } |
michael@0 | 284 | |
michael@0 | 285 | #endif // mozilla_dom_Event_h_ |