You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2020/02/27 06:08:46 UTC

[cordova-ios] branch master updated: breaking: remove MediaPlaybackRequiresUserAction and update MediaTypesRequiringUserActionForPlayback to proper variable types (#797)

This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new d9a9d01  breaking: remove MediaPlaybackRequiresUserAction and update MediaTypesRequiringUserActionForPlayback to proper variable types (#797)
d9a9d01 is described below

commit d9a9d0104cb6c473a4aaa0662239c9700a03efcb
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Thu Feb 27 15:08:39 2020 +0900

    breaking: remove MediaPlaybackRequiresUserAction and update MediaTypesRequiringUserActionForPlayback to proper variable types (#797)
    
    * fix (MediaTypesRequiringUserActionForPlayback): pass valid media type
    * breaking (MediaPlaybackRequiresUserAction): delete
    * As the new preference key always exists in "defaults.xml", the old preference key would never be used.
    * Updated deprecation warning logic to include "has been" deprecated since it was completely removed. Most cases the warning would be removed as well but the previous releases never properly warn the user. Warning will remain for next major only as a migration step for users.
---
 .../Plugins/CDVWebViewEngine/CDVWebViewEngine.m    | 22 +++++++++++----
 bin/templates/scripts/cordova/defaults.xml         |  2 +-
 bin/templates/scripts/cordova/lib/prepare.js       | 33 +++++++++++++++++-----
 tests/CordovaLibTests/CDVWebViewEngineTest.m       |  4 +--
 4 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
index 3a9ff06..4b0543f 100644
--- a/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
+++ b/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewEngine.m
@@ -75,13 +75,23 @@
 
     configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO];
 
-    // Check for usage of the older preference key, alert, and use.
-    BOOL mediaTypesRequiringUserActionForPlayback = [settings cordovaBoolSettingForKey:@"MediaTypesRequiringUserActionForPlayback" defaultValue:YES];
-    NSString *mediaPlaybackRequiresUserActionKey = [settings cordovaSettingForKey:@"MediaPlaybackRequiresUserAction"];
-    if(mediaPlaybackRequiresUserActionKey != nil) {
-        mediaTypesRequiringUserActionForPlayback = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES];
+    // Set the media types that are required for user action for playback
+    WKAudiovisualMediaTypes mediaType = WKAudiovisualMediaTypeAll; // default
+
+    // targetMediaType will always exist, either from user's "config.xml" or default ("defaults.xml").
+    id targetMediaType = [settings cordovaSettingForKey:@"MediaTypesRequiringUserActionForPlayback"];
+    if ([targetMediaType isEqualToString:@"none"]) {
+        mediaType = WKAudiovisualMediaTypeNone;
+    } else if ([targetMediaType isEqualToString:@"audio"]) {
+        mediaType = WKAudiovisualMediaTypeAudio;
+    } else if ([targetMediaType isEqualToString:@"video"]) {
+        mediaType = WKAudiovisualMediaTypeVideo;
+    } else if ([targetMediaType isEqualToString:@"all"]) {
+        mediaType = WKAudiovisualMediaTypeAll;
+    } else {
+        NSLog(@"Invalid \"MediaTypesRequiringUserActionForPlayback\" was detected. Fallback to default value of \"all\" types.");
     }
-    configuration.mediaTypesRequiringUserActionForPlayback = mediaTypesRequiringUserActionForPlayback;
+    configuration.mediaTypesRequiringUserActionForPlayback = mediaType;
 
     configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
 
diff --git a/bin/templates/scripts/cordova/defaults.xml b/bin/templates/scripts/cordova/defaults.xml
index b7edc26..f6eac29 100644
--- a/bin/templates/scripts/cordova/defaults.xml
+++ b/bin/templates/scripts/cordova/defaults.xml
@@ -27,7 +27,7 @@
     <preference name="DisallowOverscroll" value="false" />
     <preference name="EnableViewportScale" value="false" />
     <preference name="KeyboardDisplayRequiresUserAction" value="true" />
-    <preference name="MediaTypesRequiringUserActionForPlayback" value="false" />
+    <preference name="MediaTypesRequiringUserActionForPlayback" value="none" />
     <preference name="SuppressesIncrementalRendering" value="false" />
     <preference name="SuppressesLongPressGesture" value="false" />
     <preference name="Suppresses3DTouchGesture" value="false" />
diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js
index 333726f..9d6bf59 100644
--- a/bin/templates/scripts/cordova/lib/prepare.js
+++ b/bin/templates/scripts/cordova/lib/prepare.js
@@ -522,21 +522,40 @@ function updateFileResources (cordovaProject, locations) {
 
 function alertDeprecatedPreference (configParser) {
     const deprecatedToNewPreferences = {
-        MediaPlaybackRequiresUserAction: 'MediaTypesRequiringUserActionForPlayback',
-        MediaPlaybackAllowsAirPlay: 'AllowsAirPlayForMediaPlayback'
+        MediaPlaybackRequiresUserAction: {
+            newPreference: 'MediaTypesRequiringUserActionForPlayback',
+            isDeprecated: true
+        },
+        MediaPlaybackAllowsAirPlay: {
+            newPreference: 'AllowsAirPlayForMediaPlayback',
+            isDeprecated: false
+        }
     };
 
     Object.keys(deprecatedToNewPreferences).forEach(oldKey => {
         if (configParser.getPreference(oldKey)) {
-            const log = [`The preference name "${oldKey}" is being deprecated.`];
-
-            if (deprecatedToNewPreferences[oldKey]) {
-                log.push(`It is recommended to update this preference with "${deprecatedToNewPreferences[oldKey]}."`);
+            const isDeprecated = deprecatedToNewPreferences[oldKey].isDeprecated;
+            const verb = isDeprecated ? 'has been' : 'is being';
+            const newPreferenceKey = deprecatedToNewPreferences[oldKey].newPreference;
+
+            // Create the Log Message
+            const log = [`The preference name "${oldKey}" ${verb} deprecated.`];
+            if (newPreferenceKey) {
+                log.push(`It is recommended to replace this preference with "${newPreferenceKey}."`);
             } else {
                 log.push(`There is no replacement for this preference.`);
             }
 
-            log.push(`Please note that this preference will be removed in the near future.`);
+            /**
+             * If the preference has been deprecated, the usage of the old preference is no longer used.
+             * Therefore, the following line is not appended. It is added only if the old preference is still used.
+             * We are only keeping the top lines for deprecated items only for an additional major release when
+             * the pre-warning was not provided in a past major release due to a necessary quick deprecation.
+             * Typically caused by implementation nature or third-party requirement changes.
+             */
+            if (!isDeprecated) {
+                log.push(`Please note that this preference will be removed in the near future.`);
+            }
 
             events.emit('warn', log.join(' '));
         }
diff --git a/tests/CordovaLibTests/CDVWebViewEngineTest.m b/tests/CordovaLibTests/CDVWebViewEngineTest.m
index ebe6435..7c9eb82 100644
--- a/tests/CordovaLibTests/CDVWebViewEngineTest.m
+++ b/tests/CordovaLibTests/CDVWebViewEngineTest.m
@@ -90,7 +90,7 @@
     NSDictionary* preferences = @{
                                [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
                                [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
-                               [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
+                               [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
                                [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
                                [@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
                                [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
@@ -133,7 +133,7 @@
     NSDictionary* settings = @{
                                   [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
                                   [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
-                                  [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
+                                  [@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
                                   [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
                                   [@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
                                   [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org