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 | |
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
10 files changed, 311 insertions, 139 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[]; diff --git a/chrome/browser/resources/bookmark_manager/main.html b/chrome/browser/resources/bookmark_manager/main.html index e2ec832..3307c74 100644 --- a/chrome/browser/resources/bookmark_manager/main.html +++ b/chrome/browser/resources/bookmark_manager/main.html @@ -346,10 +346,8 @@ function addBookmarkModelListeners() { chrome.bookmarks.onCreated.addListener(handleCreated); chrome.bookmarks.onMoved.addListener(handleMoved); chrome.bookmarks.onRemoved.addListener(handleRemoved); - chrome.experimental.bookmarkManager.onImportBegan.addListener( - handleImportBegan); - chrome.experimental.bookmarkManager.onImportEnded.addListener( - handleImportEnded); + chrome.bookmarks.onImportBegan.addListener(handleImportBegan); + chrome.bookmarks.onImportEnded.addListener(handleImportEnded); } /** @@ -1226,9 +1224,9 @@ document.addEventListener('command', function(e) { var commandId = command.id; console.log(command.id, 'executed', 'on', e.target); if (commandId == 'import-menu-command') { - chrome.experimental.bookmarkManager.import(); + chrome.bookmarks.import(); } else if (command.id == 'export-menu-command') { - chrome.experimental.bookmarkManager.export(); + chrome.bookmarks.export(); } }); diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index ea80713..1adf289 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -1625,6 +1625,24 @@ {"type": "string", "name": "id"}, {"type": "function", "name": "callback", "optional": true, "parameters": []} ] + }, + { + "name": "import", + "type": "function", + "description": "Imports bookmarks from a chrome html bookmark file", + "nodoc": "true", + "parameters": [ + {"type": "function", "name": "callback", "optional": true, "parameters": []} + ] + }, + { + "name": "export", + "type": "function", + "description": "Exports bookmarks to a chrome html bookmark file", + "nodoc": "true", + "parameters": [ + {"type": "function", "name": "callback", "optional": true, "parameters": []} + ] } ], "events": [ @@ -1704,6 +1722,18 @@ } } ] + }, + { + "name": "onImportBegan", + "type": "function", + "description": "Fired when a bookmark import session is begun. Expensive observers should ignore handleCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately.", + "parameters": [] + }, + { + "name": "onImportEnded", + "type": "function", + "description": "Fired when a bookmark import session is ended.", + "parameters": [] } ] }, @@ -2166,24 +2196,6 @@ ] }, { - "name": "import", - "type": "function", - "description": "Imports bookmarks from a chrome html bookmark file", - "nodoc": "true", - "parameters": [ - {"type": "function", "name": "callback", "optional": true, "parameters": []} - ] - }, - { - "name": "export", - "type": "function", - "description": "Exports bookmarks to a chrome html bookmark file", - "nodoc": "true", - "parameters": [ - {"type": "function", "name": "callback", "optional": true, "parameters": []} - ] - }, - { "name": "sortChildren", "type": "function", "description": "Sorts the children of a given folder", @@ -2249,18 +2261,6 @@ ], "events": [ { - "name": "onImportBegan", - "type": "function", - "description": "Fired when a bookmark import session is begun. Expensive observers should ignore handleCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately.", - "parameters": [] - }, - { - "name": "onImportEnded", - "type": "function", - "description": "Fired when a bookmark import session is ended.", - "parameters": [] - }, - { "name": "onDragEnter", "type": "function", "description": "Fired when dragging bookmarks over the document", diff --git a/chrome/common/extensions/docs/bookmarks.html b/chrome/common/extensions/docs/bookmarks.html index 9d257c8..6401670 100644 --- a/chrome/common/extensions/docs/bookmarks.html +++ b/chrome/common/extensions/docs/bookmarks.html @@ -238,6 +238,8 @@ <ol> <li> <a href="#method-create">create</a> + </li><li style="display: none; "> + <a href="#method-anchor">methodName</a> </li><li> <a href="#method-get">get</a> </li><li> @@ -246,6 +248,8 @@ <a href="#method-getRecent">getRecent</a> </li><li> <a href="#method-getTree">getTree</a> + </li><li style="display: none; "> + <a href="#method-anchor">methodName</a> </li><li> <a href="#method-move">move</a> </li><li> @@ -269,6 +273,10 @@ </li><li> <a href="#event-onCreated">onCreated</a> </li><li> + <a href="#event-onImportBegan">onImportBegan</a> + </li><li> + <a href="#event-onImportEnded">onImportEnded</a> + </li><li> <a href="#event-onMoved">onMoved</a> </li><li> <a href="#event-onRemoved">onRemoved</a> @@ -757,6 +765,65 @@ For other examples and for help in viewing the source code, see </div> <!-- /description --> + </div><div class="apiItem" style="display: none; "> + <a></a> <!-- method-anchor --> + <h4>method name</h4> + + <div class="summary"><span>void</span> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.module.methodName</span>(<span><span>, </span><span></span> + <var><span></span></var></span>)</div> + + <div class="description"> + <p class="todo">Undocumented.</p> + <p> + A description from the json schema def of the function goes here. + </p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + </div> + </div> + </dl> + + <!-- RETURNS --> + <h4>Returns</h4> + <dl> + <div> + <div> + </div> + </div> + </dl> + + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <p> + If you specify the <em>callback</em> parameter, it should + specify a function that looks like this: + </p> + + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>);</pre> + <dl> + <div> + <div> + </div> + </div> + </dl> + </div> + </div> + + </div> <!-- /description --> + </div><div class="apiItem"> <a name="method-get"></a> <!-- method-anchor --> <h4>get</h4> @@ -1473,6 +1540,65 @@ For other examples and for help in viewing the source code, see </div> <!-- /description --> + </div><div class="apiItem" style="display: none; "> + <a></a> <!-- method-anchor --> + <h4>method name</h4> + + <div class="summary"><span>void</span> + <!-- Note: intentionally longer 80 columns --> + <span>chrome.module.methodName</span>(<span><span>, </span><span></span> + <var><span></span></var></span>)</div> + + <div class="description"> + <p class="todo">Undocumented.</p> + <p> + A description from the json schema def of the function goes here. + </p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div> + <div> + </div> + </div> + </dl> + + <!-- RETURNS --> + <h4>Returns</h4> + <dl> + <div> + <div> + </div> + </div> + </dl> + + <!-- CALLBACK --> + <div> + <div> + <h4>Callback function</h4> + <p> + The callback <em>parameter</em> should specify a function + that looks like this: + </p> + <p> + If you specify the <em>callback</em> parameter, it should + specify a function that looks like this: + </p> + + <!-- Note: intentionally longer 80 columns --> + <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>);</pre> + <dl> + <div> + <div> + </div> + </div> + </dl> + </div> + </div> + + </div> <!-- /description --> + </div><div class="apiItem"> <a name="method-move"></a> <!-- method-anchor --> <h4>move</h4> @@ -3027,6 +3153,54 @@ For other examples and for help in viewing the source code, see </div> <!-- /decription --> </div><div class="apiItem"> + <a name="event-onImportBegan"></a> + <h4>onImportBegan</h4> + + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span class="subdued">chrome.bookmarks.</span><span>onImportBegan</span><span class="subdued">.addListener</span>(function(<span></span>) <span class="subdued">{...}</span>); + </div> + + <div class="description"> + <p class="todo" style="display: none; ">Undocumented.</p> + <p>Fired when a bookmark import session is begun. Expensive observers should ignore handleCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately.</p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div style="display: none; "> + <div> + </div> + </div> + </dl> + + </div> <!-- /decription --> + + </div><div class="apiItem"> + <a name="event-onImportEnded"></a> + <h4>onImportEnded</h4> + + <div class="summary"> + <!-- Note: intentionally longer 80 columns --> + <span class="subdued">chrome.bookmarks.</span><span>onImportEnded</span><span class="subdued">.addListener</span>(function(<span></span>) <span class="subdued">{...}</span>); + </div> + + <div class="description"> + <p class="todo" style="display: none; ">Undocumented.</p> + <p>Fired when a bookmark import session is ended.</p> + + <!-- PARAMETERS --> + <h4>Parameters</h4> + <dl> + <div style="display: none; "> + <div> + </div> + </div> + </dl> + + </div> <!-- /decription --> + + </div><div class="apiItem"> <a name="event-onMoved"></a> <h4>onMoved</h4> diff --git a/chrome/common/extensions/docs/override.html b/chrome/common/extensions/docs/override.html index 71c1b72..1aba705 100644 --- a/chrome/common/extensions/docs/override.html +++ b/chrome/common/extensions/docs/override.html @@ -171,6 +171,8 @@ <li><h2><a href="tutorials.html">Tutorials</a></h2> <ul> <li><a href="tut_debugging.html">Debugging</a></li> + <li><a href="tut_analytics.html">Google Analytics</a></li> + <li><a href="tut_oauth.html">OAuth</a></li> </ul> </li> <li><h2>Reference</h2> |