зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1646165 - Implement FOG's JavaScript API via WebIDL. r=chutten,webidl,emilio,smaug
This is only the basic outline. It doesn't do anything yet, but compile. As there are no metrics generated for it it can't look up anything. To note: Actual metric types are implemented in XPIDL later. The following (priviliged) JavaScript code will soon work (if the corresponding metrics would be defined): const { Glean } = ChromeUtils.import("resource://gre/modules/Glean.jsm"); Glean.shared.test_only.count_things.add(1); Differential Revision: https://phabricator.services.mozilla.com/D92211
This commit is contained in:
Родитель
3340804df4
Коммит
eeb5f1a8c2
|
@ -46,6 +46,9 @@
|
|||
#include "mozilla/dom/TimeoutManager.h"
|
||||
#include "mozilla/dom/VisualViewport.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#ifdef MOZ_GLEAN
|
||||
# include "mozilla/glean/Glean.h"
|
||||
#endif
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/Result.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID)
|
||||
|
@ -1233,6 +1236,10 @@ void nsGlobalWindowInner::FreeInnerObjects() {
|
|||
mSpeechSynthesis = nullptr;
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
mGlean = nullptr;
|
||||
#endif
|
||||
|
||||
mParentTarget = nullptr;
|
||||
|
||||
if (mCleanMessageManager) {
|
||||
|
@ -1323,6 +1330,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSpeechSynthesis)
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlean)
|
||||
#endif
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOuterWindow)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTopInnerWindow)
|
||||
|
@ -1416,6 +1427,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSpeechSynthesis)
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlean)
|
||||
#endif
|
||||
|
||||
if (tmp->mOuterWindow) {
|
||||
nsGlobalWindowOuter::Cast(tmp->mOuterWindow)->MaybeClearInnerWindow(tmp);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOuterWindow)
|
||||
|
@ -2714,6 +2729,16 @@ bool nsGlobalWindowInner::HasActiveSpeechSynthesis() {
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
mozilla::glean::Glean* nsGlobalWindowInner::Glean() {
|
||||
if (!mGlean) {
|
||||
mGlean = new mozilla::glean::Glean();
|
||||
}
|
||||
|
||||
return mGlean;
|
||||
}
|
||||
#endif
|
||||
|
||||
Nullable<WindowProxyHolder> nsGlobalWindowInner::GetParent(
|
||||
ErrorResult& aError) {
|
||||
FORWARD_TO_OUTER_OR_THROW(GetParentOuter, (), aError, nullptr);
|
||||
|
|
|
@ -50,6 +50,9 @@
|
|||
#include "mozilla/dom/EventTarget.h"
|
||||
#include "mozilla/dom/WindowBinding.h"
|
||||
#include "mozilla/dom/WindowProxyHolder.h"
|
||||
#ifdef MOZ_GLEAN
|
||||
# include "mozilla/glean/Glean.h"
|
||||
#endif
|
||||
#include "Units.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsSize.h"
|
||||
|
@ -832,6 +835,10 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
mozilla::ErrorResult& aError);
|
||||
bool HasActiveSpeechSynthesis();
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
mozilla::glean::Glean* Glean();
|
||||
#endif
|
||||
already_AddRefed<nsICSSDeclaration> GetDefaultComputedStyle(
|
||||
mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
|
||||
mozilla::ErrorResult& aError);
|
||||
|
@ -1421,6 +1428,10 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
|
|||
RefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
RefPtr<mozilla::glean::Glean> mGlean;
|
||||
#endif
|
||||
|
||||
// This is the CC generation the last time we called CanSkip.
|
||||
uint32_t mCanSkipCCGeneration;
|
||||
|
||||
|
|
|
@ -1458,6 +1458,17 @@ DOMInterfaces = {
|
|||
'concrete': False,
|
||||
},
|
||||
|
||||
# Glean
|
||||
|
||||
'GleanImpl': {
|
||||
'nativeType': 'mozilla::glean::Glean',
|
||||
'headerFile': 'mozilla/glean/Glean.h',
|
||||
},
|
||||
'GleanCategory': {
|
||||
'nativeType': 'mozilla::glean::Category',
|
||||
'headerFile': 'mozilla/glean/Category.h',
|
||||
},
|
||||
|
||||
# WebRTC
|
||||
|
||||
'WebrtcGlobalInformation': {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
interface nsISupports;
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanCategory {
|
||||
/**
|
||||
* Get a metric by name.
|
||||
*
|
||||
* Returns an object of the corresponding metric type,
|
||||
* with only the allowed functions available.
|
||||
*/
|
||||
getter nsISupports (DOMString identifier);
|
||||
};
|
||||
|
||||
[ChromeOnly, Exposed=Window]
|
||||
interface GleanImpl {
|
||||
/**
|
||||
* Get a metric category by name.
|
||||
*
|
||||
* Returns an object for further metric lookup.
|
||||
*/
|
||||
getter GleanCategory (DOMString identifier);
|
||||
};
|
|
@ -28,6 +28,9 @@ with Files("MatchPattern.webidl"):
|
|||
with Files("WebExtension*.webidl"):
|
||||
BUG_COMPONENT = ("WebExtensions", "General")
|
||||
|
||||
with Files("Glean*.webidl"):
|
||||
BUG_COMPONENT = ('Toolkit', 'Telemetry')
|
||||
|
||||
PREPROCESSED_WEBIDL_FILES = [
|
||||
'ChromeUtils.webidl',
|
||||
]
|
||||
|
@ -83,6 +86,11 @@ if CONFIG['MOZ_PLACES']:
|
|||
'PlacesObservers.webidl',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_GLEAN']:
|
||||
WEBIDL_FILES += [
|
||||
'Glean.webidl',
|
||||
]
|
||||
|
||||
WEBIDL_FILES += [
|
||||
'PrioEncoder.webidl',
|
||||
]
|
||||
|
|
|
@ -703,6 +703,11 @@ partial interface Window {
|
|||
|
||||
[ChromeOnly]
|
||||
readonly attribute boolean isChromeWindow;
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
[ChromeOnly]
|
||||
readonly attribute GleanImpl Glean;
|
||||
#endif
|
||||
};
|
||||
|
||||
partial interface Window {
|
||||
|
|
|
@ -76,6 +76,9 @@
|
|||
#include "mozilla/dom/XMLSerializerBinding.h"
|
||||
#include "mozilla/dom/FormDataBinding.h"
|
||||
#include "mozilla/dom/nsCSPContext.h"
|
||||
#ifdef MOZ_GLEAN
|
||||
# include "mozilla/glean/Glean.h"
|
||||
#endif
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/DeferredFinalize.h"
|
||||
#include "mozilla/ExtensionPolicyService.h"
|
||||
|
@ -910,6 +913,10 @@ bool xpc::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj) {
|
|||
indexedDB = true;
|
||||
} else if (JS_LinearStringEqualsLiteral(nameStr, "isSecureContext")) {
|
||||
isSecureContext = true;
|
||||
#ifdef MOZ_GLEAN
|
||||
} else if (JS_LinearStringEqualsLiteral(nameStr, "Glean")) {
|
||||
glean = true;
|
||||
#endif
|
||||
#ifdef MOZ_WEBRTC
|
||||
} else if (JS_LinearStringEqualsLiteral(nameStr, "rtcIdentityProvider")) {
|
||||
rtcIdentityProvider = true;
|
||||
|
@ -1075,6 +1082,10 @@ bool xpc::GlobalProperties::DefineInXPCComponents(JSContext* cx,
|
|||
if (indexedDB && !IndexedDatabaseManager::DefineIndexedDB(cx, obj))
|
||||
return false;
|
||||
|
||||
#ifdef MOZ_GLEAN
|
||||
if (glean && !mozilla::glean::Glean::DefineGlean(cx, obj)) return false;
|
||||
#endif
|
||||
|
||||
return Define(cx, obj);
|
||||
}
|
||||
|
||||
|
|
|
@ -2259,6 +2259,9 @@ struct GlobalProperties {
|
|||
bool indexedDB : 1;
|
||||
bool isSecureContext : 1;
|
||||
bool rtcIdentityProvider : 1;
|
||||
#ifdef MOZ_GLEAN
|
||||
bool glean : 1;
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool Define(JSContext* cx, JS::HandleObject obj);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/glean/Glean.h"
|
||||
#include "mozilla/glean/Category.h"
|
||||
#include "mozilla/dom/GleanBinding.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Category)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Category)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Category)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Category)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
JSObject* Category::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanCategory_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<nsISupports> Category::NamedGetter(const nsAString& aName,
|
||||
bool& aFound) {
|
||||
aFound = false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Category::NameIsEnumerable(const nsAString& aName) { return false; }
|
||||
|
||||
void Category::GetSupportedNames(nsTArray<nsString>& aNames) {}
|
||||
|
||||
} // namespace mozilla::glean
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_glean_Category_h
|
||||
#define mozilla_glean_Category_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
class Category final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Category)
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() { return nullptr; }
|
||||
|
||||
Category(uint32_t id, uint32_t length) : mId(id), mLength(length) {}
|
||||
|
||||
already_AddRefed<nsISupports> NamedGetter(const nsAString& aName,
|
||||
bool& aFound);
|
||||
bool NameIsEnumerable(const nsAString& aName);
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
|
||||
private:
|
||||
uint32_t mId;
|
||||
uint32_t mLength;
|
||||
|
||||
protected:
|
||||
virtual ~Category() = default;
|
||||
};
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
||||
#endif /* mozilla_glean_Category_h */
|
|
@ -0,0 +1,60 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/DOMJSClass.h"
|
||||
#include "mozilla/dom/GleanBinding.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/glean/Glean.h"
|
||||
#include "mozilla/glean/Category.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Glean)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(Glean)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(Glean)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Glean)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
JSObject* Glean::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
||||
return dom::GleanImpl_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
// static
|
||||
bool Glean::DefineGlean(JSContext* aCx, JS::Handle<JSObject*> aGlobal) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(JS::GetClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
|
||||
"Passed object is not a global object!");
|
||||
|
||||
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> glean(aCx);
|
||||
js::AssertSameCompartment(aCx, aGlobal);
|
||||
|
||||
auto impl = MakeRefPtr<Glean>();
|
||||
if (!dom::GetOrCreateDOMReflector(aCx, impl.get(), &glean)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return JS_DefineProperty(aCx, aGlobal, "Glean", glean, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
already_AddRefed<Category> Glean::NamedGetter(const nsAString& aName,
|
||||
bool& aFound) {
|
||||
aFound = false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Glean::NameIsEnumerable(const nsAString& aName) { return false; }
|
||||
|
||||
void Glean::GetSupportedNames(nsTArray<nsString>& aNames) {}
|
||||
|
||||
} // namespace mozilla::glean
|
|
@ -0,0 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_glean_Glean_h
|
||||
#define mozilla_glean_Glean_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "mozilla/glean/Category.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
class Glean final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Glean)
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() { return nullptr; }
|
||||
|
||||
static bool DefineGlean(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
||||
|
||||
already_AddRefed<Category> NamedGetter(const nsAString& aName, bool& aFound);
|
||||
bool NameIsEnumerable(const nsAString& aName);
|
||||
void GetSupportedNames(nsTArray<nsString>& aNames);
|
||||
|
||||
protected:
|
||||
virtual ~Glean() = default;
|
||||
};
|
||||
|
||||
} // namespace mozilla::glean
|
||||
|
||||
#endif /* mozilla_glean_Glean */
|
|
@ -16,7 +16,14 @@ if CONFIG['MOZ_GLEAN']:
|
|||
'ipc/FOGIPC.h',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.glean += [
|
||||
'bindings/Category.h',
|
||||
'bindings/Glean.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'bindings/Category.cpp',
|
||||
'bindings/Glean.cpp',
|
||||
'ipc/FOGIPC.cpp',
|
||||
]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче