| OLD | NEW |
| (Empty) |
| 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_BOOKMARKS_BOOKMARK_UTILS_H_ | |
| 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "chrome/browser/bookmarks/bookmark_node_data.h" | |
| 13 | |
| 14 class BookmarkModel; | |
| 15 class BookmarkNode; | |
| 16 class Profile; | |
| 17 class GURL; | |
| 18 | |
| 19 namespace user_prefs { | |
| 20 class PrefRegistrySyncable; | |
| 21 } | |
| 22 | |
| 23 // A collection of bookmark utility functions used by various parts of the UI | |
| 24 // that show bookmarks (bookmark manager, bookmark bar view, ...) and other | |
| 25 // systems that involve indexing and searching bookmarks. | |
| 26 namespace bookmark_utils { | |
| 27 | |
| 28 // Fields to use when finding matching bookmarks. | |
| 29 struct QueryFields { | |
| 30 QueryFields(); | |
| 31 ~QueryFields(); | |
| 32 | |
| 33 scoped_ptr<base::string16> word_phrase_query; | |
| 34 scoped_ptr<base::string16> url; | |
| 35 scoped_ptr<base::string16> title; | |
| 36 }; | |
| 37 | |
| 38 // Clones bookmark node, adding newly created nodes to |parent| starting at | |
| 39 // |index_to_add_at|. If |reset_node_times| is true cloned bookmarks and | |
| 40 // folders will receive new creation times and folder modification times | |
| 41 // instead of using the values stored in |elements|. | |
| 42 void CloneBookmarkNode(BookmarkModel* model, | |
| 43 const std::vector<BookmarkNodeData::Element>& elements, | |
| 44 const BookmarkNode* parent, | |
| 45 int index_to_add_at, | |
| 46 bool reset_node_times); | |
| 47 | |
| 48 // Copies nodes onto the clipboard. If |remove_nodes| is true the nodes are | |
| 49 // removed after copied to the clipboard. The nodes are copied in such a way | |
| 50 // that if pasted again copies are made. | |
| 51 void CopyToClipboard(BookmarkModel* model, | |
| 52 const std::vector<const BookmarkNode*>& nodes, | |
| 53 bool remove_nodes); | |
| 54 | |
| 55 // Pastes from the clipboard. The new nodes are added to |parent|, unless | |
| 56 // |parent| is null in which case this does nothing. The nodes are inserted | |
| 57 // at |index|. If |index| is -1 the nodes are added to the end. | |
| 58 void PasteFromClipboard(BookmarkModel* model, | |
| 59 const BookmarkNode* parent, | |
| 60 int index); | |
| 61 | |
| 62 // Returns true if the user can copy from the pasteboard. | |
| 63 bool CanPasteFromClipboard(const BookmarkNode* node); | |
| 64 | |
| 65 // Returns a vector containing up to |max_count| of the most recently modified | |
| 66 // folders. This never returns an empty vector. | |
| 67 std::vector<const BookmarkNode*> GetMostRecentlyModifiedFolders( | |
| 68 BookmarkModel* model, size_t max_count); | |
| 69 | |
| 70 // Returns the most recently added bookmarks. This does not return folders, | |
| 71 // only nodes of type url. | |
| 72 void GetMostRecentlyAddedEntries(BookmarkModel* model, | |
| 73 size_t count, | |
| 74 std::vector<const BookmarkNode*>* nodes); | |
| 75 | |
| 76 // Returns true if |n1| was added more recently than |n2|. | |
| 77 bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); | |
| 78 | |
| 79 // Returns up to |max_count| bookmarks from |model| whose url or title contain | |
| 80 // the text |query.word_phrase_query| and exactly match |query.url| and | |
| 81 // |query.title|, for all of the preceding fields that are not NULL. | |
| 82 // |languages| is user's accept-language setting to decode IDN. | |
| 83 void GetBookmarksMatchingProperties(BookmarkModel* model, | |
| 84 const QueryFields& query, | |
| 85 size_t max_count, | |
| 86 const std::string& languages, | |
| 87 std::vector<const BookmarkNode*>* nodes); | |
| 88 | |
| 89 // Register user preferences for Bookmarks Bar. | |
| 90 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
| 91 | |
| 92 // Returns the parent for newly created folders/bookmarks. If |selection| has | |
| 93 // one element and it is a folder, |selection[0]| is returned, otherwise | |
| 94 // |parent| is returned. If |index| is non-null it is set to the index newly | |
| 95 // added nodes should be added at. | |
| 96 const BookmarkNode* GetParentForNewNodes( | |
| 97 const BookmarkNode* parent, | |
| 98 const std::vector<const BookmarkNode*>& selection, | |
| 99 int* index); | |
| 100 | |
| 101 // Deletes the bookmark folders for the given list of |ids|. | |
| 102 void DeleteBookmarkFolders(BookmarkModel* model, const std::vector<int64>& ids); | |
| 103 | |
| 104 // If there are no bookmarks for url, a bookmark is created. | |
| 105 void AddIfNotBookmarked(BookmarkModel* model, | |
| 106 const GURL& url, | |
| 107 const base::string16& title); | |
| 108 | |
| 109 // Removes all bookmarks for the given |url|. | |
| 110 void RemoveAllBookmarks(BookmarkModel* model, const GURL& url); | |
| 111 | |
| 112 // Truncates an overly-long URL, unescapes it, and lower-cases it, | |
| 113 // returning the result. This unescaping makes it possible to match | |
| 114 // substrings that were originally escaped for navigation; for | |
| 115 // example, if the user searched for "a&p", the query would be escaped | |
| 116 // as "a%26p", so without unescaping, an input string of "a&p" would | |
| 117 // no longer match this URL. Note that the resulting unescaped URL | |
| 118 // may not be directly navigable (which is why we escaped it to begin | |
| 119 // with). |languages| is passed to net::FormatUrl(). | |
| 120 base::string16 CleanUpUrlForMatching(const GURL& gurl, | |
| 121 const std::string& languages); | |
| 122 | |
| 123 // Returns the lower-cased title, possibly truncated if the original title | |
| 124 // is overly-long. | |
| 125 base::string16 CleanUpTitleForMatching(const base::string16& title); | |
| 126 | |
| 127 } // namespace bookmark_utils | |
| 128 | |
| 129 // Returns the node with |id|, or NULL if there is no node with |id|. | |
| 130 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id); | |
| 131 | |
| 132 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_UTILS_H_ | |
| OLD | NEW |