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 #ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_
8 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/browser/web_contents_user_data.h"
12 struct BookmarkNodeData
;
13 class BookmarkTabHelperDelegate
;
19 // Per-tab class to manage bookmarks.
20 class BookmarkTabHelper
21 : public BaseBookmarkModelObserver
,
22 public content::WebContentsObserver
,
23 public content::WebContentsUserData
<BookmarkTabHelper
> {
25 // Interface for forwarding bookmark drag and drop to extenstions.
28 virtual void OnDragEnter(const BookmarkNodeData
& data
) = 0;
29 virtual void OnDragOver(const BookmarkNodeData
& data
) = 0;
30 virtual void OnDragLeave(const BookmarkNodeData
& data
) = 0;
31 virtual void OnDrop(const BookmarkNodeData
& data
) = 0;
34 virtual ~BookmarkDrag() {}
37 virtual ~BookmarkTabHelper();
39 void set_delegate(BookmarkTabHelperDelegate
* delegate
) {
43 // It is up to callers to call set_bookmark_drag_delegate(NULL) when
44 // |bookmark_drag| is deleted since this class does not take ownership of
46 void set_bookmark_drag_delegate(BookmarkDrag
* bookmark_drag
) {
47 bookmark_drag_
= bookmark_drag
;
49 BookmarkDrag
* bookmark_drag_delegate() { return bookmark_drag_
; }
51 bool is_starred() const { return is_starred_
; }
53 // Returns true if the bookmark bar should be shown detached.
54 bool ShouldShowBookmarkBar() const;
57 friend class content::WebContentsUserData
<BookmarkTabHelper
>;
59 explicit BookmarkTabHelper(content::WebContents
* web_contents
);
61 // Updates the starred state from the BookmarkModel. If the state has changed,
62 // the delegate is notified.
63 void UpdateStarredStateForCurrentURL();
65 // Overridden from BaseBookmarkModelObserver:
66 virtual void BookmarkModelChanged() OVERRIDE
;
67 virtual void BookmarkModelLoaded(BookmarkModel
* model
,
68 bool ids_reassigned
) OVERRIDE
;
69 virtual void BookmarkNodeAdded(BookmarkModel
* model
,
70 const BookmarkNode
* parent
,
72 virtual void BookmarkNodeRemoved(BookmarkModel
* model
,
73 const BookmarkNode
* parent
,
75 const BookmarkNode
* node
) OVERRIDE
;
76 virtual void BookmarkAllNodesRemoved(BookmarkModel
* model
) OVERRIDE
;
78 virtual void BookmarkNodeChanged(BookmarkModel
* model
,
79 const BookmarkNode
* node
) OVERRIDE
;
81 // Overridden from content::WebContentsObserver:
82 virtual void DidNavigateMainFrame(
83 const content::LoadCommittedDetails
& details
,
84 const content::FrameNavigateParams
& params
) OVERRIDE
;
86 // Whether the current URL is starred.
89 BookmarkModel
* bookmark_model_
;
91 // Our delegate, to notify when the url starred changed.
92 BookmarkTabHelperDelegate
* delegate_
;
94 // The BookmarkDrag is used to forward bookmark drag and drop events to
96 BookmarkDrag
* bookmark_drag_
;
98 DISALLOW_COPY_AND_ASSIGN(BookmarkTabHelper
);
101 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_