OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_bookmarks_module.h" | 5 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
6 | 6 |
7 #include "base/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/bookmarks/bookmark_codec.h" | 9 #include "chrome/browser/bookmarks/bookmark_codec.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
13 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" | 13 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" |
14 #include "chrome/browser/extensions/extension_message_service.h" | 14 #include "chrome/browser/extensions/extension_message_service.h" |
15 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 args.Append(new StringValue(Int64ToString(node->id()))); | 178 args.Append(new StringValue(Int64ToString(node->id()))); |
179 DictionaryValue* object_args = new DictionaryValue(); | 179 DictionaryValue* object_args = new DictionaryValue(); |
180 object_args->SetString(keys::kParentIdKey, Int64ToString(new_parent->id())); | 180 object_args->SetString(keys::kParentIdKey, Int64ToString(new_parent->id())); |
181 object_args->SetInteger(keys::kIndexKey, new_index); | 181 object_args->SetInteger(keys::kIndexKey, new_index); |
182 object_args->SetString(keys::kOldParentIdKey, | 182 object_args->SetString(keys::kOldParentIdKey, |
183 Int64ToString(old_parent->id())); | 183 Int64ToString(old_parent->id())); |
184 object_args->SetInteger(keys::kOldIndexKey, old_index); | 184 object_args->SetInteger(keys::kOldIndexKey, old_index); |
185 args.Append(object_args); | 185 args.Append(object_args); |
186 | 186 |
187 std::string json_args; | 187 std::string json_args; |
188 JSONWriter::Write(&args, false, &json_args); | 188 base::JSONWriter::Write(&args, false, &json_args); |
189 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args); | 189 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args); |
190 } | 190 } |
191 | 191 |
192 void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, | 192 void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, |
193 const BookmarkNode* parent, | 193 const BookmarkNode* parent, |
194 int index) { | 194 int index) { |
195 ListValue args; | 195 ListValue args; |
196 const BookmarkNode* node = parent->GetChild(index); | 196 const BookmarkNode* node = parent->GetChild(index); |
197 args.Append(new StringValue(Int64ToString(node->id()))); | 197 args.Append(new StringValue(Int64ToString(node->id()))); |
198 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); | 198 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); |
199 args.Append(obj); | 199 args.Append(obj); |
200 | 200 |
201 std::string json_args; | 201 std::string json_args; |
202 JSONWriter::Write(&args, false, &json_args); | 202 base::JSONWriter::Write(&args, false, &json_args); |
203 DispatchEvent(model->profile(), keys::kOnBookmarkCreated, json_args); | 203 DispatchEvent(model->profile(), keys::kOnBookmarkCreated, json_args); |
204 } | 204 } |
205 | 205 |
206 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( | 206 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( |
207 BookmarkModel* model, | 207 BookmarkModel* model, |
208 const BookmarkNode* parent, | 208 const BookmarkNode* parent, |
209 int index, | 209 int index, |
210 const BookmarkNode* node) { | 210 const BookmarkNode* node) { |
211 ListValue args; | 211 ListValue args; |
212 args.Append(new StringValue(Int64ToString(node->id()))); | 212 args.Append(new StringValue(Int64ToString(node->id()))); |
213 DictionaryValue* object_args = new DictionaryValue(); | 213 DictionaryValue* object_args = new DictionaryValue(); |
214 object_args->SetString(keys::kParentIdKey, Int64ToString(parent->id())); | 214 object_args->SetString(keys::kParentIdKey, Int64ToString(parent->id())); |
215 object_args->SetInteger(keys::kIndexKey, index); | 215 object_args->SetInteger(keys::kIndexKey, index); |
216 args.Append(object_args); | 216 args.Append(object_args); |
217 | 217 |
218 std::string json_args; | 218 std::string json_args; |
219 JSONWriter::Write(&args, false, &json_args); | 219 base::JSONWriter::Write(&args, false, &json_args); |
220 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); | 220 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); |
221 } | 221 } |
222 | 222 |
223 void ExtensionBookmarkEventRouter::BookmarkNodeChanged( | 223 void ExtensionBookmarkEventRouter::BookmarkNodeChanged( |
224 BookmarkModel* model, const BookmarkNode* node) { | 224 BookmarkModel* model, const BookmarkNode* node) { |
225 ListValue args; | 225 ListValue args; |
226 args.Append(new StringValue(Int64ToString(node->id()))); | 226 args.Append(new StringValue(Int64ToString(node->id()))); |
227 | 227 |
228 // TODO(erikkay) The only two things that BookmarkModel sends this | 228 // TODO(erikkay) The only two things that BookmarkModel sends this |
229 // notification for are title and favicon. Since we're currently ignoring | 229 // notification for are title and favicon. Since we're currently ignoring |
230 // favicon and since the notification doesn't say which one anyway, for now | 230 // favicon and since the notification doesn't say which one anyway, for now |
231 // we only include title. The ideal thing would be to change BookmarkModel | 231 // we only include title. The ideal thing would be to change BookmarkModel |
232 // to indicate what changed. | 232 // to indicate what changed. |
233 DictionaryValue* object_args = new DictionaryValue(); | 233 DictionaryValue* object_args = new DictionaryValue(); |
234 object_args->SetString(keys::kTitleKey, node->GetTitle()); | 234 object_args->SetString(keys::kTitleKey, node->GetTitle()); |
235 args.Append(object_args); | 235 args.Append(object_args); |
236 | 236 |
237 std::string json_args; | 237 std::string json_args; |
238 JSONWriter::Write(&args, false, &json_args); | 238 base::JSONWriter::Write(&args, false, &json_args); |
239 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); | 239 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); |
240 } | 240 } |
241 | 241 |
242 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( | 242 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( |
243 BookmarkModel* model, const BookmarkNode* node) { | 243 BookmarkModel* model, const BookmarkNode* node) { |
244 // TODO(erikkay) anything we should do here? | 244 // TODO(erikkay) anything we should do here? |
245 } | 245 } |
246 | 246 |
247 void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered( | 247 void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered( |
248 BookmarkModel* model, const BookmarkNode* node) { | 248 BookmarkModel* model, const BookmarkNode* node) { |
249 ListValue args; | 249 ListValue args; |
250 args.Append(new StringValue(Int64ToString(node->id()))); | 250 args.Append(new StringValue(Int64ToString(node->id()))); |
251 int childCount = node->GetChildCount(); | 251 int childCount = node->GetChildCount(); |
252 ListValue* children = new ListValue(); | 252 ListValue* children = new ListValue(); |
253 for (int i = 0; i < childCount; ++i) { | 253 for (int i = 0; i < childCount; ++i) { |
254 const BookmarkNode* child = node->GetChild(i); | 254 const BookmarkNode* child = node->GetChild(i); |
255 Value* child_id = new StringValue(Int64ToString(child->id())); | 255 Value* child_id = new StringValue(Int64ToString(child->id())); |
256 children->Append(child_id); | 256 children->Append(child_id); |
257 } | 257 } |
258 DictionaryValue* reorder_info = new DictionaryValue(); | 258 DictionaryValue* reorder_info = new DictionaryValue(); |
259 reorder_info->Set(keys::kChildIdsKey, children); | 259 reorder_info->Set(keys::kChildIdsKey, children); |
260 args.Append(reorder_info); | 260 args.Append(reorder_info); |
261 | 261 |
262 std::string json_args; | 262 std::string json_args; |
263 JSONWriter::Write(&args, false, &json_args); | 263 base::JSONWriter::Write(&args, false, &json_args); |
264 DispatchEvent(model->profile(), | 264 DispatchEvent(model->profile(), |
265 keys::kOnBookmarkChildrenReordered, | 265 keys::kOnBookmarkChildrenReordered, |
266 json_args); | 266 json_args); |
267 } | 267 } |
268 | 268 |
269 bool GetBookmarksFunction::RunImpl() { | 269 bool GetBookmarksFunction::RunImpl() { |
270 BookmarkModel* model = profile()->GetBookmarkModel(); | 270 BookmarkModel* model = profile()->GetBookmarkModel(); |
271 scoped_ptr<ListValue> json(new ListValue()); | 271 scoped_ptr<ListValue> json(new ListValue()); |
272 if (args_->IsType(Value::TYPE_LIST)) { | 272 if (args_->IsType(Value::TYPE_LIST)) { |
273 ListValue* ids = static_cast<ListValue*>(args_); | 273 ListValue* ids = static_cast<ListValue*>(args_); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 error_ = keys::kModifySpecialError; | 543 error_ = keys::kModifySpecialError; |
544 return false; | 544 return false; |
545 } | 545 } |
546 model->SetTitle(node, title); | 546 model->SetTitle(node, title); |
547 | 547 |
548 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); | 548 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); |
549 result_.reset(ret); | 549 result_.reset(ret); |
550 | 550 |
551 return true; | 551 return true; |
552 } | 552 } |
OLD | NEW |