Chromium Code Reviews| 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 b456d25759b89cf67af0f94a725680c141f42e74..4c5c539b7760e092f27c1959d3956c261bba0174 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 }, |
| @@ -70,8 +76,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) { |
| @@ -183,4 +194,47 @@ void ImportDataHandler::ImportEnded() { |
| } |
| } |
| +void ImportDataHandler::FileSelected(const base::FilePath& path, |
| + int index, |
| + void* params) { |
| + base::FundamentalValue importing(true); |
| + web_ui()->CallJavascriptFunction("ImportDataOverlay.setImportingState", |
| + importing); |
| + import_did_succeed_ = false; |
| + |
| + importer_host_ = new ExternalProcessImporterHost(); |
| + 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()); |
|
Dan Beam
2013/08/08 05:34:00
nit: ^ not particularly useful, I'd just remove
Ilya Sherman
2013/08/08 08:09:28
In fact, can the parameter be removed entirely?
Dan Beam
2013/08/08 21:33:11
no, but it could be commented out, i.e. const base
|
| + 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 |