Skip to content

Commit

Permalink
ConsentManagement: detect __cmp in window.top (#2626)
Browse files Browse the repository at this point in the history
* ConsentManagement: detect __cmp in window.top

* Lighter modification

Credits to @YOzaz

* typo

* fixed spaces
  • Loading branch information
benjaminclot authored and jsnellbaker committed May 29, 2018
1 parent d881ecd commit b199353
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
}
}
}

let callbackHandler = handleCmpResponseCallbacks();
let cmpCallbacks = {};
let cmpFunction;

// to collect the consent information from the user, we perform two calls to the CMP in parallel:
// first to collect the user's consent choices represented in an encoded string (via getConsentData)
Expand All @@ -66,9 +68,13 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) {
// check to see if prebid is in a safeframe (with CMP support)
// else assume prebid may be inside an iframe and use the IAB CMP locator code to see if CMP's located in a higher parent window. this works in cross domain iframes
// if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow
if (utils.isFn(window.__cmp)) {
window.__cmp('getConsentData', null, callbackHandler.consentDataCallback);
window.__cmp('getVendorConsents', null, callbackHandler.vendorConsentsCallback);
try {
cmpFunction = window.__cmp || utils.getWindowTop().__cmp;
} catch (e) {}

if (utils.isFn(cmpFunction)) {
cmpFunction('getConsentData', null, callbackHandler.consentDataCallback);
cmpFunction('getVendorConsents', null, callbackHandler.vendorConsentsCallback);
} else if (inASafeFrame() && typeof window.$sf.ext.cmp === 'function') {
callCmpWhileInSafeFrame('getConsentData', callbackHandler.consentDataCallback);
callCmpWhileInSafeFrame('getVendorConsents', callbackHandler.vendorConsentsCallback);
Expand Down

0 comments on commit b199353

Please sign in to comment.