Skip to content

Commit

Permalink
Plumb user_gesture up from Blink to the JavaScript dialog code, and d…
Browse files Browse the repository at this point in the history
…on't offer to suppress dialogs if they're initiated by a user gesture.

BUG=263192
TEST=as in bug

Review URL: https://chromiumcodereview.appspot.com/22909052

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220050 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
avi@chromium.org committed Aug 28, 2013
1 parent 2f2679a commit 5f45b5c
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions android_webview/browser/aw_javascript_dialog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void AwJavaScriptDialogManager::RunJavaScriptDialog(
content::JavaScriptMessageType message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
AwContentsClientBridgeBase* bridge =
Expand Down
1 change: 1 addition & 0 deletions android_webview/browser/aw_javascript_dialog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AwJavaScriptDialogManager : public content::JavaScriptDialogManager {
content::JavaScriptMessageType message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) OVERRIDE;
virtual void RunBeforeUnloadDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,15 @@ public void testBeforeUnloadOnReloadDialog()
public void testDisableRepeatedDialogs()
throws InterruptedException, TimeoutException, ExecutionException {
OnEvaluateJavaScriptResultHelper scriptEvent =
executeJavaScriptAndWaitForDialog("alert('Android');");
executeJavaScriptAndWaitForDialog("alert('Android');alert('Android');");

// Show a dialog once.
// A dialog should appear.
JavascriptAppModalDialog jsDialog = getCurrentDialog();
assertNotNull("No dialog showing.", jsDialog);

clickCancel(jsDialog);
scriptEvent.waitUntilHasValue();

// Show it again, it should have the option to suppress subsequent dialogs.
scriptEvent = executeJavaScriptAndWaitForDialog("alert('Android');");
// Another dialog should appear with the option to suppress subsequent dialogs.
jsDialog = getCurrentDialog();
assertNotNull("No dialog showing.", jsDialog);
final AlertDialog dialog = jsDialog.getDialogForTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ChromeJavaScriptDialogManager : public JavaScriptDialogManager,
content::JavaScriptMessageType message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) OVERRIDE;

Expand Down Expand Up @@ -130,6 +131,7 @@ void ChromeJavaScriptDialogManager::RunJavaScriptDialog(
content::JavaScriptMessageType message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
*did_suppress_message = false;
Expand All @@ -146,10 +148,11 @@ void ChromeJavaScriptDialogManager::RunJavaScriptDialog(
extra_data->last_javascript_message_dismissal_;
bool display_suppress_checkbox = false;
// Show a checkbox offering to suppress further messages if this message is
// being displayed within kJavaScriptMessageExpectedDelay of the last one.
// being displayed within kJavaScriptMessageExpectedDelay of the last one and
// the dialog was not requested via an explicit user gesture.
if (time_since_last_message <
base::TimeDelta::FromMilliseconds(
chrome::kJavaScriptMessageExpectedDelay)) {
chrome::kJavaScriptMessageExpectedDelay) && !user_gesture) {
display_suppress_checkbox = true;
} else {
display_suppress_checkbox = false;
Expand Down
1 change: 1 addition & 0 deletions content/browser/browser_plugin/browser_plugin_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ void BrowserPluginGuest::RunJavaScriptDialog(
JavaScriptMessageType javascript_message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
if (permission_request_map_.size() >= kNumMaxOutstandingPermissionRequests) {
Expand Down
1 change: 1 addition & 0 deletions content/browser/browser_plugin/browser_plugin_guest.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CONTENT_EXPORT BrowserPluginGuest
JavaScriptMessageType javascript_message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) OVERRIDE;
virtual void RunBeforeUnloadDialog(
Expand Down
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_view_host_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class CONTENT_EXPORT RenderViewHostDelegate {
const string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType type,
bool user_gesture,
IPC::Message* reply_msg,
bool* did_suppress_message) {}

Expand Down
3 changes: 2 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1435,13 +1435,14 @@ void RenderViewHostImpl::OnRunJavaScriptMessage(
const string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType type,
bool user_gesture,
IPC::Message* reply_msg) {
// While a JS message dialog is showing, tabs in the same process shouldn't
// process input events.
GetProcess()->SetIgnoreInputEvents(true);
StopHangMonitorTimeout();
delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url,
type, reply_msg,
type, user_gesture, reply_msg,
&are_javascript_messages_suppressed_);
}

Expand Down
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_view_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class CONTENT_EXPORT RenderViewHostImpl
const string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType type,
bool user_gesture,
IPC::Message* reply_msg);
void OnRunBeforeUnloadConfirm(const GURL& frame_url,
const string16& message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
ntp_process_host->sink().ClearMessages();
ViewHostMsg_RunJavaScriptMessage js_msg(
rvh()->GetRoutingID(), msg, msg, kChromeURL,
JAVASCRIPT_MESSAGE_TYPE_CONFIRM, &result, &unused);
JAVASCRIPT_MESSAGE_TYPE_CONFIRM, false, &result, &unused);
js_msg.EnableMessagePumping();
EXPECT_TRUE(ntp_rvh->OnMessageReceived(js_msg));
EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
Expand Down
2 changes: 2 additions & 0 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,7 @@ void WebContentsImpl::RunJavaScriptMessage(
const string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType javascript_message_type,
bool user_gesture,
IPC::Message* reply_msg,
bool* did_suppress_message) {
// Suppress JavaScript dialogs when requested. Also suppress messages when
Expand All @@ -3379,6 +3380,7 @@ void WebContentsImpl::RunJavaScriptMessage(
javascript_message_type,
message,
default_prompt,
user_gesture,
base::Bind(&WebContentsImpl::OnDialogClosed,
base::Unretained(this),
rvh,
Expand Down
1 change: 1 addition & 0 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ class CONTENT_EXPORT WebContentsImpl
const string16& default_prompt,
const GURL& frame_url,
JavaScriptMessageType type,
bool user_gesture,
IPC::Message* reply_msg,
bool* did_suppress_message) OVERRIDE;
virtual void RunBeforeUnloadConfirm(RenderViewHost* rvh,
Expand Down
2 changes: 1 addition & 1 deletion content/browser/web_contents/web_contents_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ TEST_F(WebContentsImplTest, NoJSMessageOnInterstitials) {
bool did_suppress_message = false;
contents()->RunJavaScriptMessage(contents()->GetRenderViewHost(),
ASCIIToUTF16("This is an informative message"), ASCIIToUTF16("OK"),
kGURL, JAVASCRIPT_MESSAGE_TYPE_ALERT, dummy_message,
kGURL, JAVASCRIPT_MESSAGE_TYPE_ALERT, false, dummy_message,
&did_suppress_message);
EXPECT_TRUE(did_suppress_message);
}
Expand Down
3 changes: 2 additions & 1 deletion content/common/view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,11 +1800,12 @@ IPC_MESSAGE_ROUTED0(ViewHostMsg_RouteCloseEvent)
IPC_MESSAGE_ROUTED1(ViewHostMsg_RouteMessageEvent,
ViewMsg_PostMessage_Params)

IPC_SYNC_MESSAGE_ROUTED4_2(ViewHostMsg_RunJavaScriptMessage,
IPC_SYNC_MESSAGE_ROUTED5_2(ViewHostMsg_RunJavaScriptMessage,
string16 /* in - alert message */,
string16 /* in - default prompt */,
GURL /* in - originating page URL */,
content::JavaScriptMessageType /* in - type */,
bool /* in - user_gesture */,
bool /* out - success */,
string16 /* out - user_input field */)

Expand Down
1 change: 1 addition & 0 deletions content/public/browser/javascript_dialog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CONTENT_EXPORT JavaScriptDialogManager {
JavaScriptMessageType javascript_message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) = 0;

Expand Down
5 changes: 4 additions & 1 deletion content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2226,13 +2226,16 @@ bool RenderViewImpl::RunJavaScriptMessage(JavaScriptMessageType type,
const string16& default_value,
const GURL& frame_url,
string16* result) {
bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();
bool success = false;
string16 result_temp;
if (!result)
result = &result_temp;

SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
routing_id_, message, default_value, frame_url, type, &success, result));
routing_id_, message, default_value, frame_url, type, user_gesture,
&success, result));
WebUserGestureIndicator::consumeUserGesture();
return success;
}

Expand Down
1 change: 1 addition & 0 deletions content/shell/browser/shell_javascript_dialog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void ShellJavaScriptDialogManager::RunJavaScriptDialog(
JavaScriptMessageType javascript_message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
Expand Down
1 change: 1 addition & 0 deletions content/shell/browser/shell_javascript_dialog_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ShellJavaScriptDialogManager : public JavaScriptDialogManager {
JavaScriptMessageType javascript_message_type,
const string16& message_text,
const string16& default_prompt_text,
bool user_gesture,
const DialogClosedCallback& callback,
bool* did_suppress_message) OVERRIDE;

Expand Down

0 comments on commit 5f45b5c

Please sign in to comment.