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/bind.h" | 10 #include "base/bind.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/i18n/string_search.h" | 14 #include "base/i18n/string_search.h" |
15 #include "base/metrics/user_metrics_action.h" | 15 #include "base/metrics/user_metrics_action.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "components/bookmarks/browser/bookmark_client.h" | 21 #include "components/bookmarks/browser/bookmark_client.h" |
22 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
23 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" | 23 #include "components/bookmarks/browser/scoped_group_bookmark_actions.h" |
24 #include "components/bookmarks/common/bookmark_pref_names.h" | 24 #include "components/bookmarks/common/bookmark_pref_names.h" |
25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
26 #include "components/query_parser/query_parser.h" | 26 #include "components/query_parser/query_parser.h" |
27 #include "net/base/net_util.h" | 27 #include "components/url_formatter/url_formatter.h" |
28 #include "ui/base/clipboard/clipboard.h" | 28 #include "ui/base/clipboard/clipboard.h" |
29 #include "ui/base/models/tree_node_iterator.h" | 29 #include "ui/base/models/tree_node_iterator.h" |
30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
31 | 31 |
32 using base::Time; | 32 using base::Time; |
33 | 33 |
34 namespace bookmarks { | 34 namespace bookmarks { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 } | 89 } |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 // Returns true if |node|s title or url contains the strings in |words|. | 93 // Returns true if |node|s title or url contains the strings in |words|. |
94 // |languages| argument is user's accept-language setting to decode IDN. | 94 // |languages| argument is user's accept-language setting to decode IDN. |
95 bool DoesBookmarkContainWords(const BookmarkNode* node, | 95 bool DoesBookmarkContainWords(const BookmarkNode* node, |
96 const std::vector<base::string16>& words, | 96 const std::vector<base::string16>& words, |
97 const std::string& languages) { | 97 const std::string& languages) { |
98 return | 98 return DoesBookmarkTextContainWords(node->GetTitle(), words) || |
99 DoesBookmarkTextContainWords(node->GetTitle(), words) || | 99 DoesBookmarkTextContainWords(base::UTF8ToUTF16(node->url().spec()), |
100 DoesBookmarkTextContainWords( | 100 words) || |
101 base::UTF8ToUTF16(node->url().spec()), words) || | 101 DoesBookmarkTextContainWords( |
102 DoesBookmarkTextContainWords(net::FormatUrl( | 102 url_formatter::FormatUrl( |
103 node->url(), languages, net::kFormatUrlOmitNothing, | 103 node->url(), languages, url_formatter::kFormatUrlOmitNothing, |
104 net::UnescapeRule::NORMAL, NULL, NULL, NULL), words); | 104 net::UnescapeRule::NORMAL, NULL, NULL, NULL), |
| 105 words); |
105 } | 106 } |
106 | 107 |
107 // This is used with a tree iterator to skip subtrees which are not visible. | 108 // This is used with a tree iterator to skip subtrees which are not visible. |
108 bool PruneInvisibleFolders(const BookmarkNode* node) { | 109 bool PruneInvisibleFolders(const BookmarkNode* node) { |
109 return !node->IsVisible(); | 110 return !node->IsVisible(); |
110 } | 111 } |
111 | 112 |
112 // This traces parents up to root, determines if node is contained in a | 113 // This traces parents up to root, determines if node is contained in a |
113 // selected folder. | 114 // selected folder. |
114 bool HasSelectedAncestor(BookmarkModel* model, | 115 bool HasSelectedAncestor(BookmarkModel* model, |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 if (index > -1 && model->client()->CanBeEditedByUser(node)) | 498 if (index > -1 && model->client()->CanBeEditedByUser(node)) |
498 model->Remove(node); | 499 model->Remove(node); |
499 } | 500 } |
500 } | 501 } |
501 | 502 |
502 base::string16 CleanUpUrlForMatching( | 503 base::string16 CleanUpUrlForMatching( |
503 const GURL& gurl, | 504 const GURL& gurl, |
504 const std::string& languages, | 505 const std::string& languages, |
505 base::OffsetAdjuster::Adjustments* adjustments) { | 506 base::OffsetAdjuster::Adjustments* adjustments) { |
506 base::OffsetAdjuster::Adjustments tmp_adjustments; | 507 base::OffsetAdjuster::Adjustments tmp_adjustments; |
507 return base::i18n::ToLower(net::FormatUrlWithAdjustments( | 508 return base::i18n::ToLower(url_formatter::FormatUrlWithAdjustments( |
508 GURL(TruncateUrl(gurl.spec())), languages, | 509 GURL(TruncateUrl(gurl.spec())), languages, |
509 net::kFormatUrlOmitUsernamePassword, | 510 url_formatter::kFormatUrlOmitUsernamePassword, |
510 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS, | 511 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS, NULL, |
511 NULL, NULL, adjustments ? adjustments : &tmp_adjustments)); | 512 NULL, adjustments ? adjustments : &tmp_adjustments)); |
512 } | 513 } |
513 | 514 |
514 base::string16 CleanUpTitleForMatching(const base::string16& title) { | 515 base::string16 CleanUpTitleForMatching(const base::string16& title) { |
515 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); | 516 return base::i18n::ToLower(title.substr(0u, kCleanedUpTitleMaxLength)); |
516 } | 517 } |
517 | 518 |
518 bool CanAllBeEditedByUser(BookmarkClient* client, | 519 bool CanAllBeEditedByUser(BookmarkClient* client, |
519 const std::vector<const BookmarkNode*>& nodes) { | 520 const std::vector<const BookmarkNode*>& nodes) { |
520 for (size_t i = 0; i < nodes.size(); ++i) { | 521 for (size_t i = 0; i < nodes.size(); ++i) { |
521 if (!client->CanBeEditedByUser(nodes[i])) | 522 if (!client->CanBeEditedByUser(nodes[i])) |
(...skipping 24 matching lines...) Expand all Loading... |
546 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, | 547 bool HasDescendantsOf(const std::vector<const BookmarkNode*>& list, |
547 const BookmarkNode* root) { | 548 const BookmarkNode* root) { |
548 for (const BookmarkNode* node : list) { | 549 for (const BookmarkNode* node : list) { |
549 if (IsDescendantOf(node, root)) | 550 if (IsDescendantOf(node, root)) |
550 return true; | 551 return true; |
551 } | 552 } |
552 return false; | 553 return false; |
553 } | 554 } |
554 | 555 |
555 } // namespace bookmarks | 556 } // namespace bookmarks |
OLD | NEW |