cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject ios commit: [CB-2395] Fix CDVViewController UserAgent lock
Date Thu, 07 Feb 2013 15:22:53 GMT
Updated Branches:
  refs/heads/master 53953e109 -> 9e39f7ef8


[CB-2395] Fix CDVViewController UserAgent lock

It was not being release when the view is unloaded mid-page load.


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

Branch: refs/heads/master
Commit: 9e39f7ef8096fb15b38121ab0e245a3a958d9cbb
Parents: 53953e1
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Feb 7 10:21:48 2013 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Feb 7 10:21:48 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVInAppBrowser.m   |    7 +++----
 CordovaLib/Classes/CDVUserAgentUtil.h  |    2 +-
 CordovaLib/Classes/CDVUserAgentUtil.m  |   10 +++++++---
 CordovaLib/Classes/CDVViewController.m |   12 ++++--------
 4 files changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e39f7ef/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index 45bf705..fd4c5f4 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -374,15 +374,13 @@
 - (void)viewDidUnload
 {
     [self.webView loadHTMLString:nil baseURL:nil];
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
     [super viewDidUnload];
 }
 
 - (void)close
 {
-    if (_userAgentLockToken != 0) {
-        [CDVUserAgentUtil releaseLock:_userAgentLockToken];
-        _userAgentLockToken = 0;
-    }
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
 
     if ([self respondsToSelector:@selector(presentingViewController)]) {
         [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
@@ -398,6 +396,7 @@
 - (void)navigateTo:(NSURL*)url
 {
     NSURLRequest* request = [NSURLRequest requestWithURL:url];
+
     _requestedURL = url;
 
     if (_userAgentLockToken != 0) {

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e39f7ef/CordovaLib/Classes/CDVUserAgentUtil.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVUserAgentUtil.h b/CordovaLib/Classes/CDVUserAgentUtil.h
index 662b674..4de382f 100644
--- a/CordovaLib/Classes/CDVUserAgentUtil.h
+++ b/CordovaLib/Classes/CDVUserAgentUtil.h
@@ -22,6 +22,6 @@
 @interface CDVUserAgentUtil : NSObject
 + (NSString*)originalUserAgent;
 + (void)acquireLock:(void (^)(NSInteger lockToken))block;
-+ (void)releaseLock:(NSInteger)lockToken;
++ (void)releaseLock:(NSInteger*)lockToken;
 + (void)setUserAgent:(NSString*)value lockToken:(NSInteger)lockToken;
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e39f7ef/CordovaLib/Classes/CDVUserAgentUtil.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVUserAgentUtil.m b/CordovaLib/Classes/CDVUserAgentUtil.m
index e2baef0..5c43c51 100644
--- a/CordovaLib/Classes/CDVUserAgentUtil.m
+++ b/CordovaLib/Classes/CDVUserAgentUtil.m
@@ -84,11 +84,14 @@ static NSMutableArray* gPendingSetUserAgentBlocks = nil;
     }
 }
 
-+ (void)releaseLock:(NSInteger)lockToken
++ (void)releaseLock:(NSInteger*)lockToken
 {
-    NSAssert(gCurrentLockToken == lockToken, @"Got token %d, expected %d", lockToken, gCurrentLockToken);
+    if (*lockToken == 0) {
+        return;
+    }
+    NSAssert(gCurrentLockToken == *lockToken, @"Got token %d, expected %d", *lockToken, gCurrentLockToken);
 
-    VerboseLog(@"Released lock %d", lockToken);
+    VerboseLog(@"Released lock %d", *lockToken);
     if ([gPendingSetUserAgentBlocks count] > 0) {
         void (^block)() = [gPendingSetUserAgentBlocks objectAtIndex:0];
         [gPendingSetUserAgentBlocks removeObjectAtIndex:0];
@@ -98,6 +101,7 @@ static NSMutableArray* gPendingSetUserAgentBlocks = nil;
     } else {
         gCurrentLockToken = 0;
     }
+    *lockToken = 0;
 }
 
 + (void)setUserAgent:(NSString*)value lockToken:(NSInteger)lockToken

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e39f7ef/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index 36ae785..6c19fa4 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -480,6 +480,7 @@
 
     self.webView.delegate = nil;
     self.webView = nil;
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
 }
 
 #pragma mark UIWebViewDelegate
@@ -499,10 +500,7 @@
  */
 - (void)webViewDidFinishLoad:(UIWebView*)theWebView
 {
-    if (_userAgentLockToken != 0) {
-        [CDVUserAgentUtil releaseLock:_userAgentLockToken];
-        _userAgentLockToken = 0;
-    }
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
 
     /*
      * Hide the Top Activity THROBBER in the Battery Bar
@@ -529,10 +527,7 @@
 
 - (void)webView:(UIWebView*)webView didFailLoadWithError:(NSError*)error
 {
-    if (_userAgentLockToken != 0) {
-        [CDVUserAgentUtil releaseLock:_userAgentLockToken];
-        _userAgentLockToken = 0;
-    }
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
 
     NSLog(@"Failed to load webpage with error: %@", [error localizedDescription]);
 
@@ -958,6 +953,7 @@ BOOL gSplashScreenShown = NO;
 
     self.webView.delegate = nil;
     self.webView = nil;
+    [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
     [_commandQueue dispose];
     [[self.pluginObjects allValues] makeObjectsPerformSelector:@selector(dispose)];
 }


Mime
View raw message