Skip to content

Commit

Permalink
DocInfo: Revisions
Browse files Browse the repository at this point in the history
- Restore metaTags property in data object send with DocumentLoaded
  message (read by viewers)
- Always get viewport of host document, not of individual AmpDocShadow
  instances.
- Remove unnecessary test modifications
  • Loading branch information
mdmower committed Feb 21, 2020
1 parent 899cdad commit eb7c966
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion extensions/amp-viewer-integration/amp-doc-viewer-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The messages in this section are sent by the Viewer Integration Script and are n
| `bindReady` | Sent from AMP pages that use the amp-bind extension. Informs the Viewer that amp-bind has completed initialization. | undefined | undefined |
| `cancelFullOverlay` | Requests that Full Overlay mode is cancelled. If the header was hidden, it should be restored. | undefined | undefined (The response is sent once Viewer exits Full Overlay mode.) |
| `cid` | Requests the scoped Client ID. See Client identifiers in AMP. | undefined | string (The scoped Client ID.) |
| `documentHeight` | The AMP runtime sends this request to the Viewer when the height of the document content changes. | {'height: (number)} | undefined |
| `documentHeight` | The AMP runtime sends this request to the Viewer when the height of the document content changes. | {'height': (number)} | undefined |
| `documentLoaded` | The AMP runtime sends this request to the Viewer when it has fully loaded and is ready for display. | {'linkRels': (Map<string, string\|Array<string>>), 'viewport': (string), 'title': (string), 'sourceUrl': (string)}, where linkRels is a map <link> rel values to hrefs. | undefined |
| `loadStore` | Requests the local storage blob for the document's origin. | {'origin': (string)} | {'blob': (string)} |
| `openDialog` | Requests that the AMP Access dialog with a specified URL is opened by the Viewer. | {'url': (string)} | string (The response is the token string from the dialog if the flow completed successfully. If the dialog is closed without completing the flow, then the response is rejected.) |
Expand Down
13 changes: 12 additions & 1 deletion src/service/document-info-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class DocInfo {
}
const pageViewId = getPageViewId(ampdoc.win);
const linkRels = getLinkRels(ampdoc.win.document);
const viewport = ampdoc.getMetaByName('viewport');
const viewport = getViewport(ampdoc.win.document);
const replaceParams = getReplaceParams(ampdoc);

return (this.info_ = {
Expand Down Expand Up @@ -170,6 +170,17 @@ function getLinkRels(doc) {
return linkRels;
}

/**
* Returns the viewport of the document. Note that this is the viewport of the
* host document for AmpDocShadow instances.
* @param {!Document} doc
* @return {?string}
*/
function getViewport(doc) {
const viewportEl = doc.head.querySelector('meta[name="viewport"]');
return viewportEl ? viewportEl.getAttribute('content') : null;
}

/**
* Attempts to retrieve extra parameters from the "amp_r" query param,
* returning null if invalid.
Expand Down
4 changes: 4 additions & 0 deletions src/service/resources-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,17 @@ export class ResourcesImpl {
this.firstPassAfterDocumentReady_ = false;
const doc = this.win.document;
const documentInfo = Services.documentInfoForDoc(this.ampdoc);

// TODO(choumx, #26687): Update viewers to read data.viewport instead of
// data.metaTags.viewport from 'documentLoaded' message.
this.viewer_.sendMessage(
'documentLoaded',
dict({
'title': doc.title,
'sourceUrl': getSourceUrl(this.ampdoc.getUrl()),
'serverLayout': doc.documentElement.hasAttribute('i-amphtml-element'),
'linkRels': documentInfo.linkRels,
'metaTags': {'viewport': documentInfo.viewport} /* deprecated */,
'viewport': documentInfo.viewport,
}),
/* cancelUnsent */ true
Expand Down

0 comments on commit eb7c966

Please sign in to comment.