Bug 228943 - Partially revert r280256 behavior change since it broke Facetime
Summary: Partially revert r280256 behavior change since it broke Facetime
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on: 225997
Blocks:
  Show dependency treegraph
 
Reported: 2021-08-09 22:05 PDT by Yusuke Suzuki
Modified: 2021-08-11 10:25 PDT (History)
9 users (show)

See Also:


Attachments
Patch (5.20 KB, patch)
2021-08-09 22:09 PDT, Yusuke Suzuki
mark.lam: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (10.96 KB, patch)
2021-08-09 23:34 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (10.94 KB, patch)
2021-08-09 23:47 PDT, Yusuke Suzuki
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2021-08-09 22:05:25 PDT
Partially revert r280256 behavior change since it broke Facetime
Comment 1 Yusuke Suzuki 2021-08-09 22:09:37 PDT
Created attachment 435242 [details]
Patch
Comment 2 Yusuke Suzuki 2021-08-09 22:09:39 PDT
<rdar://problem/81700268>
Comment 3 Mark Lam 2021-08-09 22:26:32 PDT
Comment on attachment 435242 [details]
Patch

r=me
Comment 4 Yusuke Suzuki 2021-08-09 22:45:07 PDT
If we perform `location.replace` from iframe for the top-level window with app link (facetime-open-link://...), before this change, it prompted the window to open it in app. But now, this won't happen.
Comment 5 Yusuke Suzuki 2021-08-09 22:51:52 PDT
I'll also revert two tests because the semantics is reverted now.
Comment 6 Yusuke Suzuki 2021-08-09 23:34:33 PDT
Created attachment 435244 [details]
Patch
Comment 7 Yusuke Suzuki 2021-08-09 23:47:07 PDT
Created attachment 435245 [details]
Patch
Comment 8 Yusuke Suzuki 2021-08-10 01:25:42 PDT
Committed r280826 (240389@main): <https://commits.webkit.org/240389@main>
Comment 9 Geoffrey Garen 2021-08-10 10:11:44 PDT
Comment on attachment 435245 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=435245&action=review

> Source/WebCore/ChangeLog:19
> +        We revert the semantic change by using ActiveWindow for replace, assign, and reload. This is
> +        not the correct semantics from the spec, but this is the same to one before r280256, and we
> +        will change this once we find the way to bypass this issue.

Are you sure this is not the correct semantics?

My understanding from recently reading the spec for the Location object is that it is very special, and it uses a different window than most APIs use, for backwards-compatibility.
Comment 10 Geoffrey Garen 2021-08-10 10:17:05 PDT
Specifically, URL parsing is specified to use the entry settings object, which is the the *bottom* of the JS stack, where execution began:

> The href attribute's setter must run these steps:

> If this Location object's relevant Document is null, then return.

> Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception.

> Location-object navigate given the resulting URL record.
Comment 11 Alexey Shvayka 2021-08-10 10:34:36 PDT
(In reply to Geoffrey Garen from comment #10)
> Specifically, URL parsing is specified to use the entry settings object,
> which is the the *bottom* of the JS stack, where execution began:

Yeah, that's why FirstWindow (which is implemented by VMEntryScope) is passed: to complete the URL.

IncumbentWindow comes into play a little later: please see step 2 of https://html.spec.whatwg.org/multipage/history.html#location-object-navigate, for security checks and `document.referrer`.

It's normative description (https://html.spec.whatwg.org/multipage/webappapis.html#topmost-script-having-execution-context) is precisely what CallFrame::globalObjectOfClosestCodeBlock() implements: closest (in stack) userland caller function or module / global code.

Also, adjusted LayoutTests were matching Gecko and Blink before r280826.

With high degree of certainty, I believe using IncumbentWindow is the correct semantics, which was temporarily reverted until we figure out why FaceTime is broken.
Comment 12 Alexey Shvayka 2021-08-10 10:37:06 PDT
(In reply to Geoffrey Garen from comment #9)
> My understanding from recently reading the spec for the Location object is
> that it is very special, and it uses a different window than most APIs use,
> for backwards-compatibility.

That's true, most APIs use ActiveWindow, but Location is special.
Comment 13 Yusuke Suzuki 2021-08-10 12:42:43 PDT
Comment on attachment 435245 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=435245&action=review

>> Source/WebCore/ChangeLog:19
>> +        will change this once we find the way to bypass this issue.
> 
> Are you sure this is not the correct semantics?
> 
> My understanding from recently reading the spec for the Location object is that it is very special, and it uses a different window than most APIs use, for backwards-compatibility.

Yes, Location's spec states that we need to use ImcumbentWindow (while the usual APIs typically use ActiveWindow).
https://html.spec.whatwg.org/multipage/history.html#location-object-navigate
Comment 14 Geoffrey Garen 2021-08-10 12:47:20 PDT
Got it. Thanks for the explanation!
Comment 15 Geoffrey Garen 2021-08-10 12:59:27 PDT
I wonder if the incompatibility is caused by the fact that DOMWindow::setLocation expects to be passed the active window:

    void DOMWindow::setLocation(DOMWindow& activeWindow, const URL& completedURL, SetLocationLocking locking)

Since the passed-in window is the window that we will navigate, it seems appropriate to use the active window (the callee's window) rather than the incumbent window (the caller's window).

Side note: The spec name for 'active window' appears to be 'current window': https://html.spec.whatwg.org/#concept-current-everything.
Comment 16 Chris Dumez 2021-08-10 14:05:12 PDT
(In reply to Geoffrey Garen from comment #15)
> I wonder if the incompatibility is caused by the fact that
> DOMWindow::setLocation expects to be passed the active window:
> 
>     void DOMWindow::setLocation(DOMWindow& activeWindow, const URL&
> completedURL, SetLocationLocking locking)
> 
> Since the passed-in window is the window that we will navigate, it seems
> appropriate to use the active window (the callee's window) rather than the
> incumbent window (the caller's window).
> 
> Side note: The spec name for 'active window' appears to be 'current window':
> https://html.spec.whatwg.org/#concept-current-everything.

I am with Geoff on this, I think we're simply navigating the wrong window. As per:

- https://html.spec.whatwg.org/#dom-location-href
We use the first (aka entry) window for relative URL resolution.

- https://html.spec.whatwg.org/#location-object-navigate
We navigate the current (aka active) window

- https://html.spec.whatwg.org/#navigate
We use the incumbent window for the security check (allowed to navigate).
Comment 17 Alexey Shvayka 2021-08-11 10:25:54 PDT
(In reply to Geoffrey Garen from comment #15)
> I wonder if the incompatibility is caused by the fact that
> DOMWindow::setLocation expects to be passed the active window:
> 
>     void DOMWindow::setLocation(DOMWindow& activeWindow, const URL&
> completedURL, SetLocationLocking locking)
> 
> Since the passed-in window is the window that we will navigate, it seems
> appropriate to use the active window (the callee's window) rather than the
> incumbent window (the caller's window).

Please note that DOMWindow::setLocation() navigates this->frame(), while first parameter is used for security checks, outgoingReferrer(), and as initiating document for NavigationScheduler::scheduleLocationChange() (all seems to be according to https://html.spec.whatwg.org/#navigate).

this->frame() here would be the same as ActiveWindow, so I guess we navigate the correct window. Otherwise, we would see a lot of test failures.

However, it might be that we are overusing the first parameter of setLocation(); maybe it's something related to navigation policy. I will keep digging and keep you posted.