cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject [07/32] git commit: 1. Removed timers logic while loading Urls. Timers were creating threads to check for errors. That was causing crashes while navigating back and forth. Also, fixed handleDestroy() method to fix NPE while hitting back button. 2.Revert
Date Mon, 03 Feb 2014 20:26:08 GMT
1. Removed timers logic while loading Urls. Timers were creating threads to check for errors.
That was causing crashes while navigating back and forth.
Also, fixed handleDestroy() method to fix NPE while hitting back button.
2.Revert "Add Timeout Tests"
3.Implementation of Cordova delegate priority system
4.Fix for fileAccess on gen5 devices
5.Fix for potential AWV call outside UIthread


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

Branch: refs/heads/3.4.x
Commit: b5b89dcf1961c9c15c11ad3f9efe6a664e4d2a83
Parents: d1b288b
Author: Archana Naik <naika@lab126.com>
Authored: Mon Jan 13 15:46:31 2014 -0800
Committer: Archana Naik <naika@lab126.com>
Committed: Mon Feb 3 11:09:46 2014 -0800

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java  | 56 +++--------
 .../src/org/apache/cordova/PluginEntry.java     | 25 ++++-
 .../src/org/apache/cordova/PluginManager.java   | 89 +++++++++++++-----
 test/AndroidManifest.xml                        | 10 --
 test/res/xml/config.xml                         |  6 +-
 .../cordova/test/junit/CordovaTimeoutTest.java  | 99 --------------------
 test/src/org/apache/cordova/test/loadurl.java   | 13 ---
 7 files changed, 100 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index f06c66d..b26d4b8 100755
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -335,7 +335,8 @@ public class CordovaWebView extends AmazonWebView {
         
         // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
         // while we do this
-        if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
+        if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
+            || (getWebViewBackend(this.cordova.getFactory()) == WebViewBackend.CHROMIUM))
             Level16Apis.enableUniversalAccess(settings);
         
         if (getWebViewBackend(this.cordova.getFactory()) == WebViewBackend.ANDROID) {
@@ -537,49 +538,14 @@ public class CordovaWebView extends AmazonWebView {
 
         this.url = url;
         this.pluginManager.init();
-
-
-        // Create a timeout timer for loadUrl
-        final CordovaWebView me = this;
-        final int currentLoadUrlTimeout = me.loadUrlTimeout;
-        final int loadUrlTimeoutValue = Integer.parseInt(this.getProperty("LoadUrlTimeoutValue",
"20000"));
-
-        // Timeout error method
-        final Runnable loadError = new Runnable() {
-            public void run() {
-                me.stopLoading();
-                LOG.e(TAG, "CordovaWebView: TIMEOUT ERROR!");
-                if (viewClient != null) {
-                    viewClient.onReceivedError(me, -6, "The connection to the server was
unsuccessful.", url);
-                }
-            }
-        };
-
-        // Timeout timer method
-        final Runnable timeoutCheck = new Runnable() {
-            public void run() {
-                try {
-                    synchronized (this) {
-                        wait(loadUrlTimeoutValue);
-                    }
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-
-                // If timeout, then stop loading and handle error
-                if (me.loadUrlTimeout == currentLoadUrlTimeout) {
-                    me.cordova.getActivity().runOnUiThread(loadError);
-                }
-            }
-        };
-
-        // Load url
+        
+        // Got rid of the timers logic to check for errors/non-responding webpages.
+        // Timers were creating threading issues and NPE in some cases where app needed to
load more urls or navigate back and forth a lot.
+        // PS. this change exists only on amazon-fireos platform.
         this.cordova.getActivity().runOnUiThread(new Runnable() {
-            public void run() {
-                Thread thread = new Thread(timeoutCheck);
-                thread.start();
-                me.loadUrlNow(url);
-            }
+        	public void run() {
+        	    CordovaWebView.this.loadUrlNow(url);
+        	}
         });
     }
 
@@ -624,7 +590,6 @@ public class CordovaWebView extends AmazonWebView {
         this.loadUrlIntoView(url);
     }
     
-    
     public void onScrollChanged(int l, int t, int oldl, int oldt)
     {
         super.onScrollChanged(l, t, oldl, oldt);
@@ -945,7 +910,8 @@ public class CordovaWebView extends AmazonWebView {
     public void handleDestroy()
     {
         // Send destroy event to JavaScript
-        this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception
firing destroy event from native');};");
+        // Since baseUrl is set in loadUrlIntoView, if user hit Back button before loadUrl
was called, we'll get an NPE on baseUrl (CB-2458)
+        this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){};");
 
         // Load blank page so that JavaScript onunload is called
         this.loadUrl("about:blank");

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/framework/src/org/apache/cordova/PluginEntry.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginEntry.java b/framework/src/org/apache/cordova/PluginEntry.java
index 4f89538..b18fb0a 100755
--- a/framework/src/org/apache/cordova/PluginEntry.java
+++ b/framework/src/org/apache/cordova/PluginEntry.java
@@ -22,13 +22,11 @@ import org.apache.cordova.CordovaWebView;
 import org.apache.cordova.CordovaInterface;
 import org.apache.cordova.CordovaPlugin;
 
-//import android.content.Context;
-//import com.amazon.android.webkit.AmazonWebView;
 
 /**
  * This class represents a service entry object.
  */
-public class PluginEntry {
+public class PluginEntry implements Comparable<PluginEntry> {
 
     /**
      * The name of the service that this plugin implements
@@ -52,6 +50,15 @@ public class PluginEntry {
      */
     public boolean onload = false;
 
+	/**
+	 * The numerical priority used to determine which plugin takes precendence
+	 * in a conflict scenario with consumable webview callbacks. Note that this
+	 * is a float value, therefore decimal and negative values are supported.
+	 * The priority field represents order, and for this reason a lower value
+	 * will take precedence over a higher value.
+	 */
+	public float priority = 0;
+
     /**
      * Constructor
      *
@@ -59,10 +66,11 @@ public class PluginEntry {
      * @param pluginClass           The plugin class name
      * @param onload                Create plugin object when HTML page is loaded
      */
-    public PluginEntry(String service, String pluginClass, boolean onload) {
+    public PluginEntry(String service, String pluginClass, boolean onload, float priority)
{
         this.service = service;
         this.pluginClass = pluginClass;
         this.onload = onload;
+        this.priority = priority;
     }
 
     /**
@@ -76,6 +84,7 @@ public class PluginEntry {
         this.plugin = plugin;
         this.pluginClass = plugin.getClass().getName();
         this.onload = false;
+        this.priority = 0;
     }
 
     /**
@@ -129,4 +138,12 @@ public class PluginEntry {
         }
         return false;
     }
+
+	/**
+	 * Make PluginEntry comparable to allow for sorting by priority.
+	 */
+	@Override
+	public int compareTo(PluginEntry another) {
+		return Float.compare(this.priority, another.priority);
+	}
 }

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java
index 732f4f6..0c52542 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -20,24 +20,18 @@ package org.apache.cordova;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.cordova.CordovaArgs;
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.CallbackContext;
-import org.apache.cordova.CordovaInterface;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.PluginEntry;
-import org.apache.cordova.PluginResult;
 import org.json.JSONException;
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.Intent;
 import android.content.res.XmlResourceParser;
-
 import android.net.Uri;
 import android.os.Debug;
 import android.util.Log;
@@ -52,8 +46,8 @@ public class PluginManager {
     private static String TAG = "PluginManager";
     private static final int SLOW_EXEC_WARNING_THRESHOLD = Debug.isDebuggerConnected() ?
60 : 16;
 
-    // List of service entries
-    private final HashMap<String, PluginEntry> entries = new HashMap<String, PluginEntry>();
+    // List of service entries, sorted by priority
+    private final HashMap<String, PluginEntry> entries = new LinkedHashMap<String,
PluginEntry>();
 
     private final CordovaInterface ctx;
     private final CordovaWebView app;
@@ -123,10 +117,13 @@ public class PluginManager {
             }
         }
         XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
+        ArrayList<PluginEntry> tmpEntries = new ArrayList<PluginEntry>();
         int eventType = -1;
         String service = "", pluginClass = "", paramType = "";
+        float priority = 0;
         boolean onload = false;
         boolean insideFeature = false;
+
         while (eventType != XmlResourceParser.END_DOCUMENT) {
             if (eventType == XmlResourceParser.START_TAG) {
                 String strNode = xml.getName();
@@ -152,6 +149,13 @@ public class PluginManager {
                         pluginClass = xml.getAttributeValue(null,"value");
                     else if (paramType.equals("onload"))
                         onload = "true".equals(xml.getAttributeValue(null, "value"));
+                    else if (paramType.equals("priority")) {
+                        try {
+                            priority = Float.parseFloat(xml.getAttributeValue(null,"value"));
+                        } catch (NumberFormatException nfe) {
+                            priority = 0;
+                        }
+                    }
                 }
             }
             else if (eventType == XmlResourceParser.END_TAG)
@@ -159,12 +163,13 @@ public class PluginManager {
                 String strNode = xml.getName();
                 if (strNode.equals("feature") || strNode.equals("plugin"))
                 {
-                    PluginEntry entry = new PluginEntry(service, pluginClass, onload);
-                    this.addService(entry);
+                    PluginEntry entry = new PluginEntry(service, pluginClass, onload, priority);
+                    tmpEntries.add(entry);
 
                     //Empty the strings to prevent plugin loading bugs
                     service = "";
                     pluginClass = "";
+                    priority = 0;
                     insideFeature = false;
                 }
             }
@@ -176,6 +181,9 @@ public class PluginManager {
                 e.printStackTrace();
             }
         }
+
+        // sort and add list of items to final entries collection
+        this.addServices(tmpEntries);
     }
 
     /**
@@ -289,19 +297,56 @@ public class PluginManager {
      * @param className         The plugin class name
      */
     public void addService(String service, String className) {
-        PluginEntry entry = new PluginEntry(service, className, false);
+        PluginEntry entry = new PluginEntry(service, className, false, 0);
         this.addService(entry);
     }
 
-    /**
-     * Add a plugin class that implements a service to the service entry table.
-     * This does not create the plugin object instance.
-     *
-     * @param entry             The plugin entry
-     */
-    public void addService(PluginEntry entry) {
-        this.entries.put(entry.service, entry);
-    }
+	/**
+	 * Add a plugin class that implements a service to the service entry table.
+	 * This does not create the plugin object instance.
+	 *
+	 * @param entry
+	 *            The plugin entry
+	 */
+	public void addService(PluginEntry entry) {
+		/*
+		 * When adding a new plugin we must reconstruct and sort the list of
+		 * PluginEntries (which reside in a LinkedHashMap) to maintain its
+		 * order. Although this may not be entirely desirable, it prevents us
+		 * from having to maintain a separate sorted data structure while still
+		 * keeping the benefits of storing the objects in a HashMap.
+		 * Furthermore, this function is currently only called once during the
+		 * initialization; and so by default is a total of only two overall
+		 * sorts (one for initial config.xml parse, and another for the
+		 * PluginManager service).
+		 *
+		 * Note: this method is not thread-safe, and is planned to be improved
+		 * in future commits (along with some other thread-unsafe areas)
+		 */
+
+		// create list from existing set of plugin entries, then add new item to list
+		List<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(entries.values());
+		pluginEntries.add(entry);
+
+		// clear list and recreate final set entries in priority order
+		entries.clear();
+		this.addServices(pluginEntries);
+	}
+
+	/**
+	 * Takes a list of plugin entries which are first sorted by priority and
+	 * then individually added to the final ordered hashmap. This does not
+	 * create the plugin object instance.
+	 *
+	 * @param services
+	 *            the list of services to sort and add to final entry hash
+	 */
+	private void addServices(List<PluginEntry> services) {
+		Collections.sort(services);
+		for (PluginEntry pluginEntry : services) {
+			this.entries.put(pluginEntry.service, pluginEntry);
+		}
+	}
 
     /**
      * Called when the system is about to start resuming a previous activity.

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/test/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/test/AndroidManifest.xml b/test/AndroidManifest.xml
index 83128ff..8815624 100755
--- a/test/AndroidManifest.xml
+++ b/test/AndroidManifest.xml
@@ -256,16 +256,6 @@
                 <category android:name="android.intent.category.SAMPLE_CODE" />
             </intent-filter>
         </activity>
-        <activity
-            android:windowSoftInputMode="adjustPan"
-            android:label="@string/app_name" 
-            android:configChanges="orientation|keyboardHidden"
-            android:name="org.apache.cordova.test.loadurl" >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.intent.category.SAMPLE_CODE" />
-            </intent-filter>
-        </activity>
                 <!-- This is required for the Tests to work with AmazonWebView -->
         <amazon:enable-feature 
             android:name="com.amazon.webview" 

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/test/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/test/res/xml/config.xml b/test/res/xml/config.xml
index 6edf358..1986cff 100644
--- a/test/res/xml/config.xml
+++ b/test/res/xml/config.xml
@@ -6,11 +6,7 @@
     </description>
     <author email="dev@cordova.apache.org" href="http://cordova.io">
     </author>
-    
-    <access origin="*.apache.org"/>
-    <access origin="http://www.flickr.com/explore" />
-
-    <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
+    <access origin="*.apache.org" />
     <content src="index.html" />
     <log level="DEBUG" />
     <preference name="useBrowserHistory" value="true" />

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java b/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
deleted file mode 100644
index 6978dfc..0000000
--- a/test/src/org/apache/cordova/test/junit/CordovaTimeoutTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package org.apache.cordova.test.junit;
-
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.test.AmazonWebViewOnUiThread;
-import org.apache.cordova.test.loadurl;
-
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-
-public class CordovaTimeoutTest extends
-		ActivityInstrumentationTestCase2<loadurl> {
-
-	private int SLEEPTIME = 10000;
-	private static final String ERROR_URL = "file:///android_asset/www/htmlnotfound/error.html";
-	private static final String TEST_URL = "http://www.flickr.com/explore";
-
-	loadurl testActivity;
-	private FrameLayout containerView;
-	private LinearLayout innerContainer;
-	private CordovaWebView testView;
-
-	private AmazonWebViewOnUiThread mUiThread;
-
-	public CordovaTimeoutTest() {
-		super("org.apache.cordova.test.actions", loadurl.class);
-	}
-
-	protected void setUp() throws Exception {
-		super.setUp();
-		testActivity = this.getActivity();
-		containerView = (FrameLayout) testActivity
-				.findViewById(android.R.id.content);
-		innerContainer = (LinearLayout) containerView.getChildAt(0);
-		testView = (CordovaWebView) innerContainer.getChildAt(0);
-		mUiThread = new AmazonWebViewOnUiThread(this, testView);
-	}
-
-	public void testPreconditions() {
-		assertNotNull(innerContainer);
-		assertNotNull(testView);
-	}
-
-	/**
-	 * Verify that timeout error occurs and a error page is loaded when set.
-	 */
-	public void testTimeOutErrorOccurs() {
-		// Set the timeout value small so that error occurs
-		this.getActivity().setStringProperty("loadUrlTimeoutValue", "500");
-		this.getActivity().setStringProperty("errorUrl",
-				"file:///android_asset/www/htmlnotfound/error.html");
-		mUiThread.loadUrl(TEST_URL);
-		sleep();
-		String url = mUiThread.getUrl();
-		assertNotNull(url);
-		assertTrue(url.equals(ERROR_URL));
-	}
-
-	/**
-	 * Verify that timeout does not occur for default timeout
-	 */
-	public void testTimeOutErrorDoesNotOccur() {
-		// With default timeout= 20000ms verify error does not occur and
-		// page loads
-		this.getActivity().setStringProperty("errorUrl",
-				"file:///android_asset/www/htmlnotfound/error.html");
-		mUiThread.loadUrl(TEST_URL);
-		sleep();
-		String url = mUiThread.getUrl();
-		assertNotNull(url);
-		assertTrue(url.equals(TEST_URL));
-
-	}
-
-	/**
-	 * Verify if a error splash screen is showing when the error page is not set
-	 */
-	public void testErrorDialogShows() {
-		this.getActivity().setStringProperty("loadUrlTimeoutValue", "500");
-		mUiThread.loadUrl(TEST_URL);
-		sleep();
-		String url = mUiThread.getUrl();
-		assertNotNull(url);
-		assertFalse(this.getActivity().hasWindowFocus());
-	}
-
-	/**
-	 * Sleep to make sure URL loads completely
-	 */
-	private void sleep() {
-		try {
-			Thread.sleep(SLEEPTIME);
-		} catch (InterruptedException e) {
-			fail("Unexpected Timeout");
-		}
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/b5b89dcf/test/src/org/apache/cordova/test/loadurl.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/loadurl.java b/test/src/org/apache/cordova/test/loadurl.java
deleted file mode 100644
index deddc37..0000000
--- a/test/src/org/apache/cordova/test/loadurl.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package org.apache.cordova.test;
-
-import android.os.Bundle;
-import org.apache.cordova.*;
-
-public class loadurl extends CordovaActivity {
-	@Override
-	public void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		super.loadUrl(Config.getStartUrl());
-	}
-
-}


Mime
View raw message