Skip to content

Commit

Permalink
amp-action: Support whitelist lookup in AmpDocShadow (#26684)
Browse files Browse the repository at this point in the history
* amp-action: Support whitelist lookup in ShadowRoot

New getMetaByName method supports retrieving meta content values in
shadow docs as well.

* amp-action: Remove unnecessary doc check

It is safe to assume that either document.head is available if
AmpDocSingle/AmpDocFie, or that AmpDoc.meta_ is non-null if
AmpDocShadow.
  • Loading branch information
mdmower committed Feb 22, 2020
1 parent ecfb6c1 commit 4c71f6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/service/action-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,17 +807,12 @@ export class ActionService {
* @private
*/
queryWhitelist_() {
const {head} = this.ampdoc.getRootNode();
if (!head) {
return null;
}
const meta = head.querySelector('meta[name="amp-action-whitelist"]');
if (!meta) {
const actionWhitelist = this.ampdoc.getMetaByName('amp-action-whitelist');
if (actionWhitelist === null) {
return null;
}
return (
meta
.getAttribute('content')
actionWhitelist
.split(',')
// Turn an empty string whitelist into an empty array, otherwise the
// parse error in the mapper below would trigger.
Expand Down
9 changes: 8 additions & 1 deletion test/unit/test-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ import {whenCalled} from '../../testing/test-helper.js';
*/
function actionService() {
const win = {
document: {body: {}},
document: {
body: {},
head: {
nodeType: /* ELEMENT */ 1,
querySelector: () => null,
querySelectorAll: () => [],
},
},
__AMP_SERVICES: {
vsync: {obj: {}},
},
Expand Down

0 comments on commit 4c71f6c

Please sign in to comment.