Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 5a9c35f

Browse files
committed
Bug 1492036 - Reporting API - part 1 - WebIDL, r=smaug
1 parent 79ef206 commit 5a9c35f

14 files changed

Lines changed: 450 additions & 72 deletions

File tree

dom/base/DOMPrefsInternal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ DOM_WEBIDL_PREF(dom_netinfo_enabled)
2828
DOM_WEBIDL_PREF(dom_fetchObserver_enabled)
2929
DOM_WEBIDL_PREF(dom_enable_performance_observer)
3030
DOM_WEBIDL_PREF(dom_performance_enable_scheduler_timing)
31+
DOM_WEBIDL_PREF(dom_reporting_enabled)
3132
DOM_WEBIDL_PREF(javascript_options_streams)

dom/moz.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ DIRS += [
102102
'websocket',
103103
'serviceworkers',
104104
'simpledb',
105+
'reporting',
105106
]
106107

107108
if CONFIG['MOZ_LIBPRIO']:

dom/reporting/Report.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/Report.h"
8+
#include "mozilla/dom/ReportBody.h"
9+
#include "mozilla/dom/ReportingBinding.h"
10+
11+
namespace mozilla {
12+
namespace dom {
13+
14+
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Report, mWindow, mBody)
15+
NS_IMPL_CYCLE_COLLECTING_ADDREF(Report)
16+
NS_IMPL_CYCLE_COLLECTING_RELEASE(Report)
17+
18+
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Report)
19+
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20+
NS_INTERFACE_MAP_ENTRY(nsISupports)
21+
NS_INTERFACE_MAP_END
22+
23+
Report::Report(nsPIDOMWindowInner* aWindow,
24+
const nsAString& aType,
25+
const nsAString& aURL,
26+
ReportBody* aBody)
27+
: mWindow(aWindow)
28+
, mType(aType)
29+
, mURL(aURL)
30+
, mBody(aBody)
31+
{
32+
MOZ_ASSERT(aWindow);
33+
}
34+
35+
Report::~Report() = default;
36+
37+
JSObject*
38+
Report::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
39+
{
40+
return Report_Binding::Wrap(aCx, this, aGivenProto);
41+
}
42+
43+
void
44+
Report::GetType(nsAString& aType) const
45+
{
46+
aType = mType;
47+
}
48+
49+
void
50+
Report::GetUrl(nsAString& aURL) const
51+
{
52+
aURL = mURL;
53+
}
54+
55+
ReportBody*
56+
Report::GetBody() const
57+
{
58+
return mBody;
59+
}
60+
61+
} // dom namespace
62+
} // mozilla namespace

dom/reporting/Report.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#ifndef mozilla_dom_Report_h
8+
#define mozilla_dom_Report_h
9+
10+
#include "mozilla/Attributes.h"
11+
#include "mozilla/dom/BindingUtils.h"
12+
#include "nsCycleCollectionParticipant.h"
13+
#include "nsWrapperCache.h"
14+
15+
namespace mozilla {
16+
namespace dom {
17+
18+
class ReportBody;
19+
20+
class Report final : public nsISupports
21+
, public nsWrapperCache
22+
{
23+
public:
24+
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25+
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Report)
26+
27+
Report(nsPIDOMWindowInner* aWindow,
28+
const nsAString& aType,
29+
const nsAString& aURL,
30+
ReportBody* aBody);
31+
32+
JSObject*
33+
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
34+
35+
nsPIDOMWindowInner*
36+
GetParentObject() const
37+
{
38+
return mWindow;
39+
}
40+
41+
void
42+
GetType(nsAString& aType) const;
43+
44+
void
45+
GetUrl(nsAString& aURL) const;
46+
47+
ReportBody*
48+
GetBody() const;
49+
50+
private:
51+
~Report();
52+
53+
nsCOMPtr<nsPIDOMWindowInner> mWindow;
54+
55+
const nsString mType;
56+
const nsString mURL;
57+
RefPtr<ReportBody> mBody;
58+
};
59+
60+
} // dom namespace
61+
} // mozilla namespace
62+
63+
#endif // mozilla_dom_Report_h

dom/reporting/ReportBody.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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/ReportBody.h"
8+
#include "mozilla/dom/ReportingBinding.h"
9+
#include "nsPIDOMWindow.h"
10+
11+
namespace mozilla {
12+
namespace dom {
13+
14+
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ReportBody, mWindow)
15+
NS_IMPL_CYCLE_COLLECTING_ADDREF(ReportBody)
16+
NS_IMPL_CYCLE_COLLECTING_RELEASE(ReportBody)
17+
18+
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ReportBody)
19+
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20+
NS_INTERFACE_MAP_ENTRY(nsISupports)
21+
NS_INTERFACE_MAP_END
22+
23+
ReportBody::ReportBody(nsPIDOMWindowInner* aWindow)
24+
: mWindow(aWindow)
25+
{
26+
MOZ_ASSERT(aWindow);
27+
}
28+
29+
ReportBody::~ReportBody() = default;
30+
31+
JSObject*
32+
ReportBody::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
33+
{
34+
return ReportBody_Binding::Wrap(aCx, this, aGivenProto);
35+
}
36+
37+
} // dom namespace
38+
} // mozilla namespace

dom/reporting/ReportBody.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
#ifndef mozilla_dom_ReportBody_h
8+
#define mozilla_dom_ReportBody_h
9+
10+
#include "mozilla/Attributes.h"
11+
#include "mozilla/dom/BindingUtils.h"
12+
#include "nsCycleCollectionParticipant.h"
13+
#include "nsWrapperCache.h"
14+
15+
class nsPIDOMWindowInner;
16+
17+
namespace mozilla {
18+
namespace dom {
19+
20+
class ReportBody final : public nsISupports
21+
, public nsWrapperCache
22+
{
23+
public:
24+
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25+
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReportBody)
26+
27+
explicit ReportBody(nsPIDOMWindowInner* aWindow);
28+
29+
JSObject*
30+
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
31+
32+
nsPIDOMWindowInner*
33+
GetParentObject() const
34+
{
35+
return mWindow;
36+
}
37+
38+
private:
39+
~ReportBody();
40+
41+
nsCOMPtr<nsPIDOMWindowInner> mWindow;
42+
};
43+
44+
} // dom namespace
45+
} // mozilla namespace
46+
47+
#endif // mozilla_dom_ReportBody_h
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/ReportingObserver.h"
8+
#include "mozilla/dom/ReportingBinding.h"
9+
#include "nsContentUtils.h"
10+
#include "nsGlobalWindowInner.h"
11+
12+
namespace mozilla {
13+
namespace dom {
14+
15+
NS_IMPL_CYCLE_COLLECTION_CLASS(ReportingObserver)
16+
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ReportingObserver)
17+
tmp->Disconnect();
18+
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
19+
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
20+
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
21+
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
22+
23+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ReportingObserver)
24+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
25+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallback)
26+
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
27+
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(ReportingObserver)
28+
29+
NS_IMPL_CYCLE_COLLECTING_ADDREF(ReportingObserver)
30+
NS_IMPL_CYCLE_COLLECTING_RELEASE(ReportingObserver)
31+
32+
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ReportingObserver)
33+
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
34+
NS_INTERFACE_MAP_ENTRY(nsISupports)
35+
NS_INTERFACE_MAP_END
36+
37+
/* static */ already_AddRefed<ReportingObserver>
38+
ReportingObserver::Constructor(const GlobalObject& aGlobal,
39+
ReportingObserverCallback& aCallback,
40+
const ReportingObserverOptions& aOptions,
41+
ErrorResult& aRv)
42+
{
43+
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
44+
MOZ_ASSERT(window);
45+
46+
nsTArray<nsString> types;
47+
if (aOptions.mTypes.WasPassed()) {
48+
types = aOptions.mTypes.Value();
49+
}
50+
51+
RefPtr<ReportingObserver> ro =
52+
new ReportingObserver(window, aCallback, types, aOptions.mBuffered);
53+
return ro.forget();
54+
}
55+
56+
ReportingObserver::ReportingObserver(nsPIDOMWindowInner* aWindow,
57+
ReportingObserverCallback& aCallback,
58+
const nsTArray<nsString>& aTypes,
59+
bool aBuffered)
60+
: mWindow(aWindow)
61+
, mCallback(&aCallback)
62+
, mTypes(aTypes)
63+
, mBuffered(aBuffered)
64+
{
65+
MOZ_ASSERT(aWindow);
66+
}
67+
68+
ReportingObserver::~ReportingObserver()
69+
{
70+
Disconnect();
71+
}
72+
73+
JSObject*
74+
ReportingObserver::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
75+
{
76+
return ReportingObserver_Binding::Wrap(aCx, this, aGivenProto);
77+
}
78+
79+
void
80+
ReportingObserver::Observe()
81+
{
82+
// TODO
83+
}
84+
85+
void
86+
ReportingObserver::Disconnect()
87+
{
88+
// TODO
89+
}
90+
91+
void
92+
ReportingObserver::TakeRecords(nsTArray<RefPtr<Report>>& aRecords)
93+
{
94+
// TODO
95+
}
96+
97+
} // dom namespace
98+
} // mozilla namespace

dom/reporting/ReportingObserver.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
#ifndef mozilla_dom_ReportingObserver_h
8+
#define mozilla_dom_ReportingObserver_h
9+
10+
#include "mozilla/Attributes.h"
11+
#include "mozilla/dom/BindingUtils.h"
12+
#include "nsCycleCollectionParticipant.h"
13+
#include "nsWrapperCache.h"
14+
15+
class nsPIDOMWindowInner;
16+
17+
namespace mozilla {
18+
namespace dom {
19+
20+
class ReportingObserver final : public nsISupports
21+
, public nsWrapperCache
22+
{
23+
public:
24+
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25+
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ReportingObserver)
26+
27+
static already_AddRefed<ReportingObserver>
28+
Constructor(const GlobalObject& aGlobal,
29+
ReportingObserverCallback& aCallback,
30+
const ReportingObserverOptions& aOptions,
31+
ErrorResult& aRv);
32+
33+
ReportingObserver(nsPIDOMWindowInner* aWindow,
34+
ReportingObserverCallback& aCallback,
35+
const nsTArray<nsString>& aTypes,
36+
bool aBuffered);
37+
38+
JSObject*
39+
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
40+
41+
nsPIDOMWindowInner*
42+
GetParentObject() const
43+
{
44+
return mWindow;
45+
}
46+
47+
void
48+
Observe();
49+
50+
void
51+
Disconnect();
52+
53+
void
54+
TakeRecords(nsTArray<RefPtr<Report>>& aRecords);
55+
56+
private:
57+
~ReportingObserver();
58+
59+
nsCOMPtr<nsPIDOMWindowInner> mWindow;
60+
RefPtr<ReportingObserverCallback> mCallback;
61+
nsTArray<nsString> mTypes;
62+
bool mBuffered;
63+
};
64+
65+
} // dom namespace
66+
} // mozilla namespace
67+
68+
#endif // mozilla_dom_ReportingObserver_h

0 commit comments

Comments
 (0)