-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add GDPR/consent support to amp-slikeplayer #40500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import {installVideoManagerForDoc} from '#service/video-manager-impl'; | |
| import {getData, listen} from '#utils/event-helper'; | ||
| import {userAssert} from '#utils/log'; | ||
|
|
||
| import {getConsentDataToForward} from '../../../src/consent'; | ||
| import {disableScrollingOnIframe} from '../../../src/iframe-helper'; | ||
| import { | ||
| addUnsafeAllowAutoplay, | ||
|
|
@@ -266,12 +267,20 @@ export class AmpSlikeplayer extends AMP.BaseElement { | |
| } | ||
|
|
||
| const data = objOrParseJson(messageData); | ||
|
|
||
| // Handle consent request from iframe (sent as raw object with type field) | ||
| if (data['type'] === 'send-consent-data') { | ||
| this.sendConsentData_(); | ||
| return; | ||
| } | ||
|
|
||
| const event = data['event']; | ||
| const detail = data['detail']; | ||
| if (event === 'ready') { | ||
| detail && this.onReadyOnce_(detail); | ||
| return; | ||
| } | ||
|
|
||
| const {element} = this; | ||
| if (redispatch(element, event, CleoEvent)) { | ||
| return; | ||
|
|
@@ -338,6 +347,29 @@ export class AmpSlikeplayer extends AMP.BaseElement { | |
| this.postMessage_('handleViewport', inViewport); | ||
| } | ||
|
|
||
| /** | ||
| * Fetches consent data from AMP consent service | ||
| * and forwards it to the iframe via postMessage. | ||
| * @private | ||
| */ | ||
| sendConsentData_() { | ||
| getConsentDataToForward(this.element, this.getConsentPolicy()).then( | ||
| (consents) => { | ||
| if (!this.iframe_ || !this.iframe_.contentWindow) { | ||
| return; | ||
| } | ||
| this.iframe_.contentWindow./*OK*/ postMessage( | ||
| { | ||
| 'sentinel': 'amp', | ||
| 'type': 'consent-data', | ||
| ...consents, | ||
| }, | ||
| this.targetOrigin_ | ||
| ); | ||
|
Comment on lines
+355
to
+368
|
||
| } | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @override | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import '../amp-slikeplayer'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {listenOncePromise} from '#utils/event-helper'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as consent from '../../../../src/consent'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {VideoEvents_Enum} from '../../../../src/video-interface'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describes.realWin( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -212,5 +213,53 @@ describes.realWin( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Subsequent layout should be possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await el.layoutCallback(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('calls sendConsentData_ on send-consent-data message', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const consentData = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| consentPolicyState: 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| consentString: 'abc123', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| consentMetadata: {gdprApplies: true, purposeOne: true}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| consentPolicySharedData: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env.sandbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .stub(consent, 'getConsentDataToForward') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .resolves(consentData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {iframe, impl} = await buildPlayer(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const sendSpy = env.sandbox.spy(impl, 'sendConsentData_'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Simulate consent request from iframe (raw object, not JSON) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl.onMessage_({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: iframe.contentWindow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: {type: 'send-consent-data', sentinel: 'amp'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(sendSpy).to.have.been.calledOnce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for the consent promise to resolve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await new Promise((r) => setTimeout(r, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(consent.getConsentDataToForward).to.have.been.calledOnce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+217
to
+243
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('does not send consent data if iframe is gone', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const consentData = {consentPolicyState: 2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env.sandbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .stub(consent, 'getConsentDataToForward') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .resolves(consentData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const {iframe, impl} = await buildPlayer(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Destroy iframe before consent resolves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl.iframe_ = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl.onMessage_({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: iframe.contentWindow, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: {type: 'send-consent-data', sentinel: 'amp'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await new Promise((r) => setTimeout(r, 0)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+247
to
+261
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env.sandbox | |
| .stub(consent, 'getConsentDataToForward') | |
| .resolves(consentData); | |
| const {iframe, impl} = await buildPlayer(); | |
| // Destroy iframe before consent resolves | |
| impl.iframe_ = null; | |
| impl.onMessage_({ | |
| source: iframe.contentWindow, | |
| data: {type: 'send-consent-data', sentinel: 'amp'}, | |
| }); | |
| await new Promise((r) => setTimeout(r, 0)); | |
| let resolveConsentData; | |
| const consentDataPromise = new Promise((resolve) => { | |
| resolveConsentData = resolve; | |
| }); | |
| env.sandbox | |
| .stub(consent, 'getConsentDataToForward') | |
| .returns(consentDataPromise); | |
| const {iframe, impl} = await buildPlayer(); | |
| impl.onMessage_({ | |
| source: iframe.contentWindow, | |
| data: {type: 'send-consent-data', sentinel: 'amp'}, | |
| }); | |
| // Destroy iframe while consent is still pending so the async guard | |
| // inside sendConsentData_() is exercised after the promise resolves. | |
| impl.iframe_ = null; | |
| resolveConsentData(consentData); | |
| await Promise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amp-geois configured with aneeagroup, but theamp-consentconfig doesn't reference any geo group (e.g., viapromptIfUnknownForGeoGroup/consentRequiredgating), so geo detection has no effect and the consent UI will always be required. Either wireamp-consentto theeeagroup as described in the PR summary, or remove the unusedamp-geoconfiguration from the example.