Skip to content

Commit

Permalink
Bug 1782083 - Create skeleton IdentityCredential, r=dveditz,emilio
Browse files Browse the repository at this point in the history
This patch creates a do-nothing IdentityCredential that gives errors when it is used.

The IdentityCredential webidl is defined here:
  https://fedidcg.github.io/FedCM/#browser-api-identity-credential-interface

Accomplished here:
  - IdentityCredential class defined, including isupports and cycle-counting macros
  - Empty test added to hold the place of a mochitest folder
  - webidl of CredentialsContainer updated and IdentityCredential added
  - Logic to parse `identity` key from navigator.credentials.get()
  - Adding all of this to the build, including membership to the new bugzilla component DOM: Credential Management

Differential Revision: https://phabricator.services.mozilla.com/D153588
  • Loading branch information
bvandersloot-mozilla committed Sep 14, 2022
1 parent dca1e21 commit abad258
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
33 changes: 33 additions & 0 deletions dom/credentialmanagement/identity/IdentityCredential.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -*- 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/Promise.h"
#include "mozilla/dom/IdentityCredential.h"
#include "nsCycleCollectionParticipant.h"

namespace mozilla::dom {

NS_IMPL_ADDREF_INHERITED(IdentityCredential, Credential)
NS_IMPL_RELEASE_INHERITED(IdentityCredential, Credential)

NS_IMPL_CYCLE_COLLECTION_INHERITED(IdentityCredential, Credential)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IdentityCredential)
NS_INTERFACE_MAP_END_INHERITING(Credential)

JSObject* IdentityCredential::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return IdentityCredential_Binding::Wrap(aCx, this, aGivenProto);
}

void IdentityCredential::GetToken(nsAString& aToken) const {
aToken.Assign(mToken);
}
void IdentityCredential::SetToken(const nsAString& aToken) {
mToken.Assign(aToken);
}

} // namespace mozilla::dom
43 changes: 43 additions & 0 deletions dom/credentialmanagement/identity/IdentityCredential.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* -*- 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_dom_IdentityCredential_h
#define mozilla_dom_IdentityCredential_h

#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/Credential.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"

namespace mozilla::dom {

class IdentityCredential final : public Credential {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(IdentityCredential,
Credential)

explicit IdentityCredential(nsPIDOMWindowInner* aParent);

protected:
~IdentityCredential() override;

public:
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

void GetToken(nsAString& aToken) const;
void SetToken(const nsAString& aToken);

private:
nsAutoString mToken;
};

} // namespace mozilla::dom

#endif // mozilla_dom_IdentityCredential_h
23 changes: 23 additions & 0 deletions dom/credentialmanagement/identity/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.


with Files("**"):
BUG_COMPONENT = ("Core", "DOM: Credential Management")

EXPORTS.mozilla.dom += [
"IdentityCredential.h",
]

UNIFIED_SOURCES += [
"IdentityCredential.cpp",
]

include("/ipc/chromium/chromium-config.mozbuild")

FINAL_LIBRARY = "xul"

MOCHITEST_MANIFESTS += ["tests/mochitest/mochitest.ini"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DEFAULT]
[test_identity_noop.html]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title><!-- TODO: insert title here --></title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
ok(true, "TODO: implement the test");
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>
2 changes: 2 additions & 0 deletions dom/credentialmanagement/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
with Files("**"):
BUG_COMPONENT = ("Core", "DOM: Web Authentication")

DIRS += ["identity"]

EXPORTS.mozilla.dom += [
"Credential.h",
"CredentialsContainer.h",
Expand Down
2 changes: 2 additions & 0 deletions dom/webidl/CredentialManagement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dictionary CredentialRequestOptions {
// https://w3c.github.io/webauthn/#sctn-credentialrequestoptions-extension
[Pref="security.webauth.webauthn"]
PublicKeyCredentialRequestOptions publicKey;
// This is taken from the partial definition in
// https://fedidcg.github.io/FedCM/#browser-api-credential-request-options
[Pref="dom.security.credentialmanagement.identity.enabled"]
IdentityCredentialRequestOptions identity;
AbortSignal signal;
Expand Down
21 changes: 21 additions & 0 deletions dom/webidl/IdentityCredential.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* -*- 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/.
*/

[Exposed=Window, SecureContext,
Pref="dom.security.credentialmanagement.identity.enabled"]
interface IdentityCredential : Credential {
readonly attribute USVString? token;
};

dictionary IdentityCredentialRequestOptions {
sequence<IdentityProvider> providers;
};

dictionary IdentityProvider {
required USVString configURL;
required USVString clientId;
USVString nonce;
};
7 changes: 7 additions & 0 deletions dom/webidl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ with Files("ConvolverNode.webidl"):
with Files("GeolocationCoordinates.webidl"):
BUG_COMPONENT = ("Core", "DOM: Geolocation")

with Files("CredentialManagement.webidl"):
BUG_COMPONENT = ("Core", "DOM: Credential Management")

with Files("Crypto.webidl"):
BUG_COMPONENT = ("Core", "DOM: Security")

Expand Down Expand Up @@ -148,6 +151,9 @@ with Files("HashChangeEvent.webidl"):
with Files("IDB*"):
BUG_COMPONENT = ("Core", "Storage: IndexedDB")

with Files("IdentityCredential.webidl"):
BUG_COMPONENT = ("Core", "DOM: Credential Management")

with Files("IIRFilterNode.webidl"):
BUG_COMPONENT = ("Core", "Web Audio")

Expand Down Expand Up @@ -667,6 +673,7 @@ WEBIDL_FILES = [
"IDBRequest.webidl",
"IDBTransaction.webidl",
"IDBVersionChangeEvent.webidl",
"IdentityCredential.webidl",
"IdleDeadline.webidl",
"IIRFilterNode.webidl",
"ImageBitmap.webidl",
Expand Down

0 comments on commit abad258

Please sign in to comment.