| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/bookmarks/bookmarks_api.h" | 5 #include "chrome/browser/extensions/api/bookmarks/bookmarks_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 true); | 512 true); |
| 513 results_ = bookmarks::GetSubTree::Results::Create(nodes); | 513 results_ = bookmarks::GetSubTree::Results::Create(nodes); |
| 514 return true; | 514 return true; |
| 515 } | 515 } |
| 516 | 516 |
| 517 bool BookmarksSearchFunction::RunOnReady() { | 517 bool BookmarksSearchFunction::RunOnReady() { |
| 518 scoped_ptr<bookmarks::Search::Params> params( | 518 scoped_ptr<bookmarks::Search::Params> params( |
| 519 bookmarks::Search::Params::Create(*args_)); | 519 bookmarks::Search::Params::Create(*args_)); |
| 520 EXTENSION_FUNCTION_VALIDATE(params.get()); | 520 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 521 | 521 |
| 522 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); | |
| 523 std::string lang = prefs->GetString(prefs::kAcceptLanguages); | |
| 524 std::vector<const BookmarkNode*> nodes; | 522 std::vector<const BookmarkNode*> nodes; |
| 525 if (params->query.as_string) { | 523 if (params->query.as_string) { |
| 526 ::bookmarks::QueryFields query; | 524 ::bookmarks::QueryFields query; |
| 527 query.word_phrase_query.reset( | 525 query.word_phrase_query.reset( |
| 528 new base::string16(base::UTF8ToUTF16(*params->query.as_string))); | 526 new base::string16(base::UTF8ToUTF16(*params->query.as_string))); |
| 529 ::bookmarks::GetBookmarksMatchingProperties( | 527 ::bookmarks::GetBookmarksMatchingProperties( |
| 530 BookmarkModelFactory::GetForProfile(GetProfile()), | 528 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 531 query, | 529 query, |
| 532 std::numeric_limits<int>::max(), | 530 std::numeric_limits<int>::max(), |
| 533 lang, | |
| 534 &nodes); | 531 &nodes); |
| 535 } else { | 532 } else { |
| 536 DCHECK(params->query.as_object); | 533 DCHECK(params->query.as_object); |
| 537 const bookmarks::Search::Params::Query::Object& object = | 534 const bookmarks::Search::Params::Query::Object& object = |
| 538 *params->query.as_object; | 535 *params->query.as_object; |
| 539 ::bookmarks::QueryFields query; | 536 ::bookmarks::QueryFields query; |
| 540 if (object.query) { | 537 if (object.query) { |
| 541 query.word_phrase_query.reset( | 538 query.word_phrase_query.reset( |
| 542 new base::string16(base::UTF8ToUTF16(*object.query))); | 539 new base::string16(base::UTF8ToUTF16(*object.query))); |
| 543 } | 540 } |
| 544 if (object.url) | 541 if (object.url) |
| 545 query.url.reset(new base::string16(base::UTF8ToUTF16(*object.url))); | 542 query.url.reset(new base::string16(base::UTF8ToUTF16(*object.url))); |
| 546 if (object.title) | 543 if (object.title) |
| 547 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); | 544 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); |
| 548 ::bookmarks::GetBookmarksMatchingProperties( | 545 ::bookmarks::GetBookmarksMatchingProperties( |
| 549 BookmarkModelFactory::GetForProfile(GetProfile()), | 546 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 550 query, | 547 query, |
| 551 std::numeric_limits<int>::max(), | 548 std::numeric_limits<int>::max(), |
| 552 lang, | |
| 553 &nodes); | 549 &nodes); |
| 554 } | 550 } |
| 555 | 551 |
| 556 std::vector<BookmarkTreeNode> tree_nodes; | 552 std::vector<BookmarkTreeNode> tree_nodes; |
| 557 ManagedBookmarkService* managed = GetManagedBookmarkService(); | 553 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 558 for (const BookmarkNode* node : nodes) | 554 for (const BookmarkNode* node : nodes) |
| 559 bookmark_api_helpers::AddNode(managed, node, &tree_nodes, false); | 555 bookmark_api_helpers::AddNode(managed, node, &tree_nodes, false); |
| 560 | 556 |
| 561 results_ = bookmarks::Search::Results::Create(tree_nodes); | 557 results_ = bookmarks::Search::Results::Create(tree_nodes); |
| 562 return true; | 558 return true; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 837 } |
| 842 | 838 |
| 843 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 839 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
| 844 int index, | 840 int index, |
| 845 void* params) { | 841 void* params) { |
| 846 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 842 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 847 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 843 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 848 } | 844 } |
| 849 | 845 |
| 850 } // namespace extensions | 846 } // namespace extensions |
| OLD | NEW |