summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 01:00:29 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 01:00:29 +0000
commit25b77708692187791de1d416b930e36c2a0d6159 (patch)
treefa5e12f08c72c7f17f35d99328943377c4cc085c /chrome/browser/extensions
parent6df35cc27a11d1694e01d83e7c6b3f9d5ee14824 (diff)
downloadchromium_src-25b77708692187791de1d416b930e36c2a0d6159.zip
chromium_src-25b77708692187791de1d416b930e36c2a0d6159.tar.gz
chromium_src-25b77708692187791de1d416b930e36c2a0d6159.tar.bz2
Make it so that chrome.bookmarks.update can update the URL of a bookmark.
This changes the API slightly. Previously, if someone called update with an empty object ({}) it would set the title to "". This was only documented in the code and not on the API page. Now that we support updating both the url and title it seems more reasonable to ignore a missing title. BUG=34841 TEST=browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks Review URL: http://codereview.chromium.org/591006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc
index 33abc39..9385ff1 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module.cc
@@ -238,13 +238,15 @@ void ExtensionBookmarkEventRouter::BookmarkNodeChanged(
ListValue args;
args.Append(new StringValue(Int64ToString(node->id())));
- // TODO(erikkay) The only two things that BookmarkModel sends this
- // notification for are title and favicon. Since we're currently ignoring
- // favicon and since the notification doesn't say which one anyway, for now
- // we only include title. The ideal thing would be to change BookmarkModel
- // to indicate what changed.
+ // TODO(erikkay) The only three things that BookmarkModel sends this
+ // notification for are title, url and favicon. Since we're currently
+ // ignoring favicon and since the notification doesn't say which one anyway,
+ // for now we only include title and url. The ideal thing would be to change
+ // BookmarkModel to indicate what changed.
DictionaryValue* object_args = new DictionaryValue();
object_args->SetString(keys::kTitleKey, node->GetTitle());
+ if (node->is_url())
+ object_args->SetString(keys::kUrlKey, node->GetURL().spec());
args.Append(object_args);
std::string json_args;
@@ -639,8 +641,22 @@ bool UpdateBookmarkFunction::RunImpl() {
const ListValue* args = args_as_list();
DictionaryValue* updates;
EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates));
+
std::wstring title;
- updates->GetString(keys::kTitleKey, &title); // Optional (empty is clear).
+ std::string url_string;
+
+ // Optional but we need to distinguish non present from an empty title.
+ const bool has_title = updates->GetString(keys::kTitleKey, &title);
+ updates->GetString(keys::kUrlKey, &url_string); // Optional.
+
+ GURL url;
+ if (!url_string.empty()) {
+ url = GURL(url_string);
+
+ // If URL is present then it needs to be a non empty valid URL.
+ EXTENSION_FUNCTION_VALIDATE(!url.is_empty());
+ EXTENSION_FUNCTION_VALIDATE(url.is_valid());
+ }
BookmarkModel* model = profile()->GetBookmarkModel();
const BookmarkNode* node = model->GetNodeByID(ids.front());
@@ -654,7 +670,10 @@ bool UpdateBookmarkFunction::RunImpl() {
error_ = keys::kModifySpecialError;
return false;
}
- model->SetTitle(node, title);
+ if (has_title)
+ model->SetTitle(node, title);
+ if (!url.is_empty())
+ model->SetURL(node, url);
DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
result_.reset(ret);