Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils.cc

Issue 113815: Support for searching bookmarks for IDN.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include "app/drag_drop_types.h" 7 #include "app/drag_drop_types.h"
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 // TODO(port): Port these files. 9 // TODO(port): Port these files.
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/browser_list.h" 22 #include "chrome/browser/browser_list.h"
23 #include "chrome/browser/history/query_parser.h" 23 #include "chrome/browser/history/query_parser.h"
24 #include "chrome/browser/profile.h" 24 #include "chrome/browser/profile.h"
25 #include "chrome/browser/tab_contents/page_navigator.h" 25 #include "chrome/browser/tab_contents/page_navigator.h"
26 #include "chrome/browser/tab_contents/tab_contents.h" 26 #include "chrome/browser/tab_contents/tab_contents.h"
27 #include "chrome/common/notification_service.h" 27 #include "chrome/common/notification_service.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "chrome/common/pref_service.h" 29 #include "chrome/common/pref_service.h"
30 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
31 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "net/base/net_util.h"
32 #include "views/event.h" 33 #include "views/event.h"
33 34
34 using base::Time; 35 using base::Time;
35 36
36 namespace { 37 namespace {
37 38
38 // A PageNavigator implementation that creates a new Browser. This is used when 39 // A PageNavigator implementation that creates a new Browser. This is used when
39 // opening a url and there is no Browser open. The Browser is created the first 40 // opening a url and there is no Browser open. The Browser is created the first
40 // time the PageNavigator method is invoked. 41 // time the PageNavigator method is invoked.
41 class NewBrowserPageNavigator : public PageNavigator { 42 class NewBrowserPageNavigator : public PageNavigator {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool DoesBookmarkTextContainWords(const std::wstring& text, 171 bool DoesBookmarkTextContainWords(const std::wstring& text,
171 const std::vector<std::wstring>& words) { 172 const std::vector<std::wstring>& words) {
172 for (size_t i = 0; i < words.size(); ++i) { 173 for (size_t i = 0; i < words.size(); ++i) {
173 if (text.find(words[i]) == std::wstring::npos) 174 if (text.find(words[i]) == std::wstring::npos)
174 return false; 175 return false;
175 } 176 }
176 return true; 177 return true;
177 } 178 }
178 179
179 // Returns true if |node|s title or url contains the strings in |words|. 180 // Returns true if |node|s title or url contains the strings in |words|.
181 // |languages| argument is user's accept-language setting to decode IDN.
180 bool DoesBookmarkContainWords(BookmarkNode* node, 182 bool DoesBookmarkContainWords(BookmarkNode* node,
181 const std::vector<std::wstring>& words) { 183 const std::vector<std::wstring>& words,
184 const std::wstring& languages) {
182 return 185 return
183 DoesBookmarkTextContainWords( 186 DoesBookmarkTextContainWords(
184 l10n_util::ToLower(node->GetTitle()), words) || 187 l10n_util::ToLower(node->GetTitle()), words) ||
185 DoesBookmarkTextContainWords(UTF8ToWide(node->GetURL().spec()), words); 188 DoesBookmarkTextContainWords(UTF8ToWide(node->GetURL().spec()), words) ||
189 DoesBookmarkTextContainWords(net::FormatUrl(
190 node->GetURL(), languages, false, true, NULL, NULL), words);
186 } 191 }
187 192
188 } // namespace 193 } // namespace
189 194
190 namespace bookmark_utils { 195 namespace bookmark_utils {
191 196
192 int num_urls_before_prompting = 15; 197 int num_urls_before_prompting = 15;
193 198
194 int PreferredDropOperation(int source_operations, int operations) { 199 int PreferredDropOperation(int source_operations, int operations) {
195 int common_ops = (source_operations & operations); 200 int common_ops = (source_operations & operations);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 476 }
472 } 477 }
473 478
474 bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2) { 479 bool MoreRecentlyAdded(BookmarkNode* n1, BookmarkNode* n2) {
475 return n1->date_added() > n2->date_added(); 480 return n1->date_added() > n2->date_added();
476 } 481 }
477 482
478 void GetBookmarksContainingText(BookmarkModel* model, 483 void GetBookmarksContainingText(BookmarkModel* model,
479 const std::wstring& text, 484 const std::wstring& text,
480 size_t max_count, 485 size_t max_count,
486 const std::wstring& languages,
481 std::vector<BookmarkNode*>* nodes) { 487 std::vector<BookmarkNode*>* nodes) {
482 std::vector<std::wstring> words; 488 std::vector<std::wstring> words;
483 QueryParser parser; 489 QueryParser parser;
484 parser.ExtractQueryWords(l10n_util::ToLower(text), &words); 490 parser.ExtractQueryWords(l10n_util::ToLower(text), &words);
485 if (words.empty()) 491 if (words.empty())
486 return; 492 return;
487 493
488 TreeNodeIterator<BookmarkNode> iterator(model->root_node()); 494 TreeNodeIterator<BookmarkNode> iterator(model->root_node());
489 while (iterator.has_next()) { 495 while (iterator.has_next()) {
490 BookmarkNode* node = iterator.Next(); 496 BookmarkNode* node = iterator.Next();
491 if (node->is_url() && DoesBookmarkContainWords(node, words)) { 497 if (node->is_url() && DoesBookmarkContainWords(node, words, languages)) {
492 nodes->push_back(node); 498 nodes->push_back(node);
493 if (nodes->size() == max_count) 499 if (nodes->size() == max_count)
494 return; 500 return;
495 } 501 }
496 } 502 }
497 } 503 }
498 504
499 bool DoesBookmarkContainText(BookmarkNode* node, const std::wstring& text) { 505 bool DoesBookmarkContainText(BookmarkNode* node,
506 const std::wstring& text,
507 const std::wstring& languages) {
500 std::vector<std::wstring> words; 508 std::vector<std::wstring> words;
501 QueryParser parser; 509 QueryParser parser;
502 parser.ExtractQueryWords(l10n_util::ToLower(text), &words); 510 parser.ExtractQueryWords(l10n_util::ToLower(text), &words);
503 if (words.empty()) 511 if (words.empty())
504 return false; 512 return false;
505 513
506 return (node->is_url() && DoesBookmarkContainWords(node, words)); 514 return (node->is_url() && DoesBookmarkContainWords(node, words, languages));
507 } 515 }
508 516
509 void ApplyEditsWithNoGroupChange(BookmarkModel* model, 517 void ApplyEditsWithNoGroupChange(BookmarkModel* model,
510 BookmarkNode* parent, 518 BookmarkNode* parent,
511 BookmarkNode* node, 519 BookmarkNode* node,
512 const std::wstring& new_title, 520 const std::wstring& new_title,
513 const GURL& new_url, 521 const GURL& new_url,
514 BookmarkEditor::Handler* handler) { 522 BookmarkEditor::Handler* handler) {
515 BookmarkNode* old_parent = node ? node->GetParent() : NULL; 523 BookmarkNode* old_parent = node ? node->GetParent() : NULL;
516 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1; 524 const int old_index = old_parent ? old_parent->IndexOfChild(node) : -1;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 613
606 // Formerly in BookmarkTableView 614 // Formerly in BookmarkTableView
607 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1); 615 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth1, -1);
608 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1); 616 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth1, -1);
609 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1); 617 prefs->RegisterIntegerPref(prefs::kBookmarkTableNameWidth2, -1);
610 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1); 618 prefs->RegisterIntegerPref(prefs::kBookmarkTableURLWidth2, -1);
611 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1); 619 prefs->RegisterIntegerPref(prefs::kBookmarkTablePathWidth, -1);
612 } 620 }
613 621
614 } // namespace bookmark_utils 622 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.h ('k') | chrome/browser/bookmarks/bookmark_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698