Skip to content

Commit

Permalink
Bug 1647883: Part 1 - Remove hashCode and equals overrides from Gecko…
Browse files Browse the repository at this point in the history
…Session in favour of new, package-scoped GeckoSession.equalsId method; r=geckoview-reviewers,agi

Because `GeckoSession`'s overrides of `hashCode` and `equals` look solely at session ID, this may cause
strange behaviors if a `GeckoSession` is reloaded with session state from a previous instance, and the
previous instance still exists. For example, suppose the previous instance is closed and the new instance is
open. As far as the Android runtime is concerned, both objects are equivalent. Trying to insert both objects
into the same container will not work as expected.

In this patch, we revert those overrides. To ensure that we still have a short-circuit path in
`GeckoView.restoreSession`, we add and utilize a new, `package`-scoped, `equalsId` method.

Differential Revision: https://phabricator.services.mozilla.com/D81746
  • Loading branch information
dblohm7 committed Jun 30, 2020
1 parent ca3f481 commit 2790f07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1333,16 +1333,12 @@ public GeckoSession[] newArray(final int size) {
}
};

@Override
@AnyThread
public int hashCode() {
return mId.hashCode();
}
/* package */ boolean equalsId(final GeckoSession other) {
if (other == null) {
return false;
}

@Override
@AnyThread
public boolean equals(final Object obj) {
return obj instanceof GeckoSession && mId.equals(((GeckoSession) obj).mId);
return mId.equals(other.mId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ protected void onRestoreInstanceState(final Parcelable state) {
}

private void restoreSession(final @Nullable GeckoSession savedSession) {
if (savedSession == null || savedSession.equals(mSession)) {
if (savedSession == null || savedSession.equalsId(mSession)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ exclude: true

⚠️ breaking change and deprecation notices

## v80
- Removed `GeckoSession.hashCode` and `GeckoSession.equals` overrides in favor
of the default implementations. ([bug 1647883]({{bugzilla}}1647883))

## v79
- Added `runtime.openOptionsPage` support. For `options_ui.open_in_new_tab` ==
`false`, [`TabDelegate.onOpenOptionsPage`][79.1] is called.
Expand Down

0 comments on commit 2790f07

Please sign in to comment.