OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/bookmarks/browser/bookmark_utils.h" | 5 #include "components/bookmarks/browser/bookmark_utils.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 135 |
136 // If we're in the middle of an escape sequence, truncate just before it. | 136 // If we're in the middle of an escape sequence, truncate just before it. |
137 if (url[kCleanedUpUrlMaxLength - 1] == '%') | 137 if (url[kCleanedUpUrlMaxLength - 1] == '%') |
138 return url.substr(0, kCleanedUpUrlMaxLength - 1); | 138 return url.substr(0, kCleanedUpUrlMaxLength - 1); |
139 if (url[kCleanedUpUrlMaxLength - 2] == '%') | 139 if (url[kCleanedUpUrlMaxLength - 2] == '%') |
140 return url.substr(0, kCleanedUpUrlMaxLength - 2); | 140 return url.substr(0, kCleanedUpUrlMaxLength - 2); |
141 | 141 |
142 return url.substr(0, kCleanedUpUrlMaxLength); | 142 return url.substr(0, kCleanedUpUrlMaxLength); |
143 } | 143 } |
144 | 144 |
145 // Returns URL if present in clipboard | |
146 GURL ReadClipboardURL() { | |
sky
2014/09/02 17:18:54
ReadClipboardURL -> GetUrlFromClipboard()
ankit
2014/09/03 05:40:39
Done.
| |
147 base::string16 url_text; | |
148 if (!ui::Clipboard::GetForCurrentThread()->IsFormatAvailable( | |
149 ui::Clipboard::GetUrlWFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE)) | |
150 return GURL(); | |
151 | |
152 ui::Clipboard::GetForCurrentThread()->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, | |
153 &url_text); | |
154 return GURL(url_text); | |
155 } | |
156 | |
145 } // namespace | 157 } // namespace |
146 | 158 |
147 QueryFields::QueryFields() {} | 159 QueryFields::QueryFields() {} |
148 QueryFields::~QueryFields() {} | 160 QueryFields::~QueryFields() {} |
149 | 161 |
150 void CloneBookmarkNode(BookmarkModel* model, | 162 void CloneBookmarkNode(BookmarkModel* model, |
151 const std::vector<BookmarkNodeData::Element>& elements, | 163 const std::vector<BookmarkNodeData::Element>& elements, |
152 const BookmarkNode* parent, | 164 const BookmarkNode* parent, |
153 int index_to_add_at, | 165 int index_to_add_at, |
154 bool reset_node_times) { | 166 bool reset_node_times) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 } | 200 } |
189 } | 201 } |
190 | 202 |
191 void PasteFromClipboard(BookmarkModel* model, | 203 void PasteFromClipboard(BookmarkModel* model, |
192 const BookmarkNode* parent, | 204 const BookmarkNode* parent, |
193 int index) { | 205 int index) { |
194 if (!parent) | 206 if (!parent) |
195 return; | 207 return; |
196 | 208 |
197 BookmarkNodeData bookmark_data; | 209 BookmarkNodeData bookmark_data; |
198 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) | 210 if (!bookmark_data.ReadFromClipboard(ui::CLIPBOARD_TYPE_COPY_PASTE)) { |
199 return; | 211 GURL url = ReadClipboardURL(); |
200 | 212 if (!url.is_valid()) |
213 return; | |
214 BookmarkNode node(url); | |
215 node.SetTitle(base::ASCIIToUTF16(url.spec())); | |
216 BookmarkNodeData bookmark(&node); | |
sky
2014/09/02 17:18:54
Nuke this temporary, it's a bit confusingly named
ankit
2014/09/03 05:40:39
Done.
| |
217 bookmark_data = bookmark; | |
218 } | |
201 if (index == -1) | 219 if (index == -1) |
202 index = parent->child_count(); | 220 index = parent->child_count(); |
203 ScopedGroupBookmarkActions group_paste(model); | 221 ScopedGroupBookmarkActions group_paste(model); |
204 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); | 222 CloneBookmarkNode(model, bookmark_data.elements, parent, index, true); |
205 } | 223 } |
206 | 224 |
207 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { | 225 bool CanPasteFromClipboard(BookmarkModel* model, const BookmarkNode* node) { |
208 if (!node || !model->client()->CanBeEditedByUser(node)) | 226 if (!node || !model->client()->CanBeEditedByUser(node)) |
209 return false; | 227 return false; |
210 return BookmarkNodeData::ClipboardContainsBookmarks(); | 228 return (BookmarkNodeData::ClipboardContainsBookmarks() || |
229 ReadClipboardURL().is_valid()); | |
211 } | 230 } |
212 | 231 |
213 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( | 232 std::vector<const BookmarkNode*> GetMostRecentlyModifiedUserFolders( |
214 BookmarkModel* model, | 233 BookmarkModel* model, |
215 size_t max_count) { | 234 size_t max_count) { |
216 std::vector<const BookmarkNode*> nodes; | 235 std::vector<const BookmarkNode*> nodes; |
217 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), | 236 ui::TreeNodeIterator<const BookmarkNode> iterator(model->root_node(), |
218 PruneInvisibleFolders); | 237 PruneInvisibleFolders); |
219 | 238 |
220 while (iterator.has_next()) { | 239 while (iterator.has_next()) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 } | 456 } |
438 return false; | 457 return false; |
439 } | 458 } |
440 | 459 |
441 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { | 460 const BookmarkNode* GetBookmarkNodeByID(const BookmarkModel* model, int64 id) { |
442 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | 461 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. |
443 return GetNodeByID(model->root_node(), id); | 462 return GetNodeByID(model->root_node(), id); |
444 } | 463 } |
445 | 464 |
446 } // namespace bookmarks | 465 } // namespace bookmarks |
OLD | NEW |