Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/fetch/FetchObserver.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#include "FetchObserver.h"
8
#include "mozilla/dom/Event.h"
9
10
namespace mozilla {
11
namespace dom {
12
13
NS_IMPL_CYCLE_COLLECTION_CLASS(FetchObserver)
14
15
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FetchObserver,
16
0
                                                  DOMEventTargetHelper)
17
0
  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFollowingSignal)
18
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
19
20
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FetchObserver,
21
0
                                                DOMEventTargetHelper)
22
0
  tmp->Unfollow();
23
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
24
25
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FetchObserver)
26
0
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
27
28
NS_IMPL_ADDREF_INHERITED(FetchObserver, DOMEventTargetHelper)
29
NS_IMPL_RELEASE_INHERITED(FetchObserver, DOMEventTargetHelper)
30
31
FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
32
                             AbortSignalImpl* aSignalImpl)
33
  : DOMEventTargetHelper(aGlobal)
34
  , mState(FetchState::Requesting)
35
0
{
36
0
  if (aSignalImpl) {
37
0
    Follow(aSignalImpl);
38
0
  }
39
0
}
40
41
JSObject*
42
FetchObserver::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
43
0
{
44
0
  return FetchObserver_Binding::Wrap(aCx, this, aGivenProto);
45
0
}
46
47
FetchState
48
FetchObserver::State() const
49
0
{
50
0
  return mState;
51
0
}
52
53
void
54
FetchObserver::Abort()
55
0
{
56
0
  SetState(FetchState::Aborted);
57
0
}
58
59
void
60
FetchObserver::SetState(FetchState aState)
61
0
{
62
0
  MOZ_ASSERT(mState < aState);
63
0
64
0
  if (mState == FetchState::Aborted ||
65
0
      mState == FetchState::Errored ||
66
0
      mState == FetchState::Complete) {
67
0
    // We are already in a final state.
68
0
    return;
69
0
  }
70
0
71
0
  // We cannot pass from Requesting to Complete directly.
72
0
  if (mState == FetchState::Requesting &&
73
0
      aState == FetchState::Complete) {
74
0
    SetState(FetchState::Responding);
75
0
  }
76
0
77
0
  mState = aState;
78
0
79
0
  if (mState == FetchState::Aborted ||
80
0
      mState == FetchState::Errored ||
81
0
      mState == FetchState::Complete) {
82
0
    Unfollow();
83
0
  }
84
0
85
0
  EventInit init;
86
0
  init.mBubbles = false;
87
0
  init.mCancelable = false;
88
0
89
0
  // TODO which kind of event should we dispatch here?
90
0
91
0
  RefPtr<Event> event =
92
0
    Event::Constructor(this, NS_LITERAL_STRING("statechange"), init);
93
0
  event->SetTrusted(true);
94
0
95
0
  DispatchEvent(*event);
96
0
}
97
98
} // dom namespace
99
} // mozilla namespace