You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/09/21 08:09:44 UTC
[01/12] incubator-weex git commit: * [ios] fix transition filter
crash bug
Repository: incubator-weex
Updated Branches:
refs/heads/0.16-dev 5c90b13a7 -> b7631a359
* [ios] fix transition filter crash bug
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/6c4ca522
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/6c4ca522
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/6c4ca522
Branch: refs/heads/0.16-dev
Commit: 6c4ca5227956fef24fb31af2510e885371bf0f41
Parents: e52d273
Author: doumafang <do...@gmail.com>
Authored: Mon Sep 18 11:31:16 2017 +0800
Committer: doumafang <do...@gmail.com>
Committed: Mon Sep 18 11:31:16 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6c4ca522/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
index 55784b3..c53d5f1 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m
@@ -436,12 +436,11 @@ static css_node_t * rootNodeGetChild(void *context, int i)
NSMutableDictionary *normalStyles = [NSMutableDictionary new];
NSMutableArray *resetStyles = [NSMutableArray new];
[self filterStyles:styles normalStyles:normalStyles resetStyles:resetStyles];
-
- [component _updateStylesOnMainThread:normalStyles resetStyles:resetStyles];
+ [component _updateStylesOnMainThread:[normalStyles copy] resetStyles:resetStyles];
[component readyToRender];
WXPerformBlockOnComponentThread(^{
- [component _updateStylesOnComponentThread:normalStyles resetStyles:resetStyles isUpdateStyles:isUpdateStyles];
+ [component _updateStylesOnComponentThread:[normalStyles copy] resetStyles:resetStyles isUpdateStyles:isUpdateStyles];
});
}
[07/12] incubator-weex git commit: * [ios] adjust set opacity location
Posted by ac...@apache.org.
* [ios] adjust set opacity location
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/6404b4ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/6404b4ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/6404b4ca
Branch: refs/heads/0.16-dev
Commit: 6404b4cad742cb0d570483fedb25d6295c2b7b73
Parents: 82f468f
Author: acton393 <zh...@gmail.com>
Authored: Tue Sep 19 15:23:01 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Sep 19 15:23:01 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/6404b4ca/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
index 49a90db..52af2ba 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
+++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
@@ -331,14 +331,13 @@
WXRadii *radii = borderRect.radii;
CGFloat topLeft = radii.topLeft, topRight = radii.topRight, bottomLeft = radii.bottomLeft, bottomRight = radii.bottomRight;
+ CGContextSetAlpha(context, _opacity);
// fill background color
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
- CGContextSetAlpha(context, _opacity);
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
[bezierPath fill];
}
-
// Top
if (_borderTopWidth > 0) {
if(_borderTopStyle == WXBorderStyleDashed || _borderTopStyle == WXBorderStyleDotted){
[04/12] incubator-weex git commit: Merge branch '0.16-dev' of
https://git-wip-us.apache.org/repos/asf/incubator-weex into 0.16-dev
Posted by ac...@apache.org.
Merge branch '0.16-dev' of https://git-wip-us.apache.org/repos/asf/incubator-weex into 0.16-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/2398a750
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/2398a750
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/2398a750
Branch: refs/heads/0.16-dev
Commit: 2398a7502952288379c18ffec450d52ebfe1f285
Parents: 7be6c54 e52d273
Author: acton393 <zh...@gmail.com>
Authored: Mon Sep 18 22:37:55 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Sep 18 22:37:55 2017 +0800
----------------------------------------------------------------------
android/build.gradle | 13 +-
android/gradle.properties | 5 +-
.../gradle/wrapper/gradle-wrapper.properties | 2 +-
android/jacoco.gradle | 43 ++++++
.../alibaba/weex/benchmark/BenchmarkTest.java | 29 ++--
.../playground/app/src/main/AndroidManifest.xml | 8 +
.../alibaba/weex/util/CoverageDataDumper.java | 36 +++++
.../alibaba/weex/util/JacocoCodeCoverage.java | 93 ++++++++++++
android/sdk/libs/armeabi/libweexjsb.so | Bin 0 -> 22556 bytes
android/sdk/libs/armeabi/libweexjsc.so | Bin 7570392 -> 325660 bytes
android/sdk/libs/armeabi/libweexjss.so | Bin 0 -> 6754016 bytes
.../java/com/taobao/weex/WXEnvironment.java | 16 ++
.../java/com/taobao/weex/WXSDKInstance.java | 110 ++++++++------
.../weex/appfram/pickers/DatePickerImpl.java | 3 +-
.../appfram/websocket/WebSocketCloseCodes.java | 2 +-
.../com/taobao/weex/bridge/WXBridgeManager.java | 48 +++++-
.../java/com/taobao/weex/bridge/WXParams.java | 9 ++
.../java/com/taobao/weex/common/Constants.java | 2 +
.../java/com/taobao/weex/common/WXConfig.java | 1 +
.../com/taobao/weex/dom/ImmutableDomObject.java | 21 ++-
.../main/java/com/taobao/weex/dom/WXStyle.java | 17 ---
.../com/taobao/weex/dom/action/Actions.java | 4 +-
.../weex/dom/action/ReloadPageAction.java | 6 +-
.../taobao/weex/ui/component/WXComponent.java | 143 +++++++++++++-----
.../com/taobao/weex/ui/component/WXDiv.java | 74 +++++++++-
.../com/taobao/weex/ui/component/WXSlider.java | 4 +-
.../com/taobao/weex/ui/component/WXText.java | 65 +++++----
.../taobao/weex/ui/component/WXVContainer.java | 44 ++++--
.../taobao/weex/ui/component/list/WXCell.java | 63 +++++++-
.../weex/ui/component/list/WXListComponent.java | 90 ++++++------
.../com/taobao/weex/ui/flat/FlatComponent.java | 33 +++++
.../com/taobao/weex/ui/flat/FlatGUIContext.java | 146 +++++++++++++++++++
.../taobao/weex/ui/flat/WidgetContainer.java | 93 ++++++++++++
.../weex/ui/flat/widget/AndroidViewWidget.java | 76 ++++++++++
.../taobao/weex/ui/flat/widget/BaseWidget.java | 130 +++++++++++++++++
.../taobao/weex/ui/flat/widget/TextWidget.java | 49 +++++++
.../com/taobao/weex/ui/flat/widget/Widget.java | 51 +++++++
.../taobao/weex/ui/flat/widget/WidgetGroup.java | 54 +++++++
.../taobao/weex/ui/module/WXTimerModule.java | 9 +-
.../com/taobao/weex/ui/view/WXFrameLayout.java | 53 ++++++-
.../weex/ui/view/border/BorderCorner.java | 37 +++--
.../taobao/weex/ui/view/border/BorderUtil.java | 26 ----
.../weex/ui/view/border/BottomLeftCorner.java | 7 +-
.../weex/ui/view/border/BottomRightCorner.java | 7 +-
.../weex/ui/view/border/TopLeftCorner.java | 7 +-
.../weex/ui/view/border/TopRightCorner.java | 7 +-
.../com/taobao/weex/utils/FunctionParser.java | 6 -
.../java/com/taobao/weex/utils/OsVersion.java | 2 +-
.../main/java/com/taobao/weex/utils/Trace.java | 4 +-
.../java/com/taobao/weex/utils/WXViewUtils.java | 31 ++++
.../com/taobao/weex/ui/component/WXDivTest.java | 12 +-
.../taobao/weex/ui/component/WXTextTest.java | 18 +--
.../weex/ui/module/WXTimerModuleTest.java | 45 +++++-
dangerfile.js | 4 +-
.../WeexSDK/Sources/Bridge/WXBridgeContext.m | 4 +-
.../Component/Recycler/WXMultiColumnLayout.m | 32 ++--
.../Sources/Component/WXComponent_internal.h | 3 +-
.../WeexSDK/Sources/Component/WXEditComponent.m | 4 +-
.../Sources/Component/WXImageComponent.m | 34 ++++-
.../WeexSDK/Sources/Component/WXTextComponent.m | 6 +-
.../WeexSDK/Sources/Events/WXComponent+Events.m | 35 +++--
.../Sources/Manager/WXComponentManager.m | 1 +
.../WeexSDK/Sources/Manager/WXTracingManager.h | 5 +
.../WeexSDK/Sources/Manager/WXTracingManager.m | 11 ++
ios/sdk/WeexSDK/Sources/Model/WXComponent.m | 37 ++++-
ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 4 +
.../WeexSDK/Sources/Module/WXModalUIModule.m | 4 +-
.../WeexSDK/Sources/Module/WXPrerenderManager.m | 50 +++++--
ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.h | 1 +
ios/sdk/WeexSDK/Sources/Monitor/WXMonitor.m | 1 +
.../Sources/Protocol/WXAppMonitorProtocol.h | 1 +
ios/sdk/WeexSDK/Sources/Utility/WXConvert.m | 24 ++-
ios/sdk/WeexSDK/Sources/Utility/WXUtility.m | 4 +
scripts/build_from_source.sh | 2 +-
test/pages/components/textarea-placeholder.vue | 62 ++++++++
test/pages/include/navbar.vue | 121 +++++++++++++++
test/pages/include/navpage.vue | 62 ++++++++
test/pages/modules/modal-event.vue | 2 +-
test/pages/modules/navigator-event.vue | 101 +++++++++++++
test/pages/modules/picker-event.vue | 6 +-
test/pages/modules/viewport-basic.vue | 62 ++++++++
test/pages/modules/vue_timer.vue | 14 +-
test/pages/modules/we_timer.we | 14 +-
test/run.sh | 25 +++-
test/screenshot/border-android.png | Bin 158634 -> 162929 bytes
test/screenshot/border-ios.png | Bin 126185 -> 128088 bytes
test/screenshot/compositing-ios.png | Bin 228306 -> 229534 bytes
test/screenshot/image-resize-android.png | Bin 214440 -> 218804 bytes
test/screenshot/image-resize-ios.png | Bin 138033 -> 138103 bytes
.../components/textarea-placeholder.test.js | 69 +++++++++
test/scripts/modules/navigator-event.test.js | 51 +++++++
test/scripts/modules/picker-event.test.js | 4 +-
test/scripts/modules/viewport-basic.test.js | 45 ++++++
test/scripts/util.js | 37 +++++
94 files changed, 2381 insertions(+), 415 deletions(-)
----------------------------------------------------------------------
[10/12] incubator-weex git commit: Merge branch
'ios-bugfix-single-border-radius-conflict' of
https://github.com/acton393/incubator-weex into wip-us-0.16-dev
Posted by ac...@apache.org.
Merge branch 'ios-bugfix-single-border-radius-conflict' of https://github.com/acton393/incubator-weex into wip-us-0.16-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/436e4090
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/436e4090
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/436e4090
Branch: refs/heads/0.16-dev
Commit: 436e4090ac9d4a45b63153bc8309ab18ac724809
Parents: 2252798 335e7ae
Author: acton393 <zh...@gmail.com>
Authored: Thu Sep 21 15:59:33 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Sep 21 15:59:33 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 4 ----
ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m | 2 +-
2 files changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------
[02/12] incubator-weex git commit: * [ios] remove socketRocket
dependency
Posted by ac...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/dependency/SRWebSocket.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/dependency/SRWebSocket.m b/ios/sdk/WeexSDK/dependency/SRWebSocket.m
deleted file mode 100644
index 03ad557..0000000
--- a/ios/sdk/WeexSDK/dependency/SRWebSocket.m
+++ /dev/null
@@ -1,1806 +0,0 @@
-//
-// Copyright 2012 Square Inc.
-// Portions Copyright (c) 2016-present, Facebook, Inc.
-//
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
-//
-
-#import "SRWebSocket.h"
-
-#if TARGET_OS_IPHONE
-#define HAS_ICU
-#endif
-
-#ifdef HAS_ICU
-#import <unicode/utf8.h>
-#endif
-
-#if TARGET_OS_IPHONE
-#import <Endian.h>
-#else
-#import <CoreServices/CoreServices.h>
-#endif
-
-#import <CommonCrypto/CommonDigest.h>
-#import <Security/SecRandom.h>
-
-#if OS_OBJECT_USE_OBJC_RETAIN_RELEASE
-#define sr_dispatch_retain(x)
-#define sr_dispatch_release(x)
-#define maybe_bridge(x) ((__bridge void *) x)
-#else
-#define sr_dispatch_retain(x) dispatch_retain(x)
-#define sr_dispatch_release(x) dispatch_release(x)
-#define maybe_bridge(x) (x)
-#endif
-
-#if !__has_feature(objc_arc)
-#error SocketRocket must be compiled with ARC enabled
-#endif
-
-
-typedef enum {
- SROpCodeTextFrame = 0x1,
- SROpCodeBinaryFrame = 0x2,
- // 3-7 reserved.
- SROpCodeConnectionClose = 0x8,
- SROpCodePing = 0x9,
- SROpCodePong = 0xA,
- // B-F reserved.
-} SROpCode;
-
-typedef struct {
- BOOL fin;
-// BOOL rsv1;
-// BOOL rsv2;
-// BOOL rsv3;
- uint8_t opcode;
- BOOL masked;
- uint64_t payload_length;
-} frame_header;
-
-static NSString *const SRWebSocketAppendToSecKeyString = @"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
-
-static inline int32_t validate_dispatch_data_partial_string(NSData *data);
-static inline void SRFastLog(NSString *format, ...);
-
-@interface NSData (SRWebSocket)
-
-- (NSString *)stringBySHA1ThenBase64Encoding;
-
-@end
-
-
-@interface NSString (SRWebSocket)
-
-- (NSString *)stringBySHA1ThenBase64Encoding;
-
-@end
-
-
-@interface NSURL (SRWebSocket)
-
-// The origin isn't really applicable for a native application.
-// So instead, just map ws -> http and wss -> https.
-- (NSString *)SR_origin;
-
-@end
-
-
-@interface _SRRunLoopThread : NSThread
-
-@property (nonatomic, readonly) NSRunLoop *runLoop;
-
-@end
-
-
-static NSString *newSHA1String(const char *bytes, size_t length) {
- uint8_t md[CC_SHA1_DIGEST_LENGTH];
-
- assert(length >= 0);
- assert(length <= UINT32_MAX);
- CC_SHA1(bytes, (CC_LONG)length, md);
-
- NSData *data = [NSData dataWithBytes:md length:CC_SHA1_DIGEST_LENGTH];
-
- if ([data respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
- return [data base64EncodedStringWithOptions:0];
- }
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- return [data base64Encoding];
-#pragma clang diagnostic pop
-}
-
-@implementation NSData (SRWebSocket)
-
-- (NSString *)stringBySHA1ThenBase64Encoding;
-{
- return newSHA1String(self.bytes, self.length);
-}
-
-@end
-
-
-@implementation NSString (SRWebSocket)
-
-- (NSString *)stringBySHA1ThenBase64Encoding;
-{
- return newSHA1String(self.UTF8String, self.length);
-}
-
-@end
-
-NSString *const SRWebSocketErrorDomain = @"SRWebSocketErrorDomain";
-NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
-
-// Returns number of bytes consumed. Returning 0 means you didn't match.
-// Sends bytes to callback handler;
-typedef size_t (^stream_scanner)(NSData *collected_data);
-
-typedef void (^data_callback)(SRWebSocket *webSocket, NSData *data);
-
-@interface SRIOConsumer : NSObject {
- stream_scanner _scanner;
- data_callback _handler;
- size_t _bytesNeeded;
- BOOL _readToCurrentFrame;
- BOOL _unmaskBytes;
-}
-@property (nonatomic, copy, readonly) stream_scanner consumer;
-@property (nonatomic, copy, readonly) data_callback handler;
-@property (nonatomic, assign) size_t bytesNeeded;
-@property (nonatomic, assign, readonly) BOOL readToCurrentFrame;
-@property (nonatomic, assign, readonly) BOOL unmaskBytes;
-
-@end
-
-// This class is not thread-safe, and is expected to always be run on the same queue.
-@interface SRIOConsumerPool : NSObject
-
-- (id)initWithBufferCapacity:(NSUInteger)poolSize;
-
-- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
-- (void)returnConsumer:(SRIOConsumer *)consumer;
-
-@end
-
-@interface SRWebSocket () <NSStreamDelegate>
-
-@property (nonatomic) SRReadyState readyState;
-
-@property (nonatomic) NSOperationQueue *delegateOperationQueue;
-@property (nonatomic) dispatch_queue_t delegateDispatchQueue;
-
-// Specifies whether SSL trust chain should NOT be evaluated.
-// By default this flag is set to NO, meaning only secure SSL connections are allowed.
-// For DEBUG builds this flag is ignored, and SSL connections are allowed regardless
-// of the certificate trust configuration
-@property (nonatomic, readwrite) BOOL allowsUntrustedSSLCertificates;
-
-@end
-
-
-@implementation SRWebSocket {
- NSInteger _webSocketVersion;
-
- NSOperationQueue *_delegateOperationQueue;
- dispatch_queue_t _delegateDispatchQueue;
-
- dispatch_queue_t _workQueue;
- NSMutableArray *_consumers;
-
- NSInputStream *_inputStream;
- NSOutputStream *_outputStream;
-
- NSMutableData *_readBuffer;
- NSUInteger _readBufferOffset;
-
- NSMutableData *_outputBuffer;
- NSUInteger _outputBufferOffset;
-
- uint8_t _currentFrameOpcode;
- size_t _currentFrameCount;
- size_t _readOpCount;
- uint32_t _currentStringScanPosition;
- NSMutableData *_currentFrameData;
-
- NSString *_closeReason;
-
- NSString *_secKey;
- NSString *_basicAuthorizationString;
-
- BOOL _pinnedCertFound;
-
- uint8_t _currentReadMaskKey[4];
- size_t _currentReadMaskOffset;
-
- BOOL _consumerStopped;
-
- BOOL _closeWhenFinishedWriting;
- BOOL _failed;
-
- BOOL _secure;
- NSURLRequest *_urlRequest;
-
- BOOL _sentClose;
- BOOL _didFail;
- int _closeCode;
-
- BOOL _isPumping;
-
- NSMutableSet *_scheduledRunloops;
-
- // We use this to retain ourselves.
- __strong SRWebSocket *_selfRetain;
-
- NSArray *_requestedProtocols;
- SRIOConsumerPool *_consumerPool;
-}
-
-@synthesize delegate = _delegate;
-@synthesize url = _url;
-@synthesize readyState = _readyState;
-@synthesize protocol = _protocol;
-
-static __strong NSData *CRLFCRLF;
-
-+ (void)initialize;
-{
- CRLFCRLF = [[NSData alloc] initWithBytes:"\r\n\r\n" length:4];
-}
-
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-{
- self = [super init];
- if (self) {
- assert(request.URL);
- _url = request.URL;
- _urlRequest = request;
- _allowsUntrustedSSLCertificates = allowsUntrustedSSLCertificates;
-
- _requestedProtocols = [protocols copy];
-
- [self _SR_commonInit];
- }
-
- return self;
-}
-
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
-{
- return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:NO];
-}
-
-- (id)initWithURLRequest:(NSURLRequest *)request;
-{
- return [self initWithURLRequest:request protocols:nil];
-}
-
-- (id)initWithURL:(NSURL *)url;
-{
- return [self initWithURL:url protocols:nil];
-}
-
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
-{
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
- return [self initWithURLRequest:request protocols:protocols];
-}
-
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-{
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
- return [self initWithURLRequest:request protocols:protocols allowsUntrustedSSLCertificates:allowsUntrustedSSLCertificates];
-}
-
-- (void)_SR_commonInit;
-{
- NSString *scheme = _url.scheme.lowercaseString;
- assert([scheme isEqualToString:@"ws"] || [scheme isEqualToString:@"http"] || [scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]);
-
- if ([scheme isEqualToString:@"wss"] || [scheme isEqualToString:@"https"]) {
- _secure = YES;
- }
-
- _readyState = SR_CONNECTING;
- _consumerStopped = YES;
- _webSocketVersion = 13;
-
- _workQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
-
- // Going to set a specific on the queue so we can validate we're on the work queue
- dispatch_queue_set_specific(_workQueue, (__bridge void *)self, maybe_bridge(_workQueue), NULL);
-
- _delegateDispatchQueue = dispatch_get_main_queue();
- sr_dispatch_retain(_delegateDispatchQueue);
-
- _readBuffer = [[NSMutableData alloc] init];
- _outputBuffer = [[NSMutableData alloc] init];
-
- _currentFrameData = [[NSMutableData alloc] init];
-
- _consumers = [[NSMutableArray alloc] init];
-
- _consumerPool = [[SRIOConsumerPool alloc] init];
-
- _scheduledRunloops = [[NSMutableSet alloc] init];
-
- [self _initializeStreams];
-
- // default handlers
-}
-
-- (void)assertOnWorkQueue;
-{
- assert(dispatch_get_specific((__bridge void *)self) == maybe_bridge(_workQueue));
-}
-
-- (void)dealloc
-{
- _inputStream.delegate = nil;
- _outputStream.delegate = nil;
-
- [_inputStream close];
- [_outputStream close];
-
- if (_workQueue) {
- sr_dispatch_release(_workQueue);
- _workQueue = NULL;
- }
-
- if (_receivedHTTPHeaders) {
- CFRelease(_receivedHTTPHeaders);
- _receivedHTTPHeaders = NULL;
- }
-
- if (_delegateDispatchQueue) {
- sr_dispatch_release(_delegateDispatchQueue);
- _delegateDispatchQueue = NULL;
- }
-}
-
-#ifndef NDEBUG
-
-- (void)setReadyState:(SRReadyState)aReadyState;
-{
- [self willChangeValueForKey:@"readyState"];
- assert(aReadyState > _readyState);
- _readyState = aReadyState;
- [self didChangeValueForKey:@"readyState"];
-}
-
-#endif
-
-- (void)open;
-{
- assert(_url);
- NSAssert(_readyState == SR_CONNECTING, @"Cannot call -(void)open on SRWebSocket more than once");
-
- _selfRetain = self;
-
- [self openConnection];
-}
-
-// Calls block on delegate queue
-- (void)_performDelegateBlock:(dispatch_block_t)block;
-{
- if (_delegateOperationQueue) {
- [_delegateOperationQueue addOperationWithBlock:block];
- } else {
- assert(_delegateDispatchQueue);
- dispatch_async(_delegateDispatchQueue, block);
- }
-}
-
-- (void)setDelegateDispatchQueue:(dispatch_queue_t)queue;
-{
- if (queue) {
- sr_dispatch_retain(queue);
- }
-
- if (_delegateDispatchQueue) {
- sr_dispatch_release(_delegateDispatchQueue);
- }
-
- _delegateDispatchQueue = queue;
-}
-
-- (BOOL)_checkHandshake:(CFHTTPMessageRef)httpMessage;
-{
- NSString *acceptHeader = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(httpMessage, CFSTR("Sec-WebSocket-Accept")));
-
- if (acceptHeader == nil) {
- return NO;
- }
-
- NSString *concattedString = [_secKey stringByAppendingString:SRWebSocketAppendToSecKeyString];
- NSString *expectedAccept = [concattedString stringBySHA1ThenBase64Encoding];
-
- return [acceptHeader isEqualToString:expectedAccept];
-}
-
-- (void)_HTTPHeadersDidFinish;
-{
- NSInteger responseCode = CFHTTPMessageGetResponseStatusCode(_receivedHTTPHeaders);
-
- if (responseCode >= 400) {
- SRFastLog(@"Request failed with response code %d", responseCode);
- [self _failWithError:[NSError errorWithDomain:SRWebSocketErrorDomain code:2132 userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"received bad response code from server %ld", (long)responseCode], SRHTTPResponseErrorKey:@(responseCode)}]];
- return;
- }
-
- if(![self _checkHandshake:_receivedHTTPHeaders]) {
- [self _failWithError:[NSError errorWithDomain:SRWebSocketErrorDomain code:2133 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Invalid Sec-WebSocket-Accept response"] forKey:NSLocalizedDescriptionKey]]];
- return;
- }
-
- NSString *negotiatedProtocol = CFBridgingRelease(CFHTTPMessageCopyHeaderFieldValue(_receivedHTTPHeaders, CFSTR("Sec-WebSocket-Protocol")));
- if (negotiatedProtocol) {
- // Make sure we requested the protocol
- if ([_requestedProtocols indexOfObject:negotiatedProtocol] == NSNotFound) {
- [self _failWithError:[NSError errorWithDomain:SRWebSocketErrorDomain code:2133 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Server specified Sec-WebSocket-Protocol that wasn't requested"] forKey:NSLocalizedDescriptionKey]]];
- return;
- }
-
- _protocol = negotiatedProtocol;
- }
-
- self.readyState = SR_OPEN;
-
- if (!_didFail) {
- [self _readFrameNew];
- }
-
- [self _performDelegateBlock:^{
- if ([self.delegate respondsToSelector:@selector(webSocketDidOpen:)]) {
- [self.delegate webSocketDidOpen:self];
- };
- }];
-}
-
-
-- (void)_readHTTPHeader;
-{
- if (_receivedHTTPHeaders == NULL) {
- _receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO);
- }
-
- [self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *self, NSData *data) {
- CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);
-
- if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
- SRFastLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_receivedHTTPHeaders)));
- [self _HTTPHeadersDidFinish];
- } else {
- [self _readHTTPHeader];
- }
- }];
-}
-
-- (void)didConnect;
-{
- SRFastLog(@"Connected");
- CFHTTPMessageRef request = CFHTTPMessageCreateRequest(NULL, CFSTR("GET"), (__bridge CFURLRef)_url, kCFHTTPVersion1_1);
-
- // Set host first so it defaults
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Host"), (__bridge CFStringRef)(_url.port ? [NSString stringWithFormat:@"%@:%@", _url.host, _url.port] : _url.host));
-
- NSMutableData *keyBytes = [[NSMutableData alloc] initWithLength:16];
- (void)SecRandomCopyBytes(kSecRandomDefault, keyBytes.length, keyBytes.mutableBytes);
-
- if ([keyBytes respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
- _secKey = [keyBytes base64EncodedStringWithOptions:0];
- } else {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- _secKey = [keyBytes base64Encoding];
-#pragma clang diagnostic pop
- }
-
- assert([_secKey length] == 24);
-
- // Apply cookies if any have been provided
- NSDictionary * cookies = [NSHTTPCookie requestHeaderFieldsWithCookies:[self requestCookies]];
- for (NSString * cookieKey in cookies) {
- NSString * cookieValue = [cookies objectForKey:cookieKey];
- if ([cookieKey length] && [cookieValue length]) {
- CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)cookieKey, (__bridge CFStringRef)cookieValue);
- }
- }
-
- // set header for http basic auth
- if (_url.user.length && _url.password.length) {
- NSData *userAndPassword = [[NSString stringWithFormat:@"%@:%@", _url.user, _url.password] dataUsingEncoding:NSUTF8StringEncoding];
- NSString *userAndPasswordBase64Encoded;
- if ([keyBytes respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
- userAndPasswordBase64Encoded = [userAndPassword base64EncodedStringWithOptions:0];
- } else {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- userAndPasswordBase64Encoded = [userAndPassword base64Encoding];
-#pragma clang diagnostic pop
- }
- _basicAuthorizationString = [NSString stringWithFormat:@"Basic %@", userAndPasswordBase64Encoded];
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Authorization"), (__bridge CFStringRef)_basicAuthorizationString);
- }
-
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Upgrade"), CFSTR("websocket"));
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Connection"), CFSTR("Upgrade"));
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Key"), (__bridge CFStringRef)_secKey);
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Version"), (__bridge CFStringRef)[NSString stringWithFormat:@"%ld", (long)_webSocketVersion]);
-
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Origin"), (__bridge CFStringRef)_url.SR_origin);
-
- if (_requestedProtocols) {
- CFHTTPMessageSetHeaderFieldValue(request, CFSTR("Sec-WebSocket-Protocol"), (__bridge CFStringRef)[_requestedProtocols componentsJoinedByString:@", "]);
- }
-
- [_urlRequest.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
- CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)key, (__bridge CFStringRef)obj);
- }];
-
- NSData *message = CFBridgingRelease(CFHTTPMessageCopySerializedMessage(request));
-
- CFRelease(request);
-
- [self _writeData:message];
- [self _readHTTPHeader];
-}
-
-- (void)_initializeStreams;
-{
- assert(_url.port.unsignedIntValue <= UINT32_MAX);
- uint32_t port = _url.port.unsignedIntValue;
- if (port == 0) {
- if (!_secure) {
- port = 80;
- } else {
- port = 443;
- }
- }
- NSString *host = _url.host;
-
- CFReadStreamRef readStream = NULL;
- CFWriteStreamRef writeStream = NULL;
-
- CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)host, port, &readStream, &writeStream);
-
- _outputStream = CFBridgingRelease(writeStream);
- _inputStream = CFBridgingRelease(readStream);
-
- _inputStream.delegate = self;
- _outputStream.delegate = self;
-}
-
-- (void)_updateSecureStreamOptions;
-{
- if (_secure) {
- NSMutableDictionary *SSLOptions = [[NSMutableDictionary alloc] init];
-
- [_outputStream setProperty:(__bridge id)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(__bridge id)kCFStreamPropertySocketSecurityLevel];
-
- // If we're using pinned certs, don't validate the certificate chain
- if ([_urlRequest SR_SSLPinnedCertificates].count) {
- [SSLOptions setValue:@NO forKey:(__bridge id)kCFStreamSSLValidatesCertificateChain];
- }
-
-#if DEBUG
- self.allowsUntrustedSSLCertificates = YES;
-#endif
-
- if (self.allowsUntrustedSSLCertificates) {
- [SSLOptions setValue:@NO forKey:(__bridge id)kCFStreamSSLValidatesCertificateChain];
- SRFastLog(@"Allowing connection to any root cert");
- }
-
- [_outputStream setProperty:SSLOptions
- forKey:(__bridge id)kCFStreamPropertySSLSettings];
- }
-}
-
-- (void)openConnection;
-{
- [self _updateSecureStreamOptions];
-
- if (!_scheduledRunloops.count) {
- [self scheduleInRunLoop:[NSRunLoop SR_networkRunLoop] forMode:NSDefaultRunLoopMode];
- }
-
-
- [_outputStream open];
- [_inputStream open];
-}
-
-- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
-{
- [_outputStream scheduleInRunLoop:aRunLoop forMode:mode];
- [_inputStream scheduleInRunLoop:aRunLoop forMode:mode];
-
- [_scheduledRunloops addObject:@[aRunLoop, mode]];
-}
-
-- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
-{
- [_outputStream removeFromRunLoop:aRunLoop forMode:mode];
- [_inputStream removeFromRunLoop:aRunLoop forMode:mode];
-
- [_scheduledRunloops removeObject:@[aRunLoop, mode]];
-}
-
-- (void)close;
-{
- [self closeWithCode:SRStatusCodeNormal reason:nil];
-}
-
-- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
-{
- assert(code);
- dispatch_async(_workQueue, ^{
- if (self.readyState == SR_CLOSING || self.readyState == SR_CLOSED) {
- return;
- }
-
- BOOL wasConnecting = self.readyState == SR_CONNECTING;
-
- self.readyState = SR_CLOSING;
-
- SRFastLog(@"Closing with code %d reason %@", code, reason);
-
- if (wasConnecting) {
- [self closeConnection];
- return;
- }
-
- size_t maxMsgSize = [reason maximumLengthOfBytesUsingEncoding:NSUTF8StringEncoding];
- NSMutableData *mutablePayload = [[NSMutableData alloc] initWithLength:sizeof(uint16_t) + maxMsgSize];
- NSData *payload = mutablePayload;
-
- ((uint16_t *)mutablePayload.mutableBytes)[0] = EndianU16_BtoN(code);
-
- if (reason) {
- NSRange remainingRange = {0};
-
- NSUInteger usedLength = 0;
-
- BOOL success = [reason getBytes:(char *)mutablePayload.mutableBytes + sizeof(uint16_t) maxLength:payload.length - sizeof(uint16_t) usedLength:&usedLength encoding:NSUTF8StringEncoding options:NSStringEncodingConversionExternalRepresentation range:NSMakeRange(0, reason.length) remainingRange:&remainingRange];
- #pragma unused (success)
-
- assert(success);
- assert(remainingRange.length == 0);
-
- if (usedLength != maxMsgSize) {
- payload = [payload subdataWithRange:NSMakeRange(0, usedLength + sizeof(uint16_t))];
- }
- }
-
-
- [self _sendFrameWithOpcode:SROpCodeConnectionClose data:payload];
- });
-}
-
-- (void)_closeWithProtocolError:(NSString *)message;
-{
- // Need to shunt this on the _callbackQueue first to see if they received any messages
- [self _performDelegateBlock:^{
- [self closeWithCode:SRStatusCodeProtocolError reason:message];
- dispatch_async(_workQueue, ^{
- [self closeConnection];
- });
- }];
-}
-
-- (void)_failWithError:(NSError *)error;
-{
- dispatch_async(_workQueue, ^{
- if (self.readyState != SR_CLOSED) {
- _failed = YES;
- [self _performDelegateBlock:^{
- if ([self.delegate respondsToSelector:@selector(webSocket:didFailWithError:)]) {
- [self.delegate webSocket:self didFailWithError:error];
- }
- }];
-
- self.readyState = SR_CLOSED;
- _selfRetain = nil;
-
- SRFastLog(@"Failing with error %@", error.localizedDescription);
-
- [self closeConnection];
- }
- });
-}
-
-- (void)_writeData:(NSData *)data;
-{
- [self assertOnWorkQueue];
-
- if (_closeWhenFinishedWriting) {
- return;
- }
- [_outputBuffer appendData:data];
- [self _pumpWriting];
-}
-
-- (void)send:(id)data;
-{
- NSAssert(self.readyState != SR_CONNECTING, @"Invalid State: Cannot call send: until connection is open");
- // TODO: maybe not copy this for performance
- data = [data copy];
- dispatch_async(_workQueue, ^{
- if ([data isKindOfClass:[NSString class]]) {
- [self _sendFrameWithOpcode:SROpCodeTextFrame data:[(NSString *)data dataUsingEncoding:NSUTF8StringEncoding]];
- } else if ([data isKindOfClass:[NSData class]]) {
- [self _sendFrameWithOpcode:SROpCodeBinaryFrame data:data];
- } else if (data == nil) {
- [self _sendFrameWithOpcode:SROpCodeTextFrame data:data];
- } else {
- assert(NO);
- }
- });
-}
-
-- (void)sendPing:(NSData *)data;
-{
- NSAssert(self.readyState == SR_OPEN, @"Invalid State: Cannot call send: until connection is open");
- // TODO: maybe not copy this for performance
- data = [data copy] ?: [NSData data]; // It's okay for a ping to be empty
- dispatch_async(_workQueue, ^{
- [self _sendFrameWithOpcode:SROpCodePing data:data];
- });
-}
-
-- (void)handlePing:(NSData *)pingData;
-{
- // Need to pingpong this off _callbackQueue first to make sure messages happen in order
- [self _performDelegateBlock:^{
- dispatch_async(_workQueue, ^{
- [self _sendFrameWithOpcode:SROpCodePong data:pingData];
- });
- }];
-}
-
-- (void)handlePong:(NSData *)pongData;
-{
- SRFastLog(@"Received pong");
- [self _performDelegateBlock:^{
- if ([self.delegate respondsToSelector:@selector(webSocket:didReceivePong:)]) {
- [self.delegate webSocket:self didReceivePong:pongData];
- }
- }];
-}
-
-- (void)_handleMessage:(id)message
-{
- SRFastLog(@"Received message");
- [self _performDelegateBlock:^{
- [self.delegate webSocket:self didReceiveMessage:message];
- }];
-}
-
-
-static inline BOOL closeCodeIsValid(int closeCode) {
- if (closeCode < 1000) {
- return NO;
- }
-
- if (closeCode >= 1000 && closeCode <= 1011) {
- if (closeCode == 1004 ||
- closeCode == 1005 ||
- closeCode == 1006) {
- return NO;
- }
- return YES;
- }
-
- if (closeCode >= 3000 && closeCode <= 3999) {
- return YES;
- }
-
- if (closeCode >= 4000 && closeCode <= 4999) {
- return YES;
- }
-
- return NO;
-}
-
-// Note from RFC:
-//
-// If there is a body, the first two
-// bytes of the body MUST be a 2-byte unsigned integer (in network byte
-// order) representing a status code with value /code/ defined in
-// Section 7.4. Following the 2-byte integer the body MAY contain UTF-8
-// encoded data with value /reason/, the interpretation of which is not
-// defined by this specification.
-
-- (void)handleCloseWithData:(NSData *)data;
-{
- size_t dataSize = data.length;
- __block uint16_t closeCode = 0;
-
- SRFastLog(@"Received close frame");
-
- if (dataSize == 1) {
- // TODO handle error
- [self _closeWithProtocolError:@"Payload for close must be larger than 2 bytes"];
- return;
- } else if (dataSize >= 2) {
- [data getBytes:&closeCode length:sizeof(closeCode)];
- _closeCode = EndianU16_BtoN(closeCode);
- if (!closeCodeIsValid(_closeCode)) {
- [self _closeWithProtocolError:[NSString stringWithFormat:@"Cannot have close code of %d", _closeCode]];
- return;
- }
- if (dataSize > 2) {
- _closeReason = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(2, dataSize - 2)] encoding:NSUTF8StringEncoding];
- if (!_closeReason) {
- [self _closeWithProtocolError:@"Close reason MUST be valid UTF-8"];
- return;
- }
- }
- } else {
- _closeCode = SRStatusNoStatusReceived;
- }
-
- [self assertOnWorkQueue];
-
- if (self.readyState == SR_OPEN) {
- [self closeWithCode:1000 reason:nil];
- }
- dispatch_async(_workQueue, ^{
- [self closeConnection];
- });
-}
-
-- (void)closeConnection;
-{
- [self assertOnWorkQueue];
- SRFastLog(@"Trying to disconnect");
- _closeWhenFinishedWriting = YES;
- [self _pumpWriting];
-}
-
-- (void)_handleFrameWithData:(NSData *)frameData opCode:(NSInteger)opcode;
-{
- // Check that the current data is valid UTF8
-
- BOOL isControlFrame = (opcode == SROpCodePing || opcode == SROpCodePong || opcode == SROpCodeConnectionClose);
- if (!isControlFrame) {
- [self _readFrameNew];
- } else {
- dispatch_async(_workQueue, ^{
- [self _readFrameContinue];
- });
- }
-
- switch (opcode) {
- case SROpCodeTextFrame: {
- NSString *str = [[NSString alloc] initWithData:frameData encoding:NSUTF8StringEncoding];
- if (str == nil && frameData) {
- [self closeWithCode:SRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"];
- dispatch_async(_workQueue, ^{
- [self closeConnection];
- });
-
- return;
- }
- [self _handleMessage:str];
- break;
- }
- case SROpCodeBinaryFrame:
- [self _handleMessage:[frameData copy]];
- break;
- case SROpCodeConnectionClose:
- [self handleCloseWithData:frameData];
- break;
- case SROpCodePing:
- [self handlePing:frameData];
- break;
- case SROpCodePong:
- [self handlePong:frameData];
- break;
- default:
- [self _closeWithProtocolError:[NSString stringWithFormat:@"Unknown opcode %ld", (long)opcode]];
- // TODO: Handle invalid opcode
- break;
- }
-}
-
-- (void)_handleFrameHeader:(frame_header)frame_header curData:(NSData *)curData;
-{
- assert(frame_header.opcode != 0);
-
- if (self.readyState != SR_OPEN) {
- return;
- }
-
-
- BOOL isControlFrame = (frame_header.opcode == SROpCodePing || frame_header.opcode == SROpCodePong || frame_header.opcode == SROpCodeConnectionClose);
-
- if (isControlFrame && !frame_header.fin) {
- [self _closeWithProtocolError:@"Fragmented control frames not allowed"];
- return;
- }
-
- if (isControlFrame && frame_header.payload_length >= 126) {
- [self _closeWithProtocolError:@"Control frames cannot have payloads larger than 126 bytes"];
- return;
- }
-
- if (!isControlFrame) {
- _currentFrameOpcode = frame_header.opcode;
- _currentFrameCount += 1;
- }
-
- if (frame_header.payload_length == 0) {
- if (isControlFrame) {
- [self _handleFrameWithData:curData opCode:frame_header.opcode];
- } else {
- if (frame_header.fin) {
- [self _handleFrameWithData:_currentFrameData opCode:frame_header.opcode];
- } else {
- // TODO add assert that opcode is not a control;
- [self _readFrameContinue];
- }
- }
- } else {
- assert(frame_header.payload_length <= SIZE_T_MAX);
- [self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *self, NSData *newData) {
- if (isControlFrame) {
- [self _handleFrameWithData:newData opCode:frame_header.opcode];
- } else {
- if (frame_header.fin) {
- [self _handleFrameWithData:self->_currentFrameData opCode:frame_header.opcode];
- } else {
- // TODO add assert that opcode is not a control;
- [self _readFrameContinue];
- }
-
- }
- } readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked];
- }
-}
-
-/* From RFC:
-
- 0 1 2 3
- 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- +-+-+-+-+-------+-+-------------+-------------------------------+
- |F|R|R|R| opcode|M| Payload len | Extended payload length |
- |I|S|S|S| (4) |A| (7) | (16/64) |
- |N|V|V|V| |S| | (if payload len==126/127) |
- | |1|2|3| |K| | |
- +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
- | Extended payload length continued, if payload len == 127 |
- + - - - - - - - - - - - - - - - +-------------------------------+
- | |Masking-key, if MASK set to 1 |
- +-------------------------------+-------------------------------+
- | Masking-key (continued) | Payload Data |
- +-------------------------------- - - - - - - - - - - - - - - - +
- : Payload Data continued ... :
- + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
- | Payload Data continued ... |
- +---------------------------------------------------------------+
- */
-
-static const uint8_t SRFinMask = 0x80;
-static const uint8_t SROpCodeMask = 0x0F;
-static const uint8_t SRRsvMask = 0x70;
-static const uint8_t SRMaskMask = 0x80;
-static const uint8_t SRPayloadLenMask = 0x7F;
-
-
-- (void)_readFrameContinue;
-{
- assert((_currentFrameCount == 0 && _currentFrameOpcode == 0) || (_currentFrameCount > 0 && _currentFrameOpcode > 0));
-
- [self _addConsumerWithDataLength:2 callback:^(SRWebSocket *self, NSData *data) {
- __block frame_header header = {0};
-
- const uint8_t *headerBuffer = data.bytes;
- assert(data.length >= 2);
-
- if (headerBuffer[0] & SRRsvMask) {
- [self _closeWithProtocolError:@"Server used RSV bits"];
- return;
- }
-
- uint8_t receivedOpcode = (SROpCodeMask & headerBuffer[0]);
-
- BOOL isControlFrame = (receivedOpcode == SROpCodePing || receivedOpcode == SROpCodePong || receivedOpcode == SROpCodeConnectionClose);
-
- if (!isControlFrame && receivedOpcode != 0 && self->_currentFrameCount > 0) {
- [self _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
- return;
- }
-
- if (receivedOpcode == 0 && self->_currentFrameCount == 0) {
- [self _closeWithProtocolError:@"cannot continue a message"];
- return;
- }
-
- header.opcode = receivedOpcode == 0 ? self->_currentFrameOpcode : receivedOpcode;
-
- header.fin = !!(SRFinMask & headerBuffer[0]);
-
-
- header.masked = !!(SRMaskMask & headerBuffer[1]);
- header.payload_length = SRPayloadLenMask & headerBuffer[1];
-
- headerBuffer = NULL;
-
- if (header.masked) {
- [self _closeWithProtocolError:@"Client must receive unmasked data"];
- }
-
- size_t extra_bytes_needed = header.masked ? sizeof(_currentReadMaskKey) : 0;
-
- if (header.payload_length == 126) {
- extra_bytes_needed += sizeof(uint16_t);
- } else if (header.payload_length == 127) {
- extra_bytes_needed += sizeof(uint64_t);
- }
-
- if (extra_bytes_needed == 0) {
- [self _handleFrameHeader:header curData:self->_currentFrameData];
- } else {
- [self _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *self, NSData *data) {
- size_t mapped_size = data.length;
- #pragma unused (mapped_size)
- const void *mapped_buffer = data.bytes;
- size_t offset = 0;
-
- if (header.payload_length == 126) {
- assert(mapped_size >= sizeof(uint16_t));
- uint16_t newLen = EndianU16_BtoN(*(uint16_t *)(mapped_buffer));
- header.payload_length = newLen;
- offset += sizeof(uint16_t);
- } else if (header.payload_length == 127) {
- assert(mapped_size >= sizeof(uint64_t));
- header.payload_length = EndianU64_BtoN(*(uint64_t *)(mapped_buffer));
- offset += sizeof(uint64_t);
- } else {
- assert(header.payload_length < 126 && header.payload_length >= 0);
- }
-
- if (header.masked) {
- assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset);
- memcpy(self->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(self->_currentReadMaskKey));
- }
-
- [self _handleFrameHeader:header curData:self->_currentFrameData];
- } readToCurrentFrame:NO unmaskBytes:NO];
- }
- } readToCurrentFrame:NO unmaskBytes:NO];
-}
-
-- (void)_readFrameNew;
-{
- dispatch_async(_workQueue, ^{
- [_currentFrameData setLength:0];
-
- _currentFrameOpcode = 0;
- _currentFrameCount = 0;
- _readOpCount = 0;
- _currentStringScanPosition = 0;
-
- [self _readFrameContinue];
- });
-}
-
-- (void)_pumpWriting;
-{
- [self assertOnWorkQueue];
-
- NSUInteger dataLength = _outputBuffer.length;
- if (dataLength - _outputBufferOffset > 0 && _outputStream.hasSpaceAvailable) {
- NSInteger bytesWritten = [_outputStream write:_outputBuffer.bytes + _outputBufferOffset maxLength:dataLength - _outputBufferOffset];
- if (bytesWritten == -1) {
- [self _failWithError:[NSError errorWithDomain:SRWebSocketErrorDomain code:2145 userInfo:[NSDictionary dictionaryWithObject:@"Error writing to stream" forKey:NSLocalizedDescriptionKey]]];
- return;
- }
-
- _outputBufferOffset += bytesWritten;
-
- if (_outputBufferOffset > 4096 && _outputBufferOffset > (_outputBuffer.length >> 1)) {
- _outputBuffer = [[NSMutableData alloc] initWithBytes:(char *)_outputBuffer.bytes + _outputBufferOffset length:_outputBuffer.length - _outputBufferOffset];
- _outputBufferOffset = 0;
- }
- }
-
- if (_closeWhenFinishedWriting &&
- _outputBuffer.length - _outputBufferOffset == 0 &&
- (_inputStream.streamStatus != NSStreamStatusNotOpen &&
- _inputStream.streamStatus != NSStreamStatusClosed) &&
- !_sentClose) {
- _sentClose = YES;
-
- [_outputStream close];
- [_inputStream close];
-
-
- for (NSArray *runLoop in [_scheduledRunloops copy]) {
- [self unscheduleFromRunLoop:[runLoop objectAtIndex:0] forMode:[runLoop objectAtIndex:1]];
- }
-
- if (!_failed) {
- [self _performDelegateBlock:^{
- if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
- [self.delegate webSocket:self didCloseWithCode:_closeCode reason:_closeReason wasClean:YES];
- }
- }];
- }
-
- _selfRetain = nil;
- }
-}
-
-- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback;
-{
- [self assertOnWorkQueue];
- [self _addConsumerWithScanner:consumer callback:callback dataLength:0];
-}
-
-- (void)_addConsumerWithDataLength:(size_t)dataLength callback:(data_callback)callback readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
-{
- [self assertOnWorkQueue];
- assert(dataLength);
-
- [_consumers addObject:[_consumerPool consumerWithScanner:nil handler:callback bytesNeeded:dataLength readToCurrentFrame:readToCurrentFrame unmaskBytes:unmaskBytes]];
- [self _pumpScanner];
-}
-
-- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback dataLength:(size_t)dataLength;
-{
- [self assertOnWorkQueue];
- [_consumers addObject:[_consumerPool consumerWithScanner:consumer handler:callback bytesNeeded:dataLength readToCurrentFrame:NO unmaskBytes:NO]];
- [self _pumpScanner];
-}
-
-
-static const char CRLFCRLFBytes[] = {'\r', '\n', '\r', '\n'};
-
-- (void)_readUntilHeaderCompleteWithCallback:(data_callback)dataHandler;
-{
- [self _readUntilBytes:CRLFCRLFBytes length:sizeof(CRLFCRLFBytes) callback:dataHandler];
-}
-
-- (void)_readUntilBytes:(const void *)bytes length:(size_t)length callback:(data_callback)dataHandler;
-{
- // TODO optimize so this can continue from where we last searched
- stream_scanner consumer = ^size_t(NSData *data) {
- __block size_t found_size = 0;
- __block size_t match_count = 0;
-
- size_t size = data.length;
- const unsigned char *buffer = data.bytes;
- for (size_t i = 0; i < size; i++ ) {
- if (((const unsigned char *)buffer)[i] == ((const unsigned char *)bytes)[match_count]) {
- match_count += 1;
- if (match_count == length) {
- found_size = i + 1;
- break;
- }
- } else {
- match_count = 0;
- }
- }
- return found_size;
- };
- [self _addConsumerWithScanner:consumer callback:dataHandler];
-}
-
-
-// Returns true if did work
-- (BOOL)_innerPumpScanner {
-
- BOOL didWork = NO;
-
- if (self.readyState >= SR_CLOSING) {
- return didWork;
- }
-
- if (!_consumers.count) {
- return didWork;
- }
-
- size_t curSize = _readBuffer.length - _readBufferOffset;
- if (!curSize) {
- return didWork;
- }
-
- SRIOConsumer *consumer = [_consumers objectAtIndex:0];
-
- size_t bytesNeeded = consumer.bytesNeeded;
-
- size_t foundSize = 0;
- if (consumer.consumer) {
- NSData *tempView = [NSData dataWithBytesNoCopy:(char *)_readBuffer.bytes + _readBufferOffset length:_readBuffer.length - _readBufferOffset freeWhenDone:NO];
- foundSize = consumer.consumer(tempView);
- } else {
- assert(consumer.bytesNeeded);
- if (curSize >= bytesNeeded) {
- foundSize = bytesNeeded;
- } else if (consumer.readToCurrentFrame) {
- foundSize = curSize;
- }
- }
-
- NSData *slice = nil;
- if (consumer.readToCurrentFrame || foundSize) {
- NSRange sliceRange = NSMakeRange(_readBufferOffset, foundSize);
- slice = [_readBuffer subdataWithRange:sliceRange];
-
- _readBufferOffset += foundSize;
-
- if (_readBufferOffset > 4096 && _readBufferOffset > (_readBuffer.length >> 1)) {
- _readBuffer = [[NSMutableData alloc] initWithBytes:(char *)_readBuffer.bytes + _readBufferOffset length:_readBuffer.length - _readBufferOffset]; _readBufferOffset = 0;
- }
-
- if (consumer.unmaskBytes) {
- NSMutableData *mutableSlice = [slice mutableCopy];
-
- NSUInteger len = mutableSlice.length;
- uint8_t *bytes = mutableSlice.mutableBytes;
-
- for (NSUInteger i = 0; i < len; i++) {
- bytes[i] = bytes[i] ^ _currentReadMaskKey[_currentReadMaskOffset % sizeof(_currentReadMaskKey)];
- _currentReadMaskOffset += 1;
- }
-
- slice = mutableSlice;
- }
-
- if (consumer.readToCurrentFrame) {
- [_currentFrameData appendData:slice];
-
- _readOpCount += 1;
-
- if (_currentFrameOpcode == SROpCodeTextFrame) {
- // Validate UTF8 stuff.
- size_t currentDataSize = _currentFrameData.length;
- if (_currentFrameOpcode == SROpCodeTextFrame && currentDataSize > 0) {
- // TODO: Optimize the crap out of this. Don't really have to copy all the data each time
-
- size_t scanSize = currentDataSize - _currentStringScanPosition;
-
- NSData *scan_data = [_currentFrameData subdataWithRange:NSMakeRange(_currentStringScanPosition, scanSize)];
- int32_t valid_utf8_size = validate_dispatch_data_partial_string(scan_data);
-
- if (valid_utf8_size == -1) {
- [self closeWithCode:SRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"];
- dispatch_async(_workQueue, ^{
- [self closeConnection];
- });
- return didWork;
- } else {
- _currentStringScanPosition += valid_utf8_size;
- }
- }
-
- }
-
- consumer.bytesNeeded -= foundSize;
-
- if (consumer.bytesNeeded == 0) {
- [_consumers removeObjectAtIndex:0];
- consumer.handler(self, nil);
- [_consumerPool returnConsumer:consumer];
- didWork = YES;
- }
- } else if (foundSize) {
- [_consumers removeObjectAtIndex:0];
- consumer.handler(self, slice);
- [_consumerPool returnConsumer:consumer];
- didWork = YES;
- }
- }
- return didWork;
-}
-
--(void)_pumpScanner;
-{
- [self assertOnWorkQueue];
-
- if (!_isPumping) {
- _isPumping = YES;
- } else {
- return;
- }
-
- while ([self _innerPumpScanner]) {
-
- }
-
- _isPumping = NO;
-}
-
-//#define NOMASK
-
-static const size_t SRFrameHeaderOverhead = 32;
-
-- (void)_sendFrameWithOpcode:(SROpCode)opcode data:(id)data;
-{
- [self assertOnWorkQueue];
-
- if (nil == data) {
- return;
- }
-
- NSAssert([data isKindOfClass:[NSData class]] || [data isKindOfClass:[NSString class]], @"NSString or NSData");
-
- size_t payloadLength = [data isKindOfClass:[NSString class]] ? [(NSString *)data lengthOfBytesUsingEncoding:NSUTF8StringEncoding] : [data length];
-
- NSMutableData *frame = [[NSMutableData alloc] initWithLength:payloadLength + SRFrameHeaderOverhead];
- if (!frame) {
- [self closeWithCode:SRStatusCodeMessageTooBig reason:@"Message too big"];
- return;
- }
- uint8_t *frame_buffer = (uint8_t *)[frame mutableBytes];
-
- // set fin
- frame_buffer[0] = SRFinMask | opcode;
-
- BOOL useMask = YES;
-#ifdef NOMASK
- useMask = NO;
-#endif
-
- if (useMask) {
- // set the mask and header
- frame_buffer[1] |= SRMaskMask;
- }
-
- size_t frame_buffer_size = 2;
-
- const uint8_t *unmasked_payload = NULL;
- if ([data isKindOfClass:[NSData class]]) {
- unmasked_payload = (uint8_t *)[data bytes];
- } else if ([data isKindOfClass:[NSString class]]) {
- unmasked_payload = (const uint8_t *)[data UTF8String];
- } else {
- return;
- }
-
- if (payloadLength < 126) {
- frame_buffer[1] |= payloadLength;
- } else if (payloadLength <= UINT16_MAX) {
- frame_buffer[1] |= 126;
- *((uint16_t *)(frame_buffer + frame_buffer_size)) = EndianU16_BtoN((uint16_t)payloadLength);
- frame_buffer_size += sizeof(uint16_t);
- } else {
- frame_buffer[1] |= 127;
- *((uint64_t *)(frame_buffer + frame_buffer_size)) = EndianU64_BtoN((uint64_t)payloadLength);
- frame_buffer_size += sizeof(uint64_t);
- }
-
- if (!useMask) {
- for (size_t i = 0; i < payloadLength; i++) {
- frame_buffer[frame_buffer_size] = unmasked_payload[i];
- frame_buffer_size += 1;
- }
- } else {
- uint8_t *mask_key = frame_buffer + frame_buffer_size;
- (void)SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key);
- frame_buffer_size += sizeof(uint32_t);
-
- // TODO: could probably optimize this with SIMD
- for (size_t i = 0; i < payloadLength; i++) {
- frame_buffer[frame_buffer_size] = unmasked_payload[i] ^ mask_key[i % sizeof(uint32_t)];
- frame_buffer_size += 1;
- }
- }
-
- assert(frame_buffer_size <= [frame length]);
- frame.length = frame_buffer_size;
-
- [self _writeData:frame];
-}
-
-- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;
-{
- if (_secure && !_pinnedCertFound && (eventCode == NSStreamEventHasBytesAvailable || eventCode == NSStreamEventHasSpaceAvailable)) {
-
- NSArray *sslCerts = [_urlRequest SR_SSLPinnedCertificates];
- if (sslCerts) {
- SecTrustRef secTrust = (__bridge SecTrustRef)[aStream propertyForKey:(__bridge id)kCFStreamPropertySSLPeerTrust];
- if (secTrust) {
- NSInteger numCerts = SecTrustGetCertificateCount(secTrust);
- for (NSInteger i = 0; i < numCerts && !_pinnedCertFound; i++) {
- SecCertificateRef cert = SecTrustGetCertificateAtIndex(secTrust, i);
- NSData *certData = CFBridgingRelease(SecCertificateCopyData(cert));
-
- for (id ref in sslCerts) {
- SecCertificateRef trustedCert = (__bridge SecCertificateRef)ref;
- NSData *trustedCertData = CFBridgingRelease(SecCertificateCopyData(trustedCert));
-
- if ([trustedCertData isEqualToData:certData]) {
- _pinnedCertFound = YES;
- break;
- }
- }
- }
- }
-
- if (!_pinnedCertFound) {
- dispatch_async(_workQueue, ^{
- [self _failWithError:[NSError errorWithDomain:SRWebSocketErrorDomain code:23556 userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Invalid server cert"] forKey:NSLocalizedDescriptionKey]]];
- });
- return;
- }
- }
- }
-
- dispatch_async(_workQueue, ^{
- switch (eventCode) {
- case NSStreamEventOpenCompleted: {
- SRFastLog(@"NSStreamEventOpenCompleted %@", aStream);
- if (self.readyState >= SR_CLOSING) {
- return;
- }
- assert(_readBuffer);
-
- if (self.readyState == SR_CONNECTING && aStream == _inputStream) {
- [self didConnect];
- }
- [self _pumpWriting];
- [self _pumpScanner];
- break;
- }
-
- case NSStreamEventErrorOccurred: {
- SRFastLog(@"NSStreamEventErrorOccurred %@ %@", aStream, [[aStream streamError] copy]);
- /// TODO specify error better!
- [self _failWithError:aStream.streamError];
- _readBufferOffset = 0;
- [_readBuffer setLength:0];
- break;
-
- }
-
- case NSStreamEventEndEncountered: {
- [self _pumpScanner];
- SRFastLog(@"NSStreamEventEndEncountered %@", aStream);
- if (aStream.streamError) {
- [self _failWithError:aStream.streamError];
- } else {
- dispatch_async(_workQueue, ^{
- if (self.readyState != SR_CLOSED) {
- self.readyState = SR_CLOSED;
- _selfRetain = nil;
- }
-
- if (!_sentClose && !_failed) {
- _sentClose = YES;
- // If we get closed in this state it's probably not clean because we should be sending this when we send messages
- [self _performDelegateBlock:^{
- if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
- [self.delegate webSocket:self didCloseWithCode:SRStatusCodeGoingAway reason:@"Stream end encountered" wasClean:NO];
- }
- }];
- }
- });
- }
-
- break;
- }
-
- case NSStreamEventHasBytesAvailable: {
- SRFastLog(@"NSStreamEventHasBytesAvailable %@", aStream);
- const int bufferSize = 2048;
- uint8_t buffer[bufferSize];
-
- while (_inputStream.hasBytesAvailable) {
- NSInteger bytes_read = [_inputStream read:buffer maxLength:bufferSize];
-
- if (bytes_read > 0) {
- [_readBuffer appendBytes:buffer length:bytes_read];
- } else if (bytes_read < 0) {
- [self _failWithError:_inputStream.streamError];
- }
-
- if (bytes_read != bufferSize) {
- break;
- }
- };
- [self _pumpScanner];
- break;
- }
-
- case NSStreamEventHasSpaceAvailable: {
- SRFastLog(@"NSStreamEventHasSpaceAvailable %@", aStream);
- [self _pumpWriting];
- break;
- }
-
- default:
- SRFastLog(@"(default) %@", aStream);
- break;
- }
- });
-}
-
-@end
-
-
-@implementation SRIOConsumer
-
-@synthesize bytesNeeded = _bytesNeeded;
-@synthesize consumer = _scanner;
-@synthesize handler = _handler;
-@synthesize readToCurrentFrame = _readToCurrentFrame;
-@synthesize unmaskBytes = _unmaskBytes;
-
-- (void)setupWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
-{
- _scanner = [scanner copy];
- _handler = [handler copy];
- _bytesNeeded = bytesNeeded;
- _readToCurrentFrame = readToCurrentFrame;
- _unmaskBytes = unmaskBytes;
- assert(_scanner || _bytesNeeded);
-}
-
-
-@end
-
-
-@implementation SRIOConsumerPool {
- NSUInteger _poolSize;
- NSMutableArray *_bufferedConsumers;
-}
-
-- (id)initWithBufferCapacity:(NSUInteger)poolSize;
-{
- self = [super init];
- if (self) {
- _poolSize = poolSize;
- _bufferedConsumers = [[NSMutableArray alloc] initWithCapacity:poolSize];
- }
- return self;
-}
-
-- (id)init
-{
- return [self initWithBufferCapacity:8];
-}
-
-- (SRIOConsumer *)consumerWithScanner:(stream_scanner)scanner handler:(data_callback)handler bytesNeeded:(size_t)bytesNeeded readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
-{
- SRIOConsumer *consumer = nil;
- if (_bufferedConsumers.count) {
- consumer = [_bufferedConsumers lastObject];
- [_bufferedConsumers removeLastObject];
- } else {
- consumer = [[SRIOConsumer alloc] init];
- }
-
- [consumer setupWithScanner:scanner handler:handler bytesNeeded:bytesNeeded readToCurrentFrame:readToCurrentFrame unmaskBytes:unmaskBytes];
-
- return consumer;
-}
-
-- (void)returnConsumer:(SRIOConsumer *)consumer;
-{
- if (_bufferedConsumers.count < _poolSize) {
- [_bufferedConsumers addObject:consumer];
- }
-}
-
-@end
-
-
-@implementation NSURLRequest (CertificateAdditions)
-
-- (NSArray *)SR_SSLPinnedCertificates;
-{
- return [NSURLProtocol propertyForKey:@"SR_SSLPinnedCertificates" inRequest:self];
-}
-
-@end
-
-@implementation NSMutableURLRequest (CertificateAdditions)
-
-- (NSArray *)SR_SSLPinnedCertificates;
-{
- return [NSURLProtocol propertyForKey:@"SR_SSLPinnedCertificates" inRequest:self];
-}
-
-- (void)setSR_SSLPinnedCertificates:(NSArray *)SR_SSLPinnedCertificates;
-{
- [NSURLProtocol setProperty:SR_SSLPinnedCertificates forKey:@"SR_SSLPinnedCertificates" inRequest:self];
-}
-
-@end
-
-@implementation NSURL (SRWebSocket)
-
-- (NSString *)SR_origin;
-{
- NSString *scheme = [self.scheme lowercaseString];
-
- if ([scheme isEqualToString:@"wss"]) {
- scheme = @"https";
- } else if ([scheme isEqualToString:@"ws"]) {
- scheme = @"http";
- }
-
- BOOL portIsDefault = !self.port ||
- ([scheme isEqualToString:@"http"] && self.port.integerValue == 80) ||
- ([scheme isEqualToString:@"https"] && self.port.integerValue == 443);
-
- if (!portIsDefault) {
- return [NSString stringWithFormat:@"%@://%@:%@", scheme, self.host, self.port];
- } else {
- return [NSString stringWithFormat:@"%@://%@", scheme, self.host];
- }
-}
-
-@end
-
-//#define SR_ENABLE_LOG
-
-static inline void SRFastLog(NSString *format, ...) {
-#ifdef SR_ENABLE_LOG
- __block va_list arg_list;
- va_start (arg_list, format);
-
- NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list];
-
- va_end(arg_list);
-
- NSLog(@"[SR] %@", formattedString);
-#endif
-}
-
-
-#ifdef HAS_ICU
-
-static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
- if ([data length] > INT32_MAX) {
- // INT32_MAX is the limit so long as this Framework is using 32 bit ints everywhere.
- return -1;
- }
-
- int32_t size = (int32_t)[data length];
-
- const void * contents = [data bytes];
- const uint8_t *str = (const uint8_t *)contents;
-
- UChar32 codepoint = 1;
- int32_t offset = 0;
- int32_t lastOffset = 0;
- while(offset < size && codepoint > 0) {
- lastOffset = offset;
- U8_NEXT(str, offset, size, codepoint);
- }
-
- if (codepoint == -1) {
- // Check to see if the last byte is valid or whether it was just continuing
- if (!U8_IS_LEAD(str[lastOffset]) || U8_COUNT_TRAIL_BYTES(str[lastOffset]) + lastOffset < (int32_t)size) {
-
- size = -1;
- } else {
- uint8_t leadByte = str[lastOffset];
- U8_MASK_LEAD_BYTE(leadByte, U8_COUNT_TRAIL_BYTES(leadByte));
-
- for (int i = lastOffset + 1; i < offset; i++) {
- if (U8_IS_SINGLE(str[i]) || U8_IS_LEAD(str[i]) || !U8_IS_TRAIL(str[i])) {
- size = -1;
- }
- }
-
- if (size != -1) {
- size = lastOffset;
- }
- }
- }
-
- if (size != -1 && ![[NSString alloc] initWithBytesNoCopy:(char *)[data bytes] length:size encoding:NSUTF8StringEncoding freeWhenDone:NO]) {
- size = -1;
- }
-
- return size;
-}
-
-#else
-
-// This is a hack, and probably not optimal
-static inline int32_t validate_dispatch_data_partial_string(NSData *data) {
- static const int maxCodepointSize = 3;
-
- for (int i = 0; i < maxCodepointSize; i++) {
- NSString *str = [[NSString alloc] initWithBytesNoCopy:(char *)data.bytes length:data.length - i encoding:NSUTF8StringEncoding freeWhenDone:NO];
- if (str) {
- return (int32_t)data.length - i;
- }
- }
-
- return -1;
-}
-
-#endif
-
-static _SRRunLoopThread *networkThread = nil;
-static NSRunLoop *networkRunLoop = nil;
-
-@implementation NSRunLoop (SRWebSocket)
-
-+ (NSRunLoop *)SR_networkRunLoop {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- networkThread = [[_SRRunLoopThread alloc] init];
- networkThread.name = @"com.squareup.SocketRocket.NetworkThread";
- [networkThread start];
- networkRunLoop = networkThread.runLoop;
- });
-
- return networkRunLoop;
-}
-
-@end
-
-
-@implementation _SRRunLoopThread {
- dispatch_group_t _waitGroup;
-}
-
-@synthesize runLoop = _runLoop;
-
-- (void)dealloc
-{
- sr_dispatch_release(_waitGroup);
-}
-
-- (id)init
-{
- self = [super init];
- if (self) {
- _waitGroup = dispatch_group_create();
- dispatch_group_enter(_waitGroup);
- }
- return self;
-}
-
-- (void)main;
-{
- @autoreleasepool {
- _runLoop = [NSRunLoop currentRunLoop];
- dispatch_group_leave(_waitGroup);
-
- // Add an empty run loop source to prevent runloop from spinning.
- CFRunLoopSourceContext sourceCtx = {
- .version = 0,
- .info = NULL,
- .retain = NULL,
- .release = NULL,
- .copyDescription = NULL,
- .equal = NULL,
- .hash = NULL,
- .schedule = NULL,
- .cancel = NULL,
- .perform = NULL
- };
- CFRunLoopSourceRef source = CFRunLoopSourceCreate(NULL, 0, &sourceCtx);
- CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
- CFRelease(source);
-
- while ([_runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {
-
- }
- assert(NO);
- }
-}
-
-- (NSRunLoop *)runLoop;
-{
- dispatch_group_wait(_waitGroup, DISPATCH_TIME_FOREVER);
- return _runLoop;
-}
-
-@end
[05/12] incubator-weex git commit: * [ios] fix animationModule
callback recursively bug
Posted by ac...@apache.org.
* [ios] fix animationModule callback recursively bug
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/625c80cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/625c80cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/625c80cd
Branch: refs/heads/0.16-dev
Commit: 625c80cd4b64d4029933f125d3793de17152f9af
Parents: 6c4ca52
Author: doumafang <do...@gmail.com>
Authored: Tue Sep 19 14:41:27 2017 +0800
Committer: doumafang <do...@gmail.com>
Committed: Tue Sep 19 14:41:27 2017 +0800
----------------------------------------------------------------------
.../WeexSDK/Sources/Module/WXAnimationModule.m | 26 +++++++++++++++-----
1 file changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/625c80cd/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
index 824431d..962763b 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m
@@ -43,7 +43,6 @@
- (id)copyWithZone:(NSZone *)zone
{
WXAnimationInfo *info = [[WXAnimationInfo allocWithZone:zone] init];
-
info.target = self.target;
info.propertyName = self.propertyName;
info.fromValue = self.fromValue;
@@ -51,7 +50,6 @@
info.duration = self.duration;
info.delay = self.delay;
info.timingFunction = self.timingFunction;
-
return info;
}
@@ -138,6 +136,7 @@
@property (nonatomic,assign) BOOL needLayout;
@property (nonatomic, strong) WXTransition *transition;
+@property (nonatomic, assign) BOOL isAnimationedSuccess;
@end
@@ -150,11 +149,14 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
- (void)transition:(NSString *)nodeRef args:(NSDictionary *)args callback:(WXModuleCallback)callback
{
_needLayout = NO;
+ _isAnimationedSuccess = YES;
WXPerformBlockOnComponentThread(^{
WXComponent *targetComponent = [self.weexInstance componentForRef:nodeRef];
if (!targetComponent) {
if (callback) {
- callback([NSString stringWithFormat:@"No component find for ref:%@", nodeRef]);
+ NSDictionary *message = @{@"result":@"Fail",
+ @"message":[NSString stringWithFormat:@"No component find for ref:%@", nodeRef]};
+ callback(message);
}
return;
}
@@ -164,6 +166,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
});
}
+
- (NSArray<WXAnimationInfo *> *)animationInfoArrayFromArgs:(NSDictionary *)args target:(WXComponent *)target
{
UIView *view = target.view;
@@ -296,7 +299,6 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
}
}
}
-
return infos;
}
@@ -338,7 +340,17 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
[CATransaction setAnimationTimingFunction:[WXConvert CAMediaTimingFunction:args[@"timingFunction"]]];
[CATransaction setCompletionBlock:^{
if (callback) {
- callback(@"SUCCESS");
+ NSDictionary *message;
+ if (_isAnimationedSuccess) {
+ message = @{@"result":@"Success",
+ @"message":@"Success"};
+ }
+ else
+ {
+ message = @{@"result":@"Fail",
+ @"message":@"Animation did not complete"};
+ }
+ callback(message);
}
}];
NSArray<WXAnimationInfo *> *infos = [self animationInfoArrayFromArgs:args target:targetComponent];
@@ -366,7 +378,9 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:))
animation.fillMode = kCAFillModeForwards;
WXAnimationDelegate *delegate = [[WXAnimationDelegate alloc] initWithAnimationInfo:info finishBlock:^(BOOL isFinish) {
-
+ if (!isFinish) {
+ _isAnimationedSuccess = isFinish;
+ }
}];
animation.delegate = delegate;
[11/12] incubator-weex git commit: Merge branch '0.16-dev' of
https://github.com/acton393/incubator-weex into wip-us-0.16-dev
Posted by ac...@apache.org.
Merge branch '0.16-dev' of https://github.com/acton393/incubator-weex into wip-us-0.16-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/59facc19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/59facc19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/59facc19
Branch: refs/heads/0.16-dev
Commit: 59facc197488d6db9da44452643d84052cceed52
Parents: 436e409 2398a75
Author: acton393 <zh...@gmail.com>
Authored: Thu Sep 21 16:09:05 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Sep 21 16:09:05 2017 +0800
----------------------------------------------------------------------
WeexSDK.podspec | 2 -
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 38 -
.../Sources/Bridge/WXDebugLoggerBridge.h | 26 -
.../Sources/Bridge/WXDebugLoggerBridge.m | 213 ---
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 4 -
.../WeexSDK/Sources/Module/WXWebSocketModule.m | 1 -
.../Sources/WebSocket/SRWebSocket+Weex.h | 29 -
.../Sources/WebSocket/SRWebSocket+Weex.m | 47 -
.../Sources/WebSocket/WXWebSocketDefaultImpl.h | 25 -
.../Sources/WebSocket/WXWebSocketDefaultImpl.m | 121 --
ios/sdk/WeexSDK/dependency/SRWebSocket.h | 135 --
ios/sdk/WeexSDK/dependency/SRWebSocket.m | 1806 ------------------
12 files changed, 2447 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/59facc19/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
[09/12] incubator-weex git commit: * [ios] fix
_isTransitionBackgroundColorStyles crash
Posted by ac...@apache.org.
* [ios] fix _isTransitionBackgroundColorStyles crash
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/2252798d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/2252798d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/2252798d
Branch: refs/heads/0.16-dev
Commit: 2252798d4eb330c89d79c1b587a475b6ad6d96eb
Parents: 625c80c
Author: doumafang <do...@gmail.com>
Authored: Thu Sep 21 14:26:33 2017 +0800
Committer: doumafang <do...@gmail.com>
Committed: Thu Sep 21 14:26:33 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Model/WXComponent.m | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2252798d/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
index 7dd7750..0992b49 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m
@@ -168,9 +168,8 @@
{
NSDictionary *styles;
pthread_mutex_lock(&_propertyMutex);
- styles = _styles;
+ styles = [_styles copy];
pthread_mutex_unlock(&_propertyMutex);
-
return styles;
}
[08/12] incubator-weex git commit: * [ios] remove duplicated symbols
Posted by ac...@apache.org.
* [ios] remove duplicated symbols
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/335e7ae3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/335e7ae3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/335e7ae3
Branch: refs/heads/0.16-dev
Commit: 335e7ae3e93b18407ee519e5e44694d442736900
Parents: 6404b4c
Author: acton393 <zh...@gmail.com>
Authored: Wed Sep 20 16:54:27 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Wed Sep 20 16:54:27 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 4 ----
1 file changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/335e7ae3/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index d43ec0e..685019b 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -243,8 +243,6 @@
C42E8FAB1F3C7C09001EBE9D /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
C42E8FAC1F3C7C3B001EBE9D /* WXExtendCallNativeManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C47B78CD1F2998EE001D3B0C /* WXExtendCallNativeManager.m */; };
C42E8FAD1F3C7C3F001EBE9D /* WXExtendCallNativeManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C47B78CC1F2998EE001D3B0C /* WXExtendCallNativeManager.h */; };
- C42E8FAE1F3C7C49001EBE9D /* WXRecyclerDragController.m in Sources */ = {isa = PBXBuildFile; fileRef = DC7764911F3C2CA300B5727E /* WXRecyclerDragController.m */; };
- C42E8FAF1F3C7C4B001EBE9D /* WXRecyclerDragController.h in Headers */ = {isa = PBXBuildFile; fileRef = DC7764921F3C2CA300B5727E /* WXRecyclerDragController.h */; };
C43C03E81EC8ACA40044C7FF /* WXPrerenderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C43C03E41EC8ACA40044C7FF /* WXPrerenderManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
C43C03E91EC8ACA40044C7FF /* WXPrerenderManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C43C03E51EC8ACA40044C7FF /* WXPrerenderManager.m */; };
C4424E5B1F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = C4424E591F24DA3D009F52E2 /* WXExtendCallNativeProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -1674,7 +1672,6 @@
333D9A281F41507A007CED39 /* WXTransition.h in Headers */,
DCA445A51EFA571600D0CFA8 /* WXSDKError.h in Headers */,
DCA445AD1EFA575100D0CFA8 /* WXNavigationProtocol.h in Headers */,
- C42E8FAF1F3C7C4B001EBE9D /* WXRecyclerDragController.h in Headers */,
DCA445B01EFA576200D0CFA8 /* WXModalUIModule.h in Headers */,
DCA445A61EFA571E00D0CFA8 /* WXSDKEngine.h in Headers */,
DCA445AA1EFA573900D0CFA8 /* WXResourceRequest.h in Headers */,
@@ -2243,7 +2240,6 @@
DCA4457A1EFA55B300D0CFA8 /* WXSimulatorShortcutManager.m in Sources */,
DCA4457B1EFA55B300D0CFA8 /* WXAssert.m in Sources */,
DCA4457C1EFA55B300D0CFA8 /* WXAppConfiguration.m in Sources */,
- C42E8FAE1F3C7C49001EBE9D /* WXRecyclerDragController.m in Sources */,
DCA4457D1EFA55B300D0CFA8 /* WXThreadSafeMutableDictionary.m in Sources */,
DCA4457E1EFA55B300D0CFA8 /* WXThreadSafeMutableArray.m in Sources */,
DCA4457F1EFA55B300D0CFA8 /* NSObject+WXSwizzle.m in Sources */,
[03/12] incubator-weex git commit: * [ios] remove socketRocket
dependency
Posted by ac...@apache.org.
* [ios] remove socketRocket dependency
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/7be6c547
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/7be6c547
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/7be6c547
Branch: refs/heads/0.16-dev
Commit: 7be6c54728187b9bb2eb7ca59ac2d3b792d4abfc
Parents: d6388ea
Author: acton393 <zh...@gmail.com>
Authored: Mon Sep 18 21:54:10 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Sep 18 21:54:10 2017 +0800
----------------------------------------------------------------------
WeexSDK.podspec | 2 -
ios/sdk/WeexSDK.xcodeproj/project.pbxproj | 38 -
.../Sources/Bridge/WXDebugLoggerBridge.h | 26 -
.../Sources/Bridge/WXDebugLoggerBridge.m | 213 ---
ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m | 4 -
.../WeexSDK/Sources/Module/WXWebSocketModule.m | 1 -
.../Sources/WebSocket/SRWebSocket+Weex.h | 29 -
.../Sources/WebSocket/SRWebSocket+Weex.m | 47 -
.../Sources/WebSocket/WXWebSocketDefaultImpl.h | 25 -
.../Sources/WebSocket/WXWebSocketDefaultImpl.m | 121 --
ios/sdk/WeexSDK/dependency/SRWebSocket.h | 135 --
ios/sdk/WeexSDK/dependency/SRWebSocket.m | 1806 ------------------
12 files changed, 2447 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/WeexSDK.podspec
----------------------------------------------------------------------
diff --git a/WeexSDK.podspec b/WeexSDK.podspec
index fbf8139..5cb6864 100644
--- a/WeexSDK.podspec
+++ b/WeexSDK.podspec
@@ -39,8 +39,6 @@ Pod::Spec.new do |s|
s.xcconfig = { "OTHER_LINK_FLAG" => '$(inherited) -ObjC'}
s.frameworks = 'CoreMedia','MediaPlayer','AVFoundation','AVKit','JavaScriptCore', 'GLKit', 'OpenGLES', 'CoreText', 'QuartzCore', 'CoreGraphics'
-
- s.dependency 'SocketRocket'
s.libraries = "stdc++"
end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
index d43ec0e..849ed7d 100644
--- a/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
+++ b/ios/sdk/WeexSDK.xcodeproj/project.pbxproj
@@ -48,8 +48,6 @@
591DD3321D23AD5800BE8709 /* WXErrorView.h in Headers */ = {isa = PBXBuildFile; fileRef = 591DD3301D23AD5800BE8709 /* WXErrorView.h */; settings = {ATTRIBUTES = (Public, ); }; };
594C28921CF9E61A009793A4 /* WXAnimationModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 594C28901CF9E61A009793A4 /* WXAnimationModule.m */; };
594C28931CF9E61A009793A4 /* WXAnimationModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 594C28911CF9E61A009793A4 /* WXAnimationModule.h */; };
- 59597F981D2A041700EE9317 /* WXDebugLoggerBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 59597F961D2A041700EE9317 /* WXDebugLoggerBridge.h */; };
- 59597F991D2A041700EE9317 /* WXDebugLoggerBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 59597F971D2A041700EE9317 /* WXDebugLoggerBridge.m */; };
596FDD661D3F52700082CD5B /* WXAnimationModuleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 596FDD651D3F52700082CD5B /* WXAnimationModuleTests.m */; };
596FDD691D3F9EFF0082CD5B /* TestSupportUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 596FDD681D3F9EFF0082CD5B /* TestSupportUtils.m */; };
597334B11D4D9E7F00988789 /* WXSDKManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 597334B01D4D9E7F00988789 /* WXSDKManagerTests.m */; };
@@ -85,7 +83,6 @@
740451EB1E14BB26004157CB /* WXServiceFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 740451E91E14BB26004157CB /* WXServiceFactory.m */; };
7408C48E1CFB345D000BCCD0 /* WXComponent+Events.h in Headers */ = {isa = PBXBuildFile; fileRef = 7408C48C1CFB345D000BCCD0 /* WXComponent+Events.h */; };
7408C48F1CFB345D000BCCD0 /* WXComponent+Events.m in Sources */ = {isa = PBXBuildFile; fileRef = 7408C48D1CFB345D000BCCD0 /* WXComponent+Events.m */; };
- 740938EC1D3D075700DBB801 /* SRWebSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A27E7D81C3E360B00D7A552 /* SRWebSocket.m */; };
740938EE1D3D079100DBB801 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 740938ED1D3D079100DBB801 /* JavaScriptCore.framework */; };
740938EF1D3D083900DBB801 /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7469869B1C4DEAC20054A57E /* libicucore.tbd */; };
740938F31D3D0D9300DBB801 /* WXComponentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 740938EA1D3D026600DBB801 /* WXComponentTests.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
@@ -264,10 +261,6 @@
C4E375381E5FCBD3009B2D9C /* WXComponent+BoxShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = C4E375361E5FCBD3009B2D9C /* WXComponent+BoxShadow.h */; };
C4E97D331F1EF46D00ABC314 /* WXTracingManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C4E97D311F1EF46D00ABC314 /* WXTracingManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
C4E97D341F1EF46D00ABC314 /* WXTracingManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C4E97D321F1EF46D00ABC314 /* WXTracingManager.m */; };
- C4F012791E1502A6003378D0 /* SRWebSocket+Weex.h in Headers */ = {isa = PBXBuildFile; fileRef = C4F012721E1502A6003378D0 /* SRWebSocket+Weex.h */; };
- C4F0127A1E1502A6003378D0 /* SRWebSocket+Weex.m in Sources */ = {isa = PBXBuildFile; fileRef = C4F012731E1502A6003378D0 /* SRWebSocket+Weex.m */; };
- C4F0127B1E1502A6003378D0 /* WXWebSocketDefaultImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = C4F012741E1502A6003378D0 /* WXWebSocketDefaultImpl.h */; };
- C4F0127C1E1502A6003378D0 /* WXWebSocketDefaultImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = C4F012751E1502A6003378D0 /* WXWebSocketDefaultImpl.m */; };
C4F0127D1E1502A6003378D0 /* WXWebSocketHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = C4F012761E1502A6003378D0 /* WXWebSocketHandler.h */; };
C4F012821E1502E9003378D0 /* WXWebSocketModule.h in Headers */ = {isa = PBXBuildFile; fileRef = C4F012801E1502E9003378D0 /* WXWebSocketModule.h */; };
C4F012831E1502E9003378D0 /* WXWebSocketModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C4F012811E1502E9003378D0 /* WXWebSocketModule.m */; };
@@ -588,8 +581,6 @@
1D3000F01D40B9AB004F3B4F /* WXClipboardModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXClipboardModule.m; sourceTree = "<group>"; };
2A1F57B51C75C6A600B58017 /* WXTextInputComponent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXTextInputComponent.h; sourceTree = "<group>"; };
2A1F57B61C75C6A600B58017 /* WXTextInputComponent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXTextInputComponent.m; sourceTree = "<group>"; };
- 2A27E7D71C3E360B00D7A552 /* SRWebSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SRWebSocket.h; path = dependency/SRWebSocket.h; sourceTree = "<group>"; };
- 2A27E7D81C3E360B00D7A552 /* SRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SRWebSocket.m; path = dependency/SRWebSocket.m; sourceTree = "<group>"; };
2A42AF851C23B33E00818EA6 /* libWeexSDK_MTL.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWeexSDK_MTL.a; sourceTree = BUILT_PRODUCTS_DIR; };
2A42AF871C23B33E00818EA6 /* WeexSDK_MTL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WeexSDK_MTL.h; sourceTree = "<group>"; };
2A42AF891C23B33E00818EA6 /* WeexSDK_MTL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WeexSDK_MTL.m; sourceTree = "<group>"; };
@@ -624,8 +615,6 @@
591DD3301D23AD5800BE8709 /* WXErrorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXErrorView.h; sourceTree = "<group>"; };
594C28901CF9E61A009793A4 /* WXAnimationModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXAnimationModule.m; sourceTree = "<group>"; };
594C28911CF9E61A009793A4 /* WXAnimationModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXAnimationModule.h; sourceTree = "<group>"; };
- 59597F961D2A041700EE9317 /* WXDebugLoggerBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXDebugLoggerBridge.h; sourceTree = "<group>"; };
- 59597F971D2A041700EE9317 /* WXDebugLoggerBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXDebugLoggerBridge.m; sourceTree = "<group>"; };
596FDD651D3F52700082CD5B /* WXAnimationModuleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXAnimationModuleTests.m; sourceTree = "<group>"; };
596FDD671D3F9EFF0082CD5B /* TestSupportUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestSupportUtils.h; sourceTree = "<group>"; };
596FDD681D3F9EFF0082CD5B /* TestSupportUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestSupportUtils.m; sourceTree = "<group>"; };
@@ -838,10 +827,6 @@
C4E375361E5FCBD3009B2D9C /* WXComponent+BoxShadow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "WXComponent+BoxShadow.h"; sourceTree = "<group>"; };
C4E97D311F1EF46D00ABC314 /* WXTracingManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXTracingManager.h; sourceTree = "<group>"; };
C4E97D321F1EF46D00ABC314 /* WXTracingManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXTracingManager.m; sourceTree = "<group>"; };
- C4F012721E1502A6003378D0 /* SRWebSocket+Weex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SRWebSocket+Weex.h"; sourceTree = "<group>"; };
- C4F012731E1502A6003378D0 /* SRWebSocket+Weex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SRWebSocket+Weex.m"; sourceTree = "<group>"; };
- C4F012741E1502A6003378D0 /* WXWebSocketDefaultImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXWebSocketDefaultImpl.h; sourceTree = "<group>"; };
- C4F012751E1502A6003378D0 /* WXWebSocketDefaultImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXWebSocketDefaultImpl.m; sourceTree = "<group>"; };
C4F012761E1502A6003378D0 /* WXWebSocketHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXWebSocketHandler.h; sourceTree = "<group>"; };
C4F012801E1502E9003378D0 /* WXWebSocketModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXWebSocketModule.h; sourceTree = "<group>"; };
C4F012811E1502E9003378D0 /* WXWebSocketModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXWebSocketModule.m; sourceTree = "<group>"; };
@@ -929,15 +914,6 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 2A27E7D61C3E360400D7A552 /* dependency */ = {
- isa = PBXGroup;
- children = (
- 2A27E7D71C3E360B00D7A552 /* SRWebSocket.h */,
- 2A27E7D81C3E360B00D7A552 /* SRWebSocket.m */,
- );
- name = dependency;
- sourceTree = "<group>";
- };
2A42AF861C23B33E00818EA6 /* WeexSDK_MTL */ = {
isa = PBXGroup;
children = (
@@ -1166,7 +1142,6 @@
77D160FF1C02DBE70010B15B /* WeexSDK */ = {
isa = PBXGroup;
children = (
- 2A27E7D61C3E360400D7A552 /* dependency */,
77D161171C02DCB90010B15B /* Resources */,
77D161181C02DCB90010B15B /* Sources */,
);
@@ -1221,8 +1196,6 @@
74862F801E03A24500B7A041 /* WXComponentMethod.m */,
74D2051E1E091B8000128F44 /* WXCallJSMethod.h */,
74D2051F1E091B8000128F44 /* WXCallJSMethod.m */,
- 59597F961D2A041700EE9317 /* WXDebugLoggerBridge.h */,
- 59597F971D2A041700EE9317 /* WXDebugLoggerBridge.m */,
59A582FA1CF5B17B0081FD3E /* WXBridgeContext.h */,
59A582FB1CF5B17B0081FD3E /* WXBridgeContext.m */,
77D1613A1C02DEA60010B15B /* WXJSCoreBridge.h */,
@@ -1476,10 +1449,6 @@
C4F012711E1502A6003378D0 /* WebSocket */ = {
isa = PBXGroup;
children = (
- C4F012721E1502A6003378D0 /* SRWebSocket+Weex.h */,
- C4F012731E1502A6003378D0 /* SRWebSocket+Weex.m */,
- C4F012741E1502A6003378D0 /* WXWebSocketDefaultImpl.h */,
- C4F012751E1502A6003378D0 /* WXWebSocketDefaultImpl.m */,
C4F012761E1502A6003378D0 /* WXWebSocketHandler.h */,
);
path = WebSocket;
@@ -1531,7 +1500,6 @@
1D3000F11D40B9AC004F3B4F /* WXClipboardModule.h in Headers */,
59A583081CF5B2FD0081FD3E /* WXNavigationDefaultImpl.h in Headers */,
775BEE4E1C16F993008D1629 /* WXDefine.h in Headers */,
- 59597F981D2A041700EE9317 /* WXDebugLoggerBridge.h in Headers */,
77D161241C02DDD10010B15B /* WXSDKInstance.h in Headers */,
DC6836E61EBB12B200AD2D84 /* WXConfigCenterProtocol.h in Headers */,
DC7764941F3C2CA300B5727E /* WXRecyclerDragController.h in Headers */,
@@ -1575,7 +1543,6 @@
744D61141E4AF23E00B624B3 /* WXDiffUtil.h in Headers */,
74862F791E02B88D00B7A041 /* JSValue+Weex.h in Headers */,
2A1F57B71C75C6A600B58017 /* WXTextInputComponent.h in Headers */,
- C4F012791E1502A6003378D0 /* SRWebSocket+Weex.h in Headers */,
74A4BA9A1CB3BAA100195969 /* WXThreadSafeMutableDictionary.h in Headers */,
74A4BA9E1CB3C0A100195969 /* WXHandlerFactory.h in Headers */,
741DFE021DDD7D18009B020F /* WXRoundedRect.h in Headers */,
@@ -1604,7 +1571,6 @@
77E65A0D1C155E99008B8775 /* WXDivComponent.h in Headers */,
C41E1A971DC1FD15009C7F90 /* WXDatePickerManager.h in Headers */,
333D9A271F41507A007CED39 /* WXTransition.h in Headers */,
- C4F0127B1E1502A6003378D0 /* WXWebSocketDefaultImpl.h in Headers */,
7461F8901CFB373100F62D44 /* WXDisplayQueue.h in Headers */,
DCC77C141D770AE300CE7288 /* WXSliderNeighborComponent.h in Headers */,
747DF6821E31AEE4005C53A8 /* WXLength.h in Headers */,
@@ -2019,7 +1985,6 @@
DC9F46831D61AC8800A88239 /* WXStreamModuleTests.m in Sources */,
1C1A2BED1D91172800539AA1 /* WXConvertTests.m in Sources */,
74EF31C31DE6935600667A07 /* WXURLRewriteTests.m in Sources */,
- 740938EC1D3D075700DBB801 /* SRWebSocket.m in Sources */,
740938F31D3D0D9300DBB801 /* WXComponentTests.m in Sources */,
596FDD661D3F52700082CD5B /* WXAnimationModuleTests.m in Sources */,
591324A31D49B7F1004E89ED /* WXTimerModuleTests.m in Sources */,
@@ -2043,7 +2008,6 @@
74B8BEFF1DC47B72004A6027 /* WXRootView.m in Sources */,
742AD7321DF98C45007DC46C /* WXResourceRequestHandlerDefaultImpl.m in Sources */,
747DF6831E31AEE4005C53A8 /* WXLength.m in Sources */,
- C4F0127C1E1502A6003378D0 /* WXWebSocketDefaultImpl.m in Sources */,
77E65A0E1C155E99008B8775 /* WXDivComponent.m in Sources */,
2A60CE9D1C91733E00857B9F /* WXSwitchComponent.m in Sources */,
744D61111E49979000B624B3 /* WXFooterComponent.m in Sources */,
@@ -2093,7 +2057,6 @@
746319031C60AFC100EFEBD4 /* WXThreadSafeCounter.m in Sources */,
74A4BAA71CB4F98300195969 /* WXStreamModule.m in Sources */,
744D610D1E49978200B624B3 /* WXHeaderComponent.m in Sources */,
- 59597F991D2A041700EE9317 /* WXDebugLoggerBridge.m in Sources */,
77E659F21C0C3612008B8775 /* WXModuleFactory.m in Sources */,
DCF343681E49CAEE00A2FB34 /* WXJSExceptionInfo.m in Sources */,
59CE27E91CC387DB000BE37A /* WXEmbedComponent.m in Sources */,
@@ -2152,7 +2115,6 @@
77D1614C1C02E3790010B15B /* WXConvert.m in Sources */,
749DC27C1D40827B009E1C91 /* WXMonitor.m in Sources */,
C4B834271DE69B09007AD27E /* WXPickerModule.m in Sources */,
- C4F0127A1E1502A6003378D0 /* SRWebSocket+Weex.m in Sources */,
745B2D691E5A8E1E0092D38A /* WXMultiColumnLayout.m in Sources */,
77D161391C02DE940010B15B /* WXBridgeManager.m in Sources */,
);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.h b/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.h
deleted file mode 100644
index c86b12e..0000000
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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 "WXBridgeProtocol.h"
-
-@interface WXDebugLoggerBridge : NSObject <WXBridgeProtocol>
-
-- (instancetype)initWithURL:(NSURL *) URL;
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.m b/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.m
deleted file mode 100644
index fcc4cb3..0000000
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXDebugLoggerBridge.m
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * 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 "WXDebugLoggerBridge.h"
-#import "SRWebSocket.h"
-#import "WXSDKManager.h"
-#import "WXUtility.h"
-#import "WXLog.h"
-
-@interface WXDebugLoggerBridge()<SRWebSocketDelegate>
-
-@end
-
-@implementation WXDebugLoggerBridge
-{
- BOOL _isConnect;
- SRWebSocket *_webSocket;
- NSMutableArray *_msgAry;
- WXJSCallNative _nativeCallBlock;
- NSThread *_curThread;
-}
-
-- (void)dealloc
-{
- _nativeCallBlock = nil;
- [self _disconnect];
-}
-
-- (instancetype)initWithURL:(NSURL *) URL
-{
- self = [super init];
-
- _isConnect = NO;
- _curThread = [NSThread currentThread];
-
- [self _connect:URL];
-
- return self;
-}
-
-- (void)_initEnvironment
-{
- [self callJSMethod:@"setEnvironment" args:@[[WXUtility getEnvironment]]];
-}
-
-- (void)_disconnect
-{
- _msgAry = nil;
- _isConnect = NO;
- _webSocket.delegate = nil;
- [_webSocket close];
- _webSocket = nil;
-}
-
-- (void)_connect:(NSURL *)URL
-{
- _msgAry = nil;
- _msgAry = [NSMutableArray array];
- _webSocket.delegate = nil;
- [_webSocket close];
-
- _webSocket = [[SRWebSocket alloc] initWithURLRequest:[NSURLRequest requestWithURL:URL]];
- _webSocket.delegate = self;
-
- [_webSocket open];
-}
-
--(void)_executionMsgAry
-{
- if (!_isConnect) return;
-
- NSArray *templateContainers = [NSArray arrayWithArray:_msgAry];
- for (NSString *msg in templateContainers) {
- [_webSocket send:msg];
- }
- [_msgAry removeAllObjects];
-}
-
--(void)_evaluateNative:(NSString *)data
-{
- NSDictionary *dict = [WXUtility objectFromJSON:data];
- NSString *method = [dict objectForKey:@"method"];
- NSArray *args = [dict objectForKey:@"arguments"];
-
- if ([method isEqualToString:@"callNative"]) {
- // call native
- NSString *instanceId = args[0];
- NSArray *methods = args[1];
- NSString *callbackId = args[2];
-
- // params parse
- if(!methods || methods.count <= 0){
- return;
- }
- //call native
- WXLogDebug(@"Calling native... instanceId:%@, methods:%@, callbackId:%@", instanceId, [WXUtility JSONString:methods], callbackId);
- _nativeCallBlock(instanceId, methods, callbackId);
- } else if ([method isEqualToString:@"setLogLevel"]) {
- NSString *levelString = [args firstObject];
- [WXLog setLogLevelString:levelString];
- }
-}
-
-#pragma mark - WXBridgeProtocol
-
-- (void)executeJavascript:(NSString *)script
-{
- [self callJSMethod:@"evalFramework" args:@[script]];
-}
-
-- (void)executeJSFramework:(NSString *)frameworkScript
-{
- [self callJSMethod:@"evalFramework" args:@[frameworkScript]];
-}
-
-- (JSValue *)callJSMethod:(NSString *)method args:(NSArray *)args
-{
- if (![method isEqualToString:@"__logger"]) {
- // prevent recursion
- WXLogDebug(@"Calling JS... method:%@, args:%@", method, [WXUtility JSONString:args]);
- }
-
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:method forKey:@"method"];
- [dict setObject:args forKey:@"arguments"];
-
- [_msgAry addObject:[WXUtility JSONString:dict]];
- [self _executionMsgAry];
-
- return nil;
-}
-
-- (void)registerCallNative:(WXJSCallNative)callNative
-{
- _nativeCallBlock = callNative;
-}
-
-- (JSValue*) exception
-{
- return nil;
-}
-
-- (void)resetEnvironment
-{
- [self _initEnvironment];
-}
-
-- (void)garbageCollect
-{
-
-}
-
-- (void)executeBridgeThead:(dispatch_block_t)block
-{
- if([NSThread currentThread] == _curThread){
- block();
- } else {
- [self performSelector:@selector(executeBridgeThead:)
- onThread:_curThread
- withObject:[block copy]
- waitUntilDone:NO];
- }
-}
-
-#pragma mark - SRWebSocketDelegate
-
-- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
-{
- WXLogWarning(@"Websocket Connected:%@", webSocket.url);
- _isConnect = YES;
- [self _initEnvironment];
- __weak typeof(self) weakSelf = self;
- [self executeBridgeThead:^() {
- [weakSelf _executionMsgAry];
- }];
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
-{
- WXLogError(@":( Websocket Failed With Error %@", error);
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
-{
- __weak typeof(self) weakSelf = self;
- [self executeBridgeThead:^() {
- [weakSelf _evaluateNative:message];
- }];
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean
-{
- WXLogInfo(@"Websocket closed with code: %ld, reason:%@, wasClean: %d", (long)code, reason, wasClean);
- _isConnect = NO;
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
index c2db44a..cc9373b 100644
--- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
+++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m
@@ -28,7 +28,6 @@
#import "WXResourceRequestHandlerDefaultImpl.h"
#import "WXNavigationDefaultImpl.h"
#import "WXURLRewriteDefaultImpl.h"
-#import "WXWebSocketDefaultImpl.h"
#import "WXSDKManager.h"
#import "WXSDKError.h"
@@ -168,9 +167,6 @@
[self registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)];
[self registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)];
[self registerHandler:[WXURLRewriteDefaultImpl new] withProtocol:@protocol(WXURLRewriteProtocol)];
- if (NSClassFromString(@"WXWebSocketDefaultImpl")) {
- [self registerHandler:[NSClassFromString(@"WXWebSocketDefaultImpl") new] withProtocol:NSProtocolFromString(@"WXWebSocketHandler")];
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
index e12a11b..c1c7e57 100644
--- a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
+++ b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m
@@ -23,7 +23,6 @@
#import "WXHandlerFactory.h"
#import "WXWebSocketLoader.h"
#import "WXConvert.h"
-#import "SRWebSocket.h"
@interface WXWebSocketModule()
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h
deleted file mode 100644
index 6623319..0000000
--- a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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 "SRWebSocket.h"
-#import "WXWebSocketHandler.h"
-#import <objc/runtime.h>
-
-@interface SRWebSocket (Weex)
-
-@property (nonatomic, copy) NSString *wx_Identifier;
-@property (nonatomic, weak) id<WXWebSocketDelegate> wx_WebSocketDelegate;
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m
deleted file mode 100644
index afdbcfa..0000000
--- a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 "SRWebSocket+Weex.h"
-static char wx_IdentifierKey;
-static char wx_WebSocketDelegateKey;
-
-
-@implementation SRWebSocket (Weex)
-
--(void)setWx_Identifier:(NSString *)wx_Identifier
-{
- objc_setAssociatedObject(self, &wx_IdentifierKey, wx_Identifier, OBJC_ASSOCIATION_COPY);
-}
-
--(NSString *)wx_Identifier
-{
- return objc_getAssociatedObject(self, &wx_IdentifierKey);
-}
-
--(void)setWx_WebSocketDelegate:(id<WXWebSocketDelegate>)wx_WebSocketDelegate
-{
- objc_setAssociatedObject(self, &wx_WebSocketDelegateKey, wx_WebSocketDelegate, OBJC_ASSOCIATION_COPY);
-}
-
--(NSString *)wx_WebSocketDelegate
-{
- return objc_getAssociatedObject(self, &wx_WebSocketDelegateKey);
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h
deleted file mode 100644
index 4eb7631..0000000
--- a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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 "WXWebSocketHandler.h"
-
-@interface WXWebSocketDefaultImpl : NSObject<WXWebSocketHandler>
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
deleted file mode 100644
index c0b554e..0000000
--- a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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 "WXWebSocketDefaultImpl.h"
-#import "SRWebSocket.h"
-#import "WXThreadSafeMutableDictionary.h"
-#import "SRWebSocket+Weex.h"
-
-@interface WXWebSocketDefaultImpl()<SRWebSocketDelegate>
-
-@end
-
-@implementation WXWebSocketDefaultImpl
-{
- WXThreadSafeMutableDictionary<NSString *, SRWebSocket *> *_webSockets;
-}
-
-#pragma mark - WXWebSocketHandler
-- (void)open:(NSString *)url protocol:(NSString *)protocol identifier:(NSString *)identifier withDelegate:(id<WXWebSocketDelegate>)delegate
-{
- if(!_webSockets)
- {
- _webSockets = [WXThreadSafeMutableDictionary new];
- }
- if([_webSockets objectForKey:identifier]){
- SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
- webSocket.delegate = nil;
- [webSocket close];
-
- }
- NSArray *protols;
- if([protocol length]>0){
- protols = [NSArray arrayWithObject:protocol];
- }
- SRWebSocket *webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url] protocols:protols];
- webSocket.delegate = self;
- [webSocket open];
- webSocket.wx_Identifier = identifier;
- webSocket.wx_WebSocketDelegate = delegate;
- [_webSockets setObject:webSocket forKey:identifier];
-}
-
-- (void)send:(id)identifier data:(NSString *)data
-{
- SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
- if(webSocket) {
- [webSocket send:data];
- }
-}
-
-- (void)close:(NSString *)identifier
-{
- SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
- if(webSocket) {
- [webSocket close];
- }
-}
-
-- (void)close:(NSString *)identifier code:(NSInteger)code reason:(NSString *)reason
-{
- SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
- if(webSocket) {
- [webSocket closeWithCode:code reason:reason];
- }
-}
-
-- (void)clear:(NSString *)identifier
-{
- SRWebSocket *webSocket = [_webSockets objectForKey:identifier];
- if(webSocket) {
- webSocket.delegate = nil;
- [webSocket close];
- [_webSockets removeObjectForKey:identifier];
- }
-}
-
-#pragma mark -SRWebSocketDelegate
-- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
-{
- if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didOpen)]) {
- [webSocket.wx_WebSocketDelegate didOpen];
- }
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
-{
- if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didFailWithError:)]) {
- [webSocket.wx_WebSocketDelegate didFailWithError:error];
- }
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
-{
- if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didReceiveMessage:)]) {
- [webSocket.wx_WebSocketDelegate didReceiveMessage:message];
- }
-}
-
-- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
-{
- if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didCloseWithCode:reason:wasClean:)]) {
- [webSocket.wx_WebSocketDelegate didCloseWithCode:code reason:reason wasClean:wasClean];
- }
-}
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7be6c547/ios/sdk/WeexSDK/dependency/SRWebSocket.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/dependency/SRWebSocket.h b/ios/sdk/WeexSDK/dependency/SRWebSocket.h
deleted file mode 100644
index 094a39d..0000000
--- a/ios/sdk/WeexSDK/dependency/SRWebSocket.h
+++ /dev/null
@@ -1,135 +0,0 @@
-//
-// Copyright 2012 Square Inc.
-// Portions Copyright (c) 2016-present, Facebook, Inc.
-//
-// All rights reserved.
-//
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
-//
-
-#import <Foundation/Foundation.h>
-#import <Security/SecCertificate.h>
-
-typedef NS_ENUM(NSInteger, SRReadyState) {
- SR_CONNECTING = 0,
- SR_OPEN = 1,
- SR_CLOSING = 2,
- SR_CLOSED = 3,
-};
-
-typedef enum SRStatusCode : NSInteger {
- SRStatusCodeNormal = 1000,
- SRStatusCodeGoingAway = 1001,
- SRStatusCodeProtocolError = 1002,
- SRStatusCodeUnhandledType = 1003,
- // 1004 reserved.
- SRStatusNoStatusReceived = 1005,
- // 1004-1006 reserved.
- SRStatusCodeInvalidUTF8 = 1007,
- SRStatusCodePolicyViolated = 1008,
- SRStatusCodeMessageTooBig = 1009,
-} SRStatusCode;
-
-@class SRWebSocket;
-
-extern NSString *const SRWebSocketErrorDomain;
-extern NSString *const SRHTTPResponseErrorKey;
-
-#pragma mark - SRWebSocketDelegate
-
-@protocol SRWebSocketDelegate;
-
-#pragma mark - SRWebSocket
-
-@interface SRWebSocket : NSObject <NSStreamDelegate>
-
-@property (nonatomic, weak) id <SRWebSocketDelegate> delegate;
-
-@property (nonatomic, readonly) SRReadyState readyState;
-@property (nonatomic, readonly, retain) NSURL *url;
-
-
-@property (nonatomic, readonly) CFHTTPMessageRef receivedHTTPHeaders;
-
-// Optional array of cookies (NSHTTPCookie objects) to apply to the connections
-@property (nonatomic, readwrite) NSArray * requestCookies;
-
-// This returns the negotiated protocol.
-// It will be nil until after the handshake completes.
-@property (nonatomic, readonly, copy) NSString *protocol;
-
-// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol.
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols;
-- (id)initWithURLRequest:(NSURLRequest *)request;
-
-// Some helper constructors.
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates;
-- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols;
-- (id)initWithURL:(NSURL *)url;
-
-// Delegate queue will be dispatch_main_queue by default.
-// You cannot set both OperationQueue and dispatch_queue.
-- (void)setDelegateOperationQueue:(NSOperationQueue*) queue;
-- (void)setDelegateDispatchQueue:(dispatch_queue_t) queue;
-
-// By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes.
-- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
-- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;
-
-// SRWebSockets are intended for one-time-use only. Open should be called once and only once.
-- (void)open;
-
-- (void)close;
-- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
-
-// Send a UTF8 String or Data.
-- (void)send:(id)data;
-
-// Send Data (can be nil) in a ping message.
-- (void)sendPing:(NSData *)data;
-
-@end
-
-#pragma mark - SRWebSocketDelegate
-
-@protocol SRWebSocketDelegate <NSObject>
-
-// message will either be an NSString if the server is using text
-// or NSData if the server is using binary.
-- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message;
-
-@optional
-
-- (void)webSocketDidOpen:(SRWebSocket *)webSocket;
-- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error;
-- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
-- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload;
-
-@end
-
-#pragma mark - NSURLRequest (CertificateAdditions)
-
-@interface NSURLRequest (CertificateAdditions)
-
-@property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates;
-
-@end
-
-#pragma mark - NSMutableURLRequest (CertificateAdditions)
-
-@interface NSMutableURLRequest (CertificateAdditions)
-
-@property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates;
-
-@end
-
-#pragma mark - NSRunLoop (SRWebSocket)
-
-@interface NSRunLoop (SRWebSocket)
-
-+ (NSRunLoop *)SR_networkRunLoop;
-
-@end
[06/12] incubator-weex git commit: * [ios] bugfix about single border
radius conflict with opacity
Posted by ac...@apache.org.
* [ios] bugfix about single border radius conflict with opacity
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/82f468f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/82f468f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/82f468f0
Branch: refs/heads/0.16-dev
Commit: 82f468f0f98d44d9fa512c41a000e98c572613a0
Parents: e52d273
Author: acton393 <zh...@gmail.com>
Authored: Tue Sep 19 15:11:58 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Sep 19 15:11:58 2017 +0800
----------------------------------------------------------------------
ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/82f468f0/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
index 5d22939..49a90db 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
+++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
@@ -334,6 +334,7 @@
// fill background color
if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) {
CGContextSetFillColorWithColor(context, _backgroundColor.CGColor);
+ CGContextSetAlpha(context, _opacity);
UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight];
[bezierPath fill];
}
[12/12] incubator-weex git commit: Merge branch '0.16-dev' of
https://git-wip-us.apache.org/repos/asf/incubator-weex into wip-us-0.16-dev
Posted by ac...@apache.org.
Merge branch '0.16-dev' of https://git-wip-us.apache.org/repos/asf/incubator-weex into wip-us-0.16-dev
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b7631a35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b7631a35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b7631a35
Branch: refs/heads/0.16-dev
Commit: b7631a359e00d5420879b66e0d5fa3ad2865aac3
Parents: 59facc1 5c90b13
Author: acton393 <zh...@gmail.com>
Authored: Thu Sep 21 16:09:34 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Sep 21 16:09:34 2017 +0800
----------------------------------------------------------------------
.travis.yml | 47 +------
POSSIBLE-NOTICES-FOR-BIN-DIST | 5 +-
.../com/taobao/weex/dom/WXTextDomObject.java | 11 +-
.../weex/dom/action/CreateBodyAction.java | 12 +-
.../weex/ui/view/WXBaseCircleIndicator.java | 131 +++----------------
.../java/com/taobao/weex/utils/LogLevel.java | 4 +-
.../java/com/taobao/weex/utils/WXLogUtils.java | 14 ++
dangerfile-android.js | 108 +++++++++++++++
dangerfile-ios.js | 107 +++++++++++++++
dangerfile-jsfm.js | 105 +++++++++++++++
package.json | 5 +-
scripts/generate_apache_release.sh | 2 +-
test/pages/components/iconfont.vue | 6 +-
test/scripts/components/scroll-event.test.js | 2 +-
14 files changed, 386 insertions(+), 173 deletions(-)
----------------------------------------------------------------------