//
//  SBRProcessBundleBridge.h
//  SBrowser
//
//  Created by James Magahern on 7/22/20.
//

#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN

@protocol SBRResourceOriginPolicyDataSource <NSObject>

/// Returns a list of origins (e.g., "buzzert.net") for which we are allowed to load script resources from
- (NSSet<NSString *> *)allowedOriginsForScriptResources;

/// Returns a mapping between origin and SBRScriptOriginPolicyType, encoded as an NSNumber. 
- (NSDictionary<NSString *, NSNumber *> *)scriptPolicyTypeByOrigin;

@end

@class SBRProcessBundleBridge;
@protocol SBRProcessBundleBridgeDelegate <NSObject>
- (void)webProcess:(SBRProcessBundleBridge *)bridge didAllowScriptResourceFromOrigin:(NSString *)origin;
- (void)webProcess:(SBRProcessBundleBridge *)bridge didBlockScriptResourceFromOrigin:(NSString *)origin;
@end

NS_SWIFT_NAME(ProcessBundleBridge)
@interface SBRProcessBundleBridge : NSObject

@property (nonatomic, readonly) WKWebView *webView;

@property (nonatomic, weak) id<SBRProcessBundleBridgeDelegate> delegate;
@property (nonatomic, strong) id<SBRResourceOriginPolicyDataSource> policyDataSource;
@property (nonatomic, assign) BOOL allowAllScripts; // default is NO
@property (nonatomic, assign) BOOL darkModeEnabled;

- (instancetype)initWithWebViewConfiguration:(nullable WKWebViewConfiguration *)webViewConfiguration NS_DESIGNATED_INITIALIZER;

- (void)policyDataSourceDidChange;
- (void)tearDown;

- (void)parseDocumentForReaderMode:(void(^)(NSString *))completionBlock NS_SWIFT_NAME(parseDocumentForReaderMode(completion:));

- (void)reloadCustomizedUserScriptsAndStylesheets;

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
