| 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/bookmarks/bookmark_manager_extension_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/public/pref_service_base.h" | 10 #include "base/prefs/public/pref_service_base.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 15 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 17 // TODO (rdevlin.cronin): Move BookmarkManagerAPI to | 17 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage
r_private_api_constants.h" |
| 18 // chrome/browser/extensions/api so these two aren't interdependent. | |
| 19 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" | 18 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_constants.h" |
| 20 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" | 19 #include "chrome/browser/extensions/api/bookmarks/bookmark_api_helpers.h" |
| 21 #include "chrome/browser/extensions/event_router.h" | 20 #include "chrome/browser/extensions/event_router.h" |
| 22 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 23 #include "chrome/browser/extensions/extension_system.h" | 22 #include "chrome/browser/extensions/extension_system.h" |
| 24 #include "chrome/browser/extensions/extension_web_ui.h" | 23 #include "chrome/browser/extensions/extension_web_ui.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 27 #include "chrome/browser/view_type_utils.h" | 26 #include "chrome/browser/view_type_utils.h" |
| 28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 29 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 32 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 34 | 33 |
| 35 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 36 #include "win8/util/win8_util.h" | 35 #include "win8/util/win8_util.h" |
| 37 #endif // OS_WIN | 36 #endif // OS_WIN |
| 38 | 37 |
| 39 namespace keys = extensions::bookmark_api_constants; | 38 namespace extensions { |
| 39 |
| 40 namespace bookmark_keys = bookmark_api_constants; |
| 41 namespace manager_keys = bookmark_manager_api_constants; |
| 40 | 42 |
| 41 using content::WebContents; | 43 using content::WebContents; |
| 42 | 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 // Returns a single bookmark node from the argument ID. | 47 // Returns a single bookmark node from the argument ID. |
| 46 // This returns NULL in case of failure. | 48 // This returns NULL in case of failure. |
| 47 const BookmarkNode* GetNodeFromArguments(BookmarkModel* model, | 49 const BookmarkNode* GetNodeFromArguments(BookmarkModel* model, |
| 48 const ListValue* args) { | 50 const ListValue* args) { |
| 49 std::string id_string; | 51 std::string id_string; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 88 |
| 87 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| | 89 // Recursively adds a node to a list. This is by used |BookmarkNodeDataToJSON| |
| 88 // when the data comes from the current profile. In this case we have a | 90 // when the data comes from the current profile. In this case we have a |
| 89 // BookmarkNode since we got the data from the current profile. | 91 // BookmarkNode since we got the data from the current profile. |
| 90 void AddNodeToList(ListValue* list, const BookmarkNode& node) { | 92 void AddNodeToList(ListValue* list, const BookmarkNode& node) { |
| 91 DictionaryValue* dict = new DictionaryValue(); | 93 DictionaryValue* dict = new DictionaryValue(); |
| 92 | 94 |
| 93 // Add id and parentId so we can associate the data with existing nodes on the | 95 // Add id and parentId so we can associate the data with existing nodes on the |
| 94 // client side. | 96 // client side. |
| 95 std::string id_string = base::Int64ToString(node.id()); | 97 std::string id_string = base::Int64ToString(node.id()); |
| 96 dict->SetString(keys::kIdKey, id_string); | 98 dict->SetString(bookmark_keys::kIdKey, id_string); |
| 97 | 99 |
| 98 std::string parent_id_string = base::Int64ToString(node.parent()->id()); | 100 std::string parent_id_string = base::Int64ToString(node.parent()->id()); |
| 99 dict->SetString(keys::kParentIdKey, parent_id_string); | 101 dict->SetString(bookmark_keys::kParentIdKey, parent_id_string); |
| 100 | 102 |
| 101 if (node.is_url()) | 103 if (node.is_url()) |
| 102 dict->SetString(keys::kUrlKey, node.url().spec()); | 104 dict->SetString(bookmark_keys::kUrlKey, node.url().spec()); |
| 103 | 105 |
| 104 dict->SetString(keys::kTitleKey, node.GetTitle()); | 106 dict->SetString(bookmark_keys::kTitleKey, node.GetTitle()); |
| 105 | 107 |
| 106 ListValue* children = new ListValue(); | 108 ListValue* children = new ListValue(); |
| 107 for (int i = 0; i < node.child_count(); ++i) | 109 for (int i = 0; i < node.child_count(); ++i) |
| 108 AddNodeToList(children, *node.GetChild(i)); | 110 AddNodeToList(children, *node.GetChild(i)); |
| 109 dict->Set(keys::kChildrenKey, children); | 111 dict->Set(bookmark_keys::kChildrenKey, children); |
| 110 | 112 |
| 111 list->Append(dict); | 113 list->Append(dict); |
| 112 } | 114 } |
| 113 | 115 |
| 114 // Recursively adds an element to a list. This is used by | 116 // Recursively adds an element to a list. This is used by |
| 115 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When | 117 // |BookmarkNodeDataToJSON| when the data comes from a different profile. When |
| 116 // the data comes from a different profile we do not have any IDs or parent IDs. | 118 // the data comes from a different profile we do not have any IDs or parent IDs. |
| 117 void AddElementToList(ListValue* list, | 119 void AddElementToList(ListValue* list, |
| 118 const BookmarkNodeData::Element& element) { | 120 const BookmarkNodeData::Element& element) { |
| 119 DictionaryValue* dict = new DictionaryValue(); | 121 DictionaryValue* dict = new DictionaryValue(); |
| 120 | 122 |
| 121 if (element.is_url) | 123 if (element.is_url) |
| 122 dict->SetString(keys::kUrlKey, element.url.spec()); | 124 dict->SetString(bookmark_keys::kUrlKey, element.url.spec()); |
| 123 | 125 |
| 124 dict->SetString(keys::kTitleKey, element.title); | 126 dict->SetString(bookmark_keys::kTitleKey, element.title); |
| 125 | 127 |
| 126 ListValue* children = new ListValue(); | 128 ListValue* children = new ListValue(); |
| 127 for (size_t i = 0; i < element.children.size(); ++i) | 129 for (size_t i = 0; i < element.children.size(); ++i) |
| 128 AddElementToList(children, element.children[i]); | 130 AddElementToList(children, element.children[i]); |
| 129 dict->Set(keys::kChildrenKey, children); | 131 dict->Set(bookmark_keys::kChildrenKey, children); |
| 130 | 132 |
| 131 list->Append(dict); | 133 list->Append(dict); |
| 132 } | 134 } |
| 133 | 135 |
| 134 // Builds the JSON structure based on the BookmarksDragData. | 136 // Builds the JSON structure based on the BookmarksDragData. |
| 135 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, | 137 void BookmarkNodeDataToJSON(Profile* profile, const BookmarkNodeData& data, |
| 136 ListValue* args) { | 138 ListValue* args) { |
| 137 bool same_profile = data.IsFromProfile(profile); | 139 bool same_profile = data.IsFromProfile(profile); |
| 138 DictionaryValue* value = new DictionaryValue(); | 140 DictionaryValue* value = new DictionaryValue(); |
| 139 value->SetBoolean(keys::kSameProfileKey, same_profile); | 141 value->SetBoolean(manager_keys::kSameProfileKey, same_profile); |
| 140 | 142 |
| 141 ListValue* list = new ListValue(); | 143 ListValue* list = new ListValue(); |
| 142 if (same_profile) { | 144 if (same_profile) { |
| 143 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); | 145 std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); |
| 144 for (size_t i = 0; i < nodes.size(); ++i) | 146 for (size_t i = 0; i < nodes.size(); ++i) |
| 145 AddNodeToList(list, *nodes[i]); | 147 AddNodeToList(list, *nodes[i]); |
| 146 } else { | 148 } else { |
| 147 // We do not have an node IDs when the data comes from a different profile. | 149 // We do not have an node IDs when the data comes from a different profile. |
| 148 std::vector<BookmarkNodeData::Element> elements = data.elements; | 150 std::vector<BookmarkNodeData::Element> elements = data.elements; |
| 149 for (size_t i = 0; i < elements.size(); ++i) | 151 for (size_t i = 0; i < elements.size(); ++i) |
| 150 AddElementToList(list, elements[i]); | 152 AddElementToList(list, elements[i]); |
| 151 } | 153 } |
| 152 value->Set(keys::kElementsKey, list); | 154 value->Set(manager_keys::kElementsKey, list); |
| 153 | 155 |
| 154 args->Append(value); | 156 args->Append(value); |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace | 159 } // namespace |
| 158 | 160 |
| 159 BookmarkManagerExtensionEventRouter::BookmarkManagerExtensionEventRouter( | 161 BookmarkManagerEventRouter::BookmarkManagerEventRouter( |
| 160 Profile* profile, | 162 Profile* profile, |
| 161 content::WebContents* web_contents) | 163 content::WebContents* web_contents) |
| 162 : profile_(profile), | 164 : profile_(profile), |
| 163 web_contents_(web_contents) { | 165 web_contents_(web_contents) { |
| 164 BookmarkTabHelper* bookmark_tab_helper = | 166 BookmarkTabHelper* bookmark_tab_helper = |
| 165 BookmarkTabHelper::FromWebContents(web_contents_); | 167 BookmarkTabHelper::FromWebContents(web_contents_); |
| 166 bookmark_tab_helper->SetBookmarkDragDelegate(this); | 168 bookmark_tab_helper->SetBookmarkDragDelegate(this); |
| 167 } | 169 } |
| 168 | 170 |
| 169 BookmarkManagerExtensionEventRouter::~BookmarkManagerExtensionEventRouter() { | 171 BookmarkManagerEventRouter::~BookmarkManagerEventRouter() { |
| 170 BookmarkTabHelper* bookmark_tab_helper = | 172 BookmarkTabHelper* bookmark_tab_helper = |
| 171 BookmarkTabHelper::FromWebContents(web_contents_); | 173 BookmarkTabHelper::FromWebContents(web_contents_); |
| 172 if (bookmark_tab_helper->GetBookmarkDragDelegate() == this) | 174 if (bookmark_tab_helper->GetBookmarkDragDelegate() == this) |
| 173 bookmark_tab_helper->SetBookmarkDragDelegate(NULL); | 175 bookmark_tab_helper->SetBookmarkDragDelegate(NULL); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void BookmarkManagerExtensionEventRouter::DispatchEvent( | 178 void BookmarkManagerEventRouter::DispatchEvent(const char* event_name, |
| 177 const char* event_name, scoped_ptr<ListValue> args) { | 179 scoped_ptr<ListValue> args) { |
| 178 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) | 180 if (!ExtensionSystem::Get(profile_)->event_router()) |
| 179 return; | 181 return; |
| 180 | 182 |
| 181 scoped_ptr<extensions::Event> event(new extensions::Event( | 183 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
| 182 event_name, args.Pass())); | 184 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
| 183 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
| 184 BroadcastEvent(event.Pass()); | |
| 185 } | 185 } |
| 186 | 186 |
| 187 void BookmarkManagerExtensionEventRouter::DispatchDragEvent( | 187 void BookmarkManagerEventRouter::DispatchDragEvent(const BookmarkNodeData& data, |
| 188 const BookmarkNodeData& data, const char* event_name) { | 188 const char* event_name) { |
| 189 if (data.size() == 0) | 189 if (data.size() == 0) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 scoped_ptr<ListValue> args(new ListValue()); | 192 scoped_ptr<ListValue> args(new ListValue()); |
| 193 BookmarkNodeDataToJSON(profile_, data, args.get()); | 193 BookmarkNodeDataToJSON(profile_, data, args.get()); |
| 194 DispatchEvent(event_name, args.Pass()); | 194 DispatchEvent(event_name, args.Pass()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void BookmarkManagerExtensionEventRouter::OnDragEnter( | 197 void BookmarkManagerEventRouter::OnDragEnter(const BookmarkNodeData& data) { |
| 198 const BookmarkNodeData& data) { | 198 DispatchDragEvent(data, manager_keys::kOnBookmarkDragEnter); |
| 199 DispatchDragEvent(data, keys::kOnBookmarkDragEnter); | |
| 200 } | 199 } |
| 201 | 200 |
| 202 void BookmarkManagerExtensionEventRouter::OnDragOver( | 201 void BookmarkManagerEventRouter::OnDragOver(const BookmarkNodeData& data) { |
| 203 const BookmarkNodeData& data) { | |
| 204 // Intentionally empty since these events happens too often and floods the | 202 // Intentionally empty since these events happens too often and floods the |
| 205 // message queue. We do not need this event for the bookmark manager anyway. | 203 // message queue. We do not need this event for the bookmark manager anyway. |
| 206 } | 204 } |
| 207 | 205 |
| 208 void BookmarkManagerExtensionEventRouter::OnDragLeave( | 206 void BookmarkManagerEventRouter::OnDragLeave(const BookmarkNodeData& data) { |
| 209 const BookmarkNodeData& data) { | 207 DispatchDragEvent(data, manager_keys::kOnBookmarkDragLeave); |
| 210 DispatchDragEvent(data, keys::kOnBookmarkDragLeave); | |
| 211 } | 208 } |
| 212 | 209 |
| 213 void BookmarkManagerExtensionEventRouter::OnDrop( | 210 void BookmarkManagerEventRouter::OnDrop(const BookmarkNodeData& data) { |
| 214 const BookmarkNodeData& data) { | 211 DispatchDragEvent(data, manager_keys::kOnBookmarkDrop); |
| 215 DispatchDragEvent(data, keys::kOnBookmarkDrop); | |
| 216 | 212 |
| 217 // Make a copy that is owned by this instance. | 213 // Make a copy that is owned by this instance. |
| 218 ClearBookmarkNodeData(); | 214 ClearBookmarkNodeData(); |
| 219 bookmark_drag_data_ = data; | 215 bookmark_drag_data_ = data; |
| 220 } | 216 } |
| 221 | 217 |
| 222 const BookmarkNodeData* | 218 const BookmarkNodeData* BookmarkManagerEventRouter::GetBookmarkNodeData() { |
| 223 BookmarkManagerExtensionEventRouter::GetBookmarkNodeData() { | |
| 224 if (bookmark_drag_data_.is_valid()) | 219 if (bookmark_drag_data_.is_valid()) |
| 225 return &bookmark_drag_data_; | 220 return &bookmark_drag_data_; |
| 226 return NULL; | 221 return NULL; |
| 227 } | 222 } |
| 228 | 223 |
| 229 void BookmarkManagerExtensionEventRouter::ClearBookmarkNodeData() { | 224 void BookmarkManagerEventRouter::ClearBookmarkNodeData() { |
| 230 bookmark_drag_data_.Clear(); | 225 bookmark_drag_data_.Clear(); |
| 231 } | 226 } |
| 232 | 227 |
| 233 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { | 228 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) { |
| 234 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 229 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 235 std::vector<const BookmarkNode*> nodes; | 230 std::vector<const BookmarkNode*> nodes; |
| 236 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), | 231 EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(), |
| 237 0, &nodes)); | 232 0, &nodes)); |
| 238 bookmark_utils::CopyToClipboard(model, nodes, cut); | 233 bookmark_utils::CopyToClipboard(model, nodes, cut); |
| 239 return true; | 234 return true; |
| 240 } | 235 } |
| 241 | 236 |
| 242 bool CopyBookmarkManagerFunction::RunImpl() { | 237 bool CopyBookmarkManagerFunction::RunImpl() { |
| 243 return CopyOrCut(false); | 238 return CopyOrCut(false); |
| 244 } | 239 } |
| 245 | 240 |
| 246 bool CutBookmarkManagerFunction::RunImpl() { | 241 bool CutBookmarkManagerFunction::RunImpl() { |
| 247 if (!EditBookmarksEnabled()) | 242 if (!EditBookmarksEnabled()) |
| 248 return false; | 243 return false; |
| 249 return CopyOrCut(true); | 244 return CopyOrCut(true); |
| 250 } | 245 } |
| 251 | 246 |
| 252 bool PasteBookmarkManagerFunction::RunImpl() { | 247 bool PasteBookmarkManagerFunction::RunImpl() { |
| 253 if (!EditBookmarksEnabled()) | 248 if (!EditBookmarksEnabled()) |
| 254 return false; | 249 return false; |
| 255 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 250 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 256 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 251 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
| 257 if (!parent_node) { | 252 if (!parent_node) { |
| 258 error_ = keys::kNoParentError; | 253 error_ = bookmark_keys::kNoParentError; |
| 259 return false; | 254 return false; |
| 260 } | 255 } |
| 261 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); | 256 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); |
| 262 if (!can_paste) | 257 if (!can_paste) |
| 263 return false; | 258 return false; |
| 264 | 259 |
| 265 // We want to use the highest index of the selected nodes as a destination. | 260 // We want to use the highest index of the selected nodes as a destination. |
| 266 std::vector<const BookmarkNode*> nodes; | 261 std::vector<const BookmarkNode*> nodes; |
| 267 // No need to test return value, if we got an empty list, we insert at end. | 262 // No need to test return value, if we got an empty list, we insert at end. |
| 268 GetNodesFromArguments(model, args_.get(), 1, &nodes); | 263 GetNodesFromArguments(model, args_.get(), 1, &nodes); |
| 269 int highest_index = -1; // -1 means insert at end of list. | 264 int highest_index = -1; // -1 means insert at end of list. |
| 270 for (size_t node = 0; node < nodes.size(); ++node) { | 265 for (size_t node = 0; node < nodes.size(); ++node) { |
| 271 // + 1 so that we insert after the selection. | 266 // + 1 so that we insert after the selection. |
| 272 int this_node_index = parent_node->GetIndexOf(nodes[node]) + 1; | 267 int this_node_index = parent_node->GetIndexOf(nodes[node]) + 1; |
| 273 if (this_node_index > highest_index) | 268 if (this_node_index > highest_index) |
| 274 highest_index = this_node_index; | 269 highest_index = this_node_index; |
| 275 } | 270 } |
| 276 | 271 |
| 277 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); | 272 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); |
| 278 return true; | 273 return true; |
| 279 } | 274 } |
| 280 | 275 |
| 281 bool CanPasteBookmarkManagerFunction::RunImpl() { | 276 bool CanPasteBookmarkManagerFunction::RunImpl() { |
| 282 if (!EditBookmarksEnabled()) | 277 if (!EditBookmarksEnabled()) |
| 283 return false; | 278 return false; |
| 284 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 279 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 285 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 280 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
| 286 if (!parent_node) { | 281 if (!parent_node) { |
| 287 error_ = keys::kNoParentError; | 282 error_ = bookmark_keys::kNoParentError; |
| 288 return false; | 283 return false; |
| 289 } | 284 } |
| 290 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); | 285 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); |
| 291 SetResult(new base::FundamentalValue(can_paste)); | 286 SetResult(new base::FundamentalValue(can_paste)); |
| 292 return true; | 287 return true; |
| 293 } | 288 } |
| 294 | 289 |
| 295 bool SortChildrenBookmarkManagerFunction::RunImpl() { | 290 bool SortChildrenBookmarkManagerFunction::RunImpl() { |
| 296 if (!EditBookmarksEnabled()) | 291 if (!EditBookmarksEnabled()) |
| 297 return false; | 292 return false; |
| 298 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 293 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 299 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); | 294 const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); |
| 300 if (!parent_node) { | 295 if (!parent_node) { |
| 301 error_ = keys::kNoParentError; | 296 error_ = bookmark_keys::kNoParentError; |
| 302 return false; | 297 return false; |
| 303 } | 298 } |
| 304 model->SortChildren(parent_node); | 299 model->SortChildren(parent_node); |
| 305 return true; | 300 return true; |
| 306 } | 301 } |
| 307 | 302 |
| 308 bool BookmarkManagerGetStringsFunction::RunImpl() { | 303 bool BookmarkManagerGetStringsFunction::RunImpl() { |
| 309 DictionaryValue* localized_strings = new DictionaryValue(); | 304 DictionaryValue* localized_strings = new DictionaryValue(); |
| 310 | 305 |
| 311 localized_strings->SetString("title", | 306 localized_strings->SetString("title", |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (!EditBookmarksEnabled()) | 411 if (!EditBookmarksEnabled()) |
| 417 return false; | 412 return false; |
| 418 | 413 |
| 419 BookmarkModel* model =BookmarkModelFactory::GetForProfile(profile()); | 414 BookmarkModel* model =BookmarkModelFactory::GetForProfile(profile()); |
| 420 | 415 |
| 421 int64 id; | 416 int64 id; |
| 422 std::string id_string; | 417 std::string id_string; |
| 423 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); | 418 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); |
| 424 | 419 |
| 425 if (!base::StringToInt64(id_string, &id)) { | 420 if (!base::StringToInt64(id_string, &id)) { |
| 426 error_ = keys::kInvalidIdError; | 421 error_ = bookmark_keys::kInvalidIdError; |
| 427 return false; | 422 return false; |
| 428 } | 423 } |
| 429 | 424 |
| 430 const BookmarkNode* drop_parent = model->GetNodeByID(id); | 425 const BookmarkNode* drop_parent = model->GetNodeByID(id); |
| 431 if (!drop_parent) { | 426 if (!drop_parent) { |
| 432 error_ = keys::kNoParentError; | 427 error_ = bookmark_keys::kNoParentError; |
| 433 return false; | 428 return false; |
| 434 } | 429 } |
| 435 | 430 |
| 436 int drop_index; | 431 int drop_index; |
| 437 if (HasOptionalArgument(1)) | 432 if (HasOptionalArgument(1)) |
| 438 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); | 433 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index)); |
| 439 else | 434 else |
| 440 drop_index = drop_parent->child_count(); | 435 drop_index = drop_parent->child_count(); |
| 441 | 436 |
| 442 WebContents* web_contents = | 437 WebContents* web_contents = |
| 443 WebContents::FromRenderViewHost(render_view_host_); | 438 WebContents::FromRenderViewHost(render_view_host_); |
| 444 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { | 439 if (chrome::GetViewType(web_contents) == chrome::VIEW_TYPE_TAB_CONTENTS) { |
| 445 WebContents* web_contents = | 440 WebContents* web_contents = |
| 446 dispatcher()->delegate()->GetAssociatedWebContents(); | 441 dispatcher()->delegate()->GetAssociatedWebContents(); |
| 447 CHECK(web_contents); | 442 CHECK(web_contents); |
| 448 ExtensionWebUI* web_ui = | 443 ExtensionWebUI* web_ui = |
| 449 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); | 444 static_cast<ExtensionWebUI*>(web_contents->GetWebUI()->GetController()); |
| 450 CHECK(web_ui); | 445 CHECK(web_ui); |
| 451 BookmarkManagerExtensionEventRouter* router = | 446 BookmarkManagerEventRouter* router = |
| 452 web_ui->bookmark_manager_extension_event_router(); | 447 web_ui->bookmark_manager_event_router(); |
| 453 | 448 |
| 454 DCHECK(router); | 449 DCHECK(router); |
| 455 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); | 450 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); |
| 456 if (drag_data == NULL) { | 451 if (drag_data == NULL) { |
| 457 NOTREACHED() <<"Somehow we're dropping null bookmark data"; | 452 NOTREACHED() <<"Somehow we're dropping null bookmark data"; |
| 458 return false; | 453 return false; |
| 459 } | 454 } |
| 460 bookmark_utils::PerformBookmarkDrop(profile(), | 455 bookmark_utils::PerformBookmarkDrop(profile(), |
| 461 *drag_data, | 456 *drag_data, |
| 462 drop_parent, drop_index); | 457 drop_parent, drop_index); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 474 const BookmarkNode* node; | 469 const BookmarkNode* node; |
| 475 int64 id; | 470 int64 id; |
| 476 std::string id_string; | 471 std::string id_string; |
| 477 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); | 472 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string)); |
| 478 bool folders_only; | 473 bool folders_only; |
| 479 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &folders_only)); | 474 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &folders_only)); |
| 480 if (id_string == "") { | 475 if (id_string == "") { |
| 481 node = model->root_node(); | 476 node = model->root_node(); |
| 482 } else { | 477 } else { |
| 483 if (!base::StringToInt64(id_string, &id)) { | 478 if (!base::StringToInt64(id_string, &id)) { |
| 484 error_ = keys::kInvalidIdError; | 479 error_ = bookmark_keys::kInvalidIdError; |
| 485 return false; | 480 return false; |
| 486 } | 481 } |
| 487 node = model->GetNodeByID(id); | 482 node = model->GetNodeByID(id); |
| 488 } | 483 } |
| 489 if (!node) { | 484 if (!node) { |
| 490 error_ = keys::kNoNodeError; | 485 error_ = bookmark_keys::kNoNodeError; |
| 491 return false; | 486 return false; |
| 492 } | 487 } |
| 493 scoped_ptr<ListValue> json(new ListValue()); | 488 scoped_ptr<ListValue> json(new ListValue()); |
| 494 if (folders_only) { | 489 if (folders_only) |
| 495 extensions::bookmark_api_helpers::AddNodeFoldersOnly(node, | 490 bookmark_api_helpers::AddNodeFoldersOnly(node, json.get(), true); |
| 496 json.get(), | 491 else |
| 497 true); | 492 bookmark_api_helpers::AddNode(node, json.get(), true); |
| 498 } else { | |
| 499 extensions::bookmark_api_helpers::AddNode(node, json.get(), true); | |
| 500 } | |
| 501 SetResult(json.release()); | 493 SetResult(json.release()); |
| 502 return true; | 494 return true; |
| 503 } | 495 } |
| 504 | 496 |
| 505 bool CanEditBookmarkManagerFunction::RunImpl() { | 497 bool CanEditBookmarkManagerFunction::RunImpl() { |
| 506 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); | 498 PrefServiceBase* prefs = PrefServiceBase::FromBrowserContext(profile_); |
| 507 SetResult(new base::FundamentalValue( | 499 SetResult(new base::FundamentalValue( |
| 508 prefs->GetBoolean(prefs::kEditBookmarksEnabled))); | 500 prefs->GetBoolean(prefs::kEditBookmarksEnabled))); |
| 509 return true; | 501 return true; |
| 510 } | 502 } |
| 511 | 503 |
| 512 bool RecordLaunchBookmarkFunction::RunImpl() { | 504 bool RecordLaunchBookmarkFunction::RunImpl() { |
| 513 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); | 505 bookmark_utils::RecordBookmarkLaunch(bookmark_utils::LAUNCH_MANAGER); |
| 514 return true; | 506 return true; |
| 515 } | 507 } |
| 516 | 508 |
| 517 bool CanOpenNewWindowsBookmarkFunction::RunImpl() { | 509 bool CanOpenNewWindowsBookmarkFunction::RunImpl() { |
| 518 bool can_open_new_windows = true; | 510 bool can_open_new_windows = true; |
| 519 | 511 |
| 520 #if defined(OS_WIN) | 512 #if defined(OS_WIN) |
| 521 if (win8::IsSingleWindowMetroMode()) | 513 if (win8::IsSingleWindowMetroMode()) |
| 522 can_open_new_windows = false; | 514 can_open_new_windows = false; |
| 523 #endif // OS_WIN | 515 #endif // OS_WIN |
| 524 | 516 |
| 525 SetResult(new base::FundamentalValue(can_open_new_windows)); | 517 SetResult(new base::FundamentalValue(can_open_new_windows)); |
| 526 return true; | 518 return true; |
| 527 } | 519 } |
| 520 |
| 521 } // namespace extensions |
| OLD | NEW |