fixed merge conflict

This commit is contained in:
Steven Gill 2013-10-28 12:13:43 -07:00
commit a8060219d5
5 changed files with 240 additions and 183 deletions

View File

@ -36,3 +36,16 @@
### 0.2.3 (Oct 9, 2013) ### 0.2.3 (Oct 9, 2013)
* [CB-4915] Incremented plugin version on dev branch. * [CB-4915] Incremented plugin version on dev branch.
* [CB-4926] Fixes inappbrowser plugin loading for windows8 * [CB-4926] Fixes inappbrowser plugin loading for windows8
### 0.2.4 (Oct 28, 2013)
* CB-5128: added repo + issue tag to plugin.xml for inappbrowser plugin
* CB-4995 Fix crash when WebView is quickly opened then closed.
* CB-4930 - iOS - InAppBrowser should take into account the status bar
* [CB-5010] Incremented plugin version on dev branch.
* [CB-5010] Updated version and RELEASENOTES.md for release 0.2.3
* CB-4858 - Run IAB methods on the UI thread.
* CB-4858 Convert relative URLs to absolute URLs in JS
* CB-3747 Fix back button having different dismiss logic from the close button.
* CB-5021 Expose closeDialog() as a public function and make it safe to call multiple times.
* CB-5021 Make it safe to call close() multiple times
>>>>>>> dev

View File

@ -2,12 +2,18 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="org.apache.cordova.inappbrowser" id="org.apache.cordova.inappbrowser"
version="0.2.3"> version="0.2.4">
<name>InAppBrowser</name> <name>InAppBrowser</name>
<description>Cordova InAppBrowser Plugin</description> <description>Cordova InAppBrowser Plugin</description>
<license>Apache 2.0</license> <license>Apache 2.0</license>
<keywords>cordova,in,app,browser,inappbrowser</keywords> <keywords>cordova,in,app,browser,inappbrowser</keywords>
<repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git</repo>
<issue>https://issues.apache.org/jira/browse/CB/component/12320641</issue>
<engines>
<engine name="cordova" version=">=3.1.0" /><!-- Needs cordova/urlutil -->
</engines>
<js-module src="www/InAppBrowser.js" name="InAppBrowser"> <js-module src="www/InAppBrowser.js" name="InAppBrowser">
<clobbers target="window.open" /> <clobbers target="window.open" />

View File

@ -18,20 +18,6 @@
*/ */
package org.apache.cordova.inappbrowser; package org.apache.cordova.inappbrowser;
import java.util.HashMap;
import java.util.StringTokenizer;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
@ -52,11 +38,7 @@ import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.GeolocationPermissions.Callback;
import android.webkit.JsPromptResult;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Button; import android.widget.Button;
@ -64,6 +46,19 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.StringTokenizer;
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public class InAppBrowser extends CordovaPlugin { public class InAppBrowser extends CordovaPlugin {
@ -100,29 +95,30 @@ public class InAppBrowser extends CordovaPlugin {
* @param callbackId The callback id used when calling back into JavaScript. * @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message. * @return A PluginResult object with a status and message.
*/ */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
try {
if (action.equals("open")) { if (action.equals("open")) {
this.callbackContext = callbackContext; this.callbackContext = callbackContext;
String url = args.getString(0); final String url = args.getString(0);
String target = args.optString(1); String t = args.optString(1);
if (target == null || target.equals("") || target.equals(NULL)) { if (t == null || t.equals("") || t.equals(NULL)) {
target = SELF; t = SELF;
} }
HashMap<String, Boolean> features = parseFeature(args.optString(2)); final String target = t;
final HashMap<String, Boolean> features = parseFeature(args.optString(2));
Log.d(LOG_TAG, "target = " + target); Log.d(LOG_TAG, "target = " + target);
url = updateUrl(url); this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String result = ""; String result = "";
// SELF // SELF
if (SELF.equals(target)) { if (SELF.equals(target)) {
Log.d(LOG_TAG, "in self"); Log.d(LOG_TAG, "in self");
// load in webview // load in webview
if (url.startsWith("file://") || url.startsWith("javascript:") if (url.startsWith("file://") || url.startsWith("javascript:")
|| Config.isUrlWhiteListed(url)) { || Config.isUrlWhiteListed(url)) {
this.webView.loadUrl(url); webView.loadUrl(url);
} }
//Load the dialer //Load the dialer
else if (url.startsWith(WebView.SCHEME_TEL)) else if (url.startsWith(WebView.SCHEME_TEL))
@ -130,34 +126,35 @@ public class InAppBrowser extends CordovaPlugin {
try { try {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
} }
} }
// load in InAppBrowser // load in InAppBrowser
else { else {
result = this.showWebPage(url, features); result = showWebPage(url, features);
} }
} }
// SYSTEM // SYSTEM
else if (SYSTEM.equals(target)) { else if (SYSTEM.equals(target)) {
Log.d(LOG_TAG, "in system"); Log.d(LOG_TAG, "in system");
result = this.openExternal(url); result = openExternal(url);
} }
// BLANK - or anything else // BLANK - or anything else
else { else {
Log.d(LOG_TAG, "in blank"); Log.d(LOG_TAG, "in blank");
result = this.showWebPage(url, features); result = showWebPage(url, features);
} }
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
pluginResult.setKeepCallback(true); pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult); callbackContext.sendPluginResult(pluginResult);
}
});
} }
else if (action.equals("close")) { else if (action.equals("close")) {
closeDialog(); closeDialog();
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
} }
else if (action.equals("injectScriptCode")) { else if (action.equals("injectScriptCode")) {
String jsWrapper = null; String jsWrapper = null;
@ -194,13 +191,12 @@ public class InAppBrowser extends CordovaPlugin {
injectDeferredObject(args.getString(0), jsWrapper); injectDeferredObject(args.getString(0), jsWrapper);
} }
else if (action.equals("show")) { else if (action.equals("show")) {
Runnable runnable = new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
dialog.show(); dialog.show();
} }
}; });
this.cordova.getActivity().runOnUiThread(runnable);
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
pluginResult.setKeepCallback(true); pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult); this.callbackContext.sendPluginResult(pluginResult);
@ -208,12 +204,25 @@ public class InAppBrowser extends CordovaPlugin {
else { else {
return false; return false;
} }
} catch (JSONException e) {
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
return true; return true;
} }
/**
* Called when the view navigates.
*/
@Override
public void onReset() {
closeDialog();
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public void onDestroy() {
closeDialog();
}
/** /**
* Inject an object (script or style) into the InAppBrowser WebView. * Inject an object (script or style) into the InAppBrowser WebView.
* *
@ -241,8 +250,14 @@ public class InAppBrowser extends CordovaPlugin {
} else { } else {
scriptToInject = source; scriptToInject = source;
} }
final String finalScriptToInject = scriptToInject;
// This action will have the side-effect of blurring the currently focused element // This action will have the side-effect of blurring the currently focused element
this.inAppWebView.loadUrl("javascript:" + scriptToInject); this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
}
});
} }
/** /**
@ -274,20 +289,6 @@ public class InAppBrowser extends CordovaPlugin {
} }
} }
/**
* Convert relative URL to full path
*
* @param url
* @return
*/
private String updateUrl(String url) {
Uri newUrl = Uri.parse(url);
if (newUrl.isRelative()) {
url = this.webView.getUrl().substring(0, this.webView.getUrl().lastIndexOf("/")+1) + url;
}
return url;
}
/** /**
* Display a new browser with the specified URL. * Display a new browser with the specified URL.
* *
@ -311,30 +312,30 @@ public class InAppBrowser extends CordovaPlugin {
/** /**
* Closes the dialog * Closes the dialog
*/ */
private void closeDialog() { public void closeDialog() {
try {
final WebView childView = this.inAppWebView; final WebView childView = this.inAppWebView;
Runnable runnable = new Runnable() { // The JS protects against multiple calls, so this should happen only when
// closeDialog() is called by other native code.
if (childView == null) {
return;
}
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
childView.loadUrl("about:blank"); childView.loadUrl("about:blank");
if (dialog != null) {
dialog.dismiss();
} }
}
}; });
try {
this.cordova.getActivity().runOnUiThread(runnable);
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT); obj.put("type", EXIT_EVENT);
sendUpdate(obj, false); sendUpdate(obj, false);
} catch (JSONException ex) { } catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen"); Log.d(LOG_TAG, "Should never happen");
} }
if (dialog != null) {
dialog.dismiss();
}
} }
/** /**
@ -438,14 +439,7 @@ public class InAppBrowser extends CordovaPlugin {
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
try { closeDialog();
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException e) {
Log.d(LOG_TAG, "Should never happen");
}
} }
}); });
@ -620,10 +614,16 @@ public class InAppBrowser extends CordovaPlugin {
* *
* @param obj a JSONObject contain event payload information * @param obj a JSONObject contain event payload information
* @param status the status code to return to the JavaScript environment * @param status the status code to return to the JavaScript environment
*/ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
if (callbackContext != null) {
PluginResult result = new PluginResult(status, obj); PluginResult result = new PluginResult(status, obj);
result.setKeepCallback(keepCallback); result.setKeepCallback(keepCallback);
this.callbackContext.sendPluginResult(result); callbackContext.sendPluginResult(result);
if (!keepCallback) {
callbackContext = null;
}
}
} }

View File

@ -32,6 +32,11 @@
#pragma mark CDVInAppBrowser #pragma mark CDVInAppBrowser
@interface CDVInAppBrowser () {
UIStatusBarStyle _previousStatusBarStyle;
}
@end
@implementation CDVInAppBrowser @implementation CDVInAppBrowser
- (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView - (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView
@ -51,12 +56,8 @@
- (void)close:(CDVInvokedUrlCommand*)command - (void)close:(CDVInvokedUrlCommand*)command
{ {
if (self.inAppBrowserViewController != nil) { // Things are cleaned up in browserExit.
[self.inAppBrowserViewController close]; [self.inAppBrowserViewController close];
self.inAppBrowserViewController = nil;
}
self.callbackId = nil;
} }
- (BOOL) isSystemUrl:(NSURL*)url - (BOOL) isSystemUrl:(NSURL*)url
@ -115,6 +116,7 @@
} }
} }
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options]; CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
[self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showLocationBar:browserOptions.location];
@ -155,8 +157,13 @@
} }
if (! browserOptions.hidden) { if (! browserOptions.hidden) {
UINavigationController* nav = [[UINavigationController alloc]
initWithRootViewController:self.inAppBrowserViewController];
nav.navigationBarHidden = YES;
if (self.viewController.modalViewController != self.inAppBrowserViewController) { if (self.viewController.modalViewController != self.inAppBrowserViewController) {
[self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES]; [self.viewController presentModalViewController:nav animated:YES];
} }
} }
[self.inAppBrowserViewController navigateTo:url]; [self.inAppBrowserViewController navigateTo:url];
@ -166,7 +173,13 @@
{ {
if ([self.inAppBrowserViewController isViewLoaded] && self.inAppBrowserViewController.view.window) if ([self.inAppBrowserViewController isViewLoaded] && self.inAppBrowserViewController.view.window)
return; return;
[self.viewController presentModalViewController:self.inAppBrowserViewController animated:YES];
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
UINavigationController* nav = [[UINavigationController alloc]
initWithRootViewController:self.inAppBrowserViewController];
nav.navigationBarHidden = YES;
[self.viewController presentModalViewController:nav animated:YES];
} }
- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
@ -355,13 +368,18 @@
if (self.callbackId != nil) { if (self.callbackId != nil) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"exit"}]; messageAsDictionary:@{@"type":@"exit"}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
self.callbackId = nil;
} }
// Set navigationDelegate to nil to ensure no callbacks are received from it.
self.inAppBrowserViewController.navigationDelegate = nil;
// Don't recycle the ViewController since it may be consuming a lot of memory. // Don't recycle the ViewController since it may be consuming a lot of memory.
// Also - this is required for the PDF/User-Agent bug work-around. // Also - this is required for the PDF/User-Agent bug work-around.
self.inAppBrowserViewController = nil; self.inAppBrowserViewController = nil;
if (IsAtLeastiOSVersion(@"7.0")) {
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];
}
} }
@end @end
@ -633,6 +651,11 @@
[super viewDidUnload]; [super viewDidUnload];
} }
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
- (void)close - (void)close
{ {
[CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
@ -675,6 +698,15 @@
[self.webView goForward]; [self.webView goForward];
} }
- (void)viewWillAppear:(BOOL)animated
{
if (IsAtLeastiOSVersion(@"7.0")) {
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
}
[super viewWillAppear:animated];
}
#pragma mark UIWebViewDelegate #pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView*)theWebView - (void)webViewDidStartLoad:(UIWebView*)theWebView

View File

@ -22,6 +22,7 @@
var exec = require('cordova/exec'); var exec = require('cordova/exec');
var channel = require('cordova/channel'); var channel = require('cordova/channel');
var modulemapper = require('cordova/modulemapper'); var modulemapper = require('cordova/modulemapper');
var urlutil = require('cordova/urlutil');
function InAppBrowser() { function InAppBrowser() {
this.channels = { this.channels = {
@ -30,6 +31,7 @@ function InAppBrowser() {
'loaderror' : channel.create('loaderror'), 'loaderror' : channel.create('loaderror'),
'exit' : channel.create('exit') 'exit' : channel.create('exit')
}; };
this._alive = true;
} }
InAppBrowser.prototype = { InAppBrowser.prototype = {
@ -39,7 +41,10 @@ InAppBrowser.prototype = {
} }
}, },
close: function (eventname) { close: function (eventname) {
if (this._alive) {
this._alive = false;
exec(null, null, "InAppBrowser", "close", []); exec(null, null, "InAppBrowser", "close", []);
}
}, },
show: function (eventname) { show: function (eventname) {
exec(null, null, "InAppBrowser", "show", []); exec(null, null, "InAppBrowser", "show", []);
@ -77,17 +82,18 @@ InAppBrowser.prototype = {
}; };
module.exports = function(strUrl, strWindowName, strWindowFeatures) { module.exports = function(strUrl, strWindowName, strWindowFeatures) {
var iab = new InAppBrowser();
var cb = function(eventname) {
iab._eventHandler(eventname);
};
// Don't catch calls that write to existing frames (e.g. named iframes). // Don't catch calls that write to existing frames (e.g. named iframes).
if (window.frames && window.frames[strWindowName]) { if (window.frames && window.frames[strWindowName]) {
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open'); var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
return origOpenFunc.apply(window, arguments); return origOpenFunc.apply(window, arguments);
} }
strUrl = urlutil.makeAbsolute(strUrl);
var iab = new InAppBrowser();
var cb = function(eventname) {
iab._eventHandler(eventname);
};
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return iab; return iab;
}; };