Commit 30e7fbe7 authored by mek@chromium.org's avatar mek@chromium.org

Mark forwarded user gestures as forwarded, and don't forward already forwarded user gestures.

BUG=354217

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267057 0039d316-1c4b-4281-b951-d872f2087c98
parent bb151d67
......@@ -929,6 +929,38 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MessagingUserGesture) {
" window.domAutomationController.send('' + response.result);\n"
" });\n"
"});", receiver->id().c_str())));
// Messges sent from a setTimeout handler should not forward the user gesture
// again.
EXPECT_EQ(
"false",
ExecuteScriptInBackgroundPage(
sender->id(),
base::StringPrintf(
"chrome.test.runWithUserGesture(function() {\n"
" window.setTimeout(function() {\n"
" chrome.runtime.sendMessage('%s', {}, function(response) {\n"
" window.domAutomationController.send('' + "
" response.result);\n"
" });\n"
" }, 0);\n"
"});",
receiver->id().c_str())));
// The user gesture should not be send back with the reply message, gestures
// are only forwarded once.
EXPECT_EQ(
"false",
ExecuteScriptInBackgroundPage(
sender->id(),
base::StringPrintf(
"chrome.test.runWithUserGesture(function() {\n"
" chrome.runtime.sendMessage('%s', {}, function(response) {\n"
" window.domAutomationController.send('' + "
" chrome.test.isProcessingUserGesture());\n"
" });\n"
"});",
receiver->id().c_str())));
}
// Tests that a hosted app on a connectable site doesn't interfere with the
......
......@@ -30,6 +30,7 @@
#include "third_party/WebKit/public/web/WebScopedUserGesture.h"
#include "third_party/WebKit/public/web/WebScopedWindowFocusAllowedIndicator.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebUserGestureToken.h"
#include "v8/include/v8.h"
// Message passing API example (in a content script):
......@@ -102,6 +103,12 @@ class ExtensionImpl : public ObjectBackedNativeHandler {
dispatcher_->ClearPortData(port_id);
}
bool ShouldForwardUserGesture() {
return blink::WebUserGestureIndicator::isProcessingUserGesture() &&
!blink::WebUserGestureIndicator::currentUserGestureToken()
.wasForwarded();
}
// Sends a message along the given channel.
void PostMessage(const v8::FunctionCallbackInfo<v8::Value>& args) {
content::RenderView* renderview = context()->GetRenderView();
......@@ -121,9 +128,9 @@ class ExtensionImpl : public ObjectBackedNativeHandler {
}
renderview->Send(new ExtensionHostMsg_PostMessage(
renderview->GetRoutingID(), port_id,
Message(*v8::String::Utf8Value(args[1]),
blink::WebUserGestureIndicator::isProcessingUserGesture())));
renderview->GetRoutingID(),
port_id,
Message(*v8::String::Utf8Value(args[1]), ShouldForwardUserGesture())));
}
// Forcefully disconnects a port.
......@@ -357,6 +364,7 @@ void MessagingBindings::DeliverMessage(
scoped_ptr<blink::WebScopedWindowFocusAllowedIndicator> allow_window_focus;
if (message.user_gesture) {
web_user_gesture.reset(new blink::WebScopedUserGesture);
blink::WebUserGestureIndicator::currentUserGestureToken().setForwarded();
allow_window_focus.reset(new blink::WebScopedWindowFocusAllowedIndicator);
}
......
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