-
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
Add AMP.navigateTo action #9932
Changes from 3 commits
ffc0936
7609c53
e0b7047
143d929
2bca73d
f004ff3
cd6d9dd
4a402ab
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import {ActionTrust} from '../action-trust'; | ||
import {OBJECT_STRING_ARGS_KEY} from '../service/action-impl'; | ||
import {Layout, getLayoutClass} from '../layout'; | ||
import {actionServiceForDoc} from '../services'; | ||
import {actionServiceForDoc, urlReplacementsForDoc} from '../services'; | ||
import {bindForDoc} from '../services'; | ||
import {dev, user} from '../log'; | ||
import {registerServiceBuilderForDoc} from '../service'; | ||
|
@@ -55,6 +55,9 @@ export class StandardActions { | |
/** @const @private {!./resources-impl.Resources} */ | ||
this.resources_ = resourcesForDoc(ampdoc); | ||
|
||
/** @const @private {!./url-replacements-impl.UrlReplacements} */ | ||
this.urlReplacements_ = urlReplacementsForDoc(ampdoc); | ||
|
||
this.installActions_(this.actions_); | ||
} | ||
|
||
|
@@ -87,6 +90,9 @@ export class StandardActions { | |
case 'setState': | ||
this.handleAmpSetState_(invocation); | ||
return; | ||
case 'navigateTo': | ||
this.handleAmpNavigateTo_(invocation); | ||
return; | ||
case 'goBack': | ||
this.handleAmpGoBack_(invocation); | ||
return; | ||
|
@@ -121,6 +127,21 @@ export class StandardActions { | |
}); | ||
} | ||
|
||
/** | ||
* @param {!./action-impl.ActionInvocation} invocation | ||
* @private | ||
*/ | ||
handleAmpNavigateTo_(invocation) { | ||
if (!invocation.satisfiesTrust(ActionTrust.HIGH)) { | ||
return; | ||
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. Maybe a 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. Already happens inside |
||
} | ||
const url = invocation.args['url']; | ||
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. use 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. Good catch. Done. 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. Would an error message here be better, or would you prefer it silently fail? 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. Good idea. Added a user error. |
||
const expandedUrl = this.urlReplacements_.expandUrlSync(url); | ||
const node = invocation.target; | ||
const win = (node.ownerDocument || node).defaultView; | ||
win.location = expandedUrl; | ||
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. do we wanna take an optional 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. For nested iframes? I haven't heard this particular FR and it can be accomplished by binding to 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. Mostly was thinking about 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. Oh I see. Looks like 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. sgtm |
||
} | ||
|
||
/** | ||
* @param {!./action-impl.ActionInvocation} invocation | ||
* @private | ||
|
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.
@jridgewell FYI I think this is the correct trust level for clicking a button via keyboard.