summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorfeldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-28 00:04:56 +0000
committerfeldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-28 00:04:56 +0000
commitcb6cf79cacd881bcbc4f00bb449d7044619aeced (patch)
tree1b265453e2ad2a33beda3d6630444e76da3321a0 /chrome/browser/extensions
parent69b3f1eab57725dd68502c19f4eed1fa9c7f401f (diff)
downloadchromium_src-cb6cf79cacd881bcbc4f00bb449d7044619aeced.zip
chromium_src-cb6cf79cacd881bcbc4f00bb449d7044619aeced.tar.gz
chromium_src-cb6cf79cacd881bcbc4f00bb449d7044619aeced.tar.bz2
Add import/export extension apis
This is a duplicate of 543094. That code review seems to have gotten corrupted as i can no longer publish anything from their web UI. It was LGTM'd+nits by arv, which i've fixed here. BUG=32194 TEST=Import and export bookmarks from the extension Review URL: http://codereview.chromium.org/548167 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.cc63
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.h36
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.cc19
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.h2
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module_constants.cc5
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module_constants.h2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
7 files changed, 127 insertions, 2 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc
index 58986a8..a6b3e08 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc
@@ -7,6 +7,9 @@
#include "app/l10n_util.h"
#include "base/values.h"
#include "grit/generated_resources.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/bookmarks/bookmark_html_writer.h"
+#include "chrome/browser/importer/importer.h"
bool CopyBookmarkManagerFunction::RunImpl() {
NOTIMPLEMENTED();
@@ -25,6 +28,66 @@ bool PasteBookmarkManagerFunction::RunImpl() {
return true;
}
+void BookmarkManagerIOFunction::SelectFile(SelectFileDialog::Type type) {
+ // Balanced in one of the three callbacks of SelectFileDialog:
+ // either FileSelectionCanceled, MultiFilesSelected, or FileSelected
+ AddRef();
+ select_file_dialog_ = SelectFileDialog::Create(this);
+ SelectFileDialog::FileTypeInfo file_type_info;
+ file_type_info.extensions.resize(1);
+ file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html"));
+
+ select_file_dialog_->SelectFile(type,
+ string16(),
+ FilePath(),
+ &file_type_info,
+ 0,
+ FILE_PATH_LITERAL(""),
+ NULL,
+ NULL);
+}
+
+void BookmarkManagerIOFunction::FileSelectionCanceled(void* params) {
+ Release(); //Balanced in BookmarkManagerIOFunction::SelectFile()
+}
+
+void BookmarkManagerIOFunction::MultiFilesSelected(
+ const std::vector<FilePath>& files, void* params) {
+ Release(); //Balanced in BookmarkManagerIOFunction::SelectFile()
+ NOTREACHED() << "Should not be able to select multiple files";
+}
+
+bool ImportBookmarksFunction::RunImpl() {
+ SelectFile(SelectFileDialog::SELECT_OPEN_FILE);
+ return true;
+}
+
+void ImportBookmarksFunction::FileSelected(const FilePath& path,
+ int index,
+ void* params) {
+ ImporterHost* host = new ImporterHost();
+ ProfileInfo profile_info;
+ profile_info.browser_type = BOOKMARKS_HTML;
+ profile_info.source_path = path.ToWStringHack();
+ host->StartImportSettings(profile_info,
+ profile(),
+ FAVORITES,
+ new ProfileWriter(profile()),
+ true);
+ Release(); //Balanced in BookmarkManagerIOFunction::SelectFile()
+}
+
+bool ExportBookmarksFunction::RunImpl() {
+ SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE);
+ return true;
+}
+
+void ExportBookmarksFunction::FileSelected(const FilePath& path,
+ int index,
+ void* params) {
+ bookmark_html_writer::WriteBookmarks(profile()->GetBookmarkModel(), path);
+ Release(); //Balanced in BookmarkManagerIOFunction::SelectFile()
+}
bool BookmarkManagerGetStringsFunction::RunImpl() {
DictionaryValue* localized_strings = new DictionaryValue();
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.h b/chrome/browser/extensions/extension_bookmark_manager_api.h
index 2ab6be6c..f0bf1a3 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.h
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARK_MANAGER_API_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 {
public:
@@ -34,6 +36,39 @@ class PasteBookmarkManagerFunction : public AsyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.paste");
};
+class BookmarkManagerIOFunction : public BookmarksFunction,
+ public SelectFileDialog::Listener {
+ public:
+ // Overridden from SelectFileDialog::Listener:
+ virtual void FileSelected(const FilePath& path, int index, void* params) = 0;
+ void MultiFilesSelected(const std::vector<FilePath>& files, void* params);
+ void FileSelectionCanceled(void* params);
+ void SelectFile(SelectFileDialog::Type type);
+
+ protected:
+ scoped_refptr<SelectFileDialog> select_file_dialog_;
+};
+
+class ImportBookmarksFunction : public BookmarkManagerIOFunction {
+ public:
+ // Override BookmarkManagerFunction.
+ bool RunImpl();
+ void FileSelected(const FilePath& path, int index, void* params);
+
+ private:
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.import");
+};
+
+class ExportBookmarksFunction : public BookmarkManagerIOFunction {
+ public:
+ // Override BookmarkManagerFunction.
+ bool RunImpl();
+ void FileSelected(const FilePath& path, int index, void* params);
+
+ private:
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.export");
+};
+
class BookmarkManagerGetStringsFunction : public AsyncExtensionFunction {
public:
// Override BookmarkManagerFunction.
@@ -43,5 +78,4 @@ class BookmarkManagerGetStringsFunction : public AsyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.getStrings");
};
-
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARK_MANAGER_API_H_
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc
index 568391c..33abc39 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module.cc
@@ -279,6 +279,25 @@ void ExtensionBookmarkEventRouter::BookmarkNodeChildrenReordered(
json_args);
}
+void ExtensionBookmarkEventRouter::
+ BookmarkImportBeginning(BookmarkModel* model) {
+ ListValue args;
+ std::string json_args;
+ base::JSONWriter::Write(&args, false, &json_args);
+ DispatchEvent(model->profile(),
+ keys::kOnBookmarkImportBegan,
+ json_args);
+}
+
+void ExtensionBookmarkEventRouter::BookmarkImportEnding(BookmarkModel* model) {
+ ListValue args;
+ std::string json_args;
+ base::JSONWriter::Write(&args, false, &json_args);
+ DispatchEvent(model->profile(),
+ keys::kOnBookmarkImportEnded,
+ json_args);
+}
+
bool GetBookmarksFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
scoped_ptr<ListValue> json(new ListValue());
diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h
index 4caece2..b8989aa 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.h
+++ b/chrome/browser/extensions/extension_bookmarks_module.h
@@ -45,6 +45,8 @@ class ExtensionBookmarkEventRouter : public BookmarkModelObserver {
const BookmarkNode* node);
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
const BookmarkNode* node);
+ virtual void BookmarkImportBeginning(BookmarkModel* model);
+ virtual void BookmarkImportEnding(BookmarkModel* model);
private:
ExtensionBookmarkEventRouter();
diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.cc b/chrome/browser/extensions/extension_bookmarks_module_constants.cc
index 6f72669..9440f06 100644
--- a/chrome/browser/extensions/extension_bookmarks_module_constants.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module_constants.cc
@@ -33,5 +33,8 @@ const char kOnBookmarkRemoved[] = "bookmarks.onRemoved";
const char kOnBookmarkChanged[] = "bookmarks.onChanged";
const char kOnBookmarkMoved[] = "bookmarks.onMoved";
const char kOnBookmarkChildrenReordered[] = "bookmarks.onChildrenReordered";
-
+const char kOnBookmarkImportBegan[] =
+ "experimental.bookmarkManager.onImportBegan";
+const char kOnBookmarkImportEnded[] =
+ "experimental.bookmarkManager.onImportEnded";
} // namespace extension_bookmarks_module_constants
diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.h b/chrome/browser/extensions/extension_bookmarks_module_constants.h
index 159dc7f..7214e80 100644
--- a/chrome/browser/extensions/extension_bookmarks_module_constants.h
+++ b/chrome/browser/extensions/extension_bookmarks_module_constants.h
@@ -38,6 +38,8 @@ extern const char kOnBookmarkRemoved[];
extern const char kOnBookmarkChanged[];
extern const char kOnBookmarkMoved[];
extern const char kOnBookmarkChildrenReordered[];
+extern const char kOnBookmarkImportBegan[];
+extern const char kOnBookmarkImportEnded[];
}; // namespace extension_bookmarks_module_constants
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index ba3e80e..6e719fc 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -136,6 +136,8 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<CopyBookmarkManagerFunction>();
RegisterFunction<CutBookmarkManagerFunction>();
RegisterFunction<PasteBookmarkManagerFunction>();
+ RegisterFunction<ImportBookmarksFunction>();
+ RegisterFunction<ExportBookmarksFunction>();
RegisterFunction<BookmarkManagerGetStringsFunction>();
// History