Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX-625][iOS] hotpatch jsframework && support JSFrameworkLoadProtoc…
Browse files Browse the repository at this point in the history
…ol (#1546)
  • Loading branch information
doumafang authored and cxfeng1 committed Sep 20, 2018
1 parent 5996ca5 commit b1f1dfd
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 21 deletions.
18 changes: 18 additions & 0 deletions ios/sdk/WeexSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
2AFEB17C1C747139000507FA /* WXInstanceWrap.m in Sources */ = {isa = PBXBuildFile; fileRef = 2AFEB17A1C747139000507FA /* WXInstanceWrap.m */; };
333D9A271F41507A007CED39 /* WXTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 333D9A251F41507A007CED39 /* WXTransition.h */; };
333D9A2A1F41507A007CED39 /* WXTransition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 333D9A261F41507A007CED39 /* WXTransition.mm */; };
33CE190E2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 33CE190C2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h */; };
33CE190F2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 33CE190C2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h */; };
33CE19102153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CE190D2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m */; };
33CE19112153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 33CE190D2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m */; };
33CE19132153444900CF9670 /* WXJSFrameworkLoadProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 33CE19122153444900CF9670 /* WXJSFrameworkLoadProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
33CE19142153444900CF9670 /* WXJSFrameworkLoadProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 33CE19122153444900CF9670 /* WXJSFrameworkLoadProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
37B51EE41E97804D0040A743 /* WXCycleSliderComponent.h in Headers */ = {isa = PBXBuildFile; fileRef = 37B51EE21E97804D0040A743 /* WXCycleSliderComponent.h */; };
37B51EE51E97804D0040A743 /* WXCycleSliderComponent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37B51EE31E97804D0040A743 /* WXCycleSliderComponent.mm */; };
4532670A213FC84A00DAA620 /* WXDisplayLinkManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 45326708213FC84900DAA620 /* WXDisplayLinkManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -1060,6 +1066,9 @@
2AFEB17A1C747139000507FA /* WXInstanceWrap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXInstanceWrap.m; sourceTree = "<group>"; };
333D9A251F41507A007CED39 /* WXTransition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXTransition.h; sourceTree = "<group>"; };
333D9A261F41507A007CED39 /* WXTransition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WXTransition.mm; sourceTree = "<group>"; };
33CE190C2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXJSFrameworkLoadDefaultImpl.h; sourceTree = "<group>"; };
33CE190D2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXJSFrameworkLoadDefaultImpl.m; sourceTree = "<group>"; };
33CE19122153444900CF9670 /* WXJSFrameworkLoadProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXJSFrameworkLoadProtocol.h; sourceTree = "<group>"; };
37B51EE21E97804D0040A743 /* WXCycleSliderComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXCycleSliderComponent.h; sourceTree = "<group>"; };
37B51EE31E97804D0040A743 /* WXCycleSliderComponent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WXCycleSliderComponent.mm; sourceTree = "<group>"; };
45326708213FC84900DAA620 /* WXDisplayLinkManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXDisplayLinkManager.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1608,6 +1617,8 @@
59A583031CF5B2FD0081FD3E /* Handler */ = {
isa = PBXGroup;
children = (
33CE190C2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h */,
33CE190D2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m */,
59A583041CF5B2FD0081FD3E /* WXNavigationDefaultImpl.h */,
59A583051CF5B2FD0081FD3E /* WXNavigationDefaultImpl.m */,
74EF31AB1DE58BE200667A07 /* WXURLRewriteDefaultImpl.h */,
Expand Down Expand Up @@ -1969,6 +1980,7 @@
77D1611C1C02DD3C0010B15B /* Protocol */ = {
isa = PBXGroup;
children = (
33CE19122153444900CF9670 /* WXJSFrameworkLoadProtocol.h */,
17036A5220FDE7490029AE3D /* WXApmProtocol.h */,
17C74F0E2072147A00AB4CAB /* WXAnalyzerProtocol.h */,
59A596171CB630E50012CD52 /* WXNavigationProtocol.h */,
Expand Down Expand Up @@ -2717,6 +2729,7 @@
1746EA7320E9D253007E55BD /* WXComponent_performance.h in Headers */,
59A596221CB6311F0012CD52 /* WXNavigatorModule.h in Headers */,
B8F2C7082133A83C00635B37 /* rax_parser_context.h in Headers */,
33CE190E2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h in Headers */,
C47B78CE1F2998EE001D3B0C /* WXExtendCallNativeManager.h in Headers */,
B8D66CA321255730003960BD /* wson.h in Headers */,
749DC27B1D40827B009E1C91 /* WXMonitor.h in Headers */,
Expand All @@ -2742,6 +2755,7 @@
59A596191CB630E50012CD52 /* WXNavigationProtocol.h in Headers */,
B8D66CBF21255730003960BD /* LogDefines.h in Headers */,
59A5962F1CB632050012CD52 /* WXBaseViewController.h in Headers */,
33CE19132153444900CF9670 /* WXJSFrameworkLoadProtocol.h in Headers */,
B8F2C7142133A8BC00635B37 /* vm_monitor.h in Headers */,
B8D66C012125572F003960BD /* constants_value.h in Headers */,
74AD99841D5B0E59008F0336 /* WXPolyfillSet.h in Headers */,
Expand Down Expand Up @@ -3064,6 +3078,7 @@
B8D66CD021255730003960BD /* waitable_event.h in Headers */,
DCA4461E1EFA5AAF00D0CFA8 /* WXComponentFactory.h in Headers */,
B8D66CB621255730003960BD /* ViewUtils.h in Headers */,
33CE190F2153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.h in Headers */,
DCA445F41EFA5A2800D0CFA8 /* WXNavigationDefaultImpl.h in Headers */,
B8D66C9421255730003960BD /* dom_wson.h in Headers */,
DCA445E51EFA59E100D0CFA8 /* WXDivComponent.h in Headers */,
Expand Down Expand Up @@ -3116,6 +3131,7 @@
DCA445DC1EFA59AD00D0CFA8 /* WXRecyclerDataController.h in Headers */,
DCA446191EFA5A9E00D0CFA8 /* WXServiceFactory.h in Headers */,
DCA446121EFA5A8A00D0CFA8 /* WXComponentMethod.h in Headers */,
33CE19142153444900CF9670 /* WXJSFrameworkLoadProtocol.h in Headers */,
B8D66CD821255730003960BD /* CoreConstants.h in Headers */,
B8D66C1021255730003960BD /* core_side_in_platform.h in Headers */,
B8D66CCE21255730003960BD /* thread.h in Headers */,
Expand Down Expand Up @@ -3443,6 +3459,7 @@
B8F2C7042133A83C00635B37 /* class_array.cc in Sources */,
74862F7A1E02B88D00B7A041 /* JSValue+Weex.m in Sources */,
B8D66BC52125572F003960BD /* tokenizer.cc in Sources */,
33CE19102153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m in Sources */,
B8D66C7321255730003960BD /* render_list.cpp in Sources */,
B8D66BC92125572F003960BD /* ast.cc in Sources */,
740451EB1E14BB26004157CB /* WXServiceFactory.m in Sources */,
Expand Down Expand Up @@ -3710,6 +3727,7 @@
B8F2C7072133A83C00635B37 /* rax_parser_scope.cc in Sources */,
DCA4455C1EFA55B300D0CFA8 /* WXCanvasComponent.m in Sources */,
DCA4455D1EFA55B300D0CFA8 /* WXHeaderComponent.mm in Sources */,
33CE19112153443000CF9670 /* WXJSFrameworkLoadDefaultImpl.m in Sources */,
1771795821416DF1006F39A9 /* WXApmForInstance.m in Sources */,
B8D66C6021255730003960BD /* render_action_render_success.cpp in Sources */,
DCA4455E1EFA55B300D0CFA8 /* WXFooterComponent.m in Sources */,
Expand Down
39 changes: 19 additions & 20 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#import "WXSDKInstance_performance.h"
#import "JSContext+Weex.h"
#import "WXCoreBridge.h"
#import "WXJSFrameworkLoadProtocol.h"
#import "WXJSFrameworkLoadDefaultImpl.h"
#import "WXHandlerFactory.h"

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
Expand Down Expand Up @@ -418,7 +421,6 @@ - (void)createInstance:(NSString *)instanceIdString
WX_MONITOR_INSTANCE_PERF_START(WXFirstScreenJSFExecuteTime, [WXSDKManager instanceForID:instanceIdString]);
WX_MONITOR_INSTANCE_PERF_START(WXPTJSCreateInstance, [WXSDKManager instanceForID:instanceIdString]);
BOOL shoudMultiContext = [WXSDKManager sharedInstance].multiContext;
__weak typeof(self) weakSelf = self;
NSString * bundleType = nil;

if (shoudMultiContext) {
Expand All @@ -432,20 +434,18 @@ - (void)createInstance:(NSString *)instanceIdString
}
[newOptions addEntriesFromDictionary:@{@"env":[WXUtility getEnvironment]}];
newOptions[@"bundleType"] = bundleType;
NSString *raxAPIScript = nil;
NSString *raxAPIScriptPath = nil;
__block NSString *raxAPIScript = nil;
__block NSString *raxAPIScriptPath = nil;
id<WXJSFrameworkLoadProtocol> handler = [WXHandlerFactory handlerForProtocol:@protocol(WXJSFrameworkLoadProtocol)];
sdkInstance.bundleType = bundleType;
if ([bundleType.lowercaseString isEqualToString:@"rax"]) {
raxAPIScriptPath = [[NSBundle bundleForClass:[weakSelf class]] pathForResource:@"weex-rax-api" ofType:@"js"];
if (raxAPIScriptPath == nil) {
raxAPIScriptPath = [[NSBundle mainBundle] pathForResource:@"weex-rax-api" ofType:@"js"];
}
raxAPIScript = [NSString stringWithContentsOfFile:raxAPIScriptPath encoding:NSUTF8StringEncoding error:nil];
if (!raxAPIScript) {
WXLogError(@"weex-rax-api can not found");
if (handler && [handler respondsToSelector:@selector(loadRaxFramework:)]) {
[handler loadRaxFramework:^(NSString *path, NSString *script) {
raxAPIScriptPath = path;
raxAPIScript = script;
}];
}
}

if ([WXDebugTool isDevToolDebug]) {
[self callJSMethod:@"createInstanceContext" args:@[instanceIdString, newOptions, data?:@[],raxAPIScript?:@""]];

Expand Down Expand Up @@ -481,15 +481,14 @@ - (void)createInstance:(NSString *)instanceIdString
}

if (WX_SYS_VERSION_LESS_THAN(@"10.2")) {
NSString *filePath = [[NSBundle bundleForClass:[weakSelf class]] pathForResource:@"weex-polyfill" ofType:@"js"];
if (filePath == nil) {
filePath = [[NSBundle mainBundle] pathForResource:@"weex-polyfill" ofType:@"js"];
}
NSString *script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
if (script) {
[sdkInstance.instanceJavaScriptContext executeJavascript:script withSourceURL:[NSURL URLWithString:filePath]];
} else {
WXLogError(@"weex-pollyfill can not found");
if (handler && [handler respondsToSelector:@selector(loadPolyfillFramework:)]) {
[handler loadPolyfillFramework:^(NSString *path, NSString *script) {
if (script) {
[sdkInstance.instanceJavaScriptContext executeJavascript:script withSourceURL:[NSURL URLWithString:path]];
} else {
WXLogError(@"weex-pollyfill can not found");
}
}];
}
}

Expand Down
3 changes: 2 additions & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "WXResourceRequestHandlerDefaultImpl.h"
#import "WXNavigationDefaultImpl.h"
#import "WXURLRewriteDefaultImpl.h"
#import "WXJSFrameworkLoadDefaultImpl.h"

#import "WXSDKManager.h"
#import "WXSDKError.h"
Expand Down Expand Up @@ -175,7 +176,7 @@ + (void)_registerDefaultHandlers
[self registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)];
[self registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)];
[self registerHandler:[WXURLRewriteDefaultImpl new] withProtocol:@protocol(WXURLRewriteProtocol)];

[self registerHandler:[WXJSFrameworkLoadDefaultImpl new] withProtocol:@protocol(WXJSFrameworkLoadProtocol)];
}

+ (void)registerHandler:(id)handler withProtocol:(Protocol *)protocol
Expand Down
26 changes: 26 additions & 0 deletions ios/sdk/WeexSDK/Sources/Handler/WXJSFrameworkLoadDefaultImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>
#import "WXJSFrameworkLoadProtocol.h"

@interface WXJSFrameworkLoadDefaultImpl : NSObject <WXJSFrameworkLoadProtocol>


@end
53 changes: 53 additions & 0 deletions ios/sdk/WeexSDK/Sources/Handler/WXJSFrameworkLoadDefaultImpl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#import "WXJSFrameworkLoadDefaultImpl.h"
#import "WXLog.h"

@interface WXJSFrameworkLoadDefaultImpl()
@end

@implementation WXJSFrameworkLoadDefaultImpl

- (void)loadRaxFramework:(WXJSFrameworkLoadBlock)block
{
[self loadJSFramework:@"weex-rax-api" block:block];
}

- (void)loadPolyfillFramework:(WXJSFrameworkLoadBlock)block
{
[self loadJSFramework:@"weex-polyfill" block:block];
}

- (void)loadJSFramework:(NSString *)name block:(WXJSFrameworkLoadBlock)block
{
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:name ofType:@"js"];
if (path == nil) {
path = [[NSBundle mainBundle] pathForResource:name ofType:@"js"];
}
NSString *script = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
if (!script) {
WXLogError(@"%@ js can not found",name);
}
if (block) {
block(path, script);
}
}

@end
18 changes: 18 additions & 0 deletions ios/sdk/WeexSDK/Sources/Protocol/WXApmProtocol.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

Expand Down
29 changes: 29 additions & 0 deletions ios/sdk/WeexSDK/Sources/Protocol/WXJSFrameworkLoadProtocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#import <Foundation/Foundation.h>

typedef void (^WXJSFrameworkLoadBlock)(NSString *path, NSString *script);

@protocol WXJSFrameworkLoadProtocol <NSObject>

- (void)loadRaxFramework:(WXJSFrameworkLoadBlock)block;
- (void)loadPolyfillFramework:(WXJSFrameworkLoadBlock)block;

@end
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/WeexSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#import "WXModalUIModule.h"
#import "WXLog.h"
#import "WXListComponent.h"
#import "WXJSFrameworkLoadProtocol.h"
#import "WXJSExceptionProtocol.h"
#import "WXJSExceptionInfo.h"
#import "WXIndicatorComponent.h"
Expand Down

0 comments on commit b1f1dfd

Please sign in to comment.