diff options
author | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 12:24:01 +0000 |
---|---|---|
committer | joaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-30 12:24:01 +0000 |
commit | 933ebbecb4e868df6f435c3ff6d51713d64d3975 (patch) | |
tree | 97512f7ccfc0fbd8bd060d2e5220c530daed04f6 /chrome/browser | |
parent | 0af15148d0762c860ba58ebf983b10e57d798f91 (diff) | |
download | chromium_src-933ebbecb4e868df6f435c3ff6d51713d64d3975.zip chromium_src-933ebbecb4e868df6f435c3ff6d51713d64d3975.tar.gz chromium_src-933ebbecb4e868df6f435c3ff6d51713d64d3975.tar.bz2 |
Disable Bookmark Manager menus that change bookmarks when bookmark editing
is disabled by policy.
Added chrome.experimental.bookmarkManager.canEdit extension API.
BUG=84117
TEST=ExtensionApiTest.BookmarkManager*
Review URL: http://codereview.chromium.org/7194001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
4 files changed, 80 insertions, 44 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc index d3445fa..3f1388c 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.cc +++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc @@ -17,8 +17,10 @@ #include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_web_ui.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" +#include "chrome/common/pref_names.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" @@ -470,3 +472,9 @@ bool GetSubtreeBookmarkManagerFunction::RunImpl() { result_.reset(json.release()); return true; } + +bool CanEditBookmarkManagerFunction::RunImpl() { + result_.reset(Value::CreateBooleanValue( + profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled))); + return true; +} diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.h b/chrome/browser/extensions/extension_bookmark_manager_api.h index 7616145..69812a3 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.h +++ b/chrome/browser/extensions/extension_bookmark_manager_api.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -57,8 +57,7 @@ class ClipboardBookmarkManagerFunction : public BookmarksFunction { class CopyBookmarkManagerFunction : public ClipboardBookmarkManagerFunction { public: - // Override ClipboardBookmarkManagerFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.copy"); @@ -66,8 +65,7 @@ class CopyBookmarkManagerFunction : public ClipboardBookmarkManagerFunction { class CutBookmarkManagerFunction : public ClipboardBookmarkManagerFunction { public: - // Override ClipboardBookmarkManagerFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.cut"); @@ -75,48 +73,39 @@ class CutBookmarkManagerFunction : public ClipboardBookmarkManagerFunction { class PasteBookmarkManagerFunction : public BookmarksFunction { public: - // Override BookmarksFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.paste"); }; -class CanPasteBookmarkManagerFunction - : public BookmarksFunction { +class CanPasteBookmarkManagerFunction : public BookmarksFunction { public: - // Override BookmarksFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.canPaste"); }; -class SortChildrenBookmarkManagerFunction - : public BookmarksFunction { +class SortChildrenBookmarkManagerFunction : public BookmarksFunction { public: - // Override BookmarksFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: - DECLARE_EXTENSION_FUNCTION_NAME( - "experimental.bookmarkManager.sortChildren"); + DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.sortChildren"); }; class BookmarkManagerGetStringsFunction : public AsyncExtensionFunction { public: - // Override AsyncExtensionFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.getStrings"); }; -class StartDragBookmarkManagerFunction - : public BookmarksFunction { +class StartDragBookmarkManagerFunction : public BookmarksFunction { public: - // Override BookmarksFunction. - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.startDrag"); @@ -124,20 +113,26 @@ class StartDragBookmarkManagerFunction class DropBookmarkManagerFunction : public BookmarksFunction { public: - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.drop"); }; - class GetSubtreeBookmarkManagerFunction : public BookmarksFunction { public: - // Override BookmarksFunction - virtual bool RunImpl(); + virtual bool RunImpl() OVERRIDE; private: DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.getSubtree"); }; +class CanEditBookmarkManagerFunction : public BookmarksFunction { + public: + virtual bool RunImpl() OVERRIDE; + + private: + DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.canEdit"); +}; + #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARK_MANAGER_API_H_ diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index ec7be57..7ad884a 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -188,6 +188,7 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<StartDragBookmarkManagerFunction>(); RegisterFunction<DropBookmarkManagerFunction>(); RegisterFunction<GetSubtreeBookmarkManagerFunction>(); + RegisterFunction<CanEditBookmarkManagerFunction>(); // History RegisterFunction<AddUrlHistoryFunction>(); diff --git a/chrome/browser/resources/bookmark_manager/js/main.js b/chrome/browser/resources/bookmark_manager/js/main.js index baaa3d7..189f8558 100644 --- a/chrome/browser/resources/bookmark_manager/js/main.js +++ b/chrome/browser/resources/bookmark_manager/js/main.js @@ -910,6 +910,11 @@ for (var i = 0, command; command = commands[i]; i++) { } } +var canEdit = true; +chrome.experimental.bookmarkManager.canEdit(function(result) { + canEdit = result; +}); + /** * Helper function that updates the canExecute and labels for the open like * commands. @@ -986,14 +991,14 @@ function updatePasteCommand(opt_f) { } } -// We can always execute the import-menu and export-menu commands. +// We can always execute the export-menu command. document.addEventListener('canExecute', function(e) { var command = e.command; var commandId = command.id; - if (commandId == 'import-menu-command' || - commandId == 'export-menu-command') { + if (commandId == 'import-menu-command') + e.canExecute = canEdit; + if (commandId == 'export-menu-command') e.canExecute = true; - } }); /** @@ -1002,7 +1007,7 @@ document.addEventListener('canExecute', function(e) { * @param {boolean} isRecentOrSearch Whether the user is trying to do a command * on recent or search. */ -function canExcuteShared(e, isRecentOrSearch) { +function canExecuteShared(e, isRecentOrSearch) { var command = e.command; var commandId = command.id; switch (commandId) { @@ -1014,20 +1019,22 @@ function canExcuteShared(e, isRecentOrSearch) { if (isRecentOrSearch) { e.canExecute = false; } else { - e.canExecute = list.dataModel.length > 0; + e.canExecute = list.dataModel.length > 0 && canEdit; // The list might be loading so listen to the load event. - var f = function() { - list.removeEventListener('load', f); - command.disabled = list.dataModel.length == 0; - }; - list.addEventListener('load', f); + if (canEdit) { + var f = function() { + list.removeEventListener('load', f); + command.disabled = list.dataModel.length == 0 || !canEdit; + }; + list.addEventListener('load', f); + } } break; case 'add-new-bookmark-command': case 'new-folder-command': - e.canExecute = !isRecentOrSearch; + e.canExecute = !isRecentOrSearch && canEdit; break; case 'open-in-new-tab-command': @@ -1067,7 +1074,7 @@ list.addEventListener('canExecute', function(e) { command.hidden = true; } else { var isFolder = bmm.isFolder(items[0]); - e.canExecute = isFolder; + e.canExecute = isFolder && canEdit; command.hidden = !isFolder; } break; @@ -1080,7 +1087,7 @@ list.addEventListener('canExecute', function(e) { command.hidden = false; } else { var isFolder = bmm.isFolder(items[0]); - e.canExecute = !isFolder; + e.canExecute = !isFolder && canEdit; command.hidden = isFolder; } break; @@ -1091,6 +1098,9 @@ list.addEventListener('canExecute', function(e) { case 'delete-command': case 'cut-command': + e.canExecute = hasSelected() && canEdit; + break; + case 'copy-command': e.canExecute = hasSelected(); break; @@ -1100,7 +1110,7 @@ list.addEventListener('canExecute', function(e) { break; default: - canExcuteShared(e, isRecentOrSearch()); + canExecuteShared(e, isRecentOrSearch()); } }); @@ -1127,7 +1137,7 @@ tree.addEventListener('canExecute', function(e) { switch (commandId) { case 'rename-folder-command': command.hidden = false; - e.canExecute = hasSelected() && !isTopLevelItem(); + e.canExecute = hasSelected() && !isTopLevelItem() && canEdit; break; case 'edit-command': @@ -1137,12 +1147,15 @@ tree.addEventListener('canExecute', function(e) { case 'delete-command': case 'cut-command': + e.canExecute = hasSelected() && !isTopLevelItem() && canEdit; + break; + case 'copy-command': e.canExecute = hasSelected() && !isTopLevelItem(); break; default: - canExcuteShared(e, isRecentOrSearch()); + canExecuteShared(e, isRecentOrSearch()); } }); @@ -1170,6 +1183,25 @@ function updateCommandsBasedOnSelection(e) { list.addEventListener('change', updateCommandsBasedOnSelection); tree.addEventListener('change', updateCommandsBasedOnSelection); +function updateEditingCommands() { + var editingCommands = ['cut', 'delete', 'rename-folder', 'edit', + 'add-new-bookmark', 'new-folder', 'sort', 'paste']; + + chrome.experimental.bookmarkManager.canEdit(function(result) { + if (result != canEdit) { + canEdit = result; + editingCommands.forEach(function(baseId) { + $(baseId + '-command').canExecuteChange(); + }); + } + }); +} + +var organizeButton = document.querySelector('.summary > button'); +organizeButton.addEventListener('click', updateEditingCommands); +list.addEventListener('contextmenu', updateEditingCommands); +tree.addEventListener('contextmenu', updateEditingCommands); + document.addEventListener('command', function(e) { var command = e.command; var commandId = command.id; |