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/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 std::string json_args; | 231 std::string json_args; |
232 base::JSONWriter::Write(&args, false, &json_args); | 232 base::JSONWriter::Write(&args, false, &json_args); |
233 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); | 233 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); |
234 } | 234 } |
235 | 235 |
236 void ExtensionBookmarkEventRouter::BookmarkNodeChanged( | 236 void ExtensionBookmarkEventRouter::BookmarkNodeChanged( |
237 BookmarkModel* model, const BookmarkNode* node) { | 237 BookmarkModel* model, const BookmarkNode* node) { |
238 ListValue args; | 238 ListValue args; |
239 args.Append(new StringValue(Int64ToString(node->id()))); | 239 args.Append(new StringValue(Int64ToString(node->id()))); |
240 | 240 |
241 // TODO(erikkay) The only two things that BookmarkModel sends this | 241 // TODO(erikkay) The only three things that BookmarkModel sends this |
242 // notification for are title and favicon. Since we're currently ignoring | 242 // notification for are title, url and favicon. Since we're currently |
243 // favicon and since the notification doesn't say which one anyway, for now | 243 // ignoring favicon and since the notification doesn't say which one anyway, |
244 // we only include title. The ideal thing would be to change BookmarkModel | 244 // for now we only include title and url. The ideal thing would be to change |
245 // to indicate what changed. | 245 // BookmarkModel to indicate what changed. |
246 DictionaryValue* object_args = new DictionaryValue(); | 246 DictionaryValue* object_args = new DictionaryValue(); |
247 object_args->SetString(keys::kTitleKey, node->GetTitle()); | 247 object_args->SetString(keys::kTitleKey, node->GetTitle()); |
| 248 if (node->is_url()) |
| 249 object_args->SetString(keys::kUrlKey, node->GetURL().spec()); |
248 args.Append(object_args); | 250 args.Append(object_args); |
249 | 251 |
250 std::string json_args; | 252 std::string json_args; |
251 base::JSONWriter::Write(&args, false, &json_args); | 253 base::JSONWriter::Write(&args, false, &json_args); |
252 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); | 254 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); |
253 } | 255 } |
254 | 256 |
255 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( | 257 void ExtensionBookmarkEventRouter::BookmarkNodeFavIconLoaded( |
256 BookmarkModel* model, const BookmarkNode* node) { | 258 BookmarkModel* model, const BookmarkNode* node) { |
257 // TODO(erikkay) anything we should do here? | 259 // TODO(erikkay) anything we should do here? |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id)); | 634 EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id)); |
633 if (invalid_id) { | 635 if (invalid_id) { |
634 error_ = keys::kInvalidIdError; | 636 error_ = keys::kInvalidIdError; |
635 return false; | 637 return false; |
636 } | 638 } |
637 EXTENSION_FUNCTION_VALIDATE(ids.size() == 1); | 639 EXTENSION_FUNCTION_VALIDATE(ids.size() == 1); |
638 | 640 |
639 const ListValue* args = args_as_list(); | 641 const ListValue* args = args_as_list(); |
640 DictionaryValue* updates; | 642 DictionaryValue* updates; |
641 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates)); | 643 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates)); |
| 644 |
642 std::wstring title; | 645 std::wstring title; |
643 updates->GetString(keys::kTitleKey, &title); // Optional (empty is clear). | 646 std::string url_string; |
| 647 |
| 648 // Optional but we need to distinguish non present from an empty title. |
| 649 const bool has_title = updates->GetString(keys::kTitleKey, &title); |
| 650 updates->GetString(keys::kUrlKey, &url_string); // Optional. |
| 651 |
| 652 GURL url; |
| 653 if (!url_string.empty()) { |
| 654 url = GURL(url_string); |
| 655 |
| 656 // If URL is present then it needs to be a non empty valid URL. |
| 657 EXTENSION_FUNCTION_VALIDATE(!url.is_empty()); |
| 658 EXTENSION_FUNCTION_VALIDATE(url.is_valid()); |
| 659 } |
644 | 660 |
645 BookmarkModel* model = profile()->GetBookmarkModel(); | 661 BookmarkModel* model = profile()->GetBookmarkModel(); |
646 const BookmarkNode* node = model->GetNodeByID(ids.front()); | 662 const BookmarkNode* node = model->GetNodeByID(ids.front()); |
647 if (!node) { | 663 if (!node) { |
648 error_ = keys::kNoNodeError; | 664 error_ = keys::kNoNodeError; |
649 return false; | 665 return false; |
650 } | 666 } |
651 if (node == model->root_node() || | 667 if (node == model->root_node() || |
652 node == model->other_node() || | 668 node == model->other_node() || |
653 node == model->GetBookmarkBarNode()) { | 669 node == model->GetBookmarkBarNode()) { |
654 error_ = keys::kModifySpecialError; | 670 error_ = keys::kModifySpecialError; |
655 return false; | 671 return false; |
656 } | 672 } |
657 model->SetTitle(node, title); | 673 if (has_title) |
| 674 model->SetTitle(node, title); |
| 675 if (!url.is_empty()) |
| 676 model->SetURL(node, url); |
658 | 677 |
659 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); | 678 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false); |
660 result_.reset(ret); | 679 result_.reset(ret); |
661 | 680 |
662 return true; | 681 return true; |
663 } | 682 } |
664 | 683 |
665 // Mapper superclass for BookmarkFunctions. | 684 // Mapper superclass for BookmarkFunctions. |
666 template <typename BucketIdType> | 685 template <typename BucketIdType> |
667 class BookmarkBucketMapper : public BucketMapper { | 686 class BookmarkBucketMapper : public BucketMapper { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 850 |
832 void UpdateBookmarkFunction::GetQuotaLimitHeuristics( | 851 void UpdateBookmarkFunction::GetQuotaLimitHeuristics( |
833 QuotaLimitHeuristics* heuristics) const { | 852 QuotaLimitHeuristics* heuristics) const { |
834 BookmarksQuotaLimitFactory::Build<UpdateBookmarkFunction>(heuristics); | 853 BookmarksQuotaLimitFactory::Build<UpdateBookmarkFunction>(heuristics); |
835 }; | 854 }; |
836 | 855 |
837 void CreateBookmarkFunction::GetQuotaLimitHeuristics( | 856 void CreateBookmarkFunction::GetQuotaLimitHeuristics( |
838 QuotaLimitHeuristics* heuristics) const { | 857 QuotaLimitHeuristics* heuristics) const { |
839 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, profile()); | 858 BookmarksQuotaLimitFactory::BuildForCreate(heuristics, profile()); |
840 } | 859 } |
OLD | NEW |