summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 09:57:21 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 09:57:21 +0000
commit9d25f372972dc5ac24028c053e79c42d9df2795d (patch)
treecf1933fb5cb1d4fabe7190d8cc3780e815d1e81f /chrome
parentb4bd05478c5e4475d4cc91d05825094f931799e2 (diff)
downloadchromium_src-9d25f372972dc5ac24028c053e79c42d9df2795d.zip
chromium_src-9d25f372972dc5ac24028c053e79c42d9df2795d.tar.gz
chromium_src-9d25f372972dc5ac24028c053e79c42d9df2795d.tar.bz2
Bookmarks extension API checks if editing is allowed.
BUG=49604 TEST=Set the EditBookmarksEnabled preference to false, and extensions won't be able to modify bookmarks. Review URL: http://codereview.chromium.org/6824083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81389 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.cc13
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_apitest.cc30
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.cc17
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.h4
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module_constants.cc1
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module_constants.h1
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/manifest.json7
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.html (renamed from chrome/test/data/extensions/api_test/bookmark_manager/test.html)0
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.js76
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/standard/manifest.json (renamed from chrome/test/data/extensions/api_test/bookmark_manager/manifest.json)0
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/standard/test.html1
-rw-r--r--chrome/test/data/extensions/api_test/bookmark_manager/standard/test.js (renamed from chrome/test/data/extensions/api_test/bookmark_manager/test.js)0
12 files changed, 149 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc
index 0e0d074..6f23fe8 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc
@@ -224,10 +224,14 @@ bool CopyBookmarkManagerFunction::RunImpl() {
}
bool CutBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
return CopyOrCut(true);
}
bool PasteBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
BookmarkModel* model = profile()->GetBookmarkModel();
const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
if (!parent_node) {
@@ -255,6 +259,8 @@ bool PasteBookmarkManagerFunction::RunImpl() {
}
bool CanPasteBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
BookmarkModel* model = profile()->GetBookmarkModel();
const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
if (!parent_node) {
@@ -268,6 +274,8 @@ bool CanPasteBookmarkManagerFunction::RunImpl() {
}
bool SortChildrenBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
BookmarkModel* model = profile()->GetBookmarkModel();
const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get());
if (!parent_node) {
@@ -350,6 +358,8 @@ bool BookmarkManagerGetStringsFunction::RunImpl() {
}
bool StartDragBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
BookmarkModel* model = profile()->GetBookmarkModel();
std::vector<const BookmarkNode*> nodes;
EXTENSION_FUNCTION_VALIDATE(
@@ -370,6 +380,9 @@ bool StartDragBookmarkManagerFunction::RunImpl() {
}
bool DropBookmarkManagerFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
+
BookmarkModel* model = profile()->GetBookmarkModel();
int64 id;
diff --git a/chrome/browser/extensions/extension_bookmark_manager_apitest.cc b/chrome/browser/extensions/extension_bookmark_manager_apitest.cc
index 27495c1..fc7ea2b 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_apitest.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_apitest.cc
@@ -3,12 +3,40 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/extensions/extension_bookmark_manager_api.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManager) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
- ASSERT_TRUE(RunExtensionTest("bookmark_manager")) << message_;
+ ASSERT_TRUE(RunExtensionTest("bookmark_manager/standard")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BookmarkManagerEditDisabled) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableExperimentalExtensionApis);
+
+ Profile* profile = browser()->profile();
+
+ // Provide some testing data here, since bookmark editing will be disabled
+ // within the extension.
+ BookmarkModel* model = profile->GetBookmarkModel();
+ const BookmarkNode* bar = model->GetBookmarkBarNode();
+ const BookmarkNode* folder = model->AddFolder(bar, 0, ASCIIToUTF16("Folder"));
+ const BookmarkNode* node = model->AddURL(bar, 1, ASCIIToUTF16("AAA"),
+ GURL("http://aaa.example.com"));
+ node = model->AddURL(folder, 0, ASCIIToUTF16("BBB"),
+ GURL("http://bbb.example.com"));
+
+ profile->GetPrefs()->SetBoolean(prefs::kEditBookmarksEnabled, false);
+
+ ASSERT_TRUE(RunExtensionTest("bookmark_manager/edit_disabled")) << message_;
}
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc
index 0d8da7e4..e240ea8 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module.cc
@@ -101,6 +101,13 @@ bool BookmarksFunction::GetBookmarkIdAsInt64(
return false;
}
+bool BookmarksFunction::EditBookmarksEnabled() {
+ if (profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))
+ return true;
+ error_ = keys::kEditBookmarksDisabled;
+ return false;
+}
+
void BookmarksFunction::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -394,6 +401,8 @@ bool RemoveBookmarkFunction::ExtractIds(const ListValue* args,
}
bool RemoveBookmarkFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
std::list<int64> ids;
bool invalid_id = false;
EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id));
@@ -416,6 +425,8 @@ bool RemoveBookmarkFunction::RunImpl() {
}
bool CreateBookmarkFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
DictionaryValue* json;
EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
EXTENSION_FUNCTION_VALIDATE(json != NULL);
@@ -490,6 +501,8 @@ bool MoveBookmarkFunction::ExtractIds(const ListValue* args,
}
bool MoveBookmarkFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
std::list<int64> ids;
bool invalid_id = false;
EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id));
@@ -569,6 +582,8 @@ bool UpdateBookmarkFunction::ExtractIds(const ListValue* args,
}
bool UpdateBookmarkFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
std::list<int64> ids;
bool invalid_id = false;
EXTENSION_FUNCTION_VALIDATE(ExtractIds(args_.get(), &ids, &invalid_id));
@@ -861,6 +876,8 @@ void BookmarksIOFunction::MultiFilesSelected(
}
bool ImportBookmarksFunction::RunImpl() {
+ if (!EditBookmarksEnabled())
+ return false;
SelectFile(SelectFileDialog::SELECT_OPEN_FILE);
return true;
}
diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h
index 7d15b88..8c3063f 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.h
+++ b/chrome/browser/extensions/extension_bookmarks_module.h
@@ -87,6 +87,10 @@ class BookmarksFunction : public AsyncExtensionFunction,
// as an int64. In case of error, doesn't change id and returns false.
bool GetBookmarkIdAsInt64(const std::string& id_string, int64* id);
+ // Helper that checks if bookmark editing is enabled. If it's not, this sets
+ // error_ to the appropriate error string.
+ bool EditBookmarksEnabled();
+
private:
// NotificationObserver:
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.cc b/chrome/browser/extensions/extension_bookmarks_module_constants.cc
index cabd0cf..3b13942 100644
--- a/chrome/browser/extensions/extension_bookmarks_module_constants.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module_constants.cc
@@ -30,6 +30,7 @@ const char kInvalidIdError[] = "Bookmark id is invalid.";
const char kInvalidIndexError[] = "Index out of bounds.";
const char kInvalidUrlError[] = "Invalid URL.";
const char kModifySpecialError[] = "Can't modify the root bookmark folders.";
+const char kEditBookmarksDisabled[] = "Bookmark editing is disabled.";
const char kOnBookmarkCreated[] = "bookmarks.onCreated";
const char kOnBookmarkRemoved[] = "bookmarks.onRemoved";
diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.h b/chrome/browser/extensions/extension_bookmarks_module_constants.h
index a007f75..d20b1220 100644
--- a/chrome/browser/extensions/extension_bookmarks_module_constants.h
+++ b/chrome/browser/extensions/extension_bookmarks_module_constants.h
@@ -35,6 +35,7 @@ extern const char kInvalidIdError[];
extern const char kInvalidIndexError[];
extern const char kInvalidUrlError[];
extern const char kModifySpecialError[];
+extern const char kEditBookmarksDisabled[];
// Events.
extern const char kOnBookmarkCreated[];
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/manifest.json b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/manifest.json
new file mode 100644
index 0000000..6a60660
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/manifest.json
@@ -0,0 +1,7 @@
+{
+ "name": "chrome.experimental.bookmarkManager (edit disabled)",
+ "version": "0.1",
+ "description": "end-to-end browser test for chrome.experimental.bookmarkManager API with editing disabled",
+ "background_page": "test.html",
+ "permissions": ["bookmarks", "experimental"]
+}
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/test.html b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.html
index 46f4d74..46f4d74 100644
--- a/chrome/test/data/extensions/api_test/bookmark_manager/test.html
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.html
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.js b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.js
new file mode 100644
index 0000000..a016ebd
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/edit_disabled/test.js
@@ -0,0 +1,76 @@
+// Bookmark Manager API test for Chrome.
+// browser_tests.exe --gtest_filter=ExtensionApiTest.BookmarkManagerEditDisabled
+
+const pass = chrome.test.callbackPass;
+const fail = chrome.test.callbackFail;
+const assertEq = chrome.test.assertEq;
+const assertTrue = chrome.test.assertTrue;
+const bookmarks = chrome.bookmarks;
+const bookmarkManager = chrome.experimental.bookmarkManager;
+
+var ERROR = "Bookmark editing is disabled.";
+
+// Bookmark model within this test:
+// <root>/
+// Bookmarks Bar/
+// Folder/
+// "BBB"
+// "AAA"
+// Other Bookmarks/
+
+var tests = [
+ function verifyModel() {
+ bookmarks.getTree(pass(function(result) {
+ assertEq(1, result.length);
+ var root = result[0];
+ assertEq(2, root.children.length);
+ bar = root.children[0];
+ assertEq(2, bar.children.length);
+ folder = bar.children[0];
+ aaa = bar.children[1];
+ assertEq('Folder', folder.title);
+ assertEq('AAA', aaa.title);
+ bbb = folder.children[0];
+ assertEq('BBB', bbb.title);
+ }));
+ },
+
+ function createDisabled() {
+ bookmarks.create({ parentId: bar.id, title: 'Folder2' }, fail(ERROR));
+ },
+
+ function moveDisabled() {
+ bookmarks.move(aaa.id, { parentId: folder.id }, fail(ERROR));
+ },
+
+ function removeDisabled() {
+ bookmarks.remove(aaa.id, fail(ERROR));
+ },
+
+ function removeTreeDisabled() {
+ bookmarks.removeTree(folder.id, fail(ERROR));
+ },
+
+ function updateDisabled() {
+ bookmarks.update(aaa.id, { title: 'CCC' }, fail(ERROR));
+ },
+
+ function importDisabled() {
+ bookmarks.import(fail(ERROR));
+ },
+
+ function cutDisabled() {
+ bookmarkManager.cut([bbb.id], fail(ERROR));
+ },
+
+ function canPasteDisabled() {
+ bookmarkManager.canPaste(folder.id, fail(ERROR));
+ },
+
+ function pasteDisabled() {
+ bookmarkManager.paste(folder.id, [bbb.id], fail(ERROR));
+ },
+
+];
+
+chrome.test.runTests(tests);
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/manifest.json b/chrome/test/data/extensions/api_test/bookmark_manager/standard/manifest.json
index ce4e407..ce4e407 100644
--- a/chrome/test/data/extensions/api_test/bookmark_manager/manifest.json
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/standard/manifest.json
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/standard/test.html b/chrome/test/data/extensions/api_test/bookmark_manager/standard/test.html
new file mode 100644
index 0000000..46f4d74
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/standard/test.html
@@ -0,0 +1 @@
+<script src="test.js"></script>
diff --git a/chrome/test/data/extensions/api_test/bookmark_manager/test.js b/chrome/test/data/extensions/api_test/bookmark_manager/standard/test.js
index e4ec7cd..e4ec7cd 100644
--- a/chrome/test/data/extensions/api_test/bookmark_manager/test.js
+++ b/chrome/test/data/extensions/api_test/bookmark_manager/standard/test.js