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_extension_api.h" | 5 #include "chrome/browser/bookmarks/bookmark_extension_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/i18n/file_util_icu.h" | 9 #include "base/i18n/file_util_icu.h" |
10 #include "base/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 DictionaryValue* object_args = new DictionaryValue(); | 173 DictionaryValue* object_args = new DictionaryValue(); |
174 object_args->SetString(keys::kParentIdKey, | 174 object_args->SetString(keys::kParentIdKey, |
175 base::Int64ToString(new_parent->id())); | 175 base::Int64ToString(new_parent->id())); |
176 object_args->SetInteger(keys::kIndexKey, new_index); | 176 object_args->SetInteger(keys::kIndexKey, new_index); |
177 object_args->SetString(keys::kOldParentIdKey, | 177 object_args->SetString(keys::kOldParentIdKey, |
178 base::Int64ToString(old_parent->id())); | 178 base::Int64ToString(old_parent->id())); |
179 object_args->SetInteger(keys::kOldIndexKey, old_index); | 179 object_args->SetInteger(keys::kOldIndexKey, old_index); |
180 args.Append(object_args); | 180 args.Append(object_args); |
181 | 181 |
182 std::string json_args; | 182 std::string json_args; |
183 base::JSONWriter::Write(&args, false, &json_args); | 183 base::JSONWriter::Write(&args, &json_args); |
184 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args); | 184 DispatchEvent(model->profile(), keys::kOnBookmarkMoved, json_args); |
185 } | 185 } |
186 | 186 |
187 void BookmarkExtensionEventRouter::BookmarkNodeAdded(BookmarkModel* model, | 187 void BookmarkExtensionEventRouter::BookmarkNodeAdded(BookmarkModel* model, |
188 const BookmarkNode* parent, | 188 const BookmarkNode* parent, |
189 int index) { | 189 int index) { |
190 ListValue args; | 190 ListValue args; |
191 const BookmarkNode* node = parent->GetChild(index); | 191 const BookmarkNode* node = parent->GetChild(index); |
192 args.Append(new StringValue(base::Int64ToString(node->id()))); | 192 args.Append(new StringValue(base::Int64ToString(node->id()))); |
193 DictionaryValue* obj = | 193 DictionaryValue* obj = |
194 bookmark_extension_helpers::GetNodeDictionary(node, false, false); | 194 bookmark_extension_helpers::GetNodeDictionary(node, false, false); |
195 args.Append(obj); | 195 args.Append(obj); |
196 | 196 |
197 std::string json_args; | 197 std::string json_args; |
198 base::JSONWriter::Write(&args, false, &json_args); | 198 base::JSONWriter::Write(&args, &json_args); |
199 DispatchEvent(model->profile(), keys::kOnBookmarkCreated, json_args); | 199 DispatchEvent(model->profile(), keys::kOnBookmarkCreated, json_args); |
200 } | 200 } |
201 | 201 |
202 void BookmarkExtensionEventRouter::BookmarkNodeRemoved( | 202 void BookmarkExtensionEventRouter::BookmarkNodeRemoved( |
203 BookmarkModel* model, | 203 BookmarkModel* model, |
204 const BookmarkNode* parent, | 204 const BookmarkNode* parent, |
205 int index, | 205 int index, |
206 const BookmarkNode* node) { | 206 const BookmarkNode* node) { |
207 ListValue args; | 207 ListValue args; |
208 args.Append(new StringValue(base::Int64ToString(node->id()))); | 208 args.Append(new StringValue(base::Int64ToString(node->id()))); |
209 DictionaryValue* object_args = new DictionaryValue(); | 209 DictionaryValue* object_args = new DictionaryValue(); |
210 object_args->SetString(keys::kParentIdKey, | 210 object_args->SetString(keys::kParentIdKey, |
211 base::Int64ToString(parent->id())); | 211 base::Int64ToString(parent->id())); |
212 object_args->SetInteger(keys::kIndexKey, index); | 212 object_args->SetInteger(keys::kIndexKey, index); |
213 args.Append(object_args); | 213 args.Append(object_args); |
214 | 214 |
215 std::string json_args; | 215 std::string json_args; |
216 base::JSONWriter::Write(&args, false, &json_args); | 216 base::JSONWriter::Write(&args, &json_args); |
217 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); | 217 DispatchEvent(model->profile(), keys::kOnBookmarkRemoved, json_args); |
218 } | 218 } |
219 | 219 |
220 void BookmarkExtensionEventRouter::BookmarkNodeChanged( | 220 void BookmarkExtensionEventRouter::BookmarkNodeChanged( |
221 BookmarkModel* model, const BookmarkNode* node) { | 221 BookmarkModel* model, const BookmarkNode* node) { |
222 ListValue args; | 222 ListValue args; |
223 args.Append(new StringValue(base::Int64ToString(node->id()))); | 223 args.Append(new StringValue(base::Int64ToString(node->id()))); |
224 | 224 |
225 // TODO(erikkay) The only three things that BookmarkModel sends this | 225 // TODO(erikkay) The only three things that BookmarkModel sends this |
226 // notification for are title, url and favicon. Since we're currently | 226 // notification for are title, url and favicon. Since we're currently |
227 // ignoring favicon and since the notification doesn't say which one anyway, | 227 // ignoring favicon and since the notification doesn't say which one anyway, |
228 // for now we only include title and url. The ideal thing would be to change | 228 // for now we only include title and url. The ideal thing would be to change |
229 // BookmarkModel to indicate what changed. | 229 // BookmarkModel to indicate what changed. |
230 DictionaryValue* object_args = new DictionaryValue(); | 230 DictionaryValue* object_args = new DictionaryValue(); |
231 object_args->SetString(keys::kTitleKey, node->GetTitle()); | 231 object_args->SetString(keys::kTitleKey, node->GetTitle()); |
232 if (node->is_url()) | 232 if (node->is_url()) |
233 object_args->SetString(keys::kUrlKey, node->url().spec()); | 233 object_args->SetString(keys::kUrlKey, node->url().spec()); |
234 args.Append(object_args); | 234 args.Append(object_args); |
235 | 235 |
236 std::string json_args; | 236 std::string json_args; |
237 base::JSONWriter::Write(&args, false, &json_args); | 237 base::JSONWriter::Write(&args, &json_args); |
238 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); | 238 DispatchEvent(model->profile(), keys::kOnBookmarkChanged, json_args); |
239 } | 239 } |
240 | 240 |
241 void BookmarkExtensionEventRouter::BookmarkNodeFaviconChanged( | 241 void BookmarkExtensionEventRouter::BookmarkNodeFaviconChanged( |
242 BookmarkModel* model, const BookmarkNode* node) { | 242 BookmarkModel* model, const BookmarkNode* node) { |
243 // TODO(erikkay) anything we should do here? | 243 // TODO(erikkay) anything we should do here? |
244 } | 244 } |
245 | 245 |
246 void BookmarkExtensionEventRouter::BookmarkNodeChildrenReordered( | 246 void BookmarkExtensionEventRouter::BookmarkNodeChildrenReordered( |
247 BookmarkModel* model, const BookmarkNode* node) { | 247 BookmarkModel* model, const BookmarkNode* node) { |
248 ListValue args; | 248 ListValue args; |
249 args.Append(new StringValue(base::Int64ToString(node->id()))); | 249 args.Append(new StringValue(base::Int64ToString(node->id()))); |
250 int childCount = node->child_count(); | 250 int childCount = node->child_count(); |
251 ListValue* children = new ListValue(); | 251 ListValue* children = new ListValue(); |
252 for (int i = 0; i < childCount; ++i) { | 252 for (int i = 0; i < childCount; ++i) { |
253 const BookmarkNode* child = node->GetChild(i); | 253 const BookmarkNode* child = node->GetChild(i); |
254 Value* child_id = new StringValue(base::Int64ToString(child->id())); | 254 Value* child_id = new StringValue(base::Int64ToString(child->id())); |
255 children->Append(child_id); | 255 children->Append(child_id); |
256 } | 256 } |
257 DictionaryValue* reorder_info = new DictionaryValue(); | 257 DictionaryValue* reorder_info = new DictionaryValue(); |
258 reorder_info->Set(keys::kChildIdsKey, children); | 258 reorder_info->Set(keys::kChildIdsKey, children); |
259 args.Append(reorder_info); | 259 args.Append(reorder_info); |
260 | 260 |
261 std::string json_args; | 261 std::string json_args; |
262 base::JSONWriter::Write(&args, false, &json_args); | 262 base::JSONWriter::Write(&args, &json_args); |
263 DispatchEvent(model->profile(), | 263 DispatchEvent(model->profile(), |
264 keys::kOnBookmarkChildrenReordered, | 264 keys::kOnBookmarkChildrenReordered, |
265 json_args); | 265 json_args); |
266 } | 266 } |
267 | 267 |
268 void BookmarkExtensionEventRouter:: | 268 void BookmarkExtensionEventRouter:: |
269 ExtensiveBookmarkChangesBeginning(BookmarkModel* model) { | 269 ExtensiveBookmarkChangesBeginning(BookmarkModel* model) { |
270 ListValue args; | 270 ListValue args; |
271 std::string json_args; | 271 std::string json_args; |
272 base::JSONWriter::Write(&args, false, &json_args); | 272 base::JSONWriter::Write(&args, &json_args); |
273 DispatchEvent(model->profile(), | 273 DispatchEvent(model->profile(), |
274 keys::kOnBookmarkImportBegan, | 274 keys::kOnBookmarkImportBegan, |
275 json_args); | 275 json_args); |
276 } | 276 } |
277 | 277 |
278 void BookmarkExtensionEventRouter::ExtensiveBookmarkChangesEnded( | 278 void BookmarkExtensionEventRouter::ExtensiveBookmarkChangesEnded( |
279 BookmarkModel* model) { | 279 BookmarkModel* model) { |
280 ListValue args; | 280 ListValue args; |
281 std::string json_args; | 281 std::string json_args; |
282 base::JSONWriter::Write(&args, false, &json_args); | 282 base::JSONWriter::Write(&args, &json_args); |
283 DispatchEvent(model->profile(), | 283 DispatchEvent(model->profile(), |
284 keys::kOnBookmarkImportEnded, | 284 keys::kOnBookmarkImportEnded, |
285 json_args); | 285 json_args); |
286 } | 286 } |
287 | 287 |
288 bool GetBookmarksFunction::RunImpl() { | 288 bool GetBookmarksFunction::RunImpl() { |
289 BookmarkModel* model = profile()->GetBookmarkModel(); | 289 BookmarkModel* model = profile()->GetBookmarkModel(); |
290 scoped_ptr<ListValue> json(new ListValue()); | 290 scoped_ptr<ListValue> json(new ListValue()); |
291 Value* arg0; | 291 Value* arg0; |
292 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &arg0)); | 292 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &arg0)); |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 int index, | 942 int index, |
943 void* params) { | 943 void* params) { |
944 #if !defined(OS_ANDROID) | 944 #if !defined(OS_ANDROID) |
945 // Android does not have support for the standard exporter. | 945 // Android does not have support for the standard exporter. |
946 // TODO(jgreenwald): remove ifdef once extensions are no longer built on | 946 // TODO(jgreenwald): remove ifdef once extensions are no longer built on |
947 // Android. | 947 // Android. |
948 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); | 948 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); |
949 #endif | 949 #endif |
950 Release(); // Balanced in BookmarksIOFunction::SelectFile() | 950 Release(); // Balanced in BookmarksIOFunction::SelectFile() |
951 } | 951 } |
OLD | NEW |