Commit 07ff3660 authored by alexmos's avatar alexmos Committed by Commit bot

Fix ScopedPageLoadDeferrer to work with pages that have remote main frames.

BUG=628942

Review-Url: https://codereview.chromium.org/2155393002
Cr-Commit-Position: refs/heads/master@{#406632}
parent 59899871
...@@ -32,18 +32,15 @@ namespace blink { ...@@ -32,18 +32,15 @@ namespace blink {
ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion) ScopedPageLoadDeferrer::ScopedPageLoadDeferrer(Page* exclusion)
{ {
for (const Page* page : Page::ordinaryPages()) { for (Page* page : Page::ordinaryPages()) {
if (page == exclusion || page->defersLoading()) if (page == exclusion || page->defersLoading())
continue; continue;
m_deferredPages.append(page);
if (!page->mainFrame()->isLocalFrame())
continue;
m_deferredFrames.append(page->deprecatedLocalMainFrame());
// Ensure that we notify the client if the initial empty document is accessed before // Ensure that we notify the client if the initial empty document is accessed before
// showing anything modal, to prevent spoofs while the modal window or sheet is visible. // showing anything modal, to prevent spoofs while the modal window or sheet is visible.
page->deprecatedLocalMainFrame()->loader().notifyIfInitialDocumentAccessed(); if (page->mainFrame()->isLocalFrame())
page->deprecatedLocalMainFrame()->loader().notifyIfInitialDocumentAccessed();
} }
setDefersLoading(true); setDefersLoading(true);
...@@ -58,10 +55,9 @@ ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer() ...@@ -58,10 +55,9 @@ ScopedPageLoadDeferrer::~ScopedPageLoadDeferrer()
void ScopedPageLoadDeferrer::setDefersLoading(bool isDeferred) void ScopedPageLoadDeferrer::setDefersLoading(bool isDeferred)
{ {
for (const auto& frame : m_deferredFrames) {
if (Page* page = frame->page()) for (const auto& page : m_deferredPages)
page->setDefersLoading(isDeferred); page->setDefersLoading(isDeferred);
}
} }
} // namespace blink } // namespace blink
...@@ -40,7 +40,7 @@ public: ...@@ -40,7 +40,7 @@ public:
private: private:
void setDefersLoading(bool); void setDefersLoading(bool);
Vector<Persistent<LocalFrame>, 16> m_deferredFrames; Vector<Persistent<Page>, 16> m_deferredPages;
}; };
} // namespace blink } // namespace blink
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
#include "core/loader/FrameLoadRequest.h" #include "core/loader/FrameLoadRequest.h"
#include "core/loader/ThreadableLoader.h" #include "core/loader/ThreadableLoader.h"
#include "core/page/Page.h" #include "core/page/Page.h"
#include "core/page/ScopedPageLoadDeferrer.h"
#include "core/paint/PaintLayer.h" #include "core/paint/PaintLayer.h"
#include "core/testing/NullExecutionContext.h" #include "core/testing/NullExecutionContext.h"
#include "modules/mediastream/MediaStream.h" #include "modules/mediastream/MediaStream.h"
...@@ -8171,6 +8172,46 @@ TEST_P(ParameterizedWebFrameTest, RemoteToLocalSwapOnMainFrameInitializesCoreFra ...@@ -8171,6 +8172,46 @@ TEST_P(ParameterizedWebFrameTest, RemoteToLocalSwapOnMainFrameInitializesCoreFra
view->close(); view->close();
} }
// See https://crbug.com/628942.
TEST_P(ParameterizedWebFrameTest, DeferredPageLoadWithRemoteMainFrame)
{
// Prepare a page with a remote main frame.
FrameTestHelpers::TestWebViewClient viewClient;
FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
WebView* view = WebView::create(&viewClient, WebPageVisibilityStateVisible);
view->setMainFrame(remoteClient.frame());
WebRemoteFrame* remoteRoot = view->mainFrame()->toWebRemoteFrame();
remoteRoot->setReplicatedOrigin(SecurityOrigin::createUnique());
// Check that ScopedPageLoadDeferrer properly triggers deferred loading for
// the current Page.
Page* page = remoteRoot->toImplBase()->frame()->page();
EXPECT_FALSE(page->defersLoading());
{
ScopedPageLoadDeferrer deferrer;
EXPECT_TRUE(page->defersLoading());
}
EXPECT_FALSE(page->defersLoading());
// Repeat this for a page with a local child frame, and ensure that the
// child frame's loads are also deferred.
WebLocalFrame* webLocalChild = FrameTestHelpers::createLocalChild(remoteRoot);
registerMockedHttpURLLoad("foo.html");
FrameTestHelpers::loadFrame(webLocalChild, m_baseURL + "foo.html");
LocalFrame* localChild = toWebLocalFrameImpl(webLocalChild)->frame();
EXPECT_FALSE(page->defersLoading());
EXPECT_FALSE(localChild->document()->fetcher()->defersLoading());
{
ScopedPageLoadDeferrer deferrer;
EXPECT_TRUE(page->defersLoading());
EXPECT_TRUE(localChild->document()->fetcher()->defersLoading());
}
EXPECT_FALSE(page->defersLoading());
EXPECT_FALSE(localChild->document()->fetcher()->defersLoading());
view->close();
}
class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient { class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient {
public: public:
MOCK_METHOD4(didOverscroll, void(const WebFloatSize&, const WebFloatSize&, const WebFloatPoint&, const WebFloatSize&)); MOCK_METHOD4(didOverscroll, void(const WebFloatSize&, const WebFloatSize&, const WebFloatPoint&, const WebFloatSize&));
......
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