Commit b006bdf2 authored by jam@chromium.org's avatar jam@chromium.org

Separate out the Windows bookmark handling code out of the core drag & drop...

Separate out the Windows bookmark handling code out of the core drag & drop target class. This matches what we do on mac/gtk and is in prepartion for moving the core class to content (like what we did for mac/gtk).

BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9564034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124553 0039d316-1c4b-4281-b951-d872f2087c98
parent 76769350
// Copyright (c) 2011 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 "chrome/browser/tab_contents/web_drag_bookmark_handler_win.h"
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_win.h"
using content::WebContents;
WebDragBookmarkHandlerWin::WebDragBookmarkHandlerWin()
: tab_(NULL) {
}
WebDragBookmarkHandlerWin::~WebDragBookmarkHandlerWin() {
}
void WebDragBookmarkHandlerWin::DragInitialize(WebContents* contents) {
// Ideally we would want to initialize the the TabContentsWrapper member in
// the constructor. We cannot do that as the WebDragTargetWin object is
// created during the construction of the TabContents object. The
// TabContentsWrapper is created much later.
DCHECK(tab_ ? (tab_->web_contents() == contents) : true);
if (!tab_)
tab_ = TabContentsWrapper::GetCurrentWrapperForContents(contents);
}
void WebDragBookmarkHandlerWin::OnDragOver(IDataObject* data_object) {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver(
bookmark_drag_data);
}
}
void WebDragBookmarkHandlerWin::OnDragEnter(IDataObject* data_object) {
// This is non-null if web_contents_ is showing an ExtensionWebUI with
// support for (at the moment experimental) drag and drop extensions.
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter(
bookmark_drag_data);
}
}
void WebDragBookmarkHandlerWin::OnDrop(IDataObject* data_object) {
// This is non-null if tab_contents_ is showing an ExtensionWebUI with
// support for (at the moment experimental) drag and drop extensions.
if (tab_) {
if (tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data)) {
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop(
bookmark_drag_data);
}
}
// Focus the target browser.
Browser* browser = Browser::GetBrowserForController(
&tab_->web_contents()->GetController(), NULL);
if (browser)
browser->window()->Show();
}
}
void WebDragBookmarkHandlerWin::OnDragLeave(IDataObject* data_object) {
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave(
bookmark_drag_data);
}
}
// Copyright (c) 2012 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 CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_WIN_H_
#define CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_WIN_H_
#pragma once
#include "base/compiler_specific.h"
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "content/browser/tab_contents/web_drag_dest_delegate.h"
class TabContentsWrapper;
// Chrome needs to intercept content drag events so it can dispatch them to the
// bookmarks and extensions system.
class WebDragBookmarkHandlerWin : public content::WebDragDestDelegate {
public:
WebDragBookmarkHandlerWin();
virtual ~WebDragBookmarkHandlerWin();
// Overridden from content::WebDragDestDelegate:
virtual void DragInitialize(content::WebContents* contents) OVERRIDE;
virtual void OnDragOver(IDataObject* data_object) OVERRIDE;
virtual void OnDragEnter(IDataObject* data_object) OVERRIDE;
virtual void OnDrop(IDataObject* data_object) OVERRIDE;
virtual void OnDragLeave(IDataObject* data_object) OVERRIDE;
private:
// The TabContentsWrapper for the drag.
// Weak reference; may be NULL if the contents aren't contained in a wrapper
// (e.g. WebUI dialogs).
TabContentsWrapper* tab_;
DISALLOW_COPY_AND_ASSIGN(WebDragBookmarkHandlerWin);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_WEB_DRAG_BOOKMARK_HANDLER_WIN_H_
......@@ -7,13 +7,10 @@
#include <windows.h>
#include <shlobj.h>
#include "chrome/browser/bookmarks/bookmark_node_data.h"
#include "chrome/browser/tab_contents/web_drag_bookmark_handler_win.h"
#include "chrome/browser/tab_contents/web_drag_utils_win.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "content/browser/renderer_host/render_view_host.h"
#include "content/browser/tab_contents/web_drag_dest_delegate.h"
#include "content/public/browser/web_contents.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
......@@ -93,13 +90,17 @@ class InterstitialDropTarget {
WebDropTarget::WebDropTarget(HWND source_hwnd, WebContents* web_contents)
: ui::DropTarget(source_hwnd),
web_contents_(web_contents),
tab_(NULL),
current_rvh_(NULL),
drag_cursor_(WebDragOperationNone),
interstitial_drop_target_(new InterstitialDropTarget(web_contents)) {
interstitial_drop_target_(new InterstitialDropTarget(web_contents)),
delegate_(new WebDragBookmarkHandlerWin()) {
}
WebDropTarget::~WebDropTarget() {
// TODO(jam): this will be owned by chrome when it moves, so no scoped
// pointer.
if (delegate_)
delete delegate_;
}
DWORD WebDropTarget::OnDragEnter(IDataObject* data_object,
......@@ -108,8 +109,8 @@ DWORD WebDropTarget::OnDragEnter(IDataObject* data_object,
DWORD effects) {
current_rvh_ = web_contents_->GetRenderViewHost();
if (!tab_)
tab_ = TabContentsWrapper::GetCurrentWrapperForContents(web_contents_);
if (delegate_)
delegate_->DragInitialize(web_contents_);
// Don't pass messages to the renderer if an interstitial page is showing
// because we don't want the interstitial page to navigate. Instead,
......@@ -134,16 +135,8 @@ DWORD WebDropTarget::OnDragEnter(IDataObject* data_object,
gfx::Point(cursor_position.x, cursor_position.y),
web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects));
// This is non-null if web_contents_ is showing an ExtensionWebUI with
// support for (at the moment experimental) drag and drop extensions.
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragEnter(
bookmark_drag_data);
}
if (delegate_)
delegate_->OnDragEnter(data_object);
// We lie here and always return a DROPEFFECT because we don't want to
// wait for the IPC call to return.
......@@ -168,14 +161,8 @@ DWORD WebDropTarget::OnDragOver(IDataObject* data_object,
gfx::Point(cursor_position.x, cursor_position.y),
web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects));
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragOver(
bookmark_drag_data);
}
if (delegate_)
delegate_->OnDragOver(data_object);
return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
}
......@@ -191,14 +178,8 @@ void WebDropTarget::OnDragLeave(IDataObject* data_object) {
web_contents_->GetRenderViewHost()->DragTargetDragLeave();
}
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDragLeave(
bookmark_drag_data);
}
if (delegate_)
delegate_->OnDragLeave(data_object);
}
DWORD WebDropTarget::OnDrop(IDataObject* data_object,
......@@ -221,23 +202,11 @@ DWORD WebDropTarget::OnDrop(IDataObject* data_object,
gfx::Point(client_pt.x, client_pt.y),
gfx::Point(cursor_position.x, cursor_position.y));
if (tab_ && tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()) {
ui::OSExchangeData os_exchange_data(
new ui::OSExchangeDataProviderWin(data_object));
BookmarkNodeData bookmark_drag_data;
if (bookmark_drag_data.Read(os_exchange_data))
tab_->bookmark_tab_helper()->GetBookmarkDragDelegate()->OnDrop(
bookmark_drag_data);
}
if (delegate_)
delegate_->OnDrop(data_object);
current_rvh_ = NULL;
// Focus the target browser.
Browser* browser = Browser::GetBrowserForController(
&web_contents_->GetController(), NULL);
if (browser)
browser->window()->Show();
// This isn't always correct, but at least it's a close approximation.
// For now, we always map a move to a copy to prevent potential data loss.
DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_);
......
......@@ -12,10 +12,10 @@
class InterstitialDropTarget;
class RenderViewHost;
class TabContentsWrapper;
namespace content {
class WebContents;
class WebDragDestDelegate;
}
// A helper object that provides drop capabilities to a TabContents. The
......@@ -32,6 +32,9 @@ class WebDropTarget : public ui::DropTarget {
drag_cursor_ = op;
}
content::WebDragDestDelegate* delegate() const { return delegate_; }
void set_delegate(content::WebDragDestDelegate* d) { delegate_ = d; }
protected:
virtual DWORD OnDragEnter(IDataObject* data_object,
DWORD key_state,
......@@ -54,11 +57,6 @@ class WebDropTarget : public ui::DropTarget {
// Our associated WebContents.
content::WebContents* web_contents_;
// The TabContentsWrapper for |tab_contents_|.
// Weak reference; may be NULL if the contents aren't contained in a wrapper
// (e.g. WebUI dialogs).
TabContentsWrapper* tab_;
// We keep track of the render view host we're dragging over. If it changes
// during a drag, we need to re-send the DragEnter message. WARNING:
// this pointer should never be dereferenced. We only use it for comparing
......@@ -73,6 +71,9 @@ class WebDropTarget : public ui::DropTarget {
// page is showing.
scoped_ptr<InterstitialDropTarget> interstitial_drop_target_;
// A delegate that can receive drag information about drag events.
content::WebDragDestDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(WebDropTarget);
};
......
......@@ -2545,6 +2545,8 @@
'browser/tab_contents/web_drag_bookmark_handler_gtk.h',
'browser/tab_contents/web_drag_bookmark_handler_mac.h',
'browser/tab_contents/web_drag_bookmark_handler_mac.mm',
'browser/tab_contents/web_drag_bookmark_handler_win.cc',
'browser/tab_contents/web_drag_bookmark_handler_win.h',
'browser/tab_contents/web_drag_source_win.cc',
'browser/tab_contents/web_drag_source_win.h',
'browser/tab_contents/web_drag_utils_win.cc',
......
......@@ -11,7 +11,10 @@
#endif // TOOLKIT_USES_GTK
#include "base/string16.h"
#include "content/common/content_export.h"
#if defined(OS_WIN)
#include "ui/base/dragdrop/drop_target.h"
#endif
class GURL;
......@@ -20,7 +23,7 @@ namespace content {
class WebContents;
// An optional delegate that listens for drags of bookmark data.
class CONTENT_EXPORT WebDragDestDelegate {
class WebDragDestDelegate {
public:
// Announces that a drag has started. It's valid that a drag starts, along
// with over/enter/leave/drop notifications without receiving any bookmark
......@@ -28,9 +31,18 @@ class CONTENT_EXPORT WebDragDestDelegate {
virtual void DragInitialize(WebContents* contents) = 0;
// Notifications of drag progression.
#if defined(OS_WIN)
virtual void OnDragOver(IDataObject* data_object) = 0;
virtual void OnDragEnter(IDataObject* data_object) = 0;
virtual void OnDrop(IDataObject* data_object) = 0;
virtual void OnDragLeave(IDataObject* data_object) = 0;
#else
virtual void OnDragOver() = 0;
virtual void OnDragEnter() = 0;
virtual void OnDrop() = 0;
// This should also clear any state kept about this drag.
virtual void OnDragLeave() = 0;
#endif
#if defined(TOOLKIT_USES_GTK)
// Returns the bookmark atom type. GTK and Views return different values here.
......@@ -43,9 +55,6 @@ class CONTENT_EXPORT WebDragDestDelegate {
const string16& title) = 0;
#endif // TOOLKIT_USES_GTK
// This should also clear any state kept about this drag.
virtual void OnDragLeave() = 0;
virtual ~WebDragDestDelegate() {}
};
......
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