diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 47406101..a2b65663 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -28,6 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.cordova.api.CordovaInterface; +import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.LOG; import org.apache.cordova.api.PluginManager; import org.apache.cordova.api.PluginResult; @@ -103,6 +104,23 @@ public class CordovaWebView extends WebView { /** custom view created by the browser (a video player for example) */ private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; + + private ActivityResult mResult = null; + + class ActivityResult { + + int request; + int result; + Intent incoming; + + public ActivityResult(int req, int res, Intent intent) { + request = req; + result = res; + incoming = intent; + } + + + } static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new FrameLayout.LayoutParams( @@ -497,8 +515,9 @@ public class CordovaWebView extends WebView { if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) { LOG.d(TAG, ">>> loadUrlNow()"); } - if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || url.startsWith("javascript:") || this.isUrlWhiteListed(url)) { - super.loadUrl(url); + boolean isDocument = this.baseUrl != null && url.indexOf(this.baseUrl) == 0; + if (url.startsWith("file://") || isDocument || url.startsWith("javascript:") || this.isUrlWhiteListed(url)) { + super.loadUrl(url); } } @@ -922,9 +941,8 @@ public class CordovaWebView extends WebView { public void handleResume(boolean keepRunning, boolean activityResultKeepRunning) { - // Send resume event to JavaScript this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};"); - + // Forward to plugins if (this.pluginManager != null) { this.pluginManager.onResume(keepRunning); @@ -1060,4 +1078,17 @@ public class CordovaWebView extends WebView { public boolean isCustomViewShowing() { return mCustomView != null; } + + public WebBackForwardList restoreState(Bundle savedInstanceState) + { + WebBackForwardList myList = super.restoreState(savedInstanceState); + Log.d(TAG, "WebView restoration crew now restoring!"); + //Initialize the plugin manager once more + this.pluginManager.init(); + return myList; + } + + public void storeResult(int requestCode, int resultCode, Intent intent) { + mResult = new ActivityResult(requestCode, resultCode, intent); + } } diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index b0c318cd..63ab3255 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -295,6 +295,7 @@ public class CordovaWebViewClient extends WebViewClient { // not loaded yet then just set a flag so that the onNativeReady can be fired // from the JS side when the JS gets to that code. if (!url.equals("about:blank")) { + LOG.d(TAG, "Trying to fire onNativeReady"); this.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}"); this.appView.postMessage("onNativeReady", null); } diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index f504d2ea..51c9c595 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -186,6 +186,17 @@ public class DroidGap extends Activity implements CordovaInterface { // when another application (activity) is started. protected boolean keepRunning = true; + private int lastRequestCode; + + private Object responseCode; + + private Intent lastIntent; + + private Object lastResponseCode; + + private String initCallbackClass; + + /** * Sets the authentication token. * @@ -252,11 +263,15 @@ public class DroidGap extends Activity implements CordovaInterface { @SuppressWarnings("deprecation") @Override public void onCreate(Bundle savedInstanceState) { - //preferences = new PreferenceSet(); LOG.d(TAG, "DroidGap.onCreate()"); super.onCreate(savedInstanceState); + if(savedInstanceState != null) + { + initCallbackClass = savedInstanceState.getString("callbackClass"); + } + if(!this.getBooleanProperty("showTitle", false)) { getWindow().requestFeature(Window.FEATURE_NO_TITLE); @@ -344,6 +359,7 @@ public class DroidGap extends Activity implements CordovaInterface { // Clear cancel flag this.cancelLoadUrl = false; + } /** @@ -806,9 +822,22 @@ public class DroidGap extends Activity implements CordovaInterface { * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). */ protected void onActivityResult(int requestCode, int resultCode, Intent intent) { + Log.d(TAG, "Incoming Result"); super.onActivityResult(requestCode, resultCode, intent); CordovaPlugin callback = this.activityResultCallback; - if (callback != null) { + if(callback == null) + { + if(initCallbackClass != null) + { + this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass); + callback = activityResultCallback; + Log.d(TAG, "We have a callback to send this result to"); + callback.onActivityResult(requestCode, resultCode, intent); + } + } + else + { + Log.d(TAG, "We have a callback to send this result to"); callback.onActivityResult(requestCode, resultCode, intent); } } @@ -1091,4 +1120,15 @@ public class DroidGap extends Activity implements CordovaInterface { public ExecutorService getThreadPool() { return threadPool; } + + protected void onSaveInstanceState(Bundle outState) + { + super.onSaveInstanceState(outState); + if(this.activityResultCallback != null) + { + String cClass = this.activityResultCallback.getClass().getName(); + outState.putString("callbackClass", cClass); + } + } } + diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java index cafa79d3..98bb1573 100755 --- a/framework/src/org/apache/cordova/api/PluginManager.java +++ b/framework/src/org/apache/cordova/api/PluginManager.java @@ -248,7 +248,7 @@ public class PluginManager { * @param service The name of the service. * @return CordovaPlugin or null */ - private CordovaPlugin getPlugin(String service) { + public CordovaPlugin getPlugin(String service) { PluginEntry entry = this.entries.get(service); if (entry == null) { return null;