* @param {!ActionInvocation} invocation * @return {?Promise} * @private
(invocation)
| 669 | * @private |
| 670 | */ |
| 671 | invoke_(invocation) { |
| 672 | const {method, tagOrTarget} = invocation; |
| 673 | |
| 674 | // Check that this action is allowlisted (if a allowlist is set). |
| 675 | if (this.allowlist_) { |
| 676 | if (!isActionAllowlisted(invocation, this.allowlist_)) { |
| 677 | this.error_( |
| 678 | `"${tagOrTarget}.${method}" is not allowlisted ${JSON.stringify( |
| 679 | this.allowlist_ |
| 680 | )}.` |
| 681 | ); |
| 682 | return null; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | // Handle global targets e.g. "AMP". |
| 687 | const globalTarget = this.globalTargets_[tagOrTarget]; |
| 688 | if (globalTarget) { |
| 689 | return globalTarget(invocation); |
| 690 | } |
| 691 | |
| 692 | // Subsequent handlers assume that invocation target is an Element. |
| 693 | const node = dev().assertElement(invocation.node); |
| 694 | |
| 695 | // Handle global actions e.g. "<any-element-id>.toggle". |
| 696 | const globalMethod = this.globalMethodHandlers_[method]; |
| 697 | if (globalMethod && invocation.satisfiesTrust(globalMethod.minTrust)) { |
| 698 | return globalMethod.handler(invocation); |
| 699 | } |
| 700 | |
| 701 | // Handle element-specific actions. |
| 702 | const lowerTagName = node.tagName.toLowerCase(); |
| 703 | if (isAmpTagName(lowerTagName)) { |
| 704 | if (node.enqueAction) { |
| 705 | node.enqueAction(invocation); |
| 706 | } else { |
| 707 | this.error_(`Unrecognized AMP element "${lowerTagName}".`, node); |
| 708 | } |
| 709 | return null; |
| 710 | } |
| 711 | |
| 712 | // Special non-AMP elements with AMP ID or known supported actions. |
| 713 | const nonAmpActions = NON_AMP_ELEMENTS_ACTIONS_[lowerTagName]; |
| 714 | // TODO(dvoytenko, #7063): switch back to `target.id` with form proxy. |
| 715 | const targetId = node.getAttribute('id') || ''; |
| 716 | if ( |
| 717 | isAmpTagName(targetId) || |
| 718 | (nonAmpActions && nonAmpActions.indexOf(method) > -1) |
| 719 | ) { |
| 720 | const handler = node[ACTION_HANDLER_]; |
| 721 | if (handler) { |
| 722 | handler(invocation); |
| 723 | } else { |
| 724 | node[ACTION_QUEUE_] = node[ACTION_QUEUE_] || []; |
| 725 | node[ACTION_QUEUE_].push(invocation); |
| 726 | } |
| 727 | return null; |
| 728 | } |
no test coverage detected