cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-plugins git commit: CB-8032 - Set new CDVCommandDelegate.urlTransformer if available. Removed CDVFileSystem category methods.
Date Tue, 09 Dec 2014 22:59:12 GMT
Repository: cordova-plugins
Updated Branches:
  refs/heads/master 83a461590 -> bbd62028c


CB-8032 - Set new CDVCommandDelegate.urlTransformer if available. Removed CDVFileSystem category
methods.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/bbd62028
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/bbd62028
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/bbd62028

Branch: refs/heads/master
Commit: bbd62028c0260d81d285c9babe04a46682971668
Parents: 83a4615
Author: Shazron Abdullah <shazron@apache.org>
Authored: Tue Dec 9 14:59:10 2014 -0800
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Tue Dec 9 14:59:10 2014 -0800

----------------------------------------------------------------------
 .../ios/CDVAssetLibraryFileSystem+NativeURL.h   | 28 -----------
 .../ios/CDVAssetLibraryFileSystem+NativeURL.m   | 47 -------------------
 .../src/ios/CDVLocalFileSystem+NativeURL.h      | 28 -----------
 .../src/ios/CDVLocalFileSystem+NativeURL.m      | 47 -------------------
 local-webserver/src/ios/CDVLocalWebServer.m     | 49 ++++++++++++++------
 5 files changed, 36 insertions(+), 163 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bbd62028/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
deleted file mode 100644
index 6462535..0000000
--- a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
+++ /dev/null
@@ -1,28 +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 "CDVAssetLibraryFileSystem.h"
-
-
-@interface CDVAssetLibraryFilesystem (LocalWebServerNativeURL)
-
-@property (nonatomic, copy) NSURL* localWebServerURL;
-
-@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bbd62028/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m
deleted file mode 100644
index 21771b2..0000000
--- a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.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 "CDVAssetLibraryFileSystem+NativeURL.h"
-
-#import <objc/runtime.h>
-
-static void* LocalWebServerURLPropertyKey = &LocalWebServerURLPropertyKey;
-
-@implementation CDVAssetLibraryFilesystem (LocalWebServerNativeURL)
-
-
-- (NSString*) nativeURL:(NSString*)fullPath
-{
-    return [NSString stringWithFormat:@"%@://%@:%lu/assets-library/%@",
-            self.localWebServerURL.scheme,
-            self.localWebServerURL.host,
-            [self.localWebServerURL.port unsignedIntegerValue],
-            fullPath];
-}
-
-- (void) setLocalWebServerURL:(NSURL *)localWebServerURL {
-    objc_setAssociatedObject(self, LocalWebServerURLPropertyKey, localWebServerURL, OBJC_ASSOCIATION_COPY_NONATOMIC);
-}
-
-- (NSURL*) localWebServerURL {
-    return objc_getAssociatedObject(self, LocalWebServerURLPropertyKey);
-}
-
-
-@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bbd62028/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
deleted file mode 100644
index 426ba5e..0000000
--- a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
+++ /dev/null
@@ -1,28 +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 "CDVLocalFileSystem.h"
-
-
-@interface CDVLocalFilesystem (LocalWebServerNativeURL)
-
-@property (nonatomic, copy) NSURL* localWebServerURL;
-
-@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bbd62028/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m
deleted file mode 100644
index 74f47ff..0000000
--- a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.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 "CDVLocalFileSystem+NativeURL.h"
-
-#import <objc/runtime.h>
-
-static void* LocalWebServerURLPropertyKey = &LocalWebServerURLPropertyKey;
-
-@implementation CDVLocalFilesystem (LocalWebServerNativeURL)
-
-
-- (NSString*) nativeURL:(NSString*)fullPath
-{
-    return [NSString stringWithFormat:@"%@://%@:%lu/local-filesystem/%@",
-            self.localWebServerURL.scheme,
-            self.localWebServerURL.host,
-            [self.localWebServerURL.port unsignedIntegerValue],
-            fullPath];
-}
-
-- (void) setLocalWebServerURL:(NSURL *)localWebServerURL {
-    objc_setAssociatedObject(self, LocalWebServerURLPropertyKey, localWebServerURL, OBJC_ASSOCIATION_COPY_NONATOMIC);
-}
-
-- (NSURL*) localWebServerURL {
-    return objc_getAssociatedObject(self, LocalWebServerURLPropertyKey);
-}
-
-
-@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/bbd62028/local-webserver/src/ios/CDVLocalWebServer.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalWebServer.m b/local-webserver/src/ios/CDVLocalWebServer.m
index 024a6f0..dcc7b69 100644
--- a/local-webserver/src/ios/CDVLocalWebServer.m
+++ b/local-webserver/src/ios/CDVLocalWebServer.m
@@ -20,10 +20,13 @@
 #import "CDVLocalWebServer.h"
 #import "GCDWebServerPrivate.h"
 #import <Cordova/CDVViewController.h>
-#import "CDVLocalFileSystem+NativeURL.h"
-#import "CDVAssetLibraryFileSystem+NativeURL.h"
 #import <AssetsLibrary/AssetsLibrary.h>
 #import <MobileCoreServices/MobileCoreServices.h>
+#import <objc/message.h>
+
+
+#define LOCAL_FILESYSTEM_PATH   @"local-filesystem"
+#define ASSETS_LIBRARY_PATH     @"assets-library"
 
 @interface GCDWebServer()
 - (GCDWebServerResponse*)_responseWithContentsOfDirectory:(NSString*)path;
@@ -81,18 +84,38 @@
     [self addLocalFileSystemHandler:authToken];
     [self addAssetLibraryFileSystemHandler:authToken];
     
-    CDVFile* filePlugin = (CDVFile*)[self.commandDelegate getCommandInstance:@"File"];
     NSURL* localServerURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:%lu",
(unsigned long)self.server.port]];
+
+    SEL sel = NSSelectorFromString(@"setUrlTransformer:");
     
-    // set the localWebServerURL for the Obj-C categories
-    if (filePlugin) {
-        NSArray* fileSystems = filePlugin.fileSystems;
-        for (NSObject<CDVFileSystem>* fileSystem in fileSystems) {
-            SEL sel = NSSelectorFromString(@"setLocalWebServerURL:");
-            if ([fileSystem respondsToSelector:sel]) {
-                ((void (*)(id, SEL, id))[fileSystem methodForSelector:sel])(fileSystem, sel,
localServerURL);
+    if ([self.commandDelegate respondsToSelector:sel]) {
+        NSURL* (^urlTransformer)(NSURL*) = ^NSURL* (NSURL* urlToTransform) {
+            NSURL* transformedUrl = urlToTransform;
+            
+            NSString* localhostUrlString = [NSString stringWithFormat:@"http://localhost:%lu",
[localServerURL.port unsignedIntegerValue]];
+            
+            if ([[urlToTransform scheme] isEqualToString:ASSETS_LIBRARY_PATH]) {
+                transformedUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@",
+                        localhostUrlString,
+                        ASSETS_LIBRARY_PATH,
+                        urlToTransform.path
+                        ]];
+
+            } else if ([[urlToTransform scheme] isEqualToString:@"file"]) {
+                transformedUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@",
+                       localhostUrlString,
+                        LOCAL_FILESYSTEM_PATH,
+                       urlToTransform.path
+                        ]];
             }
-        }
+            
+            return transformedUrl;
+        };
+        
+        ((void (*)(id, SEL, id))objc_msgSend)(self.commandDelegate, sel, urlTransformer);
+        
+    } else {
+        NSLog(@"WARNING: CDVPlugin's commandDelegate is missing a urlTransformer property.
The local web server can't set it to transform file and asset-library urls");
     }
 }
 
@@ -184,7 +207,7 @@
 
 - (void) addLocalFileSystemHandler:(NSString*)authToken
 {
-    NSString* basePath = @"/local-filesystem/";
+    NSString* basePath = [NSString stringWithFormat:@"/%@/", LOCAL_FILESYSTEM_PATH];
     BOOL allowRangeRequests = YES;
     
     GCDWebServerAsyncProcessBlock processRequestBlock = ^void (GCDWebServerRequest* request,
GCDWebServerCompletionBlock complete) {
@@ -210,7 +233,7 @@
 
 - (void) addAssetLibraryFileSystemHandler:(NSString*)authToken
 {
-    NSString* basePath = @"/asset-library/";
+    NSString* basePath = [NSString stringWithFormat:@"/%@/", ASSETS_LIBRARY_PATH];
     
     GCDWebServerAsyncProcessBlock processRequestBlock = ^void (GCDWebServerRequest* request,
GCDWebServerCompletionBlock complete) {
         


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message