| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
| 10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/sha1.h" | 15 #include "base/sha1.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_html_writer.h" | 22 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 24 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 24 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 25 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
| 26 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" | 25 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" |
| 27 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" | 26 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
| 28 #include "chrome/browser/importer/external_process_importer_host.h" | 27 #include "chrome/browser/importer/external_process_importer_host.h" |
| 29 #include "chrome/browser/importer/importer_uma.h" | 28 #include "chrome/browser/importer/importer_uma.h" |
| 30 #include "chrome/browser/platform_util.h" | 29 #include "chrome/browser/platform_util.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/chrome_select_file_policy.h" | 31 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 33 #include "chrome/browser/ui/host_desktop.h" | 32 #include "chrome/browser/ui/host_desktop.h" |
| 34 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 35 #include "chrome/common/extensions/api/bookmarks.h" | 34 #include "chrome/common/extensions/api/bookmarks.h" |
| 36 #include "chrome/common/importer/importer_data_types.h" | 35 #include "chrome/common/importer/importer_data_types.h" |
| 37 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/grit/generated_resources.h" | 37 #include "chrome/grit/generated_resources.h" |
| 39 #include "components/bookmarks/browser/bookmark_model.h" | 38 #include "components/bookmarks/browser/bookmark_model.h" |
| 40 #include "components/bookmarks/browser/bookmark_utils.h" | 39 #include "components/bookmarks/browser/bookmark_utils.h" |
| 40 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 41 #include "components/user_prefs/user_prefs.h" | 41 #include "components/user_prefs/user_prefs.h" |
| 42 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
| 43 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 45 #include "extensions/browser/event_router.h" | 45 #include "extensions/browser/event_router.h" |
| 46 #include "extensions/browser/extension_function_dispatcher.h" | 46 #include "extensions/browser/extension_function_dispatcher.h" |
| 47 #include "extensions/browser/notification_types.h" | 47 #include "extensions/browser/notification_types.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
| 49 | 49 |
| 50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 51 #include "ui/aura/remote_window_tree_host_win.h" | 51 #include "ui/aura/remote_window_tree_host_win.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 using bookmarks::BookmarkModel; | 54 using bookmarks::BookmarkModel; |
| 55 using bookmarks::BookmarkNode; | 55 using bookmarks::BookmarkNode; |
| 56 using bookmarks::ManagedBookmarkService; |
| 56 | 57 |
| 57 namespace extensions { | 58 namespace extensions { |
| 58 | 59 |
| 59 namespace keys = bookmark_api_constants; | 60 namespace keys = bookmark_api_constants; |
| 60 namespace bookmarks = api::bookmarks; | 61 namespace bookmarks = api::bookmarks; |
| 61 | 62 |
| 62 using bookmarks::BookmarkTreeNode; | 63 using bookmarks::BookmarkTreeNode; |
| 63 using bookmarks::CreateDetails; | 64 using bookmarks::CreateDetails; |
| 64 using content::BrowserContext; | 65 using content::BrowserContext; |
| 65 using content::BrowserThread; | 66 using content::BrowserThread; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 103 } |
| 103 | 104 |
| 104 RunAndSendResponse(); | 105 RunAndSendResponse(); |
| 105 return true; | 106 return true; |
| 106 } | 107 } |
| 107 | 108 |
| 108 BookmarkModel* BookmarksFunction::GetBookmarkModel() { | 109 BookmarkModel* BookmarksFunction::GetBookmarkModel() { |
| 109 return BookmarkModelFactory::GetForProfile(GetProfile()); | 110 return BookmarkModelFactory::GetForProfile(GetProfile()); |
| 110 } | 111 } |
| 111 | 112 |
| 112 ChromeBookmarkClient* BookmarksFunction::GetChromeBookmarkClient() { | 113 ManagedBookmarkService* BookmarksFunction::GetManagedBookmarkService() { |
| 113 return ChromeBookmarkClientFactory::GetForProfile(GetProfile()); | 114 return ManagedBookmarkServiceFactory::GetForProfile(GetProfile()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, | 117 bool BookmarksFunction::GetBookmarkIdAsInt64(const std::string& id_string, |
| 117 int64* id) { | 118 int64* id) { |
| 118 if (base::StringToInt64(id_string, id)) | 119 if (base::StringToInt64(id_string, id)) |
| 119 return true; | 120 return true; |
| 120 | 121 |
| 121 error_ = keys::kInvalidIdError; | 122 error_ = keys::kInvalidIdError; |
| 122 return false; | 123 return false; |
| 123 } | 124 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 204 |
| 204 bool BookmarksFunction::CanBeModified(const BookmarkNode* node) { | 205 bool BookmarksFunction::CanBeModified(const BookmarkNode* node) { |
| 205 if (!node) { | 206 if (!node) { |
| 206 error_ = keys::kNoParentError; | 207 error_ = keys::kNoParentError; |
| 207 return false; | 208 return false; |
| 208 } | 209 } |
| 209 if (node->is_root()) { | 210 if (node->is_root()) { |
| 210 error_ = keys::kModifySpecialError; | 211 error_ = keys::kModifySpecialError; |
| 211 return false; | 212 return false; |
| 212 } | 213 } |
| 213 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 214 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 214 if (::bookmarks::IsDescendantOf(node, client->managed_node()) || | 215 if (::bookmarks::IsDescendantOf(node, managed->managed_node()) || |
| 215 ::bookmarks::IsDescendantOf(node, client->supervised_node())) { | 216 ::bookmarks::IsDescendantOf(node, managed->supervised_node())) { |
| 216 error_ = keys::kModifyManagedError; | 217 error_ = keys::kModifyManagedError; |
| 217 return false; | 218 return false; |
| 218 } | 219 } |
| 219 return true; | 220 return true; |
| 220 } | 221 } |
| 221 | 222 |
| 222 void BookmarksFunction::BookmarkModelChanged() { | 223 void BookmarksFunction::BookmarkModelChanged() { |
| 223 } | 224 } |
| 224 | 225 |
| 225 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, | 226 void BookmarksFunction::BookmarkModelLoaded(BookmarkModel* model, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 237 extensions::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
| 237 content::Source<const Extension>(extension()), | 238 content::Source<const Extension>(extension()), |
| 238 content::Details<const BookmarksFunction>(this)); | 239 content::Details<const BookmarksFunction>(this)); |
| 239 } | 240 } |
| 240 SendResponse(success); | 241 SendResponse(success); |
| 241 } | 242 } |
| 242 | 243 |
| 243 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) | 244 BookmarkEventRouter::BookmarkEventRouter(Profile* profile) |
| 244 : browser_context_(profile), | 245 : browser_context_(profile), |
| 245 model_(BookmarkModelFactory::GetForProfile(profile)), | 246 model_(BookmarkModelFactory::GetForProfile(profile)), |
| 246 client_(ChromeBookmarkClientFactory::GetForProfile(profile)) { | 247 managed_(ManagedBookmarkServiceFactory::GetForProfile(profile)) { |
| 247 model_->AddObserver(this); | 248 model_->AddObserver(this); |
| 248 } | 249 } |
| 249 | 250 |
| 250 BookmarkEventRouter::~BookmarkEventRouter() { | 251 BookmarkEventRouter::~BookmarkEventRouter() { |
| 251 if (model_) { | 252 if (model_) { |
| 252 model_->RemoveObserver(this); | 253 model_->RemoveObserver(this); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 | 256 |
| 256 void BookmarkEventRouter::DispatchEvent( | 257 void BookmarkEventRouter::DispatchEvent( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 DispatchEvent( | 290 DispatchEvent( |
| 290 events::BOOKMARKS_ON_MOVED, bookmarks::OnMoved::kEventName, | 291 events::BOOKMARKS_ON_MOVED, bookmarks::OnMoved::kEventName, |
| 291 bookmarks::OnMoved::Create(base::Int64ToString(node->id()), move_info)); | 292 bookmarks::OnMoved::Create(base::Int64ToString(node->id()), move_info)); |
| 292 } | 293 } |
| 293 | 294 |
| 294 void BookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, | 295 void BookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, |
| 295 const BookmarkNode* parent, | 296 const BookmarkNode* parent, |
| 296 int index) { | 297 int index) { |
| 297 const BookmarkNode* node = parent->GetChild(index); | 298 const BookmarkNode* node = parent->GetChild(index); |
| 298 scoped_ptr<BookmarkTreeNode> tree_node( | 299 scoped_ptr<BookmarkTreeNode> tree_node( |
| 299 bookmark_api_helpers::GetBookmarkTreeNode(client_, node, false, false)); | 300 bookmark_api_helpers::GetBookmarkTreeNode(managed_, node, false, false)); |
| 300 DispatchEvent(events::BOOKMARKS_ON_CREATED, bookmarks::OnCreated::kEventName, | 301 DispatchEvent(events::BOOKMARKS_ON_CREATED, bookmarks::OnCreated::kEventName, |
| 301 bookmarks::OnCreated::Create(base::Int64ToString(node->id()), | 302 bookmarks::OnCreated::Create(base::Int64ToString(node->id()), |
| 302 *tree_node)); | 303 *tree_node)); |
| 303 } | 304 } |
| 304 | 305 |
| 305 void BookmarkEventRouter::BookmarkNodeRemoved( | 306 void BookmarkEventRouter::BookmarkNodeRemoved( |
| 306 BookmarkModel* model, | 307 BookmarkModel* model, |
| 307 const BookmarkNode* parent, | 308 const BookmarkNode* parent, |
| 308 int index, | 309 int index, |
| 309 const BookmarkNode* node, | 310 const BookmarkNode* node, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 new BookmarkEventRouter(Profile::FromBrowserContext(browser_context_))); | 412 new BookmarkEventRouter(Profile::FromBrowserContext(browser_context_))); |
| 412 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 413 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 413 } | 414 } |
| 414 | 415 |
| 415 bool BookmarksGetFunction::RunOnReady() { | 416 bool BookmarksGetFunction::RunOnReady() { |
| 416 scoped_ptr<bookmarks::Get::Params> params( | 417 scoped_ptr<bookmarks::Get::Params> params( |
| 417 bookmarks::Get::Params::Create(*args_)); | 418 bookmarks::Get::Params::Create(*args_)); |
| 418 EXTENSION_FUNCTION_VALIDATE(params.get()); | 419 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 419 | 420 |
| 420 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 421 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 421 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 422 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 422 if (params->id_or_id_list.as_strings) { | 423 if (params->id_or_id_list.as_strings) { |
| 423 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; | 424 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; |
| 424 size_t count = ids.size(); | 425 size_t count = ids.size(); |
| 425 EXTENSION_FUNCTION_VALIDATE(count > 0); | 426 EXTENSION_FUNCTION_VALIDATE(count > 0); |
| 426 for (size_t i = 0; i < count; ++i) { | 427 for (size_t i = 0; i < count; ++i) { |
| 427 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); | 428 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); |
| 428 if (!node) | 429 if (!node) |
| 429 return false; | 430 return false; |
| 430 bookmark_api_helpers::AddNode(client, node, &nodes, false); | 431 bookmark_api_helpers::AddNode(managed, node, &nodes, false); |
| 431 } | 432 } |
| 432 } else { | 433 } else { |
| 433 const BookmarkNode* node = | 434 const BookmarkNode* node = |
| 434 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); | 435 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); |
| 435 if (!node) | 436 if (!node) |
| 436 return false; | 437 return false; |
| 437 bookmark_api_helpers::AddNode(client, node, &nodes, false); | 438 bookmark_api_helpers::AddNode(managed, node, &nodes, false); |
| 438 } | 439 } |
| 439 | 440 |
| 440 results_ = bookmarks::Get::Results::Create(nodes); | 441 results_ = bookmarks::Get::Results::Create(nodes); |
| 441 return true; | 442 return true; |
| 442 } | 443 } |
| 443 | 444 |
| 444 bool BookmarksGetChildrenFunction::RunOnReady() { | 445 bool BookmarksGetChildrenFunction::RunOnReady() { |
| 445 scoped_ptr<bookmarks::GetChildren::Params> params( | 446 scoped_ptr<bookmarks::GetChildren::Params> params( |
| 446 bookmarks::GetChildren::Params::Create(*args_)); | 447 bookmarks::GetChildren::Params::Create(*args_)); |
| 447 EXTENSION_FUNCTION_VALIDATE(params.get()); | 448 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 448 | 449 |
| 449 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 450 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
| 450 if (!node) | 451 if (!node) |
| 451 return false; | 452 return false; |
| 452 | 453 |
| 453 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 454 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 454 int child_count = node->child_count(); | 455 int child_count = node->child_count(); |
| 455 for (int i = 0; i < child_count; ++i) { | 456 for (int i = 0; i < child_count; ++i) { |
| 456 const BookmarkNode* child = node->GetChild(i); | 457 const BookmarkNode* child = node->GetChild(i); |
| 457 bookmark_api_helpers::AddNode( | 458 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), child, &nodes, |
| 458 GetChromeBookmarkClient(), child, &nodes, false); | 459 false); |
| 459 } | 460 } |
| 460 | 461 |
| 461 results_ = bookmarks::GetChildren::Results::Create(nodes); | 462 results_ = bookmarks::GetChildren::Results::Create(nodes); |
| 462 return true; | 463 return true; |
| 463 } | 464 } |
| 464 | 465 |
| 465 bool BookmarksGetRecentFunction::RunOnReady() { | 466 bool BookmarksGetRecentFunction::RunOnReady() { |
| 466 scoped_ptr<bookmarks::GetRecent::Params> params( | 467 scoped_ptr<bookmarks::GetRecent::Params> params( |
| 467 bookmarks::GetRecent::Params::Create(*args_)); | 468 bookmarks::GetRecent::Params::Create(*args_)); |
| 468 EXTENSION_FUNCTION_VALIDATE(params.get()); | 469 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 469 if (params->number_of_items < 1) | 470 if (params->number_of_items < 1) |
| 470 return false; | 471 return false; |
| 471 | 472 |
| 472 std::vector<const BookmarkNode*> nodes; | 473 std::vector<const BookmarkNode*> nodes; |
| 473 ::bookmarks::GetMostRecentlyAddedEntries( | 474 ::bookmarks::GetMostRecentlyAddedEntries( |
| 474 BookmarkModelFactory::GetForProfile(GetProfile()), | 475 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 475 params->number_of_items, | 476 params->number_of_items, |
| 476 &nodes); | 477 &nodes); |
| 477 | 478 |
| 478 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 479 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 479 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); | 480 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); |
| 480 for (; i != nodes.end(); ++i) { | 481 for (; i != nodes.end(); ++i) { |
| 481 const BookmarkNode* node = *i; | 482 const BookmarkNode* node = *i; |
| 482 bookmark_api_helpers::AddNode( | 483 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, |
| 483 GetChromeBookmarkClient(), node, &tree_nodes, false); | 484 &tree_nodes, false); |
| 484 } | 485 } |
| 485 | 486 |
| 486 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); | 487 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); |
| 487 return true; | 488 return true; |
| 488 } | 489 } |
| 489 | 490 |
| 490 bool BookmarksGetTreeFunction::RunOnReady() { | 491 bool BookmarksGetTreeFunction::RunOnReady() { |
| 491 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 492 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 492 const BookmarkNode* node = | 493 const BookmarkNode* node = |
| 493 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); | 494 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); |
| 494 bookmark_api_helpers::AddNode(GetChromeBookmarkClient(), node, &nodes, true); | 495 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, &nodes, |
| 496 true); |
| 495 results_ = bookmarks::GetTree::Results::Create(nodes); | 497 results_ = bookmarks::GetTree::Results::Create(nodes); |
| 496 return true; | 498 return true; |
| 497 } | 499 } |
| 498 | 500 |
| 499 bool BookmarksGetSubTreeFunction::RunOnReady() { | 501 bool BookmarksGetSubTreeFunction::RunOnReady() { |
| 500 scoped_ptr<bookmarks::GetSubTree::Params> params( | 502 scoped_ptr<bookmarks::GetSubTree::Params> params( |
| 501 bookmarks::GetSubTree::Params::Create(*args_)); | 503 bookmarks::GetSubTree::Params::Create(*args_)); |
| 502 EXTENSION_FUNCTION_VALIDATE(params.get()); | 504 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 503 | 505 |
| 504 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 506 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
| 505 if (!node) | 507 if (!node) |
| 506 return false; | 508 return false; |
| 507 | 509 |
| 508 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 510 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 509 bookmark_api_helpers::AddNode(GetChromeBookmarkClient(), node, &nodes, true); | 511 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, &nodes, |
| 512 true); |
| 510 results_ = bookmarks::GetSubTree::Results::Create(nodes); | 513 results_ = bookmarks::GetSubTree::Results::Create(nodes); |
| 511 return true; | 514 return true; |
| 512 } | 515 } |
| 513 | 516 |
| 514 bool BookmarksSearchFunction::RunOnReady() { | 517 bool BookmarksSearchFunction::RunOnReady() { |
| 515 scoped_ptr<bookmarks::Search::Params> params( | 518 scoped_ptr<bookmarks::Search::Params> params( |
| 516 bookmarks::Search::Params::Create(*args_)); | 519 bookmarks::Search::Params::Create(*args_)); |
| 517 EXTENSION_FUNCTION_VALIDATE(params.get()); | 520 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 518 | 521 |
| 519 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); | 522 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 544 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); | 547 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); |
| 545 ::bookmarks::GetBookmarksMatchingProperties( | 548 ::bookmarks::GetBookmarksMatchingProperties( |
| 546 BookmarkModelFactory::GetForProfile(GetProfile()), | 549 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 547 query, | 550 query, |
| 548 std::numeric_limits<int>::max(), | 551 std::numeric_limits<int>::max(), |
| 549 lang, | 552 lang, |
| 550 &nodes); | 553 &nodes); |
| 551 } | 554 } |
| 552 | 555 |
| 553 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 556 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 554 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 557 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 555 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); | 558 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); |
| 556 node_iter != nodes.end(); ++node_iter) { | 559 node_iter != nodes.end(); ++node_iter) { |
| 557 bookmark_api_helpers::AddNode(client, *node_iter, &tree_nodes, false); | 560 bookmark_api_helpers::AddNode(managed, *node_iter, &tree_nodes, false); |
| 558 } | 561 } |
| 559 | 562 |
| 560 results_ = bookmarks::Search::Results::Create(tree_nodes); | 563 results_ = bookmarks::Search::Results::Create(tree_nodes); |
| 561 return true; | 564 return true; |
| 562 } | 565 } |
| 563 | 566 |
| 564 // static | 567 // static |
| 565 bool BookmarksRemoveFunction::ExtractIds(const base::ListValue* args, | 568 bool BookmarksRemoveFunction::ExtractIds(const base::ListValue* args, |
| 566 std::list<int64>* ids, | 569 std::list<int64>* ids, |
| 567 bool* invalid_id) { | 570 bool* invalid_id) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 586 | 589 |
| 587 int64 id; | 590 int64 id; |
| 588 if (!GetBookmarkIdAsInt64(params->id, &id)) | 591 if (!GetBookmarkIdAsInt64(params->id, &id)) |
| 589 return false; | 592 return false; |
| 590 | 593 |
| 591 bool recursive = false; | 594 bool recursive = false; |
| 592 if (name() == BookmarksRemoveTreeFunction::function_name()) | 595 if (name() == BookmarksRemoveTreeFunction::function_name()) |
| 593 recursive = true; | 596 recursive = true; |
| 594 | 597 |
| 595 BookmarkModel* model = GetBookmarkModel(); | 598 BookmarkModel* model = GetBookmarkModel(); |
| 596 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 599 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 597 if (!bookmark_api_helpers::RemoveNode(model, client, id, recursive, &error_)) | 600 if (!bookmark_api_helpers::RemoveNode(model, managed, id, recursive, &error_)) |
| 598 return false; | 601 return false; |
| 599 | 602 |
| 600 return true; | 603 return true; |
| 601 } | 604 } |
| 602 | 605 |
| 603 bool BookmarksCreateFunction::RunOnReady() { | 606 bool BookmarksCreateFunction::RunOnReady() { |
| 604 if (!EditBookmarksEnabled()) | 607 if (!EditBookmarksEnabled()) |
| 605 return false; | 608 return false; |
| 606 | 609 |
| 607 scoped_ptr<bookmarks::Create::Params> params( | 610 scoped_ptr<bookmarks::Create::Params> params( |
| 608 bookmarks::Create::Params::Create(*args_)); | 611 bookmarks::Create::Params::Create(*args_)); |
| 609 EXTENSION_FUNCTION_VALIDATE(params.get()); | 612 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 610 | 613 |
| 611 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 614 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
| 612 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); | 615 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); |
| 613 if (!node) | 616 if (!node) |
| 614 return false; | 617 return false; |
| 615 | 618 |
| 616 scoped_ptr<BookmarkTreeNode> ret(bookmark_api_helpers::GetBookmarkTreeNode( | 619 scoped_ptr<BookmarkTreeNode> ret(bookmark_api_helpers::GetBookmarkTreeNode( |
| 617 GetChromeBookmarkClient(), node, false, false)); | 620 GetManagedBookmarkService(), node, false, false)); |
| 618 results_ = bookmarks::Create::Results::Create(*ret); | 621 results_ = bookmarks::Create::Results::Create(*ret); |
| 619 | 622 |
| 620 return true; | 623 return true; |
| 621 } | 624 } |
| 622 | 625 |
| 623 // static | 626 // static |
| 624 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, | 627 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, |
| 625 std::list<int64>* ids, | 628 std::list<int64>* ids, |
| 626 bool* invalid_id) { | 629 bool* invalid_id) { |
| 627 // For now, Move accepts ID parameters in the same way as an Update. | 630 // For now, Move accepts ID parameters in the same way as an Update. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 error_ = keys::kInvalidIndexError; | 670 error_ = keys::kInvalidIndexError; |
| 668 return false; | 671 return false; |
| 669 } | 672 } |
| 670 } else { | 673 } else { |
| 671 index = parent->child_count(); | 674 index = parent->child_count(); |
| 672 } | 675 } |
| 673 | 676 |
| 674 model->Move(node, parent, index); | 677 model->Move(node, parent, index); |
| 675 | 678 |
| 676 scoped_ptr<BookmarkTreeNode> tree_node( | 679 scoped_ptr<BookmarkTreeNode> tree_node( |
| 677 bookmark_api_helpers::GetBookmarkTreeNode( | 680 bookmark_api_helpers::GetBookmarkTreeNode(GetManagedBookmarkService(), |
| 678 GetChromeBookmarkClient(), node, false, false)); | 681 node, false, false)); |
| 679 results_ = bookmarks::Move::Results::Create(*tree_node); | 682 results_ = bookmarks::Move::Results::Create(*tree_node); |
| 680 | 683 |
| 681 return true; | 684 return true; |
| 682 } | 685 } |
| 683 | 686 |
| 684 // static | 687 // static |
| 685 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, | 688 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, |
| 686 std::list<int64>* ids, | 689 std::list<int64>* ids, |
| 687 bool* invalid_id) { | 690 bool* invalid_id) { |
| 688 // For now, Update accepts ID parameters in the same way as an Remove. | 691 // For now, Update accepts ID parameters in the same way as an Remove. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 if (model->is_permanent_node(node)) { | 726 if (model->is_permanent_node(node)) { |
| 724 error_ = keys::kModifySpecialError; | 727 error_ = keys::kModifySpecialError; |
| 725 return false; | 728 return false; |
| 726 } | 729 } |
| 727 if (has_title) | 730 if (has_title) |
| 728 model->SetTitle(node, title); | 731 model->SetTitle(node, title); |
| 729 if (!url.is_empty()) | 732 if (!url.is_empty()) |
| 730 model->SetURL(node, url); | 733 model->SetURL(node, url); |
| 731 | 734 |
| 732 scoped_ptr<BookmarkTreeNode> tree_node( | 735 scoped_ptr<BookmarkTreeNode> tree_node( |
| 733 bookmark_api_helpers::GetBookmarkTreeNode( | 736 bookmark_api_helpers::GetBookmarkTreeNode(GetManagedBookmarkService(), |
| 734 GetChromeBookmarkClient(), node, false, false)); | 737 node, false, false)); |
| 735 results_ = bookmarks::Update::Results::Create(*tree_node); | 738 results_ = bookmarks::Update::Results::Create(*tree_node); |
| 736 return true; | 739 return true; |
| 737 } | 740 } |
| 738 | 741 |
| 739 BookmarksIOFunction::BookmarksIOFunction() {} | 742 BookmarksIOFunction::BookmarksIOFunction() {} |
| 740 | 743 |
| 741 BookmarksIOFunction::~BookmarksIOFunction() { | 744 BookmarksIOFunction::~BookmarksIOFunction() { |
| 742 // There may be pending file dialogs, we need to tell them that we've gone | 745 // There may be pending file dialogs, we need to tell them that we've gone |
| 743 // away so they don't try and call back to us. | 746 // away so they don't try and call back to us. |
| 744 if (select_file_dialog_.get()) | 747 if (select_file_dialog_.get()) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 } | 850 } |
| 848 | 851 |
| 849 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 852 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
| 850 int index, | 853 int index, |
| 851 void* params) { | 854 void* params) { |
| 852 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 855 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 853 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 856 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 854 } | 857 } |
| 855 | 858 |
| 856 } // namespace extensions | 859 } // namespace extensions |
| OLD | NEW |