| Index: chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
|
| diff --git a/chrome/browser/bookmarks/bookmark_manager_extension_api.cc b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
|
| similarity index 85%
|
| rename from chrome/browser/bookmarks/bookmark_manager_extension_api.cc
|
| rename to chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
|
| index 385e9094c7a7b6bb183153cb2c89957a5bfaa963..44fb799e093c30e16389cead631c606798ac2de4 100644
|
| --- a/chrome/browser/bookmarks/bookmark_manager_extension_api.cc
|
| +++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/bookmarks/bookmark_manager_extension_api.h"
|
| +#include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.h"
|
|
|
| #include <vector>
|
|
|
| @@ -14,8 +14,7 @@
|
| #include "chrome/browser/bookmarks/bookmark_model_factory.h"
|
| #include "chrome/browser/bookmarks/bookmark_node_data.h"
|
| #include "chrome/browser/bookmarks/bookmark_utils.h"
|
| -// TODO (rdevlin.cronin): Move BookmarkManagerAPI to
|
| -// chrome/browser/extensions/api so these two aren't interdependent.
|
| +#include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api_constants.h"
|
| #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h"
|
| #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h"
|
| #include "chrome/browser/extensions/event_router.h"
|
| @@ -36,7 +35,10 @@
|
| #include "win8/util/win8_util.h"
|
| #endif // OS_WIN
|
|
|
| -namespace keys = extensions::bookmark_api_constants;
|
| +namespace extensions {
|
| +
|
| +namespace bookmark_keys = bookmark_api_constants;
|
| +namespace manager_keys = bookmark_manager_api_constants;
|
|
|
| using content::WebContents;
|
|
|
| @@ -93,20 +95,20 @@ void AddNodeToList(ListValue* list, const BookmarkNode& node) {
|
| // Add id and parentId so we can associate the data with existing nodes on the
|
| // client side.
|
| std::string id_string = base::Int64ToString(node.id());
|
| - dict->SetString(keys::kIdKey, id_string);
|
| + dict->SetString(bookmark_keys::kIdKey, id_string);
|
|
|
| std::string parent_id_string = base::Int64ToString(node.parent()->id());
|
| - dict->SetString(keys::kParentIdKey, parent_id_string);
|
| + dict->SetString(bookmark_keys::kParentIdKey, parent_id_string);
|
|
|
| if (node.is_url())
|
| - dict->SetString(keys::kUrlKey, node.url().spec());
|
| + dict->SetString(bookmark_keys::kUrlKey, node.url().spec());
|
|
|
| - dict->SetString(keys::kTitleKey, node.GetTitle());
|
| + dict->SetString(bookmark_keys::kTitleKey, node.GetTitle());
|
|
|
| ListValue* children = new ListValue();
|
| for (int i = 0; i < node.child_count(); ++i)
|
| AddNodeToList(children, *node.GetChild(i));
|
| - dict->Set(keys::kChildrenKey, children);
|
| + dict->Set(bookmark_keys::kChildrenKey, children);
|
|
|
| list->Append(dict);
|
| }
|
| @@ -119,14 +121,14 @@ void AddElementToList(ListValue* list,
|
| DictionaryValue* dict = new DictionaryValue();
|
|
|
| if (element.is_url)
|
| - dict->SetString(keys::kUrlKey, element.url.spec());
|
| + dict->SetString(bookmark_keys::kUrlKey, element.url.spec());
|
|
|
| - dict->SetString(keys::kTitleKey, element.title);
|
| + dict->SetString(bookmark_keys::kTitleKey, element.title);
|
|
|
| ListValue* children = new ListValue();
|
| for (size_t i = 0; i < element.children.size(); ++i)
|
| AddElementToList(children, element.children[i]);
|
| - dict->Set(keys::kChildrenKey, children);
|
| + dict->Set(bookmark_keys::kChildrenKey, children);
|
|
|
| list->Append(dict);
|
| }
|
| @@ -136,7 +138,7 @@ void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data,
|
| ListValue* args) {
|
| bool same_profile = data.IsFromProfile(profile);
|
| DictionaryValue* value = new DictionaryValue();
|
| - value->SetBoolean(keys::kSameProfileKey, same_profile);
|
| + value->SetBoolean(manager_keys::kSameProfileKey, same_profile);
|
|
|
| ListValue* list = new ListValue();
|
| if (same_profile) {
|
| @@ -149,14 +151,14 @@ void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data,
|
| for (size_t i = 0; i < elements.size(); ++i)
|
| AddElementToList(list, elements[i]);
|
| }
|
| - value->Set(keys::kElementsKey, list);
|
| + value->Set(manager_keys::kElementsKey, list);
|
|
|
| args->Append(value);
|
| }
|
|
|
| } // namespace
|
|
|
| -BookmarkManagerExtensionEventRouter::BookmarkManagerExtensionEventRouter(
|
| +BookmarkManagerEventRouter::BookmarkManagerEventRouter(
|
| Profile* profile,
|
| content::WebContents* web_contents)
|
| : profile_(profile),
|
| @@ -166,26 +168,24 @@ BookmarkManagerExtensionEventRouter::BookmarkManagerExtensionEventRouter(
|
| bookmark_tab_helper->SetBookmarkDragDelegate(this);
|
| }
|
|
|
| -BookmarkManagerExtensionEventRouter::~BookmarkManagerExtensionEventRouter() {
|
| +BookmarkManagerEventRouter::~BookmarkManagerEventRouter() {
|
| BookmarkTabHelper* bookmark_tab_helper =
|
| BookmarkTabHelper::FromWebContents(web_contents_);
|
| if (bookmark_tab_helper->GetBookmarkDragDelegate() == this)
|
| bookmark_tab_helper->SetBookmarkDragDelegate(NULL);
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::DispatchEvent(
|
| - const char* event_name, scoped_ptr<ListValue> args) {
|
| - if (!extensions::ExtensionSystem::Get(profile_)->event_router())
|
| +void BookmarkManagerEventRouter::DispatchEvent(const char* event_name,
|
| + scoped_ptr<ListValue> args) {
|
| + if (!ExtensionSystem::Get(profile_)->event_router())
|
| return;
|
|
|
| - scoped_ptr<extensions::Event> event(new extensions::Event(
|
| - event_name, args.Pass()));
|
| - extensions::ExtensionSystem::Get(profile_)->event_router()->
|
| - BroadcastEvent(event.Pass());
|
| + scoped_ptr<Event> event(new Event(event_name, args.Pass()));
|
| + ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass());
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::DispatchDragEvent(
|
| - const BookmarkNodeData& data, const char* event_name) {
|
| +void BookmarkManagerEventRouter::DispatchDragEvent(const BookmarkNodeData& data,
|
| + const char* event_name) {
|
| if (data.size() == 0)
|
| return;
|
|
|
| @@ -194,39 +194,34 @@ void BookmarkManagerExtensionEventRouter::DispatchDragEvent(
|
| DispatchEvent(event_name, args.Pass());
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::OnDragEnter(
|
| - const BookmarkNodeData& data) {
|
| - DispatchDragEvent(data, keys::kOnBookmarkDragEnter);
|
| +void BookmarkManagerEventRouter::OnDragEnter(const BookmarkNodeData& data) {
|
| + DispatchDragEvent(data, manager_keys::kOnBookmarkDragEnter);
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::OnDragOver(
|
| - const BookmarkNodeData& data) {
|
| +void BookmarkManagerEventRouter::OnDragOver(const BookmarkNodeData& data) {
|
| // Intentionally empty since these events happens too often and floods the
|
| // message queue. We do not need this event for the bookmark manager anyway.
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::OnDragLeave(
|
| - const BookmarkNodeData& data) {
|
| - DispatchDragEvent(data, keys::kOnBookmarkDragLeave);
|
| +void BookmarkManagerEventRouter::OnDragLeave(const BookmarkNodeData& data) {
|
| + DispatchDragEvent(data, manager_keys::kOnBookmarkDragLeave);
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::OnDrop(
|
| - const BookmarkNodeData& data) {
|
| - DispatchDragEvent(data, keys::kOnBookmarkDrop);
|
| +void BookmarkManagerEventRouter::OnDrop(const BookmarkNodeData& data) {
|
| + DispatchDragEvent(data, manager_keys::kOnBookmarkDrop);
|
|
|
| // Make a copy that is owned by this instance.
|
| ClearBookmarkNodeData();
|
| bookmark_drag_data_ = data;
|
| }
|
|
|
| -const BookmarkNodeData*
|
| -BookmarkManagerExtensionEventRouter::GetBookmarkNodeData() {
|
| +const BookmarkNodeData* BookmarkManagerEventRouter::GetBookmarkNodeData() {
|
| if (bookmark_drag_data_.is_valid())
|
| return &bookmark_drag_data_;
|
| return NULL;
|
| }
|
|
|
| -void BookmarkManagerExtensionEventRouter::ClearBookmarkNodeData() {
|
| +void BookmarkManagerEventRouter::ClearBookmarkNodeData() {
|
| bookmark_drag_data_.Clear();
|
| }
|
|
|
| @@ -255,7 +250,7 @@ bool PasteBookmarkManagerFunction::RunImpl() {
|
| BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
|
| const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
|
| if (!parent_node) {
|
| - error_ = keys::kNoParentError;
|
| + error_ = bookmark_keys::kNoParentError;
|
| return false;
|
| }
|
| bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node);
|
| @@ -284,7 +279,7 @@ bool CanPasteBookmarkManagerFunction::RunImpl() {
|
| BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
|
| const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
|
| if (!parent_node) {
|
| - error_ = keys::kNoParentError;
|
| + error_ = bookmark_keys::kNoParentError;
|
| return false;
|
| }
|
| bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node);
|
| @@ -298,7 +293,7 @@ bool SortChildrenBookmarkManagerFunction::RunImpl() {
|
| BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
|
| const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
|
| if (!parent_node) {
|
| - error_ = keys::kNoParentError;
|
| + error_ = bookmark_keys::kNoParentError;
|
| return false;
|
| }
|
| model->SortChildren(parent_node);
|
| @@ -423,13 +418,13 @@ bool DropBookmarkManagerFunction::RunImpl() {
|
| EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string));
|
|
|
| if (!base::StringToInt64(id_string, &id)) {
|
| - error_ = keys::kInvalidIdError;
|
| + error_ = bookmark_keys::kInvalidIdError;
|
| return false;
|
| }
|
|
|
| const BookmarkNode* drop_parent = model->GetNodeByID(id);
|
| if (!drop_parent) {
|
| - error_ = keys::kNoParentError;
|
| + error_ = bookmark_keys::kNoParentError;
|
| return false;
|
| }
|
|
|
| @@ -448,8 +443,8 @@ bool DropBookmarkManagerFunction::RunImpl() {
|
| ExtensionWebUI* web_ui =
|
| static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController());
|
| CHECK(web_ui);
|
| - BookmarkManagerExtensionEventRouter* router =
|
| - web_ui->bookmark_manager_extension_event_router();
|
| + BookmarkManagerEventRouter* router =
|
| + web_ui->bookmark_manager_event_router();
|
|
|
| DCHECK(router);
|
| const BookmarkNodeData* drag_data = router->GetBookmarkNodeData();
|
| @@ -481,23 +476,20 @@ bool GetSubtreeBookmarkManagerFunction::RunImpl() {
|
| node = model->root_node();
|
| } else {
|
| if (!base::StringToInt64(id_string, &id)) {
|
| - error_ = keys::kInvalidIdError;
|
| + error_ = bookmark_keys::kInvalidIdError;
|
| return false;
|
| }
|
| node = model->GetNodeByID(id);
|
| }
|
| if (!node) {
|
| - error_ = keys::kNoNodeError;
|
| + error_ = bookmark_keys::kNoNodeError;
|
| return false;
|
| }
|
| scoped_ptr<ListValue> json(new ListValue());
|
| - if (folders_only) {
|
| - extensions::bookmark_api_helpers::AddNodeFoldersOnly(node,
|
| - json.get(),
|
| - true);
|
| - } else {
|
| - extensions::bookmark_api_helpers::AddNode(node, json.get(), true);
|
| - }
|
| + if (folders_only)
|
| + bookmark_api_helpers::AddNodeFoldersOnly(node, json.get(), true);
|
| + else
|
| + bookmark_api_helpers::AddNode(node, json.get(), true);
|
| SetResult(json.release());
|
| return true;
|
| }
|
| @@ -525,3 +517,5 @@ bool CanOpenNewWindowsBookmarkFunction::RunImpl() {
|
| SetResult(new base::FundamentalValue(can_open_new_windows));
|
| return true;
|
| }
|
| +
|
| +} // namespace extensions
|
|
|