You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2012/09/21 19:38:49 UTC
[2/2] android commit: Add onReset to Plugin API, call on navigate.
Add onReset to Plugin API, call on navigate.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/9961d9e5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/9961d9e5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/9961d9e5
Branch: refs/heads/master
Commit: 9961d9e54d09edfb25e38b0faa48b5d69af927b9
Parents: 3d62744
Author: Braden Shepherdson <br...@chromium.org>
Authored: Wed Sep 12 14:31:01 2012 -0400
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Fri Sep 21 12:00:14 2012 -0400
----------------------------------------------------------------------
.../org/apache/cordova/CordovaWebViewClient.java | 11 +++++------
framework/src/org/apache/cordova/api/IPlugin.java | 7 +++++++
framework/src/org/apache/cordova/api/Plugin.java | 12 ++++++++++++
.../src/org/apache/cordova/api/PluginManager.java | 14 ++++++++++++++
4 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/9961d9e5/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index fe0e9e9..5f90763 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -23,20 +23,15 @@ import java.util.Hashtable;
import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.PluginResult;
-import java.io.IOException;
-import java.io.InputStream;
-
import org.apache.cordova.api.LOG;
import org.json.JSONException;
import org.json.JSONObject;
import android.annotation.TargetApi;
-import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
@@ -44,7 +39,6 @@ import android.util.Log;
import android.view.View;
import android.webkit.HttpAuthHandler;
import android.webkit.SslErrorHandler;
-import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@@ -269,6 +263,11 @@ public class CordovaWebViewClient extends WebViewClient {
// Broadcast message that page has loaded
this.appView.postMessage("onPageStarted", url);
+
+ // Notify all plugins of the navigation, so they can clean up if necessary.
+ if (this.appView.pluginManager != null) {
+ this.appView.pluginManager.onReset();
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/9961d9e5/framework/src/org/apache/cordova/api/IPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/IPlugin.java b/framework/src/org/apache/cordova/api/IPlugin.java
index 870bb9e..a33a663 100755
--- a/framework/src/org/apache/cordova/api/IPlugin.java
+++ b/framework/src/org/apache/cordova/api/IPlugin.java
@@ -116,4 +116,11 @@ public interface IPlugin {
* @return Return true to prevent the URL from loading. Default is false.
*/
boolean onOverrideUrlLoading(String url);
+
+ /**
+ * Called when the WebView does a top-level navigation or refreshes.
+ *
+ * Plugins should stop any long-running processes and clean up internal state.
+ */
+ void onReset();
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/9961d9e5/framework/src/org/apache/cordova/api/Plugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/Plugin.java b/framework/src/org/apache/cordova/api/Plugin.java
index 84b67e0..c27b1e5 100755
--- a/framework/src/org/apache/cordova/api/Plugin.java
+++ b/framework/src/org/apache/cordova/api/Plugin.java
@@ -23,6 +23,8 @@ import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Intent;
+import android.util.Log;
+
/**
* Plugin interface must be implemented by any plugin classes.
*
@@ -215,4 +217,14 @@ public abstract class Plugin implements IPlugin {
public void error(String message, String callbackId) {
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message), callbackId);
}
+
+ /**
+ * Called when the WebView does a top-level navigation or refreshes.
+ *
+ * Plugins should stop any long-running processes and clean up internal state.
+ *
+ * Does nothing by default.
+ */
+ public void onReset() {
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/9961d9e5/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index aef6302..aaf614d 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -397,6 +397,20 @@ public class PluginManager {
return false;
}
+ /**
+ * Called when the app navigates or refreshes.
+ */
+ public void onReset() {
+ Iterator<PluginEntry> it = this.entries.values().iterator();
+ while (it.hasNext()) {
+ IPlugin plugin = it.next().plugin;
+ if (plugin != null) {
+ plugin.onReset();
+ }
+ }
+ }
+
+
private void pluginConfigurationMissing() {
LOG.e(TAG, "=====================================================================================");
LOG.e(TAG, "ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project.");