Skip to content

Commit 91ca3f4

Browse files
committed
Change ads embed mechanism to be more generic for all 3p content.
1 parent 175d19a commit 91ca3f4

File tree

9 files changed

+40
-44
lines changed

9 files changed

+40
-44
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
build
44
dist
55
dist.ads
6+
dist.3p
67
examples.build
78
examples.min
89
node_modules

ads/frame.max.html 3p/frame.max.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<head>
33
<meta charset="utf-8">
44
<meta name="robots" content="noindex">
5-
<script src="./ads.js"></script>
5+
<script src="./integration.js"></script>
66
</head>
77
<body style="margin:0">
88
<div id="c" style="position:absolute;top:0;left:0;bottom:0;right:0;">
9-
<script>drawAd()</script>
9+
<script>draw3p()</script>
1010
</div>
1111
<script>if (window.docEndCallback) window.docEndCallback()</script>
1212
</body>

ads/ads.js 3p/integration.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,31 @@
2020
*/
2121

2222
import '../src/polyfills';
23-
import {a9} from './a9';
24-
import {adreactor} from './adreactor';
25-
import {adsense} from './adsense';
26-
import {adtech} from './adtech';
27-
import {doubleclick} from './doubleclick';
23+
import {a9} from '../ads/a9';
24+
import {adreactor} from '../ads/adreactor';
25+
import {adsense} from '../ads/adsense';
26+
import {adtech} from '../ads/adtech';
27+
import {doubleclick} from '../ads/doubleclick';
2828
import {twitter} from './twitter';
2929
import {register, run} from '../src/3p';
3030

31-
register('ad', 'a9', a9);
32-
register('ad', 'adreactor', adreactor);
33-
register('ad', 'adsense', adsense);
34-
register('ad', 'adtech', adtech);
35-
register('ad', 'doubleclick', doubleclick);
36-
37-
// TODO(malteubl) Move somewhere else since this is not an ad.
38-
register('ad', 'twitter', twitter);
31+
register('a9', a9);
32+
register('adreactor', adreactor);
33+
register('adsense', adsense);
34+
register('adtech', adtech);
35+
register('doubleclick', doubleclick);
36+
register('twitter', twitter);
3937

4038
/**
4139
* Visible for testing.
4240
* Draws an ad to the window. Expects the data to include the ad type.
4341
* @param {!Window} win
4442
* @param {!Object} data
4543
*/
46-
export function drawAd(win, data) {
44+
export function draw3p(win, data) {
4745
var type = data.type;
48-
run('ad', type, win, data);
49-
}
46+
run(type, win, data);
47+
};
5048

5149
/**
5250
* Returns the "master frame" for all widgets of a given type.
@@ -78,12 +76,12 @@ function masterSelection(type) {
7876
/**
7977
* Draws an optionally synchronously to the DOM.
8078
*/
81-
window.drawAd = function() {
79+
window.draw3p = function() {
8280
var fragment = location.hash;
8381
var data = fragment ? JSON.parse(fragment.substr(1)) : {};
8482
window.context = data._context;
8583
window.context.master = masterSelection(data.type);
8684
window.context.isMaster = window.context.master == window;
8785
delete data._context;
88-
drawAd(window, data);
86+
draw3p(window, data);
8987
};

ads/twitter.js 3p/twitter.js

File renamed without changes.

build-system/tasks/presubmit-checks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var util = require('gulp-util');
2020
// Directories to check for presubmit checks.
2121
var srcGlobs = [
2222
'**/*.{css,js,html,md}',
23-
'!{node_modules,dist,dist.ads}/**/*.*',
23+
'!{node_modules,dist,dist.3p}/**/*.*',
2424
'!build-system/tasks/presubmit-checks.js',
2525
'!build/polyfills.js',
2626
'!gulpfile.js'

gulpfile.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function buildExtensions(options) {
7272
}
7373

7474
function clean(done) {
75-
del(['dist', 'dist.ads', 'build', 'examples.build'], done);
75+
del(['dist', 'dist.3p', 'build', 'examples.build'], done);
7676
}
7777

7878
function polyfillsForTests() {
@@ -86,12 +86,12 @@ function compile(watch, shouldMinify) {
8686
watch: watch,
8787
minify: shouldMinify
8888
});
89-
compileJs('./ads/', 'ads.js', './dist.ads/' + internalRuntimeVersion, {
89+
compileJs('./3p/', 'integration.js', './dist.3p/' + internalRuntimeVersion, {
9090
minifiedName: 'f.js',
9191
watch: watch,
9292
minify: shouldMinify
9393
});
94-
adsBootstrap(watch);
94+
thirdPartyBootstrap(watch);
9595
}
9696

9797

@@ -240,8 +240,8 @@ function examplesWithMinifiedJs(name) {
240240
.pipe(gulp.dest('examples.build/'));
241241
}
242242

243-
function adsBootstrap(watch) {
244-
var input = 'ads/frame.max.html';
243+
function thirdPartyBootstrap(watch) {
244+
var input = '3p/frame.max.html';
245245
if (watch) {
246246
gulpWatch(input, function() {
247247
adsBootstrap(false);
@@ -250,10 +250,10 @@ function adsBootstrap(watch) {
250250
console.log('Processing ' + input);
251251
var html = fs.readFileSync(input, 'utf8');
252252
var min = html;
253-
min = min.replace(/\.\/ads\.js/g, './f.js');
253+
min = min.replace(/\.\/integration\.js/g, './f.js');
254254
gulp.src(input)
255255
.pipe(file('frame.html', min))
256-
.pipe(gulp.dest('dist.ads/' + internalRuntimeVersion));
256+
.pipe(gulp.dest('dist.3p/' + internalRuntimeVersion));
257257
}
258258

259259

src/3p-frame.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ export function addDataAndJsonAttributes_(element, attributes) {
132132
function getBootstrapBaseUrl(parentWindow) {
133133
// TODO(malteubl): Change to final URL.
134134
var url =
135-
'https://ads.ampproject.net/$internalRuntimeVersion$/frame.html';
135+
'https://3p.ampproject.net/$internalRuntimeVersion$/frame.html';
136136
if (getMode().localDev) {
137137

138138
url = 'http://ads.localhost:' + parentWindow.location.port +
139-
'/dist.ads/$internalRuntimeVersion$/frame' +
139+
'/dist.3p/$internalRuntimeVersion$/frame' +
140140
(getMode().minified ? '' : '.max') +
141141
'.html';
142142
}

src/3p.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,29 @@ import {assert} from './asserts';
2727
var ThirdPartyFunction;
2828

2929

30-
/** @const {!Object<!Object<ThirdPartyFunction>>} */
31-
var registrations = {
32-
ad: {}
33-
};
30+
/** @const {!Object<ThirdPartyFunction>} */
31+
var registrations = {};
3432

3533
var syncScriptLoads = 0;
3634

3735
/**
38-
* @param {string} type The type of 3p integration. See keys in the
39-
* registrations objects.
4036
* @param {string} id The specific 3p integration.
4137
* @param {ThirdPartyFunction} draw Function that draws the 3p integration.
4238
*/
43-
export function register(type, id, draw) {
44-
var ofType = assert(registrations[type], 'Unknown type ' + type);
45-
ofType[id] = draw;
39+
export function register(id, draw) {
40+
assert(!registrations[id], 'Double registration %s', id);
41+
registrations[id] = draw;
4642
}
4743

4844
/**
49-
* Execute the 3p integration with the given type and id.
50-
* @param {string} type
45+
* Execute the 3p integration with the given id.
5146
* @param {id} id
5247
* @param {!Window} win
5348
* @param {!Object} data
5449
*/
55-
export function run(type, id, win, data) {
56-
var fn = assert(registrations[type], 'Unknown type ' + type)[id];
57-
assert(fn, 'Unknown ' + type + ': ' + id);
50+
export function run(id, win, data) {
51+
var fn = registrations[id];
52+
assert(fn, 'Unknown 3p: ' + id);
5853
fn(win, data);
5954
}
6055

test/functional/test-error.js

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('reportErrorToServer', () => {
6767
expect(query.m).to.equal('XYZ');
6868
expect(query.el).to.equal('FOO-BAR');
6969
expect(query.a).to.equal('0');
70+
expect(query.v).to.equal('$internalRuntimeVersion$');
7071
});
7172

7273
it('reportError mark asserts', () => {
@@ -78,6 +79,7 @@ describe('reportErrorToServer', () => {
7879

7980
expect(query.m).to.equal('XYZ');
8081
expect(query.a).to.equal('1');
82+
expect(query.v).to.equal('$internalRuntimeVersion$');
8183
});
8284

8385
it('reportError without error object', () => {

0 commit comments

Comments
 (0)