Skip to content

Commit 562506d

Browse files
committed
Merge branch 'master' into release
2 parents ed3b071 + 8eec93e commit 562506d

File tree

151 files changed

+5994
-2710
lines changed

Some content is hidden

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

151 files changed

+5994
-2710
lines changed

.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
"no-throw-literal": 2,
4949
"no-trailing-spaces": 2,
5050
"no-unused-expressions": 0,
51+
"no-unused-vars": [2, {
52+
"argsIgnorePattern": "^var_|opt_|unused",
53+
"varsIgnorePattern": "AmpElement|Def|Interface$"
54+
}],
5155
"no-useless-call": 2,
5256
"no-useless-concat": 2,
5357
"no-var": 2,

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ script:
2222
- gulp build
2323
- gulp dist
2424
- gulp presubmit
25+
- gulp compile
2526
# Unit tests with Travis' default chromium
2627
- gulp test
2728
# Integration tests with all saucelabs browsers

3p/twitter.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// TODO(malteubl) Move somewhere else since this is not an ad.
1818

1919
import {loadScript} from '../src/3p';
20-
import {setStyles} from '../src/style';
2120

2221
/**
2322
* Produces the Twitter API object for the passed in callback. If the current
@@ -52,8 +51,6 @@ function getTwttr(global, cb) {
5251
export function twitter(global, data) {
5352
const tweet = document.createElement('div');
5453
tweet.id = 'tweet';
55-
const width = data.initialWindowWidth;
56-
const height = data.initialWindowHeight;
5754
tweet.style.width = '100%';
5855
global.document.getElementById('c').appendChild(tweet);
5956
getTwttr(global, function(twttr) {
@@ -65,7 +62,7 @@ export function twitter(global, data) {
6562
// Unfortunately the tweet isn't really done at this time.
6663
// We listen for resize to learn when things are
6764
// really done.
68-
iframe.contentWindow.addEventListener('resize', function(e) {
65+
iframe.contentWindow.addEventListener('resize', function() {
6966
render();
7067
}, true);
7168
render();

ads/adsense.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {writeScript, checkData} from '../src/3p';
17+
import {checkData} from '../src/3p';
1818

1919
/**
2020
* @param {!Window} global

ads/doubleclick.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export function doubleclick(global, data) {
6565
}
6666
});
6767

68-
const canvas = global.document.getElementById('c');
6968
// Exported for testing.
7069
c.slot = slot;
7170
googletag.display('c');

build-system/server.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* files and list directories for use with the gulp live server
2020
*/
2121
var app = require('connect')();
22+
var bodyParser = require('body-parser');
2223
var clr = require('connect-livereload');
2324
var finalhandler = require('finalhandler');
2425
var path = require('path');
@@ -29,9 +30,31 @@ var args = Array.prototype.slice.call(process.argv, 2, 4);
2930
var paths = args[0];
3031
var port = args[1];
3132

33+
app.use(bodyParser.json());
34+
35+
app.use('/api/show', function(req, res) {
36+
res.setHeader('Content-Type', 'application/json');
37+
res.end(JSON.stringify({
38+
showNotification: true
39+
}));
40+
});
41+
42+
app.use('/api/dont-show', function(req, res) {
43+
res.setHeader('Content-Type', 'application/json');
44+
res.end(JSON.stringify({
45+
showNotification: false
46+
}));
47+
});
48+
49+
50+
app.use('/api/echo/post', function(req, res) {
51+
res.setHeader('Content-Type', 'application/json');
52+
res.end(JSON.stringify(req.body, null, 2));
53+
});
54+
3255
app.use(clr());
3356

34-
paths.split(",").forEach(function(pth){
57+
paths.split(',').forEach(function(pth) {
3558
// Serve static files that exist
3659
app.use(serveStatic(path.join(process.cwd(), pth)));
3760
// Serve directory listings

build-system/tasks/compile.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright 2015 The AMP HTML Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS-IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
var closureCompiler = require('gulp-closure-compiler');
18+
var gulp = require('gulp');
19+
var rename = require('gulp-rename');
20+
var uglify = require('gulp-uglify');
21+
22+
// Compiles AMP with the closure compiler. This is intended only for
23+
// production use. During development we intent to continue using
24+
// babel, as it has much faster incremental compilation.
25+
// This currently only works for the main AMP JS binary, but should be
26+
// straight forward to extend to the rest of our code base.
27+
gulp.task('compile', function() {
28+
/*eslint "google-camelcase/google-camelcase": 0*/
29+
return gulp.src([
30+
'ads/**/*.js',
31+
'extensions/**/*.js',
32+
'build/css.js',
33+
'src/**/*.js',
34+
// We do not want to load the entry point that loads the babel helpers.
35+
'!src/amp-babel.js',
36+
'builtins/**.js',
37+
'third_party/caja/html-sanitizer.js',
38+
'third_party/closure-library/sha384-generated.js',
39+
'third_party/mustache/**/*.js',
40+
'node_modules/document-register-element/build/' +
41+
'document-register-element.max.js',
42+
'node_modules/core-js/modules/**.js',
43+
// Not sure what these files are, but they seem to duplicate code
44+
// one level below and confuse the compiler.
45+
'!node_modules/core-js/modules/library/**.js',
46+
// Don't include tests.
47+
'!**_test.js',
48+
'!**/test-*.js',
49+
])
50+
.pipe(closureCompiler({
51+
// Temporary shipping with our own compiler that has a single patch
52+
// applied
53+
compilerPath: 'third_party/closure-compiler/compiler.jar',
54+
fileName: 'build/cc-amp.js',
55+
compilerFlags: {
56+
// Transpile from ES6 to ES5.
57+
language_in: 'ECMASCRIPT6',
58+
language_out: 'ECMASCRIPT5',
59+
js_module_root: 'node_modules/',
60+
common_js_entry_module: 'src/amp.js',
61+
process_common_js_modules: true,
62+
// This strips all files from the input set that aren't explicitly
63+
// required.
64+
only_closure_dependencies: true,
65+
output_wrapper: '(function(){var process={env:{}};%output%})();'
66+
}
67+
}))
68+
.on('error', function(err) {
69+
if (/0 error\(s\)/.test(err.message)) {
70+
// emit warning
71+
console./*OK*/warn(err.message);
72+
this.emit('end');
73+
} else {
74+
throw err;
75+
}
76+
})
77+
.on('end', function() {
78+
console./*OK*/log('Minify closure compiler result');
79+
// Somewhat ironically we use uglify to further minify the result.
80+
// This is needed because we currently use only very basic optimizations
81+
// in closure compiler and it doesn't minify global variables at this
82+
// stage.
83+
return gulp.src(['build/cc-amp.js'])
84+
.pipe(uglify({
85+
preserveComments: 'some'
86+
}))
87+
.pipe(rename('cc-v0.js'))
88+
.pipe(gulp.dest('dist'))
89+
});
90+
});

build-system/tasks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require('./babel-helpers');
1818
require('./changelog');
1919
require('./clean');
20+
require('./compile');
2021
require('./lint');
2122
require('./make-golden');
2223
require('./presubmit-checks');

build-system/tasks/presubmit-checks.js

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,50 @@ var forbiddenTerms = {
4949
]
5050
},
5151
// Service factories that should only be installed once.
52+
'installActionService': {
53+
message: privateServiceFactory,
54+
whitelist: [
55+
'src/service/action-impl.js',
56+
'src/amp-core-service.js',
57+
],
58+
},
59+
'installActionHandler': {
60+
message: privateServiceFactory,
61+
whitelist: [
62+
'src/service/action-impl.js',
63+
'extensions/amp-access/0.1/amp-access.js',
64+
],
65+
},
5266
'installCidService': {
5367
message: privateServiceFactory,
5468
whitelist: [
5569
'src/service/cid-impl.js',
5670
'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'
71+
],
72+
},
73+
'installViewerService': {
74+
message: privateServiceFactory,
75+
whitelist: [
76+
'src/amp-core-service.js',
77+
'src/service/history-impl.js',
78+
'src/service/viewer-impl.js',
79+
'src/service/viewport-impl.js',
80+
'src/service/vsync-impl.js',
81+
],
82+
},
83+
'installViewportService': {
84+
message: privateServiceFactory,
85+
whitelist: [
86+
'src/amp-core-service.js',
87+
'src/service/viewport-impl.js',
88+
],
89+
},
90+
'installVsyncService': {
91+
message: privateServiceFactory,
92+
whitelist: [
93+
'src/amp-core-service.js',
94+
'src/service/viewport-impl.js',
95+
'src/service/vsync-impl.js',
6096
],
6197
},
6298
// Privacy sensitive
@@ -66,25 +102,21 @@ var forbiddenTerms = {
66102
'src/cid.js',
67103
'src/service/cid-impl.js',
68104
'src/url-replacements.js',
69-
'test/functional/test-cid.js',
105+
'extensions/amp-user-notification/0.1/amp-user-notification.js',
70106
],
71107
},
72108
'getBaseCid': {
73109
message: requiresReviewPrivacy,
74110
whitelist: [
75111
'src/service/cid-impl.js',
76-
'src/viewer.js',
77-
'test/functional/test-cid.js',
112+
'src/service/viewer-impl.js',
78113
],
79114
},
80115
'cookie\\W': {
81116
message: requiresReviewPrivacy,
82117
whitelist: [
83118
'src/cookies.js',
84119
'src/service/cid-impl.js',
85-
'test/functional/test-cid.js',
86-
'test/functional/test-cookies.js',
87-
'test/functional/test-experiments.js',
88120
],
89121
},
90122
'getCookie\\W': {
@@ -93,7 +125,6 @@ var forbiddenTerms = {
93125
'src/service/cid-impl.js',
94126
'src/cookies.js',
95127
'src/experiments.js',
96-
'test/functional/test-cookies.js',
97128
'tools/experiments/experiments.js',
98129
]
99130
},
@@ -102,19 +133,14 @@ var forbiddenTerms = {
102133
whitelist: [
103134
'src/cookies.js',
104135
'src/experiments.js',
105-
'test/functional/test-cookies.js',
106-
'test/functional/test-url-replacements.js',
107136
'tools/experiments/experiments.js',
108137
]
109138
},
110139
'eval\\(': '',
111140
'localStorage': {
112141
message: requiresReviewPrivacy,
113142
whitelist: [
114-
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
115-
'test/_init_tests.js',
116143
'src/service/cid-impl.js',
117-
'test/functional/test-cid.js',
118144
],
119145
},
120146
'sessionStorage': requiresReviewPrivacy,
@@ -227,6 +253,18 @@ var requiredTerms = {
227253
dedicatedCopyrightNoteSources,
228254
};
229255

256+
257+
/**
258+
* Check if root of path is test/ or file is in a folder named test.
259+
* @param {string} path
260+
* @return {boolean}
261+
*/
262+
function isInTestFolder(path) {
263+
var dirs = path.split('/');
264+
var folder = dirs[dirs.length - 2];
265+
return path.startsWith('test/') || folder == 'test';
266+
}
267+
230268
/**
231269
* Logs any issues found in the contents of file based on terms (regex
232270
* patterns), and provides any possible fix information for matched terms if
@@ -247,7 +285,8 @@ function matchTerms(file, terms) {
247285
var whitelist = terms[term].whitelist;
248286
// NOTE: we could do a glob test instead of exact check in the future
249287
// if needed but that might be too permissive.
250-
if (Array.isArray(whitelist) && whitelist.indexOf(relative) != -1) {
288+
if (Array.isArray(whitelist) && (whitelist.indexOf(relative) != -1 ||
289+
isInTestFolder(relative))) {
251290
return false;
252291
}
253292
// we can't optimize building the `RegExp` objects early unless we build

css/amp.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,12 @@ amp-analytics {
334334
overflow: hidden !important;
335335
visibility: hidden;
336336
}
337+
338+
339+
/**
340+
* Minimal AMP Access CSS. This part has to be here so that the correct UI
341+
* can be provided before AMP Access JS has been loaded.
342+
*/
343+
[amp-access][amp-access-off] {
344+
display: none;
345+
}

0 commit comments

Comments
 (0)