diff options
author | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 21:40:55 +0000 |
---|---|---|
committer | feldstein@chromium.org <feldstein@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-26 21:40:55 +0000 |
commit | dc0412127385b73df3647ebfb313b61e51ef1496 (patch) | |
tree | f1a6db934166721bf81c80909d87fd6a15565dd3 /chrome/browser/extensions | |
parent | 31db0071f84abe836f54218bd9240adb847d3211 (diff) | |
download | chromium_src-dc0412127385b73df3647ebfb313b61e51ef1496.zip chromium_src-dc0412127385b73df3647ebfb313b61e51ef1496.tar.gz chromium_src-dc0412127385b73df3647ebfb313b61e51ef1496.tar.bz2 |
Move onImportBegan/Ended to the regular bookmarks api
It used to live in the experimental.bookmarkManager namespace.
BUG=35320
TEST=none
Review URL: http://codereview.chromium.org/1353004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
6 files changed, 101 insertions, 103 deletions
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc index ff29fab..def7eeb 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.cc +++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc @@ -12,14 +12,11 @@ #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_drag_data.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/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" #include "chrome/browser/extensions/extension_dom_ui.h" #include "chrome/browser/extensions/extension_message_service.h" -#include "chrome/browser/importer/importer.h" -#include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -251,67 +248,6 @@ bool CanPasteBookmarkManagerFunction::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(); - importer::ProfileInfo profile_info; - profile_info.browser_type = importer::BOOKMARKS_HTML; - profile_info.source_path = path.ToWStringHack(); - host->StartImportSettings(profile_info, - profile(), - importer::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(), path, NULL); - Release(); // Balanced in BookmarkManagerIOFunction::SelectFile() -} - bool SortChildrenBookmarkManagerFunction::RunImpl() { BookmarkModel* model = profile()->GetBookmarkModel(); const BookmarkNode* parent_node = GetNodeFromArguments(model, args_.get()); diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.h b/chrome/browser/extensions/extension_bookmark_manager_api.h index b15e07c..5baad91 100644 --- a/chrome/browser/extensions/extension_bookmark_manager_api.h +++ b/chrome/browser/extensions/extension_bookmark_manager_api.h @@ -9,7 +9,6 @@ #include "chrome/browser/extensions/extension_bookmarks_module.h" #include "chrome/browser/extensions/extension_function.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" -#include "chrome/browser/shell_dialogs.h" struct BookmarkDragData; class BookmarkNode; @@ -93,39 +92,6 @@ class CanPasteBookmarkManagerFunction DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.canPaste"); }; -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 BookmarkManagerIOFunction. - 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 BookmarkManagerIOFunction. - bool RunImpl(); - void FileSelected(const FilePath& path, int index, void* params); - - private: - DECLARE_EXTENSION_FUNCTION_NAME("experimental.bookmarkManager.export"); -}; - class SortChildrenBookmarkManagerFunction : public BookmarksFunction { public: diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc index d561e2a..e0fadaf 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.cc +++ b/chrome/browser/extensions/extension_bookmarks_module.cc @@ -9,12 +9,15 @@ #include "base/stl_util-inl.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_codec.h" +#include "chrome/browser/bookmarks/bookmark_html_writer.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/extensions/extension_bookmarks_module_constants.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extensions_quota_service.h" +#include "chrome/browser/importer/importer.h" +#include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" #include "chrome/common/notification_service.h" @@ -857,3 +860,64 @@ void CreateBookmarkFunction::GetQuotaLimitHeuristics( QuotaLimitHeuristics* heuristics) const { BookmarksQuotaLimitFactory::BuildForCreate(heuristics, profile()); } + +void BookmarksIOFunction::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 BookmarksIOFunction::FileSelectionCanceled(void* params) { + Release(); // Balanced in BookmarksIOFunction::SelectFile() +} + +void BookmarksIOFunction::MultiFilesSelected( + const std::vector<FilePath>& files, void* params) { + Release(); // Balanced in BookmarsIOFunction::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(); + importer::ProfileInfo profile_info; + profile_info.browser_type = importer::BOOKMARKS_HTML; + profile_info.source_path = path.ToWStringHack(); + host->StartImportSettings(profile_info, + profile(), + importer::FAVORITES, + new ProfileWriter(profile()), + true); + Release(); // Balanced in BookmarksIOFunction::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(), path, NULL); + Release(); // Balanced in BookmarksIOFunction::SelectFile() +} diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h index b8989aa..cb25755 100644 --- a/chrome/browser/extensions/extension_bookmarks_module.h +++ b/chrome/browser/extensions/extension_bookmarks_module.h @@ -11,6 +11,7 @@ #include "base/singleton.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/extensions/extension_function.h" +#include "chrome/browser/shell_dialogs.h" #include "chrome/common/notification_registrar.h" // Observes BookmarkModel and then routes the notifications as events to @@ -167,4 +168,37 @@ class UpdateBookmarkFunction : public BookmarksFunction { DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.update") }; +class BookmarksIOFunction : 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 BookmarksIOFunction { + public: + // Override BookmarkManagerIOFunction. + bool RunImpl(); + void FileSelected(const FilePath& path, int index, void* params); + + private: + DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.import"); +}; + +class ExportBookmarksFunction : public BookmarksIOFunction { + public: + // Override BookmarkManagerIOFunction. + bool RunImpl(); + void FileSelected(const FilePath& path, int index, void* params); + + private: + DECLARE_EXTENSION_FUNCTION_NAME("bookmarks.export"); +}; + #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BOOKMARKS_MODULE_H_ diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.cc b/chrome/browser/extensions/extension_bookmarks_module_constants.cc index 3e20f3d..0fcb74b 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.cc +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.cc @@ -36,11 +36,9 @@ const char kOnBookmarkRemoved[] = "bookmarks.onRemoved"; const char kOnBookmarkChanged[] = "bookmarks.onChanged"; const char kOnBookmarkMoved[] = "bookmarks.onMoved"; const char kOnBookmarkChildrenReordered[] = "bookmarks.onChildrenReordered"; +const char kOnBookmarkImportBegan[] = "bookmarks.onImportBegan"; +const char kOnBookmarkImportEnded[] = "bookmarks.onImportEnded"; // TODO(arv): Move bookmark manager related constants out of this file. -const char kOnBookmarkImportBegan[] = - "experimental.bookmarkManager.onImportBegan"; -const char kOnBookmarkImportEnded[] = - "experimental.bookmarkManager.onImportEnded"; const char kOnBookmarkDragEnter[] = "experimental.bookmarkManager.onDragEnter"; const char kOnBookmarkDragLeave[] = diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.h b/chrome/browser/extensions/extension_bookmarks_module_constants.h index 3635918..582866b 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.h +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.h @@ -41,9 +41,9 @@ extern const char kOnBookmarkRemoved[]; extern const char kOnBookmarkChanged[]; extern const char kOnBookmarkMoved[]; extern const char kOnBookmarkChildrenReordered[]; -// TODO(arv): Move bookmark manager related constants out of this file. extern const char kOnBookmarkImportBegan[]; extern const char kOnBookmarkImportEnded[]; +// TODO(arv): Move bookmark manager related constants out of this file. extern const char kOnBookmarkDragEnter[]; extern const char kOnBookmarkDragLeave[]; extern const char kOnBookmarkDrop[]; |