Skip to content

Commit 3f14c5c

Browse files
committed
Merge branch 'master' into release
2 parents a7c0a36 + 23f4e5d commit 3f14c5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3029
-1419
lines changed

build-system/tasks/presubmit-checks.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ var requiresReviewPrivacy =
2929
'being privacy sensitive. Please file an issue asking for permission' +
3030
' to use if you have not yet done so.';
3131

32+
var privateServiceFactory = 'This service should only be installed in ' +
33+
'the whitelisted files. Other modules should use a public function ' +
34+
'typically called serviceNameFor.';
35+
3236
// Terms that must not appear in our source files.
3337
var forbiddenTerms = {
3438
'DO NOT SUBMIT': '',
@@ -44,11 +48,32 @@ var forbiddenTerms = {
4448
'validator/validator-in-browser.js',
4549
]
4650
},
51+
// Service factories that should only be installed once.
52+
'installCidService': {
53+
message: privateServiceFactory,
54+
whitelist: [
55+
'src/service/cid-impl.js',
56+
'extensions/amp-analytics/0.1/amp-analytics.js',
57+
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
58+
'test/functional/test-cid.js',
59+
'test/functional/test-url-replacements.js'
60+
],
61+
},
62+
// Privacy sensitive
4763
'cidFor': {
4864
message: requiresReviewPrivacy,
4965
whitelist: [
5066
'src/cid.js',
5167
'src/service/cid-impl.js',
68+
'src/url-replacements.js',
69+
'test/functional/test-cid.js',
70+
],
71+
},
72+
'getBaseCid': {
73+
message: requiresReviewPrivacy,
74+
whitelist: [
75+
'src/service/cid-impl.js',
76+
'src/viewer.js',
5277
'test/functional/test-cid.js',
5378
],
5479
},
@@ -78,13 +103,15 @@ var forbiddenTerms = {
78103
'src/cookies.js',
79104
'src/experiments.js',
80105
'test/functional/test-cookies.js',
106+
'test/functional/test-url-replacements.js',
81107
'tools/experiments/experiments.js',
82108
]
83109
},
84110
'eval\\(': '',
85111
'localStorage': {
86112
message: requiresReviewPrivacy,
87113
whitelist: [
114+
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
88115
'test/_init_tests.js',
89116
'src/service/cid-impl.js',
90117
'test/functional/test-cid.js',

builtins/amp-ad.js

Lines changed: 1 addition & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -18,83 +18,19 @@ import {BaseElement} from '../src/base-element';
1818
import {assert} from '../src/asserts';
1919
import {getIntersectionChangeEntry} from '../src/intersection-observer';
2020
import {isLayoutSizeDefined} from '../src/layout';
21-
import {setStyles} from '../src/style';
2221
import {loadPromise} from '../src/event-helper';
2322
import {registerElement} from '../src/custom-element';
2423
import {getIframe, listenOnce, postMessage, prefetchBootstrap} from
2524
'../src/3p-frame';
2625
import {adPrefetch, adPreconnect} from '../ads/_prefetch';
2726
import {timer} from '../src/timer';
28-
import {vsyncFor} from '../src/vsync';
2927

3028

31-
/**
32-
* Preview phase only default backfill for ads. If the ad
33-
* cannot fill the slot one of these will be displayed instead.
34-
* @private @const
35-
*/
36-
const BACKFILL_IMGS_ = {
37-
'300x200': [
38-
39-
40-
41-
42-
43-
],
44-
'320x50': [
45-
46-
47-
],
48-
};
49-
50-
/** @private @const */
51-
const BACKFILL_DIMENSIONS_ = [
52-
[300, 200],
53-
[320, 50],
54-
];
55-
5629
/** @private @const These tags are allowed to have fixed positioning */
5730
const POSITION_FIXED_TAG_WHITELIST = {
5831
'AMP-LIGHTBOX': true
5932
};
6033

61-
/**
62-
* Preview phase helper to score images through their dimensions.
63-
* @param {!Array<!Array<number>>} dims
64-
* @param {number} maxWidth
65-
* @param {number} maxHeight
66-
* visibleForTesting
67-
*/
68-
export function scoreDimensions_(dims, maxWidth, maxHeight) {
69-
return dims.map(function(dim) {
70-
const width = dim[0];
71-
const height = dim[1];
72-
const widthScore = Math.abs(width - maxWidth);
73-
// if the width is over the max then we need to penalize it
74-
const widthPenalty = Math.abs((maxWidth - width) * 3);
75-
// we add a multiplier to height as we prioritize it more than width
76-
const heightScore = Math.abs(height - maxHeight) * 2;
77-
// if the height is over the max then we need to penalize it
78-
const heightPenalty = Math.abs((maxHeight - height) * 2.5);
79-
80-
return (widthScore - widthPenalty) + (heightScore - heightPenalty);
81-
});
82-
}
83-
84-
/**
85-
* Preview phase helper to update a @1x.png string to @2x.png.
86-
* @param {!Object<string, !Array<string>>} images
87-
* visibleForTesting
88-
*/
89-
export function upgradeImages_(images) {
90-
Object.keys(images).forEach(key => {
91-
const curDimImgs = images[key];
92-
curDimImgs.forEach((item, index) => {
93-
curDimImgs[index] = item.replace(/@1x\.png$/, '@2x.png');
94-
});
95-
});
96-
}
97-
9834

9935
/**
10036
* @param {!Window} win Destination window for the new element.
@@ -155,9 +91,6 @@ export function installAd(win) {
15591
/** @private {?Element} */
15692
this.fallback_ = this.getFallback();
15793

158-
/** @private {boolean} */
159-
this.isDefaultFallback_ = false;
160-
16194
/** @private {boolean} */
16295
this.isInFixedContainer_ = false;
16396

@@ -177,14 +110,6 @@ export function installAd(win) {
177110

178111
/** @private {boolean} */
179112
this.shouldSendIntersectionChanges_ = false;
180-
181-
if (!this.fallback_) {
182-
this.isDefaultFallback_ = true;
183-
184-
if (this.getDpr() >= 0.5) {
185-
upgradeImages_(BACKFILL_IMGS_);
186-
}
187-
}
188113
}
189114

190115
/**
@@ -351,56 +276,10 @@ export function installAd(win) {
351276
* @private
352277
*/
353278
noContentHandler_() {
354-
if (this.isDefaultFallback_) {
355-
this.setDefaultFallback_();
356-
this.element.appendChild(this.fallback_);
357-
}
358279
this.element.removeChild(this.iframe_);
359280
this.toggleFallback(true);
360281
}
361-
362-
/**
363-
* This is a preview-phase only thing where if the ad says that it
364-
* cannot fill the slot we select from a small set of default
365-
* banners.
366-
* @private
367-
* visibleForTesting
368-
*/
369-
setDefaultFallback_() {
370-
const a = document.createElement('a');
371-
a.href = 'https://www.ampproject.org';
372-
a.target = '_blank';
373-
a.setAttribute('fallback', '');
374-
const img = new Image();
375-
setStyles(img, {
376-
width: 'auto',
377-
height: '100%',
378-
margin: 'auto',
379-
});
380-
381-
const winner = this.getFallbackImage_();
382-
img.src = `https://ampproject.org/backfill/${winner}`;
383-
this.fallback_ = a;
384-
a.appendChild(img);
385-
}
386-
387-
/**
388-
* Picks a random backfill image for the case that no real ad can be
389-
* shown.
390-
* @private
391-
* @return {string} The image URL.
392-
*/
393-
getFallbackImage_() {
394-
const scores = scoreDimensions_(BACKFILL_DIMENSIONS_,
395-
this.element./*REVIEW*/clientWidth,
396-
this.element./*REVIEW*/clientHeight);
397-
const dims = BACKFILL_DIMENSIONS_[
398-
scores.indexOf(Math.max.apply(Math, scores))];
399-
const images = BACKFILL_IMGS_[dims.join('x')];
400-
// do we need a more sophisticated randomizer?
401-
return images[Math.floor(Math.random() * images.length)];
402-
}
403-
};
282+
}
404283

405284
registerElement(win, 'amp-ad', AmpAd);
406285
}

builtins/amp-pixel.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ export function installPixel(win) {
4444

4545
/** @override */
4646
layoutCallback() {
47-
let src = this.element.getAttribute('src');
48-
src = urlReplacementsFor(this.getWin()).expand(this.assertSource(src));
49-
const image = new Image();
50-
image.src = src;
51-
image.width = 1;
52-
image.height = 1;
53-
// Make it take zero space
54-
this.element.style.width = 0;
55-
this.element.appendChild(image);
56-
return Promise.resolve();
47+
const src = this.element.getAttribute('src');
48+
return urlReplacementsFor(this.getWin()).expand(this.assertSource(src))
49+
.then(src => {
50+
const image = new Image();
51+
image.src = src;
52+
image.width = 1;
53+
image.height = 1;
54+
// Make it take zero space
55+
this.element.style.width = 0;
56+
this.element.appendChild(image);
57+
});
5758
}
5859

5960
assertSource(src) {

examples/ads.amp.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,5 @@ <h2>Doubleclick no ad with placeholder and fallback</h2>
100100
<p>You got lucky! We have no ad to show to you!</p>
101101
</div>
102102
</amp-ad>
103-
104-
<h2>Doubleclick no ad default fallback</h2>
105-
<amp-ad width=300 height=200
106-
type="doubleclick"
107-
data-slot="/4119129/doesnt-exist">
108-
</amp-ad>
109-
110-
<h2>Doubleclick no ad default fallback</h2>
111-
<amp-ad width=300 height=50
112-
type="doubleclick"
113-
data-slot="/4119129/doesnt-exist">
114-
</amp-ad>
115-
116103
</body>
117104
</html>

examples/analytics.amp.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,27 @@
55
<title>AMP Analytics</title>
66
<link rel="canonical" href="analytics.amp.html" >
77
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
8+
<style amp-custom>
9+
.box {
10+
background: #ccc;
11+
border: 1px solid #aaa;
12+
padding: 10px;
13+
margin: 10px;
14+
}
15+
</style>
816
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
917
<style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript>
1018
<script async src="https://cdn.ampproject.org/v0.js"></script>
1119
</head>
1220
<body>
1321

1422
<amp-analytics id="analytics1">
23+
<script type="application/json">
1524
{
1625
"host": "example.com",
1726
"requests": {
18-
"base": "/log?domain=DOMAIN&amp;path=PATH&amp;title=${title}",
19-
"event": "${base}&amp;name=${eventName}&amp;type=${eventId}"
27+
"base": "?domain=${canonicalHost}&path=${canonicalPath}&title=${title}",
28+
"event": "${base}&name=${eventName}&type=${eventId}&time=${timestamp}&tz=${timezone}&pid=${pageViewId}&screenSize=${screenWidth}x${screenHeight}"
2029
},
2130
"vars": {
2231
"title": "Example Request"
@@ -30,25 +39,49 @@
3039
}
3140
}]
3241
}
42+
</script>
3343
</amp-analytics>
3444

3545
<amp-analytics type="googleanalytics" id="analytics2">
46+
<script type="application/json">
3647
{
3748
"vars": {
3849
"account": "UA-XXXX-Y"
3950
},
4051
"triggers": [{
4152
"on": "visible",
4253
"request": "pageview",
43-
"vars" : {
54+
"vars": {
4455
"title": "Example Pageview"
4556
}
57+
}, {
58+
"on": "click",
59+
"selector": "#test1",
60+
"request": "event",
61+
"vars": {
62+
"eventCategory": "examples",
63+
"eventAction": "clicked-test1"
64+
}
65+
}, {
66+
"on": "click",
67+
"selector": "#top",
68+
"request": "event",
69+
"vars": {
70+
"eventCategory": "examples",
71+
"eventAction": "clicked-header"
72+
}
4673
}]
4774
}
75+
</script>
4876
</amp-analytics>
4977

5078
<div class="logo"></div>
5179
<h1 id="top">AMP Analytics</h1>
80+
81+
<span id="test1" class="box">
82+
Click here to generate an event
83+
</span>
84+
5285
</body>
5386
</html>
5487

examples/pinterest.amp.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,5 +458,19 @@ <h4>Large Circle (Red Only, Count Not Available)</h4>
458458
data-description="Next stop: Pinterest">
459459
</amp-pinterest>
460460

461+
<h4>Follow Button</h4>
462+
463+
<amp-pinterest height=20 width=87
464+
data-do="buttonFollow"
465+
data-href="https://www.pinterest.com/zackargyle/"
466+
data-label="Zack Argyle">
467+
</amp-pinterest>
468+
469+
<amp-pinterest height=20 width=87
470+
data-do="buttonFollow"
471+
data-href="https://www.pinterest.com/zackargyle"
472+
data-label="Zack Argyle">
473+
</amp-pinterest>
474+
461475
</body>
462476
</html>

0 commit comments

Comments
 (0)