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 "components/bookmarks/browser/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 class BookmarkTabHelperDelegate
;
15 struct BookmarkNodeData
;
22 // Per-tab class to manage bookmarks.
23 class BookmarkTabHelper
24 : public BaseBookmarkModelObserver
,
25 public content::WebContentsObserver
,
26 public content::WebContentsUserData
<BookmarkTabHelper
> {
28 // Interface for forwarding bookmark drag and drop to extenstions.
31 virtual void OnDragEnter(const bookmarks::BookmarkNodeData
& data
) = 0;
32 virtual void OnDragOver(const bookmarks::BookmarkNodeData
& data
) = 0;
33 virtual void OnDragLeave(const bookmarks::BookmarkNodeData
& data
) = 0;
34 virtual void OnDrop(const bookmarks::BookmarkNodeData
& data
) = 0;
37 virtual ~BookmarkDrag() {}
40 virtual ~BookmarkTabHelper();
42 void set_delegate(BookmarkTabHelperDelegate
* delegate
) {
46 // It is up to callers to call set_bookmark_drag_delegate(NULL) when
47 // |bookmark_drag| is deleted since this class does not take ownership of
49 void set_bookmark_drag_delegate(BookmarkDrag
* bookmark_drag
) {
50 bookmark_drag_
= bookmark_drag
;
52 BookmarkDrag
* bookmark_drag_delegate() { return bookmark_drag_
; }
54 bool is_starred() const { return is_starred_
; }
56 // Returns true if the bookmark bar should be shown detached.
57 bool ShouldShowBookmarkBar() const;
60 friend class content::WebContentsUserData
<BookmarkTabHelper
>;
62 explicit BookmarkTabHelper(content::WebContents
* web_contents
);
64 // Updates the starred state from the BookmarkModel. If the state has changed,
65 // the delegate is notified.
66 void UpdateStarredStateForCurrentURL();
68 // Overridden from BaseBookmarkModelObserver:
69 virtual void BookmarkModelChanged() override
;
70 virtual void BookmarkModelLoaded(BookmarkModel
* model
,
71 bool ids_reassigned
) override
;
72 virtual void BookmarkNodeAdded(BookmarkModel
* model
,
73 const BookmarkNode
* parent
,
75 virtual void BookmarkNodeRemoved(BookmarkModel
* model
,
76 const BookmarkNode
* parent
,
78 const BookmarkNode
* node
,
79 const std::set
<GURL
>& removed_urls
) override
;
80 virtual void BookmarkAllUserNodesRemoved(
82 const std::set
<GURL
>& removed_urls
) override
;
84 virtual void BookmarkNodeChanged(BookmarkModel
* model
,
85 const BookmarkNode
* node
) override
;
87 // Overridden from content::WebContentsObserver:
88 virtual void DidNavigateMainFrame(
89 const content::LoadCommittedDetails
& details
,
90 const content::FrameNavigateParams
& params
) override
;
91 virtual void DidStartNavigationToPendingEntry(
93 content::NavigationController::ReloadType reload_type
) override
;
95 // Whether the current URL is starred.
98 BookmarkModel
* bookmark_model_
;
100 // Our delegate, to notify when the url starred changed.
101 BookmarkTabHelperDelegate
* delegate_
;
103 // The BookmarkDrag is used to forward bookmark drag and drop events to
105 BookmarkDrag
* bookmark_drag_
;
107 DISALLOW_COPY_AND_ASSIGN(BookmarkTabHelper
);
110 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_