The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
Prime Video on Amazon, Amazon Music, six more services, and a Safari's Engine switch per site
Victor9e687884d1f3
diff --git a/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift b/Packages/CraCore/Sources/CraCore/ProtectedMedia.swiftindex ef187a2..dcac9f4 100644--- a/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift+++ b/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift@@ -29,7 +29,8 @@ public enum PageEngine: String, Equatable, Sendable {/// cookies. Cra's own navigations (the URL bar) pick the engine again.public struct ProtectedMediaSites: Equatable, Sendable {/// The web players of services that need Verified Media Path in Chromium on a Mac and play- /// in Safari. A host matches itself and its subdomains. Players only, not whole domains:+ /// in Safari. A host matches itself and its subdomains; "host/path" also needs the address's+ /// path to start with that path (Prime Video on Amazon). Players only, not whole domains:/// other sites send their "Sign in with Spotify/Tidal/Deezer" through accounts.spotify.com,/// login.tidal.com and connect.deezer.com, and those must finish in the engine they started in.public static let defaultHosts: [String] = [@@ -51,7 +52,20 @@ public struct ProtectedMediaSites: Equatable, Sendable {"crunchyroll.com","hotstar.com", "jiohotstar.com","v.qq.com",- ]+ // Seen refusing non-VMP Chromium ("Verified Media Path" errors for Joyn and Rakuten TV,+ // Nov 2024), and Sky's and Peacock's platforms, which fail as Peacock does (5 Nov 2026).+ "joyn.de", "joyn.at", "joyn.ch",+ "rakuten.tv",+ "skyshowtime.com", "nowtv.com", "wowtv.de", "showmax.com",+ // Prime Video where Amazon itself serves it (the US, and Amazon's stores that keep it under+ // /gp/video); the rest of Amazon (shopping, Login with Amazon) stays in Chromium.+ ] + amazonStores.map { "\($0)/gp/video" } + [+ // Amazon Music needs production VMP in Chromium (Parachord's tests, castlabs EVS, Nov 2026).+ ] + amazonStores.map { "music.\($0)" }++ /// Amazon's storefronts with Prime Video and Amazon Music.+ static let amazonStores = ["amazon.com", "amazon.co.uk", "amazon.de", "amazon.fr", "amazon.it", "amazon.es", "amazon.ca",+ "amazon.co.jp", "amazon.com.au", "amazon.in", "amazon.com.mx", "amazon.com.br"]/// What Cra calls each service when it tells the user why a page is WebKit's (the toast,/// the Site Control Center, the extension buttons' tooltips).@@ -61,11 +75,13 @@ public struct ProtectedMediaSites: Equatable, Sendable {"paramountplus.com": "Paramount+", "peacocktv.com": "Peacock", "tv.apple.com": "Apple TV","music.apple.com": "Apple Music", "listen.tidal.com": "Tidal", "www.deezer.com": "Deezer","crunchyroll.com": "Crunchyroll", "hotstar.com": "Hotstar", "jiohotstar.com": "JioHotstar", "v.qq.com": "Tencent Video",- ]+ "joyn.de": "Joyn", "joyn.at": "Joyn", "joyn.ch": "Joyn", "rakuten.tv": "Rakuten TV", "skyshowtime.com": "SkyShowtime",+ "nowtv.com": "NOW", "wowtv.de": "WOW", "showmax.com": "Showmax",+ ].merging(amazonStores.flatMap { [("\($0)/gp/video", "Prime Video"), ("music.\($0)", "Amazon Music")] }) { a, _ in a }/// Off: every page is Chromium's, as before.public var isEnabled: Bool- /// Lower-cased hosts without a leading dot.+ /// Lower-cased hosts without a leading dot, some with a path ("amazon.com/gp/video").public private(set) var hosts: [String]/// `extraHosts` add to the list (tests, a user's own entries); `removedHosts` take sites@@ -83,10 +99,46 @@ public struct ProtectedMediaSites: Equatable, Sendable {listedHost(for: url) == nil ? .chromium : .webKit}- /// The listed host `url` falls under, or nil (also while off).+ /// The listed entry `url` falls under, or nil (also while off).public func listedHost(for url: String) -> String? {guard isEnabled, let host = Self.webHost(of: url) else { return nil }- return hosts.first { host == $0 || host.hasSuffix("." + $0) }+ let path = URLComponents(string: url.trimmingCharacters(in: .whitespaces))?.path.lowercased() ?? ""+ return hosts.first { entry in+ let (h, p) = Self.split(entry)+ guard host == h || host.hasSuffix("." + h) else { return false }+ guard let p else { return true }+ return path == p || path.hasPrefix(p + "/")+ }+ }++ /// "amazon.com/gp/video" → ("amazon.com", "/gp/video"); "netflix.com" → ("netflix.com", nil).+ static func split(_ entry: String) -> (host: String, path: String?) {+ guard let slash = entry.firstIndex(of: "/") else { return (entry, nil) }+ return (String(entry[..<slash]), String(entry[slash...]))+ }++ /// The user's own choice for a site (the Site Control Center's Safari's Engine switch): the+ /// lists Cra keeps of sites added to WebKit and listed ones taken off, after choosing `engine`+ /// for `url`'s host. Choosing WebKit lifts a removal (else adds the host); choosing Chromium+ /// drops an added host, and takes off the listed entry the address falls under.+ public static func choosing(_ engine: PageEngine, for url: String, added: [String], removed: [String])+ -> (added: [String], removed: [String]) {+ guard let host = webHost(of: url) else { return (added, removed) }+ var added = added.compactMap(normalizedHost), removed = removed.compactMap(normalizedHost)+ let defaults = ProtectedMediaSites(removedHosts: removed)+ switch engine {+ case .webKit:+ // A listed entry this site falls under, taken off earlier, comes back.+ let all = ProtectedMediaSites()+ if let entry = all.listedHost(for: url) { removed.removeAll { $0 == entry } }+ if ProtectedMediaSites(extraHosts: added, removedHosts: removed).engine(for: url) == .chromium, !added.contains(host) {+ added.append(host)+ }+ case .chromium:+ added.removeAll { entry in host == split(entry).host || host.hasSuffix("." + split(entry).host) }+ if let entry = defaults.listedHost(for: url), !removed.contains(entry) { removed.append(entry) }+ }+ return (added, removed)}/// The service's name for a page at `url` ("Spotify"); a host someone added names itself.@@ -110,13 +162,16 @@ public struct ProtectedMediaSites: Equatable, Sendable {return host.hasSuffix(".") ? String(host.dropLast()) : host}- /// "Open.Spotify.com", " spotify.com ", ".spotify.com" → "spotify.com"; a URL gives its host.+ /// "Open.Spotify.com", " spotify.com ", ".spotify.com" → "spotify.com"; a URL gives its host;+ /// "amazon.com/gp/video/" keeps its path, without the last slash.static func normalizedHost(_ entry: String) -> String? {var s = entry.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()if s.contains("://"), let host = webHost(of: s) { s = host }- while s.hasPrefix(".") { s.removeFirst() }- while s.hasSuffix(".") { s.removeLast() }- guard !s.isEmpty, !s.contains("/"), !s.contains(" ") else { return nil }- return s+ var (host, path) = split(s)+ while host.hasPrefix(".") { host.removeFirst() }+ while host.hasSuffix(".") { host.removeLast() }+ while path?.hasSuffix("/") == true { path?.removeLast() }+ guard !host.isEmpty, !host.contains(" "), path?.contains(" ") != true, path?.contains("?") != true else { return nil }+ return path.map { $0.isEmpty ? host : host + $0 } ?? host}}diff --git a/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift b/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swiftindex 2916faa..947b3d1 100644--- a/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift@@ -23,6 +23,12 @@ struct ProtectedMediaTests {"https://www.hotstar.com/in","https://www.jiohotstar.com/","https://v.qq.com/x/cover/x.html",+ "https://www.joyn.de/filme/x",+ "https://www.rakuten.tv/dk",+ "https://www.skyshowtime.com/watch",+ "https://www.nowtv.com/watch/home",+ "https://www.wowtv.de/",+ "https://www.showmax.com/","http://www.hulu.com/","https://www.netflix.com./browse",])@@ -73,6 +79,50 @@ struct ProtectedMediaTests {#expect(ProtectedMediaSites.defaultHosts.allSatisfy { ProtectedMediaSites.serviceNames[$0] != nil })}+ /// Prime Video where Amazon serves it, and Amazon Music; the rest of Amazon stays in Chromium.+ @Test func amazon() {+ #expect(sites.engine(for: "https://www.amazon.com/gp/video/detail/B0X/ref=x?autoplay=1") == .webKit)+ #expect(sites.engine(for: "https://www.amazon.com/gp/video") == .webKit)+ #expect(sites.engine(for: "https://www.amazon.co.uk/gp/video/storefront") == .webKit)+ #expect(sites.engine(for: "https://music.amazon.com/albums/x") == .webKit)+ #expect(sites.engine(for: "https://music.amazon.de/") == .webKit)+ #expect(sites.engine(for: "https://www.amazon.com/") == .chromium)+ #expect(sites.engine(for: "https://www.amazon.com/dp/B0X") == .chromium)+ #expect(sites.engine(for: "https://www.amazon.com/gp/videogames") == .chromium)+ #expect(sites.engine(for: "https://www.amazon.com/ap/signin?openid.return_to=x") == .chromium)+ #expect(sites.engine(for: "https://www.amazon.dk/gp/video") == .chromium)+ #expect(sites.serviceName(for: "https://www.amazon.com/gp/video/detail/1") == "Prime Video")+ #expect(sites.serviceName(for: "https://music.amazon.co.uk/") == "Amazon Music")+ // A Chromium page going to Prime Video moves; Amazon's shopping pages don't.+ #expect(sites.handoff(from: .chromium, to: "https://www.amazon.com/gp/video/detail/1", method: "GET") == .webKit)+ #expect(sites.handoff(from: .chromium, to: "https://www.amazon.com/s?k=tv", method: "GET") == nil)+ }++ /// The Site Control Center's Safari's Engine switch: what Cra keeps after a choice.+ @Test func choosingPerSite() {+ // A site off the list goes to WebKit, and back.+ var r = ProtectedMediaSites.choosing(.webKit, for: "https://www.viaplay.dk/film", added: [], removed: [])+ #expect(r.added == ["www.viaplay.dk"] && r.removed.isEmpty)+ #expect(ProtectedMediaSites(extraHosts: r.added).engine(for: "https://www.viaplay.dk/serier") == .webKit)+ r = ProtectedMediaSites.choosing(.chromium, for: "https://www.viaplay.dk/film", added: r.added, removed: r.removed)+ #expect(r.added.isEmpty && r.removed.isEmpty)+ // A listed one taken off goes under the entry it falls under, and comes back.+ r = ProtectedMediaSites.choosing(.chromium, for: "https://www.netflix.com/browse", added: [], removed: [])+ #expect(r.added.isEmpty && r.removed == ["netflix.com"])+ #expect(ProtectedMediaSites(removedHosts: r.removed).engine(for: "https://www.netflix.com/title/1") == .chromium)+ r = ProtectedMediaSites.choosing(.webKit, for: "https://www.netflix.com/browse", added: r.added, removed: r.removed)+ #expect(r.added.isEmpty && r.removed.isEmpty)+ // Path entries too.+ r = ProtectedMediaSites.choosing(.chromium, for: "https://www.amazon.com/gp/video/detail/1", added: [], removed: [])+ #expect(r.removed == ["amazon.com/gp/video"])+ #expect(ProtectedMediaSites(removedHosts: r.removed).engine(for: "https://www.amazon.com/gp/video") == .chromium)+ // Choosing what already holds changes nothing; a non-web address changes nothing.+ r = ProtectedMediaSites.choosing(.webKit, for: "https://open.spotify.com/", added: [], removed: [])+ #expect(r.added.isEmpty && r.removed.isEmpty)+ r = ProtectedMediaSites.choosing(.webKit, for: "chrome://settings", added: ["a.com"], removed: ["b.com"])+ #expect(r.added == ["a.com"] && r.removed == ["b.com"])+ }+@Test func offMeansChromiumEverywhere() {let off = ProtectedMediaSites(isEnabled: false)#expect(off.engine(for: "https://open.spotify.com/") == .chromium)@@ -92,9 +142,10 @@ struct ProtectedMediaTests {}@Test func entriesAreCleanedAndDeduplicated() {- let custom = ProtectedMediaSites(extraHosts: ["open.spotify.com", "OPEN.SPOTIFY.COM", "", " ", "a b", "x.com/path"])+ let custom = ProtectedMediaSites(extraHosts: ["open.spotify.com", "OPEN.SPOTIFY.COM", "", " ", "a b", "x.com/a b", "x.com/?q"])#expect(custom.hosts.filter { $0 == "open.spotify.com" }.count == 1)#expect(custom.hosts.count == ProtectedMediaSites.defaultHosts.count)+ #expect(ProtectedMediaSites(extraHosts: ["X.com/Watch/"]).hosts.last == "x.com/watch")}/// A Chromium page's own navigation to a service moves before the request goes out; a POSTdiff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swiftindex 866d617..c987572 100644--- a/Sources/Cra/Services/BrowserManager.swift+++ b/Sources/Cra/Services/BrowserManager.swift@@ -1047,6 +1047,16 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {return true}+ /// The Site Control Center's Safari's Engine switch: the tab's page opens again at its address+ /// in the engine it now gets (PageEngines.choose first), in its place on screen.+ func reopenInItsEngine(_ id: UUID) {+ guard let rt = runtimes[id] else { return }+ let url = rt.browser.currentURL+ guard PageEngines.engine(of: rt.browser) != PageEngines.sites.engine(for: url) else { return }+ log(id, "moves to \(PageEngines.engine(of: rt.browser) == .webKit ? "Chromium" : "WebKit") for \(site(url, id, rt.browser)), as chosen")+ reopen(id, at: url, replacing: rt.browser)+ }+/// The tab's page closes and opens again at `url`, in the engine the address gets, on screen/// where it was (its split pane, the focus).private func reopen(_ id: UUID, at url: String, replacing old: CraBrowser) {diff --git a/Sources/Cra/Services/PageScript.swift b/Sources/Cra/Services/PageScript.swiftindex 7fb6509..258bba2 100644--- a/Sources/Cra/Services/PageScript.swift+++ b/Sources/Cra/Services/PageScript.swift@@ -12,6 +12,9 @@ import Foundation/// player can skip tracks. `setActionHandler` can't be called from outside and its handlers/// live in the page's world, so a small wrapper there keeps them in a closure and answers an/// event whose name is random per launch: nothing in the page's world names Cra.+/// - `drm`: the page asked for Widevine (navigator.requestMediaKeySystemAccess): the Site Control+/// Center then offers to play the site in Safari's engine (docs/protected-media.md). A wrapper in+/// the page's world tells this world through the same per-launch event name./// - `lt`: the top frame's long tasks (50 ms or more) for the performance recorder (GitHub #91):/// a count, the total and the last 100 durations, which Cra reads and resets for the visible/// tab every few seconds. No attribution, no addresses; the observer only runs when a long@@ -36,6 +39,15 @@ enum PageScript {try { handlers[e.detail]?.({ action: e.detail }); } catch {}});})();+ (() => {+ const proto = window.Navigator?.prototype, request = proto?.requestMediaKeySystemAccess;+ if (!request) return;+ Object.defineProperty(proto, 'requestMediaKeySystemAccess', { configurable: true, writable: true,+ value: { requestMediaKeySystemAccess(keySystem, configs) {+ if (String(keySystem).startsWith('com.widevine')) dispatchEvent(new CustomEvent('\(channel)d'));+ return request.call(this, keySystem, configs);+ } }.requestMediaKeySystemAccess });+ })();"""/// Cra's isolated world.@@ -49,6 +61,7 @@ enum PageScript {if (t instanceof Element) cra.typed.set(t, location.href);}, true);addEventListener('\(channel)r', e => { cra.handlers = String(e.detail || '').split(',').filter(Boolean); });+ addEventListener('\(channel)d', () => { cra.drm = true; });cra.send = action => dispatchEvent(new CustomEvent('\(channel)', { detail: action }));cra.query = () => (cra.send('?'), cra.handlers);if (window.top === window) try {diff --git a/Sources/Cra/Services/WebKit/PageEngines.swift b/Sources/Cra/Services/WebKit/PageEngines.swiftindex 26ba465..a410678 100644--- a/Sources/Cra/Services/WebKit/PageEngines.swift+++ b/Sources/Cra/Services/WebKit/PageEngines.swift@@ -9,15 +9,29 @@ enum PageEngines {/// it off (every page Chromium's again); `webKitProtectedMediaHosts` and/// `webKitProtectedMediaRemovedHosts` (string arrays) change the list. A test instance sets/// CRA_WEBKIT_DRM=0|1 and CRA_WEBKIT_HOSTS=<host,host> (the scenarios' 127.0.0.1).- static let sites: ProtectedMediaSites = {+ /// The Site Control Center's Safari's Engine switch writes the two lists (`choose`).+ private(set) static var sites: ProtectedMediaSites = load()++ private static let addedKey = "webKitProtectedMediaHosts", removedKey = "webKitProtectedMediaRemovedHosts"++ private static func load() -> ProtectedMediaSites {let env = ProcessInfo.processInfo.environmentlet defaults = UserDefaults.standardlet enabled = env["CRA_WEBKIT_DRM"].map { $0 != "0" } ?? (defaults.object(forKey: "webKitProtectedMedia") as? Bool ?? true)- let extra = (env["CRA_WEBKIT_HOSTS"] ?? "").split(separator: ",").map(String.init)- + (defaults.stringArray(forKey: "webKitProtectedMediaHosts") ?? [])- let removed = defaults.stringArray(forKey: "webKitProtectedMediaRemovedHosts") ?? []+ let extra = (env["CRA_WEBKIT_HOSTS"] ?? "").split(separator: ",").map(String.init) + (defaults.stringArray(forKey: addedKey) ?? [])+ let removed = defaults.stringArray(forKey: removedKey) ?? []return ProtectedMediaSites(isEnabled: enabled, extraHosts: extra, removedHosts: removed)- }()+ }++ /// The user's choice for `url`'s site (ProtectedMediaSites.choosing), kept and in force at once.+ static func choose(_ engine: PageEngine, for url: String) {+ let defaults = UserDefaults.standard+ let r = ProtectedMediaSites.choosing(engine, for: url, added: defaults.stringArray(forKey: addedKey) ?? [],+ removed: defaults.stringArray(forKey: removedKey) ?? [])+ defaults.set(r.added, forKey: addedKey)+ defaults.set(r.removed, forKey: removedKey)+ sites = load()+ }static func engine(of browser: CraBrowser) -> PageEngine { browser is WebKitBrowser ? .webKit : .chromium }diff --git a/Sources/Cra/UI/SiteControlCenter.swift b/Sources/Cra/UI/SiteControlCenter.swiftindex 60cf084..59252fe 100644--- a/Sources/Cra/UI/SiteControlCenter.swift+++ b/Sources/Cra/UI/SiteControlCenter.swift@@ -23,6 +23,8 @@ struct SiteControlCenterActions {var showCertificate: (() -> Void)?/// A WebKit page's "Learn more" (docs/protected-media.md).var learnAboutProtectedMedia: () -> Void = {}+ /// The Safari's Engine switch: true plays the site in WebKit from now on, false in Chromium.+ var chooseSafariEngine: (Bool) -> Void = { _ in }}enum SiteControlCenterMetrics {@@ -50,13 +52,16 @@ final class SiteControlCenterView: NSView {/// A WebKit page's service ("Spotify"): the card that says why takes the extensions' place,/// and the ad blocker's switch goes (it is Chromium's).private let protectedMedia: String?+ /// The Safari's Engine switch's state, nil without the switch (a page that uses no DRM).+ private let safariEngine: Bool?private var extensions: ExtensionStore { .shared }/// The tiles by extension ID, whose icons follow the extensions' own changes in place.private var extensionTiles: [String: SiteExtensionTile] = [:]init(url: String, secure: Bool, dark: Bool, profile: String, tab: UUID?, protectedMedia: String? = nil,- actions: SiteControlCenterActions, store: SidebarStore) {+ safariEngine: Bool? = nil, actions: SiteControlCenterActions, store: SidebarStore) {self.protectedMedia = protectedMedia+ self.safariEngine = safariEngineself.url = urlself.secure = secureself.profile = profile@@ -175,6 +180,11 @@ final class SiteControlCenterView: NSView {]// Chromium's blocker doesn't see a WebKit page: no switch that does nothing there.if protectedMedia != nil { rowsSpec.remove(at: 1) }+ // A page that plays DRM, or one in WebKit: which engine plays this site (docs/protected-media.md).+ if let on = safariEngine {+ let choose = actions.chooseSafariEngine+ rowsSpec.append(("safari", "Safari’s Engine", on ? "On" : "Off", on, { choose(!on) }))+ }for (i, r) in rowsSpec.enumerated() {let row = SiteSettingRow(symbol: r.0, title: r.1, subtitle: r.2, active: r.3, colors: colors, action: r.4)row.frame = NSRect(x: 0, y: 27 + CGFloat(i) * 43, width: 208, height: 33)@@ -714,8 +724,10 @@ final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {var isShown: Bool { popover?.isShown == true }- func show(relativeTo rect: NSRect, of view: NSView, url: String, secure: Bool, dark: Bool, profile: String, tab: UUID?,- protectedMedia: String? = nil, store: SidebarStore, actions: SiteControlCenterActions) {+ /// The sliders button pressed while the popover is up, or by the click that just closed it:+ /// it closes (and stays closed) instead of opening again. Asked before anything slower than+ /// the click itself (the page's DRM question), while the click is still the current event.+ func closesInstead() -> Bool {// A transient popover closes on the mouse-down outside it; the button fires on that// click's mouse-up. The same click on the sliders button closes it, as in Arc,// however long the press took (GitHub #42): the latest mouse-down is the closing one.@@ -724,8 +736,15 @@ final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {&& abs(ProcessInfo.processInfo.systemUptime - CGEventSource.secondsSinceLastEventType(.combinedSessionState, eventType: .leftMouseDown) - t) < 0.05} ?? falseclosingClick = nil- if let popover, popover.isShown { popover.performClose(nil); return }- if closedByThisClick { return }+ if let popover, popover.isShown { popover.performClose(nil); return true }+ return closedByThisClick+ }++ func show(relativeTo rect: NSRect, of view: NSView, url: String, secure: Bool, dark: Bool, profile: String, tab: UUID?,+ protectedMedia: String? = nil, safariEngine: Bool? = nil, toggleChecked: Bool = false,+ store: SidebarStore, actions: SiteControlCenterActions) {+ if !toggleChecked, closesInstead() { return }+ if let popover, popover.isShown { popover.performClose(nil) }let p = NSPopover()p.behavior = .transientp.animates = true@@ -746,8 +765,10 @@ final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {acts.clearCookies = closing(actions.clearCookies)acts.showCertificate = actions.showCertificate.map(closing)acts.learnAboutProtectedMedia = closing(actions.learnAboutProtectedMedia)+ // The page opens again in the other engine: the popover's content would be the old page's.+ acts.chooseSafariEngine = { [weak p] on in p?.performClose(nil); actions.chooseSafariEngine(on) }let content = SiteControlCenterView(url: url, secure: secure, dark: dark, profile: profile, tab: tab, protectedMedia: protectedMedia,- actions: acts, store: store)+ safariEngine: safariEngine, actions: acts, store: store)let host = NSViewController()host.view = contenthost.preferredContentSize = content.frame.sizediff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 267bf83..05f1eaa 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -2307,6 +2307,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM}private func showToolbarExtensionsMenu(from anchor: NSRect? = nil, inToolbar: Bool = false) {+ // Decided now, while the click is the current event: the page is asked a question below.+ if siteControlCenter.closesInstead() { return }// A split pane's bar has the sliders even with the toolbar hidden: hang under that bar then.let pressed = anchor.map { inToolbar ? $0 : nil } ?? Self.buttonFrameUnderPointer { $0 is ToolbarGlyphButton }guard let window, let content = window.contentView,@@ -2337,11 +2339,40 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMself?.openTab("chrome://settings/content/siteDetails?site=" + (origin.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? origin))}actions.learnAboutProtectedMedia = { [weak self] in self?.openTab(Self.protectedMediaHelp) }+ actions.chooseSafariEngine = { [weak self] on in self?.chooseSafariEngine(on, for: url) }siteControlCenterSpaceID = focusedSpaceID- siteControlCenter.show(relativeTo: rect, of: content, url: url, secure: secure, dark: SystemAppearance.shared.isDark,- profile: profileDirectoryName, tab: selectedTabID,- protectedMedia: browsers.visibleTabID.flatMap { sidebarUI.navState(for: $0).protectedMedia },- store: store, actions: actions)+ let show = { [weak self] (safariEngine: Bool?) in+ guard let self, let window = self.window, window.isVisible else { return }+ self.siteControlCenter.show(relativeTo: rect, of: content, url: url, secure: secure, dark: SystemAppearance.shared.isDark,+ profile: self.profileDirectoryName, tab: self.selectedTabID,+ protectedMedia: self.browsers.visibleTabID.flatMap { self.sidebarUI.navState(for: $0).protectedMedia },+ safariEngine: safariEngine, toggleChecked: true, store: self.store, actions: actions)+ }+ // The Safari's Engine switch: on for a WebKit page; for a Chromium page only once it asked+ // for Widevine (PageScript's `drm`), else no switch. Asked in Cra's world; a page that+ // doesn't answer within 0.3 s opens without it.+ guard let b = currentBrowser, url.hasPrefix("http") else { return show(nil) }+ if b is WebKitBrowser { return show(true) }+ var shown = false+ let once = { (value: Bool?) in if !shown { shown = true; show(value) } }+ b.evaluate(inIsolatedWorld: PageScript.world, params: #"{"expression":"window.__cra?.drm === true","returnByValue":true}"#) { result, _ in+ let drm = result.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }+ .flatMap { $0["result"] as? [String: Any] }?["value"] as? Bool == true+ DispatchQueue.main.async { once(drm ? false : nil) }+ }+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { once(nil) }+ }++ /// The Site Control Center's Safari's Engine switch: the site plays in WebKit (or Chromium)+ /// from now on, and the focused page opens again there. Choosing it is knowing about it: no toast.+ private func chooseSafariEngine(_ on: Bool, for url: String) {+ PageEngines.choose(on ? .webKit : .chromium, for: url)+ if on, let service = PageEngines.sites.serviceName(for: url) {+ let key = "protectedMediaToldServices"+ let told = UserDefaults.standard.stringArray(forKey: key) ?? []+ if !told.contains(service) { UserDefaults.standard.set(told + [service], forKey: key) }+ }+ if let id = browsers.visibleTabID { browsers.reopenInItsEngine(id) }}/// The help centre's page on why Spotify, Netflix and the others play in Safari's engine.diff --git a/Tests/BrowserManagerLifecycleTests.swift b/Tests/BrowserManagerLifecycleTests.swiftindex 6ff75c5..2c2868f 100644--- a/Tests/BrowserManagerLifecycleTests.swift+++ b/Tests/BrowserManagerLifecycleTests.swift@@ -207,6 +207,26 @@ enum BrowserManagerLifecycleTests {manager.windowVisibilityChanged(covered: false)store.settings.autoPictureInPicture = false+ // The Site Control Center's Safari's Engine switch: a site off the list moves to WebKit, in its+ // place on screen, and back; the choice holds for the next page of that site.+ let chosen = store.createTab(url: "https://stream.example.test/film").id+ manager.show([chosen, other], focused: chosen, focus: false)+ let before = manager.runtime(for: chosen)!.browser+ manager.reopenInItsEngine(chosen)+ expect(manager.runtime(for: chosen)?.browser === before, "without a choice the page stays where it is")+ PageEngines.choose(.webKit, for: "https://stream.example.test/film")+ manager.reopenInItsEngine(chosen)+ await drainMainQueue()+ expect(manager.runtime(for: chosen)?.browser is WebKitBrowser && manager.visibleTabIDs == [chosen, other] && manager.visibleTabID == chosen,+ "chosen for Safari's engine, the page opens in WebKit in its pane")+ expect(PageEngines.sites.engine(for: "https://stream.example.test/other") == .webKit, "the choice holds for the site")+ PageEngines.choose(.chromium, for: "https://stream.example.test/film")+ manager.reopenInItsEngine(chosen)+ await drainMainQueue()+ expect(!(manager.runtime(for: chosen)?.browser is WebKitBrowser), "chosen back, the page opens in Chromium")+ UserDefaults.standard.removeObject(forKey: "webKitProtectedMediaHosts")+ UserDefaults.standard.removeObject(forKey: "webKitProtectedMediaRemovedHosts")+// A late request from a page that already moved changes nothing.expect(!manager.browser(chromium, handsOffNavigationToURL: "https://www.netflix.com/", method: "GET"), "a retired page can't move its tab again")manager.closeAll()diff --git a/docs/protected-media.md b/docs/protected-media.mdindex e6bc323..a706f8e 100644--- a/docs/protected-media.md+++ b/docs/protected-media.md@@ -35,7 +35,19 @@ licence, keys usable, 720p playing). That is the whole requirement.`primevideo.com`, `hulu.com`, `paramountplus.com`, `peacocktv.com`, `tv.apple.com`,`music.apple.com`, `listen.tidal.com`, `www.deezer.com`, `crunchyroll.com`, `hotstar.com`,`jiohotstar.com` and `v.qq.com`. The last four come from Ardia, another open-source browser that- sends DRM sites to WebKit (its `PROTECTED_VIDEO_SITES`). They are players, not whole domains, except where nothing else signs in through the service (Max sends `play.max.com` on to `www.hbomax.com` and signs in on its own hosts):+ sends DRM sites to WebKit (its `PROTECTED_VIDEO_SITES`). Joyn (`joyn.de`, `.at`, `.ch`) and Rakuten TV+ (`rakuten.tv`) were seen refusing non-VMP Chromium with "Verified Media Path" errors; SkyShowtime,+ NOW (`nowtv.com`), WOW (`wowtv.de`) and Showmax run on Sky's and Peacock's platforms, which fail+ the same way. Zattoo, Movistar Plus+, Crave, RTL+ and Viaplay had weaker evidence and are left to+ the switch below. Amazon has path entries: Prime Video at+ `amazon.<store>/gp/video` (the US and Amazon's other stores that serve it there), and Amazon Music at+ `music.amazon.<store>`. The rest of Amazon (shopping, Login with Amazon) stays in Chromium.+- **Any other site, by the user**: when a Chromium page asks for Widevine (PageScript's `drm`, a+ wrapper around `navigator.requestMediaKeySystemAccess`), the Site Control Center shows a+ **Safari's Engine** switch. On, the site plays in WebKit from then on and the page reopens there.+ A WebKit page shows it on, so a listed site can be taken back to Chromium the same way+ (`ProtectedMediaSites.choosing`, kept in `webKitProtectedMediaHosts` and+ `webKitProtectedMediaRemovedHosts`). They are players, not whole domains, except where nothing else signs in through the service (Max sends `play.max.com` on to `www.hbomax.com` and signs in on its own hosts):other sites send their "Sign in with Spotify/Tidal/Deezer" through `accounts.spotify.com`,`login.tidal.com` and `connect.deezer.com`, and those must finish in the engine they started in.- **A page Cra opens** (a tab restored or created, a link opened in a new tab, a Little Window, an