| 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/bookmark_manager_private/bookmark_manage
r_private_api.h" | 5 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return false; | 81 return false; |
| 82 nodes->push_back(node); | 82 nodes->push_back(node); |
| 83 } | 83 } |
| 84 | 84 |
| 85 return true; | 85 return true; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| | 88 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| |
| 89 // when the data comes from the current profile. In this case we have a | 89 // when the data comes from the current profile. In this case we have a |
| 90 // BookmarkNode since we got the data from the current profile. | 90 // BookmarkNode since we got the data from the current profile. |
| 91 void AddNodeToList(ListValue* list, const BookmarkNode& node) { | 91 void AddNodeToList(base::ListValue* list, const BookmarkNode& node) { |
| 92 DictionaryValue* dict = new DictionaryValue(); | 92 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 93 | 93 |
| 94 // Add id and parentId so we can associate the data with existing nodes on the | 94 // Add id and parentId so we can associate the data with existing nodes on the |
| 95 // client side. | 95 // client side. |
| 96 std::string id_string = base::Int64ToString(node.id()); | 96 std::string id_string = base::Int64ToString(node.id()); |
| 97 dict->SetString(bookmark_keys::kIdKey, id_string); | 97 dict->SetString(bookmark_keys::kIdKey, id_string); |
| 98 | 98 |
| 99 std::string parent_id_string = base::Int64ToString(node.parent()->id()); | 99 std::string parent_id_string = base::Int64ToString(node.parent()->id()); |
| 100 dict->SetString(bookmark_keys::kParentIdKey, parent_id_string); | 100 dict->SetString(bookmark_keys::kParentIdKey, parent_id_string); |
| 101 | 101 |
| 102 if (node.is_url()) | 102 if (node.is_url()) |
| 103 dict->SetString(bookmark_keys::kUrlKey, node.url().spec()); | 103 dict->SetString(bookmark_keys::kUrlKey, node.url().spec()); |
| 104 | 104 |
| 105 dict->SetString(bookmark_keys::kTitleKey, node.GetTitle()); | 105 dict->SetString(bookmark_keys::kTitleKey, node.GetTitle()); |
| 106 | 106 |
| 107 ListValue* children = new ListValue(); | 107 base::ListValue* children = new base::ListValue(); |
| 108 for (int i = 0; i < node.child_count(); ++i) | 108 for (int i = 0; i < node.child_count(); ++i) |
| 109 AddNodeToList(children, *node.GetChild(i)); | 109 AddNodeToList(children, *node.GetChild(i)); |
| 110 dict->Set(bookmark_keys::kChildrenKey, children); | 110 dict->Set(bookmark_keys::kChildrenKey, children); |
| 111 | 111 |
| 112 list->Append(dict); | 112 list->Append(dict); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Recursively adds an element to a list. This is used by | 115 // Recursively adds an element to a list. This is used by |
| 116 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When | 116 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When |
| 117 // the data comes from a different profile we do not have any IDs or parent IDs. | 117 // the data comes from a different profile we do not have any IDs or parent IDs. |
| 118 void AddElementToList(ListValue* list, | 118 void AddElementToList(base::ListValue* list, |
| 119 const BookmarkNodeData::Element& element) { | 119 const BookmarkNodeData::Element& element) { |
| 120 DictionaryValue* dict = new DictionaryValue(); | 120 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 121 | 121 |
| 122 if (element.is_url) | 122 if (element.is_url) |
| 123 dict->SetString(bookmark_keys::kUrlKey, element.url.spec()); | 123 dict->SetString(bookmark_keys::kUrlKey, element.url.spec()); |
| 124 | 124 |
| 125 dict->SetString(bookmark_keys::kTitleKey, element.title); | 125 dict->SetString(bookmark_keys::kTitleKey, element.title); |
| 126 | 126 |
| 127 ListValue* children = new ListValue(); | 127 base::ListValue* children = new base::ListValue(); |
| 128 for (size_t i = 0; i < element.children.size(); ++i) | 128 for (size_t i = 0; i < element.children.size(); ++i) |
| 129 AddElementToList(children, element.children[i]); | 129 AddElementToList(children, element.children[i]); |
| 130 dict->Set(bookmark_keys::kChildrenKey, children); | 130 dict->Set(bookmark_keys::kChildrenKey, children); |
| 131 | 131 |
| 132 list->Append(dict); | 132 list->Append(dict); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Builds the JSON structure based on the BookmarksDragData. | 135 // Builds the JSON structure based on the BookmarksDragData. |
| 136 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, | 136 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, |
| 137 ListValue* args) { | 137 base::ListValue* args) { |
| 138 bool same_profile = data.IsFromProfile(profile); | 138 bool same_profile = data.IsFromProfile(profile); |
| 139 DictionaryValue* value = new DictionaryValue(); | 139 base::DictionaryValue* value = new base::DictionaryValue(); |
| 140 value->SetBoolean(manager_keys::kSameProfileKey, same_profile); | 140 value->SetBoolean(manager_keys::kSameProfileKey, same_profile); |
| 141 | 141 |
| 142 ListValue* list = new ListValue(); | 142 base::ListValue* list = new base::ListValue(); |
| 143 if (same_profile) { | 143 if (same_profile) { |
| 144 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); | 144 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); |
| 145 for (size_t i = 0; i < nodes.size(); ++i) | 145 for (size_t i = 0; i < nodes.size(); ++i) |
| 146 AddNodeToList(list, *nodes[i]); | 146 AddNodeToList(list, *nodes[i]); |
| 147 } else { | 147 } else { |
| 148 // We do not have an node IDs when the data comes from a different profile. | 148 // We do not have an node IDs when the data comes from a different profile. |
| 149 std::vector<BookmarkNodeData::Element> elements = data.elements; | 149 std::vector<BookmarkNodeData::Element> elements = data.elements; |
| 150 for (size_t i = 0; i < elements.size(); ++i) | 150 for (size_t i = 0; i < elements.size(); ++i) |
| 151 AddElementToList(list, elements[i]); | 151 AddElementToList(list, elements[i]); |
| 152 } | 152 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { | 170 BookmarkManagerPrivateEventRouter::~BookmarkManagerPrivateEventRouter() { |
| 171 BookmarkTabHelper* bookmark_tab_helper = | 171 BookmarkTabHelper* bookmark_tab_helper = |
| 172 BookmarkTabHelper::FromWebContents(web_contents_); | 172 BookmarkTabHelper::FromWebContents(web_contents_); |
| 173 if (bookmark_tab_helper->bookmark_drag_delegate() == this) | 173 if (bookmark_tab_helper->bookmark_drag_delegate() == this) |
| 174 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); | 174 bookmark_tab_helper->set_bookmark_drag_delegate(NULL); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void BookmarkManagerPrivateEventRouter::DispatchEvent( | 177 void BookmarkManagerPrivateEventRouter::DispatchEvent( |
| 178 const char* event_name, | 178 const char* event_name, |
| 179 scoped_ptr<ListValue> args) { | 179 scoped_ptr<base::ListValue> args) { |
| 180 if (!ExtensionSystem::Get(profile_)->event_router()) | 180 if (!ExtensionSystem::Get(profile_)->event_router()) |
| 181 return; | 181 return; |
| 182 | 182 |
| 183 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 183 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 184 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 184 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void BookmarkManagerPrivateEventRouter::DispatchDragEvent( | 187 void BookmarkManagerPrivateEventRouter::DispatchDragEvent( |
| 188 const BookmarkNodeData& data, | 188 const BookmarkNodeData& data, |
| 189 const char* event_name) { | 189 const char* event_name) { |
| 190 if (data.size() == 0) | 190 if (data.size() == 0) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 scoped_ptr<ListValue> args(new ListValue()); | 193 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 194 BookmarkNodeDataToJSON(profile_, data, args.get()); | 194 BookmarkNodeDataToJSON(profile_, data, args.get()); |
| 195 DispatchEvent(event_name, args.Pass()); | 195 DispatchEvent(event_name, args.Pass()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void BookmarkManagerPrivateEventRouter::OnDragEnter( | 198 void BookmarkManagerPrivateEventRouter::OnDragEnter( |
| 199 const BookmarkNodeData& data) { | 199 const BookmarkNodeData& data) { |
| 200 DispatchDragEvent(data, manager_keys::kOnBookmarkDragEnter); | 200 DispatchDragEvent(data, manager_keys::kOnBookmarkDragEnter); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void BookmarkManagerPrivateEventRouter::OnDragOver( | 203 void BookmarkManagerPrivateEventRouter::OnDragOver( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); | 316 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); |
| 317 if (!parent_node) { | 317 if (!parent_node) { |
| 318 error_ = bookmark_keys::kNoParentError; | 318 error_ = bookmark_keys::kNoParentError; |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 model->SortChildren(parent_node); | 321 model->SortChildren(parent_node); |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 | 324 |
| 325 bool BookmarkManagerPrivateGetStringsFunction::RunImpl() { | 325 bool BookmarkManagerPrivateGetStringsFunction::RunImpl() { |
| 326 DictionaryValue* localized_strings = new DictionaryValue(); | 326 base::DictionaryValue* localized_strings = new base::DictionaryValue(); |
| 327 | 327 |
| 328 localized_strings->SetString("title", | 328 localized_strings->SetString("title", |
| 329 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE)); | 329 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE)); |
| 330 localized_strings->SetString("search_button", | 330 localized_strings->SetString("search_button", |
| 331 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_SEARCH_BUTTON)); | 331 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_SEARCH_BUTTON)); |
| 332 localized_strings->SetString("organize_menu", | 332 localized_strings->SetString("organize_menu", |
| 333 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU)); | 333 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU)); |
| 334 localized_strings->SetString("show_in_folder", | 334 localized_strings->SetString("show_in_folder", |
| 335 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER)); | 335 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER)); |
| 336 localized_strings->SetString("sort", | 336 localized_strings->SetString("sort", |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 return false; | 494 return false; |
| 495 } | 495 } |
| 496 node = model->GetNodeByID(id); | 496 node = model->GetNodeByID(id); |
| 497 } | 497 } |
| 498 | 498 |
| 499 if (!node) { | 499 if (!node) { |
| 500 error_ = bookmark_keys::kNoNodeError; | 500 error_ = bookmark_keys::kNoNodeError; |
| 501 return false; | 501 return false; |
| 502 } | 502 } |
| 503 | 503 |
| 504 scoped_ptr<ListValue> json(new ListValue()); | 504 scoped_ptr<base::ListValue> json(new base::ListValue()); |
| 505 if (params->folders_only) | 505 if (params->folders_only) |
| 506 bookmark_api_helpers::AddNodeFoldersOnly(node, json.get(), true); | 506 bookmark_api_helpers::AddNodeFoldersOnly(node, json.get(), true); |
| 507 else | 507 else |
| 508 bookmark_api_helpers::AddNode(node, json.get(), true); | 508 bookmark_api_helpers::AddNode(node, json.get(), true); |
| 509 SetResult(json.release()); | 509 SetResult(json.release()); |
| 510 return true; | 510 return true; |
| 511 } | 511 } |
| 512 | 512 |
| 513 bool BookmarkManagerPrivateCanEditFunction::RunImpl() { | 513 bool BookmarkManagerPrivateCanEditFunction::RunImpl() { |
| 514 PrefService* prefs = user_prefs::UserPrefs::Get(profile_); | 514 PrefService* prefs = user_prefs::UserPrefs::Get(profile_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 528 #if defined(OS_WIN) | 528 #if defined(OS_WIN) |
| 529 if (win8::IsSingleWindowMetroMode()) | 529 if (win8::IsSingleWindowMetroMode()) |
| 530 can_open_new_windows = false; | 530 can_open_new_windows = false; |
| 531 #endif // OS_WIN | 531 #endif // OS_WIN |
| 532 | 532 |
| 533 SetResult(new base::FundamentalValue(can_open_new_windows)); | 533 SetResult(new base::FundamentalValue(can_open_new_windows)); |
| 534 return true; | 534 return true; |
| 535 } | 535 } |
| 536 | 536 |
| 537 } // namespace extensions | 537 } // namespace extensions |
| OLD | NEW |