Bug 229204

Summary: PCM: Allow measurement of links in nested, cross-site iframes
Product: WebKit Reporter: Pranay Prabhat <pranay.prabhat>
Component: WebKit Misc.Assignee: John Wilander <wilander>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, cdumez, changseok, esprehn+autocc, ews-watchlist, gyuyoung.kim, webkit-bug-importer, wilander
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Pranay Prabhat 2021-08-17 14:43:04 PDT
https://github.com/privacycg/private-click-measurement/issues/7 has highlighted the needs but for majority of publishers , ads are rendered in a secondary domain usually rendered by Google Ad Manager. PCM's click based anchor tags within secondary domain need to be propagated to publisher context in order to register the click for conversion reporting.
Comment 1 Radar WebKit Bug Importer 2021-08-24 14:44:54 PDT
<rdar://problem/82310386>
Comment 2 John Wilander 2021-10-04 15:21:04 PDT
Created attachment 440110 [details]
Patch
Comment 3 Alex Christensen 2021-10-04 15:28:29 PDT
Comment on attachment 440110 [details]
Patch

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

> Source/WebCore/html/HTMLAnchorElement.cpp:446
> +    if (frame->isMainFrame())
> +        mainDocumentRegistrableDomain = RegistrableDomain { document().url() };
> +    else if (auto mainDocument = frame->mainFrame().document())
> +        mainDocumentRegistrableDomain = RegistrableDomain { mainDocument->url() };

I think you can simplify this because Frame::mainFrame() returns itself if it's the main frame.
Comment 4 John Wilander 2021-10-04 15:35:04 PDT
(In reply to Alex Christensen from comment #3)
> Comment on attachment 440110 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=440110&action=review
> 
> > Source/WebCore/html/HTMLAnchorElement.cpp:446
> > +    if (frame->isMainFrame())
> > +        mainDocumentRegistrableDomain = RegistrableDomain { document().url() };
> > +    else if (auto mainDocument = frame->mainFrame().document())
> > +        mainDocumentRegistrableDomain = RegistrableDomain { mainDocument->url() };
> 
> I think you can simplify this because Frame::mainFrame() returns itself if
> it's the main frame.

Thanks! Will fix before landing.
Comment 5 Chris Dumez 2021-10-04 15:36:16 PDT
Comment on attachment 440110 [details]
Patch

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

>>> Source/WebCore/html/HTMLAnchorElement.cpp:446
>>> +        mainDocumentRegistrableDomain = RegistrableDomain { mainDocument->url() };
>> 
>> I think you can simplify this because Frame::mainFrame() returns itself if it's the main frame.
> 
> Thanks! Will fix before landing.

You don't even need frames, document().topDocument().url()
Comment 6 John Wilander 2021-10-04 16:26:03 PDT
(In reply to Chris Dumez from comment #5)
> Comment on attachment 440110 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=440110&action=review
> 
> >>> Source/WebCore/html/HTMLAnchorElement.cpp:446
> >>> +        mainDocumentRegistrableDomain = RegistrableDomain { mainDocument->url() };
> >> 
> >> I think you can simplify this because Frame::mainFrame() returns itself if it's the main frame.
> > 
> > Thanks! Will fix before landing.
> 
> You don't even need frames, document().topDocument().url()

I looked at the implementation of topDocument() and this part has me worried about potential misuse vectors:

if (backForwardCacheState() == NotInBackForwardCache && !m_renderTreeBeingDestroyed) {
    if (!m_frame)
        return const_cast<Document&>(*this);
    // This should always be non-null.
    Document* mainFrameDocument = m_frame->mainFrame().document();
    return mainFrameDocument ? *mainFrameDocument : const_cast<Document&>(*this);
}

I'll go with if (auto mainDocument = frame->mainFrame().document()).
Comment 7 John Wilander 2021-10-04 16:38:41 PDT
Created attachment 440122 [details]
Patch
Comment 8 John Wilander 2021-10-05 07:58:52 PDT
Created attachment 440215 [details]
Patch
Comment 9 John Wilander 2021-10-05 07:59:20 PDT
Fixed test for iOS.
Comment 10 EWS 2021-10-05 17:46:50 PDT
Committed r283593 (242549@main): <https://commits.webkit.org/242549@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 440215 [details].