You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/03/06 23:26:03 UTC
ios commit: Make webView property dynamic in CDVViewController and
CDVPlugin (from CDVWebViewEngineProtocol reference). Added scrollView
category to UIView for backwards compatibility reasons.
Repository: cordova-ios
Updated Branches:
refs/heads/wkwebview 93d819faf -> 5fae77df0
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/wkwebview
Commit: 5fae77df00adb905e28b3e1a865603d896f78b56
Parents: 93d819f
Author: Shazron Abdullah <sh...@gmail.com>
Authored: Fri Mar 6 11:35:45 2015 -0800
Committer: Shazron Abdullah <sh...@gmail.com>
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 <WebKit/WebKit.h>
#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 <CDVWebViewEngineProtocol> webViewEngine;
+
@property (nonatomic, weak) UIViewController* viewController;
@property (nonatomic, weak) id <CDVCommandDelegate> commandDelegate;
@property (readonly, assign) BOOL hasPendingOperation;
-- (instancetype)initWithWebView:(UIView*)theWebView;
+- (instancetype)initWithWebViewEngine:(id <CDVWebViewEngineProtocol>)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 <objc/message.h>
+
+@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 <CDVWebViewEngineProtocol> 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 <CDVWebViewEngineProtocol>)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