Skip to content

Commit

Permalink
[WebKit] Add methods removed by Apple. (#13133)
Browse files Browse the repository at this point in the history
Apple removed methods without deprecating and did not add them back
after a rdar was reported. We can implement those methofs using the new
ones.
  • Loading branch information
mandel-macaque authored Oct 27, 2021
1 parent f1d20dc commit 40db84a
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 16 deletions.
128 changes: 128 additions & 0 deletions src/WKWebKit/WKCompat.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Threading.Tasks;
using System.Runtime.Versioning;

using Foundation;
using ObjCRuntime;

#nullable enable

Expand All @@ -14,5 +17,130 @@ public WKWebsiteDataStore ()
{
}
}

public partial class WKWebView {

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
[Obsolete ("Use 'CloseAllMediaPresentations (Action completionHandler)' instead.")]
public virtual void CloseAllMediaPresentations () {
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
CloseAllMediaPresentationsAsync ().Wait();
else
_OldCloseAllMediaPresentations ();
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
public virtual void PauseAllMediaPlayback (Action? completionHandler)
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
_NewPauseAllMediaPlayback (completionHandler);
else
_OldPauseAllMediaPlayback (completionHandler);
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
public virtual Task PauseAllMediaPlaybackAsync ()
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return _NewPauseAllMediaPlaybackAsync ();
else
return _OldPauseAllMediaPlaybackAsync ();
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
[Obsolete ("Use 'SetAllMediaPlaybackSuspended' instead.")]
public virtual void SuspendAllMediaPlayback (Action? completionHandler)
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
SetAllMediaPlaybackSuspended (true, completionHandler);
else
_OldSuspendAllMediaPlayback (completionHandler);
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
public virtual Task SuspendAllMediaPlaybackAsync ()
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return SetAllMediaPlaybackSuspendedAsync (true);
else
return _OldSuspendAllMediaPlaybackAsync ();
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
[Obsolete ("Use 'SetAllMediaPlaybackSuspended' instead.")]
public virtual void ResumeAllMediaPlayback (Action? completionHandler)
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
SetAllMediaPlaybackSuspended (false, completionHandler);
else
_OldResumeAllMediaPlayback (completionHandler);
}

#if !NET
[Mac (11,3), iOS (14,5), MacCatalyst (14,5)]
#else
[SupportedOSPlatform ("ios14.5"), SupportedOSPlatform ("macos11.3"), SupportedOSPlatform ("maccatalyst14.5")]
#endif
public virtual Task ResumeAllMediaPlaybackAsync ()
{
#if IOS || __MACCATALYST__
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return SetAllMediaPlaybackSuspendedAsync (false);
else
return _OldResumeAllMediaPlaybackAsync ();
}

}
#endif
}
40 changes: 28 additions & 12 deletions src/wkwebkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,33 +897,49 @@ interface WKWebView
NSPrintOperation GetPrintOperation (NSPrintInfo printInfo);

// Apple renamed those API since Xcode 12.5

// [Mac (11,3)][iOS (14,5)]
// [MacCatalyst (14,5)]
// [Export ("closeAllMediaPresentations")]
// void CloseAllMediaPresentations ();
[Internal]
[Mac (11,3)][iOS (14,5)]
[MacCatalyst (14,5)]
[Export ("closeAllMediaPresentations")]
void _OldCloseAllMediaPresentations ();

[Async]
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoTV]
[Export ("closeAllMediaPresentationsWithCompletionHandler:")]
void CloseAllMediaPresentations ([NullAllowed] Action completionHandler);

[Internal]
[Mac (11,3)][iOS (14,5)]
[MacCatalyst (14,5)]
[Async]
[Export ("pauseAllMediaPlayback:")]
void _OldPauseAllMediaPlayback ([NullAllowed] Action completionHandler);

[Internal]
[Async]
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoTV]
[Export ("pauseAllMediaPlaybackWithCompletionHandler:")]
void PauseAllMediaPlayback ([NullAllowed] Action completionHandler);
void _NewPauseAllMediaPlayback ([NullAllowed] Action completionHandler);

[Internal]
[Mac (11,3)][iOS (14,5)]
[MacCatalyst (14,5)]
[Async]
[Export ("suspendAllMediaPlayback:")]
void _OldSuspendAllMediaPlayback ([NullAllowed] Action completionHandler);

[Internal]
[Mac (11,3)][iOS (14,5)]
[MacCatalyst (14,5)]
[Async]
[Export ("resumeAllMediaPlayback:")]
void _OldResumeAllMediaPlayback ([NullAllowed] Action completionHandler);

[Async]
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoTV]
[Export ("setAllMediaPlaybackSuspended:completionHandler:")]
void SetAllMediaPlaybackSuspended (bool suspended, [NullAllowed] Action completionHandler);

// [Mac (11,3)][iOS (14,5)]
// [MacCatalyst (14,5)]
// [Async]
// [Export ("resumeAllMediaPlayback:")]
// void ResumeAllMediaPlayback ([NullAllowed] Action completionHandler);

[Async]
[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoTV]
[Export ("requestMediaPlaybackStateWithCompletionHandler:")]
Expand Down
4 changes: 0 additions & 4 deletions tests/xtro-sharpie/common-WebKit.ignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# added and removed in the same version.
!missing-selector! WKWebView::closeAllMediaPresentations not bound
!missing-selector! WKWebView::loadSimulatedRequest:withResponse:responseData: not bound
!missing-selector! WKWebView::loadSimulatedRequest:withResponseHTMLString: not bound
!missing-selector! WKWebView::pauseAllMediaPlayback: not bound
!missing-selector! WKWebView::requestMediaPlaybackState: not bound
!missing-selector! WKWebView::resumeAllMediaPlayback: not bound
!missing-selector! WKWebView::suspendAllMediaPlayback: not bound

6 comments on commit 40db84a

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Packages generated

View packages

Test results

1 tests failed, 217 tests passed.

Failed tests

  • DotNet tests: Failed (Execution failed with exit code 1)

Pipeline on Agent XAMBOT-1038.BigSur'
[WebKit] Add methods removed by Apple. (#13133)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS 🔥

Not enough free space in the host.

Pipeline on Agent
[WebKit] Add methods removed by Apple. (#13133)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[WebKit] Add methods removed by Apple. (#13133)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[WebKit] Add methods removed by Apple. (#13133)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tests passed on macOS M1 - Mac Big Sur (11.5) ✅

Tests passed

All tests on macOS X M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
[WebKit] Add methods removed by Apple. (#13133)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Mojave (10.14) ❌

Tests failed on Mac Mojave (10.14).

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
[WebKit] Add methods removed by Apple. (#13133)

Please sign in to comment.