Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 3p/3p.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@ export function validateSrcContains(string, src) {
* @param {function(*)} cb Callback function that is called when the work is
* done. The first argument is the result.
*/
export function computeInMasterFrame(global, taskId, work, cb) {
const {master} = global.context;
let tasks = master.__ampMasterTasks;
export function computeInPrimaryFrame(global, taskId, work, cb) {
const {primary} = global.context;
let tasks = primary.__ampPrimaryTasks;
if (!tasks) {
tasks = master.__ampMasterTasks = {};
tasks = primary.__ampPrimaryTasks = {};
}
let cbs = tasks[taskId];
if (!tasks[taskId]) {
cbs = tasks[taskId] = [];
}
cbs.push(cb);
if (!global.context.isMaster) {
return; // Only do work in master.
if (!global.context.isPrimary) {
return; // Only do work in primary.
}
work((result) => {
for (let i = 0; i < cbs.length; i++) {
Expand Down
46 changes: 23 additions & 23 deletions 3p/ampcontext-integration.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {dev, user, userAssert} from '#utils/log';

import {computeInMasterFrame} from './3p';
import {computeInPrimaryFrame} from './3p';
import {AbstractAmpContext} from './ampcontext';

/**
* Returns the "master frame" for all widgets of a given type.
* Returns the "primary frame" for all widgets of a given type.
* This frame should be used to e.g. fetch scripts that can
* be reused across frames.
* once experiment is removed.
* @param {!Window} win
* @param {string} type
* @return {!Window}
*/
export function masterSelection(win, type) {
export function primarySelection(win, type) {
type = type.toLowerCase();
// The master has a special name.
const masterName = 'frame_' + type + '_master';
let master;
// The primary has a special name.
const primaryName = 'frame_' + type + '_primary';
let primary;
try {
// Try to get the master from the parent. If it does not
// Try to get the primary from the parent. If it does not
// exist yet we get a security exception that we catch
// and ignore.
master = win.parent.frames[masterName];
primary = win.parent.frames[primaryName];
} catch (expected) {
/* ignore */
}
if (!master) {
// No master yet, rename ourselves to be master. Yaihh.
win.name = masterName;
master = win;
if (!primary) {
// No primary yet, rename ourselves to be primary. Yaihh.
win.name = primaryName;
primary = win;
}
return master;
return primary;
}

export class IntegrationAmpContext extends AbstractAmpContext {
Expand Down Expand Up @@ -58,23 +58,23 @@ export class IntegrationAmpContext extends AbstractAmpContext {
}

/** @return {!Window} */
get master() {
return this.master_();
get primary() {
return this.primary_();
}

/** @return {!Window} */
master_() {
return masterSelection(this.win_, dev().assertString(this.embedType_));
primary_() {
return primarySelection(this.win_, dev().assertString(this.embedType_));
}

/** @return {boolean} */
get isMaster() {
return this.isMaster_();
get isPrimary() {
return this.isPrimary_();
}

/** @return {boolean} */
isMaster_() {
return this.master == this.win_;
isPrimary_() {
return this.primary == this.win_;
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ export class IntegrationAmpContext extends AbstractAmpContext {
* @param {function(*)} cb Callback function that is called when the work is
* done. The first argument is the result.
*/
computeInMasterFrame(global, taskId, work, cb) {
computeInMasterFrame(global, taskId, work, cb);
computeInPrimaryFrame(global, taskId, work, cb) {
computeInPrimaryFrame(global, taskId, work, cb);
}
}