Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et tw=80 : */
3 :
4 : /* This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 :
8 : #include "NeckoTargetHolder.h"
9 :
10 : #include "nsContentUtils.h"
11 : #include "nsILoadInfo.h"
12 :
13 : namespace mozilla {
14 : namespace net {
15 :
16 : already_AddRefed<nsIEventTarget>
17 66 : NeckoTargetHolder::GetNeckoTarget()
18 : {
19 132 : nsCOMPtr<nsIEventTarget> target = mNeckoTarget;
20 :
21 66 : if (!target) {
22 11 : target = GetMainThreadEventTarget();
23 : }
24 132 : return target.forget();
25 : }
26 :
27 : nsresult
28 2 : NeckoTargetHolder::Dispatch(already_AddRefed<nsIRunnable>&& aRunnable,
29 : uint32_t aDispatchFlags)
30 : {
31 2 : if (mNeckoTarget) {
32 1 : return mNeckoTarget->Dispatch(Move(aRunnable), aDispatchFlags);
33 : }
34 :
35 2 : nsCOMPtr<nsIEventTarget> mainThreadTarget = GetMainThreadEventTarget();
36 1 : MOZ_ASSERT(mainThreadTarget);
37 :
38 1 : return mainThreadTarget->Dispatch(Move(aRunnable), aDispatchFlags);
39 : }
40 :
41 : } // namespace net
42 : } // namespace mozilla
|