Bug 191643 - Setting document.title should have no effect for non SVG/HTML documents
Summary: Setting document.title should have no effect for non SVG/HTML documents
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Rob Buis
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-11-14 11:27 PST by Rob Buis
Modified: 2018-11-19 12:44 PST (History)
7 users (show)

See Also:


Attachments
Patch (2.28 KB, patch)
2018-11-14 11:32 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (4.30 KB, patch)
2018-11-16 07:55 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (4.08 KB, patch)
2018-11-16 09:50 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (4.74 KB, patch)
2018-11-16 10:27 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (6.11 KB, patch)
2018-11-19 02:49 PST, Rob Buis
no flags Details | Formatted Diff | Diff
Patch (6.10 KB, patch)
2018-11-19 10:44 PST, 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 2018-11-14 11:27:17 PST
Setting document.title should have no effect for non SVG/HTML documents, see https://html.spec.whatwg.org/multipage/dom.html#document.title.
Comment 1 Rob Buis 2018-11-14 11:32:50 PST
Created attachment 354840 [details]
Patch
Comment 2 Rob Buis 2018-11-16 05:58:50 PST
Chromium bug is crbug.com/906038.
Comment 3 Rob Buis 2018-11-16 07:55:01 PST
Created attachment 355060 [details]
Patch
Comment 4 Chris Dumez 2018-11-16 08:33:59 PST
Comment on attachment 355060 [details]
Patch

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

> Source/WebCore/ChangeLog:11
> +        Behavior matches Firefox.

What's Chrome behavior?

> Source/WebCore/dom/Document.cpp:1583
> +    ASSERT(!m_titleElement || isHTMLDocument() || isXHTMLDocument() || isSVGDocument());

Not sure how useful this assertion is.

> Source/WebCore/dom/Document.cpp:1597
>          }

else
    return;

> Source/WebCore/dom/Document.cpp:1600
>      if (is<HTMLTitleElement>(m_titleElement.get()))

I think we can get rid of all these if checks and simply do:
m_titleElement->setTextContent(title);
Comment 5 Rob Buis 2018-11-16 09:49:54 PST
Comment on attachment 355060 [details]
Patch

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

>> Source/WebCore/ChangeLog:11
>> +        Behavior matches Firefox.
> 
> What's Chrome behavior?

Same as WebKit. I am preparing a patch on chromium side to implement the new behavior (https://chromium-review.googlesource.com/c/chromium/src/+/1339959).

>> Source/WebCore/dom/Document.cpp:1583
>> +    ASSERT(!m_titleElement || isHTMLDocument() || isXHTMLDocument() || isSVGDocument());
> 
> Not sure how useful this assertion is.

This is maybe the controversial (and optional) part of the patch. If you read the FIXME, it is clear we suspect the old code is not useful anymore (setting m_titleElement to nullptr). I think m_titleElement will only be set for html/svg/xhtml case, so no need to set it to nullptr  
for other document types (like xml). So to play it safe I wanted to keep the check as an ASSERT, but fine to leave it out of the patch as well. Or we can just keep setting m_titleElement to nullptr to play it safe, but it does look a bit silly. My feeling is to go for removing it.

>> Source/WebCore/dom/Document.cpp:1597
>>          }
> 
> else
>     return;

Done.

>> Source/WebCore/dom/Document.cpp:1600
>>      if (is<HTMLTitleElement>(m_titleElement.get()))
> 
> I think we can get rid of all these if checks and simply do:
> m_titleElement->setTextContent(title);

I like it! Done.
Comment 6 Rob Buis 2018-11-16 09:50:38 PST
Created attachment 355069 [details]
Patch
Comment 7 Chris Dumez 2018-11-16 09:52:16 PST
Comment on attachment 355069 [details]
Patch

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

> LayoutTests/imported/w3c/ChangeLog:8
> +        * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-10.html: Added.

Aren't you missing the -expected.txt ? Unlike Blink, I believe WebKit still relies on them.
Comment 8 Rob Buis 2018-11-16 10:26:50 PST
Comment on attachment 355069 [details]
Patch

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

>> LayoutTests/imported/w3c/ChangeLog:8
>> +        * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-10.html: Added.
> 
> Aren't you missing the -expected.txt ? Unlike Blink, I believe WebKit still relies on them.

Well spotted, will fix.
Comment 9 Rob Buis 2018-11-16 10:27:45 PST
Created attachment 355072 [details]
Patch
Comment 10 Chris Dumez 2018-11-16 10:30:01 PST
Comment on attachment 355072 [details]
Patch

r=me if the bots are happy.
Comment 11 Rob Buis 2018-11-19 02:49:16 PST
Created attachment 355261 [details]
Patch
Comment 12 Rob Buis 2018-11-19 05:40:27 PST
(In reply to Chris Dumez from comment #10)
> Comment on attachment 355072 [details]
> Patch
> 
> r=me if the bots are happy.

Thanks Chris! Since your review, tkent has suggested another subtest and I had to change setTitle to make it work:
https://chromium-review.googlesource.com/c/chromium/src/+/1339959

Basically I made setTitle exactly match the specification steps, which I think is not a bad thing. Can you have a quick check that the r=me still stands?
Comment 13 Chris Dumez 2018-11-19 09:08:31 PST
Comment on attachment 355261 [details]
Patch

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

> Source/WebCore/dom/Document.cpp:1590
> +    } else if (element && element->isHTMLElement()) {

is<HTMLElement>(element)
Comment 14 Rob Buis 2018-11-19 10:44:38 PST
Created attachment 355286 [details]
Patch
Comment 15 WebKit Commit Bot 2018-11-19 12:43:01 PST
Comment on attachment 355286 [details]
Patch

Clearing flags on attachment: 355286

Committed r238377: <https://trac.webkit.org/changeset/238377>
Comment 16 WebKit Commit Bot 2018-11-19 12:43:03 PST
All reviewed patches have been landed.  Closing bug.
Comment 17 Radar WebKit Bug Importer 2018-11-19 12:44:33 PST
<rdar://problem/46172624>