Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b8413bb authored by Victoria Lease's avatar Victoria Lease
Browse files

Make WebView.findAllAsync() and WebView.setFindListener() public.

Deprecate WebView.findAll() while we're at it.

Bug: 6052412
Change-Id: I2f7116786109b4d6a01d24ac892c13b5d1f498f4
parent 04247163
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -25685,7 +25685,8 @@ package android.webkit {
    method public deprecated void emulateShiftHeld();
    method public static deprecated void enablePlatformNotifications();
    method public static java.lang.String findAddress(java.lang.String);
    method public int findAll(java.lang.String);
    method public deprecated int findAll(java.lang.String);
    method public void findAllAsync(java.lang.String);
    method public void findNext(boolean);
    method public void flingScroll(int, int);
    method public void freeMemory();
@@ -25736,6 +25737,7 @@ package android.webkit {
    method public void saveWebArchive(java.lang.String, boolean, android.webkit.ValueCallback<java.lang.String>);
    method public void setCertificate(android.net.http.SslCertificate);
    method public void setDownloadListener(android.webkit.DownloadListener);
    method public void setFindListener(android.webkit.WebView.FindListener);
    method public void setHorizontalScrollbarOverlay(boolean);
    method public void setHttpAuthUsernamePassword(java.lang.String, java.lang.String, java.lang.String, java.lang.String);
    method public void setInitialScale(int);
@@ -25754,6 +25756,10 @@ package android.webkit {
    field public static final java.lang.String SCHEME_TEL = "tel:";
  }
  public static abstract interface WebView.FindListener {
    method public abstract void onFindResultReceived(int, int, boolean);
  }
  public static class WebView.HitTestResult {
    method public java.lang.String getExtra();
    method public int getType();
+2 −2
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
        mInput.showSoftInput(mEditText, 0);
    }

    public void updateMatchCount(int matchIndex, int matchCount, boolean isNewFind) {
        if (!isNewFind) {
    public void updateMatchCount(int matchIndex, int matchCount, boolean isEmptyFind) {
        if (!isEmptyFind) {
            mNumberOfMatches = matchCount;
            mActiveMatchIndex = matchIndex;
            updateMatchesString();
+18 −10
Original line number Diff line number Diff line
@@ -313,7 +313,6 @@ public class WebView extends AbsoluteLayout

    /**
     * Interface to listen for find results.
     * @hide
     */
    public interface FindListener {
        /**
@@ -1249,8 +1248,7 @@ public class WebView extends AbsoluteLayout
     * Register the listener to be notified as find-on-page operations progress.
     * This will replace the current listener.
     *
     * @param listener An implementation of {@link WebView#FindListener}.
     * @hide
     * @param listener An implementation of {@link FindListener}.
     */
    public void setFindListener(FindListener listener) {
        checkThread();
@@ -1258,11 +1256,15 @@ public class WebView extends AbsoluteLayout
    }

    /**
     * Highlight and scroll to the next occurance of String in findAll.
     * Wraps the page infinitely, and scrolls.  Must be called after
     * calling findAll.
     * Highlight and scroll to the next match found by {@link #findAll} or
     * {@link #findAllAsync}, wrapping around page boundaries as necessary.
     * Notifies any registered {@link FindListener}. If neither
     * {@link #findAll} nor {@link #findAllAsync(String)} has been called yet,
     * or if {@link #clearMatches} has been called since the last find
     * operation, this function does nothing.
     *
     * @param forward Direction to search.
     * @see #setFindListener
     */
    public void findNext(boolean forward) {
        checkThread();
@@ -1271,10 +1273,13 @@ public class WebView extends AbsoluteLayout

    /**
     * Find all instances of find on the page and highlight them.
     * Notifies any registered {@link FindListener}.
     *
     * @param find  String to find.
     * @return int  The number of occurances of the String "find"
     *              that were found.
     * @deprecated {@link #findAllAsync} is preferred.
     * @see #setFindListener
     */
    public int findAll(String find) {
        checkThread();
@@ -1283,10 +1288,12 @@ public class WebView extends AbsoluteLayout

    /**
     * Find all instances of find on the page and highlight them,
     * asynchronously.
     * asynchronously. Notifies any registered {@link FindListener}.
     * Successive calls to this or {@link #findAll} will cancel any
     * pending searches.
     *
     * @param find  String to find.
     * @hide
     * @see #setFindListener
     */
    public void findAllAsync(String find) {
        checkThread();
@@ -1333,8 +1340,9 @@ public class WebView extends AbsoluteLayout
        return getFactory().getStatics().findAddress(addr);
    }

    /*
     * Clear the highlighting surrounding text matches created by findAll.
    /**
     * Clear the highlighting surrounding text matches created by
     * {@link #findAll} or {@link #findAllAsync}.
     */
    public void clearMatches() {
        checkThread();
+33 −20
Original line number Diff line number Diff line
@@ -3635,7 +3635,9 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
    @Override
    public void findNext(boolean forward) {
        if (0 == mNativeClass) return; // client isn't initialized
        mWebViewCore.sendMessage(EventHub.FIND_NEXT, forward ? 1 : 0);
        if (mFindRequest != null) {
            mWebViewCore.sendMessage(EventHub.FIND_NEXT, forward ? 1 : 0, mFindRequest);
        }
    }

    /**
@@ -3652,28 +3654,26 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc

    private int findAllBody(String find, boolean isAsync) {
        if (0 == mNativeClass) return 0; // client isn't initialized
        mLastFind = find;
        mFindRequest = null;
        if (find == null) return 0;
        mWebViewCore.removeMessages(EventHub.FIND_ALL);
        WebViewCore.FindAllRequest request = new
            WebViewCore.FindAllRequest(find);
        mFindRequest = new WebViewCore.FindAllRequest(find);
        if (isAsync) {
            mWebViewCore.sendMessage(EventHub.FIND_ALL, request);
            mWebViewCore.sendMessage(EventHub.FIND_ALL, mFindRequest);
            return 0; // no need to wait for response
        }
        synchronized(request) {
        synchronized(mFindRequest) {
            try {
                mWebViewCore.sendMessageAtFrontOfQueue(EventHub.FIND_ALL,
                    request);
                while (request.mMatchCount == -1) {
                    request.wait();
                mWebViewCore.sendMessageAtFrontOfQueue(EventHub.FIND_ALL, mFindRequest);
                while (mFindRequest.mMatchCount == -1) {
                    mFindRequest.wait();
                }
            }
            catch (InterruptedException e) {
                return 0;
            }
            return mFindRequest.mMatchCount;
        }
        return request.mMatchCount;
    }

    /**
@@ -3704,7 +3704,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
            return true;
        }
        if (text == null) {
            text = mLastFind;
            text = mFindRequest == null ? null : mFindRequest.mSearchText;
        }
        if (text != null) {
            mFindCallback.setText(text);
@@ -3730,9 +3730,8 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
    // or not we draw the highlights for matches.
    private boolean mFindIsUp;

    // Keep track of the last string sent, so we can search again when find is
    // reopened.
    private String mLastFind;
    // Keep track of the last find request sent.
    private WebViewCore.FindAllRequest mFindRequest = null;

    /**
     * Return the first substring consisting of the address of a physical
@@ -8548,13 +8547,27 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
                }

                case UPDATE_MATCH_COUNT: {
                    boolean isNewFind = mLastFind == null || !mLastFind.equals(msg.obj);
                    if (mFindCallback != null)
                        mFindCallback.updateMatchCount(msg.arg1, msg.arg2, isNewFind);
                    if (mFindListener != null)
                        mFindListener.onFindResultReceived(msg.arg1, msg.arg2, true);
                    WebViewCore.FindAllRequest request = (WebViewCore.FindAllRequest)msg.obj;
                    if (request == null) {
                        if (mFindCallback != null) {
                            mFindCallback.updateMatchCount(0, 0, true);
                        }
                    } else if (request == mFindRequest) {
                        int matchCount, matchIndex;
                        synchronized (mFindRequest) {
                            matchCount = request.mMatchCount;
                            matchIndex = request.mMatchIndex;
                        }
                        if (mFindCallback != null) {
                            mFindCallback.updateMatchCount(matchIndex, matchCount, false);
                        }
                        if (mFindListener != null) {
                            mFindListener.onFindResultReceived(matchIndex, matchCount, true);
                        }
                    }
                    break;
                }

                case CLEAR_CARET_HANDLE:
                    selectionDone();
                    break;
+24 −22
Original line number Diff line number Diff line
@@ -1052,9 +1052,11 @@ public final class WebViewCore {
        public FindAllRequest(String text) {
            mSearchText = text;
            mMatchCount = -1;
            mMatchIndex = -1;
        }
        public String mSearchText;
        public final String mSearchText;
        public int mMatchCount;
        public int mMatchIndex;
    }

    /**
@@ -1789,22 +1791,33 @@ public final class WebViewCore {
                            break;
                        case FIND_ALL: {
                            FindAllRequest request = (FindAllRequest)msg.obj;
                            if (request == null) {
                                nativeFindAll(mNativeClass, null);
                            } else {
                                request.mMatchCount = nativeFindAll(
                                    mNativeClass, request.mSearchText);
                            if (request != null) {
                                int matchCount = nativeFindAll(mNativeClass, request.mSearchText);
                                int matchIndex = nativeFindNext(mNativeClass, true);
                                synchronized (request) {
                                    request.mMatchCount = matchCount;
                                    request.mMatchIndex = matchIndex;
                                    request.notify();
                                }
                            } else {
                                nativeFindAll(mNativeClass, null);
                            }
                            Message.obtain(mWebViewClassic.mPrivateHandler,
                                    WebViewClassic.UPDATE_MATCH_COUNT, request).sendToTarget();
                            break;
                        }
                        case FIND_NEXT:
                            nativeFindNext(mNativeClass, msg.arg1 != 0);
                        case FIND_NEXT: {
                            FindAllRequest request = (FindAllRequest)msg.obj;
                            int matchIndex = nativeFindNext(mNativeClass, msg.arg1 != 0);
                            synchronized (request) {
                                request.mMatchIndex = matchIndex;
                            }
                            Message.obtain(mWebViewClassic.mPrivateHandler,
                                    WebViewClassic.UPDATE_MATCH_COUNT, request).sendToTarget();
                            break;
                        }
                    }
                }
            };
            // Take all queued messages and resend them to the new handler.
            synchronized (this) {
@@ -2836,17 +2849,6 @@ public final class WebViewCore {
                .sendToTarget();
    }

    // called by JNI
    private void updateMatchCount(int matchIndex, int matchCount,
        String findText) {
        if (mWebViewClassic == null) {
            return;
        }
        Message.obtain(mWebViewClassic.mPrivateHandler,
                WebViewClassic.UPDATE_MATCH_COUNT, matchIndex, matchCount,
                findText).sendToTarget();
    }

    private native void nativeRevealSelection(int nativeClass);
    private native String nativeRequestLabel(int nativeClass, int framePtr,
            int nodePtr);
@@ -3097,7 +3099,7 @@ public final class WebViewCore {
    private native void nativeAutoFillForm(int nativeClass, int queryId);
    private native void nativeScrollLayer(int nativeClass, int layer, Rect rect);
    private native int nativeFindAll(int nativeClass, String text);
    private native void nativeFindNext(int nativeClass, boolean forward);
    private native int nativeFindNext(int nativeClass, boolean forward);

    /**
     * Deletes editable text between two points. Note that the selection may