Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/extensions/extension_bookmarks_module.cc

Issue 149310: Always persist bookmark IDs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_writer.h"
8 #include "base/string_util.h"
8 #include "chrome/browser/bookmarks/bookmark_codec.h" 9 #include "chrome/browser/bookmarks/bookmark_codec.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/bookmarks/bookmark_utils.h" 11 #include "chrome/browser/bookmarks/bookmark_utils.h"
11 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" 13 #include "chrome/browser/extensions/extension_bookmarks_module_constants.h"
13 #include "chrome/browser/extensions/extension_message_service.h" 14 #include "chrome/browser/extensions/extension_message_service.h"
14 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
15 #include "chrome/common/notification_service.h" 16 #include "chrome/common/notification_service.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "chrome/common/pref_service.h" 18 #include "chrome/common/pref_service.h"
18 19
19 namespace keys = extension_bookmarks_module_constants; 20 namespace keys = extension_bookmarks_module_constants;
20 21
21 // Helper functions. 22 // Helper functions.
22 class ExtensionBookmarks { 23 class ExtensionBookmarks {
23 public: 24 public:
24 // Convert |node| into a JSON value. 25 // Convert |node| into a JSON value.
25 static DictionaryValue* GetNodeDictionary(const BookmarkNode* node, 26 static DictionaryValue* GetNodeDictionary(const BookmarkNode* node,
26 bool recurse) { 27 bool recurse) {
27 DictionaryValue* dict = new DictionaryValue(); 28 DictionaryValue* dict = new DictionaryValue();
28 dict->SetInteger(keys::kIdKey, node->id()); 29 dict->SetString(keys::kIdKey, Int64ToString(node->id()));
29 30
30 const BookmarkNode* parent = node->GetParent(); 31 const BookmarkNode* parent = node->GetParent();
31 if (parent) 32 if (parent)
32 dict->SetInteger(keys::kParentIdKey, parent->id()); 33 dict->SetString(keys::kParentIdKey, Int64ToString(parent->id()));
33 34
34 if (!node->is_folder()) { 35 if (!node->is_folder()) {
35 dict->SetString(keys::kUrlKey, node->GetURL().spec()); 36 dict->SetString(keys::kUrlKey, node->GetURL().spec());
36 } else { 37 } else {
37 // Javascript Date wants milliseconds since the epoch, ToDoubleT is 38 // Javascript Date wants milliseconds since the epoch, ToDoubleT is
38 // seconds. 39 // seconds.
39 base::Time t = node->date_group_modified(); 40 base::Time t = node->date_group_modified();
40 if (!t.is_null()) 41 if (!t.is_null())
41 dict->SetReal(keys::kDateGroupModifiedKey, floor(t.ToDoubleT() * 1000)); 42 dict->SetReal(keys::kDateGroupModifiedKey, floor(t.ToDoubleT() * 1000));
42 } 43 }
(...skipping 18 matching lines...) Expand all
61 } 62 }
62 return dict; 63 return dict;
63 } 64 }
64 65
65 // Add a JSON representation of |node| to the JSON |list|. 66 // Add a JSON representation of |node| to the JSON |list|.
66 static void AddNode(const BookmarkNode* node, ListValue* list, bool recurse) { 67 static void AddNode(const BookmarkNode* node, ListValue* list, bool recurse) {
67 DictionaryValue* dict = GetNodeDictionary(node, recurse); 68 DictionaryValue* dict = GetNodeDictionary(node, recurse);
68 list->Append(dict); 69 list->Append(dict);
69 } 70 }
70 71
71 static bool RemoveNode(BookmarkModel* model, int id, bool recursive, 72 static bool RemoveNode(BookmarkModel* model, int64 id, bool recursive,
72 std::string* error) { 73 std::string* error) {
73 const BookmarkNode* node = model->GetNodeByID(id); 74 const BookmarkNode* node = model->GetNodeByID(id);
74 if (!node) { 75 if (!node) {
75 *error = keys::kNoNodeError; 76 *error = keys::kNoNodeError;
76 return false; 77 return false;
77 } 78 }
78 if (node == model->root_node() || 79 if (node == model->root_node() ||
79 node == model->other_node() || 80 node == model->other_node() ||
80 node == model->GetBookmarkBarNode()) { 81 node == model->GetBookmarkBarNode()) {
81 *error = keys::kModifySpecialError; 82 *error = keys::kModifySpecialError;
(...skipping 25 matching lines...) Expand all
107 AddRef(); // Balanced in Observe(). 108 AddRef(); // Balanced in Observe().
108 return; 109 return;
109 } 110 }
110 111
111 ExtensionBookmarkEventRouter* event_router = 112 ExtensionBookmarkEventRouter* event_router =
112 ExtensionBookmarkEventRouter::GetSingleton(); 113 ExtensionBookmarkEventRouter::GetSingleton();
113 event_router->Observe(model); 114 event_router->Observe(model);
114 SendResponse(RunImpl()); 115 SendResponse(RunImpl());
115 } 116 }
116 117
118 bool BookmarksFunction::GetBookmarkIdAsInt64(
119 const std::string& id_string, int64* id) {
120 if (StringToInt64(id_string, id))
121 return true;
122
123 error_ = keys::kInvalidIdError;
124 return false;
125 }
126
117 void BookmarksFunction::Observe(NotificationType type, 127 void BookmarksFunction::Observe(NotificationType type,
118 const NotificationSource& source, 128 const NotificationSource& source,
119 const NotificationDetails& details) { 129 const NotificationDetails& details) {
120 DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED); 130 DCHECK(type == NotificationType::BOOKMARK_MODEL_LOADED);
121 DCHECK(profile()->GetBookmarkModel()->IsLoaded()); 131 DCHECK(profile()->GetBookmarkModel()->IsLoaded());
122 Run(); 132 Run();
123 Release(); // Balanced in Run(). 133 Release(); // Balanced in Run().
124 } 134 }
125 135
126 // static 136 // static
(...skipping 27 matching lines...) Expand all
154 } 164 }
155 165
156 void ExtensionBookmarkEventRouter::BookmarkNodeMoved( 166 void ExtensionBookmarkEventRouter::BookmarkNodeMoved(
157 BookmarkModel* model, 167 BookmarkModel* model,
158 const BookmarkNode* old_parent, 168 const BookmarkNode* old_parent,
159 int old_index, 169 int old_index,
160 const BookmarkNode* new_parent, 170 const BookmarkNode* new_parent,
161 int new_index) { 171 int new_index) {
162 ListValue args; 172 ListValue args;
163 const BookmarkNode* node = new_parent->GetChild(new_index); 173 const BookmarkNode* node = new_parent->GetChild(new_index);
164 args.Append(new FundamentalValue(node->id())); 174 args.Append(new StringValue(Int64ToString(node->id())));
165 DictionaryValue* object_args = new DictionaryValue(); 175 DictionaryValue* object_args = new DictionaryValue();
166 object_args->SetInteger(keys::kParentIdKey, new_parent->id()); 176 object_args->SetString(keys::kParentIdKey, Int64ToString(new_parent->id()));
167 object_args->SetInteger(keys::kIndexKey, new_index); 177 object_args->SetInteger(keys::kIndexKey, new_index);
168 object_args->SetInteger(keys::kOldParentIdKey, old_parent->id()); 178 object_args->SetString(keys::kOldParentIdKey,
179 Int64ToString(old_parent->id()));
169 object_args->SetInteger(keys::kOldIndexKey, old_index); 180 object_args->SetInteger(keys::kOldIndexKey, old_index);
170 args.Append(object_args); 181 args.Append(object_args);
171 182
172 std::string json_args; 183 std::string json_args;
173 JSONWriter::Write(&args, false, &json_args); 184 JSONWriter::Write(&args, false, &json_args);
174 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args); 185 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args);
175 } 186 }
176 187
177 void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model, 188 void ExtensionBookmarkEventRouter::BookmarkNodeAdded(BookmarkModel* model,
178 const BookmarkNode* parent, 189 const BookmarkNode* parent,
179 int index) { 190 int index) {
180 ListValue args; 191 ListValue args;
181 const BookmarkNode* node = parent->GetChild(index); 192 const BookmarkNode* node = parent->GetChild(index);
182 args.Append(new FundamentalValue(node->id())); 193 args.Append(new StringValue(Int64ToString(node->id())));
183 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); 194 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false);
184 195
185 // Remove id since it's already being passed as the first argument. 196 // Remove id since it's already being passed as the first argument.
186 obj->Remove(keys::kIdKey, NULL); 197 obj->Remove(keys::kIdKey, NULL);
187 args.Append(obj); 198 args.Append(obj);
188 199
189 std::string json_args; 200 std::string json_args;
190 JSONWriter::Write(&args, false, &json_args); 201 JSONWriter::Write(&args, false, &json_args);
191 DispatchEvent(model->profile(), keys::kOnBookmarkAdded, json_args); 202 DispatchEvent(model->profile(), keys::kOnBookmarkAdded, json_args);
192 } 203 }
193 204
194 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( 205 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved(
195 BookmarkModel* model, 206 BookmarkModel* model,
196 const BookmarkNode* parent, 207 const BookmarkNode* parent,
197 int index) { 208 int index) {
198 // TODO(erikkay) can this version ever be called? 209 // TODO(erikkay) can this version ever be called?
199 NOTREACHED(); 210 NOTREACHED();
200 } 211 }
201 212
202 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( 213 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved(
203 BookmarkModel* model, 214 BookmarkModel* model,
204 const BookmarkNode* parent, 215 const BookmarkNode* parent,
205 int index, 216 int index,
206 const BookmarkNode* node) { 217 const BookmarkNode* node) {
207 ListValue args; 218 ListValue args;
208 args.Append(new FundamentalValue(node->id())); 219 args.Append(new StringValue(Int64ToString(node->id())));
209 DictionaryValue* object_args = new DictionaryValue(); 220 DictionaryValue* object_args = new DictionaryValue();
210 object_args->SetInteger(keys::kParentIdKey, parent->id()); 221 object_args->SetString(keys::kParentIdKey, Int64ToString(parent->id()));
211 object_args->SetInteger(keys::kIndexKey, index); 222 object_args->SetInteger(keys::kIndexKey, index);
212 args.Append(object_args); 223 args.Append(object_args);
213 224
214 std::string json_args; 225 std::string json_args;
215 JSONWriter::Write(&args, false, &json_args); 226 JSONWriter::Write(&args, false, &json_args);
216 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); 227 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args);
217 } 228 }
218 229
219 void ExtensionBookmarkEventRouter::BookmarkNodeChanged( 230 void ExtensionBookmarkEventRouter::BookmarkNodeChanged(
220 BookmarkModel* model, const BookmarkNode* node) { 231 BookmarkModel* model, const BookmarkNode* node) {
221 ListValue args; 232 ListValue args;
222 args.Append(new FundamentalValue(node->id())); 233 args.Append(new StringValue(Int64ToString(node->id())));
223 234
224 // TODO(erikkay) The only two things that BookmarkModel sends this 235 // TODO(erikkay) The only two things that BookmarkModel sends this
225 // notification for are title and favicon. Since we're currently ignoring 236 // notification for are title and favicon. Since we're currently ignoring
226 // favicon and since the notification doesn't say which one anyway, for now 237 // favicon and since the notification doesn't say which one anyway, for now
227 // we only include title. The ideal thing would be to change BookmarkModel 238 // we only include title. The ideal thing would be to change BookmarkModel
228 // to indicate what changed. 239 // to indicate what changed.
229 DictionaryValue* object_args = new DictionaryValue(); 240 DictionaryValue* object_args = new DictionaryValue();
230 object_args->SetString(keys::kTitleKey, node->GetTitle()); 241 object_args->SetString(keys::kTitleKey, node->GetTitle());
231 args.Append(object_args); 242 args.Append(object_args);
232 243
233 std::string json_args; 244 std::string json_args;
234 JSONWriter::Write(&args, false, &json_args); 245 JSONWriter::Write(&args, false, &json_args);
235 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); 246 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args);
236 } 247 }
237 248
238 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( 249 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded(
239 BookmarkModel* model, const BookmarkNode* node) { 250 BookmarkModel* model, const BookmarkNode* node) {
240 // TODO(erikkay) anything we should do here? 251 // TODO(erikkay) anything we should do here?
241 } 252 }
242 253
243 void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered( 254 void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered(
244 BookmarkModel* model, const BookmarkNode* node) { 255 BookmarkModel* model, const BookmarkNode* node) {
245 ListValue args; 256 ListValue args;
246 args.Append(new FundamentalValue(node->id())); 257 args.Append(new StringValue(Int64ToString(node->id())));
247 int childCount = node->GetChildCount(); 258 int childCount = node->GetChildCount();
248 ListValue* children = new ListValue(); 259 ListValue* children = new ListValue();
249 for (int i = 0; i < childCount; ++i) { 260 for (int i = 0; i < childCount; ++i) {
250 const BookmarkNode* child = node->GetChild(i); 261 const BookmarkNode* child = node->GetChild(i);
251 Value* child_id = new FundamentalValue(child->id()); 262 Value* child_id = new StringValue(Int64ToString(child->id()));
252 children->Append(child_id); 263 children->Append(child_id);
253 } 264 }
254 args.Append(children); 265 args.Append(children);
255 266
256 std::string json_args; 267 std::string json_args;
257 JSONWriter::Write(&args, false, &json_args); 268 JSONWriter::Write(&args, false, &json_args);
258 DispatchEvent(model->profile(), 269 DispatchEvent(model->profile(),
259 keys::kOnBookmarkChildrenReordered, 270 keys::kOnBookmarkChildrenReordered,
260 json_args); 271 json_args);
261 } 272 }
262 273
263 bool GetBookmarksFunction::RunImpl() { 274 bool GetBookmarksFunction::RunImpl() {
264 BookmarkModel* model = profile()->GetBookmarkModel(); 275 BookmarkModel* model = profile()->GetBookmarkModel();
265 scoped_ptr<ListValue> json(new ListValue()); 276 scoped_ptr<ListValue> json(new ListValue());
266 if (args_->IsType(Value::TYPE_LIST)) { 277 if (args_->IsType(Value::TYPE_LIST)) {
267 ListValue* ids = static_cast<ListValue*>(args_); 278 ListValue* ids = static_cast<ListValue*>(args_);
268 size_t count = ids->GetSize(); 279 size_t count = ids->GetSize();
269 EXTENSION_FUNCTION_VALIDATE(count > 0); 280 EXTENSION_FUNCTION_VALIDATE(count > 0);
270 for (size_t i = 0; i < count; ++i) { 281 for (size_t i = 0; i < count; ++i) {
271 int id = 0; 282 int64 id;
272 EXTENSION_FUNCTION_VALIDATE(ids->GetInteger(i, &id)); 283 std::string id_string;
284 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
285 if (!GetBookmarkIdAsInt64(id_string, &id))
286 return false;
273 const BookmarkNode* node = model->GetNodeByID(id); 287 const BookmarkNode* node = model->GetNodeByID(id);
274 if (!node) { 288 if (!node) {
275 error_ = keys::kNoNodeError; 289 error_ = keys::kNoNodeError;
276 return false; 290 return false;
277 } else { 291 } else {
278 ExtensionBookmarks::AddNode(node, json.get(), false); 292 ExtensionBookmarks::AddNode(node, json.get(), false);
279 } 293 }
280 } 294 }
281 } else { 295 } else {
282 int id; 296 int64 id;
283 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id)); 297 std::string id_string;
298 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
299 if (!GetBookmarkIdAsInt64(id_string, &id))
300 return false;
284 const BookmarkNode* node = model->GetNodeByID(id); 301 const BookmarkNode* node = model->GetNodeByID(id);
285 if (!node) { 302 if (!node) {
286 error_ = keys::kNoNodeError; 303 error_ = keys::kNoNodeError;
287 return false; 304 return false;
288 } 305 }
289 ExtensionBookmarks::AddNode(node, json.get(), false); 306 ExtensionBookmarks::AddNode(node, json.get(), false);
290 } 307 }
291 308
292 result_.reset(json.release()); 309 result_.reset(json.release());
293 return true; 310 return true;
294 } 311 }
295 312
296 bool GetBookmarkChildrenFunction::RunImpl() { 313 bool GetBookmarkChildrenFunction::RunImpl() {
297 BookmarkModel* model = profile()->GetBookmarkModel(); 314 BookmarkModel* model = profile()->GetBookmarkModel();
298 int id; 315 int64 id;
299 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id)); 316 std::string id_string;
317 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
318 if (!GetBookmarkIdAsInt64(id_string, &id))
319 return false;
300 scoped_ptr<ListValue> json(new ListValue()); 320 scoped_ptr<ListValue> json(new ListValue());
301 const BookmarkNode* node = model->GetNodeByID(id); 321 const BookmarkNode* node = model->GetNodeByID(id);
302 if (!node) { 322 if (!node) {
303 error_ = keys::kNoNodeError; 323 error_ = keys::kNoNodeError;
304 return false; 324 return false;
305 } 325 }
306 int child_count = node->GetChildCount(); 326 int child_count = node->GetChildCount();
307 for (int i = 0; i < child_count; ++i) { 327 for (int i = 0; i < child_count; ++i) {
308 const BookmarkNode* child = node->GetChild(i); 328 const BookmarkNode* child = node->GetChild(i);
309 ExtensionBookmarks::AddNode(child, json.get(), false); 329 ExtensionBookmarks::AddNode(child, json.get(), false);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return true; 363 return true;
344 } 364 }
345 365
346 bool RemoveBookmarkFunction::RunImpl() { 366 bool RemoveBookmarkFunction::RunImpl() {
347 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); 367 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
348 const ListValue* args = static_cast<const ListValue*>(args_); 368 const ListValue* args = static_cast<const ListValue*>(args_);
349 bool recursive = false; 369 bool recursive = false;
350 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(1, &recursive)); 370 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(1, &recursive));
351 371
352 BookmarkModel* model = profile()->GetBookmarkModel(); 372 BookmarkModel* model = profile()->GetBookmarkModel();
353 int id; 373 int64 id;
354 if (args->GetInteger(0, &id)) { 374 std::string id_string;
375 if (args->GetString(0, &id_string) && StringToInt64(id_string, &id)) {
355 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_); 376 return ExtensionBookmarks::RemoveNode(model, id, recursive, &error_);
356 } else { 377 } else {
357 ListValue* ids; 378 ListValue* ids;
358 EXTENSION_FUNCTION_VALIDATE(args->GetList(0, &ids)); 379 EXTENSION_FUNCTION_VALIDATE(args->GetList(0, &ids));
359 size_t count = ids->GetSize(); 380 size_t count = ids->GetSize();
360 EXTENSION_FUNCTION_VALIDATE(count > 0); 381 EXTENSION_FUNCTION_VALIDATE(count > 0);
361 for (size_t i = 0; i < count; ++i) { 382 for (size_t i = 0; i < count; ++i) {
362 EXTENSION_FUNCTION_VALIDATE(ids->GetInteger(i, &id)); 383 EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
384 if (!GetBookmarkIdAsInt64(id_string, &id))
385 return false;
363 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_)) 386 if (!ExtensionBookmarks::RemoveNode(model, id, recursive, &error_))
364 return false; 387 return false;
365 } 388 }
366 return true; 389 return true;
367 } 390 }
368 } 391 }
369 392
370 bool CreateBookmarkFunction::RunImpl() { 393 bool CreateBookmarkFunction::RunImpl() {
371 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); 394 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
372 DictionaryValue* json = static_cast<DictionaryValue*>(args_); 395 DictionaryValue* json = static_cast<DictionaryValue*>(args_);
373 396
374 BookmarkModel* model = profile()->GetBookmarkModel(); 397 BookmarkModel* model = profile()->GetBookmarkModel();
375 int parentId; 398 int64 parentId;
376 if (!json->HasKey(keys::kParentIdKey)) { 399 if (!json->HasKey(keys::kParentIdKey)) {
377 // Optional, default to "other bookmarks". 400 // Optional, default to "other bookmarks".
378 parentId = model->other_node()->id(); 401 parentId = model->other_node()->id();
379 } else { 402 } else {
380 EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kParentIdKey, 403 std::string parentId_string;
381 &parentId)); 404 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kParentIdKey,
405 &parentId_string));
406 if (!GetBookmarkIdAsInt64(parentId_string, &parentId))
407 return false;
382 } 408 }
383 const BookmarkNode* parent = model->GetNodeByID(parentId); 409 const BookmarkNode* parent = model->GetNodeByID(parentId);
384 if (!parent) { 410 if (!parent) {
385 error_ = keys::kNoParentError; 411 error_ = keys::kNoParentError;
386 return false; 412 return false;
387 } 413 }
388 if (parent->GetParent() == NULL) { // Can't create children of the root. 414 if (parent->GetParent() == NULL) { // Can't create children of the root.
389 error_ = keys::kNoParentError; 415 error_ = keys::kNoParentError;
390 return false; 416 return false;
391 } 417 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 450
425 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); 451 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
426 result_.reset(ret); 452 result_.reset(ret);
427 453
428 return true; 454 return true;
429 } 455 }
430 456
431 bool MoveBookmarkFunction::RunImpl() { 457 bool MoveBookmarkFunction::RunImpl() {
432 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); 458 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
433 const ListValue* args = static_cast<const ListValue*>(args_); 459 const ListValue* args = static_cast<const ListValue*>(args_);
434 int id; 460 int64 id;
435 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &id)); 461 std::string id_string;
462 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string));
463 if (!GetBookmarkIdAsInt64(id_string, &id))
464 return false;
436 DictionaryValue* destination; 465 DictionaryValue* destination;
437 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination)); 466 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination));
438 467
439 BookmarkModel* model = profile()->GetBookmarkModel(); 468 BookmarkModel* model = profile()->GetBookmarkModel();
440 const BookmarkNode* node = model->GetNodeByID(id); 469 const BookmarkNode* node = model->GetNodeByID(id);
441 if (!node) { 470 if (!node) {
442 error_ = keys::kNoNodeError; 471 error_ = keys::kNoNodeError;
443 return false; 472 return false;
444 } 473 }
445 if (node == model->root_node() || 474 if (node == model->root_node() ||
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 515 }
487 516
488 bool SetBookmarkTitleFunction::RunImpl() { 517 bool SetBookmarkTitleFunction::RunImpl() {
489 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); 518 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
490 DictionaryValue* json = static_cast<DictionaryValue*>(args_); 519 DictionaryValue* json = static_cast<DictionaryValue*>(args_);
491 520
492 std::wstring title; 521 std::wstring title;
493 json->GetString(keys::kTitleKey, &title); // Optional (empty is clear). 522 json->GetString(keys::kTitleKey, &title); // Optional (empty is clear).
494 523
495 BookmarkModel* model = profile()->GetBookmarkModel(); 524 BookmarkModel* model = profile()->GetBookmarkModel();
496 int id = 0; 525 int64 id = 0;
497 EXTENSION_FUNCTION_VALIDATE(json->GetInteger(keys::kIdKey, &id)); 526 std::string id_string;
527 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kIdKey, &id_string));
528 if (!GetBookmarkIdAsInt64(id_string, &id))
529 return false;
498 const BookmarkNode* node = model->GetNodeByID(id); 530 const BookmarkNode* node = model->GetNodeByID(id);
499 if (!node) { 531 if (!node) {
500 error_ = keys::kNoNodeError; 532 error_ = keys::kNoNodeError;
501 return false; 533 return false;
502 } 534 }
503 if (node == model->root_node() || 535 if (node == model->root_node() ||
504 node == model->other_node() || 536 node == model->other_node() ||
505 node == model->GetBookmarkBarNode()) { 537 node == model->GetBookmarkBarNode()) {
506 error_ = keys::kModifySpecialError; 538 error_ = keys::kModifySpecialError;
507 return false; 539 return false;
508 } 540 }
509 model->SetTitle(node, title); 541 model->SetTitle(node, title);
510 return true; 542 return true;
511 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698