Bug 1755094 - Make autofill tree immutable. r=owlish

Before this patch, the autofill tree was mutable, which makes it hard to follow
updates and reason about state.

This change makes the autofill tree immutable and adds a separate `HashMap` to
track mutable values like `value`, `callback`.

This change also modifies the way we track nodes internally, using exclusevely
the UUID of the node rather then the int autofill ID which is now only used at
the boundary of the Autofill API.

We also simplify the API by only providing the necessary information about the
node rather than the entire tree structure.

Differential Revision: https://phabricator.services.mozilla.com/D143960
This commit is contained in:
Agi Sferro 2022-05-17 01:34:44 +00:00
Родитель 7ca6de9006
Коммит 6f503072d7
4 изменённых файлов: 685 добавлений и 724 удалений

Просмотреть файл

@ -310,7 +310,15 @@ package org.mozilla.geckoview {
}
public static interface Autofill.Delegate {
method @UiThread default public void onAutofill(@NonNull GeckoSession, int, @Nullable Autofill.Node);
method @Deprecated @DeprecationSchedule(id="autofill-node",version=104) @UiThread default public void onAutofill(@NonNull GeckoSession, int, @Nullable Autofill.Node);
method @UiThread default public void onNodeAdd(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onNodeBlur(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onNodeFocus(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onNodeRemove(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onNodeUpdate(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onSessionCancel(@NonNull GeckoSession);
method @UiThread default public void onSessionCommit(@NonNull GeckoSession, @NonNull Autofill.Node, @NonNull Autofill.NodeData);
method @UiThread default public void onSessionStart(@NonNull GeckoSession);
}
public static final class Autofill.Hint {
@ -331,7 +339,7 @@ package org.mozilla.geckoview {
}
public static final class Autofill.Node {
method @UiThread public void fillViewStructure(@NonNull View, @NonNull ViewStructure, int);
method @Deprecated @DeprecationSchedule(id="autofill-node",version=104) @UiThread public void fillViewStructure(@NonNull View, @NonNull ViewStructure, int);
method @AnyThread @Nullable public String getAttribute(@NonNull String);
method @AnyThread @NonNull public Map<String,String> getAttributes();
method @AnyThread @NonNull public Collection<Autofill.Node> getChildren();
@ -339,16 +347,21 @@ package org.mozilla.geckoview {
method @AnyThread @NonNull public String getDomain();
method @AnyThread public boolean getEnabled();
method @AnyThread public boolean getFocusable();
method @AnyThread public boolean getFocused();
method @AnyThread @Deprecated @DeprecationSchedule(id="autofill-node",version=104) public boolean getFocused();
method @AnyThread public int getHint();
method @AnyThread public int getId();
method @AnyThread @Deprecated @DeprecationSchedule(id="autofill-node",version=104) public int getId();
method @AnyThread public int getInputType();
method @AnyThread @NonNull public String getTag();
method @AnyThread @NonNull public String getValue();
method @AnyThread public boolean getVisible();
method @AnyThread @Deprecated @DeprecationSchedule(id="autofill-node",version=104) @NonNull public String getValue();
method @AnyThread @Deprecated @DeprecationSchedule(id="autofill-node",version=104) public boolean getVisible();
}
public static final class Autofill.Notify {
public static class Autofill.NodeData {
method @AnyThread public int getId();
method @AnyThread @Nullable public String getValue();
}
@Deprecated @DeprecationSchedule(id="autofill-node",version=104) public static final class Autofill.Notify {
method @AnyThread @Nullable public static String toString(int);
field public static final int NODE_ADDED = 3;
field public static final int NODE_BLURRED = 7;
@ -361,9 +374,14 @@ package org.mozilla.geckoview {
}
public static final class Autofill.Session {
method @NonNull @UiThread public Autofill.NodeData dataFor(@NonNull Autofill.Node);
method @UiThread public void fillViewStructure(@NonNull View, @NonNull ViewStructure, int);
method @AnyThread @NonNull public Rect getDefaultDimensions();
method @UiThread public void fillViewStructure(@NonNull Autofill.Node, @NonNull View, @NonNull ViewStructure, int);
method @NonNull @UiThread public Rect getDefaultDimensions();
method @Nullable @UiThread public Autofill.Node getFocused();
method @Nullable @UiThread public Autofill.NodeData getFocusedData();
method @AnyThread @NonNull public Autofill.Node getRoot();
method @UiThread public boolean isVisible(@NonNull Autofill.Node);
}
@UiThread public class BasicSelectionActionDelegate implements ActionMode.Callback GeckoSession.SelectionActionDelegate {

Просмотреть файл

@ -181,7 +181,7 @@ class AutofillDelegateTest : BaseSessionTest() {
}
}
val childId = mainSession.autofillSession.getId(child)
val childId = mainSession.autofillSession.dataFor(child)!!.id
if (childId == View.NO_ID) {
return
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -20,6 +20,12 @@ exclude: true
- Added [`GeckoSession.setPriorityHint`][102.5] function to set the session to either high priority or default.
- [`WebRequestError.ERROR_HTTPS_ONLY`][102.6] now has error category
`ERROR_CATEGORY_NETWORK` rather than `ERROR_CATEGORY_SECURITY`.
- ⚠️ The Autofill.Delegate API now receives a [`AutofillNode`][102.7] object instead of
the entire [`Node`][102.8] structure. The `onAutofill` delegate method is now split
into several methods: [`onNodeAdd`][102.9], [`onNodeBlur`][102.10],
[`onNodeFocus`][102.11], [`onNodeRemove`][102.12], [`onNodeUpdate`][102.13],
[`onSessionCancel`][102.14], [`onSessionCommit`][102.15],
[`onSessionStart`][102.16].
[102.1]: {{javadoc_uri}}/GeckoSession.PromptDelegate.DateTimePrompt.html#stepValue
[102.2]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#step
@ -27,6 +33,16 @@ exclude: true
[102.4]: {{javadoc_uri}}/GeckoSession.NavigationDelegate.html#onLocationChange(org.mozilla.geckoview.GeckoSession,java.lang.String,java.util.List)
[102.5]: {{javadoc_uri}}/GeckoSession.html#setPriorityHint(int)
[102.6]: {{javadoc_uri}}/WebRequestError.html#ERROR_HTTPS_ONLY
[102.7]: {{javadoc_uri}}/Autofill.AutofillNode.html
[102.8]: {{javadoc_uri}}/Autofill.Node.html
[102.9]: {{javadoc_uri}}/Autofill.Delegate.html#onNodeAdd(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.10]: {{javadoc_uri}}/Autofill.Delegate.html#onNodeBlur(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.11]: {{javadoc_uri}}/Autofill.Delegate.html#onNodeFocus(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.12]: {{javadoc_uri}}/Autofill.Delegate.html#onNodeRemove(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.13]: {{javadoc_uri}}/Autofill.Delegate.html#onNodeUpdate(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.14]: {{javadoc_uri}}/Autofill.Delegate.html#onSessionCancel(org.mozilla.geckoview.GeckoSession)
[102.15]: {{javadoc_uri}}/Autofill.Delegate.html#onSessionCommit(org.mozilla.geckoview.GeckoSession,org.mozilla.geckoview.Autofill.Node,org.mozilla.geckoview.Autofill.NodeData)
[102.16]: {{javadoc_uri}}/Autofill.Delegate.html#onSessionStart(org.mozilla.geckoview.GeckoSession)
## v101
- Added [`GeckoDisplay.surfaceChanged`][101.1] function taking new type [`GeckoDisplay.SurfaceInfo`][101.2].
@ -1181,4 +1197,4 @@ to allow adding gecko profiler markers.
[65.24]: {{javadoc_uri}}/CrashReporter.html#sendCrashReport(android.content.Context,android.os.Bundle,java.lang.String)
[65.25]: {{javadoc_uri}}/GeckoResult.html
[api-version]: 2f401dd976431a7a150b8743f3949a50adbeeb4b
[api-version]: dbe27cda45ed1bdff264b14f4471fdbe8438ca94