Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2652)

Unified Diff: chrome/browser/ui/webui/options/import_data_handler.cc

Issue 22560003: Reland "Add option to import from bookmarks html file to ..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: does this fix first run browser_tests for bots? Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/import_data_handler.cc
diff --git a/chrome/browser/ui/webui/options/import_data_handler.cc b/chrome/browser/ui/webui/options/import_data_handler.cc
index cd8c8b40de48063139ab2b273347b8ddea9d373a..cc1231576523f36f7709b9cb9245158f049b72f6 100644
--- a/chrome/browser/ui/webui/options/import_data_handler.cc
+++ b/chrome/browser/ui/webui/options/import_data_handler.cc
@@ -22,6 +22,8 @@
#include "chrome/browser/importer/importer_uma.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "content/public/browser/web_ui.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -34,11 +36,14 @@ ImportDataHandler::ImportDataHandler() : importer_host_(NULL),
}
ImportDataHandler::~ImportDataHandler() {
- if (importer_list_.get())
+ if (importer_list_)
importer_list_->set_observer(NULL);
if (importer_host_)
importer_host_->set_observer(NULL);
+
+ if (select_file_dialog_)
+ select_file_dialog_->ListenerDestroyed();
}
void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
@@ -52,6 +57,7 @@ void ImportDataHandler::GetLocalizedValues(DictionaryValue* localized_strings) {
{ "importFavorites", IDS_IMPORT_FAVORITES_CHKBOX },
{ "importSearch", IDS_IMPORT_SEARCH_ENGINES_CHKBOX },
{ "importPasswords", IDS_IMPORT_PASSWORDS_CHKBOX },
+ { "importChooseFile", IDS_IMPORT_CHOOSE_FILE },
{ "importCommit", IDS_IMPORT_COMMIT },
{ "noProfileFound", IDS_IMPORT_NO_PROFILE_FOUND },
{ "importSucceeded", IDS_IMPORT_SUCCEEDED },
@@ -71,8 +77,13 @@ void ImportDataHandler::InitializeHandler() {
}
void ImportDataHandler::RegisterMessages() {
- web_ui()->RegisterMessageCallback("importData",
+ web_ui()->RegisterMessageCallback(
+ "importData",
base::Bind(&ImportDataHandler::ImportData, base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "chooseBookmarksFile",
+ base::Bind(&ImportDataHandler::HandleChooseBookmarksFile,
+ base::Unretained(this)));
}
void ImportDataHandler::ImportData(const ListValue* args) {
@@ -191,4 +202,47 @@ void ImportDataHandler::ImportEnded() {
}
}
+void ImportDataHandler::FileSelected(const base::FilePath& path,
+ int index,
gab 2013/09/17 22:06:00 Comment out unused parameter, i.e.: int /* index *
gab 2013/09/17 22:52:20 Handling this myself in https://codereview.chromiu
+ void* params) {
gab 2013/09/17 22:06:00 Same for this parameter.
gab 2013/09/17 22:52:20 Handling this myself in https://codereview.chromiu
+ base::FundamentalValue importing(true);
+ web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState",
+ importing);
+ import_did_succeed_ = false;
+
+ importer_host_ = new ExternalProcessImporterHost();
gab 2013/09/17 22:06:00 Move 213-223 in a common method used by both this
gab 2013/09/17 22:52:20 Handling this myself in https://codereview.chromiu
+ importer_host_->set_observer(this);
+
+ importer::SourceProfile source_profile;
+ source_profile.importer_type = importer::TYPE_BOOKMARKS_FILE;
+ source_profile.source_path = path;
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+
+ importer_host_->StartImportSettings(
+ source_profile, profile, importer::FAVORITES, new ProfileWriter(profile));
+}
+
+void ImportDataHandler::HandleChooseBookmarksFile(const base::ListValue* args) {
+ DCHECK(args && args->empty());
+ select_file_dialog_ = ui::SelectFileDialog::Create(
+ this, new ChromeSelectFilePolicy(web_ui()->GetWebContents()));
+
+ ui::SelectFileDialog::FileTypeInfo file_type_info;
+ file_type_info.extensions.resize(1);
+ file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html"));
+
+ Browser* browser =
+ chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
+
+ select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE,
+ base::string16(),
+ base::FilePath(),
+ &file_type_info,
+ 0,
+ base::FilePath::StringType(),
+ browser->window()->GetNativeWindow(),
+ NULL);
+}
+
} // namespace options

Powered by Google App Engine
This is Rietveld 408576698