Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_AsyncEventDispatcher_h_ |
michael@0 | 7 | #define mozilla_AsyncEventDispatcher_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsIDocument.h" |
michael@0 | 12 | #include "nsIDOMEvent.h" |
michael@0 | 13 | #include "nsINode.h" |
michael@0 | 14 | #include "nsString.h" |
michael@0 | 15 | #include "nsThreadUtils.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM. |
michael@0 | 21 | * For example, you may need to fire an event from within layout, but |
michael@0 | 22 | * want to ensure that the event handler doesn't mutate the DOM at |
michael@0 | 23 | * the wrong time, in order to avoid resulting instability. |
michael@0 | 24 | */ |
michael@0 | 25 | |
michael@0 | 26 | class AsyncEventDispatcher : public nsRunnable |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | AsyncEventDispatcher(nsINode* aEventNode, const nsAString& aEventType, |
michael@0 | 30 | bool aBubbles, bool aDispatchChromeOnly) |
michael@0 | 31 | : mEventNode(aEventNode) |
michael@0 | 32 | , mEventType(aEventType) |
michael@0 | 33 | , mBubbles(aBubbles) |
michael@0 | 34 | , mDispatchChromeOnly(aDispatchChromeOnly) |
michael@0 | 35 | { |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | AsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent) |
michael@0 | 39 | : mEventNode(aEventNode) |
michael@0 | 40 | , mEvent(aEvent) |
michael@0 | 41 | , mDispatchChromeOnly(false) |
michael@0 | 42 | { |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | AsyncEventDispatcher(nsINode* aEventNode, WidgetEvent& aEvent); |
michael@0 | 46 | |
michael@0 | 47 | NS_IMETHOD Run() MOZ_OVERRIDE; |
michael@0 | 48 | nsresult PostDOMEvent(); |
michael@0 | 49 | void RunDOMEventWhenSafe(); |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<nsINode> mEventNode; |
michael@0 | 52 | nsCOMPtr<nsIDOMEvent> mEvent; |
michael@0 | 53 | nsString mEventType; |
michael@0 | 54 | bool mBubbles; |
michael@0 | 55 | bool mDispatchChromeOnly; |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | class LoadBlockingAsyncEventDispatcher MOZ_FINAL : public AsyncEventDispatcher |
michael@0 | 59 | { |
michael@0 | 60 | public: |
michael@0 | 61 | LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, |
michael@0 | 62 | const nsAString& aEventType, |
michael@0 | 63 | bool aBubbles, bool aDispatchChromeOnly) |
michael@0 | 64 | : AsyncEventDispatcher(aEventNode, aEventType, |
michael@0 | 65 | aBubbles, aDispatchChromeOnly) |
michael@0 | 66 | , mBlockedDoc(aEventNode->OwnerDoc()) |
michael@0 | 67 | { |
michael@0 | 68 | if (mBlockedDoc) { |
michael@0 | 69 | mBlockedDoc->BlockOnload(); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent) |
michael@0 | 74 | : AsyncEventDispatcher(aEventNode, aEvent) |
michael@0 | 75 | , mBlockedDoc(aEventNode->OwnerDoc()) |
michael@0 | 76 | { |
michael@0 | 77 | if (mBlockedDoc) { |
michael@0 | 78 | mBlockedDoc->BlockOnload(); |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | ~LoadBlockingAsyncEventDispatcher(); |
michael@0 | 83 | |
michael@0 | 84 | private: |
michael@0 | 85 | nsCOMPtr<nsIDocument> mBlockedDoc; |
michael@0 | 86 | }; |
michael@0 | 87 | |
michael@0 | 88 | } // namespace mozilla |
michael@0 | 89 | |
michael@0 | 90 | #endif // mozilla_AsyncEventDispatcher_h_ |