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 2012/11/20 01:30:14 UTC

ios commit: InAppBrowser - append GUID to the UIWebView UserAgent to differentiate the different instances (for the white-list)

Updated Branches:
  refs/heads/master 5a4b0ea62 -> 029ed2587


InAppBrowser - append GUID to the UIWebView UserAgent to differentiate the different instances (for the white-list)


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

Branch: refs/heads/master
Commit: 029ed258750f7b599068e070d234fd91a2e0b84e
Parents: 5a4b0ea
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Nov 19 16:30:05 2012 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Nov 19 16:30:05 2012 -0800

----------------------------------------------------------------------
 CordovaLib/Classes/CDVInAppBrowser.h |    3 +++
 CordovaLib/Classes/CDVInAppBrowser.m |   19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/029ed258/CordovaLib/Classes/CDVInAppBrowser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h
index 43ba26c..100d3ee 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.h
+++ b/CordovaLib/Classes/CDVInAppBrowser.h
@@ -43,11 +43,14 @@
 @property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
 
 @property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
+@property (nonatomic, strong) NSString* userAgent;
 
 - (void)close;
 - (void)navigateTo:(NSString*)url;
 - (void)showLocationBar:(BOOL)show;
 
+- (id)initWithUserAgent:(NSString*)userAgent;
+
 @end
 
 @interface CDVInAppBrowserOptions : NSObject {}

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/029ed258/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index f36cddf..7785e57 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -80,7 +80,15 @@
 - (void)openInInAppBrowser:(NSString*)url withOptions:(NSString*)options
 {
     if (self.inAppBrowserViewController == nil) {
-        self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] init];
+        NSString* originalUA = [self.webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
+
+        CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
+        CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
+        NSString* modifiedUA = [NSString stringWithFormat:@"%@ (%@)", originalUA, uuidString];
+        CFRelease(uuidString);
+        CFRelease(uuidRef);
+
+        self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:modifiedUA];
         if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
             self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
         }
@@ -134,11 +142,11 @@
 
 @implementation CDVInAppBrowserViewController
 
-- (id)init
+- (id)initWithUserAgent:(NSString*)userAgent
 {
     self = [super init];
     if (self != nil) {
-        // your initialization here
+        self.userAgent = userAgent;
         [self createViews];
     }
 
@@ -154,6 +162,11 @@
     webViewBounds.size.height -= FOOTER_HEIGHT;
 
     if (!self.webView) {
+        // setting the UserAgent must occur before the UIWebView is instantiated.
+        // This is read per instantiation, so it does not affect the main Cordova UIWebView
+        NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:self.userAgent, @"UserAgent", nil];
+        [[NSUserDefaults standardUserDefaults] registerDefaults:dict];
+
         self.webView = [[UIWebView alloc] initWithFrame:webViewBounds];
         self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);