Commit 39f38319 authored by dglazkov@chromium.org's avatar dglazkov@chromium.org

Add hooks for capturing meaningful text info, gently.

The two hooks are:
* WebLocalFrame::isNavigationPending
* WebViewClient::didFirstLayoutAfterFinishedParsing

The WebLocalFrame::isNavigationPending provides a
simple check whether the content of the document intends to
change the location (via Refresh or window.location change).

The WebViewClient::didFirstLayoutAfterFinishedParsing is called
when we finish the first layout after the document had finished
parsing. Another way to explain it is "first layout after
DOMContentLoaded".

BUG=521149
R=esprehn

Review URL: https://codereview.chromium.org/1309883003

git-svn-id: svn://svn.chromium.org/blink/trunk@201042 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3e944d87
......@@ -569,6 +569,7 @@ public:
void setParsingState(ParsingState);
bool parsing() const { return m_parsingState == Parsing; }
bool isInDOMContentLoaded() const { return m_parsingState == InDOMContentLoaded; }
bool hasFinishedParsing() const { return m_parsingState == FinishedParsing; }
bool shouldScheduleLayout() const;
int elapsedTime() const;
......
......@@ -158,6 +158,7 @@ public:
request.setClientRedirect(ClientRedirect);
frame->loader().load(request);
}
private:
ScheduledRedirect(double delay, Document* originDocument, const String& url, bool replacesCurrentItem)
: ScheduledURLNavigation(delay, originDocument, url, replacesCurrentItem, false)
......@@ -279,6 +280,11 @@ bool NavigationScheduler::locationChangePending()
return m_redirect && m_redirect->isLocationChange();
}
bool NavigationScheduler::isNavigationScheduled() const
{
return m_redirect;
}
inline bool NavigationScheduler::shouldScheduleReload() const
{
return m_frame->page() && isFrameNavigationAllowed() && NavigationDisablerForBeforeUnload::isNavigationAllowed();
......
......@@ -90,6 +90,7 @@ public:
~NavigationScheduler();
bool locationChangePending();
bool isNavigationScheduled() const;
void scheduleRedirect(double delay, const String& url);
void scheduleLocationChange(Document*, const String& url, bool replacesCurrentItem = true);
......
......@@ -2116,6 +2116,11 @@ bool WebLocalFrameImpl::isResourceLoadInProgress() const
return frame()->document()->fetcher()->requestCount();
}
bool WebLocalFrameImpl::isNavigationScheduled() const
{
return frame() && frame()->navigationScheduler().isNavigationScheduled();
}
void WebLocalFrameImpl::setCommittedFirstRealLoad()
{
ASSERT(frame());
......
......@@ -246,6 +246,7 @@ public:
WebHistoryLoadType) override;
bool isLoading() const override;
bool isResourceLoadInProgress() const override;
bool isNavigationScheduled() const override;
void setCommittedFirstRealLoad() override;
void sendOrientationChangeEvent() override;
void willShowInstallBannerPrompt(int requestId, const WebVector<WebString>& platforms, WebAppBannerPromptReply*) override;
......
......@@ -454,6 +454,7 @@ WebViewImpl::WebViewImpl(WebViewClient* client)
, m_zoomFactorOverride(0)
, m_userGestureObserved(false)
, m_shouldDispatchFirstVisuallyNonEmptyLayout(false)
, m_shouldDispatchFirstLayoutAfterFinishedParsing(false)
, m_displayMode(WebDisplayModeBrowser)
, m_elasticOverscroll(FloatSize())
{
......@@ -1899,11 +1900,19 @@ void WebViewImpl::layout()
m_linkHighlights[i]->updateGeometry();
if (FrameView* view = mainFrameImpl()->frameView()) {
LocalFrame* frame = mainFrameImpl()->frame();
if (m_shouldDispatchFirstVisuallyNonEmptyLayout && view->isVisuallyNonEmpty()) {
m_shouldDispatchFirstVisuallyNonEmptyLayout = false;
// TODO(esprehn): Move users of this callback to something
// better, the heuristic for "visually non-empty" is bad.
mainFrameImpl()->frame()->loader().client()->dispatchDidFirstVisuallyNonEmptyLayout();
// TODO(dglazkov): This should likely be a WebViewClient API.
frame->loader().client()->dispatchDidFirstVisuallyNonEmptyLayout();
}
if (m_shouldDispatchFirstLayoutAfterFinishedParsing && frame->document()->hasFinishedParsing()) {
m_shouldDispatchFirstLayoutAfterFinishedParsing = false;
client()->didFirstLayoutAfterFinishedParsing();
}
}
}
......@@ -4099,6 +4108,7 @@ void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* layer)
m_layerTreeView->setDeferCommits(true);
m_layerTreeView->clearRootLayer();
m_shouldDispatchFirstVisuallyNonEmptyLayout = true;
m_shouldDispatchFirstLayoutAfterFinishedParsing = true;
page()->frameHost().visualViewport().clearLayersForTreeView(m_layerTreeView);
}
......
......@@ -761,6 +761,7 @@ private:
bool m_userGestureObserved;
bool m_shouldDispatchFirstVisuallyNonEmptyLayout;
bool m_shouldDispatchFirstLayoutAfterFinishedParsing;
WebDisplayMode m_displayMode;
FloatSize m_elasticOverscroll;
......
......@@ -91,6 +91,17 @@ public:
// instead.
virtual bool isResourceLoadInProgress() const = 0;
// Returns true if there is a pending redirect or location change.
// This could be caused by:
// * an HTTP Refresh header
// * an X-Frame-Options header
// * the respective http-equiv meta tags
// * window.location value being mutated
// * CSP policy block
// * reload
// * form submission
virtual bool isNavigationScheduled() const = 0;
// Override the normal rules for whether a load has successfully committed
// in this frame. Used to propagate state when this frame has navigated
// cross process.
......
......@@ -196,6 +196,10 @@ public:
// unless the view did not need a layout.
virtual void didUpdateLayout() { }
// The frame's document finished layout immediately after the parsing finished.
// Another way to put it: first frame after DOMContentLoaded is dispatched.
virtual void didFirstLayoutAfterFinishedParsing() { }
// Return true to swallow the input event if the embedder will start a disambiguation popup
virtual bool didTapMultipleTargets(const WebSize& pinchViewportOffset, const WebRect& touchRect, const WebVector<WebRect>& targetRects) { return false; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment