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 bookmarks::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 ~BookmarkTabHelper() override
;
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 bookmarks::BaseBookmarkModelObserver:
69 void BookmarkModelChanged() override
;
70 void BookmarkModelLoaded(bookmarks::BookmarkModel
* model
,
71 bool ids_reassigned
) override
;
72 void BookmarkNodeAdded(bookmarks::BookmarkModel
* model
,
73 const bookmarks::BookmarkNode
* parent
,
75 void BookmarkNodeRemoved(bookmarks::BookmarkModel
* model
,
76 const bookmarks::BookmarkNode
* parent
,
78 const bookmarks::BookmarkNode
* node
,
79 const std::set
<GURL
>& removed_urls
) override
;
80 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel
* model
,
81 const std::set
<GURL
>& removed_urls
) override
;
82 void BookmarkNodeChanged(bookmarks::BookmarkModel
* model
,
83 const bookmarks::BookmarkNode
* node
) override
;
85 // Overridden from content::WebContentsObserver:
86 void DidNavigateMainFrame(
87 const content::LoadCommittedDetails
& details
,
88 const content::FrameNavigateParams
& params
) override
;
89 void DidStartNavigationToPendingEntry(
91 content::NavigationController::ReloadType reload_type
) override
;
93 // Whether the current URL is starred.
96 bookmarks::BookmarkModel
* bookmark_model_
;
98 // Our delegate, to notify when the url starred changed.
99 BookmarkTabHelperDelegate
* delegate_
;
101 // The BookmarkDrag is used to forward bookmark drag and drop events to
103 BookmarkDrag
* bookmark_drag_
;
105 DISALLOW_COPY_AND_ASSIGN(BookmarkTabHelper
);
108 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_