| 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,
|
| + 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());
|
| + 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
|
|
|