You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2012/06/07 22:20:54 UTC

[22/50] [abbrv] android commit: Optimize loading "about:blank"

Optimize loading "about:blank"


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/5c48ccd9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/5c48ccd9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/5c48ccd9

Branch: refs/heads/master
Commit: 5c48ccd92a68ec13b548f299c88311d39b846438
Parents: f74d8aa
Author: Bryce Curtis <cu...@gmail.com>
Authored: Wed May 16 23:27:19 2012 -0500
Committer: Bryce Curtis <cu...@gmail.com>
Committed: Wed May 16 23:27:19 2012 -0500

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaWebView.java     |  129 +++++++--------
 1 files changed, 64 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/5c48ccd9/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
old mode 100644
new mode 100755
index 2ff342a..308d222
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -291,15 +291,21 @@ public class CordovaWebView extends WebView {
      */
     @Override
     public void loadUrl(String url) {
-        String initUrl = this.getProperty("url", null);
-
-        // If first page of app, then set URL to load to be the one passed in
-        if (initUrl == null || (this.urls.size() > 0)) {
-            this.loadUrlIntoView(url);
+        if (url.equals("about:blank") || url.startsWith("javascript:")) {
+            this.loadUrlNow(url);
         }
-        // Otherwise use the URL specified in the activity's extras bundle
         else {
-            this.loadUrlIntoView(initUrl);
+
+            String initUrl = this.getProperty("url", null);
+
+            // If first page of app, then set URL to load to be the one passed in
+            if (initUrl == null || (this.urls.size() > 0)) {
+                this.loadUrlIntoView(url);
+            }
+            // Otherwise use the URL specified in the activity's extras bundle
+            else {
+                this.loadUrlIntoView(initUrl);
+            }
         }
     }
 
@@ -329,74 +335,67 @@ public class CordovaWebView extends WebView {
      * @param url
      */
     public void loadUrlIntoView(final String url) {
-        if (!url.startsWith("javascript:")) {
-            LOG.d(TAG, ">>> loadUrl(" + url + ")");
-
-            this.url = url;
-            if (this.baseUrl == null) {
-                int i = url.lastIndexOf('/');
-                if (i > 0) {
-                    this.baseUrl = url.substring(0, i + 1);
-                }
-                else {
-                    this.baseUrl = this.url + "/";
-                }
+        LOG.d(TAG, ">>> loadUrl(" + url + ")");
 
-                this.pluginManager.init();
+        this.url = url;
+        if (this.baseUrl == null) {
+            int i = url.lastIndexOf('/');
+            if (i > 0) {
+                this.baseUrl = url.substring(0, i + 1);
+            }
+            else {
+                this.baseUrl = this.url + "/";
+            }
 
-                if (!this.useBrowserHistory) {
-                    this.urls.push(url);
-                }
+            this.pluginManager.init();
+
+            if (!this.useBrowserHistory) {
+                this.urls.push(url);
             }
+        }
 
-            // 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);
-                    }
+        // 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.mCtx.getActivity().runOnUiThread(loadError);
+        // Timeout timer method
+        final Runnable timeoutCheck = new Runnable() {
+            public void run() {
+                try {
+                    synchronized (this) {
+                        wait(loadUrlTimeoutValue);
                     }
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
                 }
-            };
-
-            // Load url
-            this.mCtx.getActivity().runOnUiThread(new Runnable() {
-                public void run() {
-                    Thread thread = new Thread(timeoutCheck);
-                    thread.start();
-                    me.loadUrlNow(url);
+
+                // If timeout, then stop loading and handle error
+                if (me.loadUrlTimeout == currentLoadUrlTimeout) {
+                    me.mCtx.getActivity().runOnUiThread(loadError);
                 }
-            });
-        }
+            }
+        };
 
-        // If Javascript, then just load it now
-        else {
-            super.loadUrl(url);
-        }
+        // Load url
+        this.mCtx.getActivity().runOnUiThread(new Runnable() {
+            public void run() {
+                Thread thread = new Thread(timeoutCheck);
+                thread.start();
+                me.loadUrlNow(url);
+            }
+        });
     }
 
     /**