• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/ui/aura/tab_contents/web_drag_bookmark_handler_aura.h"
6 
7 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "components/bookmarks/browser/bookmark_node_data.h"
12 #include "content/public/browser/web_contents.h"
13 #include "ui/base/dragdrop/os_exchange_data.h"
14 
15 using content::WebContents;
16 
WebDragBookmarkHandlerAura()17 WebDragBookmarkHandlerAura::WebDragBookmarkHandlerAura()
18     : bookmark_tab_helper_(NULL),
19       web_contents_(NULL) {
20 }
21 
~WebDragBookmarkHandlerAura()22 WebDragBookmarkHandlerAura::~WebDragBookmarkHandlerAura() {
23 }
24 
DragInitialize(WebContents * contents)25 void WebDragBookmarkHandlerAura::DragInitialize(WebContents* contents) {
26   // Ideally we would want to initialize the the BookmarkTabHelper member in
27   // the constructor. We cannot do that as the WebDragDest object is
28   // created during the construction of the WebContents object.  The
29   // BookmarkTabHelper is created much later.
30   web_contents_ = contents;
31   if (!bookmark_tab_helper_)
32     bookmark_tab_helper_ = BookmarkTabHelper::FromWebContents(contents);
33 }
34 
OnDragOver()35 void WebDragBookmarkHandlerAura::OnDragOver() {
36   if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) {
37     if (bookmark_drag_data_.is_valid())
38       bookmark_tab_helper_->bookmark_drag_delegate()->OnDragOver(
39           bookmark_drag_data_);
40   }
41 }
42 
OnReceiveDragData(const ui::OSExchangeData & data)43 void WebDragBookmarkHandlerAura::OnReceiveDragData(
44     const ui::OSExchangeData& data) {
45   if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) {
46     // Read the bookmark drag data and save it for use in later events in this
47     // drag.
48     bookmark_drag_data_.Read(data);
49   }
50 }
51 
OnDragEnter()52 void WebDragBookmarkHandlerAura::OnDragEnter() {
53   if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) {
54     if (bookmark_drag_data_.is_valid())
55       bookmark_tab_helper_->bookmark_drag_delegate()->OnDragEnter(
56           bookmark_drag_data_);
57   }
58 }
59 
OnDrop()60 void WebDragBookmarkHandlerAura::OnDrop() {
61   if (bookmark_tab_helper_) {
62     if (bookmark_tab_helper_->bookmark_drag_delegate()) {
63       if (bookmark_drag_data_.is_valid()) {
64         bookmark_tab_helper_->bookmark_drag_delegate()->OnDrop(
65             bookmark_drag_data_);
66       }
67     }
68 
69     // Focus the target browser.
70     Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
71     if (browser)
72       browser->window()->Show();
73   }
74 
75   bookmark_drag_data_.Clear();
76 }
77 
OnDragLeave()78 void WebDragBookmarkHandlerAura::OnDragLeave() {
79   if (bookmark_tab_helper_ && bookmark_tab_helper_->bookmark_drag_delegate()) {
80     if (bookmark_drag_data_.is_valid())
81       bookmark_tab_helper_->bookmark_drag_delegate()->OnDragLeave(
82           bookmark_drag_data_);
83   }
84 
85   bookmark_drag_data_.Clear();
86 }
87