Fix Edge Navigation incorrect page index detection

Swiping from the left edge on a new tab before the
page loads, could some times leave edge navigation
in a bad state. This was because there was no
history for that tab.

Also added minor fix for download paths and file names

Change-Id: I94c94363275ceeb59b9d7756e728b535e3eaa32a
diff --git a/src/com/android/browser/DownloadSettings.java b/src/com/android/browser/DownloadSettings.java
index 99be356..0f91a0c 100644
--- a/src/com/android/browser/DownloadSettings.java
+++ b/src/com/android/browser/DownloadSettings.java
@@ -205,7 +205,7 @@
         public void onClick(View v) {
             filenameBase = getFilenameBaseFromUserEnter();
             // check the filename user enter is null or not
-            if (filenameBase.length() <= 0) {
+            if (TextUtils.isEmpty(filenameBase) || TextUtils.isEmpty(downloadPath)) {
                 DownloadHandler.showFilenameEmptyDialog(DownloadSettings.this);
                 return;
             }
diff --git a/src/com/android/browser/EdgeSwipeController.java b/src/com/android/browser/EdgeSwipeController.java
index c82daa7..5d6edd5 100644
--- a/src/com/android/browser/EdgeSwipeController.java
+++ b/src/com/android/browser/EdgeSwipeController.java
@@ -39,6 +39,7 @@
 import android.view.View;
 
 import org.codeaurora.swe.WebHistoryItem;
+import org.codeaurora.swe.WebView;
 import org.codeaurora.swe.util.Activator;
 import org.codeaurora.swe.util.Observable;
 
@@ -257,13 +258,21 @@
         }.start();
     }
 
+    private int lastCommittedHistoryIndex() {
+        WebView wv = mActiveTab.getWebView();
+        if (wv == null || wv.getLastCommittedHistoryIndex() == -1)
+            return 0; // WebView is null or No History has been committed for this tab
+        else
+            return wv.getLastCommittedHistoryIndex();
+    }
+
     private void monitorProgressAtHistoryUpdate(final int pageIndex) {
         if (mCommitTimer != null) {
             mCommitTimer.cancel();
         }
 
         if (mTitleBar.getProgressView().getProgressPercent() >= mMinProgress
-                && mActiveTab.getWebView().getLastCommittedHistoryIndex() == pageIndex) {
+                && lastCommittedHistoryIndex() == pageIndex) {
             swipeSessionCleanup();
             return;
         }
@@ -465,7 +474,9 @@
 
     public void onEdgeTouched (int edgeFlags, int pointerId) {
         synchronized (this) {
-            if (mActiveTab.isPrivateBrowsingEnabled() || mActiveTab.isKeyboardShowing()) {
+            if (mActiveTab.getWebView() == null ||
+                mActiveTab.isPrivateBrowsingEnabled() ||
+                mActiveTab.isKeyboardShowing()) {
                 mDragHelper.abort();
                 return;
             }
@@ -478,7 +489,7 @@
             mView.init();
 
             if (mCurrIndex == EDGE_SWIPE_INVALID_INDEX) {
-                mCurrIndex = mActiveTab.getWebView().getLastCommittedHistoryIndex();
+                mCurrIndex = lastCommittedHistoryIndex();
             }
 
             mMaxIndex = mActiveTab.getWebView().copyBackForwardList().getSize() - 1;