Bug 55370

Summary: [Qt] QWebView fails to load first page with an Anchor
Product: WebKit Reporter: Andy Nichols <andy.nichols>
Component: Page LoadingAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: aparna.nand, benjamin, cmarcelo, kling
Priority: P2 Keywords: Qt, QtTriaged
Version: 420+   
Hardware: PC   
OS: All   
Attachments:
Description Flags
Test case code none

Description Andy Nichols 2011-02-28 05:50:45 PST
If when using QWebView::setUrl() for the first time the URL contains an anchor(ex. #something) then the QWebView will fail to update.  For example:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWebView webView;
    webView.show();
    webView.setUrl(QUrl(QString::fromLatin1("http://doc.qt.nokia.com/4.7/qcombobox.html")));
    return a.exec();
}

will successfully update the view to display the page, while:

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWebView webView;
    webView.show();
    webView.setUrl(QUrl(QString::fromLatin1("http://doc.qt.nokia.com/4.7/qcombobox.html#itemDelegate")));
    return a.exec();
}

Will not update the webview at all.

Calling QWebView::load(QUrl(QString::fromLatin1("http://doc.qt.nokia.com/4.7/qcombobox.html#itemDelegate")));
does work however, but the inconsistency of behavior when using anchors with QWebView::setUrl(...) is cause for concernt.

Also not that the following also works:
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWebView webView;
    webView.show();
    webView.setUrl(QUrl(QString::fromLatin1("http://doc.qt.nokia.com/4.7/qcombobox.html#itemDelegate")));
    webView.setUrl(QUrl(QString::fromLatin1("http://doc.qt.nokia.com/4.7/qcombobox.html#itemDelegate")));
    return a.exec();
}

It is worth noting that in FrameLoader::loadWithDocumentLoader(DocumentLoader* loader, FrameLoadType type, PassRefPtr<FormState> prpFormState), WebCore/loader/FrameLoader.cpp:2077
if (shouldScrollToAnchor(isFormSubmission, policyChecker()->loadType(), newURL))
returns true for the first call to setUrl above
and false for the second.

Also, the Version of Webkit used is the one included with the Qt Master branch
Comment 1 Benjamin Poulain 2011-02-28 07:17:43 PST
Created attachment 84055 [details]
Test case code
Comment 2 Aparna Nandyal 2011-03-01 03:43:42 PST
This bug is same as https://bugs.webkit.org/show_bug.cgi?id=32723

The root cause of the problem is same in both cases, the calls to 

d->frame->loader()->activeDocumentLoader()->writer()->begin(absolute);
d->frame->loader()->activeDocumentLoader()->writer()->end();

in QWebFrame::setUrl is causing this problem. Im looking into another bug (https://bugs.webkit.org/show_bug.cgi?id=54380) that will possibly refactor this code.
Comment 3 Benjamin Poulain 2011-03-01 04:09:00 PST

*** This bug has been marked as a duplicate of bug 32723 ***