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_UTILS_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_H_
10 #include "base/strings/string16.h"
11 #include "chrome/browser/ui/host_desktop.h"
12 #include "ui/base/window_open_disposition.h"
13 #include "ui/gfx/native_widget_types.h"
22 struct BookmarkNodeData
;
36 class DropTargetEvent
;
41 // Number of bookmarks we'll open before prompting the user to see if they
42 // really want to open all.
44 // NOTE: treat this as a const. It is not const so unit tests can change the
46 extern int num_bookmark_urls_before_prompting
;
48 // Opens all the bookmarks in |nodes| that are of type url and all the child
49 // bookmarks that are of type url for folders in |nodes|. |initial_disposition|
50 // dictates how the first URL is opened, all subsequent URLs are opened as
51 // background tabs. |navigator| is used to open the URLs.
52 void OpenAll(gfx::NativeWindow parent
,
53 content::PageNavigator
* navigator
,
54 const std::vector
<const bookmarks::BookmarkNode
*>& nodes
,
55 WindowOpenDisposition initial_disposition
,
56 content::BrowserContext
* browser_context
);
58 // Convenience for OpenAll() with a single BookmarkNode.
59 void OpenAll(gfx::NativeWindow parent
,
60 content::PageNavigator
* navigator
,
61 const bookmarks::BookmarkNode
* node
,
62 WindowOpenDisposition initial_disposition
,
63 content::BrowserContext
* browser_context
);
65 // Asks the user before deleting a non-empty bookmark folder.
66 bool ConfirmDeleteBookmarkNode(const bookmarks::BookmarkNode
* node
,
67 gfx::NativeWindow window
);
69 // Shows the bookmark all tabs dialog.
70 void ShowBookmarkAllTabsDialog(Browser
* browser
);
72 // Returns true if OpenAll() can open at least one bookmark of type url
75 const std::vector
<const bookmarks::BookmarkNode
*>& selection
);
77 // Returns true if OpenAll() can open at least one bookmark of type url
78 // in |selection| with incognito mode.
79 bool HasBookmarkURLsAllowedInIncognitoMode(
80 const std::vector
<const bookmarks::BookmarkNode
*>& selection
,
81 content::BrowserContext
* browser_context
);
83 // Returns the bookmarkable URL for |web_contents|.
84 // This is normally the current URL, but when the page is the Instant Extended
85 // New Tab Page, the precise current URL may reflect various flags or other
86 // implementation details that don't represent data we should store
87 // in the bookmark. In this case we instead return a URL that always
88 // means "NTP" instead of the current URL.
89 GURL
GetURLToBookmark(content::WebContents
* web_contents
);
91 // Fills in the URL and title for a bookmark of |web_contents|.
92 void GetURLAndTitleToBookmark(content::WebContents
* web_contents
,
94 base::string16
* title
);
96 // Toggles whether the bookmark bar is shown only on the new tab page or on
97 // all tabs. This is a preference modifier, not a visual modifier.
98 void ToggleBookmarkBarWhenVisible(content::BrowserContext
* browser_context
);
100 // Returns a formatted version of |url| appropriate to display to a user with
101 // the given |prefs|, which may be NULL. When re-parsing this URL, clients
102 // should call url_formatter::FixupURL().
103 base::string16
FormatBookmarkURLForDisplay(const GURL
& url
,
104 const PrefService
* prefs
);
106 // Returns whether the Apps shortcut is enabled. If true, then the visibility
107 // of the Apps shortcut should be controllable via an item in the bookmark
109 bool IsAppsShortcutEnabled(Profile
* profile
,
110 chrome::HostDesktopType host_desktop_type
);
112 // Returns true if the Apps shortcut should be displayed in the bookmark bar.
113 bool ShouldShowAppsShortcutInBookmarkBar(
115 chrome::HostDesktopType host_desktop_type
);
117 // Whether the menu item and shortcut to bookmark a page should be removed from
118 // the user interface.
119 bool ShouldRemoveBookmarkThisPageUI(Profile
* profile
);
121 // Whether the menu item and shortcut to bookmark open pages should be removed
122 // from the user interface.
123 bool ShouldRemoveBookmarkOpenPagesUI(Profile
* profile
);
125 // Returns the drag operations for the specified node.
126 int GetBookmarkDragOperation(content::BrowserContext
* browser_context
,
127 const bookmarks::BookmarkNode
* node
);
129 // Calculates the drop operation given |source_operations| and the ideal
130 // set of drop operations (|operations|). This prefers the following ordering:
131 // COPY, LINK then MOVE.
132 int GetPreferredBookmarkDropOperation(int source_operations
, int operations
);
134 // Returns the preferred drop operation on a bookmark menu/bar.
135 // |parent| is the parent node the drop is to occur on and |index| the index the
137 int GetBookmarkDropOperation(Profile
* profile
,
138 const ui::DropTargetEvent
& event
,
139 const bookmarks::BookmarkNodeData
& data
,
140 const bookmarks::BookmarkNode
* parent
,
143 // Returns true if the bookmark data can be dropped on |drop_parent| at
144 // |index|. A drop from a separate profile is always allowed, where as
145 // a drop from the same profile is only allowed if none of the nodes in
146 // |data| are an ancestor of |drop_parent| and one of the nodes isn't already
147 // a child of |drop_parent| at |index|.
148 bool IsValidBookmarkDropLocation(Profile
* profile
,
149 const bookmarks::BookmarkNodeData
& data
,
150 const bookmarks::BookmarkNode
* drop_parent
,
153 #if defined(TOOLKIT_VIEWS)
154 // TODO(estade): If Mac wants to use these, return gfx::Image instead.
155 gfx::ImageSkia
GetBookmarkFolderIcon();
156 gfx::ImageSkia
GetBookmarkSupervisedFolderIcon();
157 gfx::ImageSkia
GetBookmarkManagedFolderIcon();
160 } // namespace chrome
162 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_UTILS_H_