Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render outstream safeframe #3159

Merged
merged 3 commits into from
Oct 9, 2018
Merged
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
18 changes: 18 additions & 0 deletions src/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,21 @@ Renderer.prototype.process = function() {
}
}
};

/**
* Checks whether creative rendering should be done by Renderer or not.
* @param {Object} renderer Renderer object installed by adapter
* @returns {Boolean}
*/
export function isRendererRequired(renderer) {
return !!(renderer && renderer.url);
}

/**
* Render the bid returned by the adapter
* @param {Object} renderer Renderer object installed by adapter
* @param {Object} bid Bid response
*/
export function executeRenderer(renderer, bid) {
renderer.render(bid);
}
5 changes: 3 additions & 2 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createHook } from 'src/hook';
import { sessionLoader } from 'src/debugging';
import includes from 'core-js/library/fn/array/includes';
import { adunitCounter } from './adUnits';
import { isRendererRequired, executeRenderer } from './Renderer';

const $$PREBID_GLOBAL$$ = getGlobal();
const CONSTANTS = require('./constants.json');
Expand Down Expand Up @@ -248,8 +249,8 @@ $$PREBID_GLOBAL$$.renderAd = function (doc, id) {
const creativeComment = document.createComment(`Creative ${bid.creativeId} served by ${bid.bidder} Prebid.js Header Bidding`);
utils.insertElement(creativeComment, doc, 'body');

if (renderer && renderer.url) {
renderer.render(bid);
if (isRendererRequired(renderer)) {
executeRenderer(renderer, bid);
} else if ((doc === document && !utils.inIframe()) || mediaType === 'video') {
const message = `Error trying to write ad. Ad render call ad id ${id} was prevented from writing to the main document.`;
emitAdRenderFail(PREVENT_WRITING_ON_MAIN_DOCUMENT, message, bid);
Expand Down
9 changes: 6 additions & 3 deletions src/secureCreatives.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EVENTS } from './constants';
import { isSlotMatchingAdUnitCode } from './utils';
import { auctionManager } from './auctionManager';
import find from 'core-js/library/fn/array/find';
import { isRendererRequired, executeRenderer } from './Renderer';

const BID_WON = EVENTS.BID_WON;

Expand Down Expand Up @@ -53,9 +54,11 @@ function receiveMessage(ev) {
}

function sendAdToCreative(adObject, remoteDomain, source) {
const { adId, ad, adUrl, width, height } = adObject;

if (adId) {
const { adId, ad, adUrl, width, height, renderer } = adObject;
// rendering for outstream safeframe
if (isRendererRequired(renderer)) {
executeRenderer(renderer, adObject);
} else if (adId) {
resizeRemoteCreative(adObject);
source.postMessage(JSON.stringify({
message: 'Prebid Response',
Expand Down