Bug 106908

Summary: [GTK] Click on an anchor link makes page title dissappear
Product: WebKit Reporter: Manuel Rego Casasnovas <rego>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: cgarcia, mrobinson, pnormand, webkit.review.bot, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Example HTML file to reproduce the issue
none
Patch
none
Patch
none
Patch none

Description Manuel Rego Casasnovas 2013-01-15 08:08:18 PST
Created attachment 182776 [details]
Example HTML file to reproduce the issue

Overview: In GtkLauncher if you go to a page with anchors and you click in one of them, the page title is set to NULL and you only see the text " - WebKit Launcher"

Steps to Reproduce:
1) Open the attached HTML page in GtkLauncher. Page title is "My page title - WebKit Launcher"
2) Click on the link with the text "this anchor link"

Actual Results: Page title is set to " - WebKit Launcher"

Expected Results: Page title is still "My page title - WebKit Launcher"
Comment 1 Manuel Rego Casasnovas 2013-01-15 08:18:22 PST
Created attachment 182779 [details]
Patch
Comment 2 Martin Robinson 2013-01-22 07:38:22 PST
Comment on attachment 182779 [details]
Patch

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

> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:856
> -    priv->title = NULL;
> +    priv->title = g_strdup(core(m_frame)->loader()->activeDocumentLoader()->title().string().utf8().data());

I'm not sure this is valid. The new title isn't necessarily available when a new load is committed. There's another FrameLoader messages that deals with titles. Perhaps what this is doing is resetting the title to the original value? it also makes sense to check the WebKit2 behavior.
Comment 3 Manuel Rego Casasnovas 2013-01-22 13:36:53 PST
(In reply to comment #2)
> (From update of attachment 182779 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=182779&action=review
> 
> > Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:856
> > -    priv->title = NULL;
> > +    priv->title = g_strdup(core(m_frame)->loader()->activeDocumentLoader()->title().string().utf8().data());
> 
> I'm not sure this is valid. The new title isn't necessarily available when a new load is committed. There's another FrameLoader messages that deals with titles. Perhaps what this is doing is resetting the title to the original value? it also makes sense to check the WebKit2 behavior.

I agree that the title could not be available at this point yet, but in these cases FrameLoaderClient::dispatchDidReceiveTitle will be called when it is available and the title will be updated accordingly.

The problem is in this particular case. When you click on an anchor, FrameLoaderClient::dispatchDidCommitLoad is called from FrameLoaderClient::dispatchDidNavigateWithinPage. Then FrameLoaderClient::dispatchDidCommitLoad resets title to NULL, however FrameLoaderClient::dispatchDidReceiveTitle is not called (as title is not received again).

About how it works in WK2, it's quite different as when you click on an anchor the method WebPageProxy::didSameDocumentNavigationForFrame is called. And it requests to update the URL but not the page title, moreover it doesn't reset the title property either.

Not sure about the best approach to fix the issue, any idea is welcomed :-)
Comment 4 Martin Robinson 2013-01-22 14:15:30 PST
The right thing to do here seems to be to to not set the title to NULL for navigation within the page.
Comment 5 Manuel Rego Casasnovas 2013-01-23 02:25:17 PST
Created attachment 184184 [details]
Patch
Comment 6 Martin Robinson 2013-01-23 06:09:54 PST
Comment on attachment 184184 [details]
Patch

Instead of adding new state to the FrameLoaderClient, wouldn't it be simpler to abstract the shared logic of dispatchDidCommitLoad into a helper method and simply keep clearing the title in dispatchDidCommitLoad?
Comment 7 Manuel Rego Casasnovas 2013-01-23 08:06:11 PST
Created attachment 184239 [details]
Patch
Comment 8 Martin Robinson 2013-01-23 08:30:57 PST
Comment on attachment 184239 [details]
Patch

Okay. Looks good. Did you run the unit tests? In the future you probably want to avoid the usage of booleans [1], but for this change it's probably okay.

1. See the WebKit style guide where it says: "Prefer enums to bools on function parameters if callers are likely to be passing constants, since named constants are easier to read at the call site. An exception to this rule is a setter function, where the name of the function already makes clear what the boolean is."
Comment 9 Manuel Rego Casasnovas 2013-01-23 09:03:38 PST
(In reply to comment #8)
> (From update of attachment 184239 [details])
> Okay. Looks good. Did you run the unit tests?

Yes, they gave me the same results than without my patch.

>In the future you probably want to avoid the usage of booleans [1], but for this change it's probably okay.

I agree that it's better to use enums, I've read the coding style guidelines but I didn't remember all of them yet :-) Anyway in this case, for a private method I think it's not so important as when you have a public method that could be called from somewhere else.

I can include a new enum if you prefer. Let me know.
Comment 10 WebKit Review Bot 2013-01-23 11:15:21 PST
Comment on attachment 184239 [details]
Patch

Clearing flags on attachment: 184239

Committed r140557: <http://trac.webkit.org/changeset/140557>
Comment 11 WebKit Review Bot 2013-01-23 11:15:24 PST
All reviewed patches have been landed.  Closing bug.