Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(947)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/JsResultHandler.java

Issue 10823340: [Android] Upstream Modal Dialogs functionality (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/JsResultHandler.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/JsResultHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/JsResultHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..09bef6b05e177cb049fd7da431ea4a9820c56be5
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/JsResultHandler.java
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.content.browser.JsResultReceiver;
+import org.chromium.content.browser.JsPromptResultReceiver;
+
+public class JsResultHandler implements JsResultReceiver, JsPromptResultReceiver {
+ private int mNativeDialogPointer;
+ private boolean mSentResult;
+ private boolean mClientCalledConfirmOrCancel;
+
+ @CalledByNative
+ public static JsResultHandler create(int nativeDialogPointer) {
+ return new JsResultHandler(nativeDialogPointer);
+ }
+
+ private JsResultHandler(int nativeDialogPointer) {
+ mNativeDialogPointer = nativeDialogPointer;
+ }
+
+ /**
+ * Called by native when the embedder returns false from WebChromeClient.onJs*
+ * (i.e. to indicate that the framework should handle the dialog). Setting this
+ * flag means that no matter what the user does with this JsResult, we won't pay
+ * attention to it as we are going to invoke the built in handler.
+ */
+ @CalledByNative
+ private void setHandledByNative() {
+ mSentResult = true;
+ }
+
+ /**
+ * @return Whether confirm() or cancel() has been called before this function is called.
+ * If true, when setJsResultHandledByNative is called, this dismisses the dialog to
+ * warn about the wrong usage of the API.
+ */
+ @CalledByNative
+ private boolean clientHasCalledConfirmOrCancel() {
+ return mClientCalledConfirmOrCancel;
+ }
+
+ @Override
+ public void confirm() {
+ confirm(null);
+ }
+
+ @Override
+ public void confirm(String promptResult) {
+ if (mSentResult || mClientCalledConfirmOrCancel) return;
+
+ mClientCalledConfirmOrCancel = true;
+ nativeConfirmJsResult(mNativeDialogPointer, promptResult);
+ }
+
+ @Override
+ public void cancel() {
+ if (mSentResult || mClientCalledConfirmOrCancel) return;
+
+ mClientCalledConfirmOrCancel = true;
+ nativeCancelJsResult(mNativeDialogPointer);
+ }
+
+ private native void nativeConfirmJsResult(int dialogPointer, String promptResult);
+ private native void nativeCancelJsResult(int dialogPointer);
+}

Powered by Google App Engine
This is Rietveld 408576698