| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_bookmarks_module.h" | 5 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| 6 | 6 |
| 7 #include "base/json_writer.h" | 7 #include "base/json_writer.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_codec.h" | 8 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" | 12 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" |
| 13 #include "chrome/browser/extensions/extension_message_service.h" | 13 #include "chrome/browser/extensions/extension_message_service.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/pref_service.h" |
| 15 | 17 |
| 16 namespace keys = extension_bookmarks_module_constants; | 18 namespace keys = extension_bookmarks_module_constants; |
| 17 | 19 |
| 18 // Helper functions. | 20 // Helper functions. |
| 19 class ExtensionBookmarks { | 21 class ExtensionBookmarks { |
| 20 public: | 22 public: |
| 21 // Convert |node| into a JSON value | 23 // Convert |node| into a JSON value |
| 22 static DictionaryValue* GetNodeDictionary(BookmarkNode* node, bool recurse) { | 24 static DictionaryValue* GetNodeDictionary(BookmarkNode* node, bool recurse) { |
| 23 DictionaryValue* dict = new DictionaryValue(); | 25 DictionaryValue* dict = new DictionaryValue(); |
| 24 dict->SetInteger(keys::kIdKey, node->id()); | 26 dict->SetInteger(keys::kIdKey, node->id()); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 279 } |
| 278 | 280 |
| 279 bool SearchBookmarksFunction::RunImpl() { | 281 bool SearchBookmarksFunction::RunImpl() { |
| 280 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_STRING)); | 282 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_STRING)); |
| 281 | 283 |
| 282 std::wstring query; | 284 std::wstring query; |
| 283 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&query)); | 285 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&query)); |
| 284 | 286 |
| 285 BookmarkModel* model = profile()->GetBookmarkModel(); | 287 BookmarkModel* model = profile()->GetBookmarkModel(); |
| 286 ListValue* json = new ListValue(); | 288 ListValue* json = new ListValue(); |
| 289 std::wstring lang = profile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 287 std::vector<BookmarkNode*> nodes; | 290 std::vector<BookmarkNode*> nodes; |
| 288 bookmark_utils::GetBookmarksContainingText(model, query, 50, &nodes); | 291 bookmark_utils::GetBookmarksContainingText(model, query, 50, lang, &nodes); |
| 289 std::vector<BookmarkNode*>::iterator i = nodes.begin(); | 292 std::vector<BookmarkNode*>::iterator i = nodes.begin(); |
| 290 for (; i != nodes.end(); ++i) { | 293 for (; i != nodes.end(); ++i) { |
| 291 BookmarkNode* node = *i; | 294 BookmarkNode* node = *i; |
| 292 ExtensionBookmarks::AddNode(node, json, false); | 295 ExtensionBookmarks::AddNode(node, json, false); |
| 293 } | 296 } |
| 294 | 297 |
| 295 result_.reset(json); | 298 result_.reset(json); |
| 296 return true; | 299 return true; |
| 297 } | 300 } |
| 298 | 301 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 471 } |
| 469 if (node == model->root_node() || | 472 if (node == model->root_node() || |
| 470 node == model->other_node() || | 473 node == model->other_node() || |
| 471 node == model->GetBookmarkBarNode()) { | 474 node == model->GetBookmarkBarNode()) { |
| 472 error_ = keys::kModifySpecialError; | 475 error_ = keys::kModifySpecialError; |
| 473 return false; | 476 return false; |
| 474 } | 477 } |
| 475 model->SetTitle(node, title); | 478 model->SetTitle(node, title); |
| 476 return true; | 479 return true; |
| 477 } | 480 } |
| OLD | NEW |