Skip to content
This repository has been archived by the owner on Jul 30, 2022. It is now read-only.

Commit

Permalink
[WM]: replace Navigator.monetization with Window.monetization
Browse files Browse the repository at this point in the history
  • Loading branch information
sidvishnoi committed Jan 25, 2021
1 parent ca6fa6a commit 517b8ce
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion browser/actors/MonetizationChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MonetizationChild extends JSWindowActorChild {
assetScale: details.amount.assetScale,
receipt: details.receipt,
};
this.contentWindow.navigator.monetization.dispatchEvent(
this.contentWindow.monetization.dispatchEvent(

This comment has been minimized.

Copy link
@sublimator

sublimator Jan 27, 2021

What was your rationale for the change?
It feels about right, but curious if there were any strong reasons

This comment has been minimized.

Copy link
@sidvishnoi

sidvishnoi Jan 27, 2021

Author Owner

From HTML spec:

..Navigator interface, which represents the identity and state of the user agent (the client), and allows web pages to register themselves as potential protocol handlers.

Based on above and looking at what other things are on Navigator (connection, gpu, hardwareConcurrency, storage, bluetooth, locks, geolocation etc.), it appears Navigator is more hardware oriented. Window then becomes a dumping ground for anything that doesn't make sense on Document or Navigator.

This comment has been minimized.

Copy link
@sublimator

sublimator Jan 27, 2021

Thanks for the explanation :)

This comment has been minimized.

Copy link
@sidvishnoi

sidvishnoi Jan 28, 2021

Author Owner

There is a catch here though. Things on window can clash with user defined variables (hopefully no one has a variable named monetization !). Navigator is safer, but doesn't exactly make sense. Will need some telemetry data just to be sure.

new this.contentWindow.MonetizationProgressEvent(
"progress",
eventInit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var EXPORTED_SYMBOLS = ["Monetization"];

/**
* `window.navigator.monetization` interface.
* `window.monetization` interface.
* See {@link dom/webidl/Monetization.webidl} for interface definition.
*/
class Monetization {
Expand Down
2 changes: 1 addition & 1 deletion browser/components/webmonetization/components.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Classes = [
{
'cid': '{880e8397-2353-4a76-b196-5544ec8cbe00}',
'contract_ids': ['@mozilla.org/webmonetization/Monetization;1'],
'jsm': 'resource:///modules/NavigatorMonetization.js',
'jsm': 'resource:///modules/MonetizationGlobal.js',
'constructor': 'Monetization',
},
]
2 changes: 1 addition & 1 deletion browser/components/webmonetization/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

EXTRA_JS_MODULES += [
"MonetizationFetcher.jsm",
"NavigatorMonetization.js",
"MonetizationGlobal.js",
]

XPCOM_MANIFESTS += [
Expand Down
18 changes: 0 additions & 18 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaSession)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAddonManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWebGpu)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMonetization)

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
Expand Down Expand Up @@ -242,8 +241,6 @@ void Navigator::Invalidate() {
mWebGpu = nullptr;

mSharePromise = nullptr;

mMonetization = nullptr;
}

void Navigator::GetUserAgent(nsAString& aUserAgent, CallerType aCallerType,
Expand Down Expand Up @@ -2128,21 +2125,6 @@ bool Navigator::HasCreatedMediaSession() const {
return mMediaSession != nullptr;
}

dom::Monetization* Navigator::Monetization() {
if (!mMonetization) {
ErrorResult rv;
mMonetization = ConstructJSImplementation<dom::Monetization>(
"@mozilla.org/webmonetization/Monetization;1", GetWindow()->AsGlobal(),
rv);
if (rv.Failed()) {
rv.SuppressException();
return nullptr;
}
}

return mMonetization;
}

Clipboard* Navigator::Clipboard() {
if (!mClipboard) {
mClipboard = new dom::Clipboard(GetWindow());
Expand Down
4 changes: 0 additions & 4 deletions dom/base/Navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/AddonManagerBinding.h"
#include "mozilla/dom/MonetizationBinding.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/Fetch.h"
#include "mozilla/dom/Nullable.h"
Expand All @@ -34,7 +33,6 @@ namespace dom {
class AddonManager;
class BodyExtractorBase;
class Geolocation;
class Monetization;
class systemMessageCallback;
class MediaDevices;
struct MediaStreamConstraints;
Expand Down Expand Up @@ -227,7 +225,6 @@ class Navigator final : public nsISupports, public nsWrapperCache {

dom::MediaCapabilities* MediaCapabilities();
dom::MediaSession* MediaSession();
dom::Monetization* Monetization();

AddonManager* GetMozAddonManager(ErrorResult& aRv);

Expand Down Expand Up @@ -295,7 +292,6 @@ class Navigator final : public nsISupports, public nsWrapperCache {
RefPtr<dom::MediaCapabilities> mMediaCapabilities;
RefPtr<dom::MediaSession> mMediaSession;
RefPtr<AddonManager> mAddonManager;
RefPtr<dom::Monetization> mMonetization;
RefPtr<webgpu::Instance> mWebGpu;
RefPtr<Promise> mSharePromise; // Web Share API related
// Gamepad moving to secure contexts
Expand Down
20 changes: 19 additions & 1 deletion dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
#include "mozilla/dom/LocalStorageCommon.h"
#include "mozilla/dom/Location.h"
#include "mozilla/dom/MediaKeys.h"
#include "mozilla/dom/MonetizationBinding.h"
#include "mozilla/dom/NavigatorBinding.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/dom/PartitionedLocalStorage.h"
Expand Down Expand Up @@ -1302,6 +1303,7 @@ void nsGlobalWindowInner::FreeInnerObjects() {
mLocalStorage = nullptr;
mSessionStorage = nullptr;
mPerformance = nullptr;
mMonetization = nullptr;

mContentMediaController = nullptr;

Expand Down Expand Up @@ -1399,7 +1401,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindowInner)
}

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator)

NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMonetization)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPerformance)

#ifdef MOZ_WEBSPEECH
Expand Down Expand Up @@ -1498,6 +1500,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindowInner)

NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator)

NS_IMPL_CYCLE_COLLECTION_UNLINK(mMonetization)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPerformance)

#ifdef MOZ_WEBSPEECH
Expand Down Expand Up @@ -1743,6 +1746,7 @@ void nsGlobalWindowInner::InitDocumentDependentState(JSContext* aCx) {
mLocalStorage = nullptr;
mSessionStorage = nullptr;
mPerformance = nullptr;
mMonetization = nullptr;

// This must be called after nullifying the internal objects because here we
// could recreate them, calling the getter methods, and store them into the JS
Expand Down Expand Up @@ -2387,6 +2391,20 @@ CustomElementRegistry* nsGlobalWindowInner::GetExistingCustomElements() {
return mCustomElements;
}

Monetization* nsPIDOMWindowInner::Monetization() {
if (!mMonetization) {
ErrorResult rv;
mMonetization = ConstructJSImplementation<dom::Monetization>(
"@mozilla.org/webmonetization/Monetization;1", AsGlobal(), rv);
if (rv.Failed()) {
rv.SuppressException();
return nullptr;
}
}

return mMonetization;
}

Performance* nsPIDOMWindowInner::GetPerformance() {
CreatePerformanceObjectIfNeeded();
return mPerformance;
Expand Down
4 changes: 4 additions & 0 deletions dom/base/nsPIDOMWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Document;
class Element;
class Location;
class MediaKeys;
class Monetization;
class Navigator;
class Performance;
class Selection;
Expand Down Expand Up @@ -184,6 +185,8 @@ class nsPIDOMWindowInner : public mozIDOMWindow {
*/
bool HasActiveMediaKeysInstance();

mozilla::dom::Monetization* Monetization();

mozilla::dom::Performance* GetPerformance();

void QueuePerformanceNavigationTiming();
Expand Down Expand Up @@ -625,6 +628,7 @@ class nsPIDOMWindowInner : public mozIDOMWindow {

nsCOMPtr<mozilla::dom::EventTarget> mParentTarget; // strong

RefPtr<mozilla::dom::Monetization> mMonetization;
RefPtr<mozilla::dom::Performance> mPerformance;
mozilla::UniquePtr<mozilla::dom::TimeoutManager> mTimeoutManager;

Expand Down
5 changes: 0 additions & 5 deletions dom/webidl/Navigator.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,6 @@ partial interface Navigator {
readonly attribute NetworkInformation connection;
};

// Monetization
partial interface Navigator {
readonly attribute Monetization monetization;
};

// https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#navigator-interface-extension
partial interface Navigator {
[Throws, Pref="dom.gamepad.enabled"]
Expand Down
5 changes: 5 additions & 0 deletions dom/webidl/Window.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ partial interface Window {
[Replaceable, Pure, StoreInSlot] readonly attribute Performance? performance;
};

// Monetization
partial interface Window {
readonly attribute Monetization monetization;
};

// https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html
Window includes GlobalCrypto;

Expand Down

0 comments on commit 517b8ce

Please sign in to comment.