blob: dbb04fccccd27f8a2c482c54c3d833d9fd3cd62e [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "FWFPreferencesHostApi.h"
#import "FWFWebViewConfigurationHostApi.h"
@interface FWFPreferencesHostApiImpl ()
@property(nonatomic) FWFInstanceManager *instanceManager;
@end
@implementation FWFPreferencesHostApiImpl
- (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager {
self = [self init];
if (self) {
_instanceManager = instanceManager;
}
return self;
}
- (WKPreferences *)preferencesForIdentifier:(NSNumber *)identifier {
return (WKPreferences *)[self.instanceManager instanceForIdentifier:identifier.longValue];
}
- (void)createWithIdentifier:(nonnull NSNumber *)identifier
error:(FlutterError *_Nullable *_Nonnull)error {
WKPreferences *preferences = [[WKPreferences alloc] init];
[self.instanceManager addDartCreatedInstance:preferences withIdentifier:identifier.longValue];
}
- (void)createFromWebViewConfigurationWithIdentifier:(nonnull NSNumber *)identifier
configurationIdentifier:(nonnull NSNumber *)configurationIdentifier
error:(FlutterError *_Nullable *_Nonnull)error {
WKWebViewConfiguration *configuration = (WKWebViewConfiguration *)[self.instanceManager
instanceForIdentifier:configurationIdentifier.longValue];
[self.instanceManager addDartCreatedInstance:configuration.preferences
withIdentifier:identifier.longValue];
}
- (void)setJavaScriptEnabledForPreferencesWithIdentifier:(nonnull NSNumber *)identifier
isEnabled:(nonnull NSNumber *)enabled
error:(FlutterError *_Nullable *_Nonnull)error {
[[self preferencesForIdentifier:identifier] setJavaScriptEnabled:enabled.boolValue];
}
@end