Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 6e19c2e

Browse files
author
Raphael Kubo da Costa
committed
Merge pull request #52 from rakuco/revert-faulty-revert
Revert "Revert "Merge 192508 "Focus a page only if the page is different from cu..."
2 parents 2a0323e + d00a85f commit 6e19c2e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Source/core/loader/FrameLoader.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,12 @@ void FrameLoader::load(const FrameLoadRequest& passedRequest)
778778

779779
RefPtrWillBeRawPtr<LocalFrame> targetFrame = toLocalFrame(request.formState() ? nullptr : m_frame->findFrameForNavigation(AtomicString(request.frameName()), *m_frame));
780780
if (targetFrame && targetFrame.get() != m_frame) {
781+
bool wasInSamePage = targetFrame->page() == m_frame->page();
782+
781783
request.setFrameName("_self");
782784
targetFrame->loader().load(request);
783-
if (Page* page = targetFrame->page())
785+
Page* page = targetFrame->page();
786+
if (!wasInSamePage && page)
784787
page->chrome().focus();
785788
return;
786789
}

Source/web/tests/WebViewTest.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,27 @@ class ViewCreatingWebViewClient : public FrameTestHelpers::TestWebViewClient {
16021602
bool m_didFocusCalled;
16031603
};
16041604

1605+
TEST_F(WebViewTest, DoNotFocusCurrentFrameOnNavigateFromLocalFrame)
1606+
{
1607+
ViewCreatingWebViewClient client;
1608+
FrameTestHelpers::WebViewHelper m_webViewHelper;
1609+
WebViewImpl* webViewImpl = m_webViewHelper.initialize(true, 0, &client);
1610+
webViewImpl->page()->settings().setJavaScriptCanOpenWindowsAutomatically(true);
1611+
1612+
WebURL baseURL = URLTestHelpers::toKURL("http://example.com/");
1613+
FrameTestHelpers::loadHTMLString(webViewImpl->mainFrame(), "<html><body><iframe src=\"about:blank\"></iframe></body></html>", baseURL);
1614+
1615+
// Make a request from a local frame.
1616+
WebURLRequest webURLRequestWithTargetStart;
1617+
webURLRequestWithTargetStart.initialize();
1618+
LocalFrame* localFrame = toWebLocalFrameImpl(webViewImpl->mainFrame()->firstChild())->frame();
1619+
FrameLoadRequest requestWithTargetStart(localFrame->document(), webURLRequestWithTargetStart.toResourceRequest(), "_top");
1620+
localFrame->loader().load(requestWithTargetStart);
1621+
EXPECT_FALSE(client.didFocusCalled());
1622+
1623+
m_webViewHelper.reset(); // Remove dependency on locally scoped client.
1624+
}
1625+
16051626
TEST_F(WebViewTest, FocusExistingFrameOnNavigate)
16061627
{
16071628
ViewCreatingWebViewClient client;

0 commit comments

Comments
 (0)