Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0D73817468 for ; Sat, 7 Mar 2015 00:18:19 +0000 (UTC) Received: (qmail 56815 invoked by uid 500); 7 Mar 2015 00:18:16 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 56773 invoked by uid 500); 7 Mar 2015 00:18:16 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 55232 invoked by uid 99); 7 Mar 2015 00:18:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Mar 2015 00:18:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 21BB5E10E5; Sat, 7 Mar 2015 00:18:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shazron@apache.org To: commits@cordova.apache.org Date: Sat, 07 Mar 2015 00:18:54 -0000 Message-Id: <3d79002d82d847f2b4b1af696ec0d287@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [41/43] ios commit: Make webView property dynamic in CDVViewController and CDVPlugin (from CDVWebViewEngineProtocol reference). Added scrollView category to UIView for backwards compatibility reasons. Make webView property dynamic in CDVViewController and CDVPlugin (from CDVWebViewEngineProtocol reference). Added scrollView category to UIView for backwards compatibility reasons. Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/5fae77df Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/5fae77df Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/5fae77df Branch: refs/heads/4.0.x Commit: 5fae77df00adb905e28b3e1a865603d896f78b56 Parents: 93d819f Author: Shazron Abdullah Authored: Fri Mar 6 11:35:45 2015 -0800 Committer: Shazron Abdullah Committed: Fri Mar 6 11:39:11 2015 -0800 ---------------------------------------------------------------------- CordovaLib/Classes/CDVPlugin.h | 14 +++++++-- CordovaLib/Classes/CDVPlugin.m | 45 ++++++++++++++++++++++------- CordovaLib/Classes/CDVViewController.h | 2 +- CordovaLib/Classes/CDVViewController.m | 26 +++++++++++------ 4 files changed, 64 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5fae77df/CordovaLib/Classes/CDVPlugin.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPlugin.h b/CordovaLib/Classes/CDVPlugin.h index 35d4cc2..b87685b 100644 --- a/CordovaLib/Classes/CDVPlugin.h +++ b/CordovaLib/Classes/CDVPlugin.h @@ -22,10 +22,18 @@ #import "CDVPluginResult.h" #import "NSMutableArray+QueueAdditions.h" #import "CDVCommandDelegate.h" +#import "CDVWebViewEngineProtocol.h" + #ifdef __IPHONE_8_0 #import #endif +@interface UIView (org_apache_cordova_UIView_Extension) + +@property (nonatomic, weak) UIScrollView* scrollView; + +@end + extern NSString* const CDVPageDidLoadNotification; extern NSString* const CDVPluginHandleOpenURLNotification; extern NSString* const CDVPluginResetNotification; @@ -35,13 +43,15 @@ extern NSString* const CDVRemoteNotificationError; @interface CDVPlugin : NSObject {} -@property (nonatomic, weak) UIView* webView; +@property (nonatomic, readonly, weak) UIView* webView; +@property (nonatomic, readonly, weak) id webViewEngine; + @property (nonatomic, weak) UIViewController* viewController; @property (nonatomic, weak) id commandDelegate; @property (readonly, assign) BOOL hasPendingOperation; -- (instancetype)initWithWebView:(UIView*)theWebView; +- (instancetype)initWithWebViewEngine:(id )theWebViewEngine; - (void)pluginInitialize; - (void)handleOpenURL:(NSNotification*)notification; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5fae77df/CordovaLib/Classes/CDVPlugin.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVPlugin.m b/CordovaLib/Classes/CDVPlugin.m index ac1ac4d..03c0c73 100644 --- a/CordovaLib/Classes/CDVPlugin.m +++ b/CordovaLib/Classes/CDVPlugin.m @@ -19,6 +19,24 @@ #import "CDVPlugin.h" #import "CDVViewController.h" +#include + +@implementation UIView (org_apache_cordova_UIView_Extension) + +@dynamic scrollView; + +- (UIScrollView*)scrollView +{ + SEL scrollViewSelector = NSSelectorFromString(@"scrollView"); + + if ([self respondsToSelector:scrollViewSelector]) { + return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector); + } + + return nil; +} + +@end NSString* const CDVPageDidLoadNotification = @"CDVPageDidLoadNotification"; NSString* const CDVPluginHandleOpenURLNotification = @"CDVPluginHandleOpenURLNotification"; @@ -30,28 +48,25 @@ NSString* const CDVRemoteNotificationError = @"CDVRemoteNotificationError"; @interface CDVPlugin () @property (readwrite, assign) BOOL hasPendingOperation; +@property (nonatomic, readwrite, weak) id webViewEngine; @end @implementation CDVPlugin -@synthesize webView, viewController, commandDelegate, hasPendingOperation; +@synthesize webViewEngine, viewController, commandDelegate, hasPendingOperation; +@dynamic webView; // Do not override these methods. Use pluginInitialize instead. -- (instancetype)initWithWebView:(UIView*)theWebView settings:(NSDictionary*)classSettings -{ - return [self initWithWebView:theWebView]; -} - -- (instancetype)initWithWebView:(UIView*)theWebView +- (instancetype)initWithWebViewEngine:(id )theWebViewEngine { self = [super init]; if (self) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:theWebView]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:theWebViewEngine.engineWebView]; - self.webView = theWebView; + self.webViewEngine = theWebViewEngine; } return self; } @@ -79,7 +94,15 @@ NSString* const CDVRemoteNotificationError = @"CDVRemoteNotificationError"; { viewController = nil; commandDelegate = nil; - webView = nil; +} + +- (UIView*)webView +{ + if (self.webViewEngine != nil) { + return self.webViewEngine.engineWebView; + } + + return nil; } /* @@ -132,7 +155,7 @@ NSString* const CDVRemoteNotificationError = @"CDVRemoteNotificationError"; - (NSString*)writeJavascript:(NSString*)javascript { // TODO: although deprecated, should have some solution here instead of removing it - [((CDVViewController*)self.viewController).webViewEngine evaluateJavaScript : javascript completionHandler : nil]; // bad cast, but ok for now + [((CDVViewController*)self.viewController).webViewEngine evaluateJavaScript:javascript completionHandler:nil]; // bad cast, but ok for now return @""; } http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5fae77df/CordovaLib/Classes/CDVViewController.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h index 68297d4..4836f14 100644 --- a/CordovaLib/Classes/CDVViewController.h +++ b/CordovaLib/Classes/CDVViewController.h @@ -38,7 +38,7 @@ NSString* _userAgent; } -@property (nonatomic, strong) IBOutlet UIView* webView; +@property (nonatomic, readonly, weak) IBOutlet UIView* webView; @property (nonatomic, readonly, strong) NSMutableDictionary* pluginObjects; @property (nonatomic, readonly, strong) NSDictionary* pluginsMap; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/5fae77df/CordovaLib/Classes/CDVViewController.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m index e59bdd7..21136f7 100644 --- a/CordovaLib/Classes/CDVViewController.m +++ b/CordovaLib/Classes/CDVViewController.m @@ -46,13 +46,14 @@ @implementation CDVViewController -@synthesize webView, supportedOrientations; +@synthesize supportedOrientations; @synthesize pluginObjects, pluginsMap, whitelist, startupPluginNames; @synthesize configParser, settings, loadFromString; @synthesize wwwFolderName, startPage, initialized, openURL, baseUserAgent; @synthesize commandDelegate = _commandDelegate; @synthesize commandQueue = _commandQueue; @synthesize webViewEngine = _webViewEngine; +@dynamic webView; - (void)__init { @@ -250,6 +251,15 @@ return errorURL; } +- (UIView*)webView +{ + if (self.webViewEngine != nil) { + return self.webViewEngine.engineWebView; + } + + return nil; +} + // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { @@ -285,7 +295,7 @@ */ if (IsAtLeastiOSVersion(@"5.1") && (([backupWebStorageType isEqualToString:@"local"]) || ([backupWebStorageType isEqualToString:@"cloud"] && !IsAtLeastiOSVersion(@"6.0")))) { - [self registerPlugin:[[CDVLocalStorage alloc] initWithWebView:self.webView] withClassName:NSStringFromClass([CDVLocalStorage class])]; + [self registerPlugin:[[CDVLocalStorage alloc] initWithWebViewEngine:self.webViewEngine] withClassName:NSStringFromClass([CDVLocalStorage class])]; } if ([self.startupPluginNames count] > 0) { @@ -471,11 +481,11 @@ webViewBounds.origin = self.view.bounds.origin; - self.webView = [self newCordovaViewWithFrame:webViewBounds]; + UIView* view = [self newCordovaViewWithFrame:webViewBounds]; - self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); - [self.view addSubview:self.webView]; - [self.view sendSubviewToBack:self.webView]; + view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); + [self.view addSubview:view]; + [self.view sendSubviewToBack:view]; } - (void)didReceiveMemoryWarning @@ -508,7 +518,6 @@ // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; - self.webView = nil; [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [super viewDidUnload]; @@ -735,7 +744,7 @@ id obj = [self.pluginObjects objectForKey:className]; if (!obj) { - obj = [[NSClassFromString(className)alloc] initWithWebView:webView]; + obj = [[NSClassFromString(className)alloc] initWithWebViewEngine:_webViewEngine]; if (obj != nil) { [self registerPlugin:obj withClassName:className]; @@ -904,7 +913,6 @@ [CDVURLProtocol unregisterViewController:self]; [[NSNotificationCenter defaultCenter] removeObserver:self]; - self.webView = nil; [CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [_commandQueue dispose]; [[self.pluginObjects allValues] makeObjectsPerformSelector:@selector(dispose)]; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org