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

ConsentManagement: detect __cmp in window.top #2626

Merged
merged 4 commits into from
May 29, 2018
Merged
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: 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