From 8e884f8eee8eff209aab2996d552e13e47606106 Mon Sep 17 00:00:00 2001
From: lpw <812862340@qq.com>
Date: Sun, 28 Sep 2025 15:06:21 +0800
Subject: [PATCH] 提交版本 4.8.0
---
frameworks/Didomi.xcframework/ios-arm64_x86_64-simulator/Didomi.framework/web_sdk_utilities.js | 523 ++++++++++++++++++++++++++++++++-------------------------
1 files changed, 290 insertions(+), 233 deletions(-)
diff --git a/frameworks/Didomi.xcframework/ios-arm64_x86_64-simulator/Didomi.framework/web_sdk_utilities.js b/frameworks/Didomi.xcframework/ios-arm64_x86_64-simulator/Didomi.framework/web_sdk_utilities.js
index 014f7f1..b83c8ea 100644
--- a/frameworks/Didomi.xcframework/ios-arm64_x86_64-simulator/Didomi.framework/web_sdk_utilities.js
+++ b/frameworks/Didomi.xcframework/ios-arm64_x86_64-simulator/Didomi.framework/web_sdk_utilities.js
@@ -1,11 +1,22 @@
+/** Script allowing to use the Web SDK from a WebView */
+
+// Check if SDK is still initializing and should not display the notice yet
+var initializationInProgress = true;
+// Check if notice was initially displayed
+var noticeDisplayed = false;
+
/**
* Initialize the SDK with the specified configuration
*/
-function initSdk(config, gvl, sdkURL, languageCode) {
+function initSdk(config, gvl, sdkURL, languageCode, isUnderage) {
if (config) {
// Set the global window configuration to the config object
- window.didomiConfig = prepareConfigFromMobile(config, languageCode);
+ window.didomiConfig = prepareConfigFromMobile(config, languageCode, isUnderage);
+ // Set the location properties
+ window.didomiCountry = extractCountryFromMobileConfig(config);
+ window.didomiRegion = extractRegionFromMobileConfig(config);
+
// If app, vendors, and iab exist, set the vendorList property
if (
window.didomiConfig.app &&
@@ -57,253 +68,269 @@
/**
* Open the notice screen
*/
-function openNotice(options) {
+function openNotice(userStatus, options) {
+ var hasDeepLink = options != null && options.deepLinkView != null
+ if (!hasDeepLink) {
+ initializationInProgress = false
+ }
+ handleWebSDKEvents();
window.didomiOnReady = window.didomiOnReady || [];
window.didomiOnReady.push(function (Didomi) {
- if (options != null && options.deepLinkView != null) {
+ Didomi.setUserStatus(userStatus);
+ if (hasDeepLink) {
+ initializationInProgress = false;
Didomi.preferences.show(
options.deepLinkView == 0 ? "purposes" : "vendors"
);
} else {
Didomi.notice.show();
}
+ noticeDisplayed = true;
});
+}
- window.didomiEventListeners = window.didomiEventListeners || [];
- // TODO: Handle all iOS events
- window.didomiEventListeners.push(
- {
- event: 'api.error',
- listener: function ({ id, reason }) {
- if (window.webkit && window.webkit.messageHandlers) {
- window.webkit.messageHandlers.onError.postMessage(reason);
- } else {
- androidInterface.onError(id, reason);
- }
- }
- },
- {
- event: "consent.changed",
- listener: function (event) {
- // If the change is coming from the WebView we don't want to trigger the message back to the WebView.
- if (event.action == "webview") {
- return;
- }
-
- if (isIOS()) {
- window.webkit.messageHandlers.consentChanged.postMessage(Didomi.getUserStatus());
- } else {
- androidInterface.onConsentChanged(JSON.stringify(Didomi.getUserStatus()));
+/**
+ * Listen to SDK events
+ */
+function handleWebSDKEvents() {
+ window.didomiEventListeners = window.didomiEventListeners || [];
+ // TODO: Handle all iOS events
+ window.didomiEventListeners.push(
+ {
+ event: 'api.error',
+ listener: function ({ id, reason }) {
+ if (window.webkit && window.webkit.messageHandlers) {
+ window.webkit.messageHandlers.onError.postMessage(reason);
+ } else {
+ androidInterface.onError(id, reason);
+ }
}
},
- },
- {
- event: 'notice.clickagree',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.noticeClickAgree.postMessage("");
- } else {
- androidInterface.onNoticeClickAgree();
+ {
+ event: "consent.changed",
+ listener: function (event) {
+ // If the change is coming from the WebView we don't want to trigger the message back to the WebView.
+ if (event.action == "webview") {
+ return;
+ }
+
+ if (isIOS()) {
+ window.webkit.messageHandlers.consentChanged.postMessage(Didomi.getUserStatus());
+ } else {
+ androidInterface.onConsentChanged(JSON.stringify(Didomi.getUserStatus()));
+ }
+ },
+ },
+ {
+ event: 'notice.clickagree',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.noticeClickAgree.postMessage("");
+ } else {
+ androidInterface.onNoticeClickAgree();
+ }
}
- }
- },
- {
- event: 'notice.clickdisagree',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.noticeClickDisagree.postMessage("");
- } else {
- androidInterface.onNoticeClickDisagree();
+ },
+ {
+ event: 'notice.clickdisagree',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.noticeClickDisagree.postMessage("");
+ } else {
+ androidInterface.onNoticeClickDisagree();
+ }
}
- }
- },
- {
- event: 'notice.clickmoreinfo',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.noticeClickMoreInfo.postMessage("");
- } else {
- androidInterface.onNoticeClickMoreInfo();
+ },
+ {
+ event: 'notice.clickmoreinfo',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.noticeClickMoreInfo.postMessage("");
+ } else {
+ androidInterface.onNoticeClickMoreInfo();
+ }
}
- }
- },
- {
- event: 'notice.clickviewvendors',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.noticeClickViewVendors.postMessage("");
- } else {
- androidInterface.onNoticeClickViewVendors();
+ },
+ {
+ event: 'notice.clickviewvendors',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.noticeClickViewVendors.postMessage("");
+ } else {
+ androidInterface.onNoticeClickViewVendors();
+ }
}
- }
- },
- {
- event: 'notice.hidden',
- listener: function () {
- if (isIOS()) {
+ },
+ {
+ event: 'notice.hidden',
+ listener: function () {
+ if (noticeDisplayed && !Didomi.preferences.isVisible()) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.noticeHidden.postMessage("");
+ } else {
+ androidInterface.onNoticeHidden();
+ }
+ }
+ }
+ },
+ {
+ event: 'notice.shown',
+ listener: function () {
+ if (initializationInProgress) {
+ // Make sure the notice is not displayed if initialization is still in progress
+ Didomi.notice.hide();
+ } else if (isIOS()) {
+ window.webkit.messageHandlers.noticeShown.postMessage("");
+ } else {
+ androidInterface.onNoticeShown();
+ }
+ }
+ },
+ {
+ event: 'preferences.clickagreetoall',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickAgreeToAll.postMessage("");
+ } else {
+ androidInterface.onPreferencesClickAgreeToAll();
+ }
+ }
+ },
+ {
+ event: 'preferences.clickcategoryagree',
+ listener: function ({ categoryId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickCategoryAgree.postMessage(categoryId);
+ } else {
+ androidInterface.onPreferencesClickCategoryAgree(categoryId);
+ }
+ }
+ },
+ {
+ event: 'preferences.clickcategorydisagree',
+ listener: function ({ categoryId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickCategoryDisagree.postMessage(categoryId);
+ } else {
+ androidInterface.onPreferencesClickCategoryDisagree(categoryId);
+ }
+ }
+ },
+ {
+ event: "preferences.clickclose",
+ listener: function () {
+ // Not handled by mobile SDKs
+ },
+ },
+ {
+ event: 'preferences.clickdisagreetoall',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickDisagreeToAll.postMessage("");
+ } else {
+ androidInterface.onPreferencesClickDisagreeToAll();
+ }
+ }
+ },
+ {
+ event: 'preferences.clickpurposeagree',
+ listener: function ({ purposeId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickPurposeAgree.postMessage(purposeId);
+ } else {
+ androidInterface.onPreferencesClickPurposeAgree(purposeId);
+ }
+ }
+ },
+ {
+ event: 'preferences.clickpurposedisagree',
+ listener: function ({ purposeId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickPurposeDisagree.postMessage(purposeId);
+ } else {
+ androidInterface.onPreferencesClickPurposeDisagree(purposeId);
+ }
+ }
+ },
+ {
+ event: 'preferences.clicksavechoices',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickSaveChoices.postMessage("");
+ } else {
+ androidInterface.onPreferencesClickSaveChoices();
+ }
+ }
+ },
+ {
+ event: 'preferences.clickvendoragree',
+ listener: function ({ vendorId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickVendorAgree.postMessage(vendorId);
+ } else {
+ androidInterface.onPreferencesClickVendorAgree(vendorId);
+ }
+ }
+ },
+ {
+ event: 'preferences.clickvendordisagree',
+ listener: function ({ vendorId }) {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickVendorDisagree.postMessage(vendorId);
+ } else {
+ androidInterface.onPreferencesClickVendorDisagree(vendorId);
+ }
+ }
+ },
+ {
+ event: 'preferences.clickvendorsavechoices',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickVendorSaveChoices.postMessage("");
+ } else {
+ androidInterface.onPreferencesClickVendorSaveChoices();
+ }
+ }
+ },
+ {
+ event: 'preferences.clickviewvendors',
+ listener: function () {
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesClickViewVendors.postMessage("");
+ } else {
+ androidInterface.onPreferencesClickViewVendors();
+ }
+ }
+ },
+ {
+ event: "preferences.hidden",
+ listener: function () {
if (Didomi.notice.isVisible()) {
- window.webkit.messageHandlers.noticeHidden.postMessage();
+ if (isIOS()) {
+ window.webkit.messageHandlers.preferencesHidden.postMessage("");
+ } else {
+ androidInterface.onPreferencesHidden();
+ }
+ } else {
+ if (isIOS()) {
+ window.webkit.messageHandlers.dismissWebView.postMessage("");
+ } else {
+ androidInterface.onDismissPreferences();
+ }
}
- } else {
- androidInterface.onNoticeHidden();
}
- }
- },
- {
- event: 'notice.shown',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.noticeShown.postMessage("");
- } else {
- androidInterface.onNoticeShown();
- }
- }
- },
- {
- event: 'preferences.clickagreetoall',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickAgreeToAll.postMessage("");
- } else {
- androidInterface.onPreferencesClickAgreeToAll();
- }
- }
- },
- {
- event: 'preferences.clickcategoryagree',
- listener: function ({ categoryId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickCategoryAgree.postMessage(categoryId);
- } else {
- androidInterface.onPreferencesClickCategoryAgree(categoryId);
- }
- }
- },
- {
- event: 'preferences.clickcategorydisagree',
- listener: function ({ categoryId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickCategoryDisagree.postMessage(categoryId);
- } else {
- androidInterface.onPreferencesClickCategoryDisagree(categoryId);
- }
- }
- },
- {
- event: "preferences.clickclose",
- listener: function () {
- // Not handled by mobile SDKs
},
- },
- {
- event: 'preferences.clickdisagreetoall',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickDisagreeToAll.postMessage("");
- } else {
- androidInterface.onPreferencesClickDisagreeToAll();
- }
- }
- },
- {
- event: 'preferences.clickpurposeagree',
- listener: function ({ purposeId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickPurposeAgree.postMessage(purposeId);
- } else {
- androidInterface.onPreferencesClickPurposeAgree(purposeId);
- }
- }
- },
- {
- event: 'preferences.clickpurposedisagree',
- listener: function ({ purposeId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickPurposeDisagree.postMessage(purposeId);
- } else {
- androidInterface.onPreferencesClickPurposeDisagree(purposeId);
- }
- }
- },
- {
- event: 'preferences.clicksavechoices',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickSaveChoices.postMessage("");
- } else {
- androidInterface.onPreferencesClickSaveChoices();
- }
- }
- },
- {
- event: 'preferences.clickvendoragree',
- listener: function ({ vendorId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickVendorAgree.postMessage(vendorId);
- } else {
- androidInterface.onPreferencesClickVendorAgree(vendorId);
- }
- }
- },
- {
- event: 'preferences.clickvendordisagree',
- listener: function ({ vendorId }) {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickVendorDisagree.postMessage(vendorId);
- } else {
- androidInterface.onPreferencesClickVendorDisagree(vendorId);
- }
- }
- },
- {
- event: 'preferences.clickvendorsavechoices',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickVendorSaveChoices.postMessage("");
- } else {
- androidInterface.onPreferencesClickVendorSaveChoices();
- }
- }
- },
- {
- event: 'preferences.clickviewvendors',
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesClickViewVendors.postMessage("");
- } else {
- androidInterface.onPreferencesClickViewVendors();
- }
- }
- },
- {
- event: "preferences.hidden",
- listener: function () {
- if (Didomi.notice.isVisible()) {
+ {
+ event: "preferences.shown",
+ listener: function () {
if (isIOS()) {
- window.webkit.messageHandlers.preferencesHidden.postMessage("");
+ window.webkit.messageHandlers.preferencesShown.postMessage("");
} else {
- androidInterface.onPreferencesHidden();
- }
- } else {
- if (isIOS()) {
- window.webkit.messageHandlers.dismissWebView.postMessage("");
- } else {
- androidInterface.onDismissPreferences();
+ androidInterface.onPreferencesShown();
}
}
- }
- },
- {
- event: "preferences.shown",
- listener: function () {
- if (isIOS()) {
- window.webkit.messageHandlers.preferencesShown.postMessage("");
- } else {
- androidInterface.onPreferencesShown();
- }
- }
- },
- );
+ },
+ );
}
/**
@@ -385,7 +412,7 @@
/**
* Remove all accents and special characters from id field
- * @param {string} id
+ * @param {string} id
* @returns the sanitized id
*/
function sanitizeID(id) {
@@ -398,16 +425,13 @@
}
/**
- * Fix unescaped quotes and html tags.
+ * Fix unescaped quotes.
+ * Note: lookbehinds (`(?<=...)` or `(?<!...)`) are only supported from safari 17+
* @param {string} text
* @returns the sanitized text
*/
function sanitizeText(text) {
- return text
- // Escape unescaped quotes
- .replace(/(?<!\\)(['"])/g, '\$1')
- // Remove html tags
- .replace(/[<>]/g, '');
+ return text.replace(/(^|[^\\])(['"])/g, '$1\$2');
}
/**
@@ -480,12 +504,31 @@
}
/**
+ * Extract the country from the mobile config.
+ * @param {*} configFromMobile
+ * @returns the country or null if not defined.
+ */
+function extractCountryFromMobileConfig(configFromMobile) {
+ return configFromMobile.user ? configFromMobile.user.country : null;
+}
+
+/**
+ * Extract the region from the mobile config.
+ * @param {*} configFromMobile
+ * @returns the region or null if not defined.
+ */
+function extractRegionFromMobileConfig(configFromMobile) {
+ return configFromMobile.user ? configFromMobile.user.region : null;
+}
+
+/**
* Prepare config file to be consumed by the Web SDK, by disabling the features already handled by Mobile SDKs.
* @param {*} configFromMobile Config provided by mobile.
* @param {string} languageCode language code to be set in the Config.
+ * @param {boolean} isUnderage whether the notice should be underage or not.
* @returns Config with unneeded features disabled
*/
-function prepareConfigFromMobile(configFromMobile, languageCode) {
+function prepareConfigFromMobile(configFromMobile, languageCode, isUnderage) {
if (configFromMobile == null) {
return null;
}
@@ -504,10 +547,24 @@
configFromMobile.app.consentString.signatureEnabled = false;
}
+ // Ignore daysBeforeShowingAgain as this is already handled by the mobile SDKs.
+ if (configFromMobile.notice) {
+ delete configFromMobile.notice.daysBeforeShowingAgain;
+ }
+
if (languageCode) {
+ if (languageCode == "pt-PT") {
+ // Temporary workaround for https://didomi.atlassian.net/browse/CMP-5552
+ languageCode = "pt";
+ }
configFromMobile.languages = { enabled: [languageCode], default: languageCode };
}
+ if (isUnderage) {
+ configFromMobile.user = configFromMobile.user || {};
+ configFromMobile.user.isUnderage = isUnderage;
+ }
+
return configFromMobile;
}
--
Gitblit v1.8.0