Bug 210036 - Use GlobalFrameIdentifier in NavigationAction
Summary: Use GlobalFrameIdentifier in NavigationAction
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-04-05 13:35 PDT by Rob Buis
Modified: 2020-04-07 00:57 PDT (History)
5 users (show)

See Also:


Attachments
Patch (4.08 KB, patch)
2020-04-05 13:37 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (3.64 KB, patch)
2020-04-05 14:17 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (7.01 KB, patch)
2020-04-06 11:09 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (5.99 KB, patch)
2020-04-06 13:15 PDT, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (5.99 KB, patch)
2020-04-07 00:20 PDT, Rob Buis
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Buis 2020-04-05 13:35:30 PDT
Use GlobalFrameIdentifier in NavigationAction rather adding yet another custom data type.
Comment 1 Rob Buis 2020-04-05 13:37:55 PDT
Created attachment 395523 [details]
Patch
Comment 2 Rob Buis 2020-04-05 14:17:16 PDT
Created attachment 395527 [details]
Patch
Comment 3 Darin Adler 2020-04-05 15:06:57 PDT
Comment on attachment 395527 [details]
Patch

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

Some comments, not things you really must do, but all a good idea.

> Source/WebCore/loader/NavigationAction.cpp:48
> -    , m_pageIDAndFrameIDPair { document.frame() ? std::make_pair(document.frame()->loader().client().pageID().valueOr(PageIdentifier { }), document.frame()->loader().client().frameID().valueOr(FrameIdentifier { })) : std::make_pair<PageIdentifier, FrameIdentifier>({ }, { }) }
>  {
> +    if (document.frame()) {
> +        m_globalFrameIdentifier.pageID = document.frame()->loader().client().pageID().valueOr(PageIdentifier { });
> +        m_globalFrameIdentifier.frameID = document.frame()->loader().client().frameID().valueOr(FrameIdentifier { });
> +    }

Would be nice to do this with construction, not assignment. Could make a helper function or use a lambda.

Would also be nice to refactor not to repeat document.frame() and document.frame()->loader().client(). Should also investigate if we can just pass { } to valueOr without repeating the type.

> Source/WebCore/loader/NavigationAction.h:67
>      class Requester {

For future refinement: This seems much more like a struct than a class to me. As long as we pass a const Requester around, that protects us against things being changed. And then there’s no need to have both function and data members for each thing.

> Source/WebCore/loader/NavigationAction.h:74
> +        PageIdentifier pageID() const { return m_globalFrameIdentifier.pageID; }
> +        FrameIdentifier frameID() const { return m_globalFrameIdentifier.frameID; }

Consider eliminating these getters and having a GlobalFrameIdentifier getter instead. Unless it makes the code significantly uglier at the call sites.

> Source/WebCore/loader/NavigationAction.h:77
>          RefPtr<SecurityOrigin> m_origin;

This should probably be Ref<> instead of RefPtr<>.
Comment 4 Rob Buis 2020-04-06 11:09:34 PDT
Created attachment 395589 [details]
Patch
Comment 5 Darin Adler 2020-04-06 11:15:45 PDT
Comment on attachment 395589 [details]
Patch

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

> Source/WebCore/loader/NavigationAction.h:71
> +        WEBCORE_EXPORT Requester(const Requester&);
> +        Requester& operator=(const Requester&);

Would also be nice to add the move constructor and assignment operator for efficiency, otherwise we will copy even when in move contexts.

    Requester(Requester&&) = default;
    Requester& operator=(Requester&&) = default;

> Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:948
> +    if (const auto& pageID = requester.globalFrameIdentifier().pageID) {

I wouldn’t have bothered with the const here.
Comment 6 Darin Adler 2020-04-06 11:16:25 PDT
Comment on attachment 395589 [details]
Patch

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

> Source/WebCore/loader/NavigationAction.cpp:68
> +NavigationAction::Requester::Requester(const Requester& other)
> +    : m_url(other.m_url)
> +    , m_origin(other.m_origin.copyRef())
> +    , m_globalFrameIdentifier(other.m_globalFrameIdentifier)
> +{
> +}
> +
> +NavigationAction::Requester& NavigationAction::Requester::operator=(const Requester& other)
>  {
> +    m_url = other.m_url;
> +    m_origin = other.m_origin.copyRef();
> +    m_globalFrameIdentifier = other.m_globalFrameIdentifier;
> +    return *this;
>  }

Looks like making this use Ref ruined everything! The fact that you can’t copy a Ref is starting to be more annoying than helpful.
Comment 7 Rob Buis 2020-04-06 11:18:04 PDT
Should I go back to RefPtr? It does seem to add a lot of complexity when adding Ref here.
Comment 8 Darin Adler 2020-04-06 11:28:37 PDT
(In reply to Rob Buis from comment #7)
> Should I go back to RefPtr? It does seem to add a lot of complexity when
> adding Ref here.

I think so.
Comment 9 Rob Buis 2020-04-06 13:15:14 PDT
Created attachment 395608 [details]
Patch
Comment 10 EWS 2020-04-06 23:59:09 PDT
ChangeLog entry in Source/WebKit/ChangeLog contains OOPS!.
Comment 11 Rob Buis 2020-04-07 00:20:53 PDT
Created attachment 395656 [details]
Patch
Comment 12 EWS 2020-04-07 00:56:02 PDT
Committed r259629: <https://trac.webkit.org/changeset/259629>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 395656 [details].
Comment 13 Radar WebKit Bug Importer 2020-04-07 00:57:14 PDT
<rdar://problem/61381656>