• 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 #ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_
7 
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"
11 
12 class BookmarkTabHelperDelegate;
13 
14 namespace bookmarks {
15 struct BookmarkNodeData;
16 }
17 
18 namespace content {
19 class WebContents;
20 }
21 
22 // Per-tab class to manage bookmarks.
23 class BookmarkTabHelper
24     : public BaseBookmarkModelObserver,
25       public content::WebContentsObserver,
26       public content::WebContentsUserData<BookmarkTabHelper> {
27  public:
28   // Interface for forwarding bookmark drag and drop to extenstions.
29   class BookmarkDrag {
30    public:
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;
35 
36    protected:
~BookmarkDrag()37     virtual ~BookmarkDrag() {}
38   };
39 
40   virtual ~BookmarkTabHelper();
41 
set_delegate(BookmarkTabHelperDelegate * delegate)42   void set_delegate(BookmarkTabHelperDelegate* delegate) {
43     delegate_ = delegate;
44   }
45 
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
48   // |bookmark_drag|.
set_bookmark_drag_delegate(BookmarkDrag * bookmark_drag)49   void set_bookmark_drag_delegate(BookmarkDrag* bookmark_drag) {
50     bookmark_drag_ = bookmark_drag;
51   }
bookmark_drag_delegate()52   BookmarkDrag* bookmark_drag_delegate() { return bookmark_drag_; }
53 
is_starred()54   bool is_starred() const { return is_starred_; }
55 
56   // Returns true if the bookmark bar should be shown detached.
57   bool ShouldShowBookmarkBar() const;
58 
59  private:
60   friend class content::WebContentsUserData<BookmarkTabHelper>;
61 
62   explicit BookmarkTabHelper(content::WebContents* web_contents);
63 
64   // Updates the starred state from the BookmarkModel. If the state has changed,
65   // the delegate is notified.
66   void UpdateStarredStateForCurrentURL();
67 
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,
74                                  int index) OVERRIDE;
75   virtual void BookmarkNodeRemoved(BookmarkModel* model,
76                                    const BookmarkNode* parent,
77                                    int old_index,
78                                    const BookmarkNode* node,
79                                    const std::set<GURL>& removed_urls) OVERRIDE;
80   virtual void BookmarkAllUserNodesRemoved(
81       BookmarkModel* model,
82       const std::set<GURL>& removed_urls) OVERRIDE;
83 
84   virtual void BookmarkNodeChanged(BookmarkModel* model,
85                                    const BookmarkNode* node) OVERRIDE;
86 
87   // Overridden from content::WebContentsObserver:
88   virtual void DidNavigateMainFrame(
89       const content::LoadCommittedDetails& details,
90       const content::FrameNavigateParams& params) OVERRIDE;
91 
92   // Whether the current URL is starred.
93   bool is_starred_;
94 
95   BookmarkModel* bookmark_model_;
96 
97   // Our delegate, to notify when the url starred changed.
98   BookmarkTabHelperDelegate* delegate_;
99 
100   // The BookmarkDrag is used to forward bookmark drag and drop events to
101   // extensions.
102   BookmarkDrag* bookmark_drag_;
103 
104   DISALLOW_COPY_AND_ASSIGN(BookmarkTabHelper);
105 };
106 
107 #endif  // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_TAB_HELPER_H_
108