-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
✨auto-lightbox: Discard tap actions with invalid references #20789
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b518536
✨auto-lightbox: Discard tap actions with invalid references
alanorozco cce4bfc
brevity
alanorozco 445a45c
comment
alanorozco 0b9eaec
type
alanorozco 6d395a5
Action test
alanorozco 978aacd
One more test
alanorozco f01fbea
doc, type
alanorozco 9526a87
wording
alanorozco 427a534
moar woerdeng
alanorozco 5e07af3
private
alanorozco 51d831a
Remove on action
alanorozco ee3cf57
Address Review
alanorozco c302e77
remove test
alanorozco 86cae68
Merge branch 'master' of github.com:ampproject/amphtml into resolve-tap
alanorozco 64db567
Remove obsolete comment
alanorozco dad7b6e
Don't create AmpDoc in test
alanorozco 3d7368b
Merge branch 'master' of github.com:ampproject/amphtml into resolve-tap
alanorozco e91ca33
naming
alanorozco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,6 +446,35 @@ export class ActionService { | |
return !!this.findAction_(target, actionEventType, opt_stopAt); | ||
} | ||
|
||
/** | ||
* Checks if the given element's registered action resolves to at least one | ||
* existing element by id or a global target (e.g. "AMP"). | ||
* @param {!Element} target | ||
* @param {string} actionEventType | ||
* @param {!Element=} opt_stopAt | ||
* @return {boolean} | ||
*/ | ||
hasResolvableAction(target, actionEventType, opt_stopAt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Rename |
||
const action = this.findAction_(target, actionEventType, opt_stopAt); | ||
if (!action) { | ||
return false; | ||
} | ||
return action.actionInfos.some(({target}) => !!this.getActionNode_(target)); | ||
} | ||
|
||
/** | ||
* For global targets e.g. "AMP", returns the document root. Otherwise, | ||
* `target` is an element id and the corresponding element is returned. | ||
* @param {string} target | ||
* @return {?Document|?Element|?ShadowRoot} | ||
* @private | ||
*/ | ||
getActionNode_(target) { | ||
return this.globalTargets_[target] ? | ||
this.root_ : | ||
this.root_.getElementById(target); | ||
} | ||
|
||
/** | ||
* Sets the action whitelist. Can be used to clear it. | ||
* @param {!Array<{tagOrTarget: string, method: string}>} whitelist | ||
|
@@ -485,25 +514,19 @@ export class ActionService { | |
// Invoke actions serially, where each action waits for its predecessor | ||
// to complete. `currentPromise` is the i'th promise in the chain. | ||
let currentPromise = null; | ||
action.actionInfos.forEach(actionInfo => { | ||
const {target} = actionInfo; | ||
action.actionInfos.forEach(({target, args, method, str}) => { | ||
// Replace any variables in args with data in `event`. | ||
const args = dereferenceExprsInArgs(actionInfo.args, event); | ||
const dereferencedArgs = dereferenceExprsInArgs(args, event); | ||
const invokeAction = () => { | ||
// For global targets e.g. "AMP, `node` is the document root. Otherwise, | ||
// `target` is an element id and `node` is the corresponding element. | ||
const node = (this.globalTargets_[target]) | ||
? this.root_ | ||
: this.root_.getElementById(target); | ||
if (node) { | ||
const invocation = new ActionInvocation(node, actionInfo.method, | ||
args, source, action.node, event, trust, | ||
actionEventType, node.tagName || target, sequenceId); | ||
return this.invoke_(invocation); | ||
} else { | ||
this.error_(`Target "${target}" not found for action ` + | ||
`[${actionInfo.str}].`); | ||
const node = this.getActionNode_(target); | ||
if (!node) { | ||
this.error_(`Target "${target}" not found for action [${str}].`); | ||
return; | ||
} | ||
const invocation = new ActionInvocation(node, method, | ||
dereferencedArgs, source, action.node, event, trust, | ||
actionEventType, node.tagName || target, sequenceId); | ||
return this.invoke_(invocation); | ||
}; | ||
// Wait for the previous action, if any. | ||
currentPromise = (currentPromise) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mm, this is probably harmless in all cases but not very comfortable removing
on
from user-code, even if invalid. also this removeson
always but check is fortap
only ( although I don't think there is any other events beside tap for images anyway ).Anyway, let's make
meetsHeuristicsForTap_
in lightbox to use the newhasResolvableAction
?