summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 23:54:57 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 23:54:57 +0000
commit03b3bbf29d5d6eb23984206379e9b9e8f89f16df (patch)
treeaf67081fbf56601b473de03fc6472672173308cf /chrome/browser
parent9ec3fdb430b97e942b6612835bb2076a704c016a (diff)
downloadchromium_src-03b3bbf29d5d6eb23984206379e9b9e8f89f16df.zip
chromium_src-03b3bbf29d5d6eb23984206379e9b9e8f89f16df.tar.gz
chromium_src-03b3bbf29d5d6eb23984206379e9b9e8f89f16df.tar.bz2
Add clipboard hooks to the bookmark manager extension API.
This adds the following functions: copy(idList) cut(idList) paste(parentId) canPaste(parentId, callback) BUG=32194 TEST=browser_tests.exe --gtest_filter=ExtensionApiTest.BookmarkManager Review URL: http://codereview.chromium.org/557050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37569 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.cc66
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.h41
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc1
3 files changed, 89 insertions, 19 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc
index a6b3e08..11fd56d 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc
@@ -6,28 +6,78 @@
#include "app/l10n_util.h"
#include "base/values.h"
-#include "grit/generated_resources.h"
-#include "chrome/browser/profile.h"
+#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
+#include "chrome/browser/bookmarks/bookmark_utils.h"
+#include "chrome/browser/extensions/extension_bookmarks_module_constants.h"
#include "chrome/browser/importer/importer.h"
+#include "chrome/browser/profile.h"
+#include "grit/generated_resources.h"
+
+namespace keys = extension_bookmarks_module_constants;
+
+bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) {
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
+ const ListValue* ids = args_as_list();
+ size_t count = ids->GetSize();
+ EXTENSION_FUNCTION_VALIDATE(count > 0);
+
+ BookmarkModel* model = profile()->GetBookmarkModel();
+ std::vector<const BookmarkNode*> nodes;
+
+ for (size_t i = 0; i < count; ++i) {
+ int64 id;
+ std::string id_string;
+ EXTENSION_FUNCTION_VALIDATE(ids->GetString(i, &id_string));
+ if (!GetBookmarkIdAsInt64(id_string, &id))
+ return false;
+ const BookmarkNode* node = model->GetNodeByID(id);
+ if (!node) {
+ error_ = keys::kNoNodeError;
+ return false;
+ } else {
+ nodes.push_back(node);
+ }
+ }
+
+ bookmark_utils::CopyToClipboard(model, nodes, cut);
-bool CopyBookmarkManagerFunction::RunImpl() {
- NOTIMPLEMENTED();
return true;
}
+const BookmarkNode* ClipboardBookmarkManagerFunction::GetNodeFromArguments() {
+ std::string id_string;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
+ int64 id;
+ EXTENSION_FUNCTION_VALIDATE(StringToInt64(id_string, &id));
+ BookmarkModel* model = profile()->GetBookmarkModel();
+ const BookmarkNode* node = model->GetNodeByID(id);
+ EXTENSION_FUNCTION_VALIDATE(node);
+ return node;
+}
-bool CutBookmarkManagerFunction::RunImpl() {
- NOTIMPLEMENTED();
- return true;
+bool CopyBookmarkManagerFunction::RunImpl() {
+ return CopyOrCut(false);
}
+bool CutBookmarkManagerFunction::RunImpl() {
+ return CopyOrCut(true);
+}
bool PasteBookmarkManagerFunction::RunImpl() {
- NOTIMPLEMENTED();
+ BookmarkModel* model = profile()->GetBookmarkModel();
+ const BookmarkNode* parent_node = GetNodeFromArguments();
+ bookmark_utils::PasteFromClipboard(model, parent_node, -1);
return true;
}
+bool CanPasteBookmarkManagerFunction::RunImpl() {
+ const BookmarkNode* parent_node = GetNodeFromArguments();
+ bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node);
+ result_.reset(Value::CreateBooleanValue(can_paste));
+ SendResponse(true);
+ return true;
+}
void BookmarkManagerIOFunction::SelectFile(SelectFileDialog::Type type) {
// Balanced in one of the three callbacks of SelectFileDialog:
// either FileSelectionCanceled, MultiFilesSelected, or FileSelected
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.h b/chrome/browser/extensions/extension_bookmark_manager_api.h
index f0bf1a3..72f1bf0 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.h
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.h
@@ -5,39 +5,58 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARK_MANAGER_API_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARK_MANAGER_API_H_
+#include "chrome/browser/extensions/extension_bookmarks_module.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/shell_dialogs.h"
-#include "chrome/browser/extensions/extension_bookmarks_module.h"
-class CopyBookmarkManagerFunction : public AsyncExtensionFunction {
+class BookmarkNode;
+
+class ClipboardBookmarkManagerFunction : public BookmarksFunction {
+ protected:
+ bool CopyOrCut(bool cut);
+ // Returns a single bookmark node from the ID passed as the first argument.
+ const BookmarkNode* GetNodeFromArguments();
+};
+
+class CopyBookmarkManagerFunction : public ClipboardBookmarkManagerFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override ClipboardBookmarkManagerFunction.
virtual bool RunImpl();
private:
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.copy");
};
-class CutBookmarkManagerFunction : public AsyncExtensionFunction {
+class CutBookmarkManagerFunction : public ClipboardBookmarkManagerFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override ClipboardBookmarkManagerFunction.
virtual bool RunImpl();
private:
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.cut");
};
-class PasteBookmarkManagerFunction : public AsyncExtensionFunction {
+class PasteBookmarkManagerFunction : public ClipboardBookmarkManagerFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override ClipboardBookmarkManagerFunction.
virtual bool RunImpl();
private:
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.paste");
};
+class CanPasteBookmarkManagerFunction
+ : public ClipboardBookmarkManagerFunction {
+ public:
+ // Override ClipboardBookmarkManagerFunction.
+ virtual bool RunImpl();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.canPaste");
+};
+
class BookmarkManagerIOFunction : public BookmarksFunction,
- public SelectFileDialog::Listener {
+ public SelectFileDialog::Listener {
public:
// Overridden from SelectFileDialog::Listener:
virtual void FileSelected(const FilePath& path, int index, void* params) = 0;
@@ -51,7 +70,7 @@ class BookmarkManagerIOFunction : public BookmarksFunction,
class ImportBookmarksFunction : public BookmarkManagerIOFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override BookmarkManagerIOFunction.
bool RunImpl();
void FileSelected(const FilePath& path, int index, void* params);
@@ -61,7 +80,7 @@ class ImportBookmarksFunction : public BookmarkManagerIOFunction {
class ExportBookmarksFunction : public BookmarkManagerIOFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override BookmarkManagerIOFunction.
bool RunImpl();
void FileSelected(const FilePath& path, int index, void* params);
@@ -71,7 +90,7 @@ class ExportBookmarksFunction : public BookmarkManagerIOFunction {
class BookmarkManagerGetStringsFunction : public AsyncExtensionFunction {
public:
- // Override BookmarkManagerFunction.
+ // Override AsyncExtensionFunction.
virtual bool RunImpl();
private:
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index ba85956..bdba709 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -138,6 +138,7 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<CopyBookmarkManagerFunction>();
RegisterFunction<CutBookmarkManagerFunction>();
RegisterFunction<PasteBookmarkManagerFunction>();
+ RegisterFunction<CanPasteBookmarkManagerFunction>();
RegisterFunction<ImportBookmarksFunction>();
RegisterFunction<ExportBookmarksFunction>();
RegisterFunction<BookmarkManagerGetStringsFunction>();