Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[gis_web] Uses TrustedTypes from pkg web.
  • Loading branch information
ditman committed Mar 5, 2024
commit c57815401f57078944ad20571d153929967ea7d0
4 changes: 4 additions & 0 deletions packages/google_identity_services_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.1+1

* Uses `TrustedTypes` from `web: ^0.5.1`.

## 0.3.1

* Updates web code to package `web: ^0.5.0`.
Expand Down
6 changes: 3 additions & 3 deletions packages/google_identity_services_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ description: An example for the google_identity_services_web package, OneTap.
publish_to: 'none'

environment:
flutter: ">=3.16.0"
sdk: ">=3.2.0 <4.0.0"
sdk: ^3.3.0
flutter: ">=3.19.0"

dependencies:
flutter:
sdk: flutter
google_identity_services_web:
path: ../
http: ">=0.13.0 <2.0.0"
web: ^0.5.0
web: ^0.5.1

dev_dependencies:
build_runner: ^2.1.10 # To extract README excerpts only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,20 @@ extension NullableTrustedTypesGetter on web.Window {
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
@JS('trustedTypes')
external TrustedTypePolicyFactory? get nullableTrustedTypes;

/// Bindings to window.trustedTypes.
///
/// This will crash if accessed in a browser that doesn't support the
/// Trusted Types API.
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
@JS('trustedTypes')
external TrustedTypePolicyFactory get trustedTypes;
external web.TrustedTypePolicyFactory? get nullableTrustedTypes;
}

/// This extension allows setting a TrustedScriptURL as the src of a script element,
/// which currently only accepts a string.
/// Allows setting a TrustedScriptURL as the src of a script element.
extension TrustedTypeSrcAttribute on web.HTMLScriptElement {
@JS('src')
external set trustedSrc(TrustedScriptURL value);
}

// TODO(kevmoo): drop all of this once `pkg:web` publishes `0.5.1`.

/// Bindings to a JS TrustedScriptURL.
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL
extension type TrustedScriptURL._(JSObject _) implements JSObject {}

/// Bindings to a JS TrustedTypePolicyFactory.
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory
extension type TrustedTypePolicyFactory._(JSObject _) implements JSObject {
///
external TrustedTypePolicy createPolicy(
String policyName, [
TrustedTypePolicyOptions policyOptions,
]);
external set trustedSrc(web.TrustedScriptURL value);
}

/// Bindings to a JS TrustedTypePolicy.
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy
extension type TrustedTypePolicy._(JSObject _) implements JSObject {
///
/// Allows creating a script URL only from a string, with no arguments.
extension CreateScriptUrlNoArgs on web.TrustedTypePolicy {
/// Allows calling `createScriptURL` with only the `input` argument.
@JS('createScriptURL')
external TrustedScriptURL createScriptURLNoArgs(
external web.TrustedScriptURL createScriptURLNoArgs(
String input,
);
}

/// Bindings to a JS TrustedTypePolicyOptions (anonymous).
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory/createPolicy#policyoptions
extension type TrustedTypePolicyOptions._(JSObject _) implements JSObject {
///
external factory TrustedTypePolicyOptions({
JSFunction createScriptURL,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Future<void> loadWebSdk({
onGoogleLibraryLoad = () => completer.complete();

// If TrustedTypes are available, prepare a trusted URL.
TrustedScriptURL? trustedUrl;
web.TrustedScriptURL? trustedUrl;
if (web.window.nullableTrustedTypes != null) {
web.console.debug(
'TrustedTypes available. Creating policy: $trustedTypePolicyName'.toJS,
);
try {
final TrustedTypePolicy policy = web.window.trustedTypes.createPolicy(
final web.TrustedTypePolicy policy = web.window.trustedTypes.createPolicy(
trustedTypePolicyName,
TrustedTypePolicyOptions(
web.TrustedTypePolicyOptions(
createScriptURL: ((JSString url) => _url).toJS,
));
trustedUrl = policy.createScriptURLNoArgs(_url);
Expand Down
4 changes: 2 additions & 2 deletions packages/google_identity_services_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: google_identity_services_web
description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22
version: 0.3.1
version: 0.3.1+1

environment:
sdk: ^3.3.0

dependencies:
meta: ^1.3.0
web: ^0.5.0
web: ^0.5.1

dev_dependencies:
path: ^1.8.1
Expand Down