WebKit's history management

Source: Internet
Author: User

Standard definition

The management of history, like HTML page loading, has its corresponding standards. The address is as follows:
WhatWG: https://html.spec.whatwg.org/multipage/browsers.html#history

Among the key points about history are the following:

1. Prior to onload, navigation operations caused by non-user actions do not establish historical entries.

Non-user actions such as the specified timer on the page modifies the navigation action that is raised by the SRC location or an iframe. When the user clicks on a timer, the timer is recorded to mark the source of the gesture when the timer is launched. But one exception is a timer initiated by another timer or a recurring timer, which is only valid for the first execution (identified at nesting level).

2. When the child frame is loaded and there is still an upper frame that is not loaded, the history item is not created.

3. If the current frame has only one history item and is About:blank, the history item is not created.

4. If the page jump interval is less than 1s, the history item is not created.


The nesting level of the timer can be consulted here:
Http://www.w3.org/html/wg/drafts/html/CR/webappapis.html#timer-nesting-level


The above rules correspond to the following three WebKit functions:

A. Lockbackforwardlist navigationscheduler::mustlockbackforwardlist (frame& targetframe)
lockbackforwardlist navigationscheduler::mustlockbackforwardlist (frame& targetframe)
{
//Non-user navigation before the page has finished firing onload should not create a new Back/forward item.
// Seehttps://webkit.org/b/42861For the original motivation.
if (! Scriptcontroller::p rocessingusergesture () && Targetframe.loader (). Documentloader () &&! Targetframe.loader (). Documentloader ()->wasonloadhandled ())
return lockbackforwardlist::yes;
   
//Navigation of a subframe during loading of a ancestor frame does not create a new Back/forward item.
//The definition of "during load" is any time before all handlers for the Load event has been run.
// Seehttps://bugs.webkit.org/show_bug.cgi?id=14957For the original motivation.
For (frame* ancestor = Targetframe.tree (). parent (); ancestor; ancestor = Ancestor->tree (). Parent ()) {
document* Document = Ancestor->document ();
if (!ancestor->loader (). Iscomplete () | | (Document && Document->processingloadevent ()))
return lockbackforwardlist::yes;
    }
return lockbackforwardlist::no;
}


B. historycontroller::currentitemshouldbereplaced () const
{
//From the HTML5 spec for location.assign ():
//"If The browsing context ' s session history contains only one Document,
//And that is theAbout:blankDocument created when the browsing context
//was created and then the navigation must is done with replacement enabled. "
return m_currentitem &&!m_previousitem && equalignoringcase (m_currentitem->urlstring (), Blankurl ());
}


c. void Navigationscheduler::scheduleredirect (double delay, const url& URL)
{
if (!shouldschedulenavigation (URL))
return;
if (Delay < 0 | | delay > int_max/1000)
return;
if (Url.isempty ())
return;
//We want a new Back/forward list item if the Refresh timeout is > 1 second.
if (!m_redirect | | delay <= m_redirect->delay ()) {
lockbackforwardlist lockbackforwardlist = delay <= 1? Lockbackforwardlist::yes:lockbackforwardlist::no;
Schedule (std::make_unique<scheduledredirect> (delay, m_frame.document ()->securityorigin (), URL, LockH Istory::yes, Lockbackforwardlist));
    }
}

Page problem Analysis


1. Timer problem The biggest problem comes from the determination of the timer Nesting level. Initially WebKit built a global variable record that is susceptible to different pages and the effects of a timer in a frame.
For example, the user clicks a link to use a timer jump, if the timer is created, there is another repeat timer is still in the loop execution, and not loaded complete (onload event is not executed), it will not be able to create history, because then the global nesting Level greater than 1 will not be recorded as a gesture-triggered jump. WebKit submitted (https://bugs.webkit.org/show_bug.cgi?id=136401 [^]), intended to avoid the problem of multi-threaded access, but also just solves the problem of nesting level error.
There is still a case that the problem will still exist. See https://bugs.webkit.org/show_bug.cgi?id=137631. As shown in the test page below, when a repeat timer executes in a document and is not loaded (the OnLoad event is not executed), other timer jumps still cannot create the history item. <body>
<input type= "button" value= "Goto next Page" onclick= "Gotonextpage ();" >
<input type= "button" value= "Start repeating Timer" onclick= "Startrepeatingtimer ();" >
<p>
<div id= "Timer" >Paused</div>
</p>
<script type= "Text/javascript" >

function Gotonextpage () {
SetTimeout (function () {location.href= "http://www.webkit.org/";},300);
}

function Startrepeatingtimer () {
SetInterval (function () {document.getElementById ("Timer"). Innerhtml= "Running ...";},500);
}
</script>




</body>
Use the test page below to reproduce the problem and note the wording of the two http://m.baidu.com in the page:<body>
<p>
<div id= "Info" >Loading...</div>
</p>
<script type= "Text/javascript" >
SetTimeout (function () {attr ("Sub_iframe", "http://m.baidu.com/?abc=23&amp;t=20080225");},5000);

function attr (id,url) {
var Obj=document.getelementbyid (ID);
Obj.setattribute ("src", url);
}

Window.onload=function () {
document.getElementById ("Info"). Innerhtml= "Loaded.";
}

</script>
<iframe src= "http://m.baidu.com/?abc=23&amp;t=20080225" id= "Sub_iframe" width= "" "height=" 480 "></ Iframe><br/>
</body>



WebKit's history management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.