Commit 65a684af authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

OOPIFs: Make sure that ctrl-click opens a new *background* tab.

This CL makes sure that Blink code that needs to consult the current
input event considers events going either through WebViewImpl or
through a WebFrameWidgetImpl.  The CL removes separately maintained
|current_input_event_| fields from WebViewImpl and WebFrameWidgetImpl
(the latter was never read anyway) and consolidates them into
a new class - CurrentInputEvent.

Bug: 804838
Change-Id: I89430f3a73f38ef5842c57635602fb079c1a34ef
Reviewed-on: https://chromium-review.googlesource.com/887346Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532241}
parent a04e5845
......@@ -1463,3 +1463,59 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest,
EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date
<< "' but current date is '" << date << "'.";
}
// There is a problem of missing keyup events with the command key after
// the NSEvent is sent to NSApplication in ui/base/test/ui_controls_mac.mm .
// This test is disabled on only the Mac until the problem is resolved.
// See http://crbug.com/425859 for more information.
#if !defined(OS_MACOSX)
// Tests that ctrl-click in a subframe results in a background, not a foreground
// tab - see https://crbug.com/804838. This test is somewhat similar to
// CtrlClickShouldEndUpIn*ProcessTest tests, but this test has to simulate an
// actual mouse click.
IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest,
SubframeAnchorOpenedInBackgroundTab) {
// Setup the test page - the ctrl-clicked link should be in a subframe.
GURL main_url(embedded_test_server()->GetURL("foo.com", "/iframe.html"));
ui_test_utils::NavigateToURL(browser(), main_url);
GURL subframe_url(embedded_test_server()->GetURL(
"bar.com", "/frame_tree/anchor_to_same_site_location.html"));
content::WebContents* old_contents =
browser()->tab_strip_model()->GetWebContentsAt(0);
ASSERT_TRUE(NavigateIframeToURL(old_contents, "test", subframe_url));
EXPECT_LE(2u, old_contents->GetAllFrames().size());
content::RenderFrameHost* subframe = old_contents->GetAllFrames()[1];
EXPECT_EQ(subframe_url, subframe->GetLastCommittedURL());
// Simulate the ctrl-return to open the anchor's link in a new background tab.
EXPECT_TRUE(ExecuteScript(
subframe, "document.getElementById('test-anchor-no-target').focus();"));
content::WebContents* new_contents = nullptr;
{
content::WebContentsAddedObserver new_tab_observer;
#if defined(OS_MACOSX)
ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
old_contents->GetTopLevelNativeWindow(), ui::VKEY_RETURN, false, false,
false, true /* cmd */));
#else
ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
old_contents->GetTopLevelNativeWindow(), ui::VKEY_RETURN,
true /* ctrl */, false, false, false));
#endif
new_contents = new_tab_observer.GetWebContents();
}
// Verify that the new content has loaded the expected contents.
GURL target_url(embedded_test_server()->GetURL("bar.com", "/title1.html"));
EXPECT_TRUE(WaitForLoadStop(new_contents));
EXPECT_EQ(target_url, new_contents->GetMainFrame()->GetLastCommittedURL());
// Verify that the anchor opened in a new background tab.
EXPECT_EQ(2, browser()->tab_strip_model()->count());
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
EXPECT_EQ(0,
browser()->tab_strip_model()->GetIndexOfWebContents(old_contents));
EXPECT_EQ(1,
browser()->tab_strip_model()->GetIndexOfWebContents(new_contents));
}
#endif
......@@ -20,6 +20,8 @@ blink_core_sources("events") {
"ClipboardEvent.h",
"CompositionEvent.cpp",
"CompositionEvent.h",
"CurrentInputEvent.cpp",
"CurrentInputEvent.h",
"DragEvent.cpp",
"DragEvent.h",
"ErrorEvent.cpp",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/events/CurrentInputEvent.h"
namespace blink {
const WebInputEvent* CurrentInputEvent::current_input_event_ = nullptr;
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CurrentInputEvent_h
#define CurrentInputEvent_h
namespace blink {
class WebFrameWidgetImpl;
class WebInputEvent;
class WebViewImpl;
class CurrentInputEvent {
public:
// Gets the "current" input event - event that is currently being processed by
// either blink::WebViewImpl::HandleInputEventInternal or by
// blink::WebFrameWidgetImpl::HandleInputEventInternal
static const WebInputEvent* Get() { return current_input_event_; }
private:
friend class WebViewImpl;
friend class WebFrameWidgetImpl;
static const WebInputEvent* current_input_event_;
};
} // namespace blink
#endif
......@@ -38,6 +38,7 @@
#include "core/CoreInitializer.h"
#include "core/dom/Document.h"
#include "core/dom/UserGestureIndicator.h"
#include "core/events/CurrentInputEvent.h"
#include "core/events/MessageEvent.h"
#include "core/events/MouseEvent.h"
#include "core/events/UIEventWithKeyState.h"
......@@ -479,7 +480,7 @@ void LocalFrameClientImpl::DispatchDidChangeThemeColor() {
}
static bool AllowCreatingBackgroundTabs() {
const WebInputEvent* input_event = WebViewImpl::CurrentInputEvent();
const WebInputEvent* input_event = CurrentInputEvent::Get();
if (!input_event || (input_event->GetType() != WebInputEvent::kMouseUp &&
(input_event->GetType() != WebInputEvent::kRawKeyDown &&
input_event->GetType() != WebInputEvent::kKeyDown) &&
......
......@@ -53,6 +53,7 @@
#include "core/editing/iterators/TextIterator.h"
#include "core/editing/serializers/HTMLInterchange.h"
#include "core/editing/serializers/Serialization.h"
#include "core/events/CurrentInputEvent.h"
#include "core/events/KeyboardEvent.h"
#include "core/events/UIEventWithKeyState.h"
#include "core/events/WebInputEventConversion.h"
......@@ -222,12 +223,6 @@ const double WebView::kTextSizeMultiplierRatio = 1.2;
const double WebView::kMinTextSizeMultiplier = 0.5;
const double WebView::kMaxTextSizeMultiplier = 3.0;
const WebInputEvent* WebViewImpl::current_input_event_ = nullptr;
const WebInputEvent* WebViewImpl::CurrentInputEvent() {
return current_input_event_;
}
// Used to defer all page activity in cases where the embedder wishes to run
// a nested event loop. Using a stack enables nesting of message loop
// invocations.
......@@ -2015,8 +2010,8 @@ WebInputEventResult WebViewImpl::HandleInputEvent(
if (WebFrameWidgetBase::IgnoreInputEvents())
return WebInputEventResult::kNotHandled;
AutoReset<const WebInputEvent*> current_event_change(&current_input_event_,
&input_event);
AutoReset<const WebInputEvent*> current_event_change(
&CurrentInputEvent::current_input_event_, &input_event);
UIEventWithKeyState::ClearNewTabModifierSetFromIsolatedWorld();
bool is_pointer_locked = false;
......
......@@ -104,7 +104,6 @@ class CORE_EXPORT WebViewImpl final
mojom::PageVisibilityState,
WebViewImpl* opener);
static HashSet<WebViewImpl*>& AllInstances();
static const WebInputEvent* CurrentInputEvent();
// Returns true if popup menus should be rendered by the browser, false if
// they should be rendered by WebKit (which is the default).
static bool UseExternalPopupMenus();
......@@ -688,8 +687,6 @@ class CORE_EXPORT WebViewImpl final
bool override_compositor_visibility_;
Persistent<ResizeViewportAnchor> resize_viewport_anchor_;
static const WebInputEvent* current_input_event_;
};
// We have no ways to check if the specified WebView is an instance of
......
......@@ -31,6 +31,7 @@
#include "core/frame/WebFrameWidgetImpl.h"
#include <memory>
#include <utility>
#include "build/build_config.h"
#include "core/dom/UserGestureIndicator.h"
......@@ -41,6 +42,7 @@
#include "core/editing/PlainTextRange.h"
#include "core/editing/SelectionTemplate.h"
#include "core/editing/ime/InputMethodController.h"
#include "core/events/CurrentInputEvent.h"
#include "core/events/WebInputEventConversion.h"
#include "core/exported/WebDevToolsAgentImpl.h"
#include "core/exported/WebPagePopupImpl.h"
......@@ -379,8 +381,6 @@ WebHitTestResult WebFrameWidgetImpl::HitTestResultAt(const WebPoint& point) {
return CoreHitTestResultAt(point);
}
const WebInputEvent* WebFrameWidgetImpl::current_input_event_ = nullptr;
WebInputEventResult WebFrameWidgetImpl::DispatchBufferedTouchEvents() {
if (doing_drag_and_drop_)
return WebInputEventResult::kHandledSuppressed;
......@@ -429,8 +429,8 @@ WebInputEventResult WebFrameWidgetImpl::HandleInputEvent(
// FIXME: pass event to m_localRoot's WebDevToolsAgentImpl once available.
AutoReset<const WebInputEvent*> current_event_change(&current_input_event_,
&input_event);
AutoReset<const WebInputEvent*> current_event_change(
&CurrentInputEvent::current_input_event_, &input_event);
DCHECK(client_);
if (client_->IsPointerLocked() &&
......
......@@ -31,6 +31,8 @@
#ifndef WebFrameWidgetImpl_h
#define WebFrameWidgetImpl_h
#include <memory>
#include "core/frame/WebFrameWidgetBase.h"
#include "core/frame/WebLocalFrameImpl.h"
#include "core/page/PageWidgetDelegate.h"
......@@ -222,8 +224,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
// Represents whether or not this object should process incoming IME events.
bool ime_accept_events_;
static const WebInputEvent* current_input_event_;
WebColor base_background_color_;
SelfKeepAlive<WebFrameWidgetImpl> self_keep_alive_;
......
......@@ -32,6 +32,7 @@
#include "build/build_config.h"
#include "core/dom/NodeComputedStyle.h"
#include "core/events/CurrentInputEvent.h"
#include "core/exported/WebViewImpl.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/LocalFrameView.h"
......@@ -118,7 +119,7 @@ void ExternalPopupMenu::Show() {
if (!ShowInternal())
return;
#if defined(OS_MACOSX)
const WebInputEvent* current_event = WebViewImpl::CurrentInputEvent();
const WebInputEvent* current_event = CurrentInputEvent::Get();
if (current_event && current_event->GetType() == WebInputEvent::kMouseDown) {
synthetic_event_ = WTF::WrapUnique(new WebMouseEvent);
*synthetic_event_ = *static_cast<const WebMouseEvent*>(current_event);
......
......@@ -28,6 +28,7 @@
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/Document.h"
#include "core/events/CurrentInputEvent.h"
#include "core/events/UIEventWithKeyState.h"
#include "core/exported/WebViewImpl.h"
#include "core/frame/FrameClient.h"
......@@ -298,8 +299,8 @@ static Frame* CreateNewWindow(LocalFrame& opener_frame,
if (!old_page)
return nullptr;
policy = EffectiveNavigationPolicy(policy, WebViewImpl::CurrentInputEvent(),
features);
policy =
EffectiveNavigationPolicy(policy, CurrentInputEvent::Get(), features);
const SandboxFlags sandbox_flags =
opener_frame.GetDocument()->IsSandboxed(
......
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