Commit feaa8cfb authored by fsamuel@chromium.org's avatar fsamuel@chromium.org

GuestView: Move Disable Drag and Drop Out to Chrome

BUG=364141, 330264
TBR=jam@chromium.org for content/public/browser_plugin_guest_delegate code deletion.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274002 0039d316-1c4b-4281-b951-d872f2087c98
parent 9e840993
...@@ -5,13 +5,16 @@ ...@@ -5,13 +5,16 @@
#include "chrome/browser/guest_view/guest_view_base.h" #include "chrome/browser/guest_view/guest_view_base.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/guest_view/ad_view/ad_view_guest.h" #include "chrome/browser/guest_view/ad_view/ad_view_guest.h"
#include "chrome/browser/guest_view/guest_view_constants.h" #include "chrome/browser/guest_view/guest_view_constants.h"
#include "chrome/browser/guest_view/guest_view_manager.h" #include "chrome/browser/guest_view/guest_view_manager.h"
#include "chrome/browser/guest_view/web_view/web_view_guest.h" #include "chrome/browser/guest_view/web_view/web_view_guest.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/content_settings.h" #include "chrome/common/content_settings.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "extensions/browser/event_router.h" #include "extensions/browser/event_router.h"
...@@ -177,6 +180,10 @@ base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() { ...@@ -177,6 +180,10 @@ base::WeakPtr<GuestViewBase> GuestViewBase::AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr(); return weak_ptr_factory_.GetWeakPtr();
} }
bool GuestViewBase::IsDragAndDropEnabled() const {
return false;
}
void GuestViewBase::Attach(content::WebContents* embedder_web_contents, void GuestViewBase::Attach(content::WebContents* embedder_web_contents,
const base::DictionaryValue& args) { const base::DictionaryValue& args) {
embedder_web_contents_ = embedder_web_contents; embedder_web_contents_ = embedder_web_contents;
...@@ -223,6 +230,17 @@ void GuestViewBase::RegisterDestructionCallback( ...@@ -223,6 +230,17 @@ void GuestViewBase::RegisterDestructionCallback(
destruction_callback_ = callback; destruction_callback_ = callback;
} }
void GuestViewBase::DidStopLoading(content::RenderViewHost* render_view_host) {
if (!IsDragAndDropEnabled()) {
const char script[] = "window.addEventListener('dragstart', function() { "
" window.event.preventDefault(); "
"});";
render_view_host->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16(script));
}
DidStopLoading();
}
void GuestViewBase::WebContentsDestroyed() { void GuestViewBase::WebContentsDestroyed() {
delete this; delete this;
} }
......
...@@ -76,11 +76,20 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -76,11 +76,20 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
virtual const char* GetViewType() const = 0; virtual const char* GetViewType() const = 0;
// This method can be overriden by subclasses. This method is called when
// the initial set of frames within the page have completed loading.
virtual void DidStopLoading() {}
// This method can be overridden by subclasses. It indicates that this guest's // This method can be overridden by subclasses. It indicates that this guest's
// embedder has been destroyed and the guest will be destroyed shortly. This // embedder has been destroyed and the guest will be destroyed shortly. This
// method gives derived classes the opportunity to perform some cleanup. // method gives derived classes the opportunity to perform some cleanup.
virtual void EmbedderDestroyed() {} virtual void EmbedderDestroyed() {}
// This method queries whether drag-and-drop is enabled for this particular
// view. By default, drag-and-drop is disabled. Derived classes can override
// this behavior to enable drag-and-drop.
virtual bool IsDragAndDropEnabled() const;
bool IsViewType(const char* const view_type) const { bool IsViewType(const char* const view_type) const {
return !strcmp(GetViewType(), view_type); return !strcmp(GetViewType(), view_type);
} }
...@@ -135,6 +144,8 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -135,6 +144,8 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void SetOpener(GuestViewBase* opener); void SetOpener(GuestViewBase* opener);
// WebContentsObserver implementation. // WebContentsObserver implementation.
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) OVERRIDE FINAL;
virtual void WebContentsDestroyed() OVERRIDE; virtual void WebContentsDestroyed() OVERRIDE;
// WebContentsDelegate implementation. // WebContentsDelegate implementation.
......
...@@ -335,6 +335,11 @@ void WebViewGuest::Attach(WebContents* embedder_web_contents, ...@@ -335,6 +335,11 @@ void WebViewGuest::Attach(WebContents* embedder_web_contents,
AddWebViewToExtensionRendererState(); AddWebViewToExtensionRendererState();
} }
void WebViewGuest::DidStopLoading() {
scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
}
void WebViewGuest::EmbedderDestroyed() { void WebViewGuest::EmbedderDestroyed() {
// TODO(fsamuel): WebRequest event listeners for <webview> should survive // TODO(fsamuel): WebRequest event listeners for <webview> should survive
// reparenting of a <webview> within a single embedder. Right now, we keep // reparenting of a <webview> within a single embedder. Right now, we keep
...@@ -353,6 +358,10 @@ void WebViewGuest::EmbedderDestroyed() { ...@@ -353,6 +358,10 @@ void WebViewGuest::EmbedderDestroyed() {
view_instance_id())); view_instance_id()));
} }
bool WebViewGuest::IsDragAndDropEnabled() const {
return true;
}
bool WebViewGuest::AddMessageToConsole(WebContents* source, bool WebViewGuest::AddMessageToConsole(WebContents* source,
int32 level, int32 level,
const base::string16& message, const base::string16& message,
...@@ -449,10 +458,6 @@ void WebViewGuest::HandleKeyboardEvent( ...@@ -449,10 +458,6 @@ void WebViewGuest::HandleKeyboardEvent(
web_contents(), event); web_contents(), event);
} }
bool WebViewGuest::IsDragAndDropEnabled() {
return true;
}
void WebViewGuest::LoadProgressChanged(content::WebContents* source, void WebViewGuest::LoadProgressChanged(content::WebContents* source,
double progress) { double progress) {
scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
...@@ -838,11 +843,6 @@ void WebViewGuest::DocumentLoadedInFrame( ...@@ -838,11 +843,6 @@ void WebViewGuest::DocumentLoadedInFrame(
InjectChromeVoxIfNeeded(render_view_host); InjectChromeVoxIfNeeded(render_view_host);
} }
void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) {
scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
}
bool WebViewGuest::OnMessageReceived(const IPC::Message& message, bool WebViewGuest::OnMessageReceived(const IPC::Message& message,
RenderFrameHost* render_frame_host) { RenderFrameHost* render_frame_host) {
bool handled = true; bool handled = true;
......
...@@ -69,7 +69,9 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -69,7 +69,9 @@ class WebViewGuest : public GuestView<WebViewGuest>,
// GuestViewBase implementation. // GuestViewBase implementation.
virtual void Attach(content::WebContents* embedder_web_contents, virtual void Attach(content::WebContents* embedder_web_contents,
const base::DictionaryValue& args) OVERRIDE; const base::DictionaryValue& args) OVERRIDE;
virtual void DidStopLoading() OVERRIDE;
virtual void EmbedderDestroyed() OVERRIDE; virtual void EmbedderDestroyed() OVERRIDE;
virtual bool IsDragAndDropEnabled() const OVERRIDE;
// WebContentsDelegate implementation. // WebContentsDelegate implementation.
virtual bool AddMessageToConsole(content::WebContents* source, virtual bool AddMessageToConsole(content::WebContents* source,
...@@ -127,7 +129,6 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -127,7 +129,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
// BrowserPluginGuestDelegate implementation. // BrowserPluginGuestDelegate implementation.
virtual void DidAttach() OVERRIDE; virtual void DidAttach() OVERRIDE;
virtual bool IsDragAndDropEnabled() OVERRIDE;
virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size) virtual void SizeChanged(const gfx::Size& old_size, const gfx::Size& new_size)
OVERRIDE; OVERRIDE;
virtual void RequestPointerLockPermission( virtual void RequestPointerLockPermission(
...@@ -294,8 +295,6 @@ class WebViewGuest : public GuestView<WebViewGuest>, ...@@ -294,8 +295,6 @@ class WebViewGuest : public GuestView<WebViewGuest>,
virtual void DocumentLoadedInFrame( virtual void DocumentLoadedInFrame(
int64 frame_id, int64 frame_id,
content::RenderViewHost* render_view_host) OVERRIDE; content::RenderViewHost* render_view_host) OVERRIDE;
virtual void DidStopLoading(
content::RenderViewHost* render_view_host) OVERRIDE;
virtual bool OnMessageReceived( virtual bool OnMessageReceived(
const IPC::Message& message, const IPC::Message& message,
content::RenderFrameHost* render_frame_host) OVERRIDE; content::RenderFrameHost* render_frame_host) OVERRIDE;
......
...@@ -410,20 +410,6 @@ void BrowserPluginGuest::DidCommitProvisionalLoadForFrame( ...@@ -410,20 +410,6 @@ void BrowserPluginGuest::DidCommitProvisionalLoadForFrame(
RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate"));
} }
void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) {
bool enable_dragdrop = delegate_ && delegate_->IsDragAndDropEnabled();
if (!enable_dragdrop) {
// Initiating a drag from inside a guest is currently not supported without
// the kEnableBrowserPluginDragDrop flag on a linux platform. So inject some
// JS to disable it. http://crbug.com/161112
const char script[] = "window.addEventListener('dragstart', function() { "
" window.event.preventDefault(); "
"});";
render_view_host->GetMainFrame()->ExecuteJavaScript(
base::ASCIIToUTF16(script));
}
}
void BrowserPluginGuest::RenderViewReady() { void BrowserPluginGuest::RenderViewReady() {
RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); RenderViewHost* rvh = GetWebContents()->GetRenderViewHost();
// TODO(fsamuel): Investigate whether it's possible to update state earlier // TODO(fsamuel): Investigate whether it's possible to update state earlier
......
...@@ -154,7 +154,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { ...@@ -154,7 +154,6 @@ class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver {
const GURL& url, const GURL& url,
PageTransition transition_type, PageTransition transition_type,
RenderViewHost* render_view_host) OVERRIDE; RenderViewHost* render_view_host) OVERRIDE;
virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
virtual void RenderViewReady() OVERRIDE; virtual void RenderViewReady() OVERRIDE;
virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
......
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
'public/browser/browser_main_runner.h', 'public/browser/browser_main_runner.h',
'public/browser/browser_message_filter.cc', 'public/browser/browser_message_filter.cc',
'public/browser/browser_message_filter.h', 'public/browser/browser_message_filter.h',
'public/browser/browser_plugin_guest_delegate.cc',
'public/browser/browser_plugin_guest_delegate.h', 'public/browser/browser_plugin_guest_delegate.h',
'public/browser/browser_plugin_guest_manager.cc', 'public/browser/browser_plugin_guest_manager.cc',
'public/browser/browser_plugin_guest_manager.h', 'public/browser/browser_plugin_guest_manager.h',
......
// Copyright 2013 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 "content/public/browser/browser_plugin_guest_delegate.h"
namespace content {
bool BrowserPluginGuestDelegate::IsDragAndDropEnabled() {
return false;
}
} // namespace content
...@@ -26,8 +26,6 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate { ...@@ -26,8 +26,6 @@ class CONTENT_EXPORT BrowserPluginGuestDelegate {
// Notification that the embedder has completed attachment. // Notification that the embedder has completed attachment.
virtual void DidAttach() {} virtual void DidAttach() {}
virtual bool IsDragAndDropEnabled();
// Notifies that the content size of the guest has changed in autosize mode. // Notifies that the content size of the guest has changed in autosize mode.
virtual void SizeChanged(const gfx::Size& old_size, virtual void SizeChanged(const gfx::Size& old_size,
const gfx::Size& new_size) {} const gfx::Size& new_size) {}
......
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