cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject ios commit: InAppBrowser: Don't inject iframe bridge until necessary.
Date Thu, 18 Apr 2013 18:21:22 GMT
Updated Branches:
  refs/heads/master 037620604 -> df1d29541


InAppBrowser: Don't inject iframe bridge until necessary.


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

Branch: refs/heads/master
Commit: df1d2954128532e5114ff9a5fe6c239426ce8c3b
Parents: 0376206
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Apr 18 14:20:52 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Apr 18 14:20:52 2013 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVInAppBrowser.h |    4 +++-
 CordovaLib/Classes/CDVInAppBrowser.m |   17 +++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/df1d2954/CordovaLib/Classes/CDVInAppBrowser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h
index a79c5f9..343f40d 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.h
+++ b/CordovaLib/Classes/CDVInAppBrowser.h
@@ -24,7 +24,9 @@
 
 @class CDVInAppBrowserViewController;
 
-@interface CDVInAppBrowser : CDVPlugin
+@interface CDVInAppBrowser : CDVPlugin {
+    BOOL _injectedIframeBridge;
+}
 
 @property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
 @property (nonatomic, copy) NSString* callbackId;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/df1d2954/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index e414d4b..f366bd8 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -171,6 +171,12 @@
 
 - (void)injectDeferredObject:(NSString*)source withWrapper:(NSString*)jsWrapper
 {
+    if (!_injectedIframeBridge) {
+        _injectedIframeBridge = YES;
+        // Create an iframe bridge in the new document to communicate with the CDVInAppBrowserViewController
+        [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:@"(function(d){var
e = _cdvIframeBridge = d.createElement('iframe');e.style.display='none';d.body.appendChild(e);})(document)"];
+    }
+
     if (jsWrapper != nil) {
         NSString* sourceArrayString = [@[source] JSONString];
         if (sourceArrayString) {
@@ -188,7 +194,7 @@
     NSString* jsWrapper = nil;
 
     if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"])
{
-        jsWrapper = [NSString stringWithFormat:@"document.getElementById('cdv-iab-bridge').src='gap-iab://%@/'+window.escape(JSON.stringify([eval(%%@)]));",
command.callbackId];
+        jsWrapper = [NSString stringWithFormat:@"_cdvIframeBridge.src='gap-iab://%@/'+window.escape(JSON.stringify([eval(%%@)]));",
command.callbackId];
     }
     [self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper];
 }
@@ -198,7 +204,7 @@
     NSString* jsWrapper;
 
     if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"])
{
-        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script');
c.src = %%@; c.onload = function() { document.getElementById('cdv-iab-bridge').src='gap-iab://%@';
}; d.body.appendChild(c); })(document)", command.callbackId];
+        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script');
c.src = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@'; }; d.body.appendChild(c);
})(document)", command.callbackId];
     } else {
         jsWrapper = @"(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c);
})(document)";
     }
@@ -210,7 +216,7 @@
     NSString* jsWrapper;
 
     if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"])
{
-        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('style');
c.innerHTML = %%@; c.onload = function() { document.getElementById('cdv-iab-bridge').src='gap-iab://%@';
}; d.body.appendChild(c); })(document)", command.callbackId];
+        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('style');
c.innerHTML = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@'; }; d.body.appendChild(c);
})(document)", command.callbackId];
     } else {
         jsWrapper = @"(function(d) { var c = d.createElement('style'); c.innerHTML = %@;
d.body.appendChild(c); })(document)";
     }
@@ -222,7 +228,7 @@
     NSString* jsWrapper;
 
     if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"])
{
-        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('link');
c.rel='stylesheet'; c.type='text/css'; c.href = %%@; c.onload = function() { document.getElementById('cdv-iab-bridge').src='gap-iab://%@';
}; d.body.appendChild(c); })(document)", command.callbackId];
+        jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('link');
c.rel='stylesheet'; c.type='text/css'; c.href = %%@; c.onload = function() { _cdvIframeBridge.src='gap-iab://%@';
}; d.body.appendChild(c); })(document)", command.callbackId];
     } else {
         jsWrapper = @"(function(d) { var c = d.createElement('link'); c.rel='stylesheet',
c.type='text/css'; c.href = %@; d.body.appendChild(c); })(document)";
     }
@@ -279,6 +285,7 @@
 
 - (void)webViewDidStartLoad:(UIWebView*)theWebView
 {
+    _injectedIframeBridge = NO;
     if (self.callbackId != nil) {
         NSString* url = [[self.inAppBrowserViewController requestedURL] absoluteString];
         CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
@@ -291,8 +298,6 @@
 
 - (void)webViewDidFinishLoad:(UIWebView*)theWebView
 {
-    // Create an iframe bridge in the new document to communicate with the CDVInAppBrowserViewController
-    [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:@"(function(d){var
e=d.createElement('iframe');e.id='cdv-iab-bridge';e.style.display='none';d.body.appendChild(e);})(document)"];
     if (self.callbackId != nil) {
         // TODO: It would be more useful to return the URL the page is actually on (e.g.
if it's been redirected).
         NSString* url = [[self.inAppBrowserViewController requestedURL] absoluteString];


Mime
View raw message