Skip to content

Commit

Permalink
PP-2077, PP-2105, PP-2082 (#502)
Browse files Browse the repository at this point in the history
* Present user settings as popover on iPhone

* remove old R2 references and clean up

* Update adept-ios

* Update AdobeContentProtectionService.swift

* Update AdobeDRMContentProtection.swift

* Update adept-ios

* Update project.pbxproj
  • Loading branch information
mauricecarrier7 authored Jan 31, 2025
1 parent d3a391d commit 0658370
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 242 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/upload-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,8 @@ jobs:
env:
BUILD_CONTEXT: ci

# Set up Python environment and install requests
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Python dependencies
run: |
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install requests
- name: Create release notes
run: |
source .venv/bin/activate
./scripts/create-release-notes.sh
env:
BUILD_CONTEXT: ci
Expand Down
52 changes: 22 additions & 30 deletions Palace.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion Palace.xcodeproj/xcshareddata/xcschemes/Palace.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
disableMainThreadChecker = "YES"
systemAttachmentLifetime = "keepNever"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<MacroExpansion>
Expand All @@ -39,6 +39,18 @@
ReferencedContainer = "container:Palace.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
<AdditionalOption
key = "MallocStackLogging"
value = ""
isEnabled = "YES">
</AdditionalOption>
<AdditionalOption
key = "PrefersMallocStackLoggingLite"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down
4 changes: 2 additions & 2 deletions Palace/AppInfrastructure/TPPRootTabBarController.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@class TPPR2Owner;
@class TPPR3Owner;
@class TPPCatalogNavigationController;

@interface TPPRootTabBarController : UITabBarController
Expand All @@ -10,7 +10,7 @@

+ (instancetype)sharedController;

@property (readonly) TPPR2Owner *r2Owner;
@property (readonly) TPPR3Owner *r3Owner;
@property (nonatomic) BOOL isPresentingSample;
@property(nonatomic, readonly) TPPCatalogNavigationController *catalogNavigationController;

Expand Down
4 changes: 2 additions & 2 deletions Palace/AppInfrastructure/TPPRootTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ @interface TPPRootTabBarController () <UITabBarControllerDelegate>
@property (nonatomic) TPPMyBooksViewController *myBooksNavigationController;
@property (nonatomic) TPPHoldsNavigationController *holdsNavigationController;
@property (nonatomic) TPPSettingsViewController *settingsViewController;
@property (readwrite) TPPR2Owner *r2Owner;
@property (readwrite) TPPR3Owner *r3Owner;

@end

Expand Down Expand Up @@ -55,7 +55,7 @@ - (instancetype)init
name:NSNotification.TPPCurrentAccountDidChange
object:nil];

self.r2Owner = [[TPPR2Owner alloc] init];
self.r3Owner = [[TPPR3Owner alloc] init];
return self;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

@objc extension TPPRootTabBarController {
func presentBook(_ book: TPPBook) {
guard let libraryService = r2Owner?.libraryService, let readerModule = r2Owner?.readerModule else {
guard let libraryService = r3Owner?.libraryService, let readerModule = r3Owner?.readerModule else {
return
}

Expand Down Expand Up @@ -44,7 +44,7 @@ import Foundation
isPresentingSample = false
}

guard let libraryService = r2Owner?.libraryService, let readerModule = r2Owner?.readerModule else {
guard let libraryService = r3Owner?.libraryService, let readerModule = r3Owner?.readerModule else {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ final class AdobeContentProtectionService: ContentProtectionService {
LocalizedString.nonlocalized("Adobe DRM")
}

/// Known technology for this type of Content Protection (Adobe DRM).
var scheme: ContentProtectionScheme {
.adept
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,52 +36,25 @@ final class AdobeDRMContentProtection: ContentProtection, Loggable {
return .failure(.assetNotSupported(DebugError("Invalid source URL")))
}

do {
let decryptor = try AdobeDRMDecryptor(url: sourceURL, encryptionData: encryptionData)
let decryptedContainer = decryptor.drmContainer

guard validateDecryptedContainer(decryptedContainer) else {
return .failure(.assetNotSupported(DebugError("Decrypted container is missing required files.")))
}

let newContainerAsset = ContainerAsset(container: decryptedContainer, format: container.format)
let cpAsset = ContentProtectionAsset(asset: .container(newContainerAsset)) { manifest, _, services in
let copyManifest = manifest

services.setContentProtectionServiceFactory { factory in
AdobeContentProtectionService(
context: PublicationServiceContext(
publication: factory.publication,
manifest: copyManifest,
container: decryptedContainer
)
let decryptedContainer = AdobeDRMContainer(url: sourceURL, encryptionData: encryptionData)

let newContainerAsset = ContainerAsset(container: decryptedContainer, format: container.format)
let cpAsset = ContentProtectionAsset(asset: .container(newContainerAsset)) { manifest, _, services in
let copyManifest = manifest

services.setContentProtectionServiceFactory { factory in
AdobeContentProtectionService(
context: PublicationServiceContext(
publication: factory.publication,
manifest: copyManifest,
container: decryptedContainer
)
}
)
}

return .success(cpAsset)
} catch {
return .failure(.assetNotSupported(error))
}
}
}

private func validateDecryptedContainer(_ container: Container) -> Bool {
let requiredFiles = ["META-INF/container.xml"]

for path in requiredFiles {
guard let urlPath = AnyURL(string: path) else {
log(.error, "Invalid URL for required file path: \(path)")
return false
}

if container[urlPath] == nil {
log(.error, "Missing required file in decrypted container: \(path)")
return false
return .success(cpAsset)
}
}

return true
}
}

Expand Down Expand Up @@ -111,29 +84,6 @@ private extension AdobeDRMContentProtection {

return .failure(DebugError("Invalid encryption.xml path"))
}

final class AdobeDRMDecryptor {
let drmContainer: AdobeDRMContainer

init(url: URL, encryptionData: Data) throws {
self.drmContainer = AdobeDRMContainer(url: url, encryptionData: encryptionData)

if let displayUntilDate = drmContainer.displayUntilDate, displayUntilDate < Date() {
throw AdobeDRMFetcherError.expiredDisplayUntilDate
}
}

func decrypt(_ data: Data, at path: String) -> Data {
let decryptedData = drmContainer.decode(data, at: path)

if let error = drmContainer.epubDecodingError {
Log.debug(#file, "Decryption failed for path \(path): \(error)")
return Data()
}

return decryptedData
}
}
}


Expand Down Expand Up @@ -174,7 +124,7 @@ extension AdobeDRMContainer: Container {
}

private func readDataFromArchive(at path: String) -> Data? {
guard let archive = Archive(url: self.fileURL!, accessMode: .read) else {
guard let fileURL, let archive = try? Archive(url: fileURL, accessMode: .read, pathEncoding: nil) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// AdobeDRMFetcherError.swift
// AdobeDRMError.swift
// Palace
//
// Created by Vladimir Fedorov on 14.10.2021.
Expand All @@ -10,7 +10,7 @@ import Foundation

#if FEATURE_DRM_CONNECTOR

enum AdobeDRMFetcherError: LocalizedError {
enum AdobeDRMError: LocalizedError {

/// Indicates the item license has expired
case expiredDisplayUntilDate
Expand Down

This file was deleted.

22 changes: 1 addition & 21 deletions Palace/Reader2/ReaderStackConfiguration/LibraryService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,9 @@ final class LibraryService: Loggable {

let httpServer: GCDHTTPServer

private lazy var documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

init() {
let httpClient = DefaultHTTPClient()

let resourceFactory = CompositeResourceFactory([
DefaultResourceFactory(httpClient: httpClient)
])

let archiveOpener = CompositeArchiveOpener([
DefaultArchiveOpener()
])

let formatSniffer = CompositeFormatSniffer([
DefaultFormatSniffer()
])

assetRetriever = AssetRetriever(
formatSniffer: formatSniffer,
resourceFactory: resourceFactory,
archiveOpener: archiveOpener
)

assetRetriever = AssetRetriever(httpClient: httpClient)
httpServer = GCDHTTPServer(assetRetriever: assetRetriever)

// DRM configurations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TPPR2Owner.swift
// TPPR3Owner.swift
//
// Created by Mickaël Menu on 20.02.19.
//
Expand All @@ -14,11 +14,11 @@ import UIKit
import ReadiumShared
import ReadiumStreamer

/// This class is the main root of R2 objects. It:
/// This class is the main root of R3 objects. It:
/// - owns the sub-modules (library, reader, etc.)
/// - orchestrates the communication between its sub-modules, through the
/// modules' delegates.
@objc public final class TPPR2Owner: NSObject {
@objc public final class TPPR3Owner: NSObject {

var libraryService: LibraryService! = nil
var readerModule: ReaderModuleAPI! = nil
Expand All @@ -30,16 +30,15 @@ import ReadiumStreamer
resourcesServer: libraryService.httpServer,
bookRegistry: TPPBookRegistry.shared)

// Set Readium 2's logging minimum level.
ReadiumEnableLog(withMinimumSeverityLevel: .debug)
}

deinit {
Log.warn(#file, "TPPR2Owner being dealloced")
Log.warn(#file, "TPPR3Owner being dealloced")
}
}

extension TPPR2Owner: ModuleDelegate {
extension TPPR3Owner: ModuleDelegate {
func presentAlert(_ title: String,
message: String,
from viewController: UIViewController) {
Expand Down
Loading

0 comments on commit 0658370

Please sign in to comment.