Flutter Engine
The Flutter Engine
FlutterRestorationPlugin.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterRestorationPlugin.h"
6
7#import <Foundation/Foundation.h>
8#import <UIKit/UIKit.h>
9
10#include "flutter/fml/logging.h"
11
13
14@interface FlutterRestorationPlugin ()
15@property(nonatomic, copy) FlutterResult pendingRequest;
16@end
17
18@implementation FlutterRestorationPlugin {
19 BOOL _waitForData;
21}
22
23- (instancetype)initWithChannel:(FlutterMethodChannel*)channel
24 restorationEnabled:(BOOL)restorationEnabled {
25 FML_DCHECK(channel) << "channel must be set";
26 self = [super init];
27 if (self) {
28 [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
29 [self handleMethodCall:call result:result];
30 }];
31 _restorationEnabled = restorationEnabled;
32 _waitForData = restorationEnabled;
33 }
34 return self;
35}
36
37- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
38 if ([[call method] isEqualToString:@"put"]) {
39 NSAssert(self.pendingRequest == nil, @"Cannot put data while a get request is pending.");
41 self.restorationData = [data data];
42 result(nil);
43 } else if ([[call method] isEqualToString:@"get"]) {
44 if (!_restorationEnabled || !_waitForData) {
45 result([self dataForFramework]);
46 return;
47 }
48 NSAssert(self.pendingRequest == nil, @"There can only be one pending request.");
49 self.pendingRequest = result;
50 } else {
52 }
53}
54
55- (void)setRestorationData:(NSData*)data {
56 if (data != _restorationData) {
57 _restorationData = [data copy];
58 }
59 _waitForData = NO;
60 if (self.pendingRequest != nil) {
61 self.pendingRequest([self dataForFramework]);
62 self.pendingRequest = nil;
63 }
64}
65
66- (void)markRestorationComplete {
67 _waitForData = NO;
68 if (self.pendingRequest != nil) {
69 NSAssert(_restorationEnabled, @"No request can be pending when restoration is disabled.");
70 self.pendingRequest([self dataForFramework]);
71 self.pendingRequest = nil;
72 }
73}
74
75- (void)reset {
76 self.pendingRequest = nil;
77 self.restorationData = nil;
78}
79
80- (NSDictionary*)dataForFramework {
82 return @{@"enabled" : @NO};
83 }
84 if (self.restorationData == nil) {
85 return @{@"enabled" : @YES};
86 }
87 return @{
88 @"enabled" : @YES,
89 @"data" : [FlutterStandardTypedData typedDataWithBytes:self.restorationData]
90 };
91}
92
93@end
m reset()
void(^ FlutterResult)(id _Nullable result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
BOOL _restorationEnabled
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
GAsyncResult * result
#define FML_DCHECK(condition)
Definition: logging.h:103
void setMethodCallHandler:(FlutterMethodCallHandler _Nullable handler)
instancetype typedDataWithBytes:(NSData *data)
def call(args)
Definition: dom.py:159
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
int BOOL
Definition: windows_types.h:37