OSDN Git Service

Automated import from //branches/donutburger/...@140604,140604
authorPatrick Scott <>
Wed, 25 Mar 2009 01:01:26 +0000 (18:01 -0700)
committerThe Android Open Source Project <initial-contribution@android.com>
Wed, 25 Mar 2009 01:01:26 +0000 (18:01 -0700)
src/com/android/browser/BrowserActivity.java

index bd6fdc6..f55ebb3 100644 (file)
@@ -137,7 +137,7 @@ import java.text.ParseException;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.List;
+import java.util.LinkedList;
 import java.util.Locale;
 import java.util.Vector;
 import java.util.regex.Matcher;
@@ -2938,6 +2938,73 @@ public class BrowserActivity extends Activity
                 .show();
         }
 
+        // Container class for the next error dialog that needs to be
+        // displayed.
+        class ErrorDialog {
+            public final int mTitle;
+            public final String mDescription;
+            public final int mError;
+            ErrorDialog(int title, String desc, int error) {
+                mTitle = title;
+                mDescription = desc;
+                mError = error;
+            }
+        };
+
+        private void processNextError() {
+            if (mQueuedErrors == null) {
+                return;
+            }
+            // The first one is currently displayed so just remove it.
+            mQueuedErrors.removeFirst();
+            if (mQueuedErrors.size() == 0) {
+                mQueuedErrors = null;
+                return;
+            }
+            showError(mQueuedErrors.getFirst());
+        }
+
+        private DialogInterface.OnDismissListener mDialogListener =
+                new DialogInterface.OnDismissListener() {
+                    public void onDismiss(DialogInterface d) {
+                        processNextError();
+                    }
+                };
+        private LinkedList<ErrorDialog> mQueuedErrors;
+
+        private void queueError(int err, String desc) {
+            if (mQueuedErrors == null) {
+                mQueuedErrors = new LinkedList<ErrorDialog>();
+            }
+            for (ErrorDialog d : mQueuedErrors) {
+                if (d.mError == err) {
+                    // Already saw a similar error, ignore the new one.
+                    return;
+                }
+            }
+            ErrorDialog errDialog = new ErrorDialog(
+                    err == EventHandler.FILE_NOT_FOUND_ERROR ?
+                    R.string.browserFrameFileErrorLabel :
+                    R.string.browserFrameNetworkErrorLabel,
+                    desc, err);
+            mQueuedErrors.addLast(errDialog);
+
+            // Show the dialog now if the queue was empty.
+            if (mQueuedErrors.size() == 1) {
+                showError(errDialog);
+            }
+        }
+
+        private void showError(ErrorDialog errDialog) {
+            AlertDialog d = new AlertDialog.Builder(BrowserActivity.this)
+                    .setTitle(errDialog.mTitle)
+                    .setMessage(errDialog.mDescription)
+                    .setPositiveButton(R.string.ok, null)
+                    .create();
+            d.setOnDismissListener(mDialogListener);
+            d.show();
+        }
+
         /**
          * Show a dialog informing the user of the network error reported by
          * WebCore.
@@ -2950,15 +3017,10 @@ public class BrowserActivity extends Activity
                     errorCode != EventHandler.ERROR_BAD_URL &&
                     errorCode != EventHandler.ERROR_UNSUPPORTED_SCHEME &&
                     errorCode != EventHandler.FILE_ERROR) {
-                new AlertDialog.Builder(BrowserActivity.this)
-                        .setTitle((errorCode == EventHandler.FILE_NOT_FOUND_ERROR) ?
-                                         R.string.browserFrameFileErrorLabel :
-                                         R.string.browserFrameNetworkErrorLabel)
-                        .setMessage(description)
-                        .setPositiveButton(R.string.ok, null)
-                        .show();
+                queueError(errorCode, description);
             }
-            Log.e(LOGTAG, "onReceivedError code:"+errorCode+" "+description);
+            Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
+                    + " " + description);
 
             // We need to reset the title after an error.
             resetTitleAndRevertLockIcon();