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.
Say why a page plays in Safari's engine: a toast, a Site Control Center card, dimmed extensions
Victorc59004a9922a
diff --git a/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift b/Packages/CraCore/Sources/CraCore/ProtectedMedia.swiftindex e531e4e..5302119 100644--- a/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift+++ b/Packages/CraCore/Sources/CraCore/ProtectedMedia.swift@@ -48,6 +48,15 @@ public struct ProtectedMediaSites: Equatable, Sendable {"www.deezer.com",]+ /// 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).+ public static let serviceNames: [String: String] = [+ "open.spotify.com": "Spotify", "netflix.com": "Netflix", "disneyplus.com": "Disney+",+ "max.com": "Max", "hbomax.com": "HBO Max", "primevideo.com": "Prime Video", "hulu.com": "Hulu",+ "paramountplus.com": "Paramount+", "peacocktv.com": "Peacock", "tv.apple.com": "Apple TV",+ "music.apple.com": "Apple Music", "listen.tidal.com": "Tidal", "www.deezer.com": "Deezer",+ ]+/// Off: every page is Chromium's, as before.public var isEnabled: Bool/// Lower-cased hosts without a leading dot.@@ -65,8 +74,18 @@ public struct ProtectedMediaSites: Equatable, Sendable {/// The engine a page Cra opens at `url` gets.public func engine(for url: String) -> PageEngine {- guard isEnabled, let host = Self.webHost(of: url) else { return .chromium }- return hosts.contains { host == $0 || host.hasSuffix("." + $0) } ? .webKit : .chromium+ listedHost(for: url) == nil ? .chromium : .webKit+ }++ /// The listed host `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) }+ }++ /// The service's name for a page at `url` ("Spotify"); a host someone added names itself.+ public func serviceName(for url: String) -> String? {+ listedHost(for: url).map { Self.serviceNames[$0] ?? $0 }}/// A navigation a page started itself: the engine it has to move to, or nil to stay.diff --git a/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift b/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swiftindex e9299ed..ec8bb9d 100644--- a/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ProtectedMediaTests.swift@@ -51,6 +51,20 @@ struct ProtectedMediaTests {#expect(sites.engine(for: url) == .chromium)}+ /// The name the toast and the Site Control Center use.+ @Test func serviceNames() {+ #expect(sites.serviceName(for: "https://open.spotify.com/track/1") == "Spotify")+ #expect(sites.serviceName(for: "https://www.netflix.com/browse") == "Netflix")+ #expect(sites.serviceName(for: "https://www.disneyplus.com/") == "Disney+")+ #expect(sites.serviceName(for: "https://play.hbomax.com/") == "HBO Max")+ #expect(sites.serviceName(for: "https://music.apple.com/us/browse") == "Apple Music")+ #expect(sites.serviceName(for: "https://www.google.com/") == nil)+ #expect(ProtectedMediaSites(extraHosts: ["crunchyroll.com"]).serviceName(for: "https://www.crunchyroll.com/") == "crunchyroll.com")+ #expect(ProtectedMediaSites(isEnabled: false).serviceName(for: "https://open.spotify.com/") == nil)+ // Every listed service has a name.+ #expect(ProtectedMediaSites.defaultHosts.allSatisfy { ProtectedMediaSites.serviceNames[$0] != nil })+ }+@Test func offMeansChromiumEverywhere() {let off = ProtectedMediaSites(isEnabled: false)#expect(off.engine(for: "https://open.spotify.com/") == .chromium)diff --git a/Sources/Cra/Services/WebKit/PageEngines.swift b/Sources/Cra/Services/WebKit/PageEngines.swiftindex 1e57dcb..26ba465 100644--- a/Sources/Cra/Services/WebKit/PageEngines.swift+++ b/Sources/Cra/Services/WebKit/PageEngines.swift@@ -21,6 +21,13 @@ enum PageEngines {static func engine(of browser: CraBrowser) -> PageEngine { browser is WebKitBrowser ? .webKit : .chromium }+ /// The service a WebKit page plays ("Spotify"), nil for a Chromium page: Cra tells the user why+ /// its extensions don't run there and it signs in on its own.+ static func protectedMediaService(of browser: CraBrowser) -> String? {+ guard let page = browser as? WebKitBrowser else { return nil }+ return page.serviceName.isEmpty ? "This site" : page.serviceName+ }+/// The page is in WebKit's own fullscreen window, which covers Cra's (Chromium's fullscreen/// is Cra's window going fullscreen).static func isInOwnFullscreen(_ browser: CraBrowser) -> Bool { (browser as? WebKitBrowser)?.isContentFullscreen == true }@@ -32,7 +39,9 @@ enum PageEngines {let engine = url.map { sites.engine(for: $0) } ?? opener.map(engine(of:)) ?? .chromiumswitch engine {case .webKit:- return WebKitBrowser(frame: frame, url: url, delegate: delegate, incognito: incognito, profilePath: profilePath)+ let page = WebKitBrowser(frame: frame, url: url, delegate: delegate, incognito: incognito, profilePath: profilePath)+ page.serviceName = url.flatMap { sites.serviceName(for: $0) } ?? (opener as? WebKitBrowser)?.serviceName ?? ""+ return pagecase .chromium:return CraBrowser(frame: frame, url: url, delegate: delegate, incognito: incognito, profilePath: profilePath)}@@ -51,3 +60,10 @@ enum PageEngines {}}}++extension ExtensionStore {+ /// The tooltip of an extension button dimmed on a WebKit page ("Extensions don’t run on Spotify").+ nonisolated static func offOnProtectedMedia(_ service: String) -> String {+ "Extensions don’t run on \(service == "This site" ? "this site" : service)"+ }+}diff --git a/Sources/Cra/Services/WebKit/WebKitBrowser.swift b/Sources/Cra/Services/WebKit/WebKitBrowser.swiftindex 523e092..1dcf278 100644--- a/Sources/Cra/Services/WebKit/WebKitBrowser.swift+++ b/Sources/Cra/Services/WebKit/WebKitBrowser.swift@@ -37,6 +37,9 @@ final class WebKitBrowser: CraBrowser, WKNavigationDelegate, WKUIDelegate, WKDowprivate var audible = falseprivate var audibleOff: DispatchWorkItem?private var capturing = false+ /// The service this page opened for ("Spotify"), kept while it signs in elsewhere: what the+ /// toast, the Site Control Center and the dimmed extension buttons name (PageEngines).+ var serviceName = ""/// WebKit took the page to its own fullscreen window (Chromium's fullscreen is Cra's window).private(set) var isContentFullscreen = falseprivate var inPictureInPicture = falsediff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swiftindex b6cc132..844e185 100644--- a/Sources/Cra/UI/PaneToolbarView.swift+++ b/Sources/Cra/UI/PaneToolbarView.swift@@ -33,6 +33,8 @@ final class PaneToolbarView: NSView {var sidebarVisible = truevar pinned: [Ext] = []var hasExtensions = false+ /// A WebKit page's service: its extension buttons dim (none run there).+ var protectedMedia: String?var fill = NSColor.clearvar fg = NSColor.labelColorvar fgDim = NSColor.secondaryLabelColor@@ -169,6 +171,7 @@ final class PaneToolbarView: NSView {// Arc shows the host only unless "Show Full URL" is on (#88).m.path = store.settings.toolbarShowsFullURL && human.hasPrefix(m.host) ? String(human.dropFirst(m.host.count)) : ""}+ m.protectedMedia = m.tabID.flatMap { ui.navState(for: $0).protectedMedia }let extensions = ExtensionStore.sharedlet profile = item.map { store.profileDirectoryName(item: $0.id) }?? store.profileDirectoryName(space: store.focusedSpaceID(window: ui.windowID))@@ -292,8 +295,10 @@ final class PaneToolbarView: NSView {case .pinnedExtension(let id):let e = m.pinned.first { $0.id == id }let b = button("ext:" + id) { ToolbarGlyphButton() }- // Arc: the 16 pt action icon with its badge, and no tooltip (Arc 1.171, #106).- b.configure(symbol: nil, image: ExtensionStore.shared.badged(e?.icon, e?.badge, tint: m.fgDim), help: "", enabled: true,+ // Arc: the 16 pt action icon with its badge, and no tooltip (Arc 1.171, #106). On a WebKit+ // page it dims and says why (docs/protected-media.md).+ b.configure(symbol: nil, image: ExtensionStore.shared.badged(e?.icon, e?.badge, tint: m.fgDim),+ help: m.protectedMedia.map(ExtensionStore.offOnProtectedMedia) ?? "", enabled: m.protectedMedia == nil,width: 34, iconSize: 16, tint: m.fgDim, hover: m.hover)let pane = paneTabIDb.action = { [weak self] in@@ -603,6 +608,8 @@ final class ToolbarGlyphButton: NSView {// A monochrome extension icon (ExtensionStore.toolbarIcon) is a template: the bar's ink.imageView.contentTintColor = image == nil || image?.isTemplate == true ? tint : nil}+ // An icon in its own colours can't be tinted grey: a disabled one fades instead.+ imageView.alphaValue = symbol == nil && !enabled ? 0.35 : 1}iconBox = symbol == nil ? NSSize(width: iconSize, height: iconSize) : nilneedsLayout = truediff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swiftindex e763dd5..f90fa32 100644--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift@@ -407,7 +407,7 @@ final class SidebarTopBarView: NSView {}}pill.show(text: text, url: url, hasTab: tab != nil, colors: colors, active: active,- pinned: pinned, hasExtensions: !entries.isEmpty)+ pinned: pinned, hasExtensions: !entries.isEmpty, protectedMedia: tab.flatMap { ui.navState(for: $0.id).protectedMedia })}needsLayout = trueif wasCompact != compact { superview?.superview?.needsLayout = true }@@ -537,7 +537,8 @@ final class SidebarURLPill: NSView {override var mouseDownCanMoveWindow: Bool { false }func show(text: String, url: String, hasTab: Bool, colors: SidebarColors, active: Bool,- pinned: [(String, String, NSImage?)], hasExtensions: Bool) {+ pinned: [(String, String, NSImage?)], hasExtensions: Bool, protectedMedia: String? = nil) {+ self.protectedMedia = protectedMediaself.colors = colorsself.hasTab = hasTabtip.text = url@@ -555,6 +556,8 @@ final class SidebarURLPill: NSView {/// Whether the pins go in this field (else in the grid over the favorites), for its width.private var pinsInField = true+ /// A WebKit page's service: the pins dim and say why (docs/protected-media.md).+ private var protectedMedia: String?/// Arc's URL-bar accessories: pinned extensions (while they leave the address room), Copy/// Link, then the site controls.@@ -565,8 +568,9 @@ final class SidebarURLPill: NSView {pinsInField = PinnedExtensionGrid.fitsInURLField(count: m.pinned.count, fieldWidth: bounds.width)for (id, _, icon) in pinsInField ? m.pinned : [] {let b = ToolbarGlyphButton()- // Arc's pinned extension buttons have no tooltip (#106).- b.configure(symbol: nil, image: icon, help: "", enabled: true, width: 28, iconSize: 16, tint: colors.textSecondary)+ // Arc's pinned extension buttons have no tooltip (#106), unless they can't run here.+ b.configure(symbol: nil, image: icon, help: protectedMedia.map(ExtensionStore.offOnProtectedMedia) ?? "",+ enabled: protectedMedia == nil, width: 28, iconSize: 16, tint: colors.textSecondary)b.action = { actions.runExtension(id) }b.menuProvider = { ExtensionStore.shared.entries.first { $0.extensionID == id }.map(ExtensionsMenu.iconMenu) }accessories.append(b)diff --git a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swiftindex a93974f..ff2fb41 100644--- a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift+++ b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift@@ -500,6 +500,7 @@ final class FavoritesGridView: NSView {var palette: SpacePalette?var dismissed = truevar pins: [Pin] = []+ var protectedMedia: String?withObservationTracking {guard let space = store.space(spaceID) else { return }palette = space.theme.palette@@ -509,6 +510,7 @@ final class FavoritesGridView: NSView {let profile = store.profileDirectoryName(space: spaceID)let entries = ext.entries(inProfile: profile)let tab = store.selectedTabID(in: spaceID, window: ui.windowID)+ protectedMedia = tab.flatMap { ui.navState(for: $0).protectedMedia }pins = ext.pinnedIDs(inProfile: profile).compactMap { id inentries.first { $0.extensionID == id }.map {Pin(id: id, name: $0.name, icon: ext.toolbarIcon(for: $0, profile: profile, tab: tab),@@ -546,7 +548,7 @@ final class FavoritesGridView: NSView {let showsCard = ids.isEmpty && !dismissed// Arc drops the card and moves the list up in one frame, like a first tile coming in.let countChanged = ids.count != order.count || showsCard == card.isHidden || pins.count != extensionOrder.count- showExtensions(pins, palette: palette)+ showExtensions(pins, palette: palette, protectedMedia: protectedMedia)for (id, t) in tiles where !ids.contains(id) {t.removeFromSuperview()tiles[id] = nil@@ -575,7 +577,7 @@ final class FavoritesGridView: NSView {/// The pinned extensions' buttons, in pin order; none while the toolbar shows them. Arc 1.171/// (4 Nov) draws each cell like a favorite tile, the tile's fill at rest and its hover fill,/// the 18 pt icon centred, and names it in a tooltip (its toolbar pins have none, #106).- private func showExtensions(_ pins: [Pin], palette: SpacePalette?) {+ private func showExtensions(_ pins: [Pin], palette: SpacePalette?, protectedMedia: String?) {let colors = palette.map(SidebarColors.init) ?? SidebarColors()let dark = palette?.isDark ?? falselet ids = pins.map(\.id)@@ -591,7 +593,9 @@ final class FavoritesGridView: NSView {addSubview(b)return b}()- b.configure(symbol: nil, image: ext.badged(p.icon, p.badge, tint: colors.textSecondary), help: p.name, enabled: true,+ // On a WebKit page they dim and say why (docs/protected-media.md).+ b.configure(symbol: nil, image: ext.badged(p.icon, p.badge, tint: colors.textSecondary),+ help: protectedMedia.map(ExtensionStore.offOnProtectedMedia) ?? p.name, enabled: protectedMedia == nil,width: 28, iconSize: 18, tint: colors.textSecondary,hover: dark ? NSColor.white.withAlphaComponent(0.15) : NSColor.black.withAlphaComponent(0.09))b.restFill = palette.map { NSColor($0.pillFill) } ?? .cleardiff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swiftindex fe5afd0..4069784 100644--- a/Sources/Cra/UI/SidebarUIState.swift+++ b/Sources/Cra/UI/SidebarUIState.swift@@ -171,6 +171,9 @@ struct TabNavState: Equatable {var canGoForward = falsevar isLoading = falsevar themeColor = ""+ /// The service a WebKit page plays ("Spotify"; docs/protected-media.md), nil for Chromium's:+ /// its extension buttons dim and the Site Control Center says why.+ var protectedMedia: String?}/// Where a dragged tab or link would go in the split (Arc: SplitViewControllerLayout.DropTarget).diff --git a/Sources/Cra/UI/SiteControlCenter.swift b/Sources/Cra/UI/SiteControlCenter.swiftindex 3a17a04..60cf084 100644--- a/Sources/Cra/UI/SiteControlCenter.swift+++ b/Sources/Cra/UI/SiteControlCenter.swift@@ -21,6 +21,8 @@ struct SiteControlCenterActions {var siteSettings: () -> Void = {}/// The lock: the page's certificate. nil without one (http, Chromium's pages).var showCertificate: (() -> Void)?+ /// A WebKit page's "Learn more" (docs/protected-media.md).+ var learnAboutProtectedMedia: () -> Void = {}}enum SiteControlCenterMetrics {@@ -45,11 +47,16 @@ final class SiteControlCenterView: NSView {private let profile: String/// The page's tab, whose extension icons the tiles show.private let tab: UUID?+ /// 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?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?, actions: SiteControlCenterActions, store: SidebarStore) {+ init(url: String, secure: Bool, dark: Bool, profile: String, tab: UUID?, protectedMedia: String? = nil,+ actions: SiteControlCenterActions, store: SidebarStore) {+ self.protectedMedia = protectedMediaself.url = urlself.secure = secureself.profile = profile@@ -120,50 +127,60 @@ final class SiteControlCenterView: NSView {addSubview(b)}y += M.tile.height + 11- // Extensions: a 4-column grid of tiles, then "+".- let ext = SiteSectionView(title: "Extensions", hoverText: "Manage", colors: colors, onHeaderClick: actions.manageExtensions)- extensionTiles = [:]- var tiles: [NSView] = orderedExtensions.map { e in- let tile = SiteExtensionTile(entry: e, pinned: extensions.isPinned(e.extensionID, inProfile: profile), colors: colors,- run: { [actions] in actions.runExtension(e.extensionID) },- togglePin: { [profile] in- ExtensionStore.shared.setPinned(e.extensionID, !ExtensionStore.shared.isPinned(e.extensionID, inProfile: profile), inProfile: profile)- })- tile.show(icon: liveIcon(e))- extensionTiles[e.extensionID] = tile- return tile- }- let add = SiteTile(colors: colors, help: "Add Extension", action: actions.addExtension)- add.setGlyph(SidebarSymbols.image("plus", size: 14, weight: .medium), tint: colors.text)- tiles.append(add)- for (i, t) in tiles.enumerated() {- t.frame = NSRect(x: CGFloat(i % 4) * (M.tile.width + M.gap), y: 27 + CGFloat(i / 4) * (M.tile.height + M.gap),- width: M.tile.width, height: M.tile.height)- ext.addSubview(t)+ if let service = protectedMedia {+ // A WebKit page: no extensions run in it, so the card says why instead (Arc has none).+ let card = SiteProtectedMediaCard(service: service, width: w, colors: colors, learnMore: actions.learnAboutProtectedMedia)+ card.frame.origin = NSPoint(x: x, y: y)+ addSubview(card)+ y += card.frame.height + 15+ } else {+ // Extensions: a 4-column grid of tiles, then "+".+ let ext = SiteSectionView(title: "Extensions", hoverText: "Manage", colors: colors, onHeaderClick: actions.manageExtensions)+ extensionTiles = [:]+ var tiles: [NSView] = orderedExtensions.map { e in+ let tile = SiteExtensionTile(entry: e, pinned: extensions.isPinned(e.extensionID, inProfile: profile), colors: colors,+ run: { [actions] in actions.runExtension(e.extensionID) },+ togglePin: { [profile] in+ ExtensionStore.shared.setPinned(e.extensionID, !ExtensionStore.shared.isPinned(e.extensionID, inProfile: profile), inProfile: profile)+ })+ tile.show(icon: liveIcon(e))+ extensionTiles[e.extensionID] = tile+ return tile+ }+ let add = SiteTile(colors: colors, help: "Add Extension", action: actions.addExtension)+ add.setGlyph(SidebarSymbols.image("plus", size: 14, weight: .medium), tint: colors.text)+ tiles.append(add)+ for (i, t) in tiles.enumerated() {+ t.frame = NSRect(x: CGFloat(i % 4) * (M.tile.width + M.gap), y: 27 + CGFloat(i / 4) * (M.tile.height + M.gap),+ width: M.tile.width, height: M.tile.height)+ ext.addSubview(t)+ }+ for case let t as SiteExtensionTile in tiles { ext.addSubview(t.badge) }+ let rows = (tiles.count + 3) / 4+ let extH = 27 + CGFloat(rows) * M.tile.height + CGFloat(rows - 1) * M.gap+ ext.frame = NSRect(x: x, y: y, width: w, height: extH)+ addSubview(ext)+ y += extH + 15}- for case let t as SiteExtensionTile in tiles { ext.addSubview(t.badge) }- let rows = (tiles.count + 3) / 4- let extH = 27 + CGFloat(rows) * M.tile.height + CGFloat(rows - 1) * M.gap- ext.frame = NSRect(x: x, y: y, width: w, height: extH)- addSubview(ext)- y += extH + 15// Settings: three switch rows.let settings = SiteSectionView(title: "Settings", hoverText: nil, colors: colors, onHeaderClick: {})let developer = store.settings.isDeveloperMode(url: url)let store = store, url = url- let rowsSpec: [(String, String, String, Bool, () -> Void)] = [+ var rowsSpec: [(String, String, String, Bool, () -> Void)] = [("hammer.fill", "Developer Mode", developer ? "On" : "Off", developer, { store.settings.toggleDeveloperMode(url: url) }),("shield.fill", "Block Ads & Trackers", store.settings.blockAdsAndTrackers ? "On" : "Off",store.settings.blockAdsAndTrackers, { store.settings.blockAdsAndTrackers.toggle() }),("gearshape.fill", "Automatic Picture-In-Picture", store.settings.autoPictureInPicture ? "Allowed" : "Disabled",store.settings.autoPictureInPicture, { store.settings.autoPictureInPicture.toggle() }),]+ // Chromium's blocker doesn't see a WebKit page: no switch that does nothing there.+ if protectedMedia != nil { rowsSpec.remove(at: 1) }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)settings.addSubview(row)}- let setH = 27 + 3 * 33 + 2 * 10+ let setH = 27 + rowsSpec.count * 33 + (rowsSpec.count - 1) * 10settings.frame = NSRect(x: x, y: y, width: w, height: CGFloat(setH))addSubview(settings)y += CGFloat(setH) + 13@@ -511,6 +528,86 @@ private final class SiteSettingRow: SiteHoverView {override func refresh() { alphaValue = hovered ? 0.85 : 1 }}+/// A WebKit page's place for the extensions: which engine plays it, and what that means here+/// (docs/protected-media.md). Header like the other sections, a line of text, three facts with+/// their glyphs, then "Learn more".+private final class SiteProtectedMediaCard: NSView {+ init(service: String, width: CGFloat, colors: SiteControlCenterColors, learnMore: @escaping () -> Void) {+ super.init(frame: NSRect(x: 0, y: 0, width: width, height: 10))+ let header = NSTextField.sidebarLabel(size: 14, weight: .bold)+ header.stringValue = "Protected Media"+ header.textColor = colors.header+ header.frame = NSRect(x: -SidebarText.inset, y: 0, width: width + SidebarText.inset, height: 17)+ addSubview(header)+ var y: CGFloat = 25+ let body = NSTextField(wrappingLabelWithString: "\(service) plays with Safari’s engine, which has the DRM it needs. Here, that means:")+ body.font = .systemFont(ofSize: 13)+ body.textColor = colors.text+ body.isSelectable = false+ body.preferredMaxLayoutWidth = width+ let bodyH = ceil(body.cell?.cellSize(forBounds: NSRect(x: 0, y: 0, width: width, height: 400)).height ?? 34)+ body.frame = NSRect(x: 0, y: y, width: width, height: bodyH)+ addSubview(body)+ y += bodyH + 9+ for (symbol, text) in [("person.crop.circle", "You sign in here once"), ("puzzlepiece.extension", "Extensions don’t run here"),+ ("hammer", "Web Inspector instead of DevTools")] {+ let glyph = NSImageView(frame: NSRect(x: 0, y: y, width: 18, height: 18))+ glyph.image = SidebarSymbols.image(symbol, size: 13, weight: .medium)+ glyph.contentTintColor = colors.secondary+ glyph.imageScaling = .scaleNone+ addSubview(glyph)+ // Wraps rather than truncates: the popover is narrow (236 pt) and the facts must read whole.+ let label = NSTextField(wrappingLabelWithString: text)+ label.font = .systemFont(ofSize: 13)+ label.textColor = colors.text+ label.isSelectable = false+ let textW = width - 26+ let h = ceil(label.cell?.cellSize(forBounds: NSRect(x: 0, y: 0, width: textW, height: 200)).height ?? 16)+ label.frame = NSRect(x: 26, y: y + 1, width: textW, height: h)+ addSubview(label)+ y += max(24, h + 8)+ }+ let link = SiteLinkLabel(text: "Learn more", colors: colors, action: learnMore)+ link.frame = NSRect(x: 0, y: y + 2, width: 90, height: 18)+ addSubview(link)+ y += 22+ setFrameSize(NSSize(width: width, height: y))+ setAccessibilityElement(true)+ setAccessibilityRole(.group)+ setAccessibilityLabel("Protected Media. \(service) plays with Safari’s engine. You sign in here once, extensions don’t run here, Web Inspector instead of DevTools.")+ }++ required init?(coder: NSCoder) { fatalError() }++ override var isFlipped: Bool { true }+}++/// "Learn more": secondary text that turns the text colour under the pointer.+private final class SiteLinkLabel: SiteHoverView {+ private let label = NSTextField.sidebarLabel(size: 13, weight: .semibold)+ private let colors: SiteControlCenterColors++ init(text: String, colors: SiteControlCenterColors, action: @escaping () -> Void) {+ self.colors = colors+ super.init(frame: .zero)+ onClick = action+ label.stringValue = text+ label.textColor = colors.secondary+ addSubview(label)+ setAccessibilityLabel(text)+ setAccessibilityRole(.link)+ }++ required init?(coder: NSCoder) { fatalError() }++ override func layout() {+ super.layout()+ label.frame = NSRect(x: -SidebarText.inset, y: 0, width: bounds.width + 2 * SidebarText.inset, height: bounds.height)+ }++ override func refresh() { label.textColor = hovered ? colors.text : colors.secondary }+}+/// Pressed, it shows the page's certificate (Arc closes the control center and opens it).private final class SiteSecurityPill: SiteHoverView {private let colors: SiteControlCenterColors@@ -618,7 +715,7 @@ 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?,- store: SidebarStore, actions: SiteControlCenterActions) {+ protectedMedia: String? = nil, store: SidebarStore, actions: SiteControlCenterActions) {// 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.@@ -648,7 +745,9 @@ final class SiteControlCenterPopover: NSObject, NSPopoverDelegate {acts.clearCache = closing(actions.clearCache)acts.clearCookies = closing(actions.clearCookies)acts.showCertificate = actions.showCertificate.map(closing)- let content = SiteControlCenterView(url: url, secure: secure, dark: dark, profile: profile, tab: tab, actions: acts, store: store)+ acts.learnAboutProtectedMedia = closing(actions.learnAboutProtectedMedia)+ let content = SiteControlCenterView(url: url, secure: secure, dark: dark, profile: profile, tab: tab, protectedMedia: protectedMedia,+ 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 c002a9e..cadbcf1 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -522,9 +522,11 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMvar nav: [UUID: TabNavState] = [:]for id in ids {guard let rt = browsers.runtime(for: id) else { continue }- nav[id] = TabNavState(canGoBack: rt.browser.canGoBack, canGoForward: rt.browser.canGoForward, isLoading: rt.browser.isLoading, themeColor: rt.themeColor)+ nav[id] = TabNavState(canGoBack: rt.browser.canGoBack, canGoForward: rt.browser.canGoForward, isLoading: rt.browser.isLoading,+ themeColor: rt.themeColor, protectedMedia: PageEngines.protectedMediaService(of: rt.browser))}if nav != sidebarUI.navStates { sidebarUI.navStates = nav }+ if let id = browsers.visibleTabID, let service = nav[id]?.protectedMedia { tellAboutProtectedMedia(service) }}// MARK: Split view@@ -2323,9 +2325,18 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMguard let origin = URL(string: url).flatMap({ u in u.host.map { "\(u.scheme ?? "https")://\($0)" } }) else { return }self?.openTab("chrome://settings/content/siteDetails?site=" + (origin.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? origin))}+ actions.learnAboutProtectedMedia = { [weak self] in self?.openTab(Self.protectedMediaHelp) }siteControlCenterSpaceID = focusedSpaceIDsiteControlCenter.show(relativeTo: rect, of: content, url: url, secure: secure, dark: SystemAppearance.shared.isDark,- profile: profileDirectoryName, tab: selectedTabID, store: store, actions: actions)+ profile: profileDirectoryName, tab: selectedTabID,+ protectedMedia: browsers.visibleTabID.flatMap { sidebarUI.navState(for: $0).protectedMedia },+ store: store, actions: actions)+ }++ /// The help centre's page on why Spotify, Netflix and the others play in Safari's engine.+ static let protectedMediaHelp = "https://crabrowser.app/help/protected-media"++ func debugSiteControlsShown() -> Bool { siteControlCenter.isShown}private func openTab(_ url: String) {@@ -2626,6 +2637,26 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMreturn url?.isEmpty == false ? url : nil}+ /// The first time a service plays in a WebKit page (docs/protected-media.md), once per service+ /// ever: "Spotify plays with Safari's engine", and Why? opens the Site Control Center, which+ /// says what that means. A moment after the page shows, so it isn't lost in the tab switch.+ private func tellAboutProtectedMedia(_ service: String) {+ let key = "protectedMediaToldServices"+ var told = UserDefaults.standard.stringArray(forKey: key) ?? []+ guard !told.contains(service), window?.isVisible == true else { return }+ told.append(service)+ UserDefaults.standard.set(told, forKey: key)+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) { [weak self] in+ guard let self, let id = self.browsers.visibleTabID, self.sidebarUI.navState(for: id).protectedMedia == service else {+ // Gone before it could be said: next time.+ UserDefaults.standard.set((UserDefaults.standard.stringArray(forKey: key) ?? []).filter { $0 != service }, forKey: key)+ return+ }+ self.showToast("\(service) plays with Safari's engine",+ action: ShinyToast.Action(title: "Why?") { [weak self] in self?.showToolbarExtensionsMenu() })+ }+ }+/// Arc's toast at the top right of the page (ShinyToast): Cra's confirmations.func showToast(_ text: String, action: ShinyToast.Action? = nil) {guard let window else { return }diff --git a/Tests/BrowserManagerSupport/AppServices.swift b/Tests/BrowserManagerSupport/AppServices.swiftindex 1a4266a..3e7b85d 100644--- a/Tests/BrowserManagerSupport/AppServices.swift+++ b/Tests/BrowserManagerSupport/AppServices.swift@@ -93,4 +93,5 @@ final class PictureInPictureChrome {/// is what PageEngines and BrowserManager decide on.final class WebKitBrowser: CraBrowser {var isContentFullscreen = false+ var serviceName = ""}diff --git a/docs/protected-media.md b/docs/protected-media.mdindex 28c1b5b..5fb2ee5 100644--- a/docs/protected-media.md+++ b/docs/protected-media.md@@ -76,6 +76,22 @@ Deleting a profile deletes its WebKit store at the next launch, together with itfolder. The user agent is Safari's (`Version/<Safari's version> Safari/605.1.15`), because theservices pick their DRM by browser.+## How Cra tells the user++- **Once per service, a toast**: the first time a service's page shows, "Spotify plays with+ Safari's engine" with a Why? button that opens the Site Control Center. Which services have+ been announced is kept in the `protectedMediaToldServices` default.+- **The Site Control Center**: on a WebKit page, a Protected Media card takes the Extensions+ grid's place. It names the service, says why, and lists what that means here: you sign in once,+ extensions don't run, and Web Inspector opens instead of DevTools. Learn more opens+ crabrowser.app/help/protected-media. The Block Ads & Trackers switch is left out there,+ because Chromium's blocker doesn't see the page.+- **Extension buttons**: pinned extensions in the toolbar, the sidebar's URL field and the+ sidebar's grid dim, and their tooltip says "Extensions don't run on Spotify".++All three follow the page's real engine (`TabNavState.protectedMedia`, from the page), not its+address. A WebKit page signing in on accounts.spotify.com still counts as Spotify's.+## What a WebKit page doesn't have- **Chrome extensions**, including password managers' autofill: those services are signed into