You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/23 18:11:28 UTC
ios commit: [CB-2305] Add InAppBrowser injectSriptCode command to
support InAppBrowser.executeScript and InAppBrowser.insertCSS APIs
Updated Branches:
refs/heads/master b586157fa -> 452db1566
[CB-2305] Add InAppBrowser injectSriptCode command to support InAppBrowser.executeScript and InAppBrowser.insertCSS APIs
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/452db156
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/452db156
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/452db156
Branch: refs/heads/master
Commit: 452db156629d202cd4f9c34adeaba5835a7411bd
Parents: b586157
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Mar 15 23:27:47 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Mar 23 13:11:15 2013 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVInAppBrowser.h | 2 ++
CordovaLib/Classes/CDVInAppBrowser.m | 25 +++++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/452db156/CordovaLib/Classes/CDVInAppBrowser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h
index f63250a..aa3e7a5 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.h
+++ b/CordovaLib/Classes/CDVInAppBrowser.h
@@ -40,6 +40,8 @@
- (void)open:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
+- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
+- (void)injectCSS:(CDVInvokedUrlCommand*)command;
@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/452db156/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index d001dfd..edc7661 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -159,6 +159,31 @@
}
}
+- (void)injectScriptCode:(CDVInvokedUrlCommand*)command
+{
+ NSString* source = [command argumentAtIndex:0];
+ // NSString* position = [command argumentAtIndex:1];
+ CDVPluginResult* pluginResult;
+
+ self.callbackId = command.callbackId;
+
+ NSError* jsonErr;
+ NSData* jsonEsc = [NSJSONSerialization dataWithJSONObject:@[source] options:0 error:&jsonErr];
+
+ if (jsonErr == nil) {
+ NSString* jsonRepr = [[NSString alloc] initWithData:jsonEsc encoding:NSUTF8StringEncoding];
+ NSString* jsonSourceString = [jsonRepr substringWithRange:(NSRange) {1, [jsonRepr length] - 2}];
+ NSString* scriptEnclosure = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script'); c.type='text/javascript'; c.innerText = %@; d.getElementsByTagName('head')[0].appendChild(c); })(document)", jsonSourceString];
+ [self.inAppBrowserViewController.webView stringByEvaluatingJavaScriptFromString:scriptEnclosure];
+
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ } else {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"unable to serialize script code"];
+ }
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:NO]];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
+}
+
#pragma mark CDVInAppBrowserNavigationDelegate
- (void)browserLoadStart:(NSURL*)url