From ebfdbc3cfddc315c20f07dd60566a8d67ba2d369 Mon Sep 17 00:00:00 2001 From: Corey Masanto Date: Mon, 23 May 2022 16:38:36 -0400 Subject: [PATCH 1/4] Enable amp-story-360 and amp-story-captions in preview mode --- extensions/amp-story-360/0.1/amp-story-360.js | 5 +++++ extensions/amp-story-captions/0.1/amp-story-captions.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/extensions/amp-story-360/0.1/amp-story-360.js b/extensions/amp-story-360/0.1/amp-story-360.js index 1d78daece321..d07017495a17 100644 --- a/extensions/amp-story-360/0.1/amp-story-360.js +++ b/extensions/amp-story-360/0.1/amp-story-360.js @@ -228,6 +228,11 @@ class CameraAnimation { } export class AmpStory360 extends AMP.BaseElement { + /** @override */ + static previewAllowed() { + return true; + } + /** @param {!AmpElement} element */ constructor(element) { super(element); diff --git a/extensions/amp-story-captions/0.1/amp-story-captions.js b/extensions/amp-story-captions/0.1/amp-story-captions.js index 0d3c1f542cca..115390a18c49 100644 --- a/extensions/amp-story-captions/0.1/amp-story-captions.js +++ b/extensions/amp-story-captions/0.1/amp-story-captions.js @@ -17,6 +17,11 @@ import {createShadowRootWithStyle} from '../../amp-story/1.0/utils'; const presetValues = ['default', 'appear']; export class AmpStoryCaptions extends AMP.BaseElement { + /** @override */ + static previewAllowed() { + return true; + } + /** @param {!AmpElement} element */ constructor(element) { super(element); From 7048b4a2a32fd5954d36f0bc9193f7302b496a60 Mon Sep 17 00:00:00 2001 From: Corey Masanto Date: Wed, 25 May 2022 13:22:44 -0400 Subject: [PATCH 2/4] Create skeleton code for AmpStory360's previewAllowed() --- extensions/amp-story-360/0.1/amp-story-360.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/extensions/amp-story-360/0.1/amp-story-360.js b/extensions/amp-story-360/0.1/amp-story-360.js index d07017495a17..420fff8079ee 100644 --- a/extensions/amp-story-360/0.1/amp-story-360.js +++ b/extensions/amp-story-360/0.1/amp-story-360.js @@ -229,8 +229,24 @@ class CameraAnimation { export class AmpStory360 extends AMP.BaseElement { /** @override */ - static previewAllowed() { - return true; + static previewAllowed(element) { + let mediaElementIsCached = true; + + const imgEl = element.querySelector('amp-img'); + if (imgEl) { + let isImgElCached; // How do I determine whether an image is cached? + mediaElementIsCached &&= isImgElCached; + } + + const videoEl = element.querySelector('amp-video'); + if (videoEl) { + let isVideoElCached; // How do I determine whether a video is cached? + mediaElementIsCached &&= isVideoElCached; + } + + // Only allow preview mode if the video or image source is cached, because + // requests for origin sources cannot be made due to privacy concerns. + return mediaElementIsCached; } /** @param {!AmpElement} element */ From a0750b183553f21fc3e2bbcc5857f01bb15dfd99 Mon Sep 17 00:00:00 2001 From: Corey Masanto Date: Wed, 25 May 2022 16:07:14 -0400 Subject: [PATCH 3/4] Update AmpStory360.previewAllowed() to allow preview mode as long as video is not being used as the 360 media source --- extensions/amp-story-360/0.1/amp-story-360.js | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/extensions/amp-story-360/0.1/amp-story-360.js b/extensions/amp-story-360/0.1/amp-story-360.js index 420fff8079ee..d232cf190045 100644 --- a/extensions/amp-story-360/0.1/amp-story-360.js +++ b/extensions/amp-story-360/0.1/amp-story-360.js @@ -230,23 +230,12 @@ class CameraAnimation { export class AmpStory360 extends AMP.BaseElement { /** @override */ static previewAllowed(element) { - let mediaElementIsCached = true; - - const imgEl = element.querySelector('amp-img'); - if (imgEl) { - let isImgElCached; // How do I determine whether an image is cached? - mediaElementIsCached &&= isImgElCached; - } - - const videoEl = element.querySelector('amp-video'); - if (videoEl) { - let isVideoElCached; // How do I determine whether a video is cached? - mediaElementIsCached &&= isVideoElCached; - } - - // Only allow preview mode if the video or image source is cached, because - // requests for origin sources cannot be made due to privacy concerns. - return mediaElementIsCached; + // We can assume that images are cached, but the same is not necessarily + // true for videos. We only allow preview mode for `AmpStory360` when it + // uses cached sources, because requests for origin sources cannot be made + // due to privacy concerns. + const usesVideo = element.querySelector('amp-video'); + return !usesVideo; } /** @param {!AmpElement} element */ From b3299fdc9d73f1db1363a6b0c8f21ccb5364cf95 Mon Sep 17 00:00:00 2001 From: Corey Masanto Date: Wed, 8 Jun 2022 15:58:50 -0400 Subject: [PATCH 4/4] Revert allowing amp-story-captions because ensuring its tracks use cached sources is likely complex --- extensions/amp-story-captions/0.1/amp-story-captions.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/extensions/amp-story-captions/0.1/amp-story-captions.js b/extensions/amp-story-captions/0.1/amp-story-captions.js index 115390a18c49..0d3c1f542cca 100644 --- a/extensions/amp-story-captions/0.1/amp-story-captions.js +++ b/extensions/amp-story-captions/0.1/amp-story-captions.js @@ -17,11 +17,6 @@ import {createShadowRootWithStyle} from '../../amp-story/1.0/utils'; const presetValues = ['default', 'appear']; export class AmpStoryCaptions extends AMP.BaseElement { - /** @override */ - static previewAllowed() { - return true; - } - /** @param {!AmpElement} element */ constructor(element) { super(element);