Commit 14ce83fb authored by estade@chromium.org's avatar estade@chromium.org

Generalize the code that checks for user actions in the render view to work on all platforms.

Also, on linux, assume the user denies every download which we would have prompted him with.

BUG=12709
TEST=windows is still carpet-bombing resilient and linux can download from the same page more than once.
Review URL: http://codereview.chromium.org/113925

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17089 0039d316-1c4b-4281-b951-d872f2087c98
parent be8d1790
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2009 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.
......@@ -6,7 +6,7 @@
BrowserProcess* g_browser_process = NULL;
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_LINUX)
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
......
......@@ -130,7 +130,7 @@ class BrowserProcess {
virtual MemoryModel memory_model() = 0;
#if defined(OS_WIN)
#if defined(OS_WIN) || defined(OS_LINUX)
DownloadRequestManager* download_request_manager();
#endif
......
......@@ -66,10 +66,15 @@ void DownloadRequestManager::TabDownloadState::PromptUserForDownload(
if (is_showing_prompt())
return; // Already showing prompt.
if (DownloadRequestManager::delegate_)
if (DownloadRequestManager::delegate_) {
NotifyCallbacks(DownloadRequestManager::delegate_->ShouldAllowDownload());
else
} else {
dialog_delegate_ = DownloadRequestDialogDelegate::Create(tab, this);
// TODO(estade): the dialog delegate isn't yet implemented on linux. Just
// assume we shouldn't allow the download.
if (dialog_delegate_ == NULL)
NotifyCallbacks(false);
}
}
void DownloadRequestManager::TabDownloadState::Cancel() {
......
......@@ -1277,8 +1277,8 @@ void RenderViewHost::UnhandledKeyboardEvent(
}
}
void RenderViewHost::OnEnterOrSpace() {
delegate_->OnEnterOrSpace();
void RenderViewHost::OnUserGesture() {
delegate_->OnUserGesture();
}
void RenderViewHost::OnMissingPluginStatus(int status) {
......
......@@ -434,7 +434,7 @@ class RenderViewHost : public RenderWidgetHost {
protected:
// RenderWidgetHost protected overrides.
virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event);
virtual void OnEnterOrSpace();
virtual void OnUserGesture();
virtual void NotifyRendererUnresponsive();
virtual void NotifyRendererResponsive();
......
......@@ -421,10 +421,10 @@ class RenderViewHostDelegate {
int32 page_id,
const webkit_glue::WebApplicationInfo& app_info) { }
// Notification the user has pressed enter or space while focus was on the
// Notification the user has made a gesture while focus was on the
// page. This is used to avoid uninitiated user downloads (aka carpet
// bombing), see DownloadRequestManager for details.
virtual void OnEnterOrSpace() { }
virtual void OnUserGesture() { }
// If this view is used to host an external tab container.
virtual bool IsExternalTabContainer() const { return false; }
......
......@@ -301,6 +301,8 @@ void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
return;
}
mouse_move_pending_ = true;
} else if (mouse_event.type == WebInputEvent::MouseDown) {
OnUserGesture();
}
ForwardInputEvent(mouse_event, sizeof(WebMouseEvent));
......@@ -316,7 +318,7 @@ void RenderWidgetHost::ForwardKeyboardEvent(
if (key_event.type == WebKeyboardEvent::Char &&
(key_event.windowsKeyCode == base::VKEY_RETURN ||
key_event.windowsKeyCode == base::VKEY_SPACE)) {
OnEnterOrSpace();
OnUserGesture();
}
// Double check the type to make sure caller hasn't sent us nonsense that
......
......@@ -275,10 +275,12 @@ class RenderWidgetHost : public IPC::Channel::Listener {
// overridden by RenderView to send upwards to its delegate.
virtual void UnhandledKeyboardEvent(const NativeWebKeyboardEvent& event) {}
// Notification that the user pressed the enter key or the spacebar. The
// render view host overrides this to forward the information to its delegate
// (see corresponding function in RenderViewHostDelegate).
virtual void OnEnterOrSpace() {}
// Notification that the user has made some kind of input that could
// perform an action. The render view host overrides this to forward the
// information to its delegate (see corresponding function in
// RenderViewHostDelegate). The gestures that count are 1) any mouse down
// event and 2) enter or space key presses.
virtual void OnUserGesture() {}
// Callbacks for notification when the renderer becomes unresponsive to user
// input events, and subsequently responsive again. RenderViewHost overrides
......
......@@ -2299,10 +2299,9 @@ void TabContents::OnDidGetApplicationInfo(
&GearsCreateShortcutCallbackFunctor::Run));
}
void TabContents::OnEnterOrSpace() {
// See comment in RenderViewHostDelegate::OnEnterOrSpace as to why we do this.
#if defined(OS_WIN)
// TODO(port): this is stubbed in BrowserProcess
void TabContents::OnUserGesture() {
// See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
#if defined(OS_WIN) || defined(OS_LINUX)
DownloadRequestManager* drm = g_browser_process->download_request_manager();
if (drm)
drm->OnUserGesture(this);
......
......@@ -841,7 +841,7 @@ class TabContents : public PageNavigator,
virtual void OnDidGetApplicationInfo(
int32 page_id,
const webkit_glue::WebApplicationInfo& info);
virtual void OnEnterOrSpace();
virtual void OnUserGesture();
virtual void OnFindReply(int request_id,
int number_of_matches,
const gfx::Rect& selection_rect,
......
......@@ -415,10 +415,6 @@ LRESULT TabContentsViewWin::OnMouseRange(UINT msg,
// Make sure this TabContents is activated when it is clicked on.
if (tab_contents()->delegate())
tab_contents()->delegate()->ActivateContents(tab_contents());
DownloadRequestManager* drm =
g_browser_process->download_request_manager();
if (drm)
drm->OnUserGesture(tab_contents());
break;
}
case WM_MOUSEMOVE:
......
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