Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / aura / tab_contents / web_drag_bookmark_handler_aura.cc
blobd96511c6c5d9e602f51553f4ddcc4b4de604243e
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.
5 #include "chrome/browser/ui/aura/tab_contents/web_drag_bookmark_handler_aura.h"
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"
15 using content::WebContents;
17 WebDragBookmarkHandlerAura::WebDragBookmarkHandlerAura()
18 : bookmark_tab_helper_(NULL),
19 web_contents_(NULL) {
22 WebDragBookmarkHandlerAura::~WebDragBookmarkHandlerAura() {
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);
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_);
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);
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_);
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_);
69 // Focus the target browser.
70 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
71 if (browser)
72 browser->window()->Show();
75 bookmark_drag_data_.Clear();
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_);
85 bookmark_drag_data_.Clear();