Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/docshell/shistory/ChildSHistory.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 "mozilla/dom/ChildSHistory.h"
8
#include "mozilla/dom/ChildSHistoryBinding.h"
9
#include "mozilla/dom/ContentFrameMessageManager.h"
10
#include "nsIMessageManager.h"
11
#include "nsComponentManagerUtils.h"
12
#include "nsSHistory.h"
13
#include "nsDocShell.h"
14
#include "nsISHEntry.h"
15
#include "nsXULAppAPI.h"
16
17
namespace mozilla {
18
namespace dom {
19
20
ChildSHistory::ChildSHistory(nsDocShell* aDocShell)
21
  : mDocShell(aDocShell)
22
  , mHistory(new nsSHistory())
23
0
{
24
0
  MOZ_ASSERT(mDocShell);
25
0
  mHistory->SetRootDocShell(mDocShell);
26
0
}
27
28
ChildSHistory::~ChildSHistory()
29
0
{
30
0
}
31
32
int32_t
33
ChildSHistory::Count()
34
0
{
35
0
  return mHistory->GetCount();
36
0
}
37
38
int32_t
39
ChildSHistory::Index()
40
0
{
41
0
  int32_t index;
42
0
  mHistory->GetIndex(&index);
43
0
  return index;
44
0
}
45
46
void
47
ChildSHistory::Reload(uint32_t aReloadFlags, ErrorResult& aRv)
48
0
{
49
0
  aRv = mHistory->Reload(aReloadFlags);
50
0
}
51
52
bool
53
ChildSHistory::CanGo(int32_t aOffset)
54
0
{
55
0
  CheckedInt<int32_t> index = Index();
56
0
  index += aOffset;
57
0
  if (!index.isValid()) {
58
0
    return false;
59
0
  }
60
0
  return index.value() < Count() && index.value() >= 0;
61
0
}
62
63
void
64
ChildSHistory::Go(int32_t aOffset, ErrorResult& aRv)
65
0
{
66
0
  CheckedInt<int32_t> index = Index();
67
0
  index += aOffset;
68
0
  if (!index.isValid()) {
69
0
    aRv.Throw(NS_ERROR_FAILURE);
70
0
    return;
71
0
  }
72
0
  aRv = mHistory->GotoIndex(index.value());
73
0
}
74
75
void
76
ChildSHistory::EvictLocalContentViewers()
77
0
{
78
0
  mHistory->EvictAllContentViewers();
79
0
}
80
81
nsISHistory*
82
ChildSHistory::LegacySHistory()
83
0
{
84
0
  return mHistory;
85
0
}
86
87
ParentSHistory*
88
ChildSHistory::GetParentIfSameProcess()
89
0
{
90
0
  if (XRE_IsContentProcess()) {
91
0
    return nullptr;
92
0
  }
93
0
94
0
  MOZ_CRASH("Unimplemented!");
95
0
}
96
97
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChildSHistory)
98
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
99
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
100
0
NS_INTERFACE_MAP_END
101
102
NS_IMPL_CYCLE_COLLECTING_ADDREF(ChildSHistory)
103
NS_IMPL_CYCLE_COLLECTING_RELEASE(ChildSHistory)
104
105
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ChildSHistory,
106
                                      mDocShell,
107
                                      mHistory)
108
109
JSObject*
110
ChildSHistory::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
111
0
{
112
0
  return ChildSHistory_Binding::Wrap(cx, this, aGivenProto);
113
0
}
114
115
nsISupports*
116
ChildSHistory::GetParentObject() const
117
0
{
118
0
  // We want to get the TabChildMessageManager, which is the
119
0
  // messageManager on mDocShell.
120
0
  RefPtr<ContentFrameMessageManager> mm;
121
0
  if (mDocShell) {
122
0
    mm = mDocShell->GetMessageManager();
123
0
  }
124
0
  // else we must be unlinked... can that happen here?
125
0
  return ToSupports(mm);
126
0
}
127
128
} // namespace dom
129
} // namespace mozilla