| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 DispatchEvent( | 289 DispatchEvent( |
| 289 bookmarks::OnMoved::kEventName, | 290 bookmarks::OnMoved::kEventName, |
| 290 bookmarks::OnMoved::Create(base::Int64ToString(node->id()), move_info)); | 291 bookmarks::OnMoved::Create(base::Int64ToString(node->id()), move_info)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 void BookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, | 294 void BookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, |
| 294 const BookmarkNode* parent, | 295 const BookmarkNode* parent, |
| 295 int index) { | 296 int index) { |
| 296 const BookmarkNode* node = parent->GetChild(index); | 297 const BookmarkNode* node = parent->GetChild(index); |
| 297 scoped_ptr<BookmarkTreeNode> tree_node( | 298 scoped_ptr<BookmarkTreeNode> tree_node( |
| 298 bookmark_api_helpers::GetBookmarkTreeNode(client_, node, false, false)); | 299 bookmark_api_helpers::GetBookmarkTreeNode(managed_, node, false, false)); |
| 299 DispatchEvent(bookmarks::OnCreated::kEventName, | 300 DispatchEvent(bookmarks::OnCreated::kEventName, |
| 300 bookmarks::OnCreated::Create(base::Int64ToString(node->id()), | 301 bookmarks::OnCreated::Create(base::Int64ToString(node->id()), |
| 301 *tree_node)); | 302 *tree_node)); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void BookmarkEventRouter::BookmarkNodeRemoved( | 305 void BookmarkEventRouter::BookmarkNodeRemoved( |
| 305 BookmarkModel* model, | 306 BookmarkModel* model, |
| 306 const BookmarkNode* parent, | 307 const BookmarkNode* parent, |
| 307 int index, | 308 int index, |
| 308 const BookmarkNode* node, | 309 const BookmarkNode* node, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 new BookmarkEventRouter(Profile::FromBrowserContext(browser_context_))); | 408 new BookmarkEventRouter(Profile::FromBrowserContext(browser_context_))); |
| 408 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 409 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
| 409 } | 410 } |
| 410 | 411 |
| 411 bool BookmarksGetFunction::RunOnReady() { | 412 bool BookmarksGetFunction::RunOnReady() { |
| 412 scoped_ptr<bookmarks::Get::Params> params( | 413 scoped_ptr<bookmarks::Get::Params> params( |
| 413 bookmarks::Get::Params::Create(*args_)); | 414 bookmarks::Get::Params::Create(*args_)); |
| 414 EXTENSION_FUNCTION_VALIDATE(params.get()); | 415 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 415 | 416 |
| 416 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 417 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 417 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 418 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 418 if (params->id_or_id_list.as_strings) { | 419 if (params->id_or_id_list.as_strings) { |
| 419 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; | 420 std::vector<std::string>& ids = *params->id_or_id_list.as_strings; |
| 420 size_t count = ids.size(); | 421 size_t count = ids.size(); |
| 421 EXTENSION_FUNCTION_VALIDATE(count > 0); | 422 EXTENSION_FUNCTION_VALIDATE(count > 0); |
| 422 for (size_t i = 0; i < count; ++i) { | 423 for (size_t i = 0; i < count; ++i) { |
| 423 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); | 424 const BookmarkNode* node = GetBookmarkNodeFromId(ids[i]); |
| 424 if (!node) | 425 if (!node) |
| 425 return false; | 426 return false; |
| 426 bookmark_api_helpers::AddNode(client, node, &nodes, false); | 427 bookmark_api_helpers::AddNode(managed, node, &nodes, false); |
| 427 } | 428 } |
| 428 } else { | 429 } else { |
| 429 const BookmarkNode* node = | 430 const BookmarkNode* node = |
| 430 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); | 431 GetBookmarkNodeFromId(*params->id_or_id_list.as_string); |
| 431 if (!node) | 432 if (!node) |
| 432 return false; | 433 return false; |
| 433 bookmark_api_helpers::AddNode(client, node, &nodes, false); | 434 bookmark_api_helpers::AddNode(managed, node, &nodes, false); |
| 434 } | 435 } |
| 435 | 436 |
| 436 results_ = bookmarks::Get::Results::Create(nodes); | 437 results_ = bookmarks::Get::Results::Create(nodes); |
| 437 return true; | 438 return true; |
| 438 } | 439 } |
| 439 | 440 |
| 440 bool BookmarksGetChildrenFunction::RunOnReady() { | 441 bool BookmarksGetChildrenFunction::RunOnReady() { |
| 441 scoped_ptr<bookmarks::GetChildren::Params> params( | 442 scoped_ptr<bookmarks::GetChildren::Params> params( |
| 442 bookmarks::GetChildren::Params::Create(*args_)); | 443 bookmarks::GetChildren::Params::Create(*args_)); |
| 443 EXTENSION_FUNCTION_VALIDATE(params.get()); | 444 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 444 | 445 |
| 445 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 446 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
| 446 if (!node) | 447 if (!node) |
| 447 return false; | 448 return false; |
| 448 | 449 |
| 449 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 450 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 450 int child_count = node->child_count(); | 451 int child_count = node->child_count(); |
| 451 for (int i = 0; i < child_count; ++i) { | 452 for (int i = 0; i < child_count; ++i) { |
| 452 const BookmarkNode* child = node->GetChild(i); | 453 const BookmarkNode* child = node->GetChild(i); |
| 453 bookmark_api_helpers::AddNode( | 454 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), child, &nodes, |
| 454 GetChromeBookmarkClient(), child, &nodes, false); | 455 false); |
| 455 } | 456 } |
| 456 | 457 |
| 457 results_ = bookmarks::GetChildren::Results::Create(nodes); | 458 results_ = bookmarks::GetChildren::Results::Create(nodes); |
| 458 return true; | 459 return true; |
| 459 } | 460 } |
| 460 | 461 |
| 461 bool BookmarksGetRecentFunction::RunOnReady() { | 462 bool BookmarksGetRecentFunction::RunOnReady() { |
| 462 scoped_ptr<bookmarks::GetRecent::Params> params( | 463 scoped_ptr<bookmarks::GetRecent::Params> params( |
| 463 bookmarks::GetRecent::Params::Create(*args_)); | 464 bookmarks::GetRecent::Params::Create(*args_)); |
| 464 EXTENSION_FUNCTION_VALIDATE(params.get()); | 465 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 465 if (params->number_of_items < 1) | 466 if (params->number_of_items < 1) |
| 466 return false; | 467 return false; |
| 467 | 468 |
| 468 std::vector<const BookmarkNode*> nodes; | 469 std::vector<const BookmarkNode*> nodes; |
| 469 ::bookmarks::GetMostRecentlyAddedEntries( | 470 ::bookmarks::GetMostRecentlyAddedEntries( |
| 470 BookmarkModelFactory::GetForProfile(GetProfile()), | 471 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 471 params->number_of_items, | 472 params->number_of_items, |
| 472 &nodes); | 473 &nodes); |
| 473 | 474 |
| 474 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 475 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 475 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); | 476 std::vector<const BookmarkNode*>::iterator i = nodes.begin(); |
| 476 for (; i != nodes.end(); ++i) { | 477 for (; i != nodes.end(); ++i) { |
| 477 const BookmarkNode* node = *i; | 478 const BookmarkNode* node = *i; |
| 478 bookmark_api_helpers::AddNode( | 479 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, |
| 479 GetChromeBookmarkClient(), node, &tree_nodes, false); | 480 &tree_nodes, false); |
| 480 } | 481 } |
| 481 | 482 |
| 482 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); | 483 results_ = bookmarks::GetRecent::Results::Create(tree_nodes); |
| 483 return true; | 484 return true; |
| 484 } | 485 } |
| 485 | 486 |
| 486 bool BookmarksGetTreeFunction::RunOnReady() { | 487 bool BookmarksGetTreeFunction::RunOnReady() { |
| 487 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 488 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 488 const BookmarkNode* node = | 489 const BookmarkNode* node = |
| 489 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); | 490 BookmarkModelFactory::GetForProfile(GetProfile())->root_node(); |
| 490 bookmark_api_helpers::AddNode(GetChromeBookmarkClient(), node, &nodes, true); | 491 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, &nodes, |
| 492 true); |
| 491 results_ = bookmarks::GetTree::Results::Create(nodes); | 493 results_ = bookmarks::GetTree::Results::Create(nodes); |
| 492 return true; | 494 return true; |
| 493 } | 495 } |
| 494 | 496 |
| 495 bool BookmarksGetSubTreeFunction::RunOnReady() { | 497 bool BookmarksGetSubTreeFunction::RunOnReady() { |
| 496 scoped_ptr<bookmarks::GetSubTree::Params> params( | 498 scoped_ptr<bookmarks::GetSubTree::Params> params( |
| 497 bookmarks::GetSubTree::Params::Create(*args_)); | 499 bookmarks::GetSubTree::Params::Create(*args_)); |
| 498 EXTENSION_FUNCTION_VALIDATE(params.get()); | 500 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 499 | 501 |
| 500 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); | 502 const BookmarkNode* node = GetBookmarkNodeFromId(params->id); |
| 501 if (!node) | 503 if (!node) |
| 502 return false; | 504 return false; |
| 503 | 505 |
| 504 std::vector<linked_ptr<BookmarkTreeNode> > nodes; | 506 std::vector<linked_ptr<BookmarkTreeNode> > nodes; |
| 505 bookmark_api_helpers::AddNode(GetChromeBookmarkClient(), node, &nodes, true); | 507 bookmark_api_helpers::AddNode(GetManagedBookmarkService(), node, &nodes, |
| 508 true); |
| 506 results_ = bookmarks::GetSubTree::Results::Create(nodes); | 509 results_ = bookmarks::GetSubTree::Results::Create(nodes); |
| 507 return true; | 510 return true; |
| 508 } | 511 } |
| 509 | 512 |
| 510 bool BookmarksSearchFunction::RunOnReady() { | 513 bool BookmarksSearchFunction::RunOnReady() { |
| 511 scoped_ptr<bookmarks::Search::Params> params( | 514 scoped_ptr<bookmarks::Search::Params> params( |
| 512 bookmarks::Search::Params::Create(*args_)); | 515 bookmarks::Search::Params::Create(*args_)); |
| 513 EXTENSION_FUNCTION_VALIDATE(params.get()); | 516 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 514 | 517 |
| 515 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); | 518 PrefService* prefs = user_prefs::UserPrefs::Get(GetProfile()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 540 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); | 543 query.title.reset(new base::string16(base::UTF8ToUTF16(*object.title))); |
| 541 ::bookmarks::GetBookmarksMatchingProperties( | 544 ::bookmarks::GetBookmarksMatchingProperties( |
| 542 BookmarkModelFactory::GetForProfile(GetProfile()), | 545 BookmarkModelFactory::GetForProfile(GetProfile()), |
| 543 query, | 546 query, |
| 544 std::numeric_limits<int>::max(), | 547 std::numeric_limits<int>::max(), |
| 545 lang, | 548 lang, |
| 546 &nodes); | 549 &nodes); |
| 547 } | 550 } |
| 548 | 551 |
| 549 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; | 552 std::vector<linked_ptr<BookmarkTreeNode> > tree_nodes; |
| 550 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 553 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 551 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); | 554 for (std::vector<const BookmarkNode*>::iterator node_iter = nodes.begin(); |
| 552 node_iter != nodes.end(); ++node_iter) { | 555 node_iter != nodes.end(); ++node_iter) { |
| 553 bookmark_api_helpers::AddNode(client, *node_iter, &tree_nodes, false); | 556 bookmark_api_helpers::AddNode(managed, *node_iter, &tree_nodes, false); |
| 554 } | 557 } |
| 555 | 558 |
| 556 results_ = bookmarks::Search::Results::Create(tree_nodes); | 559 results_ = bookmarks::Search::Results::Create(tree_nodes); |
| 557 return true; | 560 return true; |
| 558 } | 561 } |
| 559 | 562 |
| 560 // static | 563 // static |
| 561 bool BookmarksRemoveFunction::ExtractIds(const base::ListValue* args, | 564 bool BookmarksRemoveFunction::ExtractIds(const base::ListValue* args, |
| 562 std::list<int64>* ids, | 565 std::list<int64>* ids, |
| 563 bool* invalid_id) { | 566 bool* invalid_id) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 582 | 585 |
| 583 int64 id; | 586 int64 id; |
| 584 if (!GetBookmarkIdAsInt64(params->id, &id)) | 587 if (!GetBookmarkIdAsInt64(params->id, &id)) |
| 585 return false; | 588 return false; |
| 586 | 589 |
| 587 bool recursive = false; | 590 bool recursive = false; |
| 588 if (name() == BookmarksRemoveTreeFunction::function_name()) | 591 if (name() == BookmarksRemoveTreeFunction::function_name()) |
| 589 recursive = true; | 592 recursive = true; |
| 590 | 593 |
| 591 BookmarkModel* model = GetBookmarkModel(); | 594 BookmarkModel* model = GetBookmarkModel(); |
| 592 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 595 ManagedBookmarkService* managed = GetManagedBookmarkService(); |
| 593 if (!bookmark_api_helpers::RemoveNode(model, client, id, recursive, &error_)) | 596 if (!bookmark_api_helpers::RemoveNode(model, managed, id, recursive, &error_)) |
| 594 return false; | 597 return false; |
| 595 | 598 |
| 596 return true; | 599 return true; |
| 597 } | 600 } |
| 598 | 601 |
| 599 bool BookmarksCreateFunction::RunOnReady() { | 602 bool BookmarksCreateFunction::RunOnReady() { |
| 600 if (!EditBookmarksEnabled()) | 603 if (!EditBookmarksEnabled()) |
| 601 return false; | 604 return false; |
| 602 | 605 |
| 603 scoped_ptr<bookmarks::Create::Params> params( | 606 scoped_ptr<bookmarks::Create::Params> params( |
| 604 bookmarks::Create::Params::Create(*args_)); | 607 bookmarks::Create::Params::Create(*args_)); |
| 605 EXTENSION_FUNCTION_VALIDATE(params.get()); | 608 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 606 | 609 |
| 607 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 610 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
| 608 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); | 611 const BookmarkNode* node = CreateBookmarkNode(model, params->bookmark, NULL); |
| 609 if (!node) | 612 if (!node) |
| 610 return false; | 613 return false; |
| 611 | 614 |
| 612 scoped_ptr<BookmarkTreeNode> ret(bookmark_api_helpers::GetBookmarkTreeNode( | 615 scoped_ptr<BookmarkTreeNode> ret(bookmark_api_helpers::GetBookmarkTreeNode( |
| 613 GetChromeBookmarkClient(), node, false, false)); | 616 GetManagedBookmarkService(), node, false, false)); |
| 614 results_ = bookmarks::Create::Results::Create(*ret); | 617 results_ = bookmarks::Create::Results::Create(*ret); |
| 615 | 618 |
| 616 return true; | 619 return true; |
| 617 } | 620 } |
| 618 | 621 |
| 619 // static | 622 // static |
| 620 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, | 623 bool BookmarksMoveFunction::ExtractIds(const base::ListValue* args, |
| 621 std::list<int64>* ids, | 624 std::list<int64>* ids, |
| 622 bool* invalid_id) { | 625 bool* invalid_id) { |
| 623 // For now, Move accepts ID parameters in the same way as an Update. | 626 // 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... |
| 663 error_ = keys::kInvalidIndexError; | 666 error_ = keys::kInvalidIndexError; |
| 664 return false; | 667 return false; |
| 665 } | 668 } |
| 666 } else { | 669 } else { |
| 667 index = parent->child_count(); | 670 index = parent->child_count(); |
| 668 } | 671 } |
| 669 | 672 |
| 670 model->Move(node, parent, index); | 673 model->Move(node, parent, index); |
| 671 | 674 |
| 672 scoped_ptr<BookmarkTreeNode> tree_node( | 675 scoped_ptr<BookmarkTreeNode> tree_node( |
| 673 bookmark_api_helpers::GetBookmarkTreeNode( | 676 bookmark_api_helpers::GetBookmarkTreeNode(GetManagedBookmarkService(), |
| 674 GetChromeBookmarkClient(), node, false, false)); | 677 node, false, false)); |
| 675 results_ = bookmarks::Move::Results::Create(*tree_node); | 678 results_ = bookmarks::Move::Results::Create(*tree_node); |
| 676 | 679 |
| 677 return true; | 680 return true; |
| 678 } | 681 } |
| 679 | 682 |
| 680 // static | 683 // static |
| 681 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, | 684 bool BookmarksUpdateFunction::ExtractIds(const base::ListValue* args, |
| 682 std::list<int64>* ids, | 685 std::list<int64>* ids, |
| 683 bool* invalid_id) { | 686 bool* invalid_id) { |
| 684 // For now, Update accepts ID parameters in the same way as an Remove. | 687 // 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... |
| 719 if (model->is_permanent_node(node)) { | 722 if (model->is_permanent_node(node)) { |
| 720 error_ = keys::kModifySpecialError; | 723 error_ = keys::kModifySpecialError; |
| 721 return false; | 724 return false; |
| 722 } | 725 } |
| 723 if (has_title) | 726 if (has_title) |
| 724 model->SetTitle(node, title); | 727 model->SetTitle(node, title); |
| 725 if (!url.is_empty()) | 728 if (!url.is_empty()) |
| 726 model->SetURL(node, url); | 729 model->SetURL(node, url); |
| 727 | 730 |
| 728 scoped_ptr<BookmarkTreeNode> tree_node( | 731 scoped_ptr<BookmarkTreeNode> tree_node( |
| 729 bookmark_api_helpers::GetBookmarkTreeNode( | 732 bookmark_api_helpers::GetBookmarkTreeNode(GetManagedBookmarkService(), |
| 730 GetChromeBookmarkClient(), node, false, false)); | 733 node, false, false)); |
| 731 results_ = bookmarks::Update::Results::Create(*tree_node); | 734 results_ = bookmarks::Update::Results::Create(*tree_node); |
| 732 return true; | 735 return true; |
| 733 } | 736 } |
| 734 | 737 |
| 735 BookmarksIOFunction::BookmarksIOFunction() {} | 738 BookmarksIOFunction::BookmarksIOFunction() {} |
| 736 | 739 |
| 737 BookmarksIOFunction::~BookmarksIOFunction() { | 740 BookmarksIOFunction::~BookmarksIOFunction() { |
| 738 // There may be pending file dialogs, we need to tell them that we've gone | 741 // There may be pending file dialogs, we need to tell them that we've gone |
| 739 // away so they don't try and call back to us. | 742 // away so they don't try and call back to us. |
| 740 if (select_file_dialog_.get()) | 743 if (select_file_dialog_.get()) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } | 846 } |
| 844 | 847 |
| 845 void BookmarksExportFunction::FileSelected(const base::FilePath& path, | 848 void BookmarksExportFunction::FileSelected(const base::FilePath& path, |
| 846 int index, | 849 int index, |
| 847 void* params) { | 850 void* params) { |
| 848 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); | 851 bookmark_html_writer::WriteBookmarks(GetProfile(), path, NULL); |
| 849 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 852 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
| 850 } | 853 } |
| 851 | 854 |
| 852 } // namespace extensions | 855 } // namespace extensions |
| OLD | NEW |