标签:webkit
关于历史的管理,和HTML页面加载一样,都有其相应的标准。地址如下:
WhatWG: https://html.spec.whatwg.org/multipage/browsers.html#history
其中关于历史项的要点如下:
1. 在onload之前,非用户操作引起的导航操作不建立历史项。
非用户操作比如页面中指定的Timer修改location或iframe的src引发的导航操作。而用户点击发起的Timer,则在timer中记录下在发起timer时标记手势来源。但有一个例外是由另一个Timer发起的Timer或是重复执行的Timer, 则仅针对第一次执行有效(以nesting level标识)。
2. 子Frame加载完成仍有未加载的上层Frame, 则不创建历史项。
3. 当前Frame只有一个历史项,且为about:blank, 则不创建历史项。
4. 如果页面跳转的间隔小于1s,则不创建历史项。
关于Timer的nesting level可以参考这里:
http://www.w3.org/html/wg/drafts/html/CR/webappapis.html#timer-nesting-level
以上规则对应于以下三个WebKit的函数:
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.
// See https://webkit.org/b/42861 for the original motivation for this.
if (!ScriptController::processingUserGesture() && targetFrame.loader().documentLoader() && !targetFrame.loader().documentLoader()->wasOnloadHandled())
return LockBackForwardList::Yes;
// Navigation of a subframe during loading of an 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 have been run.
// See https://bugs.webkit.org/show_bug.cgi?id=14957 for the original motivation for this.
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 was the about:blank Document created when the browsing context
// was created, then the navigation must be 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, LockHistory::Yes, lockBackForwardList));
}
}
标签:webkit
原文地址:http://blog.csdn.net/horkychen/article/details/40263251