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

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

Issue 3672003: fix bookmarks API crash when handling invalid URL (Closed)
Patch Set: missing semicolon Created 10 years, 2 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/string16.h" 10 #include "base/string16.h"
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id)); 538 EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id));
539 if (invalid_id) { 539 if (invalid_id) {
540 error_ = keys::kInvalidIdError; 540 error_ = keys::kInvalidIdError;
541 return false; 541 return false;
542 } 542 }
543 EXTENSION_FUNCTION_VALIDATE(ids.size() == 1); 543 EXTENSION_FUNCTION_VALIDATE(ids.size() == 1);
544 544
545 DictionaryValue* updates; 545 DictionaryValue* updates;
546 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &updates)); 546 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &updates));
547 547
548 // Optional but we need to distinguish non present from an empty title.
548 string16 title; 549 string16 title;
550 const bool has_title = updates->GetString(keys::kTitleKey, &title);
551
552 // Optional.
549 std::string url_string; 553 std::string url_string;
550 554 updates->GetString(keys::kUrlKey, &url_string);
551 // Optional but we need to distinguish non present from an empty title. 555 GURL url(url_string);
552 const bool has_title = updates->GetString(keys::kTitleKey, &title); 556 if (!url_string.empty() && !url.is_valid()) {
553 updates->GetString(keys::kUrlKey, &url_string); // Optional. 557 error_ = keys::kInvalidUrlError;
554 558 return false;
555 GURL url;
556 if (!url_string.empty()) {
557 url = GURL(url_string);
558
559 // If URL is present then it needs to be a non empty valid URL.
560 EXTENSION_FUNCTION_VALIDATE(!url.is_empty());
561 EXTENSION_FUNCTION_VALIDATE(url.is_valid());
562 } 559 }
563 560
564 BookmarkModel* model = profile()->GetBookmarkModel(); 561 BookmarkModel* model = profile()->GetBookmarkModel();
565 const BookmarkNode* node = model->GetNodeByID(ids.front()); 562 const BookmarkNode* node = model->GetNodeByID(ids.front());
566 if (!node) { 563 if (!node) {
567 error_ = keys::kNoNodeError; 564 error_ = keys::kNoNodeError;
568 return false; 565 return false;
569 } 566 }
570 if (node == model->root_node() || 567 if (node == model->root_node() ||
571 node == model->other_node() || 568 node == model->other_node() ||
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE); 815 SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE);
819 return true; 816 return true;
820 } 817 }
821 818
822 void ExportBookmarksFunction::FileSelected(const FilePath& path, 819 void ExportBookmarksFunction::FileSelected(const FilePath& path,
823 int index, 820 int index,
824 void* params) { 821 void* params) {
825 bookmark_html_writer::WriteBookmarks(profile(), path, NULL); 822 bookmark_html_writer::WriteBookmarks(profile(), path, NULL);
826 Release(); // Balanced in BookmarksIOFunction::SelectFile() 823 Release(); // Balanced in BookmarksIOFunction::SelectFile()
827 } 824 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_bookmarks_apitest.cc ('k') | chrome/renderer/resources/extension_apitest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698