MCPcopy Index your code
hub / github.com/ampproject/amphtml / getContextMetadata

Function getContextMetadata

src/iframe-attributes.js:21–93  ·  view source on GitHub ↗
(
  parentWindow,
  element,
  sentinel,
  attributes
)

Source from the content-addressed store, hash-verified

19 * @return {!JsonObject}
20 */
21export function getContextMetadata(
22 parentWindow,
23 element,
24 sentinel,
25 attributes
26) {
27 const startTime = Date.now();
28 const width = element.getAttribute('width');
29 const height = element.getAttribute('height');
30 attributes = attributes ? attributes : {};
31 attributes['width'] = getLengthNumeral(width);
32 attributes['height'] = getLengthNumeral(height);
33 if (element.getAttribute('title')) {
34 attributes['title'] = element.getAttribute('title');
35 }
36 let locationHref = parentWindow.location.href;
37 // This is really only needed for tests, but whatever. Children
38 // see us as the logical origin, so telling them we are about:srcdoc
39 // will fail ancestor checks.
40 if (locationHref == 'about:srcdoc') {
41 locationHref = parentWindow.parent.location.href;
42 }
43
44 const ampdoc = Services.ampdoc(element);
45 const docInfo = Services.documentInfoForDoc(element);
46 const viewer = Services.viewerForDoc(element);
47 const referrer = viewer.getUnconfirmedReferrerUrl();
48
49 const layoutRect = getPageLayoutBoxBlocking(element);
50
51 // Use JsonObject to preserve field names so that ampContext can access
52 // values with name
53 // ampcontext.js and this file are compiled in different compilation unit
54
55 // Note: Field names can by preserved by using JsonObject, or by adding
56 // preserved name to extern. We are doing both right now.
57 // Please also add new introduced variable
58 // name to the extern list.
59 attributes['_context'] = {
60 'ampcontextVersion': mode.version(),
61 'ampcontextFilepath': `${
62 urls.thirdParty
63 }/${mode.version()}/ampcontext-v0.js`,
64 'sourceUrl': docInfo.sourceUrl,
65 'referrer': referrer,
66 'canonicalUrl': docInfo.canonicalUrl,
67 'pageViewId': docInfo.pageViewId,
68 'location': {
69 'href': locationHref,
70 },
71 'startTime': startTime,
72 'tagName': element.tagName,
73 'mode': getModeObject(),
74 'canary': isCanary(parentWindow),
75 'hidden': !ampdoc.isVisible(),
76 'initialLayoutRect': layoutRect
77 ? {
78 'left': layoutRect.left,

Callers 5

getFrameAttributesFunction · 0.90
renderViaIframeGet_Method · 0.90
renderMethod · 0.90
renderViaIframeGet_Method · 0.90

Calls 10

getLengthNumeralFunction · 0.90
getPageLayoutBoxBlockingFunction · 0.90
getModeObjectFunction · 0.90
isCanaryFunction · 0.85
experimentTogglesFunction · 0.85
nowMethod · 0.80
getAttributeMethod · 0.80
generateMethod · 0.80
isVisibleMethod · 0.45

Tested by

no test coverage detected